Passed
Push — master ( 169298...1b648e )
by Michael
35s queued 13s
created

getXoopsCpHeader()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 42 and the first side effect is on line 28.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
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);
29
30
//get module configuration
31
/** @var XoopsModuleHandler $moduleHandler */
32
$moduleHandler = xoops_getHandler('module');
33
$module        = $moduleHandler->getByDirname($moduleDirName);
34
$configHandler = xoops_getHandler('config');
35
$moduleConfig  = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
0 ignored issues
show
Bug introduced by
The method getConfigsByCat() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsPersistableObjectHandler. ( Ignorable by Annotation )

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

35
$moduleConfig  = $configHandler->/** @scrutinizer ignore-call */ getConfigsByCat(0, $module->getVar('mid'));
Loading history...
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;
0 ignored issues
show
Unused Code Comprehensibility introduced by
100% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
65
    $max_imgwidth      = $GLOBALS['xoopsModuleConfig']['maximgwidth']; //1500;
0 ignored issues
show
Unused Code Comprehensibility introduced by
100% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
66
    $max_imgheight     = $GLOBALS['xoopsModuleConfig']['maximgheight']; //1000;
0 ignored issues
show
Unused Code Comprehensibility introduced by
100% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
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" ;
0 ignored issues
show
Unused Code Comprehensibility introduced by
41% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
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);
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
    return '';
85
}
86
87
/**
88
 * @param $filename
89
 *
90
 * @return void
91
 */
92
function createThumbs($filename)
93
{/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
47% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
94
    require_once('phpthumb/phpthumb.class.php');
95
    $thumbnail_widths = array(150, 400);
96
    foreach ($thumbnail_widths as $thumbnail_width) {
97
        $phpThumb = new phpThumb();
98
        // set data
99
        $phpThumb->setSourceFilename('images/' . $filename);
100
        $phpThumb->w                    = $thumbnail_width;
101
        $phpThumb->config_output_format = 'jpeg';
102
        // generate & output thumbnail
103
        $output_filename = 'images/thumbnails/' . basename($filename) . '_' . $thumbnail_width . '.' . $phpThumb->config_output_format;
104
        if ($phpThumb->GenerateThumbnail()) { // this line is VERY important, do not remove it!
105
            if ($output_filename) {
106
                if ($phpThumb->RenderToFile($output_filename)) {
107
                    // do something on success
108
                    //echo 'Successfully rendered:<br><img src="'.$output_filename.'">';
109
                } else {
110
                    echo 'Failed (size=' . $thumbnail_width . '):<pre>' . implode("\n\n", $phpThumb->debugmessages) . '</pre>';
111
                }
112
            }
113
        } else {
114
            echo 'Failed (size=' . $thumbnail_width . '):<pre>' . implode("\n\n", $phpThumb->debugmessages) . '</pre>';
115
        }
116
        unset($phpThumb);
117
    }
118
119
    return true;
120
121
    */
122
123
    // load the image
124
    require_once $GLOBALS['xoops']->path('modules/' . $GLOBALS['xoopsModule']->dirname() . '/library/Zebra_Image.php');
125
    $thumbnail_widths = [150, 400];
126
127
    // indicate a target image
128
    // note that there's no extra property to set in order to specify the target
129
    // image's type -simply by writing '.jpg' as extension will instruct the script
130
    // to create a 'jpg' file
131
    $config_output_format = 'jpeg';
132
133
    // create a new instance of the class
134
    $image = new Zebra_Image();
0 ignored issues
show
Bug introduced by
The type Zebra_Image 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...
135
    // indicate a source image (a GIF, PNG or JPEG file)
136
    $image->source_path = PEDIGREE_UPLOAD_PATH . "/images/{$filename}";
0 ignored issues
show
Bug introduced by
The constant PEDIGREE_UPLOAD_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
137
138
    foreach ($thumbnail_widths as $thumbnail_width) {
139
140
        // generate & output thumbnail
141
        $output_filename    = PEDIGREE_UPLOAD_PATH . '/images/thumbnails/' . basename($filename) . "_{$thumbnail_width}.{$config_output_format}";
142
        $image->target_path = $output_filename;
143
        // since in this example we're going to have a jpeg file, let's set the output
144
        // image's quality
145
        $image->jpeg_quality = 100;
146
        // some additional properties that can be set
147
        // read about them in the documentation
148
        $image->preserve_aspect_ratio  = true;
149
        $image->enlarge_smaller_images = true;
150
        $image->preserve_time          = true;
151
152
        // resize the image to exactly 100x100 pixels by using the "crop from center" method
153
        // (read more in the overview section or in the documentation)
154
        //  and if there is an error, check what the error is about
155
        if (!$image->resize($thumbnail_width, 0)) {
156
            // if there was an error, let's see what the error is about
157
            switch ($image->error) {
158
159
                case 1:
160
                    echo 'Source file could not be found!';
161
                    break;
162
                case 2:
163
                    echo 'Source file is not readable!';
164
                    break;
165
                case 3:
166
                    echo 'Could not write target file!';
167
                    break;
168
                case 4:
169
                    echo 'Unsupported source file format!';
170
                    break;
171
                case 5:
172
                    echo 'Unsupported target file format!';
173
                    break;
174
                case 6:
175
                    echo 'GD library version does not support target file format!';
176
                    break;
177
                case 7:
178
                    echo 'GD library is not installed!';
179
                    break;
180
                case 8:
181
                    echo '"chmod" command is disabled via configuration!';
182
                    break;
183
            }
184
185
            // if no errors
186
        } else {
187
            echo 'Success!';
188
        }
189
190
        /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
191
                if ($phpThumb->GenerateThumbnail()) { // this line is VERY important, do not remove it!
192
                    if ($output_filename) {
193
                        if ($phpThumb->RenderToFile($output_filename)) {
194
                            // do something on success
195
                            //echo 'Successfully rendered:<br><img src="'.$output_filename.'">';
196
                        } else {
197
                            echo 'Failed (size='.$thumbnail_width.'):<pre>'.implode("\n\n", $phpThumb->debugmessages).'</pre>';
198
                        }
199
                    }
200
                } else {
201
                    echo 'Failed (size='.$thumbnail_width.'):<pre>'.implode("\n\n", $phpThumb->debugmessages).'</pre>';
202
                }
203
 */
204
    }
205
206
    unset($image);
207
}
208
209
/**
210
 * @param $string
211
 *
212
 * @return string
213
 */
