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