Passed
Branch master (48d769)
by Michael
02:30
created

createList()   F

Complexity

Conditions 18
Paths 264

Size

Total Lines 93
Code Lines 62

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 18
eloc 62
nc 264
nop 4
dl 0
loc 93
rs 3.6714
c 1
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/*
3
 * You may not change or alter any portion of this comment or credits
4
 * of supporting developers from this source code or any supporting source code
5
 * which is considered copyrighted (c) material of the original comment or credit authors.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
/**
13
 * @copyright      {@link https://xoops.org/ XOOPS Project}
14
 * @license        {@link http://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later}
15
 * @package
16
 * @since
17
 * @author         XOOPS Development Team
18
 */
19
20
use XoopsModules\Pedigree;
21
22
// ------------------------------------------------------------------------- //
23
// Author: Tobias Liegl (AKA CHAPI)                                          //
24
// Site: http://www.chapi.de                                                 //
25
// Project: XOOPS Project                                                    //
26
// ------------------------------------------------------------------------- //
27
28
xoops_load('Pedigree\Animal', $moduleDirName);
0 ignored issues
show
Bug introduced by
The function xoops_load was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

28
/** @scrutinizer ignore-call */ 
29
xoops_load('Pedigree\Animal', $moduleDirName);
Loading history...
29
30
//get module configuration
31
/** @var XoopsModuleHandler $moduleHandler */
32
$moduleHandler = xoops_getHandler('module');
0 ignored issues
show
Bug introduced by
The function xoops_getHandler was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

32
$moduleHandler = /** @scrutinizer ignore-call */ xoops_getHandler('module');
Loading history...
33
$module        = $moduleHandler->getByDirname($moduleDirName);
34
$configHandler = xoops_getHandler('config');
35
$moduleConfig  = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
36
37
/**
38
 * @param $columncount
39
 *
40
 * @return string
41
 */
42
function sortTable($columncount)
43
{
44
    $ttemp = '';
45
    if ($columncount > 1) {
46
        for ($t = 1; $t < $columncount; ++$t) {
47
            $ttemp .= "'S',";
48
        }
49
        $tsarray = "initSortTable('Result', Array({$ttemp}'S'));";
50
    } else {
51
        $tsarray = "initSortTable('Result',Array('S'));";
52
    }
53
54
    return $tsarray;
55
}
56
57
/**
58
 * @param $num
59
 *
60
 * @return string
61
 */
62
function uploadPicture($num)
63
{
64
    $max_imgsize       = $GLOBALS['xoopsModuleConfig']['maxfilesize']; //1024000;
65
    $max_imgwidth      = $GLOBALS['xoopsModuleConfig']['maximgwidth']; //1500;
66
    $max_imgheight     = $GLOBALS['xoopsModuleConfig']['maximgheight']; //1000;
67
    $allowed_mimetypes = ['image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png'];
68
    //    $img_dir = XOOPS_ROOT_PATH . "/modules/" . $GLOBALS['xoopsModule']->dirname() . "/images" ;
69
    $img_dir = $GLOBALS['xoopsModuleConfig']['uploaddir'] . '/images';
70
    require_once $GLOBALS['xoops']->path('class/uploader.php');
71
    $field = $_POST['xoops_upload_file'][$num];
72
    if (!empty($field) || '' != $field) {
73
        $uploader = new \XoopsMediaUploader($img_dir, $allowed_mimetypes, $max_imgsize, $max_imgwidth, $max_imgheight);
0 ignored issues
show
Bug introduced by
The type XoopsMediaUploader 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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
74
        $uploader->setPrefix('img');
75
        if ($uploader->fetchMedia($field) && $uploader->upload()) {
76
            $photo = $uploader->getSavedFileName();
77
        } else {
78
            echo $uploader->getErrors();
79
        }
80
        createThumbs($photo);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $photo does not seem to be defined for all execution paths leading up to this point.
Loading history...
81
82
        return $photo;
83
    }
84
}
85
86
/**
87
 * @param $filename
88
 *
89
 * @return void
90
 */
91
function createThumbs($filename)
92
{/*
93
    require_once('phpthumb/phpthumb.class.php');
94
    $thumbnail_widths = array(150, 400);
95
    foreach ($thumbnail_widths as $thumbnail_width) {
96
        $phpThumb = new phpThumb();
97
        // set data
98
        $phpThumb->setSourceFilename('images/' . $filename);
99
        $phpThumb->w                    = $thumbnail_width;
100
        $phpThumb->config_output_format = 'jpeg';
101
        // generate & output thumbnail
102
        $output_filename = 'images/thumbnails/' . basename($filename) . '_' . $thumbnail_width . '.' . $phpThumb->config_output_format;
103
        if ($phpThumb->GenerateThumbnail()) { // this line is VERY important, do not remove it!
104
            if ($output_filename) {
105
                if ($phpThumb->RenderToFile($output_filename)) {
106
                    // do something on success
107
                    //echo 'Successfully rendered:<br><img src="'.$output_filename.'">';
108
                } else {
109
                    echo 'Failed (size=' . $thumbnail_width . '):<pre>' . implode("\n\n", $phpThumb->debugmessages) . '</pre>';
110
                }
111
            }
112
        } else {
113
            echo 'Failed (size=' . $thumbnail_width . '):<pre>' . implode("\n\n", $phpThumb->debugmessages) . '</pre>';
114
        }
115
        unset($phpThumb);
116
    }
117
118
    return true;
119
120
    */
121
122
    // load the image
123
    require_once $GLOBALS['xoops']->path('modules/' . $GLOBALS['xoopsModule']->dirname() . '/library/Zebra_Image.php');
124
    $thumbnail_widths = [150, 400];
125
126
    // indicate a target image
127
    // note that there's no extra property to set in order to specify the target
128
    // image's type -simply by writing '.jpg' as extension will instruct the script
129
    // to create a 'jpg' file
130
    $config_output_format = 'jpeg';
131
132
    // create a new instance of the class
133
    $image = new Zebra_Image();
134
    // indicate a source image (a GIF, PNG or JPEG file)
135
    $image->source_path = PEDIGREE_UPLOAD_PATH . "/images/{$filename}";
136
137
    foreach ($thumbnail_widths as $thumbnail_width) {
138
139
        // generate & output thumbnail
140
        $output_filename    = PEDIGREE_UPLOAD_PATH . '/images/thumbnails/' . basename($filename) . "_{$thumbnail_width}.{$config_output_format}";
141
        $image->target_path = $output_filename;
142
        // since in this example we're going to have a jpeg file, let's set the output
143
        // image's quality
144
        $image->jpeg_quality = 100;
145
        // some additional properties that can be set
146
        // read about them in the documentation
147
        $image->preserve_aspect_ratio  = true;
148
        $image->enlarge_smaller_images = true;
149
        $image->preserve_time          = true;
150
151
        // resize the image to exactly 100x100 pixels by using the "crop from center" method
152
        // (read more in the overview section or in the documentation)
153
        //  and if there is an error, check what the error is about
154
        if (!$image->resize($thumbnail_width, 0)) {
155
            // if there was an error, let's see what the error is about
156
            switch ($image->error) {
157
158
                case 1:
159
                    echo 'Source file could not be found!';
160
                    break;
161
                case 2:
162
                    echo 'Source file is not readable!';
163
                    break;
164
                case 3:
165
                    echo 'Could not write target file!';
166
                    break;
167
                case 4:
168
                    echo 'Unsupported source file format!';
169
                    break;
170
                case 5:
171
                    echo 'Unsupported target file format!';
172
                    break;
173
                case 6:
174
                    echo 'GD library version does not support target file format!';
175
                    break;
176
                case 7:
177
                    echo 'GD library is not installed!';
178
                    break;
179
                case 8:
180
                    echo '"chmod" command is disabled via configuration!';
181
                    break;
182
            }
183
184
            // if no errors
185
        } else {
186
            echo 'Success!';
187
        }
188
189
        /*
190
                if ($phpThumb->GenerateThumbnail()) { // this line is VERY important, do not remove it!
191
                    if ($output_filename) {
192
                        if ($phpThumb->RenderToFile($output_filename)) {
193
                            // do something on success
194
                            //echo 'Successfully rendered:<br><img src="'.$output_filename.'">';
195
                        } else {
196
                            echo 'Failed (size='.$thumbnail_width.'):<pre>'.implode("\n\n", $phpThumb->debugmessages).'</pre>';
197
                        }
198
                    }
199
                } else {
200
                    echo 'Failed (size='.$thumbnail_width.'):<pre>'.implode("\n\n", $phpThumb->debugmessages).'</pre>';
201
                }
202
 */
203
    }
204
205
    unset($image);
206
}
207
208
/**
209
 * @param $string
210
 *
211
 * @return string
212
 */
