| Conditions | 39 |
| Paths | > 20000 |
| Total Lines | 192 |
| Code Lines | 137 |
| Lines | 24 |
| Ratio | 12.5 % |
| Changes | 0 | ||
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:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 22 | function menu_block() |
||
| 23 | { |
||
| 24 | global $xoopsTpl, $xoopsUser, $pedigree; |
||
| 25 | $moduleDirName = basename(dirname(__DIR__)); |
||
| 26 | /* |
||
| 27 | //get module configuration |
||
| 28 | $moduleHandler = xoops_getHandler('module'); |
||
| 29 | $module = $moduleHandler->getByDirname($moduleDirName); |
||
| 30 | $configHandler = xoops_getHandler('config'); |
||
| 31 | $moduleConfig = $configHandler->getConfigsByCat(0, $module->getVar('mid')); |
||
| 32 | */ |
||
| 33 | //colour variables |
||
| 34 | $colors = explode(',', $helper->getConfig('colourscheme')); |
||
| 35 | $actlink = $colors[0]; |
||
| 36 | $even = $colors[1]; |
||
| 37 | $odd = $colors[2]; |
||
| 38 | $text = $colors[3]; |
||
| 39 | $hovlink = $colors[4]; |
||
| 40 | $head = $colors[5]; |
||
| 41 | $body = $colors[6]; |
||
| 42 | $title = $colors[7]; |
||
| 43 | |||
| 44 | /* |
||
| 45 | //inline-css |
||
| 46 | echo '<style>'; |
||
| 47 | //text-colour |
||
| 48 | echo 'body {margin: 0;padding: 0;background: ' . $body . ';color: ' . $text . ";font-size: 62.5%; font-family: 'Lucida Grande', Verdana, Arial, Sans-Serif; text-align: left;}"; |
||
| 49 | //link-colour |
||
| 50 | echo 'a, h2 a:hover, h3 a:hover { color: ' . $actlink . '; text-decoration: none; }'; |
||
| 51 | //link hover colour |
||
| 52 | echo 'a:hover { color: ' . $hovlink . '; text-decoration: underline; }'; |
||
| 53 | //th |
||
| 54 | echo 'th {padding: 2px;color: #ffffff;background: ' . $title . ';font-family: Verdana, Arial, Helvetica, sans-serif;vertical-align: middle;}'; |
||
| 55 | echo 'td#centercolumn th { color: #fff; background: ' . $title . '; vertical-align: middle; }'; |
||
| 56 | //head |
||
| 57 | echo '.head {background-color: ' . $head . '; padding: 3px; font-weight: normal;}'; |
||
| 58 | //even |
||
| 59 | echo '.even {background-color: ' . $even . '; padding: 3px;}'; |
||
| 60 | echo 'tr.even td {background-color: ' . $even . '; padding: 3px;}'; |
||
| 61 | //odd |
||
| 62 | echo '.odd {background-color: ' . $odd . '; padding: 3px;}'; |
||
| 63 | echo 'tr.odd td {background-color: ' . $odd . '; padding: 3px;}'; |
||
| 64 | echo '</style>'; |
||
| 65 | */ |
||
| 66 | |||
| 67 | //iscurrent user a module admin ? |
||
| 68 | $xoopsModule = XoopsModule::getByDirname($moduleDirName); |
||
| 69 | if (!empty($xoopsUser) && ($GLOBALS['xoopsUser'] instanceof \XoopsUser) |
||
| 70 | && $xoopsUser->isAdmin($xoopsModule->mid())) { |
||
| 71 | $modadmin = true; |
||
| 72 | } else { |
||
| 73 | $modadmin = false; |
||
| 74 | } |
||
| 75 | $counter = 1; |
||
| 76 | $menuwidth = 4; |
||
| 77 | |||
| 78 | $x = $_SERVER['PHP_SELF']; |
||
| 79 | $lastpos = my_strrpos($x, '/'); |
||
| 80 | $len = strlen($x); |
||
| 81 | $curpage = substr($x, $lastpos, $len); |
||
| 82 | if (1 == $helper->getConfig('showwelcome')) { |
||
| 83 | if ('/welcome.php' === $curpage) { |
||
| 84 | $title = '<b>Welcome</b>'; |
||
| 85 | } else { |
||
| 86 | $title = 'Welcome'; |
||
| 87 | } |
||
| 88 | $menuarray[] = ['title' => $title, 'link' => 'welcome.php', 'counter' => $counter]; |
||
| 89 | ++$counter; |
||
| 90 | if ($counter == $menuwidth) { |
||
| 91 | $counter = 1; |
||
| 92 | } |
||
| 93 | } |
||
| 94 | if ('/index.php' === $curpage || '/result.php' === $curpage) { |
||
| 95 | $title = '<b>View/Search ' . $helper->getConfig('animalTypes') . '</b>'; |
||
| 96 | } else { |
||
| 97 | $title = 'View/Search ' . $helper->getConfig('animalTypes'); |
||
| 98 | } |
||
| 99 | $menuarray[] = ['title' => $title, 'link' => 'index.php', 'counter' => $counter]; |
||
| 100 | ++$counter; |
||
| 101 | if ($counter == $menuwidth) { |
||
| 102 | $counter = 1; |
||
| 103 | } |
||
| 104 | if ('/add_dog.php' === $curpage) { |
||
| 105 | $title = '<b>Add a ' . $helper->getConfig('animalType') . '</b>'; |
||
| 106 | } else { |
||
| 107 | $title = 'Add a ' . $helper->getConfig('animalType'); |
||
| 108 | } |
||
| 109 | $menuarray[] = ['title' => $title, 'link' => 'add_dog.php', 'counter' => $counter]; |
||
| 110 | ++$counter; |
||
| 111 | if ($counter == $menuwidth) { |
||
| 112 | $counter = 1; |
||
| 113 | } |
||
| 114 | if ('1' == $helper->getConfig('uselitter')) { |
||
| 115 | if ('/add_litter.php' === $curpage) { |
||
| 116 | $title = '<b>Add a ' . $helper->getConfig('litter') . '</b>'; |
||
| 117 | } else { |
||
| 118 | $title = 'Add a ' . $helper->getConfig('litter'); |
||
| 119 | } |
||
| 120 | $menuarray[] = ['title' => $title, 'link' => 'add_litter.php', 'counter' => $counter]; |
||
| 121 | ++$counter; |
||
| 122 | if ($counter == $menuwidth) { |
||
| 123 | $counter = 1; |
||
| 124 | } |
||
| 125 | } |
||
| 126 | if ('1' == $helper->getConfig('ownerbreeder')) { |
||
| 127 | if ('/breeder.php' === $curpage || '/owner.php' === $curpage) { |
||
| 128 | $title = '<b>View owners/breeders</b>'; |
||
| 129 | } else { |
||
| 130 | $title = 'View owners/breeders'; |
||
| 131 | } |
||
| 132 | $menuarray[] = ['title' => $title, 'link' => 'breeder.php', 'counter' => $counter]; |
||
| 133 | ++$counter; |
||
| 134 | if ($counter == $menuwidth) { |
||
| 135 | $counter = 1; |
||
| 136 | } |
||
| 137 | if ('/add_breeder.php' === $curpage) { |
||
| 138 | $title = '<b>Add an owner/breeder</b>'; |
||
| 139 | } else { |
||
| 140 | $title = 'Add an owner/breeder'; |
||
| 141 | } |
||
| 142 | $menuarray[] = ['title' => $title, 'link' => 'add_breeder.php', 'counter' => $counter]; |
||
| 143 | ++$counter; |
||
| 144 | if ($counter == $menuwidth) { |
||
| 145 | $counter = 1; |
||
| 146 | } |
||
| 147 | } |
||
| 148 | if ('/advanced.php' === $curpage) { |
||
| 149 | $title = '<b>Advanced info</b>'; |
||
| 150 | } else { |
||
| 151 | $title = 'Advanced info'; |
||
| 152 | } |
||
| 153 | $menuarray[] = ['title' => $title, 'link' => 'advanced.php', 'counter' => $counter]; |
||
| 154 | ++$counter; |
||
| 155 | if ($counter == $menuwidth) { |
||
| 156 | $counter = 1; |
||
| 157 | } |
||
| 158 | if ('1' == $helper->getConfig('proversion')) { |
||
| 159 | if ('/virtual.php' === $curpage) { |
||
| 160 | $title = '<b>Virtual mating</b>'; |
||
| 161 | } else { |
||
| 162 | $title = 'Virtual Mating'; |
||
| 163 | } |
||
| 164 | $menuarray[] = ['title' => $title, 'link' => 'virtual.php', 'counter' => $counter]; |
||
| 165 | ++$counter; |
||
| 166 | if ($counter == $menuwidth) { |
||
| 167 | $counter = 1; |
||
| 168 | } |
||
| 169 | } |
||
| 170 | if ('/latest.php' === $curpage) { |
||
| 171 | $title = '<b>latest additions</b>'; |
||
| 172 | } else { |
||
| 173 | $title = 'latest additions'; |
||
| 174 | } |
||
| 175 | $menuarray[] = ['title' => $title, 'link' => 'latest.php', 'counter' => $counter]; |
||
| 176 | ++$counter; |
||
| 177 | if ($counter == $menuwidth) { |
||
| 178 | $counter = 1; |
||
| 179 | } |
||
| 180 | if (true === $modadmin) { |
||
| 181 | if ('/tools.php' === $curpage) { |
||
| 182 | $title = '<b>Webmaster tools</b>'; |
||
| 183 | } else { |
||
| 184 | $title = 'Webmaster tools'; |
||
| 185 | } |
||
| 186 | $menuarray[] = ['title' => $title, 'link' => 'tools.php?op=index', 'counter' => $counter]; |
||
| 187 | ++$counter; |
||
| 188 | if ($counter == $menuwidth) { |
||
| 189 | $counter = 1; |
||
| 190 | } |
||
| 191 | $title = 'Logout'; |
||
| 192 | $menuarray[] = ['title' => $title, 'link' => '../../user.php?op=logout', 'counter' => $counter]; |
||
| 193 | ++$counter; |
||
| 194 | if ($counter == $menuwidth) { |
||
| 195 | $counter = 1; |
||
| 196 | } |
||
| 197 | } else { |
||
| 198 | if ('/user.php' === $curpage) { |
||
| 199 | $title = '<b>User login</b>'; |
||
| 200 | } else { |
||
| 201 | $title = 'User login'; |
||
| 202 | } |
||
| 203 | $menuarray[] = ['title' => $title, 'link' => '../../user.php', 'counter' => $counter]; |
||
| 204 | ++$counter; |
||
| 205 | if ($counter == $menuwidth) { |
||
| 206 | $counter = 1; |
||
| 207 | } |
||
| 208 | } |
||
| 209 | |||
| 210 | //create path taken |
||
| 211 | //showpath(); |
||
| 212 | $xoopsTpl->assign('menuarray', $menuarray); |
||
| 213 | |||
| 214 | //return the template contents |
||
| 239 |