214
function unHtmlEntities($string)
215
{
216
    $trans_tbl = array_flip(get_html_translation_table(HTML_ENTITIES));
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;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
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
    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);
0 ignored issues
show
Unused Code Comprehensibility introduced by
80% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
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
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
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 !";
0 ignored issues
show
Unused Code Comprehensibility introduced by
77% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
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;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
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
    foreach ($fields as $i => $iValue) {
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);
0 ignored issues
show
Unused Code Comprehensibility introduced by
80% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
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
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
377
        //        unset($columnvalue1);
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
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 !";
0 ignored issues
show
Unused Code Comprehensibility introduced by
77% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
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
 * @return string
461
 */
462
function showParent($PA)
463
{
464
    $sqlQuery    = 'SELECT naam FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE id='" . $PA . "'";
465
    $queryResult = $GLOBALS['xoopsDB']->query($sqlQuery);
466
    while (false !== ($rowResult = $GLOBALS['xoopsDB']->fetchArray($queryResult))) {
467
        $result = $rowResult['naam'];
468
    }
469
    if (isset($result)) {
470
        return $result;
471
    } else {
472
        return '';
473
    }
474
}
475
476
/**
477
 * @param $naam_hond
478
 *
479
 * @return mixed
480
 */
481
function findId($naam_hond)
482
{
483
    $sqlQuery    = 'SELECT id FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " where naam= '$naam_hond'";
484
    $queryResult = $GLOBALS['xoopsDB']->query($sqlQuery);
485
    while (false !== ($rowResult = $GLOBALS['xoopsDB']->fetchArray($queryResult))) {
486
        $result = $rowResult['id'];
487
    }
488
489
    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...
490
}
491
492
/**
493
 * @param $result
494
 * @param $prefix
495
 * @param $link
496
 * @param $element
497
 */
498
function createList($result, $prefix, $link, $element)
499
{
500
    global $xoopsTpl;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
501
    $animal = new Pedigree\Animal();
502
    //test to find out how many user fields there are...
503
    $fields       = $animal->getNumOfFields();
504
    $numofcolumns = 1;
505
    $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...
506
    foreach ($fields as $i => $iValue) {
507
        $userField   = new Pedigree\Field($fields[$i], $animal->getConfig());
508
        $fieldType   = $userField->getSetting('FieldType');
509
        $fieldObject = new $fieldType($userField, $animal);
510
        if ($userField->isActive() && $userField->inList()) {
511
            if ($userField->hasLookup()) {
512
                $id = $userField->getId();
513
                $q  = $userField->lookupField($id);
514
            } else {
515
                $q = '';
516
            }
517
            $columns[] = [
518
                'columnname'   => $fieldObject->fieldname,
519
                'columnnumber' => $userField->getId(),
520
                'lookuparray'  => $q
521
            ];
522
            ++$numofcolumns;
523
        }
524
    }
525
526
    //add preliminary row to array if passed
527
    if (is_array($prefix)) {
528
        $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...
529
    }
530
531
    while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
532
        //reset $gender
533
        $gender = '';
534
        if ((!empty($GLOBALS['xoopsUser']) && $GLOBALS['xoopsUser'] instanceof \XoopsUser)
535
            && ($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...
536
            $gender = "<a href='dog.php?id={$row['id']}'><img src='images/edit.png' alt='" . _EDIT . "'></a>
537
                     . <a href='delete.php?id={$row['id']}'><img src='images/delete.png' alt='" . _DELETE . "'></a>";
538
        }
539
540
        $genImg = (0 == $row['roft']) ? 'male.gif' : 'female.gif';
541
        $gender .= "<img src='assets/images/{$genImg}'>";
542
543
        if ('' != $row['foto']) {
544
            $camera = ' <img src="' . PEDIGREE_UPLOAD_URL . '/images/dog-icon25.png">';
0 ignored issues
show
Bug introduced by
The constant PEDIGREE_UPLOAD_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
545
        } else {
546
            $camera = '';
547
        }
548
        $name = stripslashes($row['naam']) . $camera;
549
        unset($columnvalue);
550
551
        //fill array
552
        for ($i = 1; $i < $numofcolumns; ++$i) {
553
            $x           = $columns[$i]['columnnumber'];
554
            $lookuparray = $columns[$i]['lookuparray'];
555
            if (is_array($lookuparray)) {
556
                foreach ($lookuparray as $index => $indexValue) {
557
                    if ($lookuparray[$index]['id'] == $row['user' . $x]) {
558
                        //echo "<h1>".$lookuparray[$index]['id']."</h1>";
0 ignored issues
show
Unused Code Comprehensibility introduced by
79% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
559
                        $value = $lookuparray[$index]['value'];
560
                    }
561
                }
562
            } //format value - cant use object because of query count
563
            elseif (0 === strncmp($row['user' . $x], 'http://', 7)) {
564
                $value = '<a href="' . $row['user' . $x] . '">' . $row['user' . $x] . '</a>';
565
            } else {
566
                $value = $row['user' . $x];
567
            }
568
            $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...
569
            unset($value);
570
        }
571
572
        $linkto = '<a href="' . $link . $row[$element] . '">' . $name . '</a>';
573
        //create array
574
        $dogs[] = [
575
            'id'          => $row['id'],
576
            'name'        => $name,
577
            'gender'      => $gender,
578
            'link'        => $linkto,
579
            'colour'      => '',
580
            'number'      => '',
581
            '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...
582
        ];
583
    }
584
585
    //add data to smarty template
586
    //assign dog
587
    $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...
588
    $xoopsTpl->assign('columns', $columns);
589
    $xoopsTpl->assign('numofcolumns', $numofcolumns);
590
    $xoopsTpl->assign('tsarray', Pedigree\Utility::sortTable($numofcolumns));
591
}
592
593
/***************Blocks**************
594
 *
595
 * @param $cats
596
 *
597
 * @return string
598
 */
599
function animal_block_addCatSelect($cats)
600
{
601
    if (is_array($cats)) {
602
        $cat_sql = '(' . current($cats);
603
        array_shift($cats);
604
        foreach ($cats as $cat) {
605
            $cat_sql .= ',' . $cat;
606
        }
607
        $cat_sql .= ')';
608
    }
609
610
    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...
611
}
612
613
/**
614
 * @deprecated
615
 * @param        $global
616
 * @param        $key
617
 * @param string $default
618
 * @param string $type
619
 *
620
 * @return mixed|string
621
 */
622
function animal_CleanVars(&$global, $key, $default = '', $type = 'int')
623
{
624
    switch ($type) {
625
        case 'string':
626
            $ret = isset($global[$key]) ? filter_var($global[$key], FILTER_SANITIZE_MAGIC_QUOTES) : $default;
627
            break;
628
        case 'int':
629
        default:
630
            $ret = isset($global[$key]) ? filter_var($global[$key], FILTER_SANITIZE_NUMBER_INT) : $default;
631
            break;
632
    }
633
    if (false === $ret) {
634
        return $default;
635
    }
636
637
    return $ret;
638
}
639
640
/**
641
 * @param $content
642
 */
643
function animal_meta_keywords($content)
644
{
645
    global $xoopsTpl, $xoTheme;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
646
    $myts    = \MyTextSanitizer::getInstance();
647
    $content = $myts->undoHtmlSpecialChars($myts->sanitizeForDisplay($content));
648
    if (isset($xoTheme) && is_object($xoTheme)) {
649
        $xoTheme->addMeta('meta', 'keywords', strip_tags($content));
650
    } else {    // Compatibility for old Xoops versions
651
        $xoopsTpl->assign('xoops_meta_keywords', strip_tags($content));
652
    }
653
}
654
655
/**
656
 * @param $content
657
 */
658
function animal_meta_description($content)
659
{
660
    global $xoopsTpl, $xoTheme;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
661
    $myts    = \MyTextSanitizer::getInstance();
662
    $content = $myts->undoHtmlSpecialChars($myts->displayTarea($content));
663
    if (isset($xoTheme) && is_object($xoTheme)) {
664
        $xoTheme->addMeta('meta', 'description', strip_tags($content));
665
    } else {    // Compatibility for old Xoops versions
666
        $xoopsTpl->assign('xoops_meta_description', strip_tags($content));
667
    }
668
}
669
670
/**
671
 * Verify that a mysql table exists
672
 *
673
 * @package       pedigree
674
 * @author        Hervé Thouzard (http://www.herve-thouzard.com)
675
 * @copyright (c) Hervé Thouzard
676
 */
677
//function tableExists($tablename)
0 ignored issues
show
Unused Code Comprehensibility introduced by
66% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
678
//{
679
//
680
//  $result=$GLOBALS['xoopsDB']->queryF("SHOW TABLES LIKE '$tablename'");
681
//  return($GLOBALS['xoopsDB']->getRowsNum($result) > 0);
682
//}
683
684
/**
685
 * Create download by letter choice bar/menu
686
 * updated starting from this idea https://xoops.org/modules/news/article.php?storyid=6497
687
 *
688
 * @return string html
689
 *
690
 * @deprecated
691
 * @access  public
692
 * @author  luciorota
693
 */
694
function lettersChoice()
695
{
696
    $helper = Pedigree\Helper::getInstance();
697
    $helper->loadLanguage('main');
698
    xoops_load('XoopsLocal');
699
700
    $criteria = $helper->getHandler('Tree')->getActiveCriteria();
701
    $criteria->setGroupby('UPPER(LEFT(naam,1))');
702
    $countsByLetters = $helper->getHandler('Tree')->getCounts($criteria);
703
    // Fill alphabet array
704
    //    $alphabet       = XoopsLocal::getAlphabet();
0 ignored issues
show
Unused Code Comprehensibility introduced by
46% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
705
    //        $xLocale = new \XoopsLocal;
0 ignored issues
show
Unused Code Comprehensibility introduced by
40% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
706
    //        $alphabet =  $xLocale->getAlphabet();
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
707
    $alphabet       = explode(',', _MA_PEDIGREE_LTRCHARS);
708
    //$alphabet       = pedigreeGetAlphabet();
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
709
    $alphabet_array = [];
710
    foreach ($alphabet as $letter) {
711
        $letter_array = [];
712
        if (isset($countsByLetters[$letter])) {
713
            $letter_array['letter'] = $letter;
714
            $letter_array['count']  = $countsByLetters[$letter];
715
            //            $letter_array['url']    = "" . XOOPS_URL . "/modules/" . $helper->getModule()->dirname() . "/viewcat.php?list={$letter}";
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
716
            $letter_array['url'] = '' . XOOPS_URL . '/modules/' . $helper->getModule()->dirname() . "/result.php?f=naam&amp;l=1&amp;w={$letter}%25&amp;o=naam";
717
        } else {
718
            $letter_array['letter'] = $letter;
719
            $letter_array['count']  = 0;
720
            $letter_array['url']    = '';
721
        }
722
        $alphabet_array[$letter] = $letter_array;
723
        unset($letter_array);
724
    }
725
    // Render output
726
    if (!isset($GLOBALS['xoTheme']) || !is_object($GLOBALS['xoTheme'])) {
727
        require_once $GLOBALS['xoops']->path('class/theme.php');
728
        $GLOBALS['xoTheme'] = new \xos_opal_Theme();
729
    }
730
    require_once $GLOBALS['xoops']->path('class/template.php');
731
    $letterschoiceTpl          = new \XoopsTpl();
732
    $letterschoiceTpl->caching = false; // Disable cache
0 ignored issues
show
Documentation Bug introduced by
The property $caching was declared of type integer, but false is of type false. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
733
    $letterschoiceTpl->assign('alphabet', $alphabet_array);
734
    $html = $letterschoiceTpl->fetch('db:' . $helper->getDirname() . '_common_letterschoice.tpl');
735
    unset($letterschoiceTpl);
736
737
    return $html;
738
}
739
740
/**
741
 * Detemines if a table exists in the current db
742
 *
743
 * @param string $table the table name (without XOOPS prefix)
744
 *
745
 * @return bool True if table exists, false if not
746
 *
747
 * @access public
748
 * @author xhelp development team
749
 */
750
function hasTable($table)
751
{
752
    $bRetVal = false;
753
    //Verifies that a MySQL table exists
754
    $GLOBALS['xoopsDB'] = \XoopsDatabaseFactory::getDatabaseConnection();
755
    $realName           = $GLOBALS['xoopsDB']->prefix($table);
756
757
    $sql = 'SHOW TABLES FROM ' . XOOPS_DB_NAME;
758
    $ret = $GLOBALS['xoopsDB']->queryF($sql);
759
760
    while (false !== (list($m_table) = $GLOBALS['xoopsDB']->fetchRow($ret))) {
761
        if ($m_table == $realName) {
762
            $bRetVal = true;
763
            break;
764
        }
765
    }
766
    $GLOBALS['xoopsDB']->freeRecordSet($ret);
767
768
    return $bRetVal;
769
}
770
771
/**
772
 * Gets a value from a key in the xhelp_meta table
773
 *
774
 * @param string $key
775
 *
776
 * @return string $value
777
 *
778
 * @access public
779
 * @author xhelp development team
780
 */
781
function getMeta($key)
782
{
783
    $GLOBALS['xoopsDB'] = \XoopsDatabaseFactory::getDatabaseConnection();
784
    $sql                = sprintf('SELECT metavalue FROM `%s` WHERE metakey= `%s` ', $GLOBALS['xoopsDB']->prefix('pedigree_meta'), $GLOBALS['xoopsDB']->quoteString($key));
785
    $ret                = $GLOBALS['xoopsDB']->query($sql);
786
    if (!$ret) {
787
        $value = false;
788
    } else {
789
        list($value) = $GLOBALS['xoopsDB']->fetchRow($ret);
790
    }
791
792
    return $value;
793
}
794
795
/**
796
 * Sets a value for a key in the xhelp_meta table
797
 *
798
 * @param string $key
799
 * @param string $value
800
 *
801
 * @return bool true if success, false if failure
802
 *
803
 * @access public
804
 * @author xhelp development team
805
 */
806
function setMeta($key, $value)
807
{
808
    $GLOBALS['xoopsDB'] = \XoopsDatabaseFactory::getDatabaseConnection();
809
    if (false !== ($ret = Pedigree\Utility::getMeta($key))) {
0 ignored issues
show
introduced by
The condition false !== $ret = XoopsMo...\Utility::getMeta($key) is always true.
Loading history...
Unused Code introduced by
The assignment to $ret is dead and can be removed.
Loading history...
810
        $sql = sprintf('UPDATE `%s` SET metavalue = `%s` WHERE metakey = `%s` ', $GLOBALS['xoopsDB']->prefix('pedigree_meta'), $GLOBALS['xoopsDB']->quoteString($value), $GLOBALS['xoopsDB']->quoteString($key));
811
    } else {
812
        $sql = sprintf('INSERT INTO `%s` (metakey, metavalue) VALUES (`%s`, `%s`)', $GLOBALS['xoopsDB']->prefix('pedigree_meta'), $GLOBALS['xoopsDB']->quoteString($key), $GLOBALS['xoopsDB']->quoteString($value));
813
    }
814
    $ret = $GLOBALS['xoopsDB']->queryF($sql);
815
    if (!$ret) {
816
        return false;
817
    }
818
819
    return true;
820
}
821
822
/**
823
 * @param     $name
824
 * @param     $value
825
 * @param int $time
826
 */
827
function setCookieVar($name, $value, $time = 0)
828
{
829
    if (0 == $time) {
830
        $time = time() + 3600 * 24 * 365;
831
    }
832
    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

832
    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

832
    setcookie($name, $value, $time, '/', ini_get('session.cookie_domain'), ini_get('session.cookie_secure'), /** @scrutinizer ignore-type */ ini_get('session.cookie_httponly'));
Loading history...
833
}
834
835
/**
836
 * @param        $name
837
 * @param string $default
838
 *
839
 * @return string
840
 */
841
function getCookieVar($name, $default = '')
842
{
843
    if (isset($_COOKIE[$name]) && ($_COOKIE[$name] > '')) {
844
        return $_COOKIE[$name];
845
    } else {
846
        return $default;
847
    }
848
}
849
850
/**
851
 * @return array
852
 */
853
function getCurrentUrls()
854
{
855
    $http        = (false === strpos(XOOPS_URL, 'https://')) ? 'http://' : 'https://';
856
    $phpSelf     = $_SERVER['SCRIPT_NAME'];
857
    $httpHost    = $_SERVER['HTTP_HOST'];
858
    $queryString = $_SERVER['QUERY_STRING'];
859
860
    if ('' != $queryString) {
861
        $queryString = '?' . $queryString;
862
    }
863
864
    $currentURL = $http . $httpHost . $phpSelf . $queryString;
865
866
    $urls                = [];
867
    $urls['http']        = $http;
868
    $urls['httphost']    = $httpHost;
869
    $urls['phpself']     = $phpSelf;
870
    $urls['querystring'] = $queryString;
871
    $urls['full']        = $currentURL;
872
873
    return $urls;
874
}
875
876
/**
877
 * @return mixed
878
 */
879
function getCurrentPage()
880
{
881
    $urls = Pedigree\Utility::getCurrentUrls();
882
883
    return $urls['full'];
884
}
885
886
/**
887
 * @param array $errors
888
 *
889
 * @return string
890
 */
891
function formatErrors($errors = [])
892
{
893
    $ret = '';
894
    foreach ($errors as $key => $value) {
895
        $ret .= "<br> - {$value}";
896
    }
897
898
    return $ret;
899
}
900