This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
1 | <?php |
||||||
2 | |||||||
3 | namespace XoopsModules\Pedigree; |
||||||
4 | |||||||
5 | /* |
||||||
6 | * You may not change or alter any portion of this comment or credits |
||||||
7 | * of supporting developers from this source code or any supporting source code |
||||||
8 | * which is considered copyrighted (c) material of the original comment or credit authors. |
||||||
9 | * |
||||||
10 | * This program is distributed in the hope that it will be useful, |
||||||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||||||
13 | */ |
||||||
14 | |||||||
15 | /** |
||||||
16 | * @package XoopsModules\Pedigree |
||||||
17 | * @copyright {@link https://xoops.org/ XOOPS Project} |
||||||
18 | * @license {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later} |
||||||
19 | * @author XOOPS Module Dev Team |
||||||
20 | */ |
||||||
21 | |||||||
22 | use XoopsModules; |
||||||
23 | |||||||
24 | |||||||
25 | |||||||
26 | /** |
||||||
27 | * Class Utility |
||||||
28 | */ |
||||||
29 | class Utility |
||||||
30 | { |
||||||
31 | use Common\VersionChecks; //checkVerXoops, checkVerPhp Traits |
||||||
0 ignored issues
–
show
introduced
by
![]() |
|||||||
32 | |||||||
33 | use Common\ServerStats; // getServerStats Trait |
||||||
34 | |||||||
35 | use Common\FilesManagement; // Files Management Trait |
||||||
36 | |||||||
37 | //--------------- Custom module methods ----------------------------- |
||||||
38 | |||||||
39 | /** |
||||||
40 | * @param string $folder The full path of the directory to check |
||||||
41 | * @deprecated - NOT USED : use Pedigree\Common\FilesManagement methods instead |
||||||
42 | * Function responsible for checking if a directory exists, we can also write in and create an index.php file |
||||||
43 | * |
||||||
44 | */ |
||||||
45 | public static function prepareFolder($folder) |
||||||
46 | { |
||||||
47 | // $filteredFolder = XoopsFilterInput::clean($folder, 'PATH'); |
||||||
48 | if (!\is_dir($folder)) { |
||||||
49 | if (!\mkdir($folder) && !\is_dir($folder)) { |
||||||
50 | throw new \RuntimeException(\sprintf('Directory "%s" was not created', $folder)); |
||||||
51 | } |
||||||
52 | file_put_contents($folder . '/index.php', "<?php\n\nheader('HTTP/1.0 404 Not Found');\n"); |
||||||
53 | } |
||||||
54 | // chmod($filteredFolder, 0777); |
||||||
55 | } |
||||||
56 | |||||||
57 | /** |
||||||
58 | * @param $columncount |
||||||
59 | * |
||||||
60 | * @return string |
||||||
61 | */ |
||||||
62 | public static function sortTable($columncount) |
||||||
63 | { |
||||||
64 | $ttemp = ''; |
||||||
65 | if ($columncount > 1) { |
||||||
66 | for ($t = 1; $t < $columncount; ++$t) { |
||||||
67 | $ttemp .= "'S',"; |
||||||
68 | } |
||||||
69 | $tsarray = "initSortTable('Result', Array({$ttemp}'S'));"; |
||||||
70 | } else { |
||||||
71 | $tsarray = "initSortTable('Result',Array('S'));"; |
||||||
72 | } |
||||||
73 | |||||||
74 | return $tsarray; |
||||||
75 | } |
||||||
76 | |||||||
77 | /** |
||||||
78 | * @param string $haystack |
||||||
79 | * @param string $needle |
||||||
80 | * @param int $offset |
||||||
81 | * |
||||||
82 | * @return bool|int |
||||||
83 | */ |
||||||
84 | public static function myStrRpos($haystack, $needle, $offset = 0) |
||||||
85 | { |
||||||
86 | // same as strrpos, except $needle can be a string |
||||||
87 | $strrpos = false; |
||||||
88 | if (\is_string($haystack) && \is_string($needle) && \is_numeric($offset)) { |
||||||
0 ignored issues
–
show
|
|||||||
89 | $strlen = \mb_strlen($haystack); |
||||||
90 | $strpos = \mb_strpos(\strrev(\mb_substr($haystack, $offset)), \strrev($needle)); |
||||||
91 | if (\is_numeric($strpos)) { |
||||||
0 ignored issues
–
show
|
|||||||
92 | $strrpos = $strlen - $strpos - \mb_strlen($needle); |
||||||
93 | } |
||||||
94 | } |
||||||
95 | |||||||
96 | return $strrpos; |
||||||
97 | } |
||||||
98 | |||||||
99 | /** |
||||||
100 | * @param int $num |
||||||
101 | * |
||||||
102 | * @return string |
||||||
103 | */ |
||||||
104 | public static function uploadPicture($num) |
||||||
105 | { |
||||||
106 | require_once $GLOBALS['xoops']->path('class/uploader.php'); |
||||||
107 | |||||||
108 | $num = (int)$num; |
||||||
109 | |||||||
110 | /** @var XoopsModules\Pedigree\Helper $helper */ |
||||||
111 | $helper = XoopsModules\Pedigree\Helper::getInstance(); |
||||||
112 | $maxImgSize = $helper->getConfig('maxfilesize'); |
||||||
113 | $maxImgWidth = $helper->getConfig('maximgwidth'); |
||||||
114 | $maxImgHeight = $helper->getConfig('maximgheight'); |
||||||
115 | $allowedMimetypes = ['image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png']; |
||||||
116 | $imgDir = $helper->getConfig('uploaddir') . '/images'; |
||||||
117 | |||||||
118 | $field = $_POST['xoops_upload_file'][$num]; |
||||||
119 | if (!empty($field)) { |
||||||
120 | $uploader = new \XoopsMediaUploader($imgDir, $allowedMimetypes, $maxImgSize, $maxImgWidth, $maxImgHeight); |
||||||
121 | $uploader->setPrefix('img'); |
||||||
122 | if ($uploader->fetchMedia($field) && $uploader->upload()) { |
||||||
123 | $photo = $uploader->getSavedFileName(); |
||||||
124 | } else { |
||||||
125 | echo $uploader->getErrors(); |
||||||
126 | } |
||||||
127 | static::createThumbs($photo); |
||||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||||
128 | |||||||
129 | return $photo; |
||||||
130 | } |
||||||
131 | |||||||
132 | $max_imgsize = $GLOBALS['xoopsModuleConfig']['maxfilesize']; //1024000; |
||||||
133 | $max_imgwidth = $GLOBALS['xoopsModuleConfig']['maximgwidth']; //1500; |
||||||
134 | $max_imgheight = $GLOBALS['xoopsModuleConfig']['maximgheight']; //1000; |
||||||
135 | $allowed_mimetypes = ['image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png']; |
||||||
136 | // $img_dir = XOOPS_ROOT_PATH . "/modules/" . $GLOBALS['xoopsModule']->dirname() . "/images" ; |
||||||
137 | $img_dir = $GLOBALS['xoopsModuleConfig']['uploaddir'] . '/images'; |
||||||
138 | require_once $GLOBALS['xoops']->path('class/uploader.php'); |
||||||
139 | $field = $_POST['xoops_upload_file'][$num]; |
||||||
140 | if (!empty($field) || '' != $field) { |
||||||
141 | $uploader = new \XoopsMediaUploader($img_dir, $allowed_mimetypes, $max_imgsize, $max_imgwidth, $max_imgheight); |
||||||
142 | $uploader->setPrefix('img'); |
||||||
143 | if ($uploader->fetchMedia($field) && $uploader->upload()) { |
||||||
144 | $photo = $uploader->getSavedFileName(); |
||||||
145 | } else { |
||||||
146 | echo $uploader->getErrors(); |
||||||
147 | } |
||||||
148 | static::createThumbs($photo); |
||||||
149 | |||||||
150 | return $photo; |
||||||
151 | } |
||||||
152 | |||||||
153 | return ''; |
||||||
154 | } |
||||||
155 | |||||||
156 | /** |
||||||
157 | * @param $filename |
||||||
158 | */ |
||||||
159 | public static function createThumbs($filename) |
||||||
160 | { |
||||||
161 | /* |
||||||
162 | require_once __DIR__ . '/phpthumb/phpthumb.class.php'; |
||||||
163 | $thumbnail_widths = array(150, 400); |
||||||
164 | foreach ($thumbnail_widths as $thumbnail_width) { |
||||||
165 | $phpThumb = new phpThumb(); |
||||||
166 | // set data |
||||||
167 | $phpThumb->setSourceFilename('images/' . $filename); |
||||||
168 | $phpThumb->w = $thumbnail_width; |
||||||
169 | $phpThumb->config_output_format = 'jpeg'; |
||||||
170 | // generate & output thumbnail |
||||||
171 | $output_filename = PEDIGREE_UPLOAD_URL . '/thumbnails/' . basename($filename) . '_' . $thumbnail_width . '.' . $phpThumb->config_output_format; |
||||||
172 | if ($phpThumb->GenerateThumbnail()) { // this line is VERY important, do not remove it! |
||||||
173 | if ($output_filename) { |
||||||
174 | if ($phpThumb->RenderToFile($output_filename)) { |
||||||
175 | // do something on success |
||||||
176 | //echo 'Successfully rendered:<br><img src="'.$output_filename.'">'; |
||||||
177 | } else { |
||||||
178 | echo 'Failed (size=' . $thumbnail_width . '):<pre>' . implode("\n\n", $phpThumb->debugmessages) . '</pre>'; |
||||||
179 | } |
||||||
180 | } |
||||||
181 | } else { |
||||||
182 | echo 'Failed (size=' . $thumbnail_width . '):<pre>' . implode("\n\n", $phpThumb->debugmessages) . '</pre>'; |
||||||
183 | } |
||||||
184 | unset($phpThumb); |
||||||
185 | } |
||||||
186 | |||||||
187 | return true; |
||||||
188 | |||||||
189 | */ |
||||||
190 | |||||||
191 | // load the image |
||||||
192 | require_once $GLOBALS['xoops']->path('modules/' . $GLOBALS['xoopsModule']->dirname() . '/library/Zebra_Image.php'); |
||||||
193 | $thumbnail_widths = [150, 400]; |
||||||
194 | |||||||
195 | // indicate a target image |
||||||
196 | // note that there's no extra property to set in order to specify the target |
||||||
197 | // image's type -simply by writing '.jpg' as extension will instruct the script |
||||||
198 | // to create a 'jpg' file |
||||||
199 | $config_output_format = 'jpeg'; |
||||||
200 | |||||||
201 | // create a new instance of the class |
||||||
202 | $image = new \Zebra_Image(); |
||||||
203 | // indicate a source image (a GIF, PNG or JPEG file) |
||||||
204 | $image->source_path = PEDIGREE_UPLOAD_PATH . "/images/{$filename}"; |
||||||
0 ignored issues
–
show
|
|||||||
205 | |||||||
206 | foreach ($thumbnail_widths as $thumbnail_width) { |
||||||
207 | // generate & output thumbnail |
||||||
208 | $output_filename = PEDIGREE_UPLOAD_PATH . '/images/thumbnails/' . \basename($filename) . "_{$thumbnail_width}.{$config_output_format}"; |
||||||
209 | $image->target_path = $output_filename; |
||||||
210 | // since in this example we're going to have a jpeg file, let's set the output |
||||||
211 | // image's quality |
||||||
212 | $image->jpeg_quality = 100; |
||||||
213 | // some additional properties that can be set |
||||||
214 | // read about them in the documentation |
||||||
215 | $image->preserve_aspect_ratio = true; |
||||||
216 | $image->enlarge_smaller_images = true; |
||||||
217 | $image->preserve_time = true; |
||||||
218 | |||||||
219 | // resize the image to exactly 100x100 pixels by using the "crop from center" method |
||||||
220 | // (read more in the overview section or in the documentation) |
||||||
221 | // and if there is an error, check what the error is about |
||||||
222 | if (!$image->resize($thumbnail_width, 0)) { |
||||||
223 | // if there was an error, let's see what the error is about |
||||||
224 | switch ($image->error) { |
||||||
225 | case 1: |
||||||
226 | echo 'Source file could not be found!'; |
||||||
227 | break; |
||||||
228 | case 2: |
||||||
229 | echo 'Source file is not readable!'; |
||||||
230 | break; |
||||||
231 | case 3: |
||||||
232 | echo 'Could not write target file!'; |
||||||
233 | break; |
||||||
234 | case 4: |
||||||
235 | echo 'Unsupported source file format!'; |
||||||
236 | break; |
||||||
237 | case 5: |
||||||
238 | echo 'Unsupported target file format!'; |
||||||
239 | break; |
||||||
240 | case 6: |
||||||
241 | echo 'GD library version does not support target file format!'; |
||||||
242 | break; |
||||||
243 | case 7: |
||||||
244 | echo 'GD library is not installed!'; |
||||||
245 | break; |
||||||
246 | case 8: |
||||||
247 | echo '"chmod" command is disabled via configuration!'; |
||||||
248 | break; |
||||||
249 | } |
||||||
250 | // if no errors |
||||||
251 | } else { |
||||||
252 | echo 'Success!'; |
||||||
253 | } |
||||||
254 | /* |
||||||
255 | if ($phpThumb->GenerateThumbnail()) { // this line is VERY important, do not remove it! |
||||||
256 | if ($output_filename) { |
||||||
257 | if ($phpThumb->RenderToFile($output_filename)) { |
||||||
258 | // do something on success |
||||||
259 | //echo 'Successfully rendered:<br><img src="'.$output_filename.'">'; |
||||||
260 | } else { |
||||||
261 | echo 'Failed (size='.$thumbnail_width.'):<pre>'.implode("\n\n", $phpThumb->debugmessages).'</pre>'; |
||||||
262 | } |
||||||
263 | } |
||||||
264 | } else { |
||||||
265 | echo 'Failed (size='.$thumbnail_width.'):<pre>'.implode("\n\n", $phpThumb->debugmessages).'</pre>'; |
||||||
266 | } |
||||||
267 | */ |
||||||
268 | } |
||||||
269 | |||||||
270 | unset($image); |
||||||
271 | } |
||||||
272 | |||||||
273 | /** |
||||||
274 | * @param $string |
||||||
275 | * |
||||||
276 | * @return string |
||||||
277 | */ |
||||||
278 | public static function unHtmlEntities($string) |
||||||
279 | { |
||||||
280 | $trans_tbl = \array_flip(\get_html_translation_table(\HTML_ENTITIES)); |
||||||
281 | |||||||
282 | return strtr($string, $trans_tbl); |
||||||
283 | } |
||||||
284 | |||||||
285 | /** |
||||||
286 | * @param $oid |
||||||
287 | * @param $gender |
||||||
288 | * @return null |
||||||
289 | */ |
||||||
290 | public static function pups($oid, $gender) |
||||||
291 | { |
||||||
292 | global $numofcolumns, $nummatch, $pages, $columns, $dogs; |
||||||
293 | $content = ''; |
||||||
0 ignored issues
–
show
|
|||||||
294 | |||||||
295 | if (0 == $gender) { |
||||||
296 | $sqlquery = 'SELECT d.id AS d_id, d.pname AS d_pname, d.roft AS d_roft, d.* FROM ' |
||||||
297 | . $GLOBALS['xoopsDB']->prefix('pedigree_registry') |
||||||
298 | . ' d LEFT JOIN ' |
||||||
299 | . $GLOBALS['xoopsDB']->prefix('pedigree_registry') |
||||||
300 | . ' f ON d.father = f.id LEFT JOIN ' |
||||||
301 | . $GLOBALS['xoopsDB']->prefix('pedigree_registry') |
||||||
302 | . ' m ON d.mother = m.id WHERE d.father=' |
||||||
303 | . $oid |
||||||
304 | . ' ORDER BY d.pname'; |
||||||
305 | } else { |
||||||
306 | $sqlquery = 'SELECT d.id AS d_id, d.pname AS d_pname, d.roft AS d_roft, d.* FROM ' |
||||||
307 | . $GLOBALS['xoopsDB']->prefix('pedigree_registry') |
||||||
308 | . ' d LEFT JOIN ' |
||||||
309 | . $GLOBALS['xoopsDB']->prefix('pedigree_registry') |
||||||
310 | . ' f ON d.father = f.id LEFT JOIN ' |
||||||
311 | . $GLOBALS['xoopsDB']->prefix('pedigree_registry') |
||||||
312 | . ' m ON d.mother = m.id WHERE d.mother=' |
||||||
313 | . $oid |
||||||
314 | . ' ORDER BY d.pname'; |
||||||
315 | } |
||||||
316 | $queryresult = $GLOBALS['xoopsDB']->query($sqlquery); |
||||||
317 | $nummatch = $GLOBALS['xoopsDB']->getRowsNum($queryresult); |
||||||
318 | |||||||
319 | $animal = new Pedigree\Animal(); |
||||||
0 ignored issues
–
show
The type
XoopsModules\Pedigree\Pedigree\Animal was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||||
320 | //test to find out how many user fields there are... |
||||||
321 | $fields = $animal->getNumOfFields(); |
||||||
322 | $numofcolumns = 1; |
||||||
323 | $columns[] = ['columnname' => 'Name']; |
||||||
324 | foreach ($fields as $i => $iValue) { |
||||||
325 | $userField = new Pedigree\Field($fields[$i], $animal->getConfig()); |
||||||
0 ignored issues
–
show
The type
XoopsModules\Pedigree\Pedigree\Field was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||||
326 | $fieldType = $userField->getSetting('fieldtype'); |
||||||
327 | $fieldObject = new $fieldType($userField, $animal); |
||||||
328 | //create empty string |
||||||
329 | $lookupvalues = ''; |
||||||
330 | if ($userField->isActive() && $userField->inList()) { |
||||||
331 | if ($userField->hasLookup()) { |
||||||
332 | $lookupvalues = $userField->lookupField($fields[$i]); |
||||||
333 | //debug information |
||||||
334 | //print_r($lookupvalues); |
||||||
335 | } |
||||||
336 | $columns[] = [ |
||||||
337 | 'columnname' => $fieldObject->fieldname, |
||||||
338 | 'columnnumber' => $userField->getId(), |
||||||
339 | 'lookupval' => $lookupvalues, |
||||||
340 | ]; |
||||||
341 | ++$numofcolumns; |
||||||
342 | unset($lookupvalues); |
||||||
343 | } |
||||||
344 | } |
||||||
345 | $columnvalue = []; |
||||||
346 | while (false !== ($rowres = $GLOBALS['xoopsDB']->fetchArray($queryresult))) { |
||||||
347 | if ('0' == $rowres['d_roft']) { |
||||||
348 | $gender = '<img src="assets/images/male.gif">'; |
||||||
349 | } else { |
||||||
350 | $gender = '<img src="assets/images/female.gif">'; |
||||||
351 | } |
||||||
352 | $name = \stripslashes($rowres['d_pname']); |
||||||
353 | //empty array |
||||||
354 | unset($columnvalue); |
||||||
355 | //fill array |
||||||
356 | for ($i = 1; $i < $numofcolumns; ++$i) { |
||||||
357 | $x = $columns[$i]['columnnumber']; |
||||||
358 | if (\is_array($columns[$i]['lookupval'])) { |
||||||
359 | foreach ($columns[$i]['lookupval'] as $key => $keyvalue) { |
||||||
360 | if ($keyvalue['id'] == $rowres['user' . $x]) { |
||||||
361 | $value = $keyvalue['value']; |
||||||
362 | } |
||||||
363 | } |
||||||
364 | //debug information |
||||||
365 | ///echo $columns[$i]['columnname']."is an array !"; |
||||||
366 | } //format value - cant use object because of query count |
||||||
367 | elseif (0 === \strncmp($rowres['user' . $x], 'http://', 7)) { |
||||||
368 | $value = '<a href="' . $rowres['user' . $x] . '">' . $rowres['user' . $x] . '</a>'; |
||||||
369 | } else { |
||||||
370 | $value = $rowres['user' . $x]; |
||||||
371 | } |
||||||
372 | $columnvalue[] = ['value' => $value]; |
||||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||||
373 | } |
||||||
374 | $columnvalue = isset($columnvalue) ? $columnvalue : null; |
||||||
375 | $dogs[] = [ |
||||||
376 | 'id' => $rowres['d_id'], |
||||||
377 | 'name' => $name, |
||||||
378 | 'gender' => $gender, |
||||||
379 | 'link' => '<a href="dog.php?id=' . $rowres['d_id'] . '">' . $name . '</a>', |
||||||
380 | 'colour' => '', |
||||||
381 | 'number' => '', |
||||||
382 | 'usercolumns' => $columnvalue, |
||||||
383 | ]; |
||||||
384 | } |
||||||
385 | |||||||
386 | return null; |
||||||
387 | } |
||||||
388 | |||||||
389 | /** |
||||||
390 | * @param $oid |
||||||
391 | * @param $pa |
||||||
392 | * @param $ma |
||||||
393 | * @return null |
||||||
394 | */ |
||||||
395 | public static function bas($oid, $pa, $ma) |
||||||
396 | { |
||||||
397 | global $numofcolumns1, $nummatch1, $pages1, $columns1, $dogs1; |
||||||
398 | if ('0' == $pa && '0' == $ma) { |
||||||
399 | $sqlquery = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . ' WHERE father = ' . $pa . ' AND mother = ' . $ma . ' AND id != ' . $oid . " AND father != '0' AND mother !='0' ORDER BY pname"; |
||||||
400 | } else { |
||||||
401 | $sqlquery = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . ' WHERE father = ' . $pa . ' AND mother = ' . $ma . ' AND id != ' . $oid . ' ORDER BY pname'; |
||||||
402 | } |
||||||
403 | $queryresult = $GLOBALS['xoopsDB']->query($sqlquery); |
||||||
404 | $nummatch1 = $GLOBALS['xoopsDB']->getRowsNum($queryresult); |
||||||
405 | |||||||
406 | $animal = new Pedigree\Animal(); |
||||||
407 | //test to find out how many user fields there are... |
||||||
408 | $fields = $animal->getNumOfFields(); |
||||||
409 | $numofcolumns1 = 1; |
||||||
410 | $columns1[] = ['columnname' => 'Name']; |
||||||
411 | foreach ($fields as $i => $iValue) { |
||||||
412 | $userField = new Pedigree\Field($fields[$i], $animal->getConfig()); |
||||||
413 | $fieldType = $userField->getSetting('fieldtype'); |
||||||
414 | $fieldObject = new $fieldType($userField, $animal); |
||||||
415 | //create empty string |
||||||
416 | $lookupvalues = ''; |
||||||
417 | if ($userField->isActive() && $userField->inList()) { |
||||||
418 | if ($userField->hasLookup()) { |
||||||
419 | $lookupvalues = $userField->lookupField($fields[$i]); |
||||||
420 | //debug information |
||||||
421 | //print_r($lookupvalues); |
||||||
422 | } |
||||||
423 | $columns1[] = [ |
||||||
424 | 'columnname' => $fieldObject->fieldname, |
||||||
425 | 'columnnumber' => $userField->getId(), |
||||||
426 | 'lookupval' => $lookupvalues, |
||||||
427 | ]; |
||||||
428 | ++$numofcolumns1; |
||||||
429 | unset($lookupvalues); |
||||||
430 | } |
||||||
431 | } |
||||||
432 | |||||||
433 | while (false !== ($rowres = $GLOBALS['xoopsDB']->fetchArray($queryresult))) { |
||||||
434 | if (0 == $rowres['roft']) { |
||||||
435 | $gender = "<img src='assets/images/male.gif'>"; |
||||||
436 | } else { |
||||||
437 | $gender = "<img src='assets/images/female.gif'>"; |
||||||
438 | } |
||||||
439 | $name = \stripslashes($rowres['pname']); |
||||||
440 | //empty array |
||||||
441 | // unset($columnvalue1); |
||||||
442 | $columnvalue1 = []; |
||||||
443 | //fill array |
||||||
444 | for ($i = 1; $i < $numofcolumns1; ++$i) { |
||||||
445 | $x = $columns1[$i]['columnnumber']; |
||||||
446 | if (\is_array($columns1[$i]['lookupval'])) { |
||||||
447 | foreach ($columns1[$i]['lookupval'] as $key => $keyvalue) { |
||||||
448 | if ($keyvalue['id'] == $rowres['user' . $x]) { |
||||||
449 | $value = $keyvalue['value']; |
||||||
450 | } |
||||||
451 | } |
||||||
452 | //debug information |
||||||
453 | ///echo $columns[$i]['columnname']."is an array !"; |
||||||
454 | } //format value - cant use object because of query count |
||||||
455 | elseif (0 === \strncmp($rowres['user' . $x], 'http://', 7)) { |
||||||
456 | $value = '<a href="' . $rowres['user' . $x] . '">' . $rowres['user' . $x] . '</a>'; |
||||||
457 | } else { |
||||||
458 | $value = $rowres['user' . $x]; |
||||||
459 | } |
||||||
460 | $columnvalue1[] = ['value' => $value]; |
||||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||||
461 | } |
||||||
462 | $dogs1[] = [ |
||||||
463 | 'id' => $rowres['id'], |
||||||
464 | 'name' => $name, |
||||||
465 | 'gender' => $gender, |
||||||
466 | 'link' => '<a href="dog.php?id=' . $rowres['id'] . '">' . $name . '</a>', |
||||||
467 | 'colour' => '', |
||||||
468 | 'number' => '', |
||||||
469 | 'usercolumns' => $columnvalue1, |
||||||
470 | ]; |
||||||
471 | } |
||||||
472 | |||||||
473 | return null; |
||||||
474 | } |
||||||
475 | |||||||
476 | /** |
||||||
477 | * @param int $oid owner/breder ID |
||||||
478 | * @param int $breeder Constants::IS_OWNER | Constants::IS_BREEDER |
||||||
479 | * |
||||||
480 | * @return string HTML code with image & link to animals owned |
||||||
481 | */ |
||||||
482 | public static function breederof($oid, $breeder) |
||||||
483 | { |
||||||
484 | $content = ''; |
||||||
485 | /** |
||||||
486 | * @var XoopsModules\Pedigree\Helper $helper |
||||||
487 | * @var XoopsModules\Pedigree\TreeHandler $treeHandler |
||||||
488 | */ |
||||||
489 | //@todo TEST refactor code below using Pedigree\Tree class CRUD methods |
||||||
490 | $helper = XoopsModules\Pedigree\Helper::getInstance(); |
||||||
491 | $treeHandler = $helper->getHandler('Tree'); |
||||||
492 | $fieldsArray = ['id', 'pname', 'roft']; |
||||||
493 | $dbField = (Constants::IS_OWNER == $breeder) ? 'id_owner' : 'id_breeder'; |
||||||
494 | $criteria = new \Criteria($dbField, (int)$oid); |
||||||
495 | $criteria->setSort('pname'); |
||||||
496 | $treeObjArray = $treeHandler->getAll($criteria, $fieldsArray); |
||||||
497 | foreach ($treeObjArray as $id => $treeObj) { |
||||||
498 | $gender = Constants::MALE == $treeObj->getVar('roft') ? "<img src=\"" . $helper->url("assets/images/male.gif") . "\" alt=\"" . $helper->getConfig('male') . "\' title=\"" . $helper->getConfig('male') . "\">" : "<img src=\"" |
||||||
499 | . $helper->url("assets/images/female.gif") |
||||||
500 | . "\" alt=\"" |
||||||
501 | . $helper->getConfig('female') |
||||||
502 | . "\' title=\"" |
||||||
503 | . $helper->getConfig('female') |
||||||
504 | . "\">"; |
||||||
505 | $link = "<a href=\"" . $helper->url("dog.php?id={$id}") . "\">" . $treeObj->getVar('pname') . "</a>"; |
||||||
506 | $content .= $gender . ' ' . $link . "<br>\n"; |
||||||
507 | } |
||||||
508 | /* |
||||||
509 | if (Constants::IS_OWNER == $breeder) { // get the owner |
||||||
510 | $sqlquery = 'SELECT id, pname, roft FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . " WHERE id_owner = '" . $oid . "' ORDER BY pname"; |
||||||
511 | } else { // get the breeder |
||||||
512 | $sqlquery = 'SELECT id, pname, roft FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . " WHERE id_breeder = '" . $oid . "' ORDER BY pname"; |
||||||
513 | } |
||||||
514 | $queryresult = $GLOBALS['xoopsDB']->query($sqlquery); |
||||||
515 | while (false !== ($rowres = $GLOBALS['xoopsDB']->fetchArray($queryresult))) { |
||||||
516 | //@todo add alt and title to <img> elements below... |
||||||
517 | if (Constants::MALE == $rowres['roft']) { |
||||||
518 | $gender = '<img src="assets/images/male.gif">'; |
||||||
519 | } else { |
||||||
520 | $gender = '<img src="assets/images/female.gif">'; |
||||||
521 | } |
||||||
522 | $link = '<a href="dog.php?id=' . $rowres['id'] . '">' . stripslashes($rowres['pname']) . '</a>'; |
||||||
523 | $content .= $gender . ' ' . $link . '<br>'; |
||||||
524 | } |
||||||
525 | */ |
||||||
526 | return $content; |
||||||
527 | } |
||||||
528 | |||||||
529 | /** |
||||||
530 | * @param int $oid |
||||||
531 | * |
||||||
532 | * @return string |
||||||
533 | */ |
||||||
534 | public static function getName($oid) |
||||||
535 | { |
||||||
536 | $oid = (int)$oid; |
||||||
537 | $an = ''; |
||||||
538 | $treeHandler = XoopsModules\Pedigree\Helper::getInstance()->getHandler('Tree'); |
||||||
539 | $treeObj = $treeHandler->get($oid); |
||||||
540 | if ($treeObj instanceof XoopsModules\Pedigree\Tree) { |
||||||
541 | $an = $treeObj->getVar('pname'); |
||||||
542 | } |
||||||
543 | /* |
||||||
544 | $sqlquery = 'SELECT pname FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . " WHERE id = '{$oid}'"; |
||||||
545 | $queryresult = $GLOBALS['xoopsDB']->query($sqlquery); |
||||||
546 | while (false !== ($rowres = $GLOBALS['xoopsDB']->fetchArray($queryresult))) { |
||||||
547 | $an = stripslashes($rowres['pname']); |
||||||
548 | } |
||||||
549 | */ |
||||||
550 | return $an; |
||||||
551 | } |
||||||
552 | |||||||
553 | /** |
||||||
554 | * Get the parent's name |
||||||
555 | * |
||||||
556 | * @param int $pId |
||||||
557 | * @return string parent's name or '' if not found |
||||||
558 | */ |
||||||
559 | public static function showParent($pId) |
||||||
560 | { |
||||||
561 | $parentName = ''; |
||||||
562 | $treeHandler = XoopsModules\Pedigree\Helper::getInstance()->getHandler('Tree'); |
||||||
563 | $parentObj = $treeHandler->get($pId); |
||||||
564 | if ($parentObj instanceof XoopsModules\Pedigree\Tree && !$parentObj->isNew()) { |
||||||
565 | $parentName = $parentObj->getVar('pname'); |
||||||
566 | } |
||||||
567 | /* |
||||||
568 | $sqlquery = 'SELECT pname FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . " WHERE id='" . (int)$pId . "'"; |
||||||
569 | $queryresult = $GLOBALS['xoopsDB']->query($sqlquery); |
||||||
570 | while (false !== ($rowres = $GLOBALS['xoopsDB']->fetchArray($queryresult))) { |
||||||
571 | $result = $rowres['pname']; |
||||||
572 | } |
||||||
573 | if (isset($result)) { |
||||||
574 | return $result; |
||||||
575 | } |
||||||
576 | |||||||
577 | return ''; |
||||||
578 | */ |
||||||
579 | return $parentName; |
||||||
580 | } |
||||||
581 | |||||||
582 | /** |
||||||
583 | * @param $pname_hond |
||||||
584 | * |
||||||
585 | * @return int id of 'pname' object |
||||||
586 | */ |
||||||
587 | public static function findId($pname_hond) |
||||||
588 | { |
||||||
589 | $id = 0; |
||||||
590 | $treeHandler = XoopsModules\Pedigree\Helper::getInstance()->getHandler('Tree'); |
||||||
591 | //@todo need to filter $pname_hond |
||||||
592 | $criteria = new \Criteria('pname', \mb_strtolower($pname_hond), '=', null, "lower(%s)"); |
||||||
593 | $criteria->setLimit(1); |
||||||
594 | $treeIdArray = $treeHandler->getIds($criteria); |
||||||
595 | if (0 !== \count($treeIdArray)) { |
||||||
596 | $id = (int)\key($treeObjArray); |
||||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||||
597 | } |
||||||
598 | return $id; |
||||||
599 | /* |
||||||
600 | $result = 0; |
||||||
601 | $sqlquery = 'SELECT id FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . " WHERE pname= '$pname_hond'"; |
||||||
602 | $queryresult = $GLOBALS['xoopsDB']->query($sqlquery); |
||||||
603 | while (false !== ($rowres = $GLOBALS['xoopsDB']->fetchArray($queryresult))) { |
||||||
604 | $result = $rowres['id']; |
||||||
605 | } |
||||||
606 | |||||||
607 | return $result; |
||||||
608 | */ |
||||||
609 | } |
||||||
610 | |||||||
611 | /** |
||||||
612 | * @param $result |
||||||
613 | * @param $prefix |
||||||
614 | * @param $link |
||||||
615 | * @param $element |
||||||
616 | */ |
||||||
617 | public static function createList($result, $prefix, $link, $element) |
||||||
618 | { |
||||||
619 | $helper = XoopsModules\Pedigree\Helper::getInstance(); |
||||||
620 | require_once $helper->path('include/common.php'); |
||||||
621 | |||||||
622 | $animal = new Pedigree\Animal(); |
||||||
623 | //test to find out how many user fields there are... |
||||||
624 | $fieldIdArray = $animal->getNumOfFields(); |
||||||
625 | $columns = []; //init columns array |
||||||
626 | $columns[] = ['columnname' => 'Name']; |
||||||
627 | foreach ($fieldIdArray as $i => $iValue) { |
||||||
628 | $userField = new Pedigree\Field($iValue, $animal->getConfig()); |
||||||
629 | $fieldType = $userField->getSetting('fieldtype'); |
||||||
630 | $fieldObject = new $fieldType($userField, $animal); |
||||||
631 | if ($userField->isActive() && $userField->inList()) { |
||||||
632 | if ($userField->hasLookup()) { |
||||||
633 | $id = $userField->getId(); |
||||||
634 | $q = $userField->lookupField($id); |
||||||
635 | } else { |
||||||
636 | $q = ''; |
||||||
637 | } |
||||||
638 | $columns[] = [ |
||||||
639 | 'columnname' => $fieldObject->fieldname, |
||||||
640 | 'columnnumber' => $userField->getId(), |
||||||
641 | 'lookuparray' => $q, |
||||||
642 | ]; |
||||||
643 | } |
||||||
644 | } |
||||||
645 | |||||||
646 | //add preliminary row to array if passed |
||||||
647 | if (\is_array($prefix)) { |
||||||
648 | $dogs[] = $prefix; |
||||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||||
649 | } |
||||||
650 | |||||||
651 | while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||||||
652 | //reset $gender |
||||||
653 | $gender = ''; |
||||||
654 | if ($helper->isUserAdmin() |
||||||
655 | || $GLOBALS['xoopsUser'] instanceof \XoopsUser |
||||||
656 | && (($row['user'] == $GLOBALS['xoopsUser']->getVar('uid') || true === $modadmin))) { |
||||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||||
657 | $gender = "<a href=\"" . $helper->url("dog.php?id={$row['id']}") . "\">{$icons['edit']}</a> |
||||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||||
658 | . <a href=\"" . $helper->url("delete.php?id={$row['id']}") . "\">{$icons['delete']}</a>\n"; |
||||||
659 | } |
||||||
660 | |||||||
661 | $genImg = (Constants::MALE == $row['roft']) ? 'male.gif' : 'female.gif'; |
||||||
662 | $gender .= "<img src=\"" . $helper->url("assets/images/{$genImg}") . "\" alt=\"" . $helper->getConfig('male') . "\" title=\"" . $helper->getConfig('female') . "\">"; |
||||||
663 | |||||||
664 | if ('' != $row['foto']) { |
||||||
665 | //@todo - figure out what dog-icon25.png is, it currently doesn't exist : also need to add alt title tags |
||||||
666 | $camera = " <img src=\"" . $helper->url("assets/images/dog-icon25.png") . "\">"; |
||||||
667 | } else { |
||||||
668 | $camera = ''; |
||||||
669 | } |
||||||
670 | $name = \stripslashes($row['pname']) . $camera; |
||||||
671 | unset($columnvalue); |
||||||
672 | |||||||
673 | //fill array |
||||||
674 | $columnCount = \count($columns); |
||||||
675 | $columnvalue = []; // init |
||||||
676 | foreach ($columns as $thisColumn) { |
||||||
677 | $value = ''; // init |
||||||
678 | $x = $thisColumn['columnnumber']; |
||||||
679 | $lookupArray = $thisColumn['lookuparray']; |
||||||
680 | if (\is_array($lookupArray)) { |
||||||
681 | foreach ($lookupArray as $key => $value) { |
||||||
682 | if ($value['id'] == $row['user' . $x]) { |
||||||
683 | $value = $value['value']; |
||||||
684 | } |
||||||
685 | } |
||||||
686 | //@todo need to refactor using preg_match to allow for http[s] |
||||||
687 | } elseif (0 === \strncmp($row["user{$x}"], 'http://', 7)) { //format value - can't use object because of query count |
||||||
688 | $value = "<a href=\"" . $row["user{$x}"] . "\">" . $row["user{$x}"] . "</a>\n"; |
||||||
689 | } else { |
||||||
690 | $value = $row["user{$x}"]; |
||||||
691 | } |
||||||
692 | $columnvalue[] = ['value' => $value]; |
||||||
693 | unset($value); |
||||||
694 | } |
||||||
695 | |||||||
696 | /* |
||||||
697 | //fill array |
||||||
698 | $columnCount = count($columns); |
||||||
699 | for ($i = 1; $i < $columnCount; ++$i) { |
||||||
700 | $x = $columns[$i]['columnnumber']; |
||||||
701 | $lookuparray = $columns[$i]['lookuparray']; |
||||||
702 | if (is_array($lookuparray)) { |
||||||
703 | foreach ($lookuparray as $index => $indexValue) { |
||||||
704 | if ($lookuparray[$index]['id'] == $row['user' . $x]) { |
||||||
705 | //echo "<h1>".$lookuparray[$index]['id']."</h1>"; |
||||||
706 | $value = $lookuparray[$index]['value']; |
||||||
707 | } |
||||||
708 | } |
||||||
709 | } //format value - can't use object because of query count |
||||||
710 | elseif (0 === strncmp($row['user' . $x], 'http://', 7)) { |
||||||
711 | $value = '<a href="' . $row['user' . $x] . '">' . $row['user' . $x] . '</a>'; |
||||||
712 | } else { |
||||||
713 | $value = $row['user' . $x]; |
||||||
714 | } |
||||||
715 | $columnvalue[] = ['value' => $value]; |
||||||
716 | unset($value); |
||||||
717 | } |
||||||
718 | */ |
||||||
719 | //create array |
||||||
720 | $dogs[] = [ |
||||||
721 | 'id' => $row['id'], |
||||||
722 | 'name' => $name, |
||||||
723 | 'gender' => $gender, |
||||||
724 | 'link' => "<a href=\"{$link}{$row[$element]}\">{$name}</a>\n", |
||||||
725 | 'colour' => '', |
||||||
726 | 'number' => '', |
||||||
727 | 'usercolumns' => $columnvalue, |
||||||
728 | ]; |
||||||
729 | } |
||||||
730 | |||||||
731 | //add data to smarty template |
||||||
732 | //assign dog |
||||||
733 | $GLOBALS['xoopsTpl']->assign([ |
||||||
734 | 'dogs' => $dogs, |
||||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||||
735 | 'columns' => $columns, |
||||||
736 | 'numofcolumns' => $columnCount, |
||||||
737 | 'tsarray' => self::sortTable($columnCount), |
||||||
738 | ]); |
||||||
739 | } |
||||||
740 | |||||||
741 | /***************Blocks************** |
||||||
742 | * |
||||||
743 | * @param array|string $cats |
||||||
744 | * |
||||||
745 | * @return string (cat1, cat2, cat3, etc) for SQL statement |
||||||
746 | * @deprecated - NOT USED |
||||||
747 | */ |
||||||
748 | public static function animal_block_addCatSelect($cats) |
||||||
749 | { |
||||||
750 | $cat_sql = ''; |
||||||
751 | if (\is_array($cats)) { |
||||||
752 | $cats = \array_map('\intval', $cats); // make sure all cats are numbers |
||||||
753 | $cat_sql = '(' . \implode(',', $cats) . ')'; |
||||||
754 | /* |
||||||
755 | $cat_sql = '(' . current($cats); |
||||||
756 | array_shift($cats); |
||||||
757 | foreach ($cats as $cat) { |
||||||
758 | $cat_sql .= ',' . $cat; |
||||||
759 | } |
||||||
760 | $cat_sql .= ')'; |
||||||
761 | */ |
||||||
762 | } else { |
||||||
763 | $cat_sql = '(' . (int)$cats . ')'; // not efficient but at least creates valid SQL statement |
||||||
764 | } |
||||||
765 | |||||||
766 | return $cat_sql; |
||||||
767 | } |
||||||
768 | |||||||
769 | /** |
||||||
770 | * @param $global |
||||||
771 | * @param $key |
||||||
772 | * @param string $default |
||||||
773 | * @param string $type |
||||||
774 | * |
||||||
775 | * @return mixed|string |
||||||
776 | * @deprecated |
||||||
777 | */ |
||||||
778 | public static function animal_CleanVars(&$global, $key, $default = '', $type = 'int') |
||||||
779 | { |
||||||
780 | switch ($type) { |
||||||
781 | case 'string': |
||||||
782 | $ret = isset($global[$key]) ? \filter_var($global[$key], \FILTER_SANITIZE_MAGIC_QUOTES) : $default; |
||||||
0 ignored issues
–
show
The constant
FILTER_SANITIZE_MAGIC_QUOTES has been deprecated: 7.4
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
783 | break; |
||||||
784 | case 'int': |
||||||
785 | default: |
||||||
786 | $ret = isset($global[$key]) ? \filter_var($global[$key], \FILTER_SANITIZE_NUMBER_INT) : $default; |
||||||
787 | break; |
||||||
788 | } |
||||||
789 | if (false === $ret) { |
||||||
790 | return $default; |
||||||
791 | } |
||||||
792 | |||||||
793 | return $ret; |
||||||
794 | } |
||||||
795 | |||||||
796 | /** |
||||||
797 | * @param $content |
||||||
798 | * @deprecated - NOT USED |
||||||
799 | */ |
||||||
800 | public static function animal_meta_keywords($content) |
||||||
801 | { |
||||||
802 | global $xoTheme; |
||||||
803 | $myts = \MyTextSanitizer::getInstance(); |
||||||
804 | $content = $myts->undoHtmlSpecialChars($myts->displayTarea($content)); |
||||||
805 | if (isset($xoTheme) && \is_object($xoTheme)) { |
||||||
806 | $xoTheme->addMeta('meta', 'keywords', \strip_tags($content)); |
||||||
807 | } else { // Compatibility for old Xoops versions |
||||||
808 | $GLOBALS['xoopsTpl']->assign('xoops_meta_keywords', \strip_tags($content)); |
||||||
809 | } |
||||||
810 | } |
||||||
811 | |||||||
812 | /** |
||||||
813 | * @param $content |
||||||
814 | * @deprecated - NOT USED |
||||||
815 | */ |
||||||
816 | public static function animal_meta_description($content) |
||||||
817 | { |
||||||
818 | global $xoTheme; |
||||||
819 | $myts = \MyTextSanitizer::getInstance(); |
||||||
820 | $content = $myts->undoHtmlSpecialChars($myts->displayTarea($content)); |
||||||
821 | if (isset($xoTheme) && \is_object($xoTheme)) { |
||||||
822 | $xoTheme->addMeta('meta', 'description', \strip_tags($content)); |
||||||
823 | } else { // Compatibility for old Xoops versions |
||||||
824 | $GLOBALS['xoopsTpl']->assign('xoops_meta_description', \strip_tags($content)); |
||||||
825 | } |
||||||
826 | } |
||||||
827 | |||||||
828 | /** |
||||||
829 | * Verify that a mysql table exists |
||||||
830 | * |
||||||
831 | * @param mixed $myObject |
||||||
832 | * @param mixed $activeObject |
||||||
833 | * @param mixed $criteria |
||||||
834 | * @param mixed $name |
||||||
835 | * @param mixed $link |
||||||
836 | * @param null|mixed $link2 |
||||||
837 | * @package pedigree |
||||||
838 | * @author Hervé Thouzard (http://www.herve-thouzard.com) |
||||||
839 | * @copyright (c) Hervé Thouzard |
||||||
840 | */ |
||||||
841 | //function tableExists($tablename) |
||||||
842 | //{ |
||||||
843 | // |
||||||
844 | // $result=$GLOBALS['xoopsDB']->queryF("SHOW TABLES LIKE '$tablename'"); |
||||||
845 | // return($GLOBALS['xoopsDB']->getRowsNum($result) > 0); |
||||||
846 | //} |
||||||
847 | |||||||
848 | /** |
||||||
849 | * Create download by letter choice bar/menu |
||||||
850 | * updated starting from this idea https://xoops.org/modules/news/article.php?storyid=6497 |
||||||
851 | * |
||||||
852 | * @param Pedigree\Helper $myObject |
||||||
0 ignored issues
–
show
The type
XoopsModules\Pedigree\Pedigree\Helper was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||||
853 | * @param $activeObject |
||||||
854 | * @param $criteria |
||||||
855 | * @param $name |
||||||
856 | * @param $link |
||||||
857 | * @param null $link2 |
||||||
0 ignored issues
–
show
|
|||||||
858 | * @return string html |
||||||
859 | * |
||||||
860 | * @internal param $file |
||||||
861 | * @internal param $file2 |
||||||
862 | * @access public |
||||||
863 | * @author luciorota |
||||||
864 | */ |
||||||
865 | public static function lettersChoice($myObject, $activeObject, $criteria, $name, $link, $link2 = null) |
||||||
866 | { |
||||||
867 | /** @var \XoopsModules\Pedigree\Helper $helper */ |
||||||
868 | $helper = Helper::getInstance(); |
||||||
869 | $helper->loadLanguage('main'); |
||||||
870 | \xoops_load('XoopsLocal'); |
||||||
871 | /* |
||||||
872 | |||||||
873 | $criteria = $helper->getHandler('tree')->getActiveCriteria(); |
||||||
874 | $criteria->setGroupby('UPPER(LEFT(pname,1))'); |
||||||
875 | $countsByLetters = $helper->getHandler('tree')->getCounts($criteria); |
||||||
876 | // Fill alphabet array |
||||||
877 | $alphabet = XoopsLocal::getAlphabet(); |
||||||
878 | $alphabet_array = array(); |
||||||
879 | foreach ($alphabet as $letter) { |
||||||
880 | $letter_array = array(); |
||||||
881 | if (isset($countsByLetters[$letter])) { |
||||||
882 | $letter_array['letter'] = $letter; |
||||||
883 | $letter_array['count'] = $countsByLetters[$letter]; |
||||||
884 | // $letter_array['url'] = "" . XOOPS_URL . "/modules/" . $helper->getModule()->dirname() . "/viewcat.php?list={$letter}"; |
||||||
885 | $letter_array['url'] = '' . XOOPS_URL . '/modules/' . $helper->getModule()->dirname() . "/result.php?f=pname&l=1&w={$letter}%25&o=pname"; |
||||||
886 | } else { |
||||||
887 | $letter_array['letter'] = $letter; |
||||||
888 | $letter_array['count'] = 0; |
||||||
889 | $letter_array['url'] = ''; |
||||||
890 | } |
||||||
891 | $alphabet_array[$letter] = $letter_array; |
||||||
892 | unset($letter_array); |
||||||
893 | } |
||||||
894 | // Render output |
||||||
895 | if (!isset($GLOBALS['xoTheme']) || !is_object($GLOBALS['xoTheme'])) { |
||||||
896 | require_once $GLOBALS['xoops']->path('class/theme.php'); |
||||||
897 | $GLOBALS['xoTheme'] = new \xos_opal_Theme(); |
||||||
898 | } |
||||||
899 | require_once $GLOBALS['xoops']->path('class/template.php'); |
||||||
900 | $letterschoiceTpl = new \XoopsTpl(); |
||||||
901 | $letterschoiceTpl->caching = false; // Disable cache |
||||||
902 | $letterschoiceTpl->assign('alphabet', $alphabet_array); |
||||||
903 | $html = $letterschoiceTpl->fetch('db:' . $helper->getModule()->dirname() . '_common_letterschoice.tpl'); |
||||||
904 | unset($letterschoiceTpl); |
||||||
905 | return $html; |
||||||
906 | */ |
||||||
907 | |||||||
908 | // $pedigree = Helper::getInstance(); |
||||||
909 | // xoops_load('XoopsLocal'); |
||||||
910 | |||||||
911 | // $criteria = $myObject->getHandler($activeObject)->getActiveCriteria(); |
||||||
912 | $criteria->setGroupby('UPPER(LEFT(' . $name . ',1))'); |
||||||
913 | $countsByLetters = $myObject->getHandler($activeObject)->getCounts($criteria); |
||||||
914 | // Fill alphabet array |
||||||
915 | |||||||
916 | //@todo getAlphabet method doesn't exist anywhere |
||||||
917 | //$alphabet = XoopsLocal::getAlphabet(); |
||||||
918 | |||||||
919 | // xoops_load('XoopsLocal'); |
||||||
920 | // $xLocale = new \XoopsLocal; |
||||||
921 | // $alphabet = $xLocale->getAlphabet(); |
||||||
922 | $alphabet = \explode(',', _MA_PEDIGREE_LTRCHARS); |
||||||
923 | //$alphabet = pedigreeGetAlphabet(); |
||||||
924 | $alphabet_array = []; |
||||||
925 | foreach ($alphabet as $letter) { |
||||||
926 | /* |
||||||
927 | if (isset($countsByLetters[$letter])) { |
||||||
928 | $letter_array['letter'] = $letter; |
||||||
929 | $letter_array['count'] = $countsByLetters[$letter]; |
||||||
930 | // $letter_array['url'] = "" . XOOPS_URL . "/modules/" . $helper->getModule()->dirname() . "/viewcat.php?list={$letter}"; |
||||||
931 | // $letter_array['url'] = '' . XOOPS_URL . '/modules/' . $myObject->getModule()->dirname() . '/'.$file.'?f='.$name."&l=1&w={$letter}%25&o=".$name; |
||||||
932 | $letter_array['url'] = '' . XOOPS_URL . '/modules/' . $myObject->getModule()->dirname() . '/' . $file2; |
||||||
933 | } else { |
||||||
934 | $letter_array['letter'] = $letter; |
||||||
935 | $letter_array['count'] = 0; |
||||||
936 | $letter_array['url'] = ''; |
||||||
937 | } |
||||||
938 | $alphabet_array[$letter] = $letter_array; |
||||||
939 | unset($letter_array); |
||||||
940 | } |
||||||
941 | |||||||
942 | |||||||
943 | $alphabet_array = array(); |
||||||
944 | // foreach ($alphabet as $letter) { |
||||||
945 | foreach (range('A', 'Z') as $letter) { |
||||||
946 | */ |
||||||
947 | $letter_array = []; |
||||||
948 | if (isset($countsByLetters[$letter])) { |
||||||
949 | $letter_array['letter'] = $letter; |
||||||
950 | $letter_array['count'] = $countsByLetters[$letter]; |
||||||
951 | // $letter_array['url'] = "" . XOOPS_URL . "/modules/" . $helper->getModule()->dirname() . "/viewcat.php?list={$letter}"; |
||||||
952 | // $letter_array['url'] = '' . XOOPS_URL . '/modules/' . $myObject->getModule()->dirname() . '/'.$file.'?f='.$name."&l=1&w={$letter}%25&o=".$name; |
||||||
953 | $letter_array['url'] = '' . XOOPS_URL . '/modules/' . $myObject->getModule()->dirname() . '/' . $link . $letter . $link2; |
||||||
954 | } else { |
||||||
955 | $letter_array['letter'] = $letter; |
||||||
956 | $letter_array['count'] = 0; |
||||||
957 | $letter_array['url'] = ''; |
||||||
958 | } |
||||||
959 | $alphabet_array[$letter] = $letter_array; |
||||||
960 | unset($letter_array); |
||||||
961 | } |
||||||
962 | |||||||
963 | // Render output |
||||||
964 | if (!isset($GLOBALS['xoTheme']) || !\is_object($GLOBALS['xoTheme'])) { |
||||||
965 | require_once $GLOBALS['xoops']->path('class/theme.php'); |
||||||
966 | $GLOBALS['xoTheme'] = new \xos_opal_Theme(); |
||||||
967 | } |
||||||
968 | require_once $GLOBALS['xoops']->path('class/template.php'); |
||||||
969 | $letterschoiceTpl = new \XoopsTpl(); |
||||||
970 | $letterschoiceTpl->caching = false; // Disable cache |
||||||
0 ignored issues
–
show
The property
$caching was declared of type integer , but false is of type false . Maybe add a type cast?
This check looks for assignments to scalar types that may be of the wrong type. To ensure the code behaves as expected, it may be a good idea to add an explicit type cast. $answer = 42;
$correct = false;
$correct = (bool) $answer;
![]() |
|||||||
971 | $letterschoiceTpl->assign('alphabet', $alphabet_array); |
||||||
972 | $html = $letterschoiceTpl->fetch('db:' . $myObject->getModule()->dirname() . '_common_letterschoice.tpl'); |
||||||
973 | unset($letterschoiceTpl); |
||||||
974 | |||||||
975 | return $html; |
||||||
976 | } |
||||||
977 | |||||||
978 | /** |
||||||
979 | * Alias for Pedigree\Helper->isUserAdmin |
||||||
980 | * |
||||||
981 | * Makes sure \XoopsModules\Pedigree\Helper class is loaded |
||||||
982 | * |
||||||
983 | * @return bool true if user is admin, false if not |
||||||
984 | */ |
||||||
985 | public static function isUserAdmin() |
||||||
986 | { |
||||||
987 | /** @var \XoopsModules\Pedigree\Helper $helper */ |
||||||
988 | $helper = Helper::getInstance(); |
||||||
989 | |||||||
990 | return $helper->isUserAdmin(); |
||||||
991 | } |
||||||
992 | |||||||
993 | /** |
||||||
994 | * Get the current colour scheme |
||||||
995 | * |
||||||
996 | * @return array colours for current colour scheme |
||||||
997 | */ |
||||||
998 | public static function getColourScheme() |
||||||
999 | { |
||||||
1000 | $helper = Helper::getInstance(); |
||||||
1001 | $colValues = $helper->getConfig('colourscheme'); |
||||||
1002 | $patterns = ['\s', '\,']; |
||||||
1003 | $replacements = ['', ';']; |
||||||
1004 | $colValues = \preg_replace($patterns, $replacements, $colValues); // remove spaces and commas - backward compatibility |
||||||
1005 | $colors = \explode(';', $colValues); |
||||||
1006 | |||||||
1007 | return $colors; |
||||||
1008 | } |
||||||
1009 | |||||||
1010 | /** |
||||||
1011 | * Detemines if a table exists in the current db |
||||||
1012 | * |
||||||
1013 | * @param string $table the table name (without XOOPS prefix) |
||||||
1014 | * |
||||||
1015 | * @return bool True if table exists, false if not |
||||||
1016 | * |
||||||
1017 | * @access public |
||||||
1018 | * @author xhelp development team |
||||||
1019 | */ |
||||||
1020 | public static function hasTable($table) |
||||||
1021 | { |
||||||
1022 | $bRetVal = false; |
||||||
1023 | //Verifies that a MySQL table exists |
||||||
1024 | $GLOBALS['xoopsDB'] = \XoopsDatabaseFactory::getDatabaseConnection(); |
||||||
1025 | $realName = $GLOBALS['xoopsDB']->prefix($table); |
||||||
1026 | |||||||
1027 | $sql = 'SHOW TABLES FROM ' . XOOPS_DB_NAME; |
||||||
1028 | $ret = $GLOBALS['xoopsDB']->queryF($sql); |
||||||
1029 | |||||||
1030 | while (false !== (list($m_table) = $GLOBALS['xoopsDB']->fetchRow($ret))) { |
||||||
1031 | if ($m_table == $realName) { |
||||||
1032 | $bRetVal = true; |
||||||
1033 | break; |
||||||
1034 | } |
||||||
1035 | } |
||||||
1036 | $GLOBALS['xoopsDB']->freeRecordSet($ret); |
||||||
1037 | |||||||
1038 | return $bRetVal; |
||||||
1039 | } |
||||||
1040 | |||||||
1041 | /** |
||||||
1042 | * Gets a value from a key in the xhelp_meta table |
||||||
1043 | * |
||||||
1044 | * @param string $key |
||||||
1045 | * |
||||||
1046 | * @return string $value |
||||||
1047 | * |
||||||
1048 | * @access public |
||||||
1049 | * @author xhelp development team |
||||||
1050 | */ |
||||||
1051 | public static function getMeta($key) |
||||||
1052 | { |
||||||
1053 | $GLOBALS['xoopsDB'] = \XoopsDatabaseFactory::getDatabaseConnection(); |
||||||
1054 | $sql = \sprintf('SELECT metavalue FROM `%s` WHERE metakey= `%s` ', $GLOBALS['xoopsDB']->prefix('pedigree_meta'), $GLOBALS['xoopsDB']->quoteString($key)); |
||||||
1055 | $ret = $GLOBALS['xoopsDB']->query($sql); |
||||||
1056 | if (!$ret) { |
||||||
1057 | $value = false; |
||||||
1058 | } else { |
||||||
1059 | [$value] = $GLOBALS['xoopsDB']->fetchRow($ret); |
||||||
1060 | } |
||||||
1061 | |||||||
1062 | return $value; |
||||||
1063 | } |
||||||
1064 | |||||||
1065 | /** |
||||||
1066 | * Sets a value for a key in the xhelp_meta table |
||||||
1067 | * |
||||||
1068 | * @param string $key |
||||||
1069 | * @param string $value |
||||||
1070 | * |
||||||
1071 | * @return bool true if success, false if failure |
||||||
1072 | * |
||||||
1073 | * @access public |
||||||
1074 | * @author xhelp development team |
||||||
1075 | */ |
||||||
1076 | public static function setMeta($key, $value) |
||||||
1077 | { |
||||||
1078 | $GLOBALS['xoopsDB'] = \XoopsDatabaseFactory::getDatabaseConnection(); |
||||||
1079 | if (false !== ($ret = self::getMeta($key))) { |
||||||
0 ignored issues
–
show
|
|||||||
1080 | $sql = \sprintf('UPDATE `%s` SET metavalue = `%s` WHERE metakey = `%s` ', $GLOBALS['xoopsDB']->prefix('pedigree_meta'), $GLOBALS['xoopsDB']->quoteString($value), $GLOBALS['xoopsDB']->quoteString($key)); |
||||||
1081 | } else { |
||||||
1082 | $sql = \sprintf('INSERT INTO `%s` (metakey, metavalue) VALUES (`%s`, `%s` )', $GLOBALS['xoopsDB']->prefix('pedigree_meta'), $GLOBALS['xoopsDB']->quoteString($key), $GLOBALS['xoopsDB']->quoteString($value)); |
||||||
1083 | } |
||||||
1084 | $ret = $GLOBALS['xoopsDB']->queryF($sql); |
||||||
1085 | if (!$ret) { |
||||||
1086 | return false; |
||||||
1087 | } |
||||||
1088 | |||||||
1089 | return true; |
||||||
1090 | } |
||||||
1091 | |||||||
1092 | /** |
||||||
1093 | * @param $name |
||||||
1094 | * @param $value |
||||||
1095 | * @param int $time |
||||||
1096 | */ |
||||||
1097 | public static function setCookieVar($name, $value, $time = 0) |
||||||
1098 | { |
||||||
1099 | if (0 == $time) { |
||||||
1100 | $time = \time() + 3600 * 24 * 365; |
||||||
1101 | } |
||||||
1102 | setcookie($name, $value, $time, '/', \ini_get('session.cookie_domain'), \ini_get('session.cookie_secure'), \ini_get('session.cookie_httponly')); |
||||||
0 ignored issues
–
show
ini_get('session.cookie_secure') of type string is incompatible with the type boolean expected by parameter $secure of setcookie() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() ini_get('session.cookie_httponly') of type string is incompatible with the type boolean expected by parameter $httponly of setcookie() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
1103 | } |
||||||
1104 | |||||||
1105 | /** |
||||||
1106 | * @param $name |
||||||
1107 | * @param string $default |
||||||
1108 | * |
||||||
1109 | * @return string |
||||||
1110 | */ |
||||||
1111 | public static function getCookieVar($name, $default = '') |
||||||
1112 | { |
||||||
1113 | if (isset($_COOKIE[$name]) && ($_COOKIE[$name] > '')) { |
||||||
1114 | return $_COOKIE[$name]; |
||||||
1115 | } |
||||||
1116 | |||||||
1117 | return $default; |
||||||
1118 | } |
||||||
1119 | |||||||
1120 | /** |
||||||
1121 | * @return array |
||||||
1122 | */ |
||||||
1123 | public static function getCurrentUrls() |
||||||
1124 | { |
||||||
1125 | $http = (false === \mb_strpos(XOOPS_URL, 'https://')) ? 'http://' : 'https://'; |
||||||
1126 | $phpSelf = $_SERVER['SCRIPT_NAME']; |
||||||
1127 | $httpHost = $_SERVER['HTTP_HOST']; |
||||||
1128 | $sql = $_SERVER['QUERY_STRING']; |
||||||
1129 | |||||||
1130 | if ('' != $sql) { |
||||||
1131 | $sql = '?' . $sql; |
||||||
1132 | } |
||||||
1133 | |||||||
1134 | $currentURL = $http . $httpHost . $phpSelf . $sql; |
||||||
1135 | |||||||
1136 | $urls = []; |
||||||
1137 | $urls['http'] = $http; |
||||||
1138 | $urls['httphost'] = $httpHost; |
||||||
1139 | $urls['phpself'] = $phpSelf; |
||||||
1140 | $urls['querystring'] = $sql; |
||||||
1141 | $urls['full'] = $currentURL; |
||||||
1142 | |||||||
1143 | return $urls; |
||||||
1144 | } |
||||||
1145 | |||||||
1146 | /** |
||||||
1147 | * @return mixed |
||||||
1148 | */ |
||||||
1149 | public static function getCurrentPage() |
||||||
1150 | { |
||||||
1151 | $urls = self::getCurrentUrls(); |
||||||
1152 | |||||||
1153 | return $urls['full']; |
||||||
1154 | } |
||||||
1155 | |||||||
1156 | /** |
||||||
1157 | * @param array $errors |
||||||
1158 | * |
||||||
1159 | * @return string |
||||||
1160 | */ |
||||||
1161 | public static function formatErrors($errors = []) |
||||||
1162 | { |
||||||
1163 | $ret = ''; |
||||||
1164 | foreach ($errors as $key => $value) { |
||||||
1165 | $ret .= "<br> - {$value}"; |
||||||
1166 | } |
||||||
1167 | |||||||
1168 | return $ret; |
||||||
1169 | } |
||||||
1170 | |||||||
1171 | /** |
||||||
1172 | * @param $tableName |
||||||
1173 | * @param $columnName |
||||||
1174 | * |
||||||
1175 | * @return array |
||||||
1176 | */ |
||||||
1177 | public static function enumerate($tableName, $columnName) |
||||||
1178 | { |
||||||
1179 | $table = $GLOBALS['xoopsDB']->prefix($tableName); |
||||||
1180 | |||||||
1181 | // $result = $GLOBALS['xoopsDB']->query("SELECT COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS |
||||||
1182 | // WHERE TABLE_NAME = '" . $table . "' AND COLUMN_NAME = '" . $columnName . "'") |
||||||
1183 | // || exit ($GLOBALS['xoopsDB']->error()); |
||||||
1184 | |||||||
1185 | $sql = 'SELECT COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = "' . $table . '" AND COLUMN_NAME = "' . $columnName . '"'; |
||||||
1186 | $result = $GLOBALS['xoopsDB']->query($sql); |
||||||
1187 | if (!$result) { |
||||||
1188 | exit($GLOBALS['xoopsDB']->error()); |
||||||
0 ignored issues
–
show
|
|||||||
1189 | } |
||||||
1190 | |||||||
1191 | $row = $GLOBALS['xoopsDB']->fetchBoth($result); |
||||||
1192 | $enumList = \explode(',', \str_replace("'", '', \mb_substr($row['COLUMN_TYPE'], 5, -6))); |
||||||
1193 | |||||||
1194 | return $enumList; |
||||||
1195 | } |
||||||
1196 | } |
||||||
1197 |