|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
/** |
|
3
|
|
|
* NewBB, the forum module for XOOPS project |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
|
6
|
|
|
* @license GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
|
7
|
|
|
* @author Taiwen Jiang (phppp or D.J.) <[email protected]> |
|
8
|
|
|
* @since 4.00 |
|
9
|
|
|
*/ |
|
10
|
|
|
defined('NEWBB_FUNCTIONS_INI') || require __DIR__ . '/functions.ini.php'; |
|
11
|
|
|
define('NEWBB_FUNCTIONS_TIME_LOADED', true); |
|
12
|
|
|
|
|
13
|
|
|
if (!defined('NEWBB_FUNCTIONS_TIME')) { |
|
14
|
|
|
define('NEWBB_FUNCTIONS_TIME', 1); |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Function to convert UNIX time to formatted time string |
|
18
|
|
|
* @param int $time |
|
19
|
|
|
* @param string $format |
|
20
|
|
|
* @param string $timeoffset |
|
21
|
|
|
* @return string |
|
22
|
|
|
*/ |
|
23
|
|
|
function newbbFormatTimestamp(int $time, string $format = 'c', string $timeoffset = ''): string |
|
24
|
|
|
{ |
|
25
|
|
|
xoops_loadLanguage('locale'); |
|
26
|
|
|
$newbbConfig = newbbLoadConfig(); |
|
27
|
|
|
|
|
28
|
|
|
$format = \mb_strtolower($format); |
|
29
|
|
|
if ('reg' === $format || '' === $format) { |
|
30
|
|
|
$format = 'c'; |
|
31
|
|
|
} |
|
32
|
|
|
if (('custom' === $format || 'c' === $format) && !empty($newbbConfig['formatTimestamp_custom'])) { |
|
33
|
|
|
$format = $newbbConfig['formatTimestamp_custom']; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
return XoopsLocal::formatTimestamp($time, $format, $timeoffset); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param int $selected |
|
41
|
|
|
* @return string |
|
42
|
|
|
*/ |
|
43
|
|
|
function newbbSinceSelectBox(int $selected = 100): string |
|
44
|
|
|
{ |
|
45
|
|
|
$newbbConfig = newbbLoadConfig(); |
|
46
|
|
|
// irmtfan - new method to get user inputs |
|
47
|
|
|
preg_match_all('/-?\d+/', (string) $newbbConfig['since_options'], $match); |
|
48
|
|
|
$select_array = array_unique($match[0]); |
|
49
|
|
|
//$select_array = explode(',', $newbbConfig['since_options']); |
|
50
|
|
|
//$select_array = array_map('trim', $select_array); |
|
51
|
|
|
// irmtfan - if the array is empty do not show selection box |
|
52
|
|
|
if (!$select_array) { |
|
|
|
|
|
|
53
|
|
|
$since = $newbbConfig['since_default']; |
|
54
|
|
|
switch ($since) { |
|
55
|
|
|
case 0: |
|
56
|
|
|
$forum_since = _MD_NEWBB_BEGINNING; |
|
57
|
|
|
break; |
|
58
|
|
|
case 365: |
|
59
|
|
|
$forum_since = _MD_NEWBB_THELASTYEAR; |
|
60
|
|
|
break; |
|
61
|
|
|
default: |
|
62
|
|
|
if ($since > 0) { |
|
63
|
|
|
$forum_since = sprintf(_MD_NEWBB_FROMLASTDAYS, $since); |
|
64
|
|
|
} else { |
|
65
|
|
|
$forum_since = sprintf(_MD_NEWBB_FROMLASTHOURS, abs($since)); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
return $forum_since; |
|
70
|
|
|
} |
|
71
|
|
|
$forum_selection_since = '<select class="form-control" name="since" id="since">'; |
|
72
|
|
|
// irmtfan no option when no selected value |
|
73
|
|
|
$forum_selection_since .= '<option value="">--------</option>'; |
|
74
|
|
|
foreach ($select_array as $since) { |
|
75
|
|
|
$forum_selection_since .= '<option value="' . $since . '"' . (($selected == $since) ? ' selected="selected"' : '') . '>'; |
|
76
|
|
|
// START irmtfan functional since 0 and 365 |
|
77
|
|
|
switch ($since) { |
|
78
|
|
|
case 0: |
|
79
|
|
|
$forum_selection_since .= _MD_NEWBB_BEGINNING; |
|
80
|
|
|
break; |
|
81
|
|
|
case 365: |
|
82
|
|
|
$forum_selection_since .= _MD_NEWBB_THELASTYEAR; |
|
83
|
|
|
break; |
|
84
|
|
|
default: |
|
85
|
|
|
if ($since > 0) { |
|
86
|
|
|
$forum_selection_since .= sprintf(_MD_NEWBB_FROMLASTDAYS, $since); |
|
87
|
|
|
} else { |
|
88
|
|
|
$forum_selection_since .= sprintf(_MD_NEWBB_FROMLASTHOURS, abs((int)$since)); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
// END irmtfan functional since 0 and 365 |
|
92
|
|
|
$forum_selection_since .= '</option>'; |
|
93
|
|
|
} |
|
94
|
|
|
// irmtfan remove hardcodes |
|
95
|
|
|
//$forum_selection_since .= '<option value="365"'.(($selected === 365) ? ' selected="selected"' : '').'>'._MD_NEWBB_THELASTYEAR.'</option>'; |
|
96
|
|
|
//$forum_selection_since .= '<option value="0"'.(($selected === 0) ? ' selected="selected"' : '').'>'._MD_NEWBB_BEGINNING.'</option>'; |
|
97
|
|
|
$forum_selection_since .= '</select>'; |
|
98
|
|
|
|
|
99
|
|
|
return $forum_selection_since; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @param int $since |
|
104
|
|
|
* |
|
105
|
|
|
* @return int |
|
106
|
|
|
* |
|
107
|
|
|
* @psalm-return 0|positive-int |
|
108
|
|
|
*/ |
|
109
|
|
|
function newbbGetSinceTime(int $since = 100) |
|
110
|
|
|
{ |
|
111
|
|
|
// irmtfan bad coding |
|
112
|
|
|
//if ($since==1000) return 0; |
|
113
|
|
|
if ($since > 0) { |
|
114
|
|
|
return (int)$since * 24 * 3600; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
return (int)abs($since) * 3600; |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.