| Total Complexity | 119 |
| Total Lines | 985 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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; |
||
| 10 | class Utility |
||
| 11 | { |
||
| 12 | use Common\VersionChecks; //checkVerXoops, checkVerPhp Traits |
||
| 13 | |||
| 14 | use Common\ServerStats; // getServerStats Trait |
||
| 15 | |||
| 16 | use Common\FilesManagement; // Files Management Trait |
||
| 17 | |||
| 18 | //--------------- Custom module methods ----------------------------- |
||
| 19 | /** |
||
| 20 | * Function responsible for checking if a directory exists, we can also write in and create an index.html file |
||
| 21 | * |
||
| 22 | * @param string $folder The full path of the directory to check |
||
| 23 | * |
||
| 24 | * @return void |
||
| 25 | */ |
||
| 26 | public static function prepareFolder($folder) |
||
| 27 | { |
||
| 28 | // $filteredFolder = XoopsFilterInput::clean($folder, 'PATH'); |
||
| 29 | if (!is_dir($folder)) { |
||
| 30 | mkdir($folder); |
||
| 31 | file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>'); |
||
| 32 | } |
||
| 33 | // chmod($filteredFolder, 0777); |
||
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @param $columncount |
||
| 38 | * |
||
| 39 | * @return string |
||
| 40 | */ |
||
| 41 | public static function sortTable($columncount) |
||
| 42 | { |
||
| 43 | $ttemp = ''; |
||
| 44 | if ($columncount > 1) { |
||
| 45 | for ($t = 1; $t < $columncount; ++$t) { |
||
| 46 | $ttemp .= "'S',"; |
||
| 47 | } |
||
| 48 | $tsarray = "initSortTable('Result', Array({$ttemp}'S'));"; |
||
| 49 | } else { |
||
| 50 | $tsarray = "initSortTable('Result',Array('S'));"; |
||
| 51 | } |
||
| 52 | |||
| 53 | return $tsarray; |
||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @param $num |
||
| 58 | * |
||
| 59 | * @return string |
||
| 60 | */ |
||
| 61 | public static function uploadPicture($num) |
||
| 62 | { |
||
| 63 | $max_imgsize = $GLOBALS['xoopsModuleConfig']['maxfilesize']; //1024000; |
||
| 64 | $max_imgwidth = $GLOBALS['xoopsModuleConfig']['maximgwidth']; //1500; |
||
| 65 | $max_imgheight = $GLOBALS['xoopsModuleConfig']['maximgheight']; //1000; |
||
| 66 | $allowed_mimetypes = ['image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png']; |
||
| 67 | // $img_dir = XOOPS_ROOT_PATH . "/modules/" . $GLOBALS['xoopsModule']->dirname() . "/images" ; |
||
| 68 | $img_dir = $GLOBALS['xoopsModuleConfig']['uploaddir'] . '/images'; |
||
| 69 | require_once $GLOBALS['xoops']->path('class/uploader.php'); |
||
| 70 | $field = $_POST['xoops_upload_file'][$num]; |
||
| 71 | if (!empty($field) || '' != $field) { |
||
| 72 | $uploader = new \XoopsMediaUploader($img_dir, $allowed_mimetypes, $max_imgsize, $max_imgwidth, $max_imgheight); |
||
| 73 | $uploader->setPrefix('img'); |
||
| 74 | if ($uploader->fetchMedia($field) && $uploader->upload()) { |
||
| 75 | $photo = $uploader->getSavedFileName(); |
||
| 76 | } else { |
||
| 77 | echo $uploader->getErrors(); |
||
| 78 | } |
||
| 79 | static::createThumbs($photo); |
||
| 80 | |||
| 81 | return $photo; |
||
| 82 | } |
||
| 83 | return ''; |
||
| 84 | } |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @param $filename |
||
| 88 | * |
||
| 89 | * @return void |
||
| 90 | */ |
||
| 91 | public static function createThumbs($filename) |
||
| 206 | } |
||
| 207 | |||
| 208 | /** |
||
| 209 | * @param $string |
||
| 210 | * |
||
| 211 | * @return string |
||
| 212 | */ |
||
| 213 | public static function unHtmlEntities($string) |
||
| 214 | { |
||
| 215 | $trans_tbl = array_flip(get_html_translation_table(HTML_ENTITIES)); |
||
| 216 | |||
| 217 | return strtr($string, $trans_tbl); |
||
| 218 | } |
||
| 219 | |||
| 220 | /** |
||
| 221 | * @param $oid |
||
| 222 | * @param $gender |
||
| 223 | * |
||
| 224 | * @return null |
||
| 225 | */ |
||
| 226 | public static function pups($oid, $gender) |
||
| 227 | { |
||
| 228 | global $numofcolumns, $nummatch, $pages, $columns, $dogs; |
||
| 229 | $content = ''; |
||
| 230 | |||
| 231 | if (0 == $gender) { |
||
| 232 | $sqlquery = 'SELECT d.id AS d_id, d.naam AS d_naam, d.roft AS d_roft, d.* FROM ' |
||
| 233 | . $GLOBALS['xoopsDB']->prefix('pedigree_tree') |
||
| 234 | . ' d LEFT JOIN ' |
||
| 235 | . $GLOBALS['xoopsDB']->prefix('pedigree_tree') |
||
| 236 | . ' f ON d.father = f.id LEFT JOIN ' |
||
| 237 | . $GLOBALS['xoopsDB']->prefix('pedigree_tree') |
||
| 238 | . ' m ON d.mother = m.id WHERE d.father=' |
||
| 239 | . $oid |
||
| 240 | . ' ORDER BY d.naam'; |
||
| 241 | } else { |
||
| 242 | $sqlquery = 'SELECT d.id AS d_id, d.naam AS d_naam, d.roft AS d_roft, d.* FROM ' |
||
| 243 | . $GLOBALS['xoopsDB']->prefix('pedigree_tree') |
||
| 244 | . ' d LEFT JOIN ' |
||
| 245 | . $GLOBALS['xoopsDB']->prefix('pedigree_tree') |
||
| 246 | . ' f ON d.father = f.id LEFT JOIN ' |
||
| 247 | . $GLOBALS['xoopsDB']->prefix('pedigree_tree') |
||
| 248 | . ' m ON d.mother = m.id WHERE d.mother=' |
||
| 249 | . $oid |
||
| 250 | . ' ORDER BY d.naam'; |
||
| 251 | } |
||
| 252 | $queryresult = $GLOBALS['xoopsDB']->query($sqlquery); |
||
| 253 | $nummatch = $GLOBALS['xoopsDB']->getRowsNum($queryresult); |
||
| 254 | |||
| 255 | $animal = new Pedigree\Animal(); |
||
| 256 | //test to find out how many user fields there are... |
||
| 257 | $fields = $animal->getNumOfFields(); |
||
| 258 | $numofcolumns = 1; |
||
| 259 | $columns[] = ['columnname' => 'Name']; |
||
| 260 | foreach ($fields as $i => $iValue) { |
||
| 261 | $userField = new Pedigree\Field($fields[$i], $animal->getConfig()); |
||
| 262 | $fieldType = $userField->getSetting('fieldtype'); |
||
| 263 | $fieldObject = new $fieldType($userField, $animal); |
||
| 264 | //create empty string |
||
| 265 | $lookupvalues = ''; |
||
| 266 | if ($userField->isActive() && $userField->inList()) { |
||
| 267 | if ($userField->hasLookup()) { |
||
| 268 | $lookupvalues = $userField->lookupField($fields[$i]); |
||
| 269 | //debug information |
||
| 270 | //print_r($lookupvalues); |
||
| 271 | } |
||
| 272 | $columns[] = [ |
||
| 273 | 'columnname' => $fieldObject->fieldname, |
||
| 274 | 'columnnumber' => $userField->getId(), |
||
| 275 | 'lookupval' => $lookupvalues |
||
| 276 | ]; |
||
| 277 | ++$numofcolumns; |
||
| 278 | unset($lookupvalues); |
||
| 279 | } |
||
| 280 | } |
||
| 281 | $columnvalue = []; |
||
| 282 | while (false !== ($rowres = $GLOBALS['xoopsDB']->fetchArray($queryresult))) { |
||
| 283 | if ('0' == $rowres['d_roft']) { |
||
| 284 | $gender = '<img src="assets/images/male.gif">'; |
||
| 285 | } else { |
||
| 286 | $gender = '<img src="assets/images/female.gif">'; |
||
| 287 | } |
||
| 288 | $name = stripslashes($rowres['d_naam']); |
||
| 289 | //empty array |
||
| 290 | unset($columnvalue); |
||
| 291 | //fill array |
||
| 292 | for ($i = 1; $i < $numofcolumns; ++$i) { |
||
| 293 | $x = $columns[$i]['columnnumber']; |
||
| 294 | if (is_array($columns[$i]['lookupval'])) { |
||
| 295 | foreach ($columns[$i]['lookupval'] as $key => $keyvalue) { |
||
| 296 | if ($keyvalue['id'] == $rowres['user' . $x]) { |
||
| 297 | $value = $keyvalue['value']; |
||
| 298 | } |
||
| 299 | } |
||
| 300 | //debug information |
||
| 301 | ///echo $columns[$i]['columnname']."is an array !"; |
||
| 302 | } //format value - cant use object because of query count |
||
| 303 | elseif (0 === strncmp($rowres['user' . $x], 'http://', 7)) { |
||
| 304 | $value = '<a href="' . $rowres['user' . $x] . '">' . $rowres['user' . $x] . '</a>'; |
||
| 305 | } else { |
||
| 306 | $value = $rowres['user' . $x]; |
||
| 307 | } |
||
| 308 | $columnvalue[] = ['value' => $value]; |
||
| 309 | } |
||
| 310 | $columnvalue = isset($columnvalue) ? $columnvalue : null; |
||
| 311 | $dogs[] = [ |
||
| 312 | 'id' => $rowres['d_id'], |
||
| 313 | 'name' => $name, |
||
| 314 | 'gender' => $gender, |
||
| 315 | 'link' => '<a href="dog.php?id=' . $rowres['d_id'] . '">' . $name . '</a>', |
||
| 316 | 'colour' => '', |
||
| 317 | 'number' => '', |
||
| 318 | 'usercolumns' => $columnvalue |
||
| 319 | ]; |
||
| 320 | } |
||
| 321 | |||
| 322 | return null; |
||
| 323 | } |
||
| 324 | |||
| 325 | /** |
||
| 326 | * @param $oid |
||
| 327 | * @param $pa |
||
| 328 | * @param $ma |
||
| 329 | * |
||
| 330 | * @return null |
||
| 331 | */ |
||
| 332 | public static function bas($oid, $pa, $ma) |
||
| 333 | { |
||
| 334 | global $numofcolumns1, $nummatch1, $pages1, $columns1, $dogs1; |
||
| 335 | if ('0' == $pa && '0' == $ma) { |
||
| 336 | $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"; |
||
| 337 | } else { |
||
| 338 | $sqlquery = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' WHERE father = ' . $pa . ' AND mother = ' . $ma . ' AND id != ' . $oid . ' ORDER BY naam'; |
||
| 339 | } |
||
| 340 | $queryresult = $GLOBALS['xoopsDB']->query($sqlquery); |
||
| 341 | $nummatch1 = $GLOBALS['xoopsDB']->getRowsNum($queryresult); |
||
| 342 | |||
| 343 | $animal = new Pedigree\Animal(); |
||
| 344 | //test to find out how many user fields there are... |
||
| 345 | $fields = $animal->getNumOfFields(); |
||
| 346 | $numofcolumns1 = 1; |
||
| 347 | $columns1[] = ['columnname' => 'Name']; |
||
| 348 | foreach ($fields as $i => $iValue) { |
||
| 349 | $userField = new Pedigree\Field($fields[$i], $animal->getConfig()); |
||
| 350 | $fieldType = $userField->getSetting('fieldtype'); |
||
| 351 | $fieldObject = new $fieldType($userField, $animal); |
||
| 352 | //create empty string |
||
| 353 | $lookupvalues = ''; |
||
| 354 | if ($userField->isActive() && $userField->inList()) { |
||
| 355 | if ($userField->hasLookup()) { |
||
| 356 | $lookupvalues = $userField->lookupField($fields[$i]); |
||
| 357 | //debug information |
||
| 358 | //print_r($lookupvalues); |
||
| 359 | } |
||
| 360 | $columns1[] = [ |
||
| 361 | 'columnname' => $fieldObject->fieldname, |
||
| 362 | 'columnnumber' => $userField->getId(), |
||
| 363 | 'lookupval' => $lookupvalues |
||
| 364 | ]; |
||
| 365 | ++$numofcolumns1; |
||
| 366 | unset($lookupvalues); |
||
| 367 | } |
||
| 368 | } |
||
| 369 | |||
| 370 | while (false !== ($rowres = $GLOBALS['xoopsDB']->fetchArray($queryresult))) { |
||
| 371 | if (0 == $rowres['roft']) { |
||
| 372 | $gender = "<img src='assets/images/male.gif'>"; |
||
| 373 | } else { |
||
| 374 | $gender = "<img src='assets/images/female.gif'>"; |
||
| 375 | } |
||
| 376 | $name = stripslashes($rowres['naam']); |
||
| 377 | //empty array |
||
| 378 | // unset($columnvalue1); |
||
| 379 | $columnvalue1 = []; |
||
| 380 | //fill array |
||
| 381 | for ($i = 1; $i < $numofcolumns1; ++$i) { |
||
| 382 | $x = $columns1[$i]['columnnumber']; |
||
| 383 | if (is_array($columns1[$i]['lookupval'])) { |
||
| 384 | foreach ($columns1[$i]['lookupval'] as $key => $keyvalue) { |
||
| 385 | if ($keyvalue['id'] == $rowres['user' . $x]) { |
||
| 386 | $value = $keyvalue['value']; |
||
| 387 | } |
||
| 388 | } |
||
| 389 | //debug information |
||
| 390 | ///echo $columns[$i]['columnname']."is an array !"; |
||
| 391 | } //format value - cant use object because of query count |
||
| 392 | elseif (0 === strncmp($rowres['user' . $x], 'http://', 7)) { |
||
| 393 | $value = '<a href="' . $rowres['user' . $x] . '">' . $rowres['user' . $x] . '</a>'; |
||
| 394 | } else { |
||
| 395 | $value = $rowres['user' . $x]; |
||
| 396 | } |
||
| 397 | $columnvalue1[] = ['value' => $value]; |
||
| 398 | } |
||
| 399 | $dogs1[] = [ |
||
| 400 | 'id' => $rowres['id'], |
||
| 401 | 'name' => $name, |
||
| 402 | 'gender' => $gender, |
||
| 403 | 'link' => '<a href="dog.php?id=' . $rowres['id'] . '">' . $name . '</a>', |
||
| 404 | 'colour' => '', |
||
| 405 | 'number' => '', |
||
| 406 | 'usercolumns' => $columnvalue1 |
||
| 407 | ]; |
||
| 408 | } |
||
| 409 | |||
| 410 | return null; |
||
| 411 | } |
||
| 412 | |||
| 413 | /** |
||
| 414 | * @param $oid |
||
| 415 | * @param $breeder |
||
| 416 | * |
||
| 417 | * @return string |
||
| 418 | */ |
||
| 419 | public static function breederof($oid, $breeder) |
||
| 420 | { |
||
| 421 | $content = ''; |
||
| 422 | |||
| 423 | if (0 == $breeder) { |
||
| 424 | $sqlquery = 'SELECT id, naam, roft FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE id_owner = '" . $oid . "' ORDER BY naam"; |
||
| 425 | } else { |
||
| 426 | $sqlquery = 'SELECT id, naam, roft FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE id_breeder = '" . $oid . "' ORDER BY naam"; |
||
| 427 | } |
||
| 428 | $queryresult = $GLOBALS['xoopsDB']->query($sqlquery); |
||
| 429 | while (false !== ($rowres = $GLOBALS['xoopsDB']->fetchArray($queryresult))) { |
||
| 430 | if ('0' == $rowres['roft']) { |
||
| 431 | $gender = '<img src="assets/images/male.gif">'; |
||
| 432 | } else { |
||
| 433 | $gender = '<img src="assets/images/female.gif">'; |
||
| 434 | } |
||
| 435 | $link = '<a href="dog.php?id=' . $rowres['id'] . '">' . stripslashes($rowres['naam']) . '</a>'; |
||
| 436 | $content .= $gender . ' ' . $link . '<br>'; |
||
| 437 | } |
||
| 438 | |||
| 439 | return $content; |
||
| 440 | } |
||
| 441 | |||
| 442 | /** |
||
| 443 | * @param $oid |
||
| 444 | * |
||
| 445 | * @return string |
||
| 446 | */ |
||
| 447 | public static function getName($oid) |
||
| 448 | { |
||
| 449 | $oid = (int)$oid; |
||
| 450 | $sqlquery = 'SELECT naam FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE id = '{$oid}'"; |
||
| 451 | $queryresult = $GLOBALS['xoopsDB']->query($sqlquery); |
||
| 452 | while (false !== ($rowres = $GLOBALS['xoopsDB']->fetchArray($queryresult))) { |
||
| 453 | $an = stripslashes($rowres['naam']); |
||
| 454 | } |
||
| 455 | |||
| 456 | return $an; |
||
| 457 | } |
||
| 458 | |||
| 459 | /** |
||
| 460 | * @param $PA |
||
| 461 | * @return string |
||
| 462 | */ |
||
| 463 | public static function showParent($PA) |
||
| 464 | { |
||
| 465 | $sqlquery = 'SELECT naam FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE id='" . $PA . "'"; |
||
| 466 | $queryresult = $GLOBALS['xoopsDB']->query($sqlquery); |
||
| 467 | while (false !== ($rowres = $GLOBALS['xoopsDB']->fetchArray($queryresult))) { |
||
| 468 | $result = $rowres['naam']; |
||
| 469 | } |
||
| 470 | if (isset($result)) { |
||
| 471 | return $result; |
||
| 472 | } else { |
||
| 473 | return ''; |
||
| 474 | } |
||
| 475 | } |
||
| 476 | |||
| 477 | /** |
||
| 478 | * @param $naam_hond |
||
| 479 | * |
||
| 480 | * @return mixed |
||
| 481 | */ |
||
| 482 | public static function findId($naam_hond) |
||
| 483 | { |
||
| 484 | $sqlquery = 'SELECT id FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE naam= '$naam_hond'"; |
||
| 485 | $queryresult = $GLOBALS['xoopsDB']->query($sqlquery); |
||
| 486 | while (false !== ($rowres = $GLOBALS['xoopsDB']->fetchArray($queryresult))) { |
||
| 487 | $result = $rowres['id']; |
||
| 488 | } |
||
| 489 | |||
| 490 | return $result; |
||
| 491 | } |
||
| 492 | |||
| 493 | /** |
||
| 494 | * @param $result |
||
| 495 | * @param $prefix |
||
| 496 | * @param $link |
||
| 497 | * @param $element |
||
| 498 | */ |
||
| 499 | public static function createList($result, $prefix, $link, $element) |
||
| 500 | { |
||
| 501 | global $xoopsTpl; |
||
| 502 | $animal = new Pedigree\Animal(); |
||
| 503 | //test to find out how many user fields there are... |
||
| 504 | $fields = $animal->getNumOfFields(); |
||
| 505 | $numofcolumns = 1; |
||
| 506 | $columns[] = ['columnname' => 'Name']; |
||
| 507 | foreach ($fields as $i => $iValue) { |
||
| 508 | $userField = new Pedigree\Field($fields[$i], $animal->getConfig()); |
||
| 509 | $fieldType = $userField->getSetting('fieldtype'); |
||
| 510 | $fieldObject = new $fieldType($userField, $animal); |
||
| 511 | if ($userField->isActive() && $userField->inList()) { |
||
| 512 | if ($userField->hasLookup()) { |
||
| 513 | $id = $userField->getId(); |
||
| 514 | $q = $userField->lookupField($id); |
||
| 515 | } else { |
||
| 516 | $q = ''; |
||
| 517 | } |
||
| 518 | $columns[] = [ |
||
| 519 | 'columnname' => $fieldObject->fieldname, |
||
| 520 | 'columnnumber' => $userField->getId(), |
||
| 521 | 'lookuparray' => $q |
||
| 522 | ]; |
||
| 523 | ++$numofcolumns; |
||
| 524 | } |
||
| 525 | } |
||
| 526 | |||
| 527 | //add preliminary row to array if passed |
||
| 528 | if (is_array($prefix)) { |
||
| 529 | $dogs[] = $prefix; |
||
| 530 | } |
||
| 531 | |||
| 532 | while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||
| 533 | //reset $gender |
||
| 534 | $gender = ''; |
||
| 535 | if ((!empty($GLOBALS['xoopsUser']) && $GLOBALS['xoopsUser'] instanceof \XoopsUser) |
||
| 536 | && ($row['user'] == $GLOBALS['xoopsUser']->getVar('uid') || true === $modadmin)) { |
||
| 537 | $gender = "<a href='dog.php?id={$row['id']}'><img src='assets/images/edit.png' alt='" . _EDIT . "'></a> |
||
| 538 | . <a href='delete.php?id={$row['id']}'><img src='assets/images/delete.png' alt='" . _DELETE . "'></a>"; |
||
| 539 | } |
||
| 540 | |||
| 541 | $genImg = (0 == $row['roft']) ? 'male.gif' : 'female.gif'; |
||
| 542 | $gender .= "<img src='assets/images/{$genImg}'>"; |
||
| 543 | |||
| 544 | if ('' != $row['foto']) { |
||
| 545 | $camera = ' <img src="assets/images/dog-icon25.png">'; |
||
| 546 | } else { |
||
| 547 | $camera = ''; |
||
| 548 | } |
||
| 549 | $name = stripslashes($row['naam']) . $camera; |
||
| 550 | unset($columnvalue); |
||
| 551 | |||
| 552 | //fill array |
||
| 553 | for ($i = 1; $i < $numofcolumns; ++$i) { |
||
| 554 | $x = $columns[$i]['columnnumber']; |
||
| 555 | $lookuparray = $columns[$i]['lookuparray']; |
||
| 556 | if (is_array($lookuparray)) { |
||
| 557 | foreach ($lookuparray as $index => $indexValue) { |
||
| 558 | if ($lookuparray[$index]['id'] == $row['user' . $x]) { |
||
| 559 | //echo "<h1>".$lookuparray[$index]['id']."</h1>"; |
||
| 560 | $value = $lookuparray[$index]['value']; |
||
| 561 | } |
||
| 562 | } |
||
| 563 | } //format value - cant use object because of query count |
||
| 564 | elseif (0 === strncmp($row['user' . $x], 'http://', 7)) { |
||
| 565 | $value = '<a href="' . $row['user' . $x] . '">' . $row['user' . $x] . '</a>'; |
||
| 566 | } else { |
||
| 567 | $value = $row['user' . $x]; |
||
| 568 | } |
||
| 569 | $columnvalue[] = ['value' => $value]; |
||
| 570 | unset($value); |
||
| 571 | } |
||
| 572 | |||
| 573 | $linkto = '<a href="' . $link . $row[$element] . '">' . $name . '</a>'; |
||
| 574 | //create array |
||
| 575 | $dogs[] = [ |
||
| 576 | 'id' => $row['id'], |
||
| 577 | 'name' => $name, |
||
| 578 | 'gender' => $gender, |
||
| 579 | 'link' => $linkto, |
||
| 580 | 'colour' => '', |
||
| 581 | 'number' => '', |
||
| 582 | 'usercolumns' => $columnvalue |
||
| 583 | ]; |
||
| 584 | } |
||
| 585 | |||
| 586 | //add data to smarty template |
||
| 587 | //assign dog |
||
| 588 | $xoopsTpl->assign('dogs', $dogs); |
||
| 589 | $xoopsTpl->assign('columns', $columns); |
||
| 590 | $xoopsTpl->assign('numofcolumns', $numofcolumns); |
||
| 591 | $xoopsTpl->assign('tsarray', self::sortTable($numofcolumns)); |
||
| 592 | } |
||
| 593 | |||
| 594 | /***************Blocks************** |
||
| 595 | * |
||
| 596 | * @param array|string $cats |
||
| 597 | * |
||
| 598 | * @return string (cat1, cat2, cat3, etc) for SQL statement |
||
| 599 | */ |
||
| 600 | public static function animal_block_addCatSelect($cats) |
||
| 601 | { |
||
| 602 | $cat_sql = ''; |
||
| 603 | if (is_array($cats)) { |
||
| 604 | $cats = array_map('intval', $cats); // make sure all cats are numbers |
||
| 605 | $cat_sql = '(' . implode(',', $cats) . ')'; |
||
| 606 | /* |
||
| 607 | $cat_sql = '(' . current($cats); |
||
| 608 | array_shift($cats); |
||
| 609 | foreach ($cats as $cat) { |
||
| 610 | $cat_sql .= ',' . $cat; |
||
| 611 | } |
||
| 612 | $cat_sql .= ')'; |
||
| 613 | */ |
||
| 614 | } else { |
||
| 615 | $cat_sql = '(' . (int)$cats . ')'; // not efficient but at least creates valid SQL statement |
||
| 616 | } |
||
| 617 | |||
| 618 | return $cat_sql; |
||
| 619 | } |
||
| 620 | |||
| 621 | /** |
||
| 622 | * @deprecated |
||
| 623 | * @param $global |
||
| 624 | * @param $key |
||
| 625 | * @param string $default |
||
| 626 | * @param string $type |
||
| 627 | * |
||
| 628 | * @return mixed|string |
||
| 629 | */ |
||
| 630 | public static function animal_CleanVars(&$global, $key, $default = '', $type = 'int') |
||
| 646 | } |
||
| 647 | |||
| 648 | /** |
||
| 649 | * @param $content |
||
| 650 | */ |
||
| 651 | public static function animal_meta_keywords($content) |
||
| 652 | { |
||
| 653 | global $xoopsTpl, $xoTheme; |
||
| 654 | $myts = \MyTextSanitizer::getInstance(); |
||
| 655 | $content = $myts->undoHtmlSpecialChars($myts->sanitizeForDisplay($content)); |
||
| 656 | if (isset($xoTheme) && is_object($xoTheme)) { |
||
| 657 | $xoTheme->addMeta('meta', 'keywords', strip_tags($content)); |
||
| 658 | } else { // Compatibility for old Xoops versions |
||
| 659 | $xoopsTpl->assign('xoops_meta_keywords', strip_tags($content)); |
||
| 660 | } |
||
| 661 | } |
||
| 662 | |||
| 663 | /** |
||
| 664 | * @param $content |
||
| 665 | */ |
||
| 666 | public static function animal_meta_description($content) |
||
| 667 | { |
||
| 668 | global $xoopsTpl, $xoTheme; |
||
| 669 | $myts = \MyTextSanitizer::getInstance(); |
||
| 670 | $content = $myts->undoHtmlSpecialChars($myts->displayTarea($content)); |
||
| 671 | if (isset($xoTheme) && is_object($xoTheme)) { |
||
| 672 | $xoTheme->addMeta('meta', 'description', strip_tags($content)); |
||
| 673 | } else { // Compatibility for old Xoops versions |
||
| 674 | $xoopsTpl->assign('xoops_meta_description', strip_tags($content)); |
||
| 675 | } |
||
| 676 | } |
||
| 677 | |||
| 678 | /** |
||
| 679 | * Verify that a mysql table exists |
||
| 680 | * |
||
| 681 | * @package pedigree |
||
| 682 | * @author Hervé Thouzard (http://www.herve-thouzard.com) |
||
| 683 | * @copyright (c) Hervé Thouzard |
||
| 684 | */ |
||
| 685 | //function tableExists($tablename) |
||
| 686 | //{ |
||
| 687 | // |
||
| 688 | // $result=$GLOBALS['xoopsDB']->queryF("SHOW TABLES LIKE '$tablename'"); |
||
| 689 | // return($GLOBALS['xoopsDB']->getRowsNum($result) > 0); |
||
| 690 | //} |
||
| 691 | |||
| 692 | /** |
||
| 693 | * Create download by letter choice bar/menu |
||
| 694 | * updated starting from this idea https://xoops.org/modules/news/article.php?storyid=6497 |
||
| 695 | * |
||
| 696 | * @param Pedigree\Helper $myObject |
||
| 697 | * @param $activeObject |
||
| 698 | * @param $criteria |
||
| 699 | * @param $name |
||
| 700 | * @param $link |
||
| 701 | * @param null $link2 |
||
| 702 | * @return string html |
||
| 703 | * |
||
| 704 | * @internal param $file |
||
| 705 | * @internal param $file2 |
||
| 706 | * @access public |
||
| 707 | * @author luciorota |
||
| 708 | */ |
||
| 709 | public static function lettersChoice($myObject, $activeObject, $criteria, $name, $link, $link2 = null) |
||
| 817 | } |
||
| 818 | |||
| 819 | /** |
||
| 820 | * @return bool |
||
| 821 | */ |
||
| 822 | public static function userIsAdmin() |
||
| 823 | { |
||
| 824 | $helper = Pedigree\Helper::getInstance(); |
||
| 825 | |||
| 826 | $pedigree_isAdmin = $helper->isUserAdmin(); |
||
| 827 | |||
| 828 | return $pedigree_isAdmin; |
||
| 829 | } |
||
| 830 | |||
| 831 | public static function getXoopsCpHeader() |
||
| 834 | } |
||
| 835 | |||
| 836 | /** |
||
| 837 | * Detemines if a table exists in the current db |
||
| 838 | * |
||
| 839 | * @param string $table the table name (without XOOPS prefix) |
||
| 840 | * |
||
| 841 | * @return bool True if table exists, false if not |
||
| 842 | * |
||
| 843 | * @access public |
||
| 844 | * @author xhelp development team |
||
| 845 | */ |
||
| 846 | public static function hasTable($table) |
||
| 847 | { |
||
| 848 | $bRetVal = false; |
||
| 849 | //Verifies that a MySQL table exists |
||
| 850 | $GLOBALS['xoopsDB'] = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 851 | $realName = $GLOBALS['xoopsDB']->prefix($table); |
||
| 852 | |||
| 853 | $sql = 'SHOW TABLES FROM ' . XOOPS_DB_NAME; |
||
| 854 | $ret = $GLOBALS['xoopsDB']->queryF($sql); |
||
| 855 | |||
| 856 | while (false !== (list($m_table) = $GLOBALS['xoopsDB']->fetchRow($ret))) { |
||
| 857 | if ($m_table == $realName) { |
||
| 858 | $bRetVal = true; |
||
| 859 | break; |
||
| 860 | } |
||
| 861 | } |
||
| 862 | $GLOBALS['xoopsDB']->freeRecordSet($ret); |
||
| 863 | |||
| 864 | return $bRetVal; |
||
| 865 | } |
||
| 866 | |||
| 867 | /** |
||
| 868 | * Gets a value from a key in the xhelp_meta table |
||
| 869 | * |
||
| 870 | * @param string $key |
||
| 871 | * |
||
| 872 | * @return string $value |
||
| 873 | * |
||
| 874 | * @access public |
||
| 875 | * @author xhelp development team |
||
| 876 | */ |
||
| 877 | public static function getMeta($key) |
||
| 878 | { |
||
| 879 | $GLOBALS['xoopsDB'] = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 880 | $sql = sprintf('SELECT metavalue FROM `%s` WHERE metakey= `%s` ', $GLOBALS['xoopsDB']->prefix('pedigree_meta'), $GLOBALS['xoopsDB']->quoteString($key)); |
||
| 881 | $ret = $GLOBALS['xoopsDB']->query($sql); |
||
| 882 | if (!$ret) { |
||
| 883 | $value = false; |
||
| 884 | } else { |
||
| 885 | list($value) = $GLOBALS['xoopsDB']->fetchRow($ret); |
||
| 886 | } |
||
| 887 | |||
| 888 | return $value; |
||
| 889 | } |
||
| 890 | |||
| 891 | /** |
||
| 892 | * Sets a value for a key in the xhelp_meta table |
||
| 893 | * |
||
| 894 | * @param string $key |
||
| 895 | * @param string $value |
||
| 896 | * |
||
| 897 | * @return bool true if success, false if failure |
||
| 898 | * |
||
| 899 | * @access public |
||
| 900 | * @author xhelp development team |
||
| 901 | */ |
||
| 902 | public static function setMeta($key, $value) |
||
| 903 | { |
||
| 904 | $GLOBALS['xoopsDB'] = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 905 | if (false !== ($ret = self::getMeta($key))) { |
||
| 906 | $sql = sprintf('UPDATE `%s` SET metavalue = `%s` WHERE metakey = `%s` ', $GLOBALS['xoopsDB']->prefix('pedigree_meta'), $GLOBALS['xoopsDB']->quoteString($value), $GLOBALS['xoopsDB']->quoteString($key)); |
||
| 907 | } else { |
||
| 908 | $sql = sprintf('INSERT INTO `%s` (metakey, metavalue) VALUES (`%s`, `%s` )', $GLOBALS['xoopsDB']->prefix('pedigree_meta'), $GLOBALS['xoopsDB']->quoteString($key), $GLOBALS['xoopsDB']->quoteString($value)); |
||
| 909 | } |
||
| 910 | $ret = $GLOBALS['xoopsDB']->queryF($sql); |
||
| 911 | if (!$ret) { |
||
| 912 | return false; |
||
| 913 | } |
||
| 914 | |||
| 915 | return true; |
||
| 916 | } |
||
| 917 | |||
| 918 | /** |
||
| 919 | * @param $name |
||
| 920 | * @param $value |
||
| 921 | * @param int $time |
||
| 922 | */ |
||
| 923 | public static function setCookieVar($name, $value, $time = 0) |
||
| 924 | { |
||
| 925 | if (0 == $time) { |
||
| 926 | $time = time() + 3600 * 24 * 365; |
||
| 927 | } |
||
| 928 | setcookie($name, $value, $time, '/', ini_get('session.cookie_domain'), ini_get('session.cookie_secure'), ini_get('session.cookie_httponly')); |
||
| 929 | } |
||
| 930 | |||
| 931 | /** |
||
| 932 | * @param $name |
||
| 933 | * @param string $default |
||
| 934 | * |
||
| 935 | * @return string |
||
| 936 | */ |
||
| 937 | public static function getCookieVar($name, $default = '') |
||
| 938 | { |
||
| 939 | if (isset($_COOKIE[$name]) && ($_COOKIE[$name] > '')) { |
||
| 940 | return $_COOKIE[$name]; |
||
| 941 | } else { |
||
| 942 | return $default; |
||
| 943 | } |
||
| 944 | } |
||
| 945 | |||
| 946 | /** |
||
| 947 | * @return array |
||
| 948 | */ |
||
| 949 | public static function getCurrentUrls() |
||
| 950 | { |
||
| 951 | $http = (false === strpos(XOOPS_URL, 'https://')) ? 'http://' : 'https://'; |
||
| 952 | $phpSelf = $_SERVER['PHP_SELF']; |
||
| 953 | $httpHost = $_SERVER['HTTP_HOST']; |
||
| 954 | $queryString = $_SERVER['QUERY_STRING']; |
||
| 955 | |||
| 956 | if ('' != $queryString) { |
||
| 957 | $queryString = '?' . $queryString; |
||
| 958 | } |
||
| 959 | |||
| 960 | $currentURL = $http . $httpHost . $phpSelf . $queryString; |
||
| 961 | |||
| 962 | $urls = []; |
||
| 963 | $urls['http'] = $http; |
||
| 964 | $urls['httphost'] = $httpHost; |
||
| 965 | $urls['phpself'] = $phpSelf; |
||
| 966 | $urls['querystring'] = $queryString; |
||
| 967 | $urls['full'] = $currentURL; |
||
| 968 | |||
| 969 | return $urls; |
||
| 970 | } |
||
| 971 | |||
| 972 | /** |
||
| 973 | * @return mixed |
||
| 974 | */ |
||
| 975 | public static function getCurrentPage() |
||
| 980 | } |
||
| 981 | |||
| 982 | /** |
||
| 983 | * @param array $errors |
||
| 984 | * |
||
| 985 | * @return string |
||
| 986 | */ |
||
| 987 | public static function formatErrors($errors = []) |
||
| 997 |
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: