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