213
function unHtmlEntities($string)
214
{
215
    $trans_tbl = get_html_translation_table(HTML_ENTITIES);
216
    $trans_tbl = array_flip($trans_tbl);
217
218
    return strtr($string, $trans_tbl);
219
}
220
221
/**
222
 * @param $oid
223
 * @param $gender
224
 *
225
 * @return null
226
 */
227
function pups($oid, $gender)
228
{
229
    global $numofcolumns, $numMatch, $pages, $columns, $dogs;
230
    $content = '';
0 ignored issues
show
Unused Code introduced by
The assignment to $content is dead and can be removed.
Loading history...
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
    for ($i = 0, $iMax = count($fields); $i < $iMax; ++$i) {
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
282
    while (false !== ($rowResult = $GLOBALS['xoopsDB']->fetchArray($queryResult))) {
283
        if ('0' == $rowResult['d_roft']) {
284
            $gender = '<img src="assets/images/male.gif">';
285
        } else {
286
            $gender = '<img src="assets/images/female.gif">';
287
        }
288
        $name = stripslashes($rowResult['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'] == $rowResult['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($rowResult['user' . $x], 'http://', 7)) {
304
                $value = '<a href="' . $rowResult['user' . $x] . '">' . $rowResult['user' . $x] . '</a>';
305
            } else {
306
                $value = $rowResult['user' . $x];
307
            }
308
            $columnvalue[] = ['value' => $value];
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $value does not seem to be defined for all execution paths leading up to this point.
Loading history...
309
        }
310
        $dogs[] = [
311
            'id'          => $rowResult['d_id'],
312
            'name'        => $name,
313
            'gender'      => $gender,
314
            'link'        => '<a href="dog.php?id=' . $rowResult['d_id'] . '">' . $name . '</a>',
315
            'colour'      => '',
316
            'number'      => '',
317
            'usercolumns' => $columnvalue
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $columnvalue does not seem to be defined for all execution paths leading up to this point.
Loading history...
318
        ];
319
    }
320
321
    return null;
322
}
323
324
/**
325
 * @param $oid
326
 * @param $pa
327
 * @param $ma
328
 *
329
 * @return null
330
 */
331
function bas($oid, $pa, $ma)
332
{
333
    global $numofcolumns1, $nummatch1, $pages1, $columns1, $dogs1;
334
    if ('0' == $pa && '0' == $ma) {
335
        $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";
336
    } else {
337
        $sqlQuery = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' WHERE father = ' . $pa . ' AND mother = ' . $ma . ' AND id != ' . $oid . ' ORDER BY naam';
338
    }
339
    $queryResult = $GLOBALS['xoopsDB']->query($sqlQuery);
340
    $nummatch1   = $GLOBALS['xoopsDB']->getRowsNum($queryResult);
341
342
    $animal = new Pedigree\Animal();
343
    //test to find out how many user fields there are...
344
    $fields        = $animal->getNumOfFields();
345
    $numofcolumns1 = 1;
346
    $columns1[]    = ['columnname' => 'Name'];
347
    for ($i = 0, $iMax = count($fields); $i < $iMax; ++$i) {
348
        $userField   = new Pedigree\Field($fields[$i], $animal->getConfig());
349
        $fieldType   = $userField->getSetting('FieldType');
350
        $fieldObject = new $fieldType($userField, $animal);
351
        //create empty string
352
        $lookupValues = '';
353
        if ($userField->isActive() && $userField->inList()) {
354
            if ($userField->hasLookup()) {
355
                $lookupValues = $userField->lookupField($fields[$i]);
356
                //debug information
357
                //print_r($lookupValues);
358
            }
359
            $columns1[] = [
360
                'columnname'   => $fieldObject->fieldname,
361
                'columnnumber' => $userField->getId(),
362
                'lookupval'    => $lookupValues
363
            ];
364
            ++$numofcolumns1;
365
            unset($lookupValues);
366
        }
367
    }
368
369
    while (false !== ($rowResult = $GLOBALS['xoopsDB']->fetchArray($queryResult))) {
370
        if (0 == $rowResult['roft']) {
371
            $gender = "<img src='assets/images/male.gif'>";
372
        } else {
373
            $gender = "<img src='assets/images/female.gif'>";
374
        }
375
        $name = stripslashes($rowResult['naam']);
376
        //empty array
377
        //        unset($columnvalue1);
378
        $columnvalue1 = [];
379
        //fill array
380
        for ($i = 1; $i < $numofcolumns1; ++$i) {
381
            $x = $columns1[$i]['columnnumber'];
382
            if (is_array($columns1[$i]['lookupval'])) {
383
                foreach ($columns1[$i]['lookupval'] as $key => $keyValue) {
384
                    if ($keyValue['id'] == $rowResult['user' . $x]) {
385
                        $value = $keyValue['value'];
386
                    }
387
                }
388
                //debug information
389
                ///echo $columns[$i]['columnname']."is an array !";
390
            } //format value - cant use object because of query count
391
            elseif (0 === strncmp($rowResult['user' . $x], 'http://', 7)) {
392
                $value = '<a href="' . $rowResult['user' . $x] . '">' . $rowResult['user' . $x] . '</a>';
393
            } else {
394
                $value = $rowResult['user' . $x];
395
            }
396
            $columnvalue1[] = ['value' => $value];
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $value does not seem to be defined for all execution paths leading up to this point.
Loading history...
397
        }
398
        $dogs1[] = [
399
            'id'          => $rowResult['id'],
400
            'name'        => $name,
401
            'gender'      => $gender,
402
            'link'        => '<a href="dog.php?id=' . $rowResult['id'] . '">' . $name . '</a>',
403
            'colour'      => '',
404
            'number'      => '',
405
            'usercolumns' => $columnvalue1
406
        ];
407
    }
408
409
    return null;
410
}
411
412
/**
413
 * @param $oid
414
 * @param $breeder
415
 *
416
 * @return string
417
 */
418
function breederof($oid, $breeder)
419
{
420
    $content = '';
421
422
    if (0 == $breeder) {
423
        $sqlQuery = 'SELECT id, naam, roft FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE id_owner = '" . $oid . "' ORDER BY naam";
424
    } else {
425
        $sqlQuery = 'SELECT id, naam, roft FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE id_breeder = '" . $oid . "' ORDER BY naam";
426
    }
427
    $queryResult = $GLOBALS['xoopsDB']->query($sqlQuery);
428
    while (false !== ($rowResult = $GLOBALS['xoopsDB']->fetchArray($queryResult))) {
429
        if ('0' == $rowResult['roft']) {
430
            $gender = '<img src="assets/images/male.gif">';
431
        } else {
432
            $gender = '<img src="assets/images/female.gif">';
433
        }
434
        $link    = '<a href="dog.php?id=' . $rowResult['id'] . '">' . stripslashes($rowResult['naam']) . '</a>';
435
        $content .= $gender . ' ' . $link . '<br>';
436
    }
437
438
    return $content;
439
}
440
441
/**
442
 * @param $oid
443
 *
444
 * @return string
445
 */
446
function getName($oid)
447
{
448
    $oid         = (int)$oid;
449
    $sqlQuery    = 'SELECT naam FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE id = '{$oid}'";
450
    $queryResult = $GLOBALS['xoopsDB']->query($sqlQuery);
451
    while (false !== ($rowResult = $GLOBALS['xoopsDB']->fetchArray($queryResult))) {
452
        $an = stripslashes($rowResult['naam']);
453
    }
454
455
    return $an;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $an does not seem to be defined for all execution paths leading up to this point.
Loading history...
456
}
457
458
/**
459
 * @param $PA
460
 */
461
function showParent($PA)
462
{
463
    $sqlQuery    = 'SELECT naam FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE id='" . $PA . "'";
464
    $queryResult = $GLOBALS['xoopsDB']->query($sqlQuery);
465
    while (false !== ($rowResult = $GLOBALS['xoopsDB']->fetchArray($queryResult))) {
466
        $result = $rowResult['naam'];
467
    }
468
    if (isset($result)) {
469
        return $result;
470
    } else {
471
        return;
472
    }
473
}
474
475
/**
476
 * @param $naam_hond
477
 *
478
 * @return mixed
479
 */
480
function findId($naam_hond)
481
{
482
    $sqlQuery    = 'SELECT id FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " where naam= '$naam_hond'";
483
    $queryResult = $GLOBALS['xoopsDB']->query($sqlQuery);
484
    while (false !== ($rowResult = $GLOBALS['xoopsDB']->fetchArray($queryResult))) {
485
        $result = $rowResult['id'];
486
    }
487
488
    return $result;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $result does not seem to be defined for all execution paths leading up to this point.
Loading history...
489
}
490
491
/**
492
 * @param $result
493
 * @param $prefix
494
 * @param $link
495
 * @param $element
496
 */
497
function createList($result, $prefix, $link, $element)
498
{
499
    global $xoopsTpl;
500
    $animal = new Pedigree\Animal();
501
    //test to find out how many user fields there are...
502
    $fields       = $animal->getNumOfFields();
503
    $numofcolumns = 1;
504
    $columns[]    = ['columnname' => 'Name'];
0 ignored issues
show
Comprehensibility Best Practice introduced by
$columns was never initialized. Although not strictly required by PHP, it is generally a good practice to add $columns = array(); before regardless.
Loading history...
505
    for ($i = 0, $iMax = count($fields); $i < $iMax; ++$i) {
506
        $userField   = new Pedigree\Field($fields[$i], $animal->getConfig());
507
        $fieldType   = $userField->getSetting('FieldType');
508
        $fieldObject = new $fieldType($userField, $animal);
509
        if ($userField->isActive() && $userField->inList()) {
510
            if ($userField->hasLookup()) {
511
                $id = $userField->getId();
512
                $q  = $userField->lookupField($id);
513
            } else {
514
                $q = '';
515
            }
516
            $columns[] = [
517
                'columnname'   => $fieldObject->fieldname,
518
                'columnnumber' => $userField->getId(),
519
                'lookuparray'  => $q
520
            ];
521
            ++$numofcolumns;
522
        }
523
    }
524
525
    //add preliminary row to array if passed
526
    if (is_array($prefix)) {
527
        $dogs[] = $prefix;
0 ignored issues
show
Comprehensibility Best Practice introduced by
$dogs was never initialized. Although not strictly required by PHP, it is generally a good practice to add $dogs = array(); before regardless.
Loading history...
528
    }
529
530
    while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
531
        //reset $gender
532
        $gender = '';
533
        if ((!empty($GLOBALS['xoopsUser']) && $GLOBALS['xoopsUser'] instanceof \XoopsUser)
0 ignored issues
show
Bug introduced by
The type XoopsUser 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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
534
            && ($row['user'] == $GLOBALS['xoopsUser']->getVar('uid') || true === $modadmin)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $modadmin seems to be never defined.
Loading history...
535
            $gender = "<a href='dog.php?id={$row['id']}'><img src='images/edit.png' alt='" . _EDIT . "'></a>
0 ignored issues
show
Bug introduced by
The constant _EDIT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
536
                     . <a href='delete.php?id={$row['id']}'><img src='images/delete.png' alt='" . _DELETE . "'></a>";
0 ignored issues
show
Bug introduced by
The constant _DELETE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
537
        }
538
539
        $genImg = (0 == $row['roft']) ? 'male.gif' : 'female.gif';
540
        $gender .= "<img src='assets/images/{$genImg}'>";
541
542
        if ('' != $row['foto']) {
543
            $camera = ' <img src="' . PEDIGREE_UPLOAD_URL . '/images/dog-icon25.png">';
544
        } else {
545
            $camera = '';
546
        }
547
        $name = stripslashes($row['naam']) . $camera;
548
        unset($columnvalue);
549
550
        //fill array
551
        for ($i = 1; $i < $numofcolumns; ++$i) {
552
            $x           = $columns[$i]['columnnumber'];
553
            $lookuparray = $columns[$i]['lookuparray'];
554
            if (is_array($lookuparray)) {
555
                for ($index = 0, $indexMax = count($lookuparray); $index < $indexMax; ++$index) {
556
                    if ($lookuparray[$index]['id'] == $row['user' . $x]) {
557
                        //echo "<h1>".$lookuparray[$index]['id']."</h1>";
558
                        $value = $lookuparray[$index]['value'];
559
                    }
560
                }
561
            } //format value - cant use object because of query count
562
            elseif (0 === strncmp($row['user' . $x], 'http://', 7)) {
563
                $value = '<a href="' . $row['user' . $x] . '">' . $row['user' . $x] . '</a>';
564
            } else {
565
                $value = $row['user' . $x];
566
            }
567
            $columnvalue[] = ['value' => $value];
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $value does not seem to be defined for all execution paths leading up to this point.
Loading history...
568
            unset($value);
569
        }
570
571
        $linkto = '<a href="' . $link . $row[$element] . '">' . $name . '</a>';
572
        //create array
573
        $dogs[] = [
574
            'id'          => $row['id'],
575
            'name'        => $name,
576
            'gender'      => $gender,
577
            'link'        => $linkto,
578
            'colour'      => '',
579
            'number'      => '',
580
            'usercolumns' => $columnvalue
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $columnvalue does not seem to be defined for all execution paths leading up to this point.
Loading history...
581
        ];
582
    }
583
584
    //add data to smarty template
585
    //assign dog
586
    $xoopsTpl->assign('dogs', $dogs);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $dogs does not seem to be defined for all execution paths leading up to this point.
Loading history...
587
    $xoopsTpl->assign('columns', $columns);
588
    $xoopsTpl->assign('numofcolumns', $numofcolumns);
589
    $xoopsTpl->assign('tsarray', Pedigree\Utility::sortTable($numofcolumns));
590
}
591
592
/***************Blocks**************
593
 *
594
 * @param $cats
595
 *
596
 * @return string
597
 */
598
function animal_block_addCatSelect($cats)
599
{
600
    if (is_array($cats)) {
601
        $cat_sql = '(' . current($cats);
602
        array_shift($cats);
603
        foreach ($cats as $cat) {
604
            $cat_sql .= ',' . $cat;
605
        }
606
        $cat_sql .= ')';
607
    }
608
609
    return $cat_sql;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $cat_sql does not seem to be defined for all execution paths leading up to this point.
Loading history...
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
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
function animal_meta_keywords($content)
643
{
644
    global $xoopsTpl, $xoTheme;
645
    $myts    = \MyTextSanitizer::getInstance();
0 ignored issues
show
Bug introduced by
The type MyTextSanitizer 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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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
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
 * @return string html
688
 *
689
 * @access  public
690
 * @author  luciorota
691
 */
692
function lettersChoice()
693
{
694
    $helper = Pedigree\Helper::getInstance();
695
    xoops_load('XoopsLocal');
0 ignored issues
show
Bug introduced by
The function xoops_load was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

695
    /** @scrutinizer ignore-call */ 
696
    xoops_load('XoopsLocal');
Loading history...
696
697
    $criteria = $helper->getHandler('Tree')->getActiveCriteria();
698
    $criteria->setGroupby('UPPER(LEFT(naam,1))');
699
    $countsByLetters = $helper->getHandler('Tree')->getCounts($criteria);
700
    // Fill alphabet array
701
    //    $alphabet       = XoopsLocal::getAlphabet();
702
    //        $xLocale = new \XoopsLocal;
703
    //        $alphabet =  $xLocale->getAlphabet();
704
    $alphabet       = pedigreeGetAlphabet();
705
    $alphabet_array = [];
706
    foreach ($alphabet as $letter) {
707
        $letter_array = [];
708
        if (isset($countsByLetters[$letter])) {
709
            $letter_array['letter'] = $letter;
710
            $letter_array['count']  = $countsByLetters[$letter];
711
            //            $letter_array['url']    = "" . XOOPS_URL . "/modules/" . $helper->getModule()->dirname() . "/viewcat.php?list={$letter}";
712
            $letter_array['url'] = '' . XOOPS_URL . '/modules/' . $helper->getModule()->dirname() . "/result.php?f=naam&amp;l=1&amp;w={$letter}%25&amp;o=naam";
0 ignored issues
show
Bug introduced by
The constant XOOPS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
713
        } else {
714
            $letter_array['letter'] = $letter;
715
            $letter_array['count']  = 0;
716
            $letter_array['url']    = '';
717
        }
718
        $alphabet_array[$letter] = $letter_array;
719
        unset($letter_array);
720
    }
721
    // Render output
722
    if (!isset($GLOBALS['xoTheme']) || !is_object($GLOBALS['xoTheme'])) {
723
        require_once $GLOBALS['xoops']->path('class/theme.php');
724
        $GLOBALS['xoTheme'] = new \xos_opal_Theme();
0 ignored issues
show
Bug introduced by
The type xos_opal_Theme 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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
725
    }
726
    require_once $GLOBALS['xoops']->path('class/template.php');
727
    $letterschoiceTpl          = new \XoopsTpl();
0 ignored issues
show
Bug introduced by
The type XoopsTpl 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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
728
    $letterschoiceTpl->caching = false; // Disable cache
729
    $letterschoiceTpl->assign('alphabet', $alphabet_array);
730
    $html = $letterschoiceTpl->fetch('db:' . $helper->getModule()->dirname() . '_common_letterschoice.tpl');
731
    unset($letterschoiceTpl);
732
733
    return $html;
734
}
735
736
/**
737
 * @return bool
738
 */
739
function userIsAdmin()
740
{
741
    $helper = Pedigree\Helper::getInstance();
742
743
    static $pedigree_isAdmin;
744
745
    if (isset($pedigree_isAdmin)) {
746
        return $pedigree_isAdmin;
747
    }
748
749
    if (!$GLOBALS['xoopsUser']) {
750
        $pedigree_isAdmin = false;
751
    } else {
752
        $pedigree_isAdmin = $GLOBALS['xoopsUser']->isAdmin($helper->getModule()->getVar('mid'));
753
    }
754
755
    return $pedigree_isAdmin;
756
}
757
758
function getXoopsCpHeader()
759
{
760
    xoops_cp_header();
0 ignored issues
show
Bug introduced by
The function xoops_cp_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

760
    /** @scrutinizer ignore-call */ 
761
    xoops_cp_header();
Loading history...
761
}
762
763
/**
764
 * @param bool $withLink
765
 *
766
 * @return string
767
 */
768
function getModuleName($withLink = true)
769
{
770
    $helper = Pedigree\Helper::getInstance();
771
772
    $pedigreeModuleName = $helper->getModule()->getVar('name');
773
    if (!$withLink) {
774
        return $pedigreeModuleName;
775
    } else {
776
        return '<a href="' . PEDIGREE_URL . '/">{$pedigreeModuleName}</a>';
777
    }
778
}
779
780
/**
781
 * Detemines if a table exists in the current db
782
 *
783
 * @param string $table the table name (without XOOPS prefix)
784
 *
785
 * @return bool True if table exists, false if not
786
 *
787
 * @access public
788
 * @author xhelp development team
789
 */
790
function hasTable($table)
791
{
792
    $bRetVal = false;
793
    //Verifies that a MySQL table exists
794
    $GLOBALS['xoopsDB'] = \XoopsDatabaseFactory::getDatabaseConnection();
0 ignored issues
show
Bug introduced by
The type XoopsDatabaseFactory 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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
795
    $realName           = $GLOBALS['xoopsDB']->prefix($table);
796
797
    $sql = 'SHOW TABLES FROM ' . XOOPS_DB_NAME;
0 ignored issues
show
Bug introduced by
The constant XOOPS_DB_NAME was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
798
    $ret = $GLOBALS['xoopsDB']->queryF($sql);
799
800
    while (false !== (list($m_table) = $GLOBALS['xoopsDB']->fetchRow($ret))) {
801
        if ($m_table == $realName) {
802
            $bRetVal = true;
803
            break;
804
        }
805
    }
806
    $GLOBALS['xoopsDB']->freeRecordSet($ret);
807
808
    return $bRetVal;
809
}
810
811
/**
812
 * Gets a value from a key in the xhelp_meta table
813
 *
814
 * @param string $key
815
 *
816
 * @return string $value
817
 *
818
 * @access public
819
 * @author xhelp development team
820
 */
821
function getMeta($key)
822
{
823
    $GLOBALS['xoopsDB'] = \XoopsDatabaseFactory::getDatabaseConnection();
824
    $sql                = sprintf('SELECT metavalue FROM `%s` WHERE metakey= `%s` ', $GLOBALS['xoopsDB']->prefix('pedigree_meta'), $GLOBALS['xoopsDB']->quoteString($key));
825
    $ret                = $GLOBALS['xoopsDB']->query($sql);
826
    if (!$ret) {
827
        $value = false;
828
    } else {
829
        list($value) = $GLOBALS['xoopsDB']->fetchRow($ret);
830
    }
831
832
    return $value;
833
}
834
835
/**
836
 * Sets a value for a key in the xhelp_meta table
837
 *
838
 * @param string $key
839
 * @param string $value
840
 *
841
 * @return bool true if success, false if failure
842
 *
843
 * @access public
844
 * @author xhelp development team
845
 */
846
function setMeta($key, $value)
847
{
848
    $GLOBALS['xoopsDB'] = \XoopsDatabaseFactory::getDatabaseConnection();
849
    if (false !== ($ret = Pedigree\Utility::getMeta($key))) {
0 ignored issues
show
Unused Code introduced by
The assignment to $ret is dead and can be removed.
Loading history...
introduced by
The condition false !== $ret = XoopsMo...\Utility::getMeta($key) is always true.
Loading history...
850
        $sql = sprintf('UPDATE `%s` SET metavalue = `%s` WHERE metakey = `%s` ', $GLOBALS['xoopsDB']->prefix('pedigree_meta'), $GLOBALS['xoopsDB']->quoteString($value), $GLOBALS['xoopsDB']->quoteString($key));
851
    } else {
852
        $sql = sprintf('INSERT INTO `%s` (metakey, metavalue) VALUES (`%s`, `%s`)', $GLOBALS['xoopsDB']->prefix('pedigree_meta'), $GLOBALS['xoopsDB']->quoteString($key), $GLOBALS['xoopsDB']->quoteString($value));
853
    }
854
    $ret = $GLOBALS['xoopsDB']->queryF($sql);
855
    if (!$ret) {
856
        return false;
857
    }
858
859
    return true;
860
}
861
862
/**
863
 * @param     $name
864
 * @param     $value
865
 * @param int $time
866
 */
867
function setCookieVar($name, $value, $time = 0)
868
{
869
    if (0 == $time) {
870
        $time = time() + 3600 * 24 * 365;
871
        //$time = '';
872
    }
873
    setcookie($name, $value, $time, '/', ini_get('session.cookie_domain'), ini_get('session.cookie_secure'), ini_get('session.cookie_httponly'));
0 ignored issues
show
Bug introduced by
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 ignore-type  annotation

873
    setcookie($name, $value, $time, '/', ini_get('session.cookie_domain'), /** @scrutinizer ignore-type */ ini_get('session.cookie_secure'), ini_get('session.cookie_httponly'));
Loading history...
Bug introduced by
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 ignore-type  annotation

873
    setcookie($name, $value, $time, '/', ini_get('session.cookie_domain'), ini_get('session.cookie_secure'), /** @scrutinizer ignore-type */ ini_get('session.cookie_httponly'));
Loading history...
874
}
875
876
/**
877
 * @param        $name
878
 * @param string $default
879
 *
880
 * @return string
881
 */
882
function getCookieVar($name, $default = '')
883
{
884
    if (isset($_COOKIE[$name]) && ($_COOKIE[$name] > '')) {
885
        return $_COOKIE[$name];
886
    } else {
887
        return $default;
888
    }
889
}
890
891
/**
892
 * @return array
893
 */
894
function getCurrentUrls()
895
{
896
    $http        = (false === strpos(XOOPS_URL, 'https://')) ? 'http://' : 'https://';
0 ignored issues
show
Bug introduced by
The constant XOOPS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
897
    $phpSelf     = $_SERVER['PHP_SELF'];
898
    $httpHost    = $_SERVER['HTTP_HOST'];
899
    $queryString = $_SERVER['QUERY_STRING'];
900
901
    if ('' != $queryString) {
902
        $queryString = '?' . $queryString;
903
    }
904
905
    $currentURL = $http . $httpHost . $phpSelf . $queryString;
906
907
    $urls                = [];
908
    $urls['http']        = $http;
909
    $urls['httphost']    = $httpHost;
910
    $urls['phpself']     = $phpSelf;
911
    $urls['querystring'] = $queryString;
912
    $urls['full']        = $currentURL;
913
914
    return $urls;
915
}
916
917
/**
918
 * @return mixed
919
 */
920
function getCurrentPage()
921
{
922
    $urls = Pedigree\Utility::getCurrentUrls();
923
924
    return $urls['full'];
925
}
926
927
/**
928
 * @param array $errors
929
 *
930
 * @return string
931
 */
932
function formatErrors($errors = [])
933
{
934
    $ret = '';
935
    foreach ($errors as $key => $value) {
936
        $ret .= "<br> - {$value}";
937
    }
938
939
    return $ret;
940
}
941