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