| Total Complexity | 121 |
| Total Lines | 997 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like Utility often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Utility, and based on these observations, apply Extract Interface, too.
| 1 | <?php namespace XoopsModules\Pedigree; |
||
| 8 | class Utility |
||
| 9 | { |
||
| 10 | |||
| 11 | /** |
||
| 12 | * Function responsible for checking if a directory exists, we can also write in and create an index.html file |
||
| 13 | * |
||
| 14 | * @param string $folder The full path of the directory to check |
||
| 15 | * |
||
| 16 | * @return void |
||
| 17 | */ |
||
| 18 | public static function prepareFolder($folder) |
||
| 19 | { |
||
| 20 | // $filteredFolder = XoopsFilterInput::clean($folder, 'PATH'); |
||
| 21 | if (!is_dir($folder)) { |
||
| 22 | mkdir($folder); |
||
| 23 | file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>'); |
||
| 24 | } |
||
| 25 | // chmod($filteredFolder, 0777); |
||
| 26 | } |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @param $columncount |
||
| 30 | * |
||
| 31 | * @return string |
||
| 32 | */ |
||
| 33 | public static function sortTable($columncount) |
||
| 34 | { |
||
| 35 | $ttemp = ''; |
||
| 36 | if ($columncount > 1) { |
||
| 37 | for ($t = 1; $t < $columncount; ++$t) { |
||
| 38 | $ttemp .= "'S',"; |
||
| 39 | } |
||
| 40 | $tsarray = "initSortTable('Result', Array({$ttemp}'S'));"; |
||
| 41 | } else { |
||
| 42 | $tsarray = "initSortTable('Result',Array('S'));"; |
||
| 43 | } |
||
| 44 | |||
| 45 | return $tsarray; |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @param $num |
||
| 50 | * |
||
| 51 | * @return string |
||
| 52 | */ |
||
| 53 | public static function uploadPicture($num) |
||
| 54 | { |
||
| 55 | $max_imgsize = $GLOBALS['xoopsModuleConfig']['maxfilesize']; //1024000; |
||
| 56 | $max_imgwidth = $GLOBALS['xoopsModuleConfig']['maximgwidth']; //1500; |
||
| 57 | $max_imgheight = $GLOBALS['xoopsModuleConfig']['maximgheight']; //1000; |
||
| 58 | $allowed_mimetypes = ['image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png']; |
||
| 59 | // $img_dir = XOOPS_ROOT_PATH . "/modules/" . $GLOBALS['xoopsModule']->dirname() . "/images" ; |
||
| 60 | $img_dir = $GLOBALS['xoopsModuleConfig']['uploaddir'] . '/images'; |
||
| 61 | require_once $GLOBALS['xoops']->path('class/uploader.php'); |
||
| 62 | $field = $_POST['xoops_upload_file'][$num]; |
||
| 63 | if (!empty($field) || '' != $field) { |
||
| 64 | $uploader = new \XoopsMediaUploader($img_dir, $allowed_mimetypes, $max_imgsize, $max_imgwidth, $max_imgheight); |
||
|
|
|||
| 65 | $uploader->setPrefix('img'); |
||
| 66 | if ($uploader->fetchMedia($field) && $uploader->upload()) { |
||
| 67 | $photo = $uploader->getSavedFileName(); |
||
| 68 | } else { |
||
| 69 | echo $uploader->getErrors(); |
||
| 70 | } |
||
| 71 | static::createThumbs($photo); |
||
| 72 | |||
| 73 | return $photo; |
||
| 74 | } |
||
| 75 | } |
||
| 76 | |||
| 77 | /** |
||
| 78 | * @param $filename |
||
| 79 | * |
||
| 80 | * @return void |
||
| 81 | */ |
||
| 82 | public static function createThumbs($filename) |
||
| 197 | } |
||
| 198 | |||
| 199 | /** |
||
| 200 | * @param $string |
||
| 201 | * |
||
| 202 | * @return string |
||
| 203 | */ |
||
| 204 | public static function unHtmlEntities($string) |
||
| 205 | { |
||
| 206 | $trans_tbl = get_html_translation_table(HTML_ENTITIES); |
||
| 207 | $trans_tbl = array_flip($trans_tbl); |
||
| 208 | |||
| 209 | return strtr($string, $trans_tbl); |
||
| 210 | } |
||
| 211 | |||
| 212 | /** |
||
| 213 | * @param $oid |
||
| 214 | * @param $gender |
||
| 215 | * |
||
| 216 | * @return null |
||
| 217 | */ |
||
| 218 | public static function pups($oid, $gender) |
||
| 219 | { |
||
| 220 | global $numofcolumns, $nummatch, $pages, $columns, $dogs; |
||
| 221 | $content = ''; |
||
| 222 | |||
| 223 | if (0 == $gender) { |
||
| 224 | $sqlquery = 'SELECT d.id AS d_id, d.naam AS d_naam, d.roft AS d_roft, d.* FROM ' |
||
| 225 | . $GLOBALS['xoopsDB']->prefix('pedigree_tree') |
||
| 226 | . ' d LEFT JOIN ' |
||
| 227 | . $GLOBALS['xoopsDB']->prefix('pedigree_tree') |
||
| 228 | . ' f ON d.father = f.id LEFT JOIN ' |
||
| 229 | . $GLOBALS['xoopsDB']->prefix('pedigree_tree') |
||
| 230 | . ' m ON d.mother = m.id WHERE d.father=' |
||
| 231 | . $oid |
||
| 232 | . ' ORDER BY d.naam'; |
||
| 233 | } else { |
||
| 234 | $sqlquery = 'SELECT d.id AS d_id, d.naam AS d_naam, d.roft AS d_roft, d.* FROM ' |
||
| 235 | . $GLOBALS['xoopsDB']->prefix('pedigree_tree') |
||
| 236 | . ' d LEFT JOIN ' |
||
| 237 | . $GLOBALS['xoopsDB']->prefix('pedigree_tree') |
||
| 238 | . ' f ON d.father = f.id LEFT JOIN ' |
||
| 239 | . $GLOBALS['xoopsDB']->prefix('pedigree_tree') |
||
| 240 | . ' m ON d.mother = m.id WHERE d.mother=' |
||
| 241 | . $oid |
||
| 242 | . ' ORDER BY d.naam'; |
||
| 243 | } |
||
| 244 | $queryresult = $GLOBALS['xoopsDB']->query($sqlquery); |
||
| 245 | $nummatch = $GLOBALS['xoopsDB']->getRowsNum($queryresult); |
||
| 246 | |||
| 247 | $animal = new Pedigree\Animal(); |
||
| 248 | //test to find out how many user fields there are... |
||
| 249 | $fields = $animal->getNumOfFields(); |
||
| 250 | $numofcolumns = 1; |
||
| 251 | $columns[] = ['columnname' => 'Name']; |
||
| 252 | for ($i = 0, $iMax = count($fields); $i < $iMax; ++$i) { |
||
| 253 | $userField = new Pedigree\Field($fields[$i], $animal->getConfig()); |
||
| 254 | $fieldType = $userField->getSetting('fieldtype'); |
||
| 255 | $fieldObject = new $fieldType($userField, $animal); |
||
| 256 | //create empty string |
||
| 257 | $lookupvalues = ''; |
||
| 258 | if ($userField->isActive() && $userField->inList()) { |
||
| 259 | if ($userField->hasLookup()) { |
||
| 260 | $lookupvalues = $userField->lookupField($fields[$i]); |
||
| 261 | //debug information |
||
| 262 | //print_r($lookupvalues); |
||
| 263 | } |
||
| 264 | $columns[] = [ |
||
| 265 | 'columnname' => $fieldObject->fieldname, |
||
| 266 | 'columnnumber' => $userField->getId(), |
||
| 267 | 'lookupval' => $lookupvalues |
||
| 268 | ]; |
||
| 269 | ++$numofcolumns; |
||
| 270 | unset($lookupvalues); |
||
| 271 | } |
||
| 272 | } |
||
| 273 | $columnvalue = []; |
||
| 274 | while (false !== ($rowres = $GLOBALS['xoopsDB']->fetchArray($queryresult))) { |
||
| 275 | if ('0' == $rowres['d_roft']) { |
||
| 276 | $gender = '<img src="assets/images/male.gif">'; |
||
| 277 | } else { |
||
| 278 | $gender = '<img src="assets/images/female.gif">'; |
||
| 279 | } |
||
| 280 | $name = stripslashes($rowres['d_naam']); |
||
| 281 | //empty array |
||
| 282 | unset($columnvalue); |
||
| 283 | //fill array |
||
| 284 | for ($i = 1; $i < $numofcolumns; ++$i) { |
||
| 285 | $x = $columns[$i]['columnnumber']; |
||
| 286 | if (is_array($columns[$i]['lookupval'])) { |
||
| 287 | foreach ($columns[$i]['lookupval'] as $key => $keyvalue) { |
||
| 288 | if ($keyvalue['id'] == $rowres['user' . $x]) { |
||
| 289 | $value = $keyvalue['value']; |
||
| 290 | } |
||
| 291 | } |
||
| 292 | //debug information |
||
| 293 | ///echo $columns[$i]['columnname']."is an array !"; |
||
| 294 | } //format value - cant use object because of query count |
||
| 295 | elseif (0 === strncmp($rowres['user' . $x], 'http://', 7)) { |
||
| 296 | $value = '<a href="' . $rowres['user' . $x] . '">' . $rowres['user' . $x] . '</a>'; |
||
| 297 | } else { |
||
| 298 | $value = $rowres['user' . $x]; |
||
| 299 | } |
||
| 300 | $columnvalue[] = ['value' => $value]; |
||
| 301 | } |
||
| 302 | $columnvalue = isset($columnvalue) ? $columnvalue : null; |
||
| 303 | $dogs[] = [ |
||
| 304 | 'id' => $rowres['d_id'], |
||
| 305 | 'name' => $name, |
||
| 306 | 'gender' => $gender, |
||
| 307 | 'link' => '<a href="dog.php?id=' . $rowres['d_id'] . '">' . $name . '</a>', |
||
| 308 | 'colour' => '', |
||
| 309 | 'number' => '', |
||
| 310 | 'usercolumns' => $columnvalue |
||
| 311 | ]; |
||
| 312 | } |
||
| 313 | |||
| 314 | return null; |
||
| 315 | } |
||
| 316 | |||
| 317 | /** |
||
| 318 | * @param $oid |
||
| 319 | * @param $pa |
||
| 320 | * @param $ma |
||
| 321 | * |
||
| 322 | * @return null |
||
| 323 | */ |
||
| 324 | public static function bas($oid, $pa, $ma) |
||
| 325 | { |
||
| 326 | global $numofcolumns1, $nummatch1, $pages1, $columns1, $dogs1; |
||
| 327 | if ('0' == $pa && '0' == $ma) { |
||
| 328 | $sqlquery = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' WHERE father = ' . $pa . ' AND mother = ' . $ma . ' AND id != ' . $oid . " AND father != '0' AND mother !='0' ORDER BY naam"; |
||
| 329 | } else { |
||
| 330 | $sqlquery = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' WHERE father = ' . $pa . ' AND mother = ' . $ma . ' AND id != ' . $oid . ' ORDER BY naam'; |
||
| 331 | } |
||
| 332 | $queryresult = $GLOBALS['xoopsDB']->query($sqlquery); |
||
| 333 | $nummatch1 = $GLOBALS['xoopsDB']->getRowsNum($queryresult); |
||
| 334 | |||
| 335 | $animal = new Pedigree\Animal(); |
||
| 336 | //test to find out how many user fields there are... |
||
| 337 | $fields = $animal->getNumOfFields(); |
||
| 338 | $numofcolumns1 = 1; |
||
| 339 | $columns1[] = ['columnname' => 'Name']; |
||
| 340 | for ($i = 0, $iMax = count($fields); $i < $iMax; ++$i) { |
||
| 341 | $userField = new Pedigree\Field($fields[$i], $animal->getConfig()); |
||
| 342 | $fieldType = $userField->getSetting('fieldtype'); |
||
| 343 | $fieldObject = new $fieldType($userField, $animal); |
||
| 344 | //create empty string |
||
| 345 | $lookupvalues = ''; |
||
| 346 | if ($userField->isActive() && $userField->inList()) { |
||
| 347 | if ($userField->hasLookup()) { |
||
| 348 | $lookupvalues = $userField->lookupField($fields[$i]); |
||
| 349 | //debug information |
||
| 350 | //print_r($lookupvalues); |
||
| 351 | } |
||
| 352 | $columns1[] = [ |
||
| 353 | 'columnname' => $fieldObject->fieldname, |
||
| 354 | 'columnnumber' => $userField->getId(), |
||
| 355 | 'lookupval' => $lookupvalues |
||
| 356 | ]; |
||
| 357 | ++$numofcolumns1; |
||
| 358 | unset($lookupvalues); |
||
| 359 | } |
||
| 360 | } |
||
| 361 | |||
| 362 | while (false !== ($rowres = $GLOBALS['xoopsDB']->fetchArray($queryresult))) { |
||
| 363 | if (0 == $rowres['roft']) { |
||
| 364 | $gender = "<img src='assets/images/male.gif'>"; |
||
| 365 | } else { |
||
| 366 | $gender = "<img src='assets/images/female.gif'>"; |
||
| 367 | } |
||
| 368 | $name = stripslashes($rowres['naam']); |
||
| 369 | //empty array |
||
| 370 | // unset($columnvalue1); |
||
| 371 | $columnvalue1 = []; |
||
| 372 | //fill array |
||
| 373 | for ($i = 1; $i < $numofcolumns1; ++$i) { |
||
| 374 | $x = $columns1[$i]['columnnumber']; |
||
| 375 | if (is_array($columns1[$i]['lookupval'])) { |
||
| 376 | foreach ($columns1[$i]['lookupval'] as $key => $keyvalue) { |
||
| 377 | if ($keyvalue['id'] == $rowres['user' . $x]) { |
||
| 378 | $value = $keyvalue['value']; |
||
| 379 | } |
||
| 380 | } |
||
| 381 | //debug information |
||
| 382 | ///echo $columns[$i]['columnname']."is an array !"; |
||
| 383 | } //format value - cant use object because of query count |
||
| 384 | elseif (0 === strncmp($rowres['user' . $x], 'http://', 7)) { |
||
| 385 | $value = '<a href="' . $rowres['user' . $x] . '">' . $rowres['user' . $x] . '</a>'; |
||
| 386 | } else { |
||
| 387 | $value = $rowres['user' . $x]; |
||
| 388 | } |
||
| 389 | $columnvalue1[] = ['value' => $value]; |
||
| 390 | } |
||
| 391 | $dogs1[] = [ |
||
| 392 | 'id' => $rowres['id'], |
||
| 393 | 'name' => $name, |
||
| 394 | 'gender' => $gender, |
||
| 395 | 'link' => '<a href="dog.php?id=' . $rowres['id'] . '">' . $name . '</a>', |
||
| 396 | 'colour' => '', |
||
| 397 | 'number' => '', |
||
| 398 | 'usercolumns' => $columnvalue1 |
||
| 399 | ]; |
||
| 400 | } |
||
| 401 | |||
| 402 | return null; |
||
| 403 | } |
||
| 404 | |||
| 405 | /** |
||
| 406 | * @param $oid |
||
| 407 | * @param $breeder |
||
| 408 | * |
||
| 409 | * @return string |
||
| 410 | */ |
||
| 411 | public static function breederof($oid, $breeder) |
||
| 412 | { |
||
| 413 | $content = ''; |
||
| 414 | |||
| 415 | if (0 == $breeder) { |
||
| 416 | $sqlquery = 'SELECT id, naam, roft FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE id_owner = '" . $oid . "' ORDER BY naam"; |
||
| 417 | } else { |
||
| 418 | $sqlquery = 'SELECT id, naam, roft FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE id_breeder = '" . $oid . "' ORDER BY naam"; |
||
| 419 | } |
||
| 420 | $queryresult = $GLOBALS['xoopsDB']->query($sqlquery); |
||
| 421 | while (false !== ($rowres = $GLOBALS['xoopsDB']->fetchArray($queryresult))) { |
||
| 422 | if ('0' == $rowres['roft']) { |
||
| 423 | $gender = '<img src="assets/images/male.gif">'; |
||
| 424 | } else { |
||
| 425 | $gender = '<img src="assets/images/female.gif">'; |
||
| 426 | } |
||
| 427 | $link = '<a href="dog.php?id=' . $rowres['id'] . '">' . stripslashes($rowres['naam']) . '</a>'; |
||
| 428 | $content .= $gender . ' ' . $link . '<br>'; |
||
| 429 | } |
||
| 430 | |||
| 431 | return $content; |
||
| 432 | } |
||
| 433 | |||
| 434 | /** |
||
| 435 | * @param $oid |
||
| 436 | * |
||
| 437 | * @return string |
||
| 438 | */ |
||
| 439 | public static function getName($oid) |
||
| 440 | { |
||
| 441 | $oid = (int)$oid; |
||
| 442 | $sqlquery = 'SELECT naam FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE id = '{$oid}'"; |
||
| 443 | $queryresult = $GLOBALS['xoopsDB']->query($sqlquery); |
||
| 444 | while (false !== ($rowres = $GLOBALS['xoopsDB']->fetchArray($queryresult))) { |
||
| 445 | $an = stripslashes($rowres['naam']); |
||
| 446 | } |
||
| 447 | |||
| 448 | return $an; |
||
| 449 | } |
||
| 450 | |||
| 451 | /** |
||
| 452 | * @param $PA |
||
| 453 | */ |
||
| 454 | public static function showParent($PA) |
||
| 455 | { |
||
| 456 | $sqlquery = 'SELECT naam FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE id='" . $PA . "'"; |
||
| 457 | $queryresult = $GLOBALS['xoopsDB']->query($sqlquery); |
||
| 458 | while (false !== ($rowres = $GLOBALS['xoopsDB']->fetchArray($queryresult))) { |
||
| 459 | $result = $rowres['naam']; |
||
| 460 | } |
||
| 461 | if (isset($result)) { |
||
| 462 | return $result; |
||
| 463 | } else { |
||
| 464 | return; |
||
| 465 | } |
||
| 466 | } |
||
| 467 | |||
| 468 | /** |
||
| 469 | * @param $naam_hond |
||
| 470 | * |
||
| 471 | * @return mixed |
||
| 472 | */ |
||
| 473 | public static function findId($naam_hond) |
||
| 474 | { |
||
| 475 | $sqlquery = 'SELECT id FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE naam= '$naam_hond'"; |
||
| 476 | $queryresult = $GLOBALS['xoopsDB']->query($sqlquery); |
||
| 477 | while (false !== ($rowres = $GLOBALS['xoopsDB']->fetchArray($queryresult))) { |
||
| 478 | $result = $rowres['id']; |
||
| 479 | } |
||
| 480 | |||
| 481 | return $result; |
||
| 482 | } |
||
| 483 | |||
| 484 | /** |
||
| 485 | * @param $result |
||
| 486 | * @param $prefix |
||
| 487 | * @param $link |
||
| 488 | * @param $element |
||
| 489 | */ |
||
| 490 | public static function createList($result, $prefix, $link, $element) |
||
| 491 | { |
||
| 492 | global $xoopsTpl; |
||
| 493 | $animal = new Pedigree\Animal(); |
||
| 494 | //test to find out how many user fields there are... |
||
| 495 | $fields = $animal->getNumOfFields(); |
||
| 496 | $numofcolumns = 1; |
||
| 497 | $columns[] = ['columnname' => 'Name']; |
||
| 498 | for ($i = 0, $iMax = count($fields); $i < $iMax; ++$i) { |
||
| 499 | $userField = new Pedigree\Field($fields[$i], $animal->getConfig()); |
||
| 500 | $fieldType = $userField->getSetting('fieldtype'); |
||
| 501 | $fieldObject = new $fieldType($userField, $animal); |
||
| 502 | if ($userField->isActive() && $userField->inList()) { |
||
| 503 | if ($userField->hasLookup()) { |
||
| 504 | $id = $userField->getId(); |
||
| 505 | $q = $userField->lookupField($id); |
||
| 506 | } else { |
||
| 507 | $q = ''; |
||
| 508 | } |
||
| 509 | $columns[] = [ |
||
| 510 | 'columnname' => $fieldObject->fieldname, |
||
| 511 | 'columnnumber' => $userField->getId(), |
||
| 512 | 'lookuparray' => $q |
||
| 513 | ]; |
||
| 514 | ++$numofcolumns; |
||
| 515 | } |
||
| 516 | } |
||
| 517 | |||
| 518 | //add preliminary row to array if passed |
||
| 519 | if (is_array($prefix)) { |
||
| 520 | $dogs[] = $prefix; |
||
| 521 | } |
||
| 522 | |||
| 523 | while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||
| 524 | //reset $gender |
||
| 525 | $gender = ''; |
||
| 526 | if ((!empty($GLOBALS['xoopsUser']) && $GLOBALS['xoopsUser'] instanceof \XoopsUser) |
||
| 527 | && ($row['user'] == $GLOBALS['xoopsUser']->getVar('uid') || true === $modadmin)) { |
||
| 528 | $gender = "<a href='dog.php?id={$row['id']}'><img src='assets/images/edit.png' alt='" . _EDIT . "'></a> |
||
| 529 | . <a href='delete.php?id={$row['id']}'><img src='assets/images/delete.png' alt='" . _DELETE . "'></a>"; |
||
| 530 | } |
||
| 531 | |||
| 532 | $genImg = (0 == $row['roft']) ? 'male.gif' : 'female.gif'; |
||
| 533 | $gender .= "<img src='assets/images/{$genImg}'>"; |
||
| 534 | |||
| 535 | if ('' != $row['foto']) { |
||
| 536 | $camera = ' <img src="assets/images/dog-icon25.png">'; |
||
| 537 | } else { |
||
| 538 | $camera = ''; |
||
| 539 | } |
||
| 540 | $name = stripslashes($row['naam']) . $camera; |
||
| 541 | unset($columnvalue); |
||
| 542 | |||
| 543 | //fill array |
||
| 544 | for ($i = 1; $i < $numofcolumns; ++$i) { |
||
| 545 | $x = $columns[$i]['columnnumber']; |
||
| 546 | $lookuparray = $columns[$i]['lookuparray']; |
||
| 547 | if (is_array($lookuparray)) { |
||
| 548 | for ($index = 0, $indexMax = count($lookuparray); $index < $indexMax; ++$index) { |
||
| 549 | if ($lookuparray[$index]['id'] == $row['user' . $x]) { |
||
| 550 | //echo "<h1>".$lookuparray[$index]['id']."</h1>"; |
||
| 551 | $value = $lookuparray[$index]['value']; |
||
| 552 | } |
||
| 553 | } |
||
| 554 | } //format value - cant use object because of query count |
||
| 555 | elseif (0 === strncmp($row['user' . $x], 'http://', 7)) { |
||
| 556 | $value = '<a href="' . $row['user' . $x] . '">' . $row['user' . $x] . '</a>'; |
||
| 557 | } else { |
||
| 558 | $value = $row['user' . $x]; |
||
| 559 | } |
||
| 560 | $columnvalue[] = ['value' => $value]; |
||
| 561 | unset($value); |
||
| 562 | } |
||
| 563 | |||
| 564 | $linkto = '<a href="' . $link . $row[$element] . '">' . $name . '</a>'; |
||
| 565 | //create array |
||
| 566 | $dogs[] = [ |
||
| 567 | 'id' => $row['id'], |
||
| 568 | 'name' => $name, |
||
| 569 | 'gender' => $gender, |
||
| 570 | 'link' => $linkto, |
||
| 571 | 'colour' => '', |
||
| 572 | 'number' => '', |
||
| 573 | 'usercolumns' => $columnvalue |
||
| 574 | ]; |
||
| 575 | } |
||
| 576 | |||
| 577 | //add data to smarty template |
||
| 578 | //assign dog |
||
| 579 | $xoopsTpl->assign('dogs', $dogs); |
||
| 580 | $xoopsTpl->assign('columns', $columns); |
||
| 581 | $xoopsTpl->assign('numofcolumns', $numofcolumns); |
||
| 582 | $xoopsTpl->assign('tsarray', self::sortTable($numofcolumns)); |
||
| 583 | } |
||
| 584 | |||
| 585 | /***************Blocks************** |
||
| 586 | * |
||
| 587 | * @param array|string $cats |
||
| 588 | * |
||
| 589 | * @return string (cat1, cat2, cat3, etc) for SQL statement |
||
| 590 | */ |
||
| 591 | public static function animal_block_addCatSelect($cats) |
||
| 592 | { |
||
| 593 | $cat_sql = ''; |
||
| 594 | if (is_array($cats)) { |
||
| 595 | $cats = array_map('intval', $cats); // make sure all cats are numbers |
||
| 596 | $cat_sql = '(' . implode(',', $cats) . ')'; |
||
| 597 | /* |
||
| 598 | $cat_sql = '(' . current($cats); |
||
| 599 | array_shift($cats); |
||
| 600 | foreach ($cats as $cat) { |
||
| 601 | $cat_sql .= ',' . $cat; |
||
| 602 | } |
||
| 603 | $cat_sql .= ')'; |
||
| 604 | */ |
||
| 605 | } else { |
||
| 606 | $cat_sql = '(' . (int)$cats . ')'; // not efficient but at least creates valid SQL statement |
||
| 607 | } |
||
| 608 | |||
| 609 | return $cat_sql; |
||
| 610 | } |
||
| 611 | |||
| 612 | /** |
||
| 613 | * @deprecated |
||
| 614 | * @param $global |
||
| 615 | * @param $key |
||
| 616 | * @param string $default |
||
| 617 | * @param string $type |
||
| 618 | * |
||
| 619 | * @return mixed|string |
||
| 620 | */ |
||
| 621 | public static function animal_CleanVars(&$global, $key, $default = '', $type = 'int') |
||
| 622 | { |
||
| 623 | switch ($type) { |
||
| 624 | case 'string': |
||
| 625 | $ret = isset($global[$key]) ? filter_var($global[$key], FILTER_SANITIZE_MAGIC_QUOTES) : $default; |
||
| 626 | break; |
||
| 627 | case 'int': |
||
| 628 | default: |
||
| 629 | $ret = isset($global[$key]) ? filter_var($global[$key], FILTER_SANITIZE_NUMBER_INT) : $default; |
||
| 630 | break; |
||
| 631 | } |
||
| 632 | if (false === $ret) { |
||
| 633 | return $default; |
||
| 634 | } |
||
| 635 | |||
| 636 | return $ret; |
||
| 637 | } |
||
| 638 | |||
| 639 | /** |
||
| 640 | * @param $content |
||
| 641 | */ |
||
| 642 | public static function animal_meta_keywords($content) |
||
| 643 | { |
||
| 644 | global $xoopsTpl, $xoTheme; |
||
| 645 | $myts = \MyTextSanitizer::getInstance(); |
||
| 646 | $content = $myts->undoHtmlSpecialChars($myts->sanitizeForDisplay($content)); |
||
| 647 | if (isset($xoTheme) && is_object($xoTheme)) { |
||
| 648 | $xoTheme->addMeta('meta', 'keywords', strip_tags($content)); |
||
| 649 | } else { // Compatibility for old Xoops versions |
||
| 650 | $xoopsTpl->assign('xoops_meta_keywords', strip_tags($content)); |
||
| 651 | } |
||
| 652 | } |
||
| 653 | |||
| 654 | /** |
||
| 655 | * @param $content |
||
| 656 | */ |
||
| 657 | public static function animal_meta_description($content) |
||
| 658 | { |
||
| 659 | global $xoopsTpl, $xoTheme; |
||
| 660 | $myts = \MyTextSanitizer::getInstance(); |
||
| 661 | $content = $myts->undoHtmlSpecialChars($myts->displayTarea($content)); |
||
| 662 | if (isset($xoTheme) && is_object($xoTheme)) { |
||
| 663 | $xoTheme->addMeta('meta', 'description', strip_tags($content)); |
||
| 664 | } else { // Compatibility for old Xoops versions |
||
| 665 | $xoopsTpl->assign('xoops_meta_description', strip_tags($content)); |
||
| 666 | } |
||
| 667 | } |
||
| 668 | |||
| 669 | /** |
||
| 670 | * Verify that a mysql table exists |
||
| 671 | * |
||
| 672 | * @package pedigree |
||
| 673 | * @author Hervé Thouzard (http://www.herve-thouzard.com) |
||
| 674 | * @copyright (c) Hervé Thouzard |
||
| 675 | */ |
||
| 676 | //function tableExists($tablename) |
||
| 677 | //{ |
||
| 678 | // |
||
| 679 | // $result=$GLOBALS['xoopsDB']->queryF("SHOW TABLES LIKE '$tablename'"); |
||
| 680 | // return($GLOBALS['xoopsDB']->getRowsNum($result) > 0); |
||
| 681 | //} |
||
| 682 | |||
| 683 | /** |
||
| 684 | * Create download by letter choice bar/menu |
||
| 685 | * updated starting from this idea https://xoops.org/modules/news/article.php?storyid=6497 |
||
| 686 | * |
||
| 687 | * @param Pedigree\Helper $myObject |
||
| 688 | * @param $activeObject |
||
| 689 | * @param $criteria |
||
| 690 | * @param $name |
||
| 691 | * @param $link |
||
| 692 | * @param null $link2 |
||
| 693 | * @return string html |
||
| 694 | * |
||
| 695 | * @internal param $file |
||
| 696 | * @internal param $file2 |
||
| 697 | * @access public |
||
| 698 | * @author luciorota |
||
| 699 | */ |
||
| 700 | public static function lettersChoice($myObject, $activeObject, $criteria, $name, $link, $link2 = null) |
||
| 701 | { |
||
| 702 | /* |
||
| 703 | $pedigree = Pedigree\Helper::getInstance(); |
||
| 704 | xoops_load('XoopsLocal'); |
||
| 705 | |||
| 706 | $criteria = $helper->getHandler('tree')->getActiveCriteria(); |
||
| 707 | $criteria->setGroupby('UPPER(LEFT(naam,1))'); |
||
| 708 | $countsByLetters = $helper->getHandler('tree')->getCounts($criteria); |
||
| 709 | // Fill alphabet array |
||
| 710 | $alphabet = XoopsLocal::getAlphabet(); |
||
| 711 | $alphabet_array = array(); |
||
| 712 | foreach ($alphabet as $letter) { |
||
| 713 | $letter_array = array(); |
||
| 714 | if (isset($countsByLetters[$letter])) { |
||
| 715 | $letter_array['letter'] = $letter; |
||
| 716 | $letter_array['count'] = $countsByLetters[$letter]; |
||
| 717 | // $letter_array['url'] = "" . XOOPS_URL . "/modules/" . $helper->getModule()->dirname() . "/viewcat.php?list={$letter}"; |
||
| 718 | $letter_array['url'] = '' . XOOPS_URL . '/modules/' . $helper->getModule()->dirname() . "/result.php?f=naam&l=1&w={$letter}%25&o=naam"; |
||
| 719 | } else { |
||
| 720 | $letter_array['letter'] = $letter; |
||
| 721 | $letter_array['count'] = 0; |
||
| 722 | $letter_array['url'] = ''; |
||
| 723 | } |
||
| 724 | $alphabet_array[$letter] = $letter_array; |
||
| 725 | unset($letter_array); |
||
| 726 | } |
||
| 727 | // Render output |
||
| 728 | if (!isset($GLOBALS['xoTheme']) || !is_object($GLOBALS['xoTheme'])) { |
||
| 729 | require_once $GLOBALS['xoops']->path('class/theme.php'); |
||
| 730 | $GLOBALS['xoTheme'] = new \xos_opal_Theme(); |
||
| 731 | } |
||
| 732 | require_once $GLOBALS['xoops']->path('class/template.php'); |
||
| 733 | $letterschoiceTpl = new \XoopsTpl(); |
||
| 734 | $letterschoiceTpl->caching = false; // Disable cache |
||
| 735 | $letterschoiceTpl->assign('alphabet', $alphabet_array); |
||
| 736 | $html = $letterschoiceTpl->fetch('db:' . $helper->getModule()->dirname() . '_common_letterschoice.tpl'); |
||
| 737 | unset($letterschoiceTpl); |
||
| 738 | return $html; |
||
| 739 | */ |
||
| 740 | |||
| 741 | // $pedigree = Pedigree\Helper::getInstance(); |
||
| 742 | // xoops_load('XoopsLocal'); |
||
| 743 | |||
| 744 | // $criteria = $myObject->getHandler($activeObject)->getActiveCriteria(); |
||
| 745 | $criteria->setGroupby('UPPER(LEFT(' . $name . ',1))'); |
||
| 746 | $countsByLetters = $myObject->getHandler($activeObject)->getCounts($criteria); |
||
| 747 | // Fill alphabet array |
||
| 748 | |||
| 749 | //@todo getAlphabet method doesn't exist anywhere |
||
| 750 | //$alphabet = XoopsLocal::getAlphabet(); |
||
| 751 | |||
| 752 | // xoops_load('XoopsLocal'); |
||
| 753 | // $xLocale = new \XoopsLocal; |
||
| 754 | // $alphabet = $xLocale->getAlphabet(); |
||
| 755 | $alphabet = pedigreeGetAlphabet(); |
||
| 756 | $alphabet_array = []; |
||
| 757 | foreach ($alphabet as $letter) { |
||
| 758 | /* |
||
| 759 | if (isset($countsByLetters[$letter])) { |
||
| 760 | $letter_array['letter'] = $letter; |
||
| 761 | $letter_array['count'] = $countsByLetters[$letter]; |
||
| 762 | // $letter_array['url'] = "" . XOOPS_URL . "/modules/" . $helper->getModule()->dirname() . "/viewcat.php?list={$letter}"; |
||
| 763 | // $letter_array['url'] = '' . XOOPS_URL . '/modules/' . $myObject->getModule()->dirname() . '/'.$file.'?f='.$name."&l=1&w={$letter}%25&o=".$name; |
||
| 764 | $letter_array['url'] = '' . XOOPS_URL . '/modules/' . $myObject->getModule()->dirname() . '/' . $file2; |
||
| 765 | } else { |
||
| 766 | $letter_array['letter'] = $letter; |
||
| 767 | $letter_array['count'] = 0; |
||
| 768 | $letter_array['url'] = ''; |
||
| 769 | } |
||
| 770 | $alphabet_array[$letter] = $letter_array; |
||
| 771 | unset($letter_array); |
||
| 772 | } |
||
| 773 | |||
| 774 | |||
| 775 | $alphabet_array = array(); |
||
| 776 | // foreach ($alphabet as $letter) { |
||
| 777 | foreach (range('A', 'Z') as $letter) { |
||
| 778 | */ |
||
| 779 | $letter_array = []; |
||
| 780 | if (isset($countsByLetters[$letter])) { |
||
| 781 | $letter_array['letter'] = $letter; |
||
| 782 | $letter_array['count'] = $countsByLetters[$letter]; |
||
| 783 | // $letter_array['url'] = "" . XOOPS_URL . "/modules/" . $helper->getModule()->dirname() . "/viewcat.php?list={$letter}"; |
||
| 784 | // $letter_array['url'] = '' . XOOPS_URL . '/modules/' . $myObject->getModule()->dirname() . '/'.$file.'?f='.$name."&l=1&w={$letter}%25&o=".$name; |
||
| 785 | $letter_array['url'] = '' . XOOPS_URL . '/modules/' . $myObject->getModule()->dirname() . '/' . $link . $letter . $link2; |
||
| 786 | } else { |
||
| 787 | $letter_array['letter'] = $letter; |
||
| 788 | $letter_array['count'] = 0; |
||
| 789 | $letter_array['url'] = ''; |
||
| 790 | } |
||
| 791 | $alphabet_array[$letter] = $letter_array; |
||
| 792 | unset($letter_array); |
||
| 793 | } |
||
| 794 | |||
| 795 | // Render output |
||
| 796 | if (!isset($GLOBALS['xoTheme']) || !is_object($GLOBALS['xoTheme'])) { |
||
| 797 | require_once $GLOBALS['xoops']->path('class/theme.php'); |
||
| 798 | $GLOBALS['xoTheme'] = new \xos_opal_Theme(); |
||
| 799 | } |
||
| 800 | require_once $GLOBALS['xoops']->path('class/template.php'); |
||
| 801 | $letterschoiceTpl = new \XoopsTpl(); |
||
| 802 | $letterschoiceTpl->caching = false; // Disable cache |
||
| 803 | $letterschoiceTpl->assign('alphabet', $alphabet_array); |
||
| 804 | $html = $letterschoiceTpl->fetch('db:' . $myObject->getModule()->dirname() . '_common_letterschoice.tpl'); |
||
| 805 | unset($letterschoiceTpl); |
||
| 806 | |||
| 807 | return $html; |
||
| 808 | } |
||
| 809 | |||
| 810 | /** |
||
| 811 | * @return bool |
||
| 812 | */ |
||
| 813 | public static function userIsAdmin() |
||
| 814 | { |
||
| 815 | $helper = Pedigree\Helper::getInstance(); |
||
| 816 | |||
| 817 | $pedigree_isAdmin = $helper->isUserAdmin(); |
||
| 818 | |||
| 819 | return $pedigree_isAdmin; |
||
| 820 | } |
||
| 821 | |||
| 822 | public static function getXoopsCpHeader() |
||
| 823 | { |
||
| 824 | xoops_cp_header(); |
||
| 825 | } |
||
| 826 | |||
| 827 | /** |
||
| 828 | * @deprecated |
||
| 829 | * @param bool $withLink |
||
| 830 | * |
||
| 831 | * @return string |
||
| 832 | */ |
||
| 833 | public static function getModuleName($withLink = true) |
||
| 834 | { |
||
| 835 | $helper = Pedigree\Helper::getInstance(); |
||
| 836 | |||
| 837 | $pedigreeModuleName = $helper->getModule()->getVar('name'); |
||
| 838 | if (!$withLink) { |
||
| 839 | return $pedigreeModuleName; |
||
| 840 | } else { |
||
| 841 | return '<a href="' . PEDIGREE_URL . '/">{$pedigreeModuleName}</a>'; |
||
| 842 | } |
||
| 843 | } |
||
| 844 | |||
| 845 | /** |
||
| 846 | * Detemines if a table exists in the current db |
||
| 847 | * |
||
| 848 | * @param string $table the table name (without XOOPS prefix) |
||
| 849 | * |
||
| 850 | * @return bool True if table exists, false if not |
||
| 851 | * |
||
| 852 | * @access public |
||
| 853 | * @author xhelp development team |
||
| 854 | */ |
||
| 855 | public static function hasTable($table) |
||
| 856 | { |
||
| 857 | $bRetVal = false; |
||
| 858 | //Verifies that a MySQL table exists |
||
| 859 | $GLOBALS['xoopsDB'] = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 860 | $realName = $GLOBALS['xoopsDB']->prefix($table); |
||
| 861 | |||
| 862 | $sql = 'SHOW TABLES FROM ' . XOOPS_DB_NAME; |
||
| 863 | $ret = $GLOBALS['xoopsDB']->queryF($sql); |
||
| 864 | |||
| 865 | while (false !== (list($m_table) = $GLOBALS['xoopsDB']->fetchRow($ret))) { |
||
| 866 | if ($m_table == $realName) { |
||
| 867 | $bRetVal = true; |
||
| 868 | break; |
||
| 869 | } |
||
| 870 | } |
||
| 871 | $GLOBALS['xoopsDB']->freeRecordSet($ret); |
||
| 872 | |||
| 873 | return $bRetVal; |
||
| 874 | } |
||
| 875 | |||
| 876 | /** |
||
| 877 | * Gets a value from a key in the xhelp_meta table |
||
| 878 | * |
||
| 879 | * @param string $key |
||
| 880 | * |
||
| 881 | * @return string $value |
||
| 882 | * |
||
| 883 | * @access public |
||
| 884 | * @author xhelp development team |
||
| 885 | */ |
||
| 886 | public static function getMeta($key) |
||
| 887 | { |
||
| 888 | $GLOBALS['xoopsDB'] = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 889 | $sql = sprintf('SELECT metavalue FROM `%s` WHERE metakey= `%s` ', $GLOBALS['xoopsDB']->prefix('pedigree_meta'), $GLOBALS['xoopsDB']->quoteString($key)); |
||
| 890 | $ret = $GLOBALS['xoopsDB']->query($sql); |
||
| 891 | if (!$ret) { |
||
| 892 | $value = false; |
||
| 893 | } else { |
||
| 894 | list($value) = $GLOBALS['xoopsDB']->fetchRow($ret); |
||
| 895 | } |
||
| 896 | |||
| 897 | return $value; |
||
| 898 | } |
||
| 899 | |||
| 900 | /** |
||
| 901 | * Sets a value for a key in the xhelp_meta table |
||
| 902 | * |
||
| 903 | * @param string $key |
||
| 904 | * @param string $value |
||
| 905 | * |
||
| 906 | * @return bool true if success, false if failure |
||
| 907 | * |
||
| 908 | * @access public |
||
| 909 | * @author xhelp development team |
||
| 910 | */ |
||
| 911 | public static function setMeta($key, $value) |
||
| 912 | { |
||
| 913 | $GLOBALS['xoopsDB'] = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 914 | if (false !== ($ret = self::getMeta($key))) { |
||
| 915 | $sql = sprintf('UPDATE `%s` SET metavalue = `%s` WHERE metakey = `%s` ', $GLOBALS['xoopsDB']->prefix('pedigree_meta'), $GLOBALS['xoopsDB']->quoteString($value), $GLOBALS['xoopsDB']->quoteString($key)); |
||
| 916 | } else { |
||
| 917 | $sql = sprintf('INSERT INTO `%s` (metakey, metavalue) VALUES (`%s`, `%s` )', $GLOBALS['xoopsDB']->prefix('pedigree_meta'), $GLOBALS['xoopsDB']->quoteString($key), $GLOBALS['xoopsDB']->quoteString($value)); |
||
| 918 | } |
||
| 919 | $ret = $GLOBALS['xoopsDB']->queryF($sql); |
||
| 920 | if (!$ret) { |
||
| 921 | return false; |
||
| 922 | } |
||
| 923 | |||
| 924 | return true; |
||
| 925 | } |
||
| 926 | |||
| 927 | /** |
||
| 928 | * @param $name |
||
| 929 | * @param $value |
||
| 930 | * @param int $time |
||
| 931 | */ |
||
| 932 | public static function setCookieVar($name, $value, $time = 0) |
||
| 933 | { |
||
| 934 | if (0 == $time) { |
||
| 935 | $time = time() + 3600 * 24 * 365; |
||
| 936 | //$time = ''; |
||
| 937 | } |
||
| 938 | setcookie($name, $value, $time, '/', ini_get('session.cookie_domain'), ini_get('session.cookie_secure'), ini_get('session.cookie_httponly')); |
||
| 939 | } |
||
| 940 | |||
| 941 | /** |
||
| 942 | * @param $name |
||
| 943 | * @param string $default |
||
| 944 | * |
||
| 945 | * @return string |
||
| 946 | */ |
||
| 947 | public static function getCookieVar($name, $default = '') |
||
| 948 | { |
||
| 949 | if (isset($_COOKIE[$name]) && ($_COOKIE[$name] > '')) { |
||
| 950 | return $_COOKIE[$name]; |
||
| 951 | } else { |
||
| 952 | return $default; |
||
| 953 | } |
||
| 954 | } |
||
| 955 | |||
| 956 | /** |
||
| 957 | * @return array |
||
| 958 | */ |
||
| 959 | public static function getCurrentUrls() |
||
| 960 | { |
||
| 961 | $http = (false === strpos(XOOPS_URL, 'https://')) ? 'http://' : 'https://'; |
||
| 962 | $phpSelf = $_SERVER['PHP_SELF']; |
||
| 963 | $httpHost = $_SERVER['HTTP_HOST']; |
||
| 964 | $queryString = $_SERVER['QUERY_STRING']; |
||
| 965 | |||
| 966 | if ('' != $queryString) { |
||
| 967 | $queryString = '?' . $queryString; |
||
| 968 | } |
||
| 969 | |||
| 970 | $currentURL = $http . $httpHost . $phpSelf . $queryString; |
||
| 971 | |||
| 972 | $urls = []; |
||
| 973 | $urls['http'] = $http; |
||
| 974 | $urls['httphost'] = $httpHost; |
||
| 975 | $urls['phpself'] = $phpSelf; |
||
| 976 | $urls['querystring'] = $queryString; |
||
| 977 | $urls['full'] = $currentURL; |
||
| 978 | |||
| 979 | return $urls; |
||
| 980 | } |
||
| 981 | |||
| 982 | /** |
||
| 983 | * @return mixed |
||
| 984 | */ |
||
| 985 | public static function getCurrentPage() |
||
| 990 | } |
||
| 991 | |||
| 992 | /** |
||
| 993 | * @param array $errors |
||
| 994 | * |
||
| 995 | * @return string |
||
| 996 | */ |
||
| 997 | public static function formatErrors($errors = []) |
||
| 998 | { |
||
| 999 | $ret = ''; |
||
| 1000 | foreach ($errors as $key => $value) { |
||
| 1001 | $ret .= "<br> - {$value}"; |
||
| 1002 | } |
||
| 1003 | |||
| 1004 | return $ret; |
||
| 1005 | } |
||
| 1006 | } |
||
| 1007 |
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.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths