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