Passed
Pull Request — master (#2)
by Michael
07:48 queued 04:06
created
class/Common/Blocksadmin.php 2 patches
Indentation   +637 added lines, -637 removed lines patch added patch discarded remove patch
@@ -25,260 +25,260 @@  discard block
 block discarded – undo
25 25
  */
26 26
 class Blocksadmin
27 27
 {
28
-    /**
29
-     * @var \XoopsMySQLDatabase|null
30
-     */
31
-    public $db;
32
-    public $helper;
33
-    public $moduleDirName;
34
-    public $moduleDirNameUpper;
35
-
36
-    /**
37
-     * Blocksadmin constructor.
38
-     */
39
-    public function __construct(?\XoopsDatabase $db, Helper $helper)
40
-    {
41
-        if (null === $db) {
42
-            $db = \XoopsDatabaseFactory::getDatabaseConnection();
43
-        }
44
-        $this->db                 = $db;
45
-        $this->helper             = $helper;
46
-        $this->moduleDirName      = \basename(\dirname(__DIR__, 2));
47
-        $this->moduleDirNameUpper = \mb_strtoupper($this->moduleDirName);
48
-        \xoops_loadLanguage('admin', 'system');
49
-        \xoops_loadLanguage('admin/blocksadmin', 'system');
50
-        \xoops_loadLanguage('admin/groups', 'system');
51
-        \xoops_loadLanguage('common', $this->moduleDirName);
52
-        \xoops_loadLanguage('blocksadmin', $this->moduleDirName);
53
-    }
54
-
55
-    public function listBlocks(): void
56
-    {
57
-        global $xoopsModule, $pathIcon16;
58
-        require_once XOOPS_ROOT_PATH . '/class/xoopslists.php';
59
-        //        xoops_loadLanguage('admin', 'system');
60
-        //        xoops_loadLanguage('admin/blocksadmin', 'system');
61
-        //        xoops_loadLanguage('admin/groups', 'system');
62
-        //        xoops_loadLanguage('common', $moduleDirName);
63
-        //        xoops_loadLanguage('blocks', $moduleDirName);
64
-
65
-        /** @var \XoopsModuleHandler $moduleHandler */
66
-        $moduleHandler = \xoops_getHandler('module');
67
-        /** @var \XoopsMemberHandler $memberHandler */
68
-        $memberHandler = \xoops_getHandler('member');
69
-        /** @var \XoopsGroupPermHandler $grouppermHandler */
70
-        $grouppermHandler = \xoops_getHandler('groupperm');
71
-        $groups           = $memberHandler->getGroups();
72
-        $criteria         = new \CriteriaCompo(new \Criteria('hasmain', 1));
73
-        $criteria->add(new \Criteria('isactive', 1));
74
-        $moduleList     = $moduleHandler->getList($criteria);
75
-        $moduleList[-1] = \_AM_SYSTEM_BLOCKS_TOPPAGE;
76
-        $moduleList[0]  = \_AM_SYSTEM_BLOCKS_ALLPAGES;
77
-        \ksort($moduleList);
78
-        echo "
28
+	/**
29
+	 * @var \XoopsMySQLDatabase|null
30
+	 */
31
+	public $db;
32
+	public $helper;
33
+	public $moduleDirName;
34
+	public $moduleDirNameUpper;
35
+
36
+	/**
37
+	 * Blocksadmin constructor.
38
+	 */
39
+	public function __construct(?\XoopsDatabase $db, Helper $helper)
40
+	{
41
+		if (null === $db) {
42
+			$db = \XoopsDatabaseFactory::getDatabaseConnection();
43
+		}
44
+		$this->db                 = $db;
45
+		$this->helper             = $helper;
46
+		$this->moduleDirName      = \basename(\dirname(__DIR__, 2));
47
+		$this->moduleDirNameUpper = \mb_strtoupper($this->moduleDirName);
48
+		\xoops_loadLanguage('admin', 'system');
49
+		\xoops_loadLanguage('admin/blocksadmin', 'system');
50
+		\xoops_loadLanguage('admin/groups', 'system');
51
+		\xoops_loadLanguage('common', $this->moduleDirName);
52
+		\xoops_loadLanguage('blocksadmin', $this->moduleDirName);
53
+	}
54
+
55
+	public function listBlocks(): void
56
+	{
57
+		global $xoopsModule, $pathIcon16;
58
+		require_once XOOPS_ROOT_PATH . '/class/xoopslists.php';
59
+		//        xoops_loadLanguage('admin', 'system');
60
+		//        xoops_loadLanguage('admin/blocksadmin', 'system');
61
+		//        xoops_loadLanguage('admin/groups', 'system');
62
+		//        xoops_loadLanguage('common', $moduleDirName);
63
+		//        xoops_loadLanguage('blocks', $moduleDirName);
64
+
65
+		/** @var \XoopsModuleHandler $moduleHandler */
66
+		$moduleHandler = \xoops_getHandler('module');
67
+		/** @var \XoopsMemberHandler $memberHandler */
68
+		$memberHandler = \xoops_getHandler('member');
69
+		/** @var \XoopsGroupPermHandler $grouppermHandler */
70
+		$grouppermHandler = \xoops_getHandler('groupperm');
71
+		$groups           = $memberHandler->getGroups();
72
+		$criteria         = new \CriteriaCompo(new \Criteria('hasmain', 1));
73
+		$criteria->add(new \Criteria('isactive', 1));
74
+		$moduleList     = $moduleHandler->getList($criteria);
75
+		$moduleList[-1] = \_AM_SYSTEM_BLOCKS_TOPPAGE;
76
+		$moduleList[0]  = \_AM_SYSTEM_BLOCKS_ALLPAGES;
77
+		\ksort($moduleList);
78
+		echo "
79 79
         <h4 style='text-align:left;'>" . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'BADMIN') . '</h4>';
80
-        echo "<form action='" . $_SERVER['SCRIPT_NAME'] . "' name='blockadmin' method='post'>";
81
-        echo $GLOBALS['xoopsSecurity']->getTokenHTML();
82
-        echo "<table width='100%' class='outer' cellpadding='4' cellspacing='1'>
80
+		echo "<form action='" . $_SERVER['SCRIPT_NAME'] . "' name='blockadmin' method='post'>";
81
+		echo $GLOBALS['xoopsSecurity']->getTokenHTML();
82
+		echo "<table width='100%' class='outer' cellpadding='4' cellspacing='1'>
83 83
         <tr valign='middle'><th align='center'>"
84
-             . \_AM_SYSTEM_BLOCKS_TITLE
85
-             . "</th><th align='center' nowrap='nowrap'>"
86
-             . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'SIDE')
87
-             . '<br>'
88
-             . _LEFT
89
-             . '-'
90
-             . _CENTER
91
-             . '-'
92
-             . _RIGHT
93
-             . "</th><th align='center'>"
94
-             . \constant(
95
-                 'CO_' . $this->moduleDirNameUpper . '_' . 'WEIGHT'
96
-             )
97
-             . "</th><th align='center'>"
98
-             . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'VISIBLE')
99
-             . "</th><th align='center'>"
100
-             . \_AM_SYSTEM_BLOCKS_VISIBLEIN
101
-             . "</th><th align='center'>"
102
-             . \_AM_SYSTEM_ADGS
103
-             . "</th><th align='center'>"
104
-             . \_AM_SYSTEM_BLOCKS_BCACHETIME
105
-             . "</th><th align='center'>"
106
-             . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'ACTION')
107
-             . '</th></tr>
84
+			 . \_AM_SYSTEM_BLOCKS_TITLE
85
+			 . "</th><th align='center' nowrap='nowrap'>"
86
+			 . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'SIDE')
87
+			 . '<br>'
88
+			 . _LEFT
89
+			 . '-'
90
+			 . _CENTER
91
+			 . '-'
92
+			 . _RIGHT
93
+			 . "</th><th align='center'>"
94
+			 . \constant(
95
+				 'CO_' . $this->moduleDirNameUpper . '_' . 'WEIGHT'
96
+			 )
97
+			 . "</th><th align='center'>"
98
+			 . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'VISIBLE')
99
+			 . "</th><th align='center'>"
100
+			 . \_AM_SYSTEM_BLOCKS_VISIBLEIN
101
+			 . "</th><th align='center'>"
102
+			 . \_AM_SYSTEM_ADGS
103
+			 . "</th><th align='center'>"
104
+			 . \_AM_SYSTEM_BLOCKS_BCACHETIME
105
+			 . "</th><th align='center'>"
106
+			 . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'ACTION')
107
+			 . '</th></tr>
108 108
         ';
109
-        $blockArray = \XoopsBlock::getByModule($xoopsModule->mid());
110
-        $blockCount = \count($blockArray);
111
-        $class      = 'even';
112
-        $cachetimes = [
113
-            0       => _NOCACHE,
114
-            30      => \sprintf(_SECONDS, 30),
115
-            60      => _MINUTE,
116
-            300     => \sprintf(_MINUTES, 5),
117
-            1800    => \sprintf(_MINUTES, 30),
118
-            3600    => _HOUR,
119
-            18000   => \sprintf(_HOURS, 5),
120
-            86400   => _DAY,
121
-            259200  => \sprintf(_DAYS, 3),
122
-            604800  => _WEEK,
123
-            2592000 => _MONTH,
124
-        ];
125
-        foreach ($blockArray as $i) {
126
-            $groupsPermissions = $grouppermHandler->getGroupIds('block_read', $i->getVar('bid'));
127
-            $sql               = 'SELECT module_id FROM ' . $this->db->prefix('block_module_link') . ' WHERE block_id=' . $i->getVar('bid');
128
-            $result            = $this->db->query($sql);
129
-            $modules           = [];
130
-            if (!$result instanceof \mysqli_result) {
131
-                \trigger_error("Query Failed! SQL: $sql Error: " . $this->db->error(), \E_USER_ERROR);
132
-            }
133
-            while (false !== ($row = $this->db->fetchArray($result))) {
134
-                $modules[] = (int)$row['module_id'];
135
-            }
136
-
137
-            $cachetimeOptions = '';
138
-            foreach ($cachetimes as $cachetime => $cachetimeName) {
139
-                if ($i->getVar('bcachetime') == $cachetime) {
140
-                    $cachetimeOptions .= "<option value='$cachetime' selected='selected'>$cachetimeName</option>\n";
141
-                } else {
142
-                    $cachetimeOptions .= "<option value='$cachetime'>$cachetimeName</option>\n";
143
-                }
144
-            }
145
-
146
-            $ssel7 = '';
147
-            $ssel6 = $ssel7;
148
-            $ssel5 = $ssel6;
149
-            $ssel4 = $ssel5;
150
-            $ssel3 = $ssel4;
151
-            $ssel2 = $ssel3;
152
-            $ssel1 = $ssel2;
153
-            $ssel0 = $ssel1;
154
-            $sel1  = $ssel0;
155
-            $sel0  = $sel1;
156
-            if (1 === $i->getVar('visible')) {
157
-                $sel1 = ' checked';
158
-            } else {
159
-                $sel0 = ' checked';
160
-            }
161
-            if (\XOOPS_SIDEBLOCK_LEFT === $i->getVar('side')) {
162
-                $ssel0 = ' checked';
163
-            } elseif (\XOOPS_SIDEBLOCK_RIGHT === $i->getVar('side')) {
164
-                $ssel1 = ' checked';
165
-            } elseif (\XOOPS_CENTERBLOCK_LEFT === $i->getVar('side')) {
166
-                $ssel2 = ' checked';
167
-            } elseif (\XOOPS_CENTERBLOCK_RIGHT === $i->getVar('side')) {
168
-                $ssel4 = ' checked';
169
-            } elseif (\XOOPS_CENTERBLOCK_CENTER === $i->getVar('side')) {
170
-                $ssel3 = ' checked';
171
-            } elseif (\XOOPS_CENTERBLOCK_BOTTOMLEFT === $i->getVar('side')) {
172
-                $ssel5 = ' checked';
173
-            } elseif (\XOOPS_CENTERBLOCK_BOTTOMRIGHT === $i->getVar('side')) {
174
-                $ssel6 = ' checked';
175
-            } elseif (\XOOPS_CENTERBLOCK_BOTTOM === $i->getVar('side')) {
176
-                $ssel7 = ' checked';
177
-            }
178
-            if ('' === $i->getVar('title')) {
179
-                $title = '&nbsp;';
180
-            } else {
181
-                $title = $i->getVar('title');
182
-            }
183
-            $name = $i->getVar('name');
184
-            echo "<tr valign='top'><td class='$class' align='center'><input type='text' name='title["
185
-                 . $i->getVar('bid')
186
-                 . "]' value='"
187
-                 . $title
188
-                 . "'></td><td class='$class' align='center' nowrap='nowrap'>
109
+		$blockArray = \XoopsBlock::getByModule($xoopsModule->mid());
110
+		$blockCount = \count($blockArray);
111
+		$class      = 'even';
112
+		$cachetimes = [
113
+			0       => _NOCACHE,
114
+			30      => \sprintf(_SECONDS, 30),
115
+			60      => _MINUTE,
116
+			300     => \sprintf(_MINUTES, 5),
117
+			1800    => \sprintf(_MINUTES, 30),
118
+			3600    => _HOUR,
119
+			18000   => \sprintf(_HOURS, 5),
120
+			86400   => _DAY,
121
+			259200  => \sprintf(_DAYS, 3),
122
+			604800  => _WEEK,
123
+			2592000 => _MONTH,
124
+		];
125
+		foreach ($blockArray as $i) {
126
+			$groupsPermissions = $grouppermHandler->getGroupIds('block_read', $i->getVar('bid'));
127
+			$sql               = 'SELECT module_id FROM ' . $this->db->prefix('block_module_link') . ' WHERE block_id=' . $i->getVar('bid');
128
+			$result            = $this->db->query($sql);
129
+			$modules           = [];
130
+			if (!$result instanceof \mysqli_result) {
131
+				\trigger_error("Query Failed! SQL: $sql Error: " . $this->db->error(), \E_USER_ERROR);
132
+			}
133
+			while (false !== ($row = $this->db->fetchArray($result))) {
134
+				$modules[] = (int)$row['module_id'];
135
+			}
136
+
137
+			$cachetimeOptions = '';
138
+			foreach ($cachetimes as $cachetime => $cachetimeName) {
139
+				if ($i->getVar('bcachetime') == $cachetime) {
140
+					$cachetimeOptions .= "<option value='$cachetime' selected='selected'>$cachetimeName</option>\n";
141
+				} else {
142
+					$cachetimeOptions .= "<option value='$cachetime'>$cachetimeName</option>\n";
143
+				}
144
+			}
145
+
146
+			$ssel7 = '';
147
+			$ssel6 = $ssel7;
148
+			$ssel5 = $ssel6;
149
+			$ssel4 = $ssel5;
150
+			$ssel3 = $ssel4;
151
+			$ssel2 = $ssel3;
152
+			$ssel1 = $ssel2;
153
+			$ssel0 = $ssel1;
154
+			$sel1  = $ssel0;
155
+			$sel0  = $sel1;
156
+			if (1 === $i->getVar('visible')) {
157
+				$sel1 = ' checked';
158
+			} else {
159
+				$sel0 = ' checked';
160
+			}
161
+			if (\XOOPS_SIDEBLOCK_LEFT === $i->getVar('side')) {
162
+				$ssel0 = ' checked';
163
+			} elseif (\XOOPS_SIDEBLOCK_RIGHT === $i->getVar('side')) {
164
+				$ssel1 = ' checked';
165
+			} elseif (\XOOPS_CENTERBLOCK_LEFT === $i->getVar('side')) {
166
+				$ssel2 = ' checked';
167
+			} elseif (\XOOPS_CENTERBLOCK_RIGHT === $i->getVar('side')) {
168
+				$ssel4 = ' checked';
169
+			} elseif (\XOOPS_CENTERBLOCK_CENTER === $i->getVar('side')) {
170
+				$ssel3 = ' checked';
171
+			} elseif (\XOOPS_CENTERBLOCK_BOTTOMLEFT === $i->getVar('side')) {
172
+				$ssel5 = ' checked';
173
+			} elseif (\XOOPS_CENTERBLOCK_BOTTOMRIGHT === $i->getVar('side')) {
174
+				$ssel6 = ' checked';
175
+			} elseif (\XOOPS_CENTERBLOCK_BOTTOM === $i->getVar('side')) {
176
+				$ssel7 = ' checked';
177
+			}
178
+			if ('' === $i->getVar('title')) {
179
+				$title = '&nbsp;';
180
+			} else {
181
+				$title = $i->getVar('title');
182
+			}
183
+			$name = $i->getVar('name');
184
+			echo "<tr valign='top'><td class='$class' align='center'><input type='text' name='title["
185
+				 . $i->getVar('bid')
186
+				 . "]' value='"
187
+				 . $title
188
+				 . "'></td><td class='$class' align='center' nowrap='nowrap'>
189 189
                     <div align='center' >
190 190
                     <input type='radio' name='side["
191
-                 . $i->getVar('bid')
192
-                 . "]' value='"
193
-                 . \XOOPS_CENTERBLOCK_LEFT
194
-                 . "'$ssel2>
191
+				 . $i->getVar('bid')
192
+				 . "]' value='"
193
+				 . \XOOPS_CENTERBLOCK_LEFT
194
+				 . "'$ssel2>
195 195
                         <input type='radio' name='side["
196
-                 . $i->getVar('bid')
197
-                 . "]' value='"
198
-                 . \XOOPS_CENTERBLOCK_CENTER
199
-                 . "'$ssel3>
196
+				 . $i->getVar('bid')
197
+				 . "]' value='"
198
+				 . \XOOPS_CENTERBLOCK_CENTER
199
+				 . "'$ssel3>
200 200
                     <input type='radio' name='side["
201
-                 . $i->getVar('bid')
202
-                 . "]' value='"
203
-                 . \XOOPS_CENTERBLOCK_RIGHT
204
-                 . "'$ssel4>
201
+				 . $i->getVar('bid')
202
+				 . "]' value='"
203
+				 . \XOOPS_CENTERBLOCK_RIGHT
204
+				 . "'$ssel4>
205 205
                     </div>
206 206
                     <div>
207 207
                         <span style='float:right;'><input type='radio' name='side["
208
-                 . $i->getVar('bid')
209
-                 . "]' value='"
210
-                 . \XOOPS_SIDEBLOCK_RIGHT
211
-                 . "'$ssel1></span>
208
+				 . $i->getVar('bid')
209
+				 . "]' value='"
210
+				 . \XOOPS_SIDEBLOCK_RIGHT
211
+				 . "'$ssel1></span>
212 212
                     <div align='left'><input type='radio' name='side["
213
-                 . $i->getVar('bid')
214
-                 . "]' value='"
215
-                 . \XOOPS_SIDEBLOCK_LEFT
216
-                 . "'$ssel0></div>
213
+				 . $i->getVar('bid')
214
+				 . "]' value='"
215
+				 . \XOOPS_SIDEBLOCK_LEFT
216
+				 . "'$ssel0></div>
217 217
                     </div>
218 218
                     <div align='center'>
219 219
                     <input type='radio' name='side["
220
-                 . $i->getVar('bid')
221
-                 . "]' value='"
222
-                 . \XOOPS_CENTERBLOCK_BOTTOMLEFT
223
-                 . "'$ssel5>
220
+				 . $i->getVar('bid')
221
+				 . "]' value='"
222
+				 . \XOOPS_CENTERBLOCK_BOTTOMLEFT
223
+				 . "'$ssel5>
224 224
                         <input type='radio' name='side["
225
-                 . $i->getVar('bid')
226
-                 . "]' value='"
227
-                 . \XOOPS_CENTERBLOCK_BOTTOM
228
-                 . "'$ssel7>
225
+				 . $i->getVar('bid')
226
+				 . "]' value='"
227
+				 . \XOOPS_CENTERBLOCK_BOTTOM
228
+				 . "'$ssel7>
229 229
                     <input type='radio' name='side["
230
-                 . $i->getVar('bid')
231
-                 . "]' value='"
232
-                 . \XOOPS_CENTERBLOCK_BOTTOMRIGHT
233
-                 . "'$ssel6>
230
+				 . $i->getVar('bid')
231
+				 . "]' value='"
232
+				 . \XOOPS_CENTERBLOCK_BOTTOMRIGHT
233
+				 . "'$ssel6>
234 234
                     </div>
235 235
                 </td><td class='$class' align='center'><input type='text' name='weight["
236
-                 . $i->getVar('bid')
237
-                 . "]' value='"
238
-                 . $i->getVar('weight')
239
-                 . "' size='5' maxlength='5'></td><td class='$class' align='center' nowrap><input type='radio' name='visible["
240
-                 . $i->getVar('bid')
241
-                 . "]' value='1'$sel1>"
242
-                 . _YES
243
-                 . "&nbsp;<input type='radio' name='visible["
244
-                 . $i->getVar('bid')
245
-                 . "]' value='0'$sel0>"
246
-                 . _NO
247
-                 . '</td>';
248
-
249
-            echo "<td class='$class' align='center'><select size='5' name='bmodule[" . $i->getVar('bid') . "][]' id='bmodule[" . $i->getVar('bid') . "][]' multiple='multiple'>";
250
-            foreach ($moduleList as $k => $v) {
251
-                echo "<option value='$k'" . (\in_array($k, $modules, true) ? " selected='selected'" : '') . ">$v</option>";
252
-            }
253
-            echo '</select></td>';
254
-
255
-            echo "<td class='$class' align='center'><select size='5' name='groups[" . $i->getVar('bid') . "][]' id='groups[" . $i->getVar('bid') . "][]' multiple='multiple'>";
256
-            foreach ($groups as $grp) {
257
-                echo "<option value='" . $grp->getVar('groupid') . "' " . (\in_array($grp->getVar('groupid'), $groupsPermissions, true) ? " selected='selected'" : '') . '>' . $grp->getVar('name') . '</option>';
258
-            }
259
-            echo '</select></td>';
260
-
261
-            // Cache lifetime
262
-            echo '<td class="' . $class . '" align="center"> <select name="bcachetime[' . $i->getVar('bid') . ']" size="1">' . $cachetimeOptions . '</select>
236
+				 . $i->getVar('bid')
237
+				 . "]' value='"
238
+				 . $i->getVar('weight')
239
+				 . "' size='5' maxlength='5'></td><td class='$class' align='center' nowrap><input type='radio' name='visible["
240
+				 . $i->getVar('bid')
241
+				 . "]' value='1'$sel1>"
242
+				 . _YES
243
+				 . "&nbsp;<input type='radio' name='visible["
244
+				 . $i->getVar('bid')
245
+				 . "]' value='0'$sel0>"
246
+				 . _NO
247
+				 . '</td>';
248
+
249
+			echo "<td class='$class' align='center'><select size='5' name='bmodule[" . $i->getVar('bid') . "][]' id='bmodule[" . $i->getVar('bid') . "][]' multiple='multiple'>";
250
+			foreach ($moduleList as $k => $v) {
251
+				echo "<option value='$k'" . (\in_array($k, $modules, true) ? " selected='selected'" : '') . ">$v</option>";
252
+			}
253
+			echo '</select></td>';
254
+
255
+			echo "<td class='$class' align='center'><select size='5' name='groups[" . $i->getVar('bid') . "][]' id='groups[" . $i->getVar('bid') . "][]' multiple='multiple'>";
256
+			foreach ($groups as $grp) {
257
+				echo "<option value='" . $grp->getVar('groupid') . "' " . (\in_array($grp->getVar('groupid'), $groupsPermissions, true) ? " selected='selected'" : '') . '>' . $grp->getVar('name') . '</option>';
258
+			}
259
+			echo '</select></td>';
260
+
261
+			// Cache lifetime
262
+			echo '<td class="' . $class . '" align="center"> <select name="bcachetime[' . $i->getVar('bid') . ']" size="1">' . $cachetimeOptions . '</select>
263 263
                                     </td>';
264 264
 
265
-            // Actions
265
+			// Actions
266 266
 
267
-            echo "<td class='$class' align='center'>
267
+			echo "<td class='$class' align='center'>
268 268
                 <a href='blocksadmin.php?op=edit&amp;bid=" . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/edit.png' . " alt='" . _EDIT . "' title='" . _EDIT . "'></a> 
269 269
                 <a href='blocksadmin.php?op=clone&amp;bid=" . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/editcopy.png' . " alt='" . _CLONE . "' title='" . _CLONE . "'></a>";
270
-            //            if ('S' !== $i->getVar('block_type') && 'M' !== $i->getVar('block_type')) {
271
-            //                echo "&nbsp;<a href='" . XOOPS_URL . '/modules/system/admin.php?fct=blocksadmin&amp;op=delete&amp;bid=' . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/delete.png' . " alt='" . _DELETE . "' title='" . _DELETE . "'>
272
-            //                     </a>";
273
-            //            }
274
-
275
-            //            if ('S' !== $i->getVar('block_type') && 'M' !== $i->getVar('block_type')) {
276
-            if (!\in_array($i->getVar('block_type'), ['M', 'S'], true)) {
277
-                echo "&nbsp;
270
+			//            if ('S' !== $i->getVar('block_type') && 'M' !== $i->getVar('block_type')) {
271
+			//                echo "&nbsp;<a href='" . XOOPS_URL . '/modules/system/admin.php?fct=blocksadmin&amp;op=delete&amp;bid=' . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/delete.png' . " alt='" . _DELETE . "' title='" . _DELETE . "'>
272
+			//                     </a>";
273
+			//            }
274
+
275
+			//            if ('S' !== $i->getVar('block_type') && 'M' !== $i->getVar('block_type')) {
276
+			if (!\in_array($i->getVar('block_type'), ['M', 'S'], true)) {
277
+				echo "&nbsp;
278 278
                 <a href='blocksadmin.php?op=delete&amp;bid=" . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/delete.png' . " alt='" . _DELETE . "' title='" . _DELETE . "'>
279 279
                      </a>";
280
-            }
281
-            echo "
280
+			}
281
+			echo "
282 282
             <input type='hidden' name='oldtitle[" . $i->getVar('bid') . "]' value='" . $i->getVar('title') . "'>
283 283
             <input type='hidden' name='oldside[" . $i->getVar('bid') . "]' value='" . $i->getVar('side') . "'>
284 284
             <input type='hidden' name='oldweight[" . $i->getVar('bid') . "]' value='" . $i->getVar('weight') . "'>
@@ -288,418 +288,418 @@  discard block
 block discarded – undo
288 288
             <input type='hidden' name='bid[" . $i->getVar('bid') . "]' value='" . $i->getVar('bid') . "'>
289 289
             </td></tr>
290 290
             ";
291
-            $class = ('even' === $class) ? 'odd' : 'even';
292
-        }
293
-        echo "<tr><td class='foot' align='center' colspan='8'>
291
+			$class = ('even' === $class) ? 'odd' : 'even';
292
+		}
293
+		echo "<tr><td class='foot' align='center' colspan='8'>
294 294
         <input type='hidden' name='op' value='order'>
295 295
         " . $GLOBALS['xoopsSecurity']->getTokenHTML() . "
296 296
         <input type='submit' name='submit' value='" . _SUBMIT . "'>
297 297
         </td></tr></table>
298 298
         </form>
299 299
         <br><br>";
300
-    }
301
-
302
-    public function deleteBlock(int $bid): void
303
-    {
304
-        //        \xoops_cp_header();
305
-
306
-        \xoops_loadLanguage('admin', 'system');
307
-        \xoops_loadLanguage('admin/blocksadmin', 'system');
308
-        \xoops_loadLanguage('admin/groups', 'system');
309
-
310
-        $myblock = new \XoopsBlock($bid);
311
-
312
-        $sql = \sprintf('DELETE FROM %s WHERE bid = %u', $this->db->prefix('newblocks'), $bid);
313
-        $this->db->queryF($sql) or \trigger_error($GLOBALS['xoopsDB']->error());
314
-
315
-        $sql = \sprintf('DELETE FROM %s WHERE block_id = %u', $this->db->prefix('block_module_link'), $bid);
316
-        $this->db->queryF($sql) or \trigger_error($GLOBALS['xoopsDB']->error());
317
-
318
-        $this->helper->redirect('admin/blocksadmin.php?op=list', 1, _AM_DBUPDATED);
319
-    }
320
-
321
-    public function cloneBlock(int $bid): void
322
-    {
323
-        //require __DIR__ . '/admin_header.php';
324
-        //        \xoops_cp_header();
325
-
326
-        \xoops_loadLanguage('admin', 'system');
327
-        \xoops_loadLanguage('admin/blocksadmin', 'system');
328
-        \xoops_loadLanguage('admin/groups', 'system');
329
-
330
-        $myblock = new \XoopsBlock($bid);
331
-        $sql     = 'SELECT module_id FROM ' . $this->db->prefix('block_module_link') . ' WHERE block_id=' . $bid;
332
-        $result  = $this->db->query($sql);
333
-        $modules = [];
334
-        if ($result instanceof \mysqli_result) {
335
-            while (false !== ($row = $this->db->fetchArray($result))) {
336
-                $modules[] = (int)$row['module_id'];
337
-            }
338
-        }
339
-        $isCustom = \in_array($myblock->getVar('block_type'), ['C', 'E'], true);
340
-        $block    = [
341
-            'title'      => $myblock->getVar('title') . ' Clone',
342
-            'form_title' => \constant('CO_' . $this->moduleDirNameUpper . '_' . 'BLOCKS_CLONEBLOCK'),
343
-            'name'       => $myblock->getVar('name'),
344
-            'side'       => $myblock->getVar('side'),
345
-            'weight'     => $myblock->getVar('weight'),
346
-            'visible'    => $myblock->getVar('visible'),
347
-            'content'    => $myblock->getVar('content', 'N'),
348
-            'modules'    => $modules,
349
-            'is_custom'  => $isCustom,
350
-            'ctype'      => $myblock->getVar('c_type'),
351
-            'bcachetime' => $myblock->getVar('bcachetime'),
352
-            'op'         => 'clone_ok',
353
-            'bid'        => $myblock->getVar('bid'),
354
-            'edit_form'  => $myblock->getOptions(),
355
-            'template'   => $myblock->getVar('template'),
356
-            'options'    => $myblock->getVar('options'),
357
-        ];
358
-        echo '<a href="blocksadmin.php">' . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'BADMIN') . '</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;' . \_AM_SYSTEM_BLOCKS_CLONEBLOCK . '<br><br>';
359
-        //        $form = new Blockform();
360
-        //        $form->render();
361
-
362
-        echo $this->render($block);
363
-        //        xoops_cp_footer();
364
-        //        require_once __DIR__ . '/admin_footer.php';
365
-        //        exit();
366
-    }
367
-
368
-    /**
369
-     * @param null|array|string $options
370
-     */
371
-    public function isBlockCloned(int $bid, string $bside, string $bweight, string $bvisible, string $bcachetime, ?array $bmodule, ?array $options, ?array $groups): void
372
-    {
373
-        \xoops_loadLanguage('admin', 'system');
374
-        \xoops_loadLanguage('admin/blocksadmin', 'system');
375
-        \xoops_loadLanguage('admin/groups', 'system');
376
-
377
-        $block = new \XoopsBlock($bid);
378
-        $clone = $block->xoopsClone();
379
-        if (empty($bmodule)) {
380
-            //            \xoops_cp_header();
381
-            \xoops_error(\sprintf(_AM_NOTSELNG, _AM_VISIBLEIN));
382
-            \xoops_cp_footer();
383
-            exit();
384
-        }
385
-        $clone->setVar('side', $bside);
386
-        $clone->setVar('weight', $bweight);
387
-        $clone->setVar('visible', $bvisible);
388
-        //$clone->setVar('content', $_POST['bcontent']);
389
-        $clone->setVar('title', Request::getString('btitle', '', 'POST'));
390
-        $clone->setVar('bcachetime', $bcachetime);
391
-        if (\is_array($options) && (\count($options) > 0)) {
392
-            $options = \implode('|', $options);
393
-            $clone->setVar('options', $options);
394
-        }
395
-        $clone->setVar('bid', 0);
396
-        if (\in_array($block->getVar('block_type'), ['C', 'E'], true)) {
397
-            $clone->setVar('block_type', 'E');
398
-        } else {
399
-            $clone->setVar('block_type', 'D');
400
-        }
401
-        //        $newid = $clone->store(); //see https://github.com/XOOPS/XoopsCore25/issues/1105
402
-        if ($clone->store()) {
403
-            $newid = $clone->id();  //get the id of the cloned block
404
-        }
405
-        if (!$newid) {
406
-            //            \xoops_cp_header();
407
-            $clone->getHtmlErrors();
408
-            \xoops_cp_footer();
409
-            exit();
410
-        }
411
-        if ('' !== $clone->getVar('template')) {
412
-            /** @var \XoopsTplfileHandler $tplfileHandler */
413
-            $tplfileHandler = \xoops_getHandler('tplfile');
414
-            $btemplate      = $tplfileHandler->find($GLOBALS['xoopsConfig']['template_set'], 'block', (string)$bid);
415
-            if (\count($btemplate) > 0) {
416
-                $tplclone = $btemplate[0]->xoopsClone();
417
-                $tplclone->setVar('tpl_id', 0);
418
-                $tplclone->setVar('tpl_refid', $newid);
419
-                $tplfileHandler->insert($tplclone);
420
-            }
421
-        }
422
-
423
-        foreach ($bmodule as $bmid) {
424
-            $sql = 'INSERT INTO ' . $this->db->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newid . ', ' . $bmid . ')';
425
-            $this->db->query($sql);
426
-        }
427
-        //$groups = &$GLOBALS['xoopsUser']->getGroups();
428
-        foreach ($groups as $iValue) {
429
-            $sql = 'INSERT INTO ' . $this->db->prefix('group_permission') . ' (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (' . $iValue . ', ' . $newid . ", 1, 'block_read')";
430
-            $this->db->query($sql);
431
-        }
432
-        $this->helper->redirect('admin/blocksadmin.php?op=list', 1, _AM_DBUPDATED);
433
-    }
434
-
435
-    public function setOrder(string $bid, string $title, string $weight, string $visible, string $side, string $bcachetime, ?array $bmodule = null): void
436
-    {
437
-        $myblock = new \XoopsBlock($bid);
438
-        $myblock->setVar('title', $title);
439
-        $myblock->setVar('weight', $weight);
440
-        $myblock->setVar('visible', $visible);
441
-        $myblock->setVar('side', $side);
442
-        $myblock->setVar('bcachetime', $bcachetime);
443
-        $myblock->store();
444
-        //        /** @var \XoopsBlockHandler $blockHandler */
445
-        //        $blockHandler = \xoops_getHandler('block');
446
-        //        return $blockHandler->insert($myblock);
447
-    }
448
-
449
-    public function editBlock(int $bid): void
450
-    {
451
-        //        require_once \dirname(__DIR__,2) . '/admin/admin_header.php';
452
-        //        \xoops_cp_header();
453
-        \xoops_loadLanguage('admin', 'system');
454
-        \xoops_loadLanguage('admin/blocksadmin', 'system');
455
-        \xoops_loadLanguage('admin/groups', 'system');
456
-        //        mpu_adm_menu();
457
-        $myblock = new \XoopsBlock($bid);
458
-        $sql     = 'SELECT module_id FROM ' . $this->db->prefix('block_module_link') . ' WHERE block_id=' . $bid;
459
-        $result  = $this->db->query($sql);
460
-        $modules = [];
461
-        if ($result instanceof \mysqli_result) {
462
-            while (false !== ($row = $this->db->fetchArray($result))) {
463
-                $modules[] = (int)$row['module_id'];
464
-            }
465
-        }
466
-        $isCustom = \in_array($myblock->getVar('block_type'), ['C', 'E'], true);
467
-        $block    = [
468
-            'title'      => $myblock->getVar('title'),
469
-            'form_title' => \_AM_SYSTEM_BLOCKS_EDITBLOCK,
470
-            //        'name'       => $myblock->getVar('name'),
471
-            'side'       => $myblock->getVar('side'),
472
-            'weight'     => $myblock->getVar('weight'),
473
-            'visible'    => $myblock->getVar('visible'),
474
-            'content'    => $myblock->getVar('content', 'N'),
475
-            'modules'    => $modules,
476
-            'is_custom'  => $isCustom,
477
-            'ctype'      => $myblock->getVar('c_type'),
478
-            'bcachetime' => $myblock->getVar('bcachetime'),
479
-            'op'         => 'edit_ok',
480
-            'bid'        => $myblock->getVar('bid'),
481
-            'edit_form'  => $myblock->getOptions(),
482
-            'template'   => $myblock->getVar('template'),
483
-            'options'    => $myblock->getVar('options'),
484
-        ];
485
-        echo '<a href="blocksadmin.php">' . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'BADMIN') . '</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;' . \_AM_SYSTEM_BLOCKS_EDITBLOCK . '<br><br>';
486
-
487
-        echo $this->render($block);
488
-    }
489
-
490
-    public function updateBlock(int $bid, string $btitle, string $bside, string $bweight, string $bvisible, string $bcachetime, ?array $bmodule, ?array $options, ?array $groups): void
491
-    {
492
-        $myblock = new \XoopsBlock($bid);
493
-        $myblock->setVar('title', $btitle);
494
-        $myblock->setVar('weight', $bweight);
495
-        $myblock->setVar('visible', $bvisible);
496
-        $myblock->setVar('side', $bside);
497
-        $myblock->setVar('bcachetime', $bcachetime);
498
-        //update block options
499
-        if (isset($options) && \is_array($options)) {
500
-            $optionsCount = \count($options);
501
-            if ($optionsCount > 0) {
502
-                //Convert array values to comma-separated
503
-                foreach ($options as $i => $iValue) {
504
-                    if (\is_array($iValue)) {
505
-                        $options[$i] = \implode(',', $iValue);
506
-                    }
507
-                }
508
-                $options = \implode('|', $options);
509
-                $myblock->setVar('options', $options);
510
-            }
511
-        }
512
-        $myblock->store();
513
-        //        /** @var \XoopsBlockHandler $blockHandler */
514
-        //        $blockHandler = \xoops_getHandler('block');
515
-        //        $blockHandler->insert($myblock);
516
-
517
-        if (!empty($bmodule) && \count($bmodule) > 0) {
518
-            $sql = \sprintf('DELETE FROM `%s` WHERE block_id = %u', $this->db->prefix('block_module_link'), $bid);
519
-            $this->db->query($sql);
520
-            if (\in_array(0, $bmodule, true)) {
521
-                $sql = \sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $this->db->prefix('block_module_link'), $bid, 0);
522
-                $this->db->query($sql);
523
-            } else {
524
-                foreach ($bmodule as $bmid) {
525
-                    $sql = \sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $this->db->prefix('block_module_link'), $bid, (int)$bmid);
526
-                    $this->db->query($sql);
527
-                }
528
-            }
529
-        }
530
-        $sql = \sprintf('DELETE FROM `%s` WHERE gperm_itemid = %u', $this->db->prefix('group_permission'), $bid);
531
-        $this->db->query($sql);
532
-        if (!empty($groups)) {
533
-            foreach ($groups as $grp) {
534
-                $sql = \sprintf("INSERT INTO `%s` (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (%u, %u, 1, 'block_read')", $this->db->prefix('group_permission'), $grp, $bid);
535
-                $this->db->query($sql);
536
-            }
537
-        }
538
-        $this->helper->redirect('admin/blocksadmin.php', 1, \constant('CO_' . $this->moduleDirNameUpper . '_' . 'UPDATE_SUCCESS'));
539
-    }
540
-
541
-    public function orderBlock(
542
-        array $bid,
543
-        array $oldtitle,
544
-        array $oldside,
545
-        array $oldweight,
546
-        array $oldvisible,
547
-        array $oldgroups,
548
-        array $oldbcachetime,
549
-        array $oldbmodule,
550
-        array $title,
551
-        array $weight,
552
-        array $visible,
553
-        array $side,
554
-        array $bcachetime,
555
-        array $groups,
556
-        array $bmodule
557
-    ): void {
558
-        if (!$GLOBALS['xoopsSecurity']->check()) {
559
-            \redirect_header($_SERVER['SCRIPT_NAME'], 3, \implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
560
-        }
561
-        foreach (\array_keys($bid) as $i) {
562
-            if ($oldtitle[$i] !== $title[$i]
563
-                || $oldweight[$i] !== $weight[$i]
564
-                || $oldvisible[$i] !== $visible[$i]
565
-                || $oldside[$i] !== $side[$i]
566
-                || $oldbcachetime[$i] !== $bcachetime[$i]
567
-                || $oldbmodule[$i] !== $bmodule[$i]) {
568
-                $this->setOrder($bid[$i], $title[$i], $weight[$i], $visible[$i], $side[$i], $bcachetime[$i], $bmodule[$i]);
569
-            }
570
-            if (!empty($bmodule[$i]) && \count($bmodule[$i]) > 0) {
571
-                $sql = \sprintf('DELETE FROM `%s` WHERE block_id = %u', $this->db->prefix('block_module_link'), $bid[$i]);
572
-                $this->db->query($sql);
573
-                if (\in_array(0, $bmodule[$i], true)) {
574
-                    $sql = \sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $this->db->prefix('block_module_link'), $bid[$i], 0);
575
-                    $this->db->query($sql);
576
-                } else {
577
-                    foreach ($bmodule[$i] as $bmid) {
578
-                        $sql = \sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $this->db->prefix('block_module_link'), $bid[$i], (int)$bmid);
579
-                        $this->db->query($sql);
580
-                    }
581
-                }
582
-            }
583
-            $sql = \sprintf('DELETE FROM `%s` WHERE gperm_itemid = %u', $this->db->prefix('group_permission'), $bid[$i]);
584
-            $this->db->query($sql);
585
-            if (!empty($groups[$i])) {
586
-                foreach ($groups[$i] as $grp) {
587
-                    $sql = \sprintf("INSERT INTO `%s` (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (%u, %u, 1, 'block_read')", $this->db->prefix('group_permission'), $grp, $bid[$i]);
588
-                    $this->db->query($sql);
589
-                }
590
-            }
591
-        }
592
-
593
-        $this->helper->redirect('admin/blocksadmin.php', 1, \constant('CO_' . $this->moduleDirNameUpper . '_' . 'UPDATE_SUCCESS'));
594
-    }
595
-
596
-    public function render(?array $block = null): void
597
-    {
598
-        \xoops_load('XoopsFormLoader');
599
-        \xoops_loadLanguage('common', $this->moduleDirNameUpper);
600
-
601
-        $form = new \XoopsThemeForm($block['form_title'], 'blockform', 'blocksadmin.php', 'post', true);
602
-        if (isset($block['name'])) {
603
-            $form->addElement(new \XoopsFormLabel(\_AM_SYSTEM_BLOCKS_NAME, $block['name']));
604
-        }
605
-        $sideSelect = new \XoopsFormSelect(\_AM_SYSTEM_BLOCKS_TYPE, 'bside', $block['side']);
606
-        $sideSelect->addOptionArray([
607
-                                        0 => \_AM_SYSTEM_BLOCKS_SBLEFT,
608
-                                        1 => \_AM_SYSTEM_BLOCKS_SBRIGHT,
609
-                                        3 => \_AM_SYSTEM_BLOCKS_CBLEFT,
610
-                                        4 => \_AM_SYSTEM_BLOCKS_CBRIGHT,
611
-                                        5 => \_AM_SYSTEM_BLOCKS_CBCENTER,
612
-                                        7 => \_AM_SYSTEM_BLOCKS_CBBOTTOMLEFT,
613
-                                        8 => \_AM_SYSTEM_BLOCKS_CBBOTTOMRIGHT,
614
-                                        9 => \_AM_SYSTEM_BLOCKS_CBBOTTOM,
615
-                                    ]);
616
-        $form->addElement($sideSelect);
617
-        $form->addElement(new \XoopsFormText(\constant('CO_' . $this->moduleDirNameUpper . '_' . 'WEIGHT'), 'bweight', 2, 5, $block['weight']));
618
-        $form->addElement(new \XoopsFormRadioYN(\constant('CO_' . $this->moduleDirNameUpper . '_' . 'VISIBLE'), 'bvisible', $block['visible']));
619
-        $modSelect = new \XoopsFormSelect(\constant('CO_' . $this->moduleDirNameUpper . '_' . 'VISIBLEIN'), 'bmodule', $block['modules'], 5, true);
620
-        /** @var \XoopsModuleHandler $moduleHandler */
621
-        $moduleHandler = \xoops_getHandler('module');
622
-        $criteria      = new \CriteriaCompo(new \Criteria('hasmain', 1));
623
-        $criteria->add(new \Criteria('isactive', 1));
624
-        $moduleList     = $moduleHandler->getList($criteria);
625
-        $moduleList[-1] = \_AM_SYSTEM_BLOCKS_TOPPAGE;
626
-        $moduleList[0]  = \_AM_SYSTEM_BLOCKS_ALLPAGES;
627
-        \ksort($moduleList);
628
-        $modSelect->addOptionArray($moduleList);
629
-        $form->addElement($modSelect);
630
-        $form->addElement(new \XoopsFormText(\_AM_SYSTEM_BLOCKS_TITLE, 'btitle', 50, 255, $block['title']), false);
631
-        if ($block['is_custom']) {
632
-            $textarea = new \XoopsFormDhtmlTextArea(\_AM_SYSTEM_BLOCKS_CONTENT, 'bcontent', $block['content'], 15, 70);
633
-            $textarea->setDescription('<span style="font-size:x-small;font-weight:bold;">' . \_AM_SYSTEM_BLOCKS_USEFULTAGS . '</span><br><span style="font-size:x-small;font-weight:normal;">' . \sprintf(_AM_BLOCKTAG1, '{X_SITEURL}', XOOPS_URL . '/') . '</span>');
634
-            $form->addElement($textarea, true);
635
-            $ctypeSelect = new \XoopsFormSelect(\_AM_SYSTEM_BLOCKS_CTYPE, 'bctype', $block['ctype']);
636
-            $ctypeSelect->addOptionArray([
637
-                                             'H' => \_AM_SYSTEM_BLOCKS_HTML,
638
-                                             'P' => \_AM_SYSTEM_BLOCKS_PHP,
639
-                                             'S' => \_AM_SYSTEM_BLOCKS_AFWSMILE,
640
-                                             'T' => \_AM_SYSTEM_BLOCKS_AFNOSMILE,
641
-                                         ]);
642
-            $form->addElement($ctypeSelect);
643
-        } else {
644
-            if ('' !== $block['template']) {
645
-                /** @var \XoopsTplfileHandler $tplfileHandler */
646
-                $tplfileHandler = \xoops_getHandler('tplfile');
647
-                $btemplate      = $tplfileHandler->find($GLOBALS['xoopsConfig']['template_set'], 'block', $block['bid']);
648
-                if (\count($btemplate) > 0) {
649
-                    $form->addElement(new \XoopsFormLabel(\_AM_SYSTEM_BLOCKS_CONTENT, '<a href="' . XOOPS_URL . '/modules/system/admin.php?fct=tplsets&amp;op=edittpl&amp;id=' . $btemplate[0]->getVar('tpl_id') . '">' . \_AM_SYSTEM_BLOCKS_EDITTPL . '</a>'));
650
-                } else {
651
-                    $btemplate2 = $tplfileHandler->find('default', 'block', $block['bid']);
652
-                    if (\count($btemplate2) > 0) {
653
-                        $form->addElement(new \XoopsFormLabel(\_AM_SYSTEM_BLOCKS_CONTENT, '<a href="' . XOOPS_URL . '/modules/system/admin.php?fct=tplsets&amp;op=edittpl&amp;id=' . $btemplate2[0]->getVar('tpl_id') . '" target="_blank">' . \_AM_SYSTEM_BLOCKS_EDITTPL . '</a>'));
654
-                    }
655
-                }
656
-            }
657
-            if (false !== $block['edit_form']) {
658
-                $form->addElement(new \XoopsFormLabel(\_AM_SYSTEM_BLOCKS_OPTIONS, $block['edit_form']));
659
-            }
660
-        }
661
-        $cache_select = new \XoopsFormSelect(\_AM_SYSTEM_BLOCKS_BCACHETIME, 'bcachetime', $block['bcachetime']);
662
-        $cache_select->addOptionArray([
663
-                                          0       => _NOCACHE,
664
-                                          30      => \sprintf(_SECONDS, 30),
665
-                                          60      => _MINUTE,
666
-                                          300     => \sprintf(_MINUTES, 5),
667
-                                          1800    => \sprintf(_MINUTES, 30),
668
-                                          3600    => _HOUR,
669
-                                          18000   => \sprintf(_HOURS, 5),
670
-                                          86400   => _DAY,
671
-                                          259200  => \sprintf(_DAYS, 3),
672
-                                          604800  => _WEEK,
673
-                                          2592000 => _MONTH,
674
-                                      ]);
675
-        $form->addElement($cache_select);
676
-
677
-        /** @var \XoopsGroupPermHandler $grouppermHandler */
678
-        $grouppermHandler = \xoops_getHandler('groupperm');
679
-        $groups           = $grouppermHandler->getGroupIds('block_read', $block['bid']);
680
-
681
-        $form->addElement(new \XoopsFormSelectGroup(\_AM_SYSTEM_BLOCKS_GROUP, 'groups', true, $groups, 5, true));
682
-
683
-        if (isset($block['bid'])) {
684
-            $form->addElement(new \XoopsFormHidden('bid', $block['bid']));
685
-        }
686
-        $form->addElement(new \XoopsFormHidden('op', $block['op']));
687
-        $form->addElement(new \XoopsFormHidden('fct', 'blocksadmin'));
688
-        $buttonTray = new \XoopsFormElementTray('', '&nbsp;');
689
-        if ($block['is_custom']) {
690
-            $buttonTray->addElement(new \XoopsFormButton('', 'previewblock', _PREVIEW, 'submit'));
691
-        }
692
-
693
-        //Submit buttons
694
-        $buttonTray   = new \XoopsFormElementTray('', '');
695
-        $submitButton = new \XoopsFormButton('', 'submitblock', _SUBMIT, 'submit');
696
-        $buttonTray->addElement($submitButton);
697
-
698
-        $cancelButton = new \XoopsFormButton('', '', _CANCEL, 'button');
699
-        $cancelButton->setExtra('onclick="history.go(-1)"');
700
-        $buttonTray->addElement($cancelButton);
701
-
702
-        $form->addElement($buttonTray);
703
-        $form->display();
704
-    }
300
+	}
301
+
302
+	public function deleteBlock(int $bid): void
303
+	{
304
+		//        \xoops_cp_header();
305
+
306
+		\xoops_loadLanguage('admin', 'system');
307
+		\xoops_loadLanguage('admin/blocksadmin', 'system');
308
+		\xoops_loadLanguage('admin/groups', 'system');
309
+
310
+		$myblock = new \XoopsBlock($bid);
311
+
312
+		$sql = \sprintf('DELETE FROM %s WHERE bid = %u', $this->db->prefix('newblocks'), $bid);
313
+		$this->db->queryF($sql) or \trigger_error($GLOBALS['xoopsDB']->error());
314
+
315
+		$sql = \sprintf('DELETE FROM %s WHERE block_id = %u', $this->db->prefix('block_module_link'), $bid);
316
+		$this->db->queryF($sql) or \trigger_error($GLOBALS['xoopsDB']->error());
317
+
318
+		$this->helper->redirect('admin/blocksadmin.php?op=list', 1, _AM_DBUPDATED);
319
+	}
320
+
321
+	public function cloneBlock(int $bid): void
322
+	{
323
+		//require __DIR__ . '/admin_header.php';
324
+		//        \xoops_cp_header();
325
+
326
+		\xoops_loadLanguage('admin', 'system');
327
+		\xoops_loadLanguage('admin/blocksadmin', 'system');
328
+		\xoops_loadLanguage('admin/groups', 'system');
329
+
330
+		$myblock = new \XoopsBlock($bid);
331
+		$sql     = 'SELECT module_id FROM ' . $this->db->prefix('block_module_link') . ' WHERE block_id=' . $bid;
332
+		$result  = $this->db->query($sql);
333
+		$modules = [];
334
+		if ($result instanceof \mysqli_result) {
335
+			while (false !== ($row = $this->db->fetchArray($result))) {
336
+				$modules[] = (int)$row['module_id'];
337
+			}
338
+		}
339
+		$isCustom = \in_array($myblock->getVar('block_type'), ['C', 'E'], true);
340
+		$block    = [
341
+			'title'      => $myblock->getVar('title') . ' Clone',
342
+			'form_title' => \constant('CO_' . $this->moduleDirNameUpper . '_' . 'BLOCKS_CLONEBLOCK'),
343
+			'name'       => $myblock->getVar('name'),
344
+			'side'       => $myblock->getVar('side'),
345
+			'weight'     => $myblock->getVar('weight'),
346
+			'visible'    => $myblock->getVar('visible'),
347
+			'content'    => $myblock->getVar('content', 'N'),
348
+			'modules'    => $modules,
349
+			'is_custom'  => $isCustom,
350
+			'ctype'      => $myblock->getVar('c_type'),
351
+			'bcachetime' => $myblock->getVar('bcachetime'),
352
+			'op'         => 'clone_ok',
353
+			'bid'        => $myblock->getVar('bid'),
354
+			'edit_form'  => $myblock->getOptions(),
355
+			'template'   => $myblock->getVar('template'),
356
+			'options'    => $myblock->getVar('options'),
357
+		];
358
+		echo '<a href="blocksadmin.php">' . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'BADMIN') . '</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;' . \_AM_SYSTEM_BLOCKS_CLONEBLOCK . '<br><br>';
359
+		//        $form = new Blockform();
360
+		//        $form->render();
361
+
362
+		echo $this->render($block);
363
+		//        xoops_cp_footer();
364
+		//        require_once __DIR__ . '/admin_footer.php';
365
+		//        exit();
366
+	}
367
+
368
+	/**
369
+	 * @param null|array|string $options
370
+	 */
371
+	public function isBlockCloned(int $bid, string $bside, string $bweight, string $bvisible, string $bcachetime, ?array $bmodule, ?array $options, ?array $groups): void
372
+	{
373
+		\xoops_loadLanguage('admin', 'system');
374
+		\xoops_loadLanguage('admin/blocksadmin', 'system');
375
+		\xoops_loadLanguage('admin/groups', 'system');
376
+
377
+		$block = new \XoopsBlock($bid);
378
+		$clone = $block->xoopsClone();
379
+		if (empty($bmodule)) {
380
+			//            \xoops_cp_header();
381
+			\xoops_error(\sprintf(_AM_NOTSELNG, _AM_VISIBLEIN));
382
+			\xoops_cp_footer();
383
+			exit();
384
+		}
385
+		$clone->setVar('side', $bside);
386
+		$clone->setVar('weight', $bweight);
387
+		$clone->setVar('visible', $bvisible);
388
+		//$clone->setVar('content', $_POST['bcontent']);
389
+		$clone->setVar('title', Request::getString('btitle', '', 'POST'));
390
+		$clone->setVar('bcachetime', $bcachetime);
391
+		if (\is_array($options) && (\count($options) > 0)) {
392
+			$options = \implode('|', $options);
393
+			$clone->setVar('options', $options);
394
+		}
395
+		$clone->setVar('bid', 0);
396
+		if (\in_array($block->getVar('block_type'), ['C', 'E'], true)) {
397
+			$clone->setVar('block_type', 'E');
398
+		} else {
399
+			$clone->setVar('block_type', 'D');
400
+		}
401
+		//        $newid = $clone->store(); //see https://github.com/XOOPS/XoopsCore25/issues/1105
402
+		if ($clone->store()) {
403
+			$newid = $clone->id();  //get the id of the cloned block
404
+		}
405
+		if (!$newid) {
406
+			//            \xoops_cp_header();
407
+			$clone->getHtmlErrors();
408
+			\xoops_cp_footer();
409
+			exit();
410
+		}
411
+		if ('' !== $clone->getVar('template')) {
412
+			/** @var \XoopsTplfileHandler $tplfileHandler */
413
+			$tplfileHandler = \xoops_getHandler('tplfile');
414
+			$btemplate      = $tplfileHandler->find($GLOBALS['xoopsConfig']['template_set'], 'block', (string)$bid);
415
+			if (\count($btemplate) > 0) {
416
+				$tplclone = $btemplate[0]->xoopsClone();
417
+				$tplclone->setVar('tpl_id', 0);
418
+				$tplclone->setVar('tpl_refid', $newid);
419
+				$tplfileHandler->insert($tplclone);
420
+			}
421
+		}
422
+
423
+		foreach ($bmodule as $bmid) {
424
+			$sql = 'INSERT INTO ' . $this->db->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newid . ', ' . $bmid . ')';
425
+			$this->db->query($sql);
426
+		}
427
+		//$groups = &$GLOBALS['xoopsUser']->getGroups();
428
+		foreach ($groups as $iValue) {
429
+			$sql = 'INSERT INTO ' . $this->db->prefix('group_permission') . ' (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (' . $iValue . ', ' . $newid . ", 1, 'block_read')";
430
+			$this->db->query($sql);
431
+		}
432
+		$this->helper->redirect('admin/blocksadmin.php?op=list', 1, _AM_DBUPDATED);
433
+	}
434
+
435
+	public function setOrder(string $bid, string $title, string $weight, string $visible, string $side, string $bcachetime, ?array $bmodule = null): void
436
+	{
437
+		$myblock = new \XoopsBlock($bid);
438
+		$myblock->setVar('title', $title);
439
+		$myblock->setVar('weight', $weight);
440
+		$myblock->setVar('visible', $visible);
441
+		$myblock->setVar('side', $side);
442
+		$myblock->setVar('bcachetime', $bcachetime);
443
+		$myblock->store();
444
+		//        /** @var \XoopsBlockHandler $blockHandler */
445
+		//        $blockHandler = \xoops_getHandler('block');
446
+		//        return $blockHandler->insert($myblock);
447
+	}
448
+
449
+	public function editBlock(int $bid): void
450
+	{
451
+		//        require_once \dirname(__DIR__,2) . '/admin/admin_header.php';
452
+		//        \xoops_cp_header();
453
+		\xoops_loadLanguage('admin', 'system');
454
+		\xoops_loadLanguage('admin/blocksadmin', 'system');
455
+		\xoops_loadLanguage('admin/groups', 'system');
456
+		//        mpu_adm_menu();
457
+		$myblock = new \XoopsBlock($bid);
458
+		$sql     = 'SELECT module_id FROM ' . $this->db->prefix('block_module_link') . ' WHERE block_id=' . $bid;
459
+		$result  = $this->db->query($sql);
460
+		$modules = [];
461
+		if ($result instanceof \mysqli_result) {
462
+			while (false !== ($row = $this->db->fetchArray($result))) {
463
+				$modules[] = (int)$row['module_id'];
464
+			}
465
+		}
466
+		$isCustom = \in_array($myblock->getVar('block_type'), ['C', 'E'], true);
467
+		$block    = [
468
+			'title'      => $myblock->getVar('title'),
469
+			'form_title' => \_AM_SYSTEM_BLOCKS_EDITBLOCK,
470
+			//        'name'       => $myblock->getVar('name'),
471
+			'side'       => $myblock->getVar('side'),
472
+			'weight'     => $myblock->getVar('weight'),
473
+			'visible'    => $myblock->getVar('visible'),
474
+			'content'    => $myblock->getVar('content', 'N'),
475
+			'modules'    => $modules,
476
+			'is_custom'  => $isCustom,
477
+			'ctype'      => $myblock->getVar('c_type'),
478
+			'bcachetime' => $myblock->getVar('bcachetime'),
479
+			'op'         => 'edit_ok',
480
+			'bid'        => $myblock->getVar('bid'),
481
+			'edit_form'  => $myblock->getOptions(),
482
+			'template'   => $myblock->getVar('template'),
483
+			'options'    => $myblock->getVar('options'),
484
+		];
485
+		echo '<a href="blocksadmin.php">' . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'BADMIN') . '</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;' . \_AM_SYSTEM_BLOCKS_EDITBLOCK . '<br><br>';
486
+
487
+		echo $this->render($block);
488
+	}
489
+
490
+	public function updateBlock(int $bid, string $btitle, string $bside, string $bweight, string $bvisible, string $bcachetime, ?array $bmodule, ?array $options, ?array $groups): void
491
+	{
492
+		$myblock = new \XoopsBlock($bid);
493
+		$myblock->setVar('title', $btitle);
494
+		$myblock->setVar('weight', $bweight);
495
+		$myblock->setVar('visible', $bvisible);
496
+		$myblock->setVar('side', $bside);
497
+		$myblock->setVar('bcachetime', $bcachetime);
498
+		//update block options
499
+		if (isset($options) && \is_array($options)) {
500
+			$optionsCount = \count($options);
501
+			if ($optionsCount > 0) {
502
+				//Convert array values to comma-separated
503
+				foreach ($options as $i => $iValue) {
504
+					if (\is_array($iValue)) {
505
+						$options[$i] = \implode(',', $iValue);
506
+					}
507
+				}
508
+				$options = \implode('|', $options);
509
+				$myblock->setVar('options', $options);
510
+			}
511
+		}
512
+		$myblock->store();
513
+		//        /** @var \XoopsBlockHandler $blockHandler */
514
+		//        $blockHandler = \xoops_getHandler('block');
515
+		//        $blockHandler->insert($myblock);
516
+
517
+		if (!empty($bmodule) && \count($bmodule) > 0) {
518
+			$sql = \sprintf('DELETE FROM `%s` WHERE block_id = %u', $this->db->prefix('block_module_link'), $bid);
519
+			$this->db->query($sql);
520
+			if (\in_array(0, $bmodule, true)) {
521
+				$sql = \sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $this->db->prefix('block_module_link'), $bid, 0);
522
+				$this->db->query($sql);
523
+			} else {
524
+				foreach ($bmodule as $bmid) {
525
+					$sql = \sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $this->db->prefix('block_module_link'), $bid, (int)$bmid);
526
+					$this->db->query($sql);
527
+				}
528
+			}
529
+		}
530
+		$sql = \sprintf('DELETE FROM `%s` WHERE gperm_itemid = %u', $this->db->prefix('group_permission'), $bid);
531
+		$this->db->query($sql);
532
+		if (!empty($groups)) {
533
+			foreach ($groups as $grp) {
534
+				$sql = \sprintf("INSERT INTO `%s` (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (%u, %u, 1, 'block_read')", $this->db->prefix('group_permission'), $grp, $bid);
535
+				$this->db->query($sql);
536
+			}
537
+		}
538
+		$this->helper->redirect('admin/blocksadmin.php', 1, \constant('CO_' . $this->moduleDirNameUpper . '_' . 'UPDATE_SUCCESS'));
539
+	}
540
+
541
+	public function orderBlock(
542
+		array $bid,
543
+		array $oldtitle,
544
+		array $oldside,
545
+		array $oldweight,
546
+		array $oldvisible,
547
+		array $oldgroups,
548
+		array $oldbcachetime,
549
+		array $oldbmodule,
550
+		array $title,
551
+		array $weight,
552
+		array $visible,
553
+		array $side,
554
+		array $bcachetime,
555
+		array $groups,
556
+		array $bmodule
557
+	): void {
558
+		if (!$GLOBALS['xoopsSecurity']->check()) {
559
+			\redirect_header($_SERVER['SCRIPT_NAME'], 3, \implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
560
+		}
561
+		foreach (\array_keys($bid) as $i) {
562
+			if ($oldtitle[$i] !== $title[$i]
563
+				|| $oldweight[$i] !== $weight[$i]
564
+				|| $oldvisible[$i] !== $visible[$i]
565
+				|| $oldside[$i] !== $side[$i]
566
+				|| $oldbcachetime[$i] !== $bcachetime[$i]
567
+				|| $oldbmodule[$i] !== $bmodule[$i]) {
568
+				$this->setOrder($bid[$i], $title[$i], $weight[$i], $visible[$i], $side[$i], $bcachetime[$i], $bmodule[$i]);
569
+			}
570
+			if (!empty($bmodule[$i]) && \count($bmodule[$i]) > 0) {
571
+				$sql = \sprintf('DELETE FROM `%s` WHERE block_id = %u', $this->db->prefix('block_module_link'), $bid[$i]);
572
+				$this->db->query($sql);
573
+				if (\in_array(0, $bmodule[$i], true)) {
574
+					$sql = \sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $this->db->prefix('block_module_link'), $bid[$i], 0);
575
+					$this->db->query($sql);
576
+				} else {
577
+					foreach ($bmodule[$i] as $bmid) {
578
+						$sql = \sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $this->db->prefix('block_module_link'), $bid[$i], (int)$bmid);
579
+						$this->db->query($sql);
580
+					}
581
+				}
582
+			}
583
+			$sql = \sprintf('DELETE FROM `%s` WHERE gperm_itemid = %u', $this->db->prefix('group_permission'), $bid[$i]);
584
+			$this->db->query($sql);
585
+			if (!empty($groups[$i])) {
586
+				foreach ($groups[$i] as $grp) {
587
+					$sql = \sprintf("INSERT INTO `%s` (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (%u, %u, 1, 'block_read')", $this->db->prefix('group_permission'), $grp, $bid[$i]);
588
+					$this->db->query($sql);
589
+				}
590
+			}
591
+		}
592
+
593
+		$this->helper->redirect('admin/blocksadmin.php', 1, \constant('CO_' . $this->moduleDirNameUpper . '_' . 'UPDATE_SUCCESS'));
594
+	}
595
+
596
+	public function render(?array $block = null): void
597
+	{
598
+		\xoops_load('XoopsFormLoader');
599
+		\xoops_loadLanguage('common', $this->moduleDirNameUpper);
600
+
601
+		$form = new \XoopsThemeForm($block['form_title'], 'blockform', 'blocksadmin.php', 'post', true);
602
+		if (isset($block['name'])) {
603
+			$form->addElement(new \XoopsFormLabel(\_AM_SYSTEM_BLOCKS_NAME, $block['name']));
604
+		}
605
+		$sideSelect = new \XoopsFormSelect(\_AM_SYSTEM_BLOCKS_TYPE, 'bside', $block['side']);
606
+		$sideSelect->addOptionArray([
607
+										0 => \_AM_SYSTEM_BLOCKS_SBLEFT,
608
+										1 => \_AM_SYSTEM_BLOCKS_SBRIGHT,
609
+										3 => \_AM_SYSTEM_BLOCKS_CBLEFT,
610
+										4 => \_AM_SYSTEM_BLOCKS_CBRIGHT,
611
+										5 => \_AM_SYSTEM_BLOCKS_CBCENTER,
612
+										7 => \_AM_SYSTEM_BLOCKS_CBBOTTOMLEFT,
613
+										8 => \_AM_SYSTEM_BLOCKS_CBBOTTOMRIGHT,
614
+										9 => \_AM_SYSTEM_BLOCKS_CBBOTTOM,
615
+									]);
616
+		$form->addElement($sideSelect);
617
+		$form->addElement(new \XoopsFormText(\constant('CO_' . $this->moduleDirNameUpper . '_' . 'WEIGHT'), 'bweight', 2, 5, $block['weight']));
618
+		$form->addElement(new \XoopsFormRadioYN(\constant('CO_' . $this->moduleDirNameUpper . '_' . 'VISIBLE'), 'bvisible', $block['visible']));
619
+		$modSelect = new \XoopsFormSelect(\constant('CO_' . $this->moduleDirNameUpper . '_' . 'VISIBLEIN'), 'bmodule', $block['modules'], 5, true);
620
+		/** @var \XoopsModuleHandler $moduleHandler */
621
+		$moduleHandler = \xoops_getHandler('module');
622
+		$criteria      = new \CriteriaCompo(new \Criteria('hasmain', 1));
623
+		$criteria->add(new \Criteria('isactive', 1));
624
+		$moduleList     = $moduleHandler->getList($criteria);
625
+		$moduleList[-1] = \_AM_SYSTEM_BLOCKS_TOPPAGE;
626
+		$moduleList[0]  = \_AM_SYSTEM_BLOCKS_ALLPAGES;
627
+		\ksort($moduleList);
628
+		$modSelect->addOptionArray($moduleList);
629
+		$form->addElement($modSelect);
630
+		$form->addElement(new \XoopsFormText(\_AM_SYSTEM_BLOCKS_TITLE, 'btitle', 50, 255, $block['title']), false);
631
+		if ($block['is_custom']) {
632
+			$textarea = new \XoopsFormDhtmlTextArea(\_AM_SYSTEM_BLOCKS_CONTENT, 'bcontent', $block['content'], 15, 70);
633
+			$textarea->setDescription('<span style="font-size:x-small;font-weight:bold;">' . \_AM_SYSTEM_BLOCKS_USEFULTAGS . '</span><br><span style="font-size:x-small;font-weight:normal;">' . \sprintf(_AM_BLOCKTAG1, '{X_SITEURL}', XOOPS_URL . '/') . '</span>');
634
+			$form->addElement($textarea, true);
635
+			$ctypeSelect = new \XoopsFormSelect(\_AM_SYSTEM_BLOCKS_CTYPE, 'bctype', $block['ctype']);
636
+			$ctypeSelect->addOptionArray([
637
+											 'H' => \_AM_SYSTEM_BLOCKS_HTML,
638
+											 'P' => \_AM_SYSTEM_BLOCKS_PHP,
639
+											 'S' => \_AM_SYSTEM_BLOCKS_AFWSMILE,
640
+											 'T' => \_AM_SYSTEM_BLOCKS_AFNOSMILE,
641
+										 ]);
642
+			$form->addElement($ctypeSelect);
643
+		} else {
644
+			if ('' !== $block['template']) {
645
+				/** @var \XoopsTplfileHandler $tplfileHandler */
646
+				$tplfileHandler = \xoops_getHandler('tplfile');
647
+				$btemplate      = $tplfileHandler->find($GLOBALS['xoopsConfig']['template_set'], 'block', $block['bid']);
648
+				if (\count($btemplate) > 0) {
649
+					$form->addElement(new \XoopsFormLabel(\_AM_SYSTEM_BLOCKS_CONTENT, '<a href="' . XOOPS_URL . '/modules/system/admin.php?fct=tplsets&amp;op=edittpl&amp;id=' . $btemplate[0]->getVar('tpl_id') . '">' . \_AM_SYSTEM_BLOCKS_EDITTPL . '</a>'));
650
+				} else {
651
+					$btemplate2 = $tplfileHandler->find('default', 'block', $block['bid']);
652
+					if (\count($btemplate2) > 0) {
653
+						$form->addElement(new \XoopsFormLabel(\_AM_SYSTEM_BLOCKS_CONTENT, '<a href="' . XOOPS_URL . '/modules/system/admin.php?fct=tplsets&amp;op=edittpl&amp;id=' . $btemplate2[0]->getVar('tpl_id') . '" target="_blank">' . \_AM_SYSTEM_BLOCKS_EDITTPL . '</a>'));
654
+					}
655
+				}
656
+			}
657
+			if (false !== $block['edit_form']) {
658
+				$form->addElement(new \XoopsFormLabel(\_AM_SYSTEM_BLOCKS_OPTIONS, $block['edit_form']));
659
+			}
660
+		}
661
+		$cache_select = new \XoopsFormSelect(\_AM_SYSTEM_BLOCKS_BCACHETIME, 'bcachetime', $block['bcachetime']);
662
+		$cache_select->addOptionArray([
663
+										  0       => _NOCACHE,
664
+										  30      => \sprintf(_SECONDS, 30),
665
+										  60      => _MINUTE,
666
+										  300     => \sprintf(_MINUTES, 5),
667
+										  1800    => \sprintf(_MINUTES, 30),
668
+										  3600    => _HOUR,
669
+										  18000   => \sprintf(_HOURS, 5),
670
+										  86400   => _DAY,
671
+										  259200  => \sprintf(_DAYS, 3),
672
+										  604800  => _WEEK,
673
+										  2592000 => _MONTH,
674
+									  ]);
675
+		$form->addElement($cache_select);
676
+
677
+		/** @var \XoopsGroupPermHandler $grouppermHandler */
678
+		$grouppermHandler = \xoops_getHandler('groupperm');
679
+		$groups           = $grouppermHandler->getGroupIds('block_read', $block['bid']);
680
+
681
+		$form->addElement(new \XoopsFormSelectGroup(\_AM_SYSTEM_BLOCKS_GROUP, 'groups', true, $groups, 5, true));
682
+
683
+		if (isset($block['bid'])) {
684
+			$form->addElement(new \XoopsFormHidden('bid', $block['bid']));
685
+		}
686
+		$form->addElement(new \XoopsFormHidden('op', $block['op']));
687
+		$form->addElement(new \XoopsFormHidden('fct', 'blocksadmin'));
688
+		$buttonTray = new \XoopsFormElementTray('', '&nbsp;');
689
+		if ($block['is_custom']) {
690
+			$buttonTray->addElement(new \XoopsFormButton('', 'previewblock', _PREVIEW, 'submit'));
691
+		}
692
+
693
+		//Submit buttons
694
+		$buttonTray   = new \XoopsFormElementTray('', '');
695
+		$submitButton = new \XoopsFormButton('', 'submitblock', _SUBMIT, 'submit');
696
+		$buttonTray->addElement($submitButton);
697
+
698
+		$cancelButton = new \XoopsFormButton('', '', _CANCEL, 'button');
699
+		$cancelButton->setExtra('onclick="history.go(-1)"');
700
+		$buttonTray->addElement($cancelButton);
701
+
702
+		$form->addElement($buttonTray);
703
+		$form->display();
704
+	}
705 705
 }
Please login to merge, or discard this patch.
Spacing   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
      */
39 39
     public function __construct(?\XoopsDatabase $db, Helper $helper)
40 40
     {
41
-        if (null === $db) {
41
+        if (null===$db) {
42 42
             $db = \XoopsDatabaseFactory::getDatabaseConnection();
43 43
         }
44 44
         $this->db                 = $db;
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
     public function listBlocks(): void
56 56
     {
57 57
         global $xoopsModule, $pathIcon16;
58
-        require_once XOOPS_ROOT_PATH . '/class/xoopslists.php';
58
+        require_once XOOPS_ROOT_PATH.'/class/xoopslists.php';
59 59
         //        xoops_loadLanguage('admin', 'system');
60 60
         //        xoops_loadLanguage('admin/blocksadmin', 'system');
61 61
         //        xoops_loadLanguage('admin/groups', 'system');
@@ -76,14 +76,14 @@  discard block
 block discarded – undo
76 76
         $moduleList[0]  = \_AM_SYSTEM_BLOCKS_ALLPAGES;
77 77
         \ksort($moduleList);
78 78
         echo "
79
-        <h4 style='text-align:left;'>" . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'BADMIN') . '</h4>';
80
-        echo "<form action='" . $_SERVER['SCRIPT_NAME'] . "' name='blockadmin' method='post'>";
79
+        <h4 style='text-align:left;'>" . \constant('CO_'.$this->moduleDirNameUpper.'_'.'BADMIN').'</h4>';
80
+        echo "<form action='".$_SERVER['SCRIPT_NAME']."' name='blockadmin' method='post'>";
81 81
         echo $GLOBALS['xoopsSecurity']->getTokenHTML();
82 82
         echo "<table width='100%' class='outer' cellpadding='4' cellspacing='1'>
83 83
         <tr valign='middle'><th align='center'>"
84 84
              . \_AM_SYSTEM_BLOCKS_TITLE
85 85
              . "</th><th align='center' nowrap='nowrap'>"
86
-             . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'SIDE')
86
+             . \constant('CO_'.$this->moduleDirNameUpper.'_'.'SIDE')
87 87
              . '<br>'
88 88
              . _LEFT
89 89
              . '-'
@@ -92,10 +92,10 @@  discard block
 block discarded – undo
92 92
              . _RIGHT
93 93
              . "</th><th align='center'>"
94 94
              . \constant(
95
-                 'CO_' . $this->moduleDirNameUpper . '_' . 'WEIGHT'
95
+                 'CO_'.$this->moduleDirNameUpper.'_'.'WEIGHT'
96 96
              )
97 97
              . "</th><th align='center'>"
98
-             . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'VISIBLE')
98
+             . \constant('CO_'.$this->moduleDirNameUpper.'_'.'VISIBLE')
99 99
              . "</th><th align='center'>"
100 100
              . \_AM_SYSTEM_BLOCKS_VISIBLEIN
101 101
              . "</th><th align='center'>"
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
              . "</th><th align='center'>"
104 104
              . \_AM_SYSTEM_BLOCKS_BCACHETIME
105 105
              . "</th><th align='center'>"
106
-             . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'ACTION')
106
+             . \constant('CO_'.$this->moduleDirNameUpper.'_'.'ACTION')
107 107
              . '</th></tr>
108 108
         ';
109 109
         $blockArray = \XoopsBlock::getByModule($xoopsModule->mid());
@@ -124,19 +124,19 @@  discard block
 block discarded – undo
124 124
         ];
125 125
         foreach ($blockArray as $i) {
126 126
             $groupsPermissions = $grouppermHandler->getGroupIds('block_read', $i->getVar('bid'));
127
-            $sql               = 'SELECT module_id FROM ' . $this->db->prefix('block_module_link') . ' WHERE block_id=' . $i->getVar('bid');
127
+            $sql               = 'SELECT module_id FROM '.$this->db->prefix('block_module_link').' WHERE block_id='.$i->getVar('bid');
128 128
             $result            = $this->db->query($sql);
129 129
             $modules           = [];
130 130
             if (!$result instanceof \mysqli_result) {
131
-                \trigger_error("Query Failed! SQL: $sql Error: " . $this->db->error(), \E_USER_ERROR);
131
+                \trigger_error("Query Failed! SQL: $sql Error: ".$this->db->error(), \E_USER_ERROR);
132 132
             }
133
-            while (false !== ($row = $this->db->fetchArray($result))) {
134
-                $modules[] = (int)$row['module_id'];
133
+            while (false!==($row = $this->db->fetchArray($result))) {
134
+                $modules[] = (int) $row['module_id'];
135 135
             }
136 136
 
137 137
             $cachetimeOptions = '';
138 138
             foreach ($cachetimes as $cachetime => $cachetimeName) {
139
-                if ($i->getVar('bcachetime') == $cachetime) {
139
+                if ($i->getVar('bcachetime')==$cachetime) {
140 140
                     $cachetimeOptions .= "<option value='$cachetime' selected='selected'>$cachetimeName</option>\n";
141 141
                 } else {
142 142
                     $cachetimeOptions .= "<option value='$cachetime'>$cachetimeName</option>\n";
@@ -153,29 +153,29 @@  discard block
 block discarded – undo
153 153
             $ssel0 = $ssel1;
154 154
             $sel1  = $ssel0;
155 155
             $sel0  = $sel1;
156
-            if (1 === $i->getVar('visible')) {
156
+            if (1===$i->getVar('visible')) {
157 157
                 $sel1 = ' checked';
158 158
             } else {
159 159
                 $sel0 = ' checked';
160 160
             }
161
-            if (\XOOPS_SIDEBLOCK_LEFT === $i->getVar('side')) {
161
+            if (\XOOPS_SIDEBLOCK_LEFT===$i->getVar('side')) {
162 162
                 $ssel0 = ' checked';
163
-            } elseif (\XOOPS_SIDEBLOCK_RIGHT === $i->getVar('side')) {
163
+            } elseif (\XOOPS_SIDEBLOCK_RIGHT===$i->getVar('side')) {
164 164
                 $ssel1 = ' checked';
165
-            } elseif (\XOOPS_CENTERBLOCK_LEFT === $i->getVar('side')) {
165
+            } elseif (\XOOPS_CENTERBLOCK_LEFT===$i->getVar('side')) {
166 166
                 $ssel2 = ' checked';
167
-            } elseif (\XOOPS_CENTERBLOCK_RIGHT === $i->getVar('side')) {
167
+            } elseif (\XOOPS_CENTERBLOCK_RIGHT===$i->getVar('side')) {
168 168
                 $ssel4 = ' checked';
169
-            } elseif (\XOOPS_CENTERBLOCK_CENTER === $i->getVar('side')) {
169
+            } elseif (\XOOPS_CENTERBLOCK_CENTER===$i->getVar('side')) {
170 170
                 $ssel3 = ' checked';
171
-            } elseif (\XOOPS_CENTERBLOCK_BOTTOMLEFT === $i->getVar('side')) {
171
+            } elseif (\XOOPS_CENTERBLOCK_BOTTOMLEFT===$i->getVar('side')) {
172 172
                 $ssel5 = ' checked';
173
-            } elseif (\XOOPS_CENTERBLOCK_BOTTOMRIGHT === $i->getVar('side')) {
173
+            } elseif (\XOOPS_CENTERBLOCK_BOTTOMRIGHT===$i->getVar('side')) {
174 174
                 $ssel6 = ' checked';
175
-            } elseif (\XOOPS_CENTERBLOCK_BOTTOM === $i->getVar('side')) {
175
+            } elseif (\XOOPS_CENTERBLOCK_BOTTOM===$i->getVar('side')) {
176 176
                 $ssel7 = ' checked';
177 177
             }
178
-            if ('' === $i->getVar('title')) {
178
+            if (''===$i->getVar('title')) {
179 179
                 $title = '&nbsp;';
180 180
             } else {
181 181
                 $title = $i->getVar('title');
@@ -246,27 +246,27 @@  discard block
 block discarded – undo
246 246
                  . _NO
247 247
                  . '</td>';
248 248
 
249
-            echo "<td class='$class' align='center'><select size='5' name='bmodule[" . $i->getVar('bid') . "][]' id='bmodule[" . $i->getVar('bid') . "][]' multiple='multiple'>";
249
+            echo "<td class='$class' align='center'><select size='5' name='bmodule[".$i->getVar('bid')."][]' id='bmodule[".$i->getVar('bid')."][]' multiple='multiple'>";
250 250
             foreach ($moduleList as $k => $v) {
251
-                echo "<option value='$k'" . (\in_array($k, $modules, true) ? " selected='selected'" : '') . ">$v</option>";
251
+                echo "<option value='$k'".(\in_array($k, $modules, true) ? " selected='selected'" : '').">$v</option>";
252 252
             }
253 253
             echo '</select></td>';
254 254
 
255
-            echo "<td class='$class' align='center'><select size='5' name='groups[" . $i->getVar('bid') . "][]' id='groups[" . $i->getVar('bid') . "][]' multiple='multiple'>";
255
+            echo "<td class='$class' align='center'><select size='5' name='groups[".$i->getVar('bid')."][]' id='groups[".$i->getVar('bid')."][]' multiple='multiple'>";
256 256
             foreach ($groups as $grp) {
257
-                echo "<option value='" . $grp->getVar('groupid') . "' " . (\in_array($grp->getVar('groupid'), $groupsPermissions, true) ? " selected='selected'" : '') . '>' . $grp->getVar('name') . '</option>';
257
+                echo "<option value='".$grp->getVar('groupid')."' ".(\in_array($grp->getVar('groupid'), $groupsPermissions, true) ? " selected='selected'" : '').'>'.$grp->getVar('name').'</option>';
258 258
             }
259 259
             echo '</select></td>';
260 260
 
261 261
             // Cache lifetime
262
-            echo '<td class="' . $class . '" align="center"> <select name="bcachetime[' . $i->getVar('bid') . ']" size="1">' . $cachetimeOptions . '</select>
262
+            echo '<td class="'.$class.'" align="center"> <select name="bcachetime['.$i->getVar('bid').']" size="1">'.$cachetimeOptions.'</select>
263 263
                                     </td>';
264 264
 
265 265
             // Actions
266 266
 
267 267
             echo "<td class='$class' align='center'>
268
-                <a href='blocksadmin.php?op=edit&amp;bid=" . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/edit.png' . " alt='" . _EDIT . "' title='" . _EDIT . "'></a> 
269
-                <a href='blocksadmin.php?op=clone&amp;bid=" . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/editcopy.png' . " alt='" . _CLONE . "' title='" . _CLONE . "'></a>";
268
+                <a href='blocksadmin.php?op=edit&amp;bid=".$i->getVar('bid')."'><img src=".$pathIcon16.'/edit.png'." alt='"._EDIT."' title='"._EDIT."'></a> 
269
+                <a href='blocksadmin.php?op=clone&amp;bid=" . $i->getVar('bid')."'><img src=".$pathIcon16.'/editcopy.png'." alt='"._CLONE."' title='"._CLONE."'></a>";
270 270
             //            if ('S' !== $i->getVar('block_type') && 'M' !== $i->getVar('block_type')) {
271 271
             //                echo "&nbsp;<a href='" . XOOPS_URL . '/modules/system/admin.php?fct=blocksadmin&amp;op=delete&amp;bid=' . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/delete.png' . " alt='" . _DELETE . "' title='" . _DELETE . "'>
272 272
             //                     </a>";
@@ -275,25 +275,25 @@  discard block
 block discarded – undo
275 275
             //            if ('S' !== $i->getVar('block_type') && 'M' !== $i->getVar('block_type')) {
276 276
             if (!\in_array($i->getVar('block_type'), ['M', 'S'], true)) {
277 277
                 echo "&nbsp;
278
-                <a href='blocksadmin.php?op=delete&amp;bid=" . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/delete.png' . " alt='" . _DELETE . "' title='" . _DELETE . "'>
278
+                <a href='blocksadmin.php?op=delete&amp;bid=" . $i->getVar('bid')."'><img src=".$pathIcon16.'/delete.png'." alt='"._DELETE."' title='"._DELETE."'>
279 279
                      </a>";
280 280
             }
281 281
             echo "
282
-            <input type='hidden' name='oldtitle[" . $i->getVar('bid') . "]' value='" . $i->getVar('title') . "'>
283
-            <input type='hidden' name='oldside[" . $i->getVar('bid') . "]' value='" . $i->getVar('side') . "'>
284
-            <input type='hidden' name='oldweight[" . $i->getVar('bid') . "]' value='" . $i->getVar('weight') . "'>
285
-            <input type='hidden' name='oldvisible[" . $i->getVar('bid') . "]' value='" . $i->getVar('visible') . "'>
286
-            <input type='hidden' name='oldgroups[" . $i->getVar('groups') . "]' value='" . $i->getVar('groups') . "'>
287
-            <input type='hidden' name='oldbcachetime[" . $i->getVar('bid') . "]' value='" . $i->getVar('bcachetime') . "'>
288
-            <input type='hidden' name='bid[" . $i->getVar('bid') . "]' value='" . $i->getVar('bid') . "'>
282
+            <input type='hidden' name='oldtitle[" . $i->getVar('bid')."]' value='".$i->getVar('title')."'>
283
+            <input type='hidden' name='oldside[" . $i->getVar('bid')."]' value='".$i->getVar('side')."'>
284
+            <input type='hidden' name='oldweight[" . $i->getVar('bid')."]' value='".$i->getVar('weight')."'>
285
+            <input type='hidden' name='oldvisible[" . $i->getVar('bid')."]' value='".$i->getVar('visible')."'>
286
+            <input type='hidden' name='oldgroups[" . $i->getVar('groups')."]' value='".$i->getVar('groups')."'>
287
+            <input type='hidden' name='oldbcachetime[" . $i->getVar('bid')."]' value='".$i->getVar('bcachetime')."'>
288
+            <input type='hidden' name='bid[" . $i->getVar('bid')."]' value='".$i->getVar('bid')."'>
289 289
             </td></tr>
290 290
             ";
291
-            $class = ('even' === $class) ? 'odd' : 'even';
291
+            $class = ('even'===$class) ? 'odd' : 'even';
292 292
         }
293 293
         echo "<tr><td class='foot' align='center' colspan='8'>
294 294
         <input type='hidden' name='op' value='order'>
295
-        " . $GLOBALS['xoopsSecurity']->getTokenHTML() . "
296
-        <input type='submit' name='submit' value='" . _SUBMIT . "'>
295
+        " . $GLOBALS['xoopsSecurity']->getTokenHTML()."
296
+        <input type='submit' name='submit' value='" . _SUBMIT."'>
297 297
         </td></tr></table>
298 298
         </form>
299 299
         <br><br>";
@@ -328,18 +328,18 @@  discard block
 block discarded – undo
328 328
         \xoops_loadLanguage('admin/groups', 'system');
329 329
 
330 330
         $myblock = new \XoopsBlock($bid);
331
-        $sql     = 'SELECT module_id FROM ' . $this->db->prefix('block_module_link') . ' WHERE block_id=' . $bid;
331
+        $sql     = 'SELECT module_id FROM '.$this->db->prefix('block_module_link').' WHERE block_id='.$bid;
332 332
         $result  = $this->db->query($sql);
333 333
         $modules = [];
334 334
         if ($result instanceof \mysqli_result) {
335
-            while (false !== ($row = $this->db->fetchArray($result))) {
336
-                $modules[] = (int)$row['module_id'];
335
+            while (false!==($row = $this->db->fetchArray($result))) {
336
+                $modules[] = (int) $row['module_id'];
337 337
             }
338 338
         }
339 339
         $isCustom = \in_array($myblock->getVar('block_type'), ['C', 'E'], true);
340 340
         $block    = [
341
-            'title'      => $myblock->getVar('title') . ' Clone',
342
-            'form_title' => \constant('CO_' . $this->moduleDirNameUpper . '_' . 'BLOCKS_CLONEBLOCK'),
341
+            'title'      => $myblock->getVar('title').' Clone',
342
+            'form_title' => \constant('CO_'.$this->moduleDirNameUpper.'_'.'BLOCKS_CLONEBLOCK'),
343 343
             'name'       => $myblock->getVar('name'),
344 344
             'side'       => $myblock->getVar('side'),
345 345
             'weight'     => $myblock->getVar('weight'),
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
             'template'   => $myblock->getVar('template'),
356 356
             'options'    => $myblock->getVar('options'),
357 357
         ];
358
-        echo '<a href="blocksadmin.php">' . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'BADMIN') . '</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;' . \_AM_SYSTEM_BLOCKS_CLONEBLOCK . '<br><br>';
358
+        echo '<a href="blocksadmin.php">'.\constant('CO_'.$this->moduleDirNameUpper.'_'.'BADMIN').'</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;'.\_AM_SYSTEM_BLOCKS_CLONEBLOCK.'<br><br>';
359 359
         //        $form = new Blockform();
360 360
         //        $form->render();
361 361
 
@@ -388,7 +388,7 @@  discard block
 block discarded – undo
388 388
         //$clone->setVar('content', $_POST['bcontent']);
389 389
         $clone->setVar('title', Request::getString('btitle', '', 'POST'));
390 390
         $clone->setVar('bcachetime', $bcachetime);
391
-        if (\is_array($options) && (\count($options) > 0)) {
391
+        if (\is_array($options) && (\count($options)>0)) {
392 392
             $options = \implode('|', $options);
393 393
             $clone->setVar('options', $options);
394 394
         }
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
         }
401 401
         //        $newid = $clone->store(); //see https://github.com/XOOPS/XoopsCore25/issues/1105
402 402
         if ($clone->store()) {
403
-            $newid = $clone->id();  //get the id of the cloned block
403
+            $newid = $clone->id(); //get the id of the cloned block
404 404
         }
405 405
         if (!$newid) {
406 406
             //            \xoops_cp_header();
@@ -408,11 +408,11 @@  discard block
 block discarded – undo
408 408
             \xoops_cp_footer();
409 409
             exit();
410 410
         }
411
-        if ('' !== $clone->getVar('template')) {
411
+        if (''!==$clone->getVar('template')) {
412 412
             /** @var \XoopsTplfileHandler $tplfileHandler */
413 413
             $tplfileHandler = \xoops_getHandler('tplfile');
414
-            $btemplate      = $tplfileHandler->find($GLOBALS['xoopsConfig']['template_set'], 'block', (string)$bid);
415
-            if (\count($btemplate) > 0) {
414
+            $btemplate      = $tplfileHandler->find($GLOBALS['xoopsConfig']['template_set'], 'block', (string) $bid);
415
+            if (\count($btemplate)>0) {
416 416
                 $tplclone = $btemplate[0]->xoopsClone();
417 417
                 $tplclone->setVar('tpl_id', 0);
418 418
                 $tplclone->setVar('tpl_refid', $newid);
@@ -421,12 +421,12 @@  discard block
 block discarded – undo
421 421
         }
422 422
 
423 423
         foreach ($bmodule as $bmid) {
424
-            $sql = 'INSERT INTO ' . $this->db->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newid . ', ' . $bmid . ')';
424
+            $sql = 'INSERT INTO '.$this->db->prefix('block_module_link').' (block_id, module_id) VALUES ('.$newid.', '.$bmid.')';
425 425
             $this->db->query($sql);
426 426
         }
427 427
         //$groups = &$GLOBALS['xoopsUser']->getGroups();
428 428
         foreach ($groups as $iValue) {
429
-            $sql = 'INSERT INTO ' . $this->db->prefix('group_permission') . ' (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (' . $iValue . ', ' . $newid . ", 1, 'block_read')";
429
+            $sql = 'INSERT INTO '.$this->db->prefix('group_permission').' (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES ('.$iValue.', '.$newid.", 1, 'block_read')";
430 430
             $this->db->query($sql);
431 431
         }
432 432
         $this->helper->redirect('admin/blocksadmin.php?op=list', 1, _AM_DBUPDATED);
@@ -455,12 +455,12 @@  discard block
 block discarded – undo
455 455
         \xoops_loadLanguage('admin/groups', 'system');
456 456
         //        mpu_adm_menu();
457 457
         $myblock = new \XoopsBlock($bid);
458
-        $sql     = 'SELECT module_id FROM ' . $this->db->prefix('block_module_link') . ' WHERE block_id=' . $bid;
458
+        $sql     = 'SELECT module_id FROM '.$this->db->prefix('block_module_link').' WHERE block_id='.$bid;
459 459
         $result  = $this->db->query($sql);
460 460
         $modules = [];
461 461
         if ($result instanceof \mysqli_result) {
462
-            while (false !== ($row = $this->db->fetchArray($result))) {
463
-                $modules[] = (int)$row['module_id'];
462
+            while (false!==($row = $this->db->fetchArray($result))) {
463
+                $modules[] = (int) $row['module_id'];
464 464
             }
465 465
         }
466 466
         $isCustom = \in_array($myblock->getVar('block_type'), ['C', 'E'], true);
@@ -482,7 +482,7 @@  discard block
 block discarded – undo
482 482
             'template'   => $myblock->getVar('template'),
483 483
             'options'    => $myblock->getVar('options'),
484 484
         ];
485
-        echo '<a href="blocksadmin.php">' . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'BADMIN') . '</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;' . \_AM_SYSTEM_BLOCKS_EDITBLOCK . '<br><br>';
485
+        echo '<a href="blocksadmin.php">'.\constant('CO_'.$this->moduleDirNameUpper.'_'.'BADMIN').'</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;'.\_AM_SYSTEM_BLOCKS_EDITBLOCK.'<br><br>';
486 486
 
487 487
         echo $this->render($block);
488 488
     }
@@ -498,7 +498,7 @@  discard block
 block discarded – undo
498 498
         //update block options
499 499
         if (isset($options) && \is_array($options)) {
500 500
             $optionsCount = \count($options);
501
-            if ($optionsCount > 0) {
501
+            if ($optionsCount>0) {
502 502
                 //Convert array values to comma-separated
503 503
                 foreach ($options as $i => $iValue) {
504 504
                     if (\is_array($iValue)) {
@@ -514,7 +514,7 @@  discard block
 block discarded – undo
514 514
         //        $blockHandler = \xoops_getHandler('block');
515 515
         //        $blockHandler->insert($myblock);
516 516
 
517
-        if (!empty($bmodule) && \count($bmodule) > 0) {
517
+        if (!empty($bmodule) && \count($bmodule)>0) {
518 518
             $sql = \sprintf('DELETE FROM `%s` WHERE block_id = %u', $this->db->prefix('block_module_link'), $bid);
519 519
             $this->db->query($sql);
520 520
             if (\in_array(0, $bmodule, true)) {
@@ -522,7 +522,7 @@  discard block
 block discarded – undo
522 522
                 $this->db->query($sql);
523 523
             } else {
524 524
                 foreach ($bmodule as $bmid) {
525
-                    $sql = \sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $this->db->prefix('block_module_link'), $bid, (int)$bmid);
525
+                    $sql = \sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $this->db->prefix('block_module_link'), $bid, (int) $bmid);
526 526
                     $this->db->query($sql);
527 527
                 }
528 528
             }
@@ -535,7 +535,7 @@  discard block
 block discarded – undo
535 535
                 $this->db->query($sql);
536 536
             }
537 537
         }
538
-        $this->helper->redirect('admin/blocksadmin.php', 1, \constant('CO_' . $this->moduleDirNameUpper . '_' . 'UPDATE_SUCCESS'));
538
+        $this->helper->redirect('admin/blocksadmin.php', 1, \constant('CO_'.$this->moduleDirNameUpper.'_'.'UPDATE_SUCCESS'));
539 539
     }
540 540
 
541 541
     public function orderBlock(
@@ -559,15 +559,15 @@  discard block
 block discarded – undo
559 559
             \redirect_header($_SERVER['SCRIPT_NAME'], 3, \implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
560 560
         }
561 561
         foreach (\array_keys($bid) as $i) {
562
-            if ($oldtitle[$i] !== $title[$i]
563
-                || $oldweight[$i] !== $weight[$i]
564
-                || $oldvisible[$i] !== $visible[$i]
565
-                || $oldside[$i] !== $side[$i]
566
-                || $oldbcachetime[$i] !== $bcachetime[$i]
567
-                || $oldbmodule[$i] !== $bmodule[$i]) {
562
+            if ($oldtitle[$i]!==$title[$i]
563
+                || $oldweight[$i]!==$weight[$i]
564
+                || $oldvisible[$i]!==$visible[$i]
565
+                || $oldside[$i]!==$side[$i]
566
+                || $oldbcachetime[$i]!==$bcachetime[$i]
567
+                || $oldbmodule[$i]!==$bmodule[$i]) {
568 568
                 $this->setOrder($bid[$i], $title[$i], $weight[$i], $visible[$i], $side[$i], $bcachetime[$i], $bmodule[$i]);
569 569
             }
570
-            if (!empty($bmodule[$i]) && \count($bmodule[$i]) > 0) {
570
+            if (!empty($bmodule[$i]) && \count($bmodule[$i])>0) {
571 571
                 $sql = \sprintf('DELETE FROM `%s` WHERE block_id = %u', $this->db->prefix('block_module_link'), $bid[$i]);
572 572
                 $this->db->query($sql);
573 573
                 if (\in_array(0, $bmodule[$i], true)) {
@@ -575,7 +575,7 @@  discard block
 block discarded – undo
575 575
                     $this->db->query($sql);
576 576
                 } else {
577 577
                     foreach ($bmodule[$i] as $bmid) {
578
-                        $sql = \sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $this->db->prefix('block_module_link'), $bid[$i], (int)$bmid);
578
+                        $sql = \sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $this->db->prefix('block_module_link'), $bid[$i], (int) $bmid);
579 579
                         $this->db->query($sql);
580 580
                     }
581 581
                 }
@@ -590,7 +590,7 @@  discard block
 block discarded – undo
590 590
             }
591 591
         }
592 592
 
593
-        $this->helper->redirect('admin/blocksadmin.php', 1, \constant('CO_' . $this->moduleDirNameUpper . '_' . 'UPDATE_SUCCESS'));
593
+        $this->helper->redirect('admin/blocksadmin.php', 1, \constant('CO_'.$this->moduleDirNameUpper.'_'.'UPDATE_SUCCESS'));
594 594
     }
595 595
 
596 596
     public function render(?array $block = null): void
@@ -614,9 +614,9 @@  discard block
 block discarded – undo
614 614
                                         9 => \_AM_SYSTEM_BLOCKS_CBBOTTOM,
615 615
                                     ]);
616 616
         $form->addElement($sideSelect);
617
-        $form->addElement(new \XoopsFormText(\constant('CO_' . $this->moduleDirNameUpper . '_' . 'WEIGHT'), 'bweight', 2, 5, $block['weight']));
618
-        $form->addElement(new \XoopsFormRadioYN(\constant('CO_' . $this->moduleDirNameUpper . '_' . 'VISIBLE'), 'bvisible', $block['visible']));
619
-        $modSelect = new \XoopsFormSelect(\constant('CO_' . $this->moduleDirNameUpper . '_' . 'VISIBLEIN'), 'bmodule', $block['modules'], 5, true);
617
+        $form->addElement(new \XoopsFormText(\constant('CO_'.$this->moduleDirNameUpper.'_'.'WEIGHT'), 'bweight', 2, 5, $block['weight']));
618
+        $form->addElement(new \XoopsFormRadioYN(\constant('CO_'.$this->moduleDirNameUpper.'_'.'VISIBLE'), 'bvisible', $block['visible']));
619
+        $modSelect = new \XoopsFormSelect(\constant('CO_'.$this->moduleDirNameUpper.'_'.'VISIBLEIN'), 'bmodule', $block['modules'], 5, true);
620 620
         /** @var \XoopsModuleHandler $moduleHandler */
621 621
         $moduleHandler = \xoops_getHandler('module');
622 622
         $criteria      = new \CriteriaCompo(new \Criteria('hasmain', 1));
@@ -630,7 +630,7 @@  discard block
 block discarded – undo
630 630
         $form->addElement(new \XoopsFormText(\_AM_SYSTEM_BLOCKS_TITLE, 'btitle', 50, 255, $block['title']), false);
631 631
         if ($block['is_custom']) {
632 632
             $textarea = new \XoopsFormDhtmlTextArea(\_AM_SYSTEM_BLOCKS_CONTENT, 'bcontent', $block['content'], 15, 70);
633
-            $textarea->setDescription('<span style="font-size:x-small;font-weight:bold;">' . \_AM_SYSTEM_BLOCKS_USEFULTAGS . '</span><br><span style="font-size:x-small;font-weight:normal;">' . \sprintf(_AM_BLOCKTAG1, '{X_SITEURL}', XOOPS_URL . '/') . '</span>');
633
+            $textarea->setDescription('<span style="font-size:x-small;font-weight:bold;">'.\_AM_SYSTEM_BLOCKS_USEFULTAGS.'</span><br><span style="font-size:x-small;font-weight:normal;">'.\sprintf(_AM_BLOCKTAG1, '{X_SITEURL}', XOOPS_URL.'/').'</span>');
634 634
             $form->addElement($textarea, true);
635 635
             $ctypeSelect = new \XoopsFormSelect(\_AM_SYSTEM_BLOCKS_CTYPE, 'bctype', $block['ctype']);
636 636
             $ctypeSelect->addOptionArray([
@@ -641,20 +641,20 @@  discard block
 block discarded – undo
641 641
                                          ]);
642 642
             $form->addElement($ctypeSelect);
643 643
         } else {
644
-            if ('' !== $block['template']) {
644
+            if (''!==$block['template']) {
645 645
                 /** @var \XoopsTplfileHandler $tplfileHandler */
646 646
                 $tplfileHandler = \xoops_getHandler('tplfile');
647 647
                 $btemplate      = $tplfileHandler->find($GLOBALS['xoopsConfig']['template_set'], 'block', $block['bid']);
648
-                if (\count($btemplate) > 0) {
649
-                    $form->addElement(new \XoopsFormLabel(\_AM_SYSTEM_BLOCKS_CONTENT, '<a href="' . XOOPS_URL . '/modules/system/admin.php?fct=tplsets&amp;op=edittpl&amp;id=' . $btemplate[0]->getVar('tpl_id') . '">' . \_AM_SYSTEM_BLOCKS_EDITTPL . '</a>'));
648
+                if (\count($btemplate)>0) {
649
+                    $form->addElement(new \XoopsFormLabel(\_AM_SYSTEM_BLOCKS_CONTENT, '<a href="'.XOOPS_URL.'/modules/system/admin.php?fct=tplsets&amp;op=edittpl&amp;id='.$btemplate[0]->getVar('tpl_id').'">'.\_AM_SYSTEM_BLOCKS_EDITTPL.'</a>'));
650 650
                 } else {
651 651
                     $btemplate2 = $tplfileHandler->find('default', 'block', $block['bid']);
652
-                    if (\count($btemplate2) > 0) {
653
-                        $form->addElement(new \XoopsFormLabel(\_AM_SYSTEM_BLOCKS_CONTENT, '<a href="' . XOOPS_URL . '/modules/system/admin.php?fct=tplsets&amp;op=edittpl&amp;id=' . $btemplate2[0]->getVar('tpl_id') . '" target="_blank">' . \_AM_SYSTEM_BLOCKS_EDITTPL . '</a>'));
652
+                    if (\count($btemplate2)>0) {
653
+                        $form->addElement(new \XoopsFormLabel(\_AM_SYSTEM_BLOCKS_CONTENT, '<a href="'.XOOPS_URL.'/modules/system/admin.php?fct=tplsets&amp;op=edittpl&amp;id='.$btemplate2[0]->getVar('tpl_id').'" target="_blank">'.\_AM_SYSTEM_BLOCKS_EDITTPL.'</a>'));
654 654
                     }
655 655
                 }
656 656
             }
657
-            if (false !== $block['edit_form']) {
657
+            if (false!==$block['edit_form']) {
658 658
                 $form->addElement(new \XoopsFormLabel(\_AM_SYSTEM_BLOCKS_OPTIONS, $block['edit_form']));
659 659
             }
660 660
         }
Please login to merge, or discard this patch.
class/Common/VersionChecks.php 2 patches
Indentation   +113 added lines, -113 removed lines patch added patch discarded remove patch
@@ -19,127 +19,127 @@
 block discarded – undo
19 19
  */
20 20
 trait VersionChecks
21 21
 {
22
-    /**
23
-     * Verifies XOOPS version meets minimum requirements for this module
24
-     * @static
25
-     * @param \XoopsModule|null $module
26
-     *
27
-     * @param null|string       $requiredVer
28
-     * @return bool true if meets requirements, false if not
29
-     */
30
-    public static function checkVerXoops(\XoopsModule $module = null, $requiredVer = null): bool
31
-    {
32
-        $moduleDirName      = \basename(\dirname(__DIR__, 2));
33
-        $moduleDirNameUpper = \mb_strtoupper($moduleDirName);
34
-        if (null === $module) {
35
-            $module = \XoopsModule::getByDirname($moduleDirName);
36
-        }
37
-        \xoops_loadLanguage('admin', $moduleDirName);
38
-        \xoops_loadLanguage('common', $moduleDirName);
22
+	/**
23
+	 * Verifies XOOPS version meets minimum requirements for this module
24
+	 * @static
25
+	 * @param \XoopsModule|null $module
26
+	 *
27
+	 * @param null|string       $requiredVer
28
+	 * @return bool true if meets requirements, false if not
29
+	 */
30
+	public static function checkVerXoops(\XoopsModule $module = null, $requiredVer = null): bool
31
+	{
32
+		$moduleDirName      = \basename(\dirname(__DIR__, 2));
33
+		$moduleDirNameUpper = \mb_strtoupper($moduleDirName);
34
+		if (null === $module) {
35
+			$module = \XoopsModule::getByDirname($moduleDirName);
36
+		}
37
+		\xoops_loadLanguage('admin', $moduleDirName);
38
+		\xoops_loadLanguage('common', $moduleDirName);
39 39
 
40
-        //check for minimum XOOPS version
41
-        $currentVer = mb_substr(\XOOPS_VERSION, 6); // get the numeric part of string
42
-        if (null === $requiredVer) {
43
-            $requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string
44
-        }
45
-        $success = true;
40
+		//check for minimum XOOPS version
41
+		$currentVer = mb_substr(\XOOPS_VERSION, 6); // get the numeric part of string
42
+		if (null === $requiredVer) {
43
+			$requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string
44
+		}
45
+		$success = true;
46 46
 
47
-        if (\version_compare($currentVer, $requiredVer, '<')) {
48
-            $success = false;
49
-            $module->setErrors(\sprintf(\constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_XOOPS'), $requiredVer, $currentVer));
50
-        }
47
+		if (\version_compare($currentVer, $requiredVer, '<')) {
48
+			$success = false;
49
+			$module->setErrors(\sprintf(\constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_XOOPS'), $requiredVer, $currentVer));
50
+		}
51 51
 
52
-        return $success;
53
-    }
52
+		return $success;
53
+	}
54 54
 
55
-    /**
56
-     * Verifies PHP version meets minimum requirements for this module
57
-     * @static
58
-     * @param \XoopsModule|bool|null $module
59
-     *
60
-     * @return bool true if meets requirements, false if not
61
-     */
62
-    public static function checkVerPhp(\XoopsModule $module = null): bool
63
-    {
64
-        $moduleDirName      = \basename(\dirname(__DIR__, 2));
65
-        $moduleDirNameUpper = \mb_strtoupper($moduleDirName);
66
-        if (null === $module) {
67
-            $module = \XoopsModule::getByDirname($moduleDirName);
68
-        }
69
-        \xoops_loadLanguage('admin', $moduleDirName);
70
-        \xoops_loadLanguage('common', $moduleDirName);
55
+	/**
56
+	 * Verifies PHP version meets minimum requirements for this module
57
+	 * @static
58
+	 * @param \XoopsModule|bool|null $module
59
+	 *
60
+	 * @return bool true if meets requirements, false if not
61
+	 */
62
+	public static function checkVerPhp(\XoopsModule $module = null): bool
63
+	{
64
+		$moduleDirName      = \basename(\dirname(__DIR__, 2));
65
+		$moduleDirNameUpper = \mb_strtoupper($moduleDirName);
66
+		if (null === $module) {
67
+			$module = \XoopsModule::getByDirname($moduleDirName);
68
+		}
69
+		\xoops_loadLanguage('admin', $moduleDirName);
70
+		\xoops_loadLanguage('common', $moduleDirName);
71 71
 
72
-        // check for minimum PHP version
73
-        $success = true;
72
+		// check for minimum PHP version
73
+		$success = true;
74 74
 
75
-        $verNum = \PHP_VERSION;
76
-        $reqVer = &$module->getInfo('min_php');
75
+		$verNum = \PHP_VERSION;
76
+		$reqVer = &$module->getInfo('min_php');
77 77
 
78
-        if (false !== $reqVer && '' !== $reqVer) {
79
-            if (\version_compare($verNum, $reqVer, '<')) {
80
-                $module->setErrors(\sprintf(\constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_PHP'), $reqVer, $verNum));
81
-                $success = false;
82
-            }
83
-        }
78
+		if (false !== $reqVer && '' !== $reqVer) {
79
+			if (\version_compare($verNum, $reqVer, '<')) {
80
+				$module->setErrors(\sprintf(\constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_PHP'), $reqVer, $verNum));
81
+				$success = false;
82
+			}
83
+		}
84 84
 
85
-        return $success;
86
-    }
85
+		return $success;
86
+	}
87 87
 
88
-    /**
89
-     * compares current module version with the latest GitHub release
90
-     * @static
91
-     *
92
-     * @return string|array info about the latest module version, if newer
93
-     */
94
-    public static function checkVerModule(\Xmf\Module\Helper $helper, ?string $source = 'github', ?string $default = 'master'): ?array
95
-    {
96
-        $moduleDirName      = \basename(\dirname(__DIR__, 2));
97
-        $moduleDirNameUpper = \mb_strtoupper($moduleDirName);
98
-        $update             = '';
99
-        $repository         = 'XoopsModules25x/' . $moduleDirName;
100
-        //        $repository         = 'XoopsModules25x/publisher'; //for testing only
101
-        $ret             = null;
102
-        $infoReleasesUrl = "https://api.github.com/repos/$repository/releases";
103
-        if ('github' === $source) {
104
-            if (\function_exists('curl_init') && false !== ($curlHandle = \curl_init())) {
105
-                \curl_setopt($curlHandle, \CURLOPT_URL, $infoReleasesUrl);
106
-                \curl_setopt($curlHandle, \CURLOPT_RETURNTRANSFER, true);
107
-                \curl_setopt($curlHandle, \CURLOPT_SSL_VERIFYPEER, true); //TODO: how to avoid an error when 'Peer's Certificate issuer is not recognized'
108
-                \curl_setopt($curlHandle, \CURLOPT_HTTPHEADER, ["User-Agent:Publisher\r\n"]);
109
-                $curlReturn = \curl_exec($curlHandle);
110
-                if (false === $curlReturn) {
111
-                    \trigger_error(\curl_error($curlHandle));
112
-                } elseif (false !== \mb_strpos($curlReturn, 'Not Found')) {
113
-                    \trigger_error('Repository Not Found: ' . $infoReleasesUrl);
114
-                } else {
115
-                    $file              = json_decode($curlReturn, false);
116
-                    $latestVersionLink = \sprintf("https://github.com/$repository/archive/%s.zip", $file ? \reset($file)->tag_name : $default);
117
-                    $latestVersion     = $file[0]->tag_name;
118
-                    $prerelease        = $file[0]->prerelease;
119
-                    if ('master' !== $latestVersionLink) {
120
-                        $update = \constant('CO_' . $moduleDirNameUpper . '_' . 'NEW_VERSION') . $latestVersion;
121
-                    }
122
-                    //"PHP-standardized" version
123
-                    $latestVersion = \mb_strtolower($latestVersion);
124
-                    if (false !== mb_strpos($latestVersion, 'final')) {
125
-                        $latestVersion = \str_replace('_', '', \mb_strtolower($latestVersion));
126
-                        $latestVersion = \str_replace('final', '', \mb_strtolower($latestVersion));
127
-                    }
128
-                    $moduleVersion = ($helper->getModule()->getInfo('version') . '_' . $helper->getModule()->getInfo('module_status'));
129
-                    //"PHP-standardized" version
130
-                    $moduleVersion = \str_replace(' ', '', \mb_strtolower($moduleVersion));
131
-                    //                    $moduleVersion = '1.0'; //for testing only
132
-                    //                    $moduleDirName = 'publisher'; //for testing only
133
-                    if (!$prerelease && \version_compare($moduleVersion, $latestVersion, '<')) {
134
-                        $ret   = [];
135
-                        $ret[] = $update;
136
-                        $ret[] = $latestVersionLink;
137
-                    }
138
-                }
139
-                \curl_close($curlHandle);
140
-            }
141
-        }
88
+	/**
89
+	 * compares current module version with the latest GitHub release
90
+	 * @static
91
+	 *
92
+	 * @return string|array info about the latest module version, if newer
93
+	 */
94
+	public static function checkVerModule(\Xmf\Module\Helper $helper, ?string $source = 'github', ?string $default = 'master'): ?array
95
+	{
96
+		$moduleDirName      = \basename(\dirname(__DIR__, 2));
97
+		$moduleDirNameUpper = \mb_strtoupper($moduleDirName);
98
+		$update             = '';
99
+		$repository         = 'XoopsModules25x/' . $moduleDirName;
100
+		//        $repository         = 'XoopsModules25x/publisher'; //for testing only
101
+		$ret             = null;
102
+		$infoReleasesUrl = "https://api.github.com/repos/$repository/releases";
103
+		if ('github' === $source) {
104
+			if (\function_exists('curl_init') && false !== ($curlHandle = \curl_init())) {
105
+				\curl_setopt($curlHandle, \CURLOPT_URL, $infoReleasesUrl);
106
+				\curl_setopt($curlHandle, \CURLOPT_RETURNTRANSFER, true);
107
+				\curl_setopt($curlHandle, \CURLOPT_SSL_VERIFYPEER, true); //TODO: how to avoid an error when 'Peer's Certificate issuer is not recognized'
108
+				\curl_setopt($curlHandle, \CURLOPT_HTTPHEADER, ["User-Agent:Publisher\r\n"]);
109
+				$curlReturn = \curl_exec($curlHandle);
110
+				if (false === $curlReturn) {
111
+					\trigger_error(\curl_error($curlHandle));
112
+				} elseif (false !== \mb_strpos($curlReturn, 'Not Found')) {
113
+					\trigger_error('Repository Not Found: ' . $infoReleasesUrl);
114
+				} else {
115
+					$file              = json_decode($curlReturn, false);
116
+					$latestVersionLink = \sprintf("https://github.com/$repository/archive/%s.zip", $file ? \reset($file)->tag_name : $default);
117
+					$latestVersion     = $file[0]->tag_name;
118
+					$prerelease        = $file[0]->prerelease;
119
+					if ('master' !== $latestVersionLink) {
120
+						$update = \constant('CO_' . $moduleDirNameUpper . '_' . 'NEW_VERSION') . $latestVersion;
121
+					}
122
+					//"PHP-standardized" version
123
+					$latestVersion = \mb_strtolower($latestVersion);
124
+					if (false !== mb_strpos($latestVersion, 'final')) {
125
+						$latestVersion = \str_replace('_', '', \mb_strtolower($latestVersion));
126
+						$latestVersion = \str_replace('final', '', \mb_strtolower($latestVersion));
127
+					}
128
+					$moduleVersion = ($helper->getModule()->getInfo('version') . '_' . $helper->getModule()->getInfo('module_status'));
129
+					//"PHP-standardized" version
130
+					$moduleVersion = \str_replace(' ', '', \mb_strtolower($moduleVersion));
131
+					//                    $moduleVersion = '1.0'; //for testing only
132
+					//                    $moduleDirName = 'publisher'; //for testing only
133
+					if (!$prerelease && \version_compare($moduleVersion, $latestVersion, '<')) {
134
+						$ret   = [];
135
+						$ret[] = $update;
136
+						$ret[] = $latestVersionLink;
137
+					}
138
+				}
139
+				\curl_close($curlHandle);
140
+			}
141
+		}
142 142
 
143
-        return $ret;
144
-    }
143
+		return $ret;
144
+	}
145 145
 }
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
     {
32 32
         $moduleDirName      = \basename(\dirname(__DIR__, 2));
33 33
         $moduleDirNameUpper = \mb_strtoupper($moduleDirName);
34
-        if (null === $module) {
34
+        if (null===$module) {
35 35
             $module = \XoopsModule::getByDirname($moduleDirName);
36 36
         }
37 37
         \xoops_loadLanguage('admin', $moduleDirName);
@@ -39,14 +39,14 @@  discard block
 block discarded – undo
39 39
 
40 40
         //check for minimum XOOPS version
41 41
         $currentVer = mb_substr(\XOOPS_VERSION, 6); // get the numeric part of string
42
-        if (null === $requiredVer) {
43
-            $requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string
42
+        if (null===$requiredVer) {
43
+            $requiredVer = ''.$module->getInfo('min_xoops'); //making sure it's a string
44 44
         }
45 45
         $success = true;
46 46
 
47 47
         if (\version_compare($currentVer, $requiredVer, '<')) {
48 48
             $success = false;
49
-            $module->setErrors(\sprintf(\constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_XOOPS'), $requiredVer, $currentVer));
49
+            $module->setErrors(\sprintf(\constant('CO_'.$moduleDirNameUpper.'_ERROR_BAD_XOOPS'), $requiredVer, $currentVer));
50 50
         }
51 51
 
52 52
         return $success;
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
     {
64 64
         $moduleDirName      = \basename(\dirname(__DIR__, 2));
65 65
         $moduleDirNameUpper = \mb_strtoupper($moduleDirName);
66
-        if (null === $module) {
66
+        if (null===$module) {
67 67
             $module = \XoopsModule::getByDirname($moduleDirName);
68 68
         }
69 69
         \xoops_loadLanguage('admin', $moduleDirName);
@@ -75,9 +75,9 @@  discard block
 block discarded – undo
75 75
         $verNum = \PHP_VERSION;
76 76
         $reqVer = &$module->getInfo('min_php');
77 77
 
78
-        if (false !== $reqVer && '' !== $reqVer) {
78
+        if (false!==$reqVer && ''!==$reqVer) {
79 79
             if (\version_compare($verNum, $reqVer, '<')) {
80
-                $module->setErrors(\sprintf(\constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_PHP'), $reqVer, $verNum));
80
+                $module->setErrors(\sprintf(\constant('CO_'.$moduleDirNameUpper.'_ERROR_BAD_PHP'), $reqVer, $verNum));
81 81
                 $success = false;
82 82
             }
83 83
         }
@@ -96,36 +96,36 @@  discard block
 block discarded – undo
96 96
         $moduleDirName      = \basename(\dirname(__DIR__, 2));
97 97
         $moduleDirNameUpper = \mb_strtoupper($moduleDirName);
98 98
         $update             = '';
99
-        $repository         = 'XoopsModules25x/' . $moduleDirName;
99
+        $repository         = 'XoopsModules25x/'.$moduleDirName;
100 100
         //        $repository         = 'XoopsModules25x/publisher'; //for testing only
101 101
         $ret             = null;
102 102
         $infoReleasesUrl = "https://api.github.com/repos/$repository/releases";
103
-        if ('github' === $source) {
104
-            if (\function_exists('curl_init') && false !== ($curlHandle = \curl_init())) {
103
+        if ('github'===$source) {
104
+            if (\function_exists('curl_init') && false!==($curlHandle = \curl_init())) {
105 105
                 \curl_setopt($curlHandle, \CURLOPT_URL, $infoReleasesUrl);
106 106
                 \curl_setopt($curlHandle, \CURLOPT_RETURNTRANSFER, true);
107 107
                 \curl_setopt($curlHandle, \CURLOPT_SSL_VERIFYPEER, true); //TODO: how to avoid an error when 'Peer's Certificate issuer is not recognized'
108 108
                 \curl_setopt($curlHandle, \CURLOPT_HTTPHEADER, ["User-Agent:Publisher\r\n"]);
109 109
                 $curlReturn = \curl_exec($curlHandle);
110
-                if (false === $curlReturn) {
110
+                if (false===$curlReturn) {
111 111
                     \trigger_error(\curl_error($curlHandle));
112
-                } elseif (false !== \mb_strpos($curlReturn, 'Not Found')) {
113
-                    \trigger_error('Repository Not Found: ' . $infoReleasesUrl);
112
+                } elseif (false!==\mb_strpos($curlReturn, 'Not Found')) {
113
+                    \trigger_error('Repository Not Found: '.$infoReleasesUrl);
114 114
                 } else {
115 115
                     $file              = json_decode($curlReturn, false);
116 116
                     $latestVersionLink = \sprintf("https://github.com/$repository/archive/%s.zip", $file ? \reset($file)->tag_name : $default);
117 117
                     $latestVersion     = $file[0]->tag_name;
118 118
                     $prerelease        = $file[0]->prerelease;
119
-                    if ('master' !== $latestVersionLink) {
120
-                        $update = \constant('CO_' . $moduleDirNameUpper . '_' . 'NEW_VERSION') . $latestVersion;
119
+                    if ('master'!==$latestVersionLink) {
120
+                        $update = \constant('CO_'.$moduleDirNameUpper.'_'.'NEW_VERSION').$latestVersion;
121 121
                     }
122 122
                     //"PHP-standardized" version
123 123
                     $latestVersion = \mb_strtolower($latestVersion);
124
-                    if (false !== mb_strpos($latestVersion, 'final')) {
124
+                    if (false!==mb_strpos($latestVersion, 'final')) {
125 125
                         $latestVersion = \str_replace('_', '', \mb_strtolower($latestVersion));
126 126
                         $latestVersion = \str_replace('final', '', \mb_strtolower($latestVersion));
127 127
                     }
128
-                    $moduleVersion = ($helper->getModule()->getInfo('version') . '_' . $helper->getModule()->getInfo('module_status'));
128
+                    $moduleVersion = ($helper->getModule()->getInfo('version').'_'.$helper->getModule()->getInfo('module_status'));
129 129
                     //"PHP-standardized" version
130 130
                     $moduleVersion = \str_replace(' ', '', \mb_strtolower($moduleVersion));
131 131
                     //                    $moduleVersion = '1.0'; //for testing only
Please login to merge, or discard this patch.
class/Common/TestdataButtons.php 2 patches
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -29,64 +29,64 @@
 block discarded – undo
29 29
  */
30 30
 class TestdataButtons
31 31
 {
32
-    /** Button status constants */
33
-    private const SHOW_BUTTONS = 1;
34
-    private const HIDE_BUTTONS = 0;
32
+	/** Button status constants */
33
+	private const SHOW_BUTTONS = 1;
34
+	private const HIDE_BUTTONS = 0;
35 35
 
36
-    /**
37
-     * Load the test button configuration
38
-     *
39
-     * @param \Xmf\Module\Admin $adminObject
40
-     *
41
-     * @return void
42
-     */
43
-    public static function loadButtonConfig($adminObject): void
44
-    {
45
-        $moduleDirName      = \basename(\dirname(__DIR__, 2));
46
-        $moduleDirNameUpper = \mb_strtoupper($moduleDirName);
47
-        $helper              = Helper::getInstance();
48
-        $yamlFile            = $helper->path('/config/admin.yml');
49
-        $config             = Yaml::readWrapped($yamlFile); // work with phpmyadmin YAML dumps
50
-        $displaySampleButton = $config['displaySampleButton'];
36
+	/**
37
+	 * Load the test button configuration
38
+	 *
39
+	 * @param \Xmf\Module\Admin $adminObject
40
+	 *
41
+	 * @return void
42
+	 */
43
+	public static function loadButtonConfig($adminObject): void
44
+	{
45
+		$moduleDirName      = \basename(\dirname(__DIR__, 2));
46
+		$moduleDirNameUpper = \mb_strtoupper($moduleDirName);
47
+		$helper              = Helper::getInstance();
48
+		$yamlFile            = $helper->path('/config/admin.yml');
49
+		$config             = Yaml::readWrapped($yamlFile); // work with phpmyadmin YAML dumps
50
+		$displaySampleButton = $config['displaySampleButton'];
51 51
 
52
-        if (self::SHOW_BUTTONS == $displaySampleButton) {
53
-            \xoops_loadLanguage('admin/modulesadmin', 'system');
54
-            $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'LOAD_SAMPLEDATA'), $helper->url('testdata/index.php?op=load'), 'add');
55
-            $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'SAVE_SAMPLEDATA'), $helper->url('testdata/index.php?op=save'), 'add');
56
-            $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'CLEAR_SAMPLEDATA'), $helper->url('testdata/index.php?op=clear'), 'alert');
57
-            //    $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA'), $helper->url( 'testdata/index.php?op=exportschema'), 'add');
58
-            $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'HIDE_SAMPLEDATA_BUTTONS'), '?op=hide_buttons', 'delete');
59
-        } else {
60
-            $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'SHOW_SAMPLEDATA_BUTTONS'), '?op=show_buttons', 'add');
61
-            // $displaySampleButton = $config['displaySampleButton'];
62
-        }
63
-    }
52
+		if (self::SHOW_BUTTONS == $displaySampleButton) {
53
+			\xoops_loadLanguage('admin/modulesadmin', 'system');
54
+			$adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'LOAD_SAMPLEDATA'), $helper->url('testdata/index.php?op=load'), 'add');
55
+			$adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'SAVE_SAMPLEDATA'), $helper->url('testdata/index.php?op=save'), 'add');
56
+			$adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'CLEAR_SAMPLEDATA'), $helper->url('testdata/index.php?op=clear'), 'alert');
57
+			//    $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA'), $helper->url( 'testdata/index.php?op=exportschema'), 'add');
58
+			$adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'HIDE_SAMPLEDATA_BUTTONS'), '?op=hide_buttons', 'delete');
59
+		} else {
60
+			$adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'SHOW_SAMPLEDATA_BUTTONS'), '?op=show_buttons', 'add');
61
+			// $displaySampleButton = $config['displaySampleButton'];
62
+		}
63
+	}
64 64
 
65
-    /**
66
-     * Hide the test buttons
67
-     *
68
-     * @return void
69
-     */
70
-    public static function hideButtons(): void
71
-    {
72
-        $yamlFile                   = \dirname(__DIR__, 2) . '/config/admin.yml';
73
-        $app                        = [];
74
-        $app['displaySampleButton'] = self::HIDE_BUTTONS;
75
-        Yaml::save($app, $yamlFile);
76
-        \redirect_header('index.php', 0, '');
77
-    }
65
+	/**
66
+	 * Hide the test buttons
67
+	 *
68
+	 * @return void
69
+	 */
70
+	public static function hideButtons(): void
71
+	{
72
+		$yamlFile                   = \dirname(__DIR__, 2) . '/config/admin.yml';
73
+		$app                        = [];
74
+		$app['displaySampleButton'] = self::HIDE_BUTTONS;
75
+		Yaml::save($app, $yamlFile);
76
+		\redirect_header('index.php', 0, '');
77
+	}
78 78
 
79
-    /**
80
-     * Show the test buttons
81
-     *
82
-     * @return void
83
-     */
84
-    public static function showButtons(): void
85
-    {
86
-        $yamlFile                   = \dirname(__DIR__, 2) . '/config/admin.yml';
87
-        $app                        = [];
88
-        $app['displaySampleButton'] = self::SHOW_BUTTONS;
89
-        Yaml::save($app, $yamlFile);
90
-        \redirect_header('index.php', 0, '');
91
-    }
79
+	/**
80
+	 * Show the test buttons
81
+	 *
82
+	 * @return void
83
+	 */
84
+	public static function showButtons(): void
85
+	{
86
+		$yamlFile                   = \dirname(__DIR__, 2) . '/config/admin.yml';
87
+		$app                        = [];
88
+		$app['displaySampleButton'] = self::SHOW_BUTTONS;
89
+		Yaml::save($app, $yamlFile);
90
+		\redirect_header('index.php', 0, '');
91
+	}
92 92
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -49,15 +49,15 @@  discard block
 block discarded – undo
49 49
         $config             = Yaml::readWrapped($yamlFile); // work with phpmyadmin YAML dumps
50 50
         $displaySampleButton = $config['displaySampleButton'];
51 51
 
52
-        if (self::SHOW_BUTTONS == $displaySampleButton) {
52
+        if (self::SHOW_BUTTONS==$displaySampleButton) {
53 53
             \xoops_loadLanguage('admin/modulesadmin', 'system');
54
-            $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'LOAD_SAMPLEDATA'), $helper->url('testdata/index.php?op=load'), 'add');
55
-            $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'SAVE_SAMPLEDATA'), $helper->url('testdata/index.php?op=save'), 'add');
56
-            $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'CLEAR_SAMPLEDATA'), $helper->url('testdata/index.php?op=clear'), 'alert');
54
+            $adminObject->addItemButton(\constant('CO_'.$moduleDirNameUpper.'_'.'LOAD_SAMPLEDATA'), $helper->url('testdata/index.php?op=load'), 'add');
55
+            $adminObject->addItemButton(\constant('CO_'.$moduleDirNameUpper.'_'.'SAVE_SAMPLEDATA'), $helper->url('testdata/index.php?op=save'), 'add');
56
+            $adminObject->addItemButton(\constant('CO_'.$moduleDirNameUpper.'_'.'CLEAR_SAMPLEDATA'), $helper->url('testdata/index.php?op=clear'), 'alert');
57 57
             //    $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA'), $helper->url( 'testdata/index.php?op=exportschema'), 'add');
58
-            $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'HIDE_SAMPLEDATA_BUTTONS'), '?op=hide_buttons', 'delete');
58
+            $adminObject->addItemButton(\constant('CO_'.$moduleDirNameUpper.'_'.'HIDE_SAMPLEDATA_BUTTONS'), '?op=hide_buttons', 'delete');
59 59
         } else {
60
-            $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'SHOW_SAMPLEDATA_BUTTONS'), '?op=show_buttons', 'add');
60
+            $adminObject->addItemButton(\constant('CO_'.$moduleDirNameUpper.'_'.'SHOW_SAMPLEDATA_BUTTONS'), '?op=show_buttons', 'add');
61 61
             // $displaySampleButton = $config['displaySampleButton'];
62 62
         }
63 63
     }
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
      */
70 70
     public static function hideButtons(): void
71 71
     {
72
-        $yamlFile                   = \dirname(__DIR__, 2) . '/config/admin.yml';
72
+        $yamlFile                   = \dirname(__DIR__, 2).'/config/admin.yml';
73 73
         $app                        = [];
74 74
         $app['displaySampleButton'] = self::HIDE_BUTTONS;
75 75
         Yaml::save($app, $yamlFile);
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
      */
84 84
     public static function showButtons(): void
85 85
     {
86
-        $yamlFile                   = \dirname(__DIR__, 2) . '/config/admin.yml';
86
+        $yamlFile                   = \dirname(__DIR__, 2).'/config/admin.yml';
87 87
         $app                        = [];
88 88
         $app['displaySampleButton'] = self::SHOW_BUTTONS;
89 89
         Yaml::save($app, $yamlFile);
Please login to merge, or discard this patch.
class/Common/ServerStats.php 2 patches
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -19,60 +19,60 @@
 block discarded – undo
19 19
  */
20 20
 trait ServerStats
21 21
 {
22
-    /**
23
-     * serverStats()
24
-     *
25
-     * @return string
26
-     */
27
-    public static function getServerStats(): string
28
-    {
29
-        //mb    $wfdownloads = WfdownloadsWfdownloads::getInstance();
30
-        $moduleDirName      = \basename(\dirname(__DIR__, 2));
31
-        $moduleDirNameUpper = \mb_strtoupper($moduleDirName);
32
-        \xoops_loadLanguage('common', $moduleDirName);
33
-        $html = '';
34
-        //        $sql   = 'SELECT metavalue';
35
-        //        $sql   .= ' FROM ' . $GLOBALS['xoopsDB']->prefix('wfdownloads_meta');
36
-        //        $sql   .= " WHERE metakey='version' LIMIT 1";
37
-        //        $query = $GLOBALS['xoopsDB']->query($sql);
38
-        //        list($meta) = $GLOBALS['xoopsDB']->fetchRow($query);
39
-        $html .= "<fieldset><legend style='font-weight: bold; color: #900;'>" . \constant('CO_' . $moduleDirNameUpper . '_IMAGEINFO') . "</legend>\n";
40
-        $html .= "<div style='padding: 8px;'>\n";
41
-        //        $html .= '<div>' . constant('CO_' . $moduleDirNameUpper . '_METAVERSION') . $meta . "</div>\n";
42
-        //        $html .= "<br>\n";
43
-        //        $html .= "<br>\n";
44
-        $html .= '<div>' . \constant('CO_' . $moduleDirNameUpper . '_SPHPINI') . "</div>\n";
45
-        $html .= "<ul>\n";
22
+	/**
23
+	 * serverStats()
24
+	 *
25
+	 * @return string
26
+	 */
27
+	public static function getServerStats(): string
28
+	{
29
+		//mb    $wfdownloads = WfdownloadsWfdownloads::getInstance();
30
+		$moduleDirName      = \basename(\dirname(__DIR__, 2));
31
+		$moduleDirNameUpper = \mb_strtoupper($moduleDirName);
32
+		\xoops_loadLanguage('common', $moduleDirName);
33
+		$html = '';
34
+		//        $sql   = 'SELECT metavalue';
35
+		//        $sql   .= ' FROM ' . $GLOBALS['xoopsDB']->prefix('wfdownloads_meta');
36
+		//        $sql   .= " WHERE metakey='version' LIMIT 1";
37
+		//        $query = $GLOBALS['xoopsDB']->query($sql);
38
+		//        list($meta) = $GLOBALS['xoopsDB']->fetchRow($query);
39
+		$html .= "<fieldset><legend style='font-weight: bold; color: #900;'>" . \constant('CO_' . $moduleDirNameUpper . '_IMAGEINFO') . "</legend>\n";
40
+		$html .= "<div style='padding: 8px;'>\n";
41
+		//        $html .= '<div>' . constant('CO_' . $moduleDirNameUpper . '_METAVERSION') . $meta . "</div>\n";
42
+		//        $html .= "<br>\n";
43
+		//        $html .= "<br>\n";
44
+		$html .= '<div>' . \constant('CO_' . $moduleDirNameUpper . '_SPHPINI') . "</div>\n";
45
+		$html .= "<ul>\n";
46 46
 
47
-        $gdlib = \function_exists('gd_info') ? '<span style="color: green;">' . \constant('CO_' . $moduleDirNameUpper . '_GDON') . '</span>' : '<span style="color: red;">' . \constant('CO_' . $moduleDirNameUpper . '_GDOFF') . '</span>';
48
-        $html  .= '<li>' . \constant('CO_' . $moduleDirNameUpper . '_GDLIBSTATUS') . $gdlib;
49
-        if (\function_exists('gd_info')) {
50
-            if (true == ($gdlib = gd_info())) {
51
-                $html .= '<li>' . \constant('CO_' . $moduleDirNameUpper . '_GDLIBVERSION') . '<b>' . $gdlib['GD Version'] . '</b>';
52
-            }
53
-        }
54
-        //
55
-        //    $safemode = ini_get('safe_mode') ? constant('CO_' . $moduleDirNameUpper . '_ON') . constant('CO_' . $moduleDirNameUpper . '_SAFEMODEPROBLEMS : constant('CO_' . $moduleDirNameUpper . '_OFF');
56
-        //    $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_SAFEMODESTATUS . $safemode;
57
-        //
58
-        //    $registerglobals = (!ini_get('register_globals')) ? "<span style=\"color: green;\">" . constant('CO_' . $moduleDirNameUpper . '_OFF') . '</span>' : "<span style=\"color: red;\">" . constant('CO_' . $moduleDirNameUpper . '_ON') . '</span>';
59
-        //    $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_REGISTERGLOBALS . $registerglobals;
60
-        //
61
-        $downloads = \ini_get('file_uploads') ? '<span style="color: green;">' . \constant('CO_' . $moduleDirNameUpper . '_ON') . '</span>' : '<span style="color: red;">' . \constant('CO_' . $moduleDirNameUpper . '_OFF') . '</span>';
62
-        $html      .= '<li>' . \constant('CO_' . $moduleDirNameUpper . '_SERVERUPLOADSTATUS') . $downloads;
47
+		$gdlib = \function_exists('gd_info') ? '<span style="color: green;">' . \constant('CO_' . $moduleDirNameUpper . '_GDON') . '</span>' : '<span style="color: red;">' . \constant('CO_' . $moduleDirNameUpper . '_GDOFF') . '</span>';
48
+		$html  .= '<li>' . \constant('CO_' . $moduleDirNameUpper . '_GDLIBSTATUS') . $gdlib;
49
+		if (\function_exists('gd_info')) {
50
+			if (true == ($gdlib = gd_info())) {
51
+				$html .= '<li>' . \constant('CO_' . $moduleDirNameUpper . '_GDLIBVERSION') . '<b>' . $gdlib['GD Version'] . '</b>';
52
+			}
53
+		}
54
+		//
55
+		//    $safemode = ini_get('safe_mode') ? constant('CO_' . $moduleDirNameUpper . '_ON') . constant('CO_' . $moduleDirNameUpper . '_SAFEMODEPROBLEMS : constant('CO_' . $moduleDirNameUpper . '_OFF');
56
+		//    $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_SAFEMODESTATUS . $safemode;
57
+		//
58
+		//    $registerglobals = (!ini_get('register_globals')) ? "<span style=\"color: green;\">" . constant('CO_' . $moduleDirNameUpper . '_OFF') . '</span>' : "<span style=\"color: red;\">" . constant('CO_' . $moduleDirNameUpper . '_ON') . '</span>';
59
+		//    $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_REGISTERGLOBALS . $registerglobals;
60
+		//
61
+		$downloads = \ini_get('file_uploads') ? '<span style="color: green;">' . \constant('CO_' . $moduleDirNameUpper . '_ON') . '</span>' : '<span style="color: red;">' . \constant('CO_' . $moduleDirNameUpper . '_OFF') . '</span>';
62
+		$html      .= '<li>' . \constant('CO_' . $moduleDirNameUpper . '_SERVERUPLOADSTATUS') . $downloads;
63 63
 
64
-        $html .= '<li>' . \constant('CO_' . $moduleDirNameUpper . '_MAXUPLOADSIZE') . ' <b><span style="color: blue;">' . \ini_get('upload_max_filesize') . "</span></b>\n";
65
-        $html .= '<li>' . \constant('CO_' . $moduleDirNameUpper . '_MAXPOSTSIZE') . ' <b><span style="color: blue;">' . \ini_get('post_max_size') . "</span></b>\n";
66
-        $html .= '<li>' . \constant('CO_' . $moduleDirNameUpper . '_MEMORYLIMIT') . ' <b><span style="color: blue;">' . \ini_get('memory_limit') . "</span></b>\n";
67
-        $html .= "</ul>\n";
68
-        $html .= "<ul>\n";
69
-        $html .= '<li>' . \constant('CO_' . $moduleDirNameUpper . '_SERVERPATH') . ' <b>' . XOOPS_ROOT_PATH . "</b>\n";
70
-        $html .= "</ul>\n";
71
-        $html .= "<br>\n";
72
-        $html .= \constant('CO_' . $moduleDirNameUpper . '_UPLOADPATHDSC') . "\n";
73
-        $html .= '</div>';
74
-        $html .= '</fieldset><br>';
64
+		$html .= '<li>' . \constant('CO_' . $moduleDirNameUpper . '_MAXUPLOADSIZE') . ' <b><span style="color: blue;">' . \ini_get('upload_max_filesize') . "</span></b>\n";
65
+		$html .= '<li>' . \constant('CO_' . $moduleDirNameUpper . '_MAXPOSTSIZE') . ' <b><span style="color: blue;">' . \ini_get('post_max_size') . "</span></b>\n";
66
+		$html .= '<li>' . \constant('CO_' . $moduleDirNameUpper . '_MEMORYLIMIT') . ' <b><span style="color: blue;">' . \ini_get('memory_limit') . "</span></b>\n";
67
+		$html .= "</ul>\n";
68
+		$html .= "<ul>\n";
69
+		$html .= '<li>' . \constant('CO_' . $moduleDirNameUpper . '_SERVERPATH') . ' <b>' . XOOPS_ROOT_PATH . "</b>\n";
70
+		$html .= "</ul>\n";
71
+		$html .= "<br>\n";
72
+		$html .= \constant('CO_' . $moduleDirNameUpper . '_UPLOADPATHDSC') . "\n";
73
+		$html .= '</div>';
74
+		$html .= '</fieldset><br>';
75 75
 
76
-        return $html;
77
-    }
76
+		return $html;
77
+	}
78 78
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -36,19 +36,19 @@  discard block
 block discarded – undo
36 36
         //        $sql   .= " WHERE metakey='version' LIMIT 1";
37 37
         //        $query = $GLOBALS['xoopsDB']->query($sql);
38 38
         //        list($meta) = $GLOBALS['xoopsDB']->fetchRow($query);
39
-        $html .= "<fieldset><legend style='font-weight: bold; color: #900;'>" . \constant('CO_' . $moduleDirNameUpper . '_IMAGEINFO') . "</legend>\n";
39
+        $html .= "<fieldset><legend style='font-weight: bold; color: #900;'>".\constant('CO_'.$moduleDirNameUpper.'_IMAGEINFO')."</legend>\n";
40 40
         $html .= "<div style='padding: 8px;'>\n";
41 41
         //        $html .= '<div>' . constant('CO_' . $moduleDirNameUpper . '_METAVERSION') . $meta . "</div>\n";
42 42
         //        $html .= "<br>\n";
43 43
         //        $html .= "<br>\n";
44
-        $html .= '<div>' . \constant('CO_' . $moduleDirNameUpper . '_SPHPINI') . "</div>\n";
44
+        $html .= '<div>'.\constant('CO_'.$moduleDirNameUpper.'_SPHPINI')."</div>\n";
45 45
         $html .= "<ul>\n";
46 46
 
47
-        $gdlib = \function_exists('gd_info') ? '<span style="color: green;">' . \constant('CO_' . $moduleDirNameUpper . '_GDON') . '</span>' : '<span style="color: red;">' . \constant('CO_' . $moduleDirNameUpper . '_GDOFF') . '</span>';
48
-        $html  .= '<li>' . \constant('CO_' . $moduleDirNameUpper . '_GDLIBSTATUS') . $gdlib;
47
+        $gdlib = \function_exists('gd_info') ? '<span style="color: green;">'.\constant('CO_'.$moduleDirNameUpper.'_GDON').'</span>' : '<span style="color: red;">'.\constant('CO_'.$moduleDirNameUpper.'_GDOFF').'</span>';
48
+        $html .= '<li>'.\constant('CO_'.$moduleDirNameUpper.'_GDLIBSTATUS').$gdlib;
49 49
         if (\function_exists('gd_info')) {
50
-            if (true == ($gdlib = gd_info())) {
51
-                $html .= '<li>' . \constant('CO_' . $moduleDirNameUpper . '_GDLIBVERSION') . '<b>' . $gdlib['GD Version'] . '</b>';
50
+            if (true==($gdlib = gd_info())) {
51
+                $html .= '<li>'.\constant('CO_'.$moduleDirNameUpper.'_GDLIBVERSION').'<b>'.$gdlib['GD Version'].'</b>';
52 52
             }
53 53
         }
54 54
         //
@@ -58,18 +58,18 @@  discard block
 block discarded – undo
58 58
         //    $registerglobals = (!ini_get('register_globals')) ? "<span style=\"color: green;\">" . constant('CO_' . $moduleDirNameUpper . '_OFF') . '</span>' : "<span style=\"color: red;\">" . constant('CO_' . $moduleDirNameUpper . '_ON') . '</span>';
59 59
         //    $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_REGISTERGLOBALS . $registerglobals;
60 60
         //
61
-        $downloads = \ini_get('file_uploads') ? '<span style="color: green;">' . \constant('CO_' . $moduleDirNameUpper . '_ON') . '</span>' : '<span style="color: red;">' . \constant('CO_' . $moduleDirNameUpper . '_OFF') . '</span>';
62
-        $html      .= '<li>' . \constant('CO_' . $moduleDirNameUpper . '_SERVERUPLOADSTATUS') . $downloads;
61
+        $downloads = \ini_get('file_uploads') ? '<span style="color: green;">'.\constant('CO_'.$moduleDirNameUpper.'_ON').'</span>' : '<span style="color: red;">'.\constant('CO_'.$moduleDirNameUpper.'_OFF').'</span>';
62
+        $html .= '<li>'.\constant('CO_'.$moduleDirNameUpper.'_SERVERUPLOADSTATUS').$downloads;
63 63
 
64
-        $html .= '<li>' . \constant('CO_' . $moduleDirNameUpper . '_MAXUPLOADSIZE') . ' <b><span style="color: blue;">' . \ini_get('upload_max_filesize') . "</span></b>\n";
65
-        $html .= '<li>' . \constant('CO_' . $moduleDirNameUpper . '_MAXPOSTSIZE') . ' <b><span style="color: blue;">' . \ini_get('post_max_size') . "</span></b>\n";
66
-        $html .= '<li>' . \constant('CO_' . $moduleDirNameUpper . '_MEMORYLIMIT') . ' <b><span style="color: blue;">' . \ini_get('memory_limit') . "</span></b>\n";
64
+        $html .= '<li>'.\constant('CO_'.$moduleDirNameUpper.'_MAXUPLOADSIZE').' <b><span style="color: blue;">'.\ini_get('upload_max_filesize')."</span></b>\n";
65
+        $html .= '<li>'.\constant('CO_'.$moduleDirNameUpper.'_MAXPOSTSIZE').' <b><span style="color: blue;">'.\ini_get('post_max_size')."</span></b>\n";
66
+        $html .= '<li>'.\constant('CO_'.$moduleDirNameUpper.'_MEMORYLIMIT').' <b><span style="color: blue;">'.\ini_get('memory_limit')."</span></b>\n";
67 67
         $html .= "</ul>\n";
68 68
         $html .= "<ul>\n";
69
-        $html .= '<li>' . \constant('CO_' . $moduleDirNameUpper . '_SERVERPATH') . ' <b>' . XOOPS_ROOT_PATH . "</b>\n";
69
+        $html .= '<li>'.\constant('CO_'.$moduleDirNameUpper.'_SERVERPATH').' <b>'.XOOPS_ROOT_PATH."</b>\n";
70 70
         $html .= "</ul>\n";
71 71
         $html .= "<br>\n";
72
-        $html .= \constant('CO_' . $moduleDirNameUpper . '_UPLOADPATHDSC') . "\n";
72
+        $html .= \constant('CO_'.$moduleDirNameUpper.'_UPLOADPATHDSC')."\n";
73 73
         $html .= '</div>';
74 74
         $html .= '</fieldset><br>';
75 75
 
Please login to merge, or discard this patch.
class/Common/Migrate.php 2 patches
Indentation   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -25,49 +25,49 @@  discard block
 block discarded – undo
25 25
  */
26 26
 class Migrate extends \Xmf\Database\Migrate
27 27
 {
28
-    private $moduleDirName;
29
-    private $renameColumns;
30
-    private $renameTables;
28
+	private $moduleDirName;
29
+	private $renameColumns;
30
+	private $renameTables;
31 31
 
32
-    /**
33
-     * Migrate constructor.
34
-     * @throws \RuntimeException
35
-     * @throws \InvalidArgumentException
36
-     */
37
-    public function __construct()
38
-    {
39
-        $class = __NAMESPACE__ . '\\' . 'Configurator';
40
-        if (!\class_exists($class)) {
41
-            throw new \RuntimeException("Class '$class' not found");
42
-        }
43
-        $configurator       = new $class();
44
-        $this->renameTables = $configurator->renameTables;
45
-        $this->renameColumns = $configurator->renameColumns;
32
+	/**
33
+	 * Migrate constructor.
34
+	 * @throws \RuntimeException
35
+	 * @throws \InvalidArgumentException
36
+	 */
37
+	public function __construct()
38
+	{
39
+		$class = __NAMESPACE__ . '\\' . 'Configurator';
40
+		if (!\class_exists($class)) {
41
+			throw new \RuntimeException("Class '$class' not found");
42
+		}
43
+		$configurator       = new $class();
44
+		$this->renameTables = $configurator->renameTables;
45
+		$this->renameColumns = $configurator->renameColumns;
46 46
 
47
-        $this->moduleDirName = \basename(\dirname(__DIR__, 2));
48
-        parent::__construct($this->moduleDirName);
49
-    }
47
+		$this->moduleDirName = \basename(\dirname(__DIR__, 2));
48
+		parent::__construct($this->moduleDirName);
49
+	}
50 50
 
51
-    /**
52
-     * change table prefix if needed
53
-     */
54
-    private function changePrefix()
55
-    {
51
+	/**
52
+	 * change table prefix if needed
53
+	 */
54
+	private function changePrefix()
55
+	{
56 56
 //        foreach ($this->renameTables as $oldName => $newName) {
57 57
 //            if ($this->tableHandler->useTable($oldName) && !$this->tableHandler->useTable($newName)) {
58 58
 //                $this->tableHandler->renameTable($oldName, $newName);
59 59
 //            }
60 60
 //        }
61
-    }
61
+	}
62 62
 
63
-    /**
64
-     * Change integer IPv4 column to varchar IPv6 capable
65
-     *
66
-     * @param string $tableName  table to convert
67
-     * @param string $columnName column with IP address
68
-     */
69
-    private function convertIPAddresses($tableName, $columnName)
70
-    {
63
+	/**
64
+	 * Change integer IPv4 column to varchar IPv6 capable
65
+	 *
66
+	 * @param string $tableName  table to convert
67
+	 * @param string $columnName column with IP address
68
+	 */
69
+	private function convertIPAddresses($tableName, $columnName)
70
+	{
71 71
 //        if ($this->tableHandler->useTable($tableName)) {
72 72
 //            $attributes = $this->tableHandler->getColumnAttributes($tableName, $columnName);
73 73
 //            if (false !== \mb_strpos($attributes, ' int(')) {
@@ -79,14 +79,14 @@  discard block
 block discarded – undo
79 79
 //                $this->tableHandler->update($tableName, [$columnName => "INET_NTOA($columnName)"], '', false);
80 80
 //            }
81 81
 //        }
82
-    }
82
+	}
83 83
 
84
-    /**
85
-     * @deprecated (just as an example here)
86
-     * Move do* columns from newbb_posts to newbb_posts_text table
87
-     */
88
-    private function moveDoColumns()
89
-    {
84
+	/**
85
+	 * @deprecated (just as an example here)
86
+	 * Move do* columns from newbb_posts to newbb_posts_text table
87
+	 */
88
+	private function moveDoColumns()
89
+	{
90 90
 //        $tableName    = 'newbb_posts_text';
91 91
 //        $srcTableName = 'newbb_posts';
92 92
 //        if ($this->tableHandler->useTable($tableName)
@@ -100,62 +100,62 @@  discard block
 block discarded – undo
100 100
 //                $this->tableHandler->addToQueue($sql);
101 101
 //            }
102 102
 //        }
103
-    }
103
+	}
104 104
 
105
-    /**
106
-     * rename table if needed
107
-     */
108
-    private function renameTable()
109
-    {
110
-        foreach ($this->renameTables as $oldName => $newName) {
111
-            if ($this->tableHandler->useTable($oldName) && !$this->tableHandler->useTable($newName)) {
112
-                $this->tableHandler->renameTable($oldName, $newName);
113
-            }
114
-        }
115
-    }
105
+	/**
106
+	 * rename table if needed
107
+	 */
108
+	private function renameTable()
109
+	{
110
+		foreach ($this->renameTables as $oldName => $newName) {
111
+			if ($this->tableHandler->useTable($oldName) && !$this->tableHandler->useTable($newName)) {
112
+				$this->tableHandler->renameTable($oldName, $newName);
113
+			}
114
+		}
115
+	}
116 116
 
117 117
 
118
-    /**
119
-     * rename columns if needed
120
-     */
121
-    private function renameColumns()
122
-    {
123
-        foreach ($this->renameColumns as $tableName) {
124
-            if ($this->tableHandler->useTable($tableName)) {
125
-                $oldName = $tableName['from'];
126
-                $newName = $tableName['to'];
127
-                $attributes = $this->tableHandler->getColumnAttributes($tableName, $oldName);
128
-                if (false !== \strpos($attributes, ' int(')) {
129
-                    $this->tableHandler->alterColumn($tableName, $oldName, $attributes, $newName);
130
-                }
131
-            }
132
-        }
133
-    }
118
+	/**
119
+	 * rename columns if needed
120
+	 */
121
+	private function renameColumns()
122
+	{
123
+		foreach ($this->renameColumns as $tableName) {
124
+			if ($this->tableHandler->useTable($tableName)) {
125
+				$oldName = $tableName['from'];
126
+				$newName = $tableName['to'];
127
+				$attributes = $this->tableHandler->getColumnAttributes($tableName, $oldName);
128
+				if (false !== \strpos($attributes, ' int(')) {
129
+					$this->tableHandler->alterColumn($tableName, $oldName, $attributes, $newName);
130
+				}
131
+			}
132
+		}
133
+	}
134 134
 
135
-    /**
136
-     * Perform any upfront actions before synchronizing the schema
137
-     *
138
-     * Some typical uses include
139
-     *   table and column renames
140
-     *   data conversions
141
-     */
142
-    protected function preSyncActions()
143
-    {
144
-        // change 'bb' table prefix to 'newbb'
145
-        $this->changePrefix();
146
-        // columns dohtml, dosmiley, doxcode, doimage and dobr moved between tables as some point
147
-        $this->moveDoColumns();
148
-        // Convert IP address columns from int to readable varchar(45) for IPv6
135
+	/**
136
+	 * Perform any upfront actions before synchronizing the schema
137
+	 *
138
+	 * Some typical uses include
139
+	 *   table and column renames
140
+	 *   data conversions
141
+	 */
142
+	protected function preSyncActions()
143
+	{
144
+		// change 'bb' table prefix to 'newbb'
145
+		$this->changePrefix();
146
+		// columns dohtml, dosmiley, doxcode, doimage and dobr moved between tables as some point
147
+		$this->moveDoColumns();
148
+		// Convert IP address columns from int to readable varchar(45) for IPv6
149 149
 //        $this->convertIPAddresses('newbb_posts', 'poster_ip');
150 150
 //        $this->convertIPAddresses('newbb_report', 'reporter_ip');
151 151
 
152
-        // rename table
153
-        if ($this->renameTables && \is_array($this->renameTables)) {
154
-            $this->renameTable();
155
-        }
156
-        // rename column
157
-        if ($this->renameColumns && \is_array($this->renameColumns)) {
158
-            $this->renameColumns();
159
-        }
160
-    }
152
+		// rename table
153
+		if ($this->renameTables && \is_array($this->renameTables)) {
154
+			$this->renameTable();
155
+		}
156
+		// rename column
157
+		if ($this->renameColumns && \is_array($this->renameColumns)) {
158
+			$this->renameColumns();
159
+		}
160
+	}
161 161
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
      */
37 37
     public function __construct()
38 38
     {
39
-        $class = __NAMESPACE__ . '\\' . 'Configurator';
39
+        $class = __NAMESPACE__.'\\'.'Configurator';
40 40
         if (!\class_exists($class)) {
41 41
             throw new \RuntimeException("Class '$class' not found");
42 42
         }
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
                 $oldName = $tableName['from'];
126 126
                 $newName = $tableName['to'];
127 127
                 $attributes = $this->tableHandler->getColumnAttributes($tableName, $oldName);
128
-                if (false !== \strpos($attributes, ' int(')) {
128
+                if (false!==\strpos($attributes, ' int(')) {
129 129
                     $this->tableHandler->alterColumn($tableName, $oldName, $attributes, $newName);
130 130
                 }
131 131
             }
Please login to merge, or discard this patch.
class/Common/Breadcrumb.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -32,39 +32,39 @@  discard block
 block discarded – undo
32 32
  */
33 33
 class Breadcrumb
34 34
 {
35
-    public  $dirname;
36
-    private $bread = [];
35
+	public  $dirname;
36
+	private $bread = [];
37 37
 
38
-    public function __construct()
39
-    {
40
-        $this->dirname = \basename(\dirname(__DIR__, 2));
41
-    }
38
+	public function __construct()
39
+	{
40
+		$this->dirname = \basename(\dirname(__DIR__, 2));
41
+	}
42 42
 
43
-    /**
44
-     * Add link to breadcrumb
45
-     *
46
-     * @param string $title
47
-     * @param string $link
48
-     */
49
-    public function addLink($title = '', $link = ''): void
50
-    {
51
-        $this->bread[] = [
52
-            'link'  => $link,
53
-            'title' => $title,
54
-        ];
55
-    }
43
+	/**
44
+	 * Add link to breadcrumb
45
+	 *
46
+	 * @param string $title
47
+	 * @param string $link
48
+	 */
49
+	public function addLink($title = '', $link = ''): void
50
+	{
51
+		$this->bread[] = [
52
+			'link'  => $link,
53
+			'title' => $title,
54
+		];
55
+	}
56 56
 
57
-    /**
58
-     * Render BreadCrumb
59
-     */
60
-    public function render(): void
61
-    {
62
-        /*
57
+	/**
58
+	 * Render BreadCrumb
59
+	 */
60
+	public function render(): void
61
+	{
62
+		/*
63 63
         TODO if you want to use the render code below,
64 64
         1) create ./templates/chess_common_breadcrumb.tpl)
65 65
         2) add declaration to  xoops_version.php
66 66
         */
67
-        /*
67
+		/*
68 68
         if (!isset($GLOBALS['xoTheme']) || !\is_object($GLOBALS['xoTheme'])) {
69 69
             require $GLOBALS['xoops']->path('class/theme.php');
70 70
 
@@ -83,5 +83,5 @@  discard block
 block discarded – undo
83 83
 
84 84
         return $html;
85 85
         */
86
-    }
86
+	}
87 87
 }
Please login to merge, or discard this patch.
class/Common/Configurator.php 2 patches
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -24,41 +24,41 @@
 block discarded – undo
24 24
  */
25 25
 class Configurator
26 26
 {
27
-    public $name;
28
-    public $paths           = [];
29
-    public $uploadFolders   = [];
30
-    public $copyBlankFiles  = [];
31
-    public $copyTestFolders = [];
32
-    public $templateFolders = [];
33
-    public $oldFiles        = [];
34
-    public $oldFolders      = [];
35
-    public $renameTables    = [];
36
-    public $renameColumns   = [];
37
-    public $moduleStats     = [];
38
-    public $modCopyright;
39
-    public $icons;
27
+	public $name;
28
+	public $paths           = [];
29
+	public $uploadFolders   = [];
30
+	public $copyBlankFiles  = [];
31
+	public $copyTestFolders = [];
32
+	public $templateFolders = [];
33
+	public $oldFiles        = [];
34
+	public $oldFolders      = [];
35
+	public $renameTables    = [];
36
+	public $renameColumns   = [];
37
+	public $moduleStats     = [];
38
+	public $modCopyright;
39
+	public $icons;
40 40
 
41
-    /**
42
-     * Configurator constructor.
43
-     */
44
-    public function __construct()
45
-    {
46
-        $config = require \dirname(__DIR__, 2) . '/config/config.php';
41
+	/**
42
+	 * Configurator constructor.
43
+	 */
44
+	public function __construct()
45
+	{
46
+		$config = require \dirname(__DIR__, 2) . '/config/config.php';
47 47
 
48
-        $this->name            = $config->name;
49
-        $this->paths           = $config->paths;
50
-        $this->uploadFolders   = $config->uploadFolders;
51
-        $this->copyBlankFiles  = $config->copyBlankFiles;
52
-        $this->copyTestFolders = $config->copyTestFolders;
53
-        $this->templateFolders = $config->templateFolders;
54
-        $this->oldFiles        = $config->oldFiles;
55
-        $this->oldFolders      = $config->oldFolders;
56
-        $this->renameTables    = $config->renameTables;
57
-        $this->renameColumns   = $config->renameColumns;
58
-        $this->moduleStats     = $config->moduleStats;
59
-        $this->modCopyright    = $config->modCopyright;
48
+		$this->name            = $config->name;
49
+		$this->paths           = $config->paths;
50
+		$this->uploadFolders   = $config->uploadFolders;
51
+		$this->copyBlankFiles  = $config->copyBlankFiles;
52
+		$this->copyTestFolders = $config->copyTestFolders;
53
+		$this->templateFolders = $config->templateFolders;
54
+		$this->oldFiles        = $config->oldFiles;
55
+		$this->oldFolders      = $config->oldFolders;
56
+		$this->renameTables    = $config->renameTables;
57
+		$this->renameColumns   = $config->renameColumns;
58
+		$this->moduleStats     = $config->moduleStats;
59
+		$this->modCopyright    = $config->modCopyright;
60 60
 
61
-        $this->icons = require \dirname(__DIR__, 2) . '/config/icons.php';
62
-        $this->paths = require \dirname(__DIR__, 2) . '/config/paths.php';
63
-    }
61
+		$this->icons = require \dirname(__DIR__, 2) . '/config/icons.php';
62
+		$this->paths = require \dirname(__DIR__, 2) . '/config/paths.php';
63
+	}
64 64
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
      */
44 44
     public function __construct()
45 45
     {
46
-        $config = require \dirname(__DIR__, 2) . '/config/config.php';
46
+        $config = require \dirname(__DIR__, 2).'/config/config.php';
47 47
 
48 48
         $this->name            = $config->name;
49 49
         $this->paths           = $config->paths;
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
         $this->moduleStats     = $config->moduleStats;
59 59
         $this->modCopyright    = $config->modCopyright;
60 60
 
61
-        $this->icons = require \dirname(__DIR__, 2) . '/config/icons.php';
62
-        $this->paths = require \dirname(__DIR__, 2) . '/config/paths.php';
61
+        $this->icons = require \dirname(__DIR__, 2).'/config/icons.php';
62
+        $this->paths = require \dirname(__DIR__, 2).'/config/paths.php';
63 63
     }
64 64
 }
Please login to merge, or discard this patch.
class/JSON.php 2 patches
Indentation   +676 added lines, -676 removed lines patch added patch discarded remove patch
@@ -76,271 +76,271 @@  discard block
 block discarded – undo
76 76
  */
77 77
 class ServicesJSON
78 78
 {
79
-    /**
80
-     * constructs a new JSON instance
81
-     *
82
-     * @param int $use object behavior flags; combine with boolean-OR
83
-     *
84
-     *                           possible values:
85
-     *                           - SERVICES_JSON_LOOSE_TYPE:  loose typing.
86
-     *                                   "{...}" syntax creates associative arrays
87
-     *                                   instead of objects in decode().
88
-     *                           - SERVICES_JSON_SUPPRESS_ERRORS:  error suppression.
89
-     *                                   Values which can't be encoded (e.g. resources)
90
-     *                                   appear as NULL instead of throwing errors.
91
-     *                                   By default, a deeply-nested resource will
92
-     *                                   bubble up with an error, so all return values
93
-     *                                   from encode() should be checked with isError()
94
-     */
95
-    public function __construct($use = 0)
96
-    {
97
-        $this->use = $use;
98
-    }
99
-
100
-    /**
101
-     * convert a string from one UTF-16 char to one UTF-8 char
102
-     *
103
-     * Normally should be handled by mb_convert_encoding, but
104
-     * provides a slower PHP-only method for installations
105
-     * that lack the multibye string extension.
106
-     *
107
-     * @param string $utf16 UTF-16 character
108
-     * @return   string  UTF-8 character
109
-     */
110
-    public function utf162utf8($utf16): string
111
-    {
112
-        // oh please oh please oh please oh please oh please
113
-        if (function_exists('mb_convert_encoding')) {
114
-            return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16');
115
-        }
116
-
117
-        $bytes = (ord($utf16[0]) << 8) | ord($utf16[1]);
118
-
119
-        switch (true) {
120
-            case ((0x7F & $bytes) == $bytes):
121
-                // this case should never be reached, because we are in ASCII range
122
-                // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
123
-                return chr(0x7F & $bytes);
124
-            case (0x07FF & $bytes) == $bytes:
125
-                // return a 2-byte UTF-8 character
126
-                // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
127
-                return chr(0xC0 | (($bytes >> 6) & 0x1F)) . chr(0x80 | ($bytes & 0x3F));
128
-            case (0xFFFF & $bytes) == $bytes:
129
-                // return a 3-byte UTF-8 character
130
-                // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
131
-                return chr(0xE0 | (($bytes >> 12) & 0x0F)) . chr(0x80 | (($bytes >> 6) & 0x3F)) . chr(0x80 | ($bytes & 0x3F));
132
-        }
133
-
134
-        // ignoring UTF-32 for now, sorry
135
-        return '';
136
-    }
137
-
138
-    /**
139
-     * convert a string from one UTF-8 char to one UTF-16 char
140
-     *
141
-     * Normally should be handled by mb_convert_encoding, but
142
-     * provides a slower PHP-only method for installations
143
-     * that lack the multibye string extension.
144
-     *
145
-     * @param string $utf8 UTF-8 character
146
-     * @return   string  UTF-16 character
147
-     */
148
-    public function utf82utf16($utf8): string
149
-    {
150
-        // oh please oh please oh please oh please oh please
151
-        if (function_exists('mb_convert_encoding')) {
152
-            return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8');
153
-        }
154
-
155
-        switch (mb_strlen($utf8)) {
156
-            case 1:
157
-                // this case should never be reached, because we are in ASCII range
158
-                // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
159
-                return $utf8;
160
-            case 2:
161
-                // return a UTF-16 character from a 2-byte UTF-8 char
162
-                // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
163
-                return chr(0x07 & (ord($utf8[0]) >> 2)) . chr((0xC0 & (ord($utf8[0]) << 6)) | (0x3F & ord($utf8[1])));
164
-            case 3:
165
-                // return a UTF-16 character from a 3-byte UTF-8 char
166
-                // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
167
-                return chr((0xF0 & (ord($utf8[0]) << 4)) | (0x0F & (ord($utf8[1]) >> 2))) . chr((0xC0 & (ord($utf8[1]) << 6)) | (0x7F & ord($utf8[2])));
168
-        }
169
-
170
-        // ignoring UTF-32 for now, sorry
171
-        return '';
172
-    }
173
-
174
-    /**
175
-     * encodes an arbitrary variable into JSON format (and sends JSON Header)
176
-     *
177
-     * @param mixed $var         any number, boolean, string, array, or object to be encoded.
178
-     *                           see argument 1 to ServicesJSON() above for array-parsing behavior.
179
-     *                           if var is a strng, note that encode() always expects it
180
-     *                           to be in ASCII or UTF-8 format!
181
-     *
182
-     * @return   mixed   JSON string representation of input var or an error if a problem occurs
183
-     */
184
-    public function encode($var)
185
-    {
186
-        header('Document-type: application/json');
187
-
188
-        return $this->encodeUnsafe($var);
189
-    }
190
-
191
-    /**
192
-     * encodes an arbitrary variable into JSON format without JSON Header - warning - may allow CSS!!!!)
193
-     *
194
-     * @param mixed $var         any number, boolean, string, array, or object to be encoded.
195
-     *                           see argument 1 to ServicesJSON() above for array-parsing behavior.
196
-     *                           if var is a strng, note that encode() always expects it
197
-     *                           to be in ASCII or UTF-8 format!
198
-     *
199
-     * @return   mixed   JSON string representation of input var or an error if a problem occurs
200
-     */
201
-    public function encodeUnsafe($var)
202
-    {
203
-        // see bug #16908 - regarding numeric locale printing
204
-        $lc = setlocale(LC_NUMERIC, 0);
205
-        setlocale(LC_NUMERIC, 'C');
206
-        $ret = $this->_encode($var);
207
-        setlocale(LC_NUMERIC, $lc);
208
-
209
-        return $ret;
210
-    }
211
-
212
-    /**
213
-     * PRIVATE CODE that does the work of encodes an arbitrary variable into JSON format
214
-     *
215
-     * @param mixed $var         any number, boolean, string, array, or object to be encoded.
216
-     *                           see argument 1 to ServicesJSON() above for array-parsing behavior.
217
-     *                           if var is a strng, note that encode() always expects it
218
-     *                           to be in ASCII or UTF-8 format!
219
-     *
220
-     * @return   mixed   JSON string representation of input var or an error if a problem occurs
221
-     */
222
-    public function _encode($var)
223
-    {
224
-        switch (gettype($var)) {
225
-            case 'boolean':
226
-                return $var ? 'true' : 'false';
227
-            case 'NULL':
228
-                return 'null';
229
-            case 'integer':
230
-                return (int)$var;
231
-            case 'double':
232
-            case 'float':
233
-                return (float)$var;
234
-            case 'string':
235
-                // STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT
236
-                $ascii      = '';
237
-                $strlen_var = mb_strlen($var);
238
-
239
-                /*
79
+	/**
80
+	 * constructs a new JSON instance
81
+	 *
82
+	 * @param int $use object behavior flags; combine with boolean-OR
83
+	 *
84
+	 *                           possible values:
85
+	 *                           - SERVICES_JSON_LOOSE_TYPE:  loose typing.
86
+	 *                                   "{...}" syntax creates associative arrays
87
+	 *                                   instead of objects in decode().
88
+	 *                           - SERVICES_JSON_SUPPRESS_ERRORS:  error suppression.
89
+	 *                                   Values which can't be encoded (e.g. resources)
90
+	 *                                   appear as NULL instead of throwing errors.
91
+	 *                                   By default, a deeply-nested resource will
92
+	 *                                   bubble up with an error, so all return values
93
+	 *                                   from encode() should be checked with isError()
94
+	 */
95
+	public function __construct($use = 0)
96
+	{
97
+		$this->use = $use;
98
+	}
99
+
100
+	/**
101
+	 * convert a string from one UTF-16 char to one UTF-8 char
102
+	 *
103
+	 * Normally should be handled by mb_convert_encoding, but
104
+	 * provides a slower PHP-only method for installations
105
+	 * that lack the multibye string extension.
106
+	 *
107
+	 * @param string $utf16 UTF-16 character
108
+	 * @return   string  UTF-8 character
109
+	 */
110
+	public function utf162utf8($utf16): string
111
+	{
112
+		// oh please oh please oh please oh please oh please
113
+		if (function_exists('mb_convert_encoding')) {
114
+			return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16');
115
+		}
116
+
117
+		$bytes = (ord($utf16[0]) << 8) | ord($utf16[1]);
118
+
119
+		switch (true) {
120
+			case ((0x7F & $bytes) == $bytes):
121
+				// this case should never be reached, because we are in ASCII range
122
+				// see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
123
+				return chr(0x7F & $bytes);
124
+			case (0x07FF & $bytes) == $bytes:
125
+				// return a 2-byte UTF-8 character
126
+				// see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
127
+				return chr(0xC0 | (($bytes >> 6) & 0x1F)) . chr(0x80 | ($bytes & 0x3F));
128
+			case (0xFFFF & $bytes) == $bytes:
129
+				// return a 3-byte UTF-8 character
130
+				// see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
131
+				return chr(0xE0 | (($bytes >> 12) & 0x0F)) . chr(0x80 | (($bytes >> 6) & 0x3F)) . chr(0x80 | ($bytes & 0x3F));
132
+		}
133
+
134
+		// ignoring UTF-32 for now, sorry
135
+		return '';
136
+	}
137
+
138
+	/**
139
+	 * convert a string from one UTF-8 char to one UTF-16 char
140
+	 *
141
+	 * Normally should be handled by mb_convert_encoding, but
142
+	 * provides a slower PHP-only method for installations
143
+	 * that lack the multibye string extension.
144
+	 *
145
+	 * @param string $utf8 UTF-8 character
146
+	 * @return   string  UTF-16 character
147
+	 */
148
+	public function utf82utf16($utf8): string
149
+	{
150
+		// oh please oh please oh please oh please oh please
151
+		if (function_exists('mb_convert_encoding')) {
152
+			return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8');
153
+		}
154
+
155
+		switch (mb_strlen($utf8)) {
156
+			case 1:
157
+				// this case should never be reached, because we are in ASCII range
158
+				// see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
159
+				return $utf8;
160
+			case 2:
161
+				// return a UTF-16 character from a 2-byte UTF-8 char
162
+				// see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
163
+				return chr(0x07 & (ord($utf8[0]) >> 2)) . chr((0xC0 & (ord($utf8[0]) << 6)) | (0x3F & ord($utf8[1])));
164
+			case 3:
165
+				// return a UTF-16 character from a 3-byte UTF-8 char
166
+				// see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
167
+				return chr((0xF0 & (ord($utf8[0]) << 4)) | (0x0F & (ord($utf8[1]) >> 2))) . chr((0xC0 & (ord($utf8[1]) << 6)) | (0x7F & ord($utf8[2])));
168
+		}
169
+
170
+		// ignoring UTF-32 for now, sorry
171
+		return '';
172
+	}
173
+
174
+	/**
175
+	 * encodes an arbitrary variable into JSON format (and sends JSON Header)
176
+	 *
177
+	 * @param mixed $var         any number, boolean, string, array, or object to be encoded.
178
+	 *                           see argument 1 to ServicesJSON() above for array-parsing behavior.
179
+	 *                           if var is a strng, note that encode() always expects it
180
+	 *                           to be in ASCII or UTF-8 format!
181
+	 *
182
+	 * @return   mixed   JSON string representation of input var or an error if a problem occurs
183
+	 */
184
+	public function encode($var)
185
+	{
186
+		header('Document-type: application/json');
187
+
188
+		return $this->encodeUnsafe($var);
189
+	}
190
+
191
+	/**
192
+	 * encodes an arbitrary variable into JSON format without JSON Header - warning - may allow CSS!!!!)
193
+	 *
194
+	 * @param mixed $var         any number, boolean, string, array, or object to be encoded.
195
+	 *                           see argument 1 to ServicesJSON() above for array-parsing behavior.
196
+	 *                           if var is a strng, note that encode() always expects it
197
+	 *                           to be in ASCII or UTF-8 format!
198
+	 *
199
+	 * @return   mixed   JSON string representation of input var or an error if a problem occurs
200
+	 */
201
+	public function encodeUnsafe($var)
202
+	{
203
+		// see bug #16908 - regarding numeric locale printing
204
+		$lc = setlocale(LC_NUMERIC, 0);
205
+		setlocale(LC_NUMERIC, 'C');
206
+		$ret = $this->_encode($var);
207
+		setlocale(LC_NUMERIC, $lc);
208
+
209
+		return $ret;
210
+	}
211
+
212
+	/**
213
+	 * PRIVATE CODE that does the work of encodes an arbitrary variable into JSON format
214
+	 *
215
+	 * @param mixed $var         any number, boolean, string, array, or object to be encoded.
216
+	 *                           see argument 1 to ServicesJSON() above for array-parsing behavior.
217
+	 *                           if var is a strng, note that encode() always expects it
218
+	 *                           to be in ASCII or UTF-8 format!
219
+	 *
220
+	 * @return   mixed   JSON string representation of input var or an error if a problem occurs
221
+	 */
222
+	public function _encode($var)
223
+	{
224
+		switch (gettype($var)) {
225
+			case 'boolean':
226
+				return $var ? 'true' : 'false';
227
+			case 'NULL':
228
+				return 'null';
229
+			case 'integer':
230
+				return (int)$var;
231
+			case 'double':
232
+			case 'float':
233
+				return (float)$var;
234
+			case 'string':
235
+				// STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT
236
+				$ascii      = '';
237
+				$strlen_var = mb_strlen($var);
238
+
239
+				/*
240 240
                  * Iterate over every character in the string,
241 241
                  * escaping with a slash or encoding to UTF-8 where necessary
242 242
                  */
243
-                for ($c = 0; $c < $strlen_var; ++$c) {
244
-                    $ord_var_c = ord($var[$c]);
245
-
246
-                    switch (true) {
247
-                        case 0x08 == $ord_var_c:
248
-                            $ascii .= '\b';
249
-                            break;
250
-                        case 0x09 == $ord_var_c:
251
-                            $ascii .= '\t';
252
-                            break;
253
-                        case 0x0A == $ord_var_c:
254
-                            $ascii .= '\n';
255
-                            break;
256
-                        case 0x0C == $ord_var_c:
257
-                            $ascii .= '\f';
258
-                            break;
259
-                        case 0x0D == $ord_var_c:
260
-                            $ascii .= '\r';
261
-                            break;
262
-                        case 0x22 == $ord_var_c:
263
-                        case 0x2F == $ord_var_c:
264
-                        case 0x5C == $ord_var_c:
265
-                            // double quote, slash, slosh
266
-                            $ascii .= '\\' . $var[$c];
267
-                            break;
268
-                        case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)):
269
-                            // characters U-00000000 - U-0000007F (same as ASCII)
270
-                            $ascii .= $var[$c];
271
-                            break;
272
-                        case (0xC0 == ($ord_var_c & 0xE0)):
273
-                            // characters U-00000080 - U-000007FF, mask 110SONGLIST
274
-                            // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
275
-                            if ($c + 1 >= $strlen_var) {
276
-                                ++$c;
277
-                                $ascii .= '?';
278
-                                break;
279
-                            }
280
-
281
-                            $char = pack('C*', $ord_var_c, ord($var[$c + 1]));
282
-                            ++$c;
283
-                            $utf16 = $this->utf82utf16($char);
284
-                            $ascii .= sprintf('\u%04s', bin2hex($utf16));
285
-                            break;
286
-                        case (0xE0 == ($ord_var_c & 0xF0)):
287
-                            if ($c + 2 >= $strlen_var) {
288
-                                $c     += 2;
289
-                                $ascii .= '?';
290
-                                break;
291
-                            }
292
-                            // characters U-00000800 - U-0000FFFF, mask 1110XXXX
293
-                            // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
294
-                            $char  = pack('C*', $ord_var_c, @ord($var[$c + 1]), @ord($var[$c + 2]));
295
-                            $c     += 2;
296
-                            $utf16 = $this->utf82utf16($char);
297
-                            $ascii .= sprintf('\u%04s', bin2hex($utf16));
298
-                            break;
299
-                        case (0xF0 == ($ord_var_c & 0xF8)):
300
-                            if ($c + 3 >= $strlen_var) {
301
-                                $c     += 3;
302
-                                $ascii .= '?';
303
-                                break;
304
-                            }
305
-                            // characters U-00010000 - U-001FFFFF, mask 11110XXX
306
-                            // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
307
-                            $char  = pack('C*', $ord_var_c, ord($var[$c + 1]), ord($var[$c + 2]), ord($var[$c + 3]));
308
-                            $c     += 3;
309
-                            $utf16 = $this->utf82utf16($char);
310
-                            $ascii .= sprintf('\u%04s', bin2hex($utf16));
311
-                            break;
312
-                        case (0xF8 == ($ord_var_c & 0xFC)):
313
-                            // characters U-00200000 - U-03FFFFFF, mask 111110XX
314
-                            // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
315
-                            if ($c + 4 >= $strlen_var) {
316
-                                $c     += 4;
317
-                                $ascii .= '?';
318
-                                break;
319
-                            }
320
-                            $char  = pack('C*', $ord_var_c, ord($var[$c + 1]), ord($var[$c + 2]), ord($var[$c + 3]), ord($var[$c + 4]));
321
-                            $c     += 4;
322
-                            $utf16 = $this->utf82utf16($char);
323
-                            $ascii .= sprintf('\u%04s', bin2hex($utf16));
324
-                            break;
325
-                        case (0xFC == ($ord_var_c & 0xFE)):
326
-                            if ($c + 5 >= $strlen_var) {
327
-                                $c     += 5;
328
-                                $ascii .= '?';
329
-                                break;
330
-                            }
331
-                            // characters U-04000000 - U-7FFFFFFF, mask 1111110X
332
-                            // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
333
-                            $char  = pack('C*', $ord_var_c, ord($var[$c + 1]), ord($var[$c + 2]), ord($var[$c + 3]), ord($var[$c + 4]), ord($var[$c + 5]));
334
-                            $c     += 5;
335
-                            $utf16 = $this->utf82utf16($char);
336
-                            $ascii .= sprintf('\u%04s', bin2hex($utf16));
337
-                            break;
338
-                    }
339
-                }
340
-
341
-                return '"' . $ascii . '"';
342
-            case 'array':
343
-                /*
243
+				for ($c = 0; $c < $strlen_var; ++$c) {
244
+					$ord_var_c = ord($var[$c]);
245
+
246
+					switch (true) {
247
+						case 0x08 == $ord_var_c:
248
+							$ascii .= '\b';
249
+							break;
250
+						case 0x09 == $ord_var_c:
251
+							$ascii .= '\t';
252
+							break;
253
+						case 0x0A == $ord_var_c:
254
+							$ascii .= '\n';
255
+							break;
256
+						case 0x0C == $ord_var_c:
257
+							$ascii .= '\f';
258
+							break;
259
+						case 0x0D == $ord_var_c:
260
+							$ascii .= '\r';
261
+							break;
262
+						case 0x22 == $ord_var_c:
263
+						case 0x2F == $ord_var_c:
264
+						case 0x5C == $ord_var_c:
265
+							// double quote, slash, slosh
266
+							$ascii .= '\\' . $var[$c];
267
+							break;
268
+						case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)):
269
+							// characters U-00000000 - U-0000007F (same as ASCII)
270
+							$ascii .= $var[$c];
271
+							break;
272
+						case (0xC0 == ($ord_var_c & 0xE0)):
273
+							// characters U-00000080 - U-000007FF, mask 110SONGLIST
274
+							// see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
275
+							if ($c + 1 >= $strlen_var) {
276
+								++$c;
277
+								$ascii .= '?';
278
+								break;
279
+							}
280
+
281
+							$char = pack('C*', $ord_var_c, ord($var[$c + 1]));
282
+							++$c;
283
+							$utf16 = $this->utf82utf16($char);
284
+							$ascii .= sprintf('\u%04s', bin2hex($utf16));
285
+							break;
286
+						case (0xE0 == ($ord_var_c & 0xF0)):
287
+							if ($c + 2 >= $strlen_var) {
288
+								$c     += 2;
289
+								$ascii .= '?';
290
+								break;
291
+							}
292
+							// characters U-00000800 - U-0000FFFF, mask 1110XXXX
293
+							// see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
294
+							$char  = pack('C*', $ord_var_c, @ord($var[$c + 1]), @ord($var[$c + 2]));
295
+							$c     += 2;
296
+							$utf16 = $this->utf82utf16($char);
297
+							$ascii .= sprintf('\u%04s', bin2hex($utf16));
298
+							break;
299
+						case (0xF0 == ($ord_var_c & 0xF8)):
300
+							if ($c + 3 >= $strlen_var) {
301
+								$c     += 3;
302
+								$ascii .= '?';
303
+								break;
304
+							}
305
+							// characters U-00010000 - U-001FFFFF, mask 11110XXX
306
+							// see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
307
+							$char  = pack('C*', $ord_var_c, ord($var[$c + 1]), ord($var[$c + 2]), ord($var[$c + 3]));
308
+							$c     += 3;
309
+							$utf16 = $this->utf82utf16($char);
310
+							$ascii .= sprintf('\u%04s', bin2hex($utf16));
311
+							break;
312
+						case (0xF8 == ($ord_var_c & 0xFC)):
313
+							// characters U-00200000 - U-03FFFFFF, mask 111110XX
314
+							// see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
315
+							if ($c + 4 >= $strlen_var) {
316
+								$c     += 4;
317
+								$ascii .= '?';
318
+								break;
319
+							}
320
+							$char  = pack('C*', $ord_var_c, ord($var[$c + 1]), ord($var[$c + 2]), ord($var[$c + 3]), ord($var[$c + 4]));
321
+							$c     += 4;
322
+							$utf16 = $this->utf82utf16($char);
323
+							$ascii .= sprintf('\u%04s', bin2hex($utf16));
324
+							break;
325
+						case (0xFC == ($ord_var_c & 0xFE)):
326
+							if ($c + 5 >= $strlen_var) {
327
+								$c     += 5;
328
+								$ascii .= '?';
329
+								break;
330
+							}
331
+							// characters U-04000000 - U-7FFFFFFF, mask 1111110X
332
+							// see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
333
+							$char  = pack('C*', $ord_var_c, ord($var[$c + 1]), ord($var[$c + 2]), ord($var[$c + 3]), ord($var[$c + 4]), ord($var[$c + 5]));
334
+							$c     += 5;
335
+							$utf16 = $this->utf82utf16($char);
336
+							$ascii .= sprintf('\u%04s', bin2hex($utf16));
337
+							break;
338
+					}
339
+				}
340
+
341
+				return '"' . $ascii . '"';
342
+			case 'array':
343
+				/*
344 344
                  * As per JSON spec if any array key is not an integer
345 345
                  * we must treat the the whole array as an object. We
346 346
                  * also try to catch a sparsely populated associative
@@ -358,422 +358,422 @@  discard block
 block discarded – undo
358 358
                  * bracket notation.
359 359
                  */
360 360
 
361
-                // treat as a JSON object
362
-                if (is_array($var) && count($var) && (array_keys($var) !== range(0, count($var) - 1))) {
363
-                    $properties = array_map([$this, 'name_value'], array_keys($var), array_values($var));
364
-
365
-                    foreach ($properties as $property) {
366
-                        if ($this->isError($property)) {
367
-                            return $property;
368
-                        }
369
-                    }
370
-
371
-                    return '{' . implode(',', $properties) . '}';
372
-                }
373
-
374
-                // treat it like a regular array
375
-                $elements = array_map([$this, '_encode'], $var);
376
-
377
-                foreach ($elements as $element) {
378
-                    if ($this->isError($element)) {
379
-                        return $element;
380
-                    }
381
-                }
382
-
383
-                return '[' . implode(',', $elements) . ']';
384
-            case 'object':
385
-                $vars = get_object_vars($var);
386
-
387
-                $properties = array_map([$this, 'name_value'], array_keys($vars), array_values($vars));
388
-
389
-                foreach ($properties as $property) {
390
-                    if ($this->isError($property)) {
391
-                        return $property;
392
-                    }
393
-                }
394
-
395
-                return '{' . implode(',', $properties) . '}';
396
-            default:
397
-                return ($this->use & SERVICES_JSON_SUPPRESS_ERRORS) ? 'null' : new ServicesJSON_Error(gettype($var) . ' can not be encoded as JSON string');
398
-        }
399
-    }
400
-
401
-    /**
402
-     * array-walking function for use in generating JSON-formatted name-value pairs
403
-     *
404
-     * @param string $name  name of key to use
405
-     * @param mixed  $value reference to an array element to be encoded
406
-     *
407
-     * @return   string  JSON-formatted name-value pair, like '"name":value'
408
-     */
409
-    public function name_value($name, $value)
410
-    {
411
-        $encoded_value = $this->_encode($value);
412
-
413
-        if ($this->isError($encoded_value)) {
414
-            return $encoded_value;
415
-        }
416
-
417
-        return $this->_encode((string)$name) . ':' . $encoded_value;
418
-    }
419
-
420
-    /**
421
-     * reduce a string by removing leading and trailing comments and whitespace
422
-     *
423
-     * @param string $str string value to strip of comments and whitespace
424
-     *
425
-     * @return   string  string value stripped of comments and whitespace
426
-     */
427
-    public function reduce_string($str): string
428
-    {
429
-        $str = preg_replace(
430
-            [
431
-                // eliminate single line comments in '// ...' form
432
-                '#^\s*//(.+)$#m',
433
-
434
-                // eliminate multi-line comments in '/* ... */' form, at start of string
435
-                '#^\s*/\*(.+)\*/#Us',
436
-
437
-                // eliminate multi-line comments in '/* ... */' form, at end of string
438
-                '#/\*(.+)\*/\s*$#Us',
439
-            ],
440
-            '',
441
-            $str
442
-        );
443
-
444
-        // eliminate extraneous space
445
-        return trim($str);
446
-    }
447
-
448
-    /**
449
-     * decodes a JSON string into appropriate variable
450
-     *
451
-     * @param string $str JSON-formatted string
452
-     *
453
-     * @return   array|bool|float|int|\stdClass|string|void|null   number, boolean, string, array, or object
454
-     *                   corresponding to given JSON input string.
455
-     *                   See argument 1 to ServicesJSON() above for object-output behavior.
456
-     *                   Note that decode() always returns strings
457
-     *                   in ASCII or UTF-8 format!
458
-     */
459
-    public function decode($str)
460
-    {
461
-        $str = $this->reduce_string($str);
462
-
463
-        switch (mb_strtolower($str)) {
464
-            case 'true':
465
-                return true;
466
-            case 'false':
467
-                return false;
468
-            case 'null':
469
-                return null;
470
-            default:
471
-                $m = [];
472
-
473
-                if (is_numeric($str)) {
474
-                    // Lookie-loo, it's a number
475
-
476
-                    // This would work on its own, but I'm trying to be
477
-                    // good about returning integers where appropriate:
478
-                    // return (float)$str;
479
-
480
-                    // Return float or int, as appropriate
481
-                    return ((float)$str == (int)$str) ? (int)$str : (float)$str;
482
-                }
483
-
484
-                if (preg_match('/^("|\').*(\1)$/s', $str, $m) && $m[1] == $m[2]) {
485
-                    // STRINGS RETURNED IN UTF-8 FORMAT
486
-                    $delim       = mb_substr($str, 0, 1);
487
-                    $chrs        = mb_substr($str, 1, -1);
488
-                    $utf8        = '';
489
-                    $strlen_chrs = mb_strlen($chrs);
490
-
491
-                    for ($c = 0; $c < $strlen_chrs; ++$c) {
492
-                        $substr_chrs_c_2 = mb_substr($chrs, $c, 2);
493
-                        $ord_chrs_c      = ord($chrs[$c]);
494
-
495
-                        switch (true) {
496
-                            case '\b' === $substr_chrs_c_2:
497
-                                $utf8 .= chr(0x08);
498
-                                ++$c;
499
-                                break;
500
-                            case '\t' === $substr_chrs_c_2:
501
-                                $utf8 .= chr(0x09);
502
-                                ++$c;
503
-                                break;
504
-                            case '\n' === $substr_chrs_c_2:
505
-                                $utf8 .= chr(0x0A);
506
-                                ++$c;
507
-                                break;
508
-                            case '\f' === $substr_chrs_c_2:
509
-                                $utf8 .= chr(0x0C);
510
-                                ++$c;
511
-                                break;
512
-                            case '\r' === $substr_chrs_c_2:
513
-                                $utf8 .= chr(0x0D);
514
-                                ++$c;
515
-                                break;
516
-                            case '\\"' === $substr_chrs_c_2:
517
-                            case '\\\'' === $substr_chrs_c_2:
518
-                            case '\\\\' === $substr_chrs_c_2:
519
-                            case '\\/' === $substr_chrs_c_2:
520
-                                if (('"' === $delim && '\\\'' !== $substr_chrs_c_2)
521
-                                    || ("'" === $delim && '\\"' !== $substr_chrs_c_2)) {
522
-                                    $utf8 .= $chrs[++$c];
523
-                                }
524
-                                break;
525
-                            case preg_match('/\\\u[0-9A-F]{4}/i', mb_substr($chrs, $c, 6)):
526
-                                // single, escaped unicode character
527
-                                $utf16 = chr(hexdec(mb_substr($chrs, $c + 2, 2))) . chr(hexdec(mb_substr($chrs, $c + 4, 2)));
528
-                                $utf8  .= $this->utf162utf8($utf16);
529
-                                $c     += 5;
530
-                                break;
531
-                            case ($ord_chrs_c >= 0x20) && ($ord_chrs_c <= 0x7F):
532
-                                $utf8 .= $chrs[$c];
533
-                                break;
534
-                            case 0xC0 == ($ord_chrs_c & 0xE0):
535
-                                // characters U-00000080 - U-000007FF, mask 110SONGLIST
536
-                                //see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
537
-                                $utf8 .= mb_substr($chrs, $c, 2);
538
-                                ++$c;
539
-                                break;
540
-                            case 0xE0 == ($ord_chrs_c & 0xF0):
541
-                                // characters U-00000800 - U-0000FFFF, mask 1110XXXX
542
-                                // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
543
-                                $utf8 .= mb_substr($chrs, $c, 3);
544
-                                $c    += 2;
545
-                                break;
546
-                            case 0xF0 == ($ord_chrs_c & 0xF8):
547
-                                // characters U-00010000 - U-001FFFFF, mask 11110XXX
548
-                                // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
549
-                                $utf8 .= mb_substr($chrs, $c, 4);
550
-                                $c    += 3;
551
-                                break;
552
-                            case 0xF8 == ($ord_chrs_c & 0xFC):
553
-                                // characters U-00200000 - U-03FFFFFF, mask 111110XX
554
-                                // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
555
-                                $utf8 .= mb_substr($chrs, $c, 5);
556
-                                $c    += 4;
557
-                                break;
558
-                            case 0xFC == ($ord_chrs_c & 0xFE):
559
-                                // characters U-04000000 - U-7FFFFFFF, mask 1111110X
560
-                                // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
561
-                                $utf8 .= mb_substr($chrs, $c, 6);
562
-                                $c    += 5;
563
-                                break;
564
-                        }
565
-                    }
566
-
567
-                    return $utf8;
568
-                }
569
-
570
-                if (preg_match('/^\[.*\]$/s', $str) || preg_match('/^\{.*\}$/s', $str)) {
571
-                    // array, or object notation
572
-
573
-                    if ('[' === $str[0]) {
574
-                        $stk = [SERVICES_JSON_IN_ARR];
575
-                        $arr = [];
576
-                    } elseif ($this->use & SERVICES_JSON_LOOSE_TYPE) {
577
-                            $stk = [SERVICES_JSON_IN_OBJ];
578
-                            $obj = [];
579
-                        } else {
580
-                            $stk = [SERVICES_JSON_IN_OBJ];
581
-                            $obj = new stdClass();
582
-                    }
583
-
584
-                    array_push(
585
-                        $stk,
586
-                        [
587
-                            'what'  => SERVICES_JSON_SLICE,
588
-                            'where' => 0,
589
-                            'delim' => false,
590
-                        ]
591
-                    );
592
-
593
-                    $chrs = mb_substr($str, 1, -1);
594
-                    $chrs = $this->reduce_string($chrs);
595
-
596
-                    if ('' == $chrs) {
597
-                        if (SERVICES_JSON_IN_ARR == reset($stk)) {
598
-                            return $arr;
599
-                        }
600
-
601
-                        return $obj;
602
-                    }
603
-
604
-                    //print("\nparsing {$chrs}\n");
605
-
606
-                    $strlen_chrs = mb_strlen($chrs);
607
-
608
-                    for ($c = 0; $c <= $strlen_chrs; ++$c) {
609
-                        $top             = end($stk);
610
-                        $substr_chrs_c_2 = mb_substr($chrs, $c, 2);
611
-
612
-                        if (($c == $strlen_chrs) || ((',' === $chrs[$c]) && (SERVICES_JSON_SLICE == $top['what']))) {
613
-                            // found a comma that is not inside a string, array, etc.,
614
-                            // OR we've reached the end of the character list
615
-                            $slice = mb_substr($chrs, $top['where'], $c - $top['where']);
616
-                            array_push($stk, ['what' => SERVICES_JSON_SLICE, 'where' => $c + 1, 'delim' => false]);
617
-                            //print("Found split at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
618
-
619
-                            if (SERVICES_JSON_IN_ARR == reset($stk)) {
620
-                                // we are in an array, so just push an element onto the stack
621
-                                $arr[] = $this->decode($slice);
622
-                            } elseif (SERVICES_JSON_IN_OBJ == reset($stk)) {
623
-                                // we are in an object, so figure
624
-                                // out the property name and set an
625
-                                // element in an associative array,
626
-                                // for now
627
-                                $parts = [];
628
-
629
-                                if (preg_match('/^\s*(["\'].*[^\\\]["\'])\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
630
-                                    // "name":value pair
631
-                                    $key = $this->decode($parts[1]);
632
-                                    $val = $this->decode($parts[2]);
633
-
634
-                                    if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
635
-                                        $obj[$key] = $val;
636
-                                    } else {
637
-                                        $obj->$key = $val;
638
-                                    }
639
-                                } elseif (preg_match('/^\s*(\w+)\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
640
-                                    // name:value pair, where name is unquoted
641
-                                    $key = $parts[1];
642
-                                    $val = $this->decode($parts[2]);
643
-
644
-                                    if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
645
-                                        $obj[$key] = $val;
646
-                                    } else {
647
-                                        $obj->$key = $val;
648
-                                    }
649
-                                }
650
-                            }
651
-                        } elseif ((('"' === $chrs[$c]) || ("'" === $chrs[$c])) && (SERVICES_JSON_IN_STR != $top['what'])) {
652
-                            // found a quote, and we are not inside a string
653
-                            array_push($stk, ['what' => SERVICES_JSON_IN_STR, 'where' => $c, 'delim' => $chrs[$c]]);
654
-                            //print("Found start of string at {$c}\n");
655
-                        } elseif (($chrs[$c] == $top['delim'])
656
-                                  && (SERVICES_JSON_IN_STR == $top['what'])
657
-                                  && (1 != (mb_strlen(mb_substr($chrs, 0, $c)) - mb_strlen(rtrim(mb_substr($chrs, 0, $c), '\\'))) % 2)) {
658
-                            // found a quote, we're in a string, and it's not escaped
659
-                            // we know that it's not escaped becase there is _not_ an
660
-                            // odd number of backslashes at the end of the string so far
661
-                            array_pop($stk);
662
-                            //print("Found end of string at {$c}: ".substr($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n");
663
-                        } elseif (('[' === $chrs[$c])
664
-                                  && in_array($top['what'], [SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ], true)) {
665
-                            // found a left-bracket, and we are in an array, object, or slice
666
-                            array_push($stk, ['what' => SERVICES_JSON_IN_ARR, 'where' => $c, 'delim' => false]);
667
-                            //print("Found start of array at {$c}\n");
668
-                        } elseif ((']' === $chrs[$c]) && (SERVICES_JSON_IN_ARR == $top['what'])) {
669
-                            // found a right-bracket, and we're in an array
670
-                            array_pop($stk);
671
-                            //print("Found end of array at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
672
-                        } elseif (('{' === $chrs[$c])
673
-                                  && in_array($top['what'], [SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ], true)) {
674
-                            // found a left-brace, and we are in an array, object, or slice
675
-                            array_push($stk, ['what' => SERVICES_JSON_IN_OBJ, 'where' => $c, 'delim' => false]);
676
-                            //print("Found start of object at {$c}\n");
677
-                        } elseif (('}' === $chrs[$c]) && (SERVICES_JSON_IN_OBJ == $top['what'])) {
678
-                            // found a right-brace, and we're in an object
679
-                            array_pop($stk);
680
-                            //print("Found end of object at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
681
-                        } elseif (('/*' === $substr_chrs_c_2)
682
-                                  && in_array($top['what'], [SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ], true)) {
683
-                            // found a comment start, and we are in an array, object, or slice
684
-                            array_push($stk, ['what' => SERVICES_JSON_IN_CMT, 'where' => $c, 'delim' => false]);
685
-                            ++$c;
686
-                            //print("Found start of comment at {$c}\n");
687
-                        } elseif (('*/' === $substr_chrs_c_2) && (SERVICES_JSON_IN_CMT == $top['what'])) {
688
-                            // found a comment end, and we're in one now
689
-                            array_pop($stk);
690
-                            ++$c;
691
-
692
-                            for ($i = $top['where']; $i <= $c; ++$i) {
693
-                                $chrs = substr_replace($chrs, ' ', $i, 1);
694
-                            }
695
-                            //print("Found end of comment at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
696
-                        }
697
-                    }
698
-
699
-                    if (SERVICES_JSON_IN_ARR == reset($stk)) {
700
-                        return $arr;
701
-                    }
702
-
703
-                    if (SERVICES_JSON_IN_OBJ == reset($stk)) {
704
-                        return $obj;
705
-                    }
706
-                }
707
-        }
708
-    }
709
-
710
-    /**
711
-     * @param      $data
712
-     * @param null $code
713
-     * @return bool
714
-     * @todo Ultimately, this should just call PEAR::isError()
715
-     */
716
-    public function isError($data, $code = null): bool
717
-    {
718
-        if (class_exists('pear')) {
719
-            return PEAR::isError($data, $code);
720
-        }
721
-
722
-        if (is_object($data)
723
-            && ($data instanceof \services_json_error
724
-                || $data instanceof \services_json_error)) {
725
-            return true;
726
-        }
727
-
728
-        return false;
729
-    }
361
+				// treat as a JSON object
362
+				if (is_array($var) && count($var) && (array_keys($var) !== range(0, count($var) - 1))) {
363
+					$properties = array_map([$this, 'name_value'], array_keys($var), array_values($var));
364
+
365
+					foreach ($properties as $property) {
366
+						if ($this->isError($property)) {
367
+							return $property;
368
+						}
369
+					}
370
+
371
+					return '{' . implode(',', $properties) . '}';
372
+				}
373
+
374
+				// treat it like a regular array
375
+				$elements = array_map([$this, '_encode'], $var);
376
+
377
+				foreach ($elements as $element) {
378
+					if ($this->isError($element)) {
379
+						return $element;
380
+					}
381
+				}
382
+
383
+				return '[' . implode(',', $elements) . ']';
384
+			case 'object':
385
+				$vars = get_object_vars($var);
386
+
387
+				$properties = array_map([$this, 'name_value'], array_keys($vars), array_values($vars));
388
+
389
+				foreach ($properties as $property) {
390
+					if ($this->isError($property)) {
391
+						return $property;
392
+					}
393
+				}
394
+
395
+				return '{' . implode(',', $properties) . '}';
396
+			default:
397
+				return ($this->use & SERVICES_JSON_SUPPRESS_ERRORS) ? 'null' : new ServicesJSON_Error(gettype($var) . ' can not be encoded as JSON string');
398
+		}
399
+	}
400
+
401
+	/**
402
+	 * array-walking function for use in generating JSON-formatted name-value pairs
403
+	 *
404
+	 * @param string $name  name of key to use
405
+	 * @param mixed  $value reference to an array element to be encoded
406
+	 *
407
+	 * @return   string  JSON-formatted name-value pair, like '"name":value'
408
+	 */
409
+	public function name_value($name, $value)
410
+	{
411
+		$encoded_value = $this->_encode($value);
412
+
413
+		if ($this->isError($encoded_value)) {
414
+			return $encoded_value;
415
+		}
416
+
417
+		return $this->_encode((string)$name) . ':' . $encoded_value;
418
+	}
419
+
420
+	/**
421
+	 * reduce a string by removing leading and trailing comments and whitespace
422
+	 *
423
+	 * @param string $str string value to strip of comments and whitespace
424
+	 *
425
+	 * @return   string  string value stripped of comments and whitespace
426
+	 */
427
+	public function reduce_string($str): string
428
+	{
429
+		$str = preg_replace(
430
+			[
431
+				// eliminate single line comments in '// ...' form
432
+				'#^\s*//(.+)$#m',
433
+
434
+				// eliminate multi-line comments in '/* ... */' form, at start of string
435
+				'#^\s*/\*(.+)\*/#Us',
436
+
437
+				// eliminate multi-line comments in '/* ... */' form, at end of string
438
+				'#/\*(.+)\*/\s*$#Us',
439
+			],
440
+			'',
441
+			$str
442
+		);
443
+
444
+		// eliminate extraneous space
445
+		return trim($str);
446
+	}
447
+
448
+	/**
449
+	 * decodes a JSON string into appropriate variable
450
+	 *
451
+	 * @param string $str JSON-formatted string
452
+	 *
453
+	 * @return   array|bool|float|int|\stdClass|string|void|null   number, boolean, string, array, or object
454
+	 *                   corresponding to given JSON input string.
455
+	 *                   See argument 1 to ServicesJSON() above for object-output behavior.
456
+	 *                   Note that decode() always returns strings
457
+	 *                   in ASCII or UTF-8 format!
458
+	 */
459
+	public function decode($str)
460
+	{
461
+		$str = $this->reduce_string($str);
462
+
463
+		switch (mb_strtolower($str)) {
464
+			case 'true':
465
+				return true;
466
+			case 'false':
467
+				return false;
468
+			case 'null':
469
+				return null;
470
+			default:
471
+				$m = [];
472
+
473
+				if (is_numeric($str)) {
474
+					// Lookie-loo, it's a number
475
+
476
+					// This would work on its own, but I'm trying to be
477
+					// good about returning integers where appropriate:
478
+					// return (float)$str;
479
+
480
+					// Return float or int, as appropriate
481
+					return ((float)$str == (int)$str) ? (int)$str : (float)$str;
482
+				}
483
+
484
+				if (preg_match('/^("|\').*(\1)$/s', $str, $m) && $m[1] == $m[2]) {
485
+					// STRINGS RETURNED IN UTF-8 FORMAT
486
+					$delim       = mb_substr($str, 0, 1);
487
+					$chrs        = mb_substr($str, 1, -1);
488
+					$utf8        = '';
489
+					$strlen_chrs = mb_strlen($chrs);
490
+
491
+					for ($c = 0; $c < $strlen_chrs; ++$c) {
492
+						$substr_chrs_c_2 = mb_substr($chrs, $c, 2);
493
+						$ord_chrs_c      = ord($chrs[$c]);
494
+
495
+						switch (true) {
496
+							case '\b' === $substr_chrs_c_2:
497
+								$utf8 .= chr(0x08);
498
+								++$c;
499
+								break;
500
+							case '\t' === $substr_chrs_c_2:
501
+								$utf8 .= chr(0x09);
502
+								++$c;
503
+								break;
504
+							case '\n' === $substr_chrs_c_2:
505
+								$utf8 .= chr(0x0A);
506
+								++$c;
507
+								break;
508
+							case '\f' === $substr_chrs_c_2:
509
+								$utf8 .= chr(0x0C);
510
+								++$c;
511
+								break;
512
+							case '\r' === $substr_chrs_c_2:
513
+								$utf8 .= chr(0x0D);
514
+								++$c;
515
+								break;
516
+							case '\\"' === $substr_chrs_c_2:
517
+							case '\\\'' === $substr_chrs_c_2:
518
+							case '\\\\' === $substr_chrs_c_2:
519
+							case '\\/' === $substr_chrs_c_2:
520
+								if (('"' === $delim && '\\\'' !== $substr_chrs_c_2)
521
+									|| ("'" === $delim && '\\"' !== $substr_chrs_c_2)) {
522
+									$utf8 .= $chrs[++$c];
523
+								}
524
+								break;
525
+							case preg_match('/\\\u[0-9A-F]{4}/i', mb_substr($chrs, $c, 6)):
526
+								// single, escaped unicode character
527
+								$utf16 = chr(hexdec(mb_substr($chrs, $c + 2, 2))) . chr(hexdec(mb_substr($chrs, $c + 4, 2)));
528
+								$utf8  .= $this->utf162utf8($utf16);
529
+								$c     += 5;
530
+								break;
531
+							case ($ord_chrs_c >= 0x20) && ($ord_chrs_c <= 0x7F):
532
+								$utf8 .= $chrs[$c];
533
+								break;
534
+							case 0xC0 == ($ord_chrs_c & 0xE0):
535
+								// characters U-00000080 - U-000007FF, mask 110SONGLIST
536
+								//see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
537
+								$utf8 .= mb_substr($chrs, $c, 2);
538
+								++$c;
539
+								break;
540
+							case 0xE0 == ($ord_chrs_c & 0xF0):
541
+								// characters U-00000800 - U-0000FFFF, mask 1110XXXX
542
+								// see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
543
+								$utf8 .= mb_substr($chrs, $c, 3);
544
+								$c    += 2;
545
+								break;
546
+							case 0xF0 == ($ord_chrs_c & 0xF8):
547
+								// characters U-00010000 - U-001FFFFF, mask 11110XXX
548
+								// see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
549
+								$utf8 .= mb_substr($chrs, $c, 4);
550
+								$c    += 3;
551
+								break;
552
+							case 0xF8 == ($ord_chrs_c & 0xFC):
553
+								// characters U-00200000 - U-03FFFFFF, mask 111110XX
554
+								// see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
555
+								$utf8 .= mb_substr($chrs, $c, 5);
556
+								$c    += 4;
557
+								break;
558
+							case 0xFC == ($ord_chrs_c & 0xFE):
559
+								// characters U-04000000 - U-7FFFFFFF, mask 1111110X
560
+								// see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
561
+								$utf8 .= mb_substr($chrs, $c, 6);
562
+								$c    += 5;
563
+								break;
564
+						}
565
+					}
566
+
567
+					return $utf8;
568
+				}
569
+
570
+				if (preg_match('/^\[.*\]$/s', $str) || preg_match('/^\{.*\}$/s', $str)) {
571
+					// array, or object notation
572
+
573
+					if ('[' === $str[0]) {
574
+						$stk = [SERVICES_JSON_IN_ARR];
575
+						$arr = [];
576
+					} elseif ($this->use & SERVICES_JSON_LOOSE_TYPE) {
577
+							$stk = [SERVICES_JSON_IN_OBJ];
578
+							$obj = [];
579
+						} else {
580
+							$stk = [SERVICES_JSON_IN_OBJ];
581
+							$obj = new stdClass();
582
+					}
583
+
584
+					array_push(
585
+						$stk,
586
+						[
587
+							'what'  => SERVICES_JSON_SLICE,
588
+							'where' => 0,
589
+							'delim' => false,
590
+						]
591
+					);
592
+
593
+					$chrs = mb_substr($str, 1, -1);
594
+					$chrs = $this->reduce_string($chrs);
595
+
596
+					if ('' == $chrs) {
597
+						if (SERVICES_JSON_IN_ARR == reset($stk)) {
598
+							return $arr;
599
+						}
600
+
601
+						return $obj;
602
+					}
603
+
604
+					//print("\nparsing {$chrs}\n");
605
+
606
+					$strlen_chrs = mb_strlen($chrs);
607
+
608
+					for ($c = 0; $c <= $strlen_chrs; ++$c) {
609
+						$top             = end($stk);
610
+						$substr_chrs_c_2 = mb_substr($chrs, $c, 2);
611
+
612
+						if (($c == $strlen_chrs) || ((',' === $chrs[$c]) && (SERVICES_JSON_SLICE == $top['what']))) {
613
+							// found a comma that is not inside a string, array, etc.,
614
+							// OR we've reached the end of the character list
615
+							$slice = mb_substr($chrs, $top['where'], $c - $top['where']);
616
+							array_push($stk, ['what' => SERVICES_JSON_SLICE, 'where' => $c + 1, 'delim' => false]);
617
+							//print("Found split at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
618
+
619
+							if (SERVICES_JSON_IN_ARR == reset($stk)) {
620
+								// we are in an array, so just push an element onto the stack
621
+								$arr[] = $this->decode($slice);
622
+							} elseif (SERVICES_JSON_IN_OBJ == reset($stk)) {
623
+								// we are in an object, so figure
624
+								// out the property name and set an
625
+								// element in an associative array,
626
+								// for now
627
+								$parts = [];
628
+
629
+								if (preg_match('/^\s*(["\'].*[^\\\]["\'])\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
630
+									// "name":value pair
631
+									$key = $this->decode($parts[1]);
632
+									$val = $this->decode($parts[2]);
633
+
634
+									if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
635
+										$obj[$key] = $val;
636
+									} else {
637
+										$obj->$key = $val;
638
+									}
639
+								} elseif (preg_match('/^\s*(\w+)\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
640
+									// name:value pair, where name is unquoted
641
+									$key = $parts[1];
642
+									$val = $this->decode($parts[2]);
643
+
644
+									if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
645
+										$obj[$key] = $val;
646
+									} else {
647
+										$obj->$key = $val;
648
+									}
649
+								}
650
+							}
651
+						} elseif ((('"' === $chrs[$c]) || ("'" === $chrs[$c])) && (SERVICES_JSON_IN_STR != $top['what'])) {
652
+							// found a quote, and we are not inside a string
653
+							array_push($stk, ['what' => SERVICES_JSON_IN_STR, 'where' => $c, 'delim' => $chrs[$c]]);
654
+							//print("Found start of string at {$c}\n");
655
+						} elseif (($chrs[$c] == $top['delim'])
656
+								  && (SERVICES_JSON_IN_STR == $top['what'])
657
+								  && (1 != (mb_strlen(mb_substr($chrs, 0, $c)) - mb_strlen(rtrim(mb_substr($chrs, 0, $c), '\\'))) % 2)) {
658
+							// found a quote, we're in a string, and it's not escaped
659
+							// we know that it's not escaped becase there is _not_ an
660
+							// odd number of backslashes at the end of the string so far
661
+							array_pop($stk);
662
+							//print("Found end of string at {$c}: ".substr($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n");
663
+						} elseif (('[' === $chrs[$c])
664
+								  && in_array($top['what'], [SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ], true)) {
665
+							// found a left-bracket, and we are in an array, object, or slice
666
+							array_push($stk, ['what' => SERVICES_JSON_IN_ARR, 'where' => $c, 'delim' => false]);
667
+							//print("Found start of array at {$c}\n");
668
+						} elseif ((']' === $chrs[$c]) && (SERVICES_JSON_IN_ARR == $top['what'])) {
669
+							// found a right-bracket, and we're in an array
670
+							array_pop($stk);
671
+							//print("Found end of array at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
672
+						} elseif (('{' === $chrs[$c])
673
+								  && in_array($top['what'], [SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ], true)) {
674
+							// found a left-brace, and we are in an array, object, or slice
675
+							array_push($stk, ['what' => SERVICES_JSON_IN_OBJ, 'where' => $c, 'delim' => false]);
676
+							//print("Found start of object at {$c}\n");
677
+						} elseif (('}' === $chrs[$c]) && (SERVICES_JSON_IN_OBJ == $top['what'])) {
678
+							// found a right-brace, and we're in an object
679
+							array_pop($stk);
680
+							//print("Found end of object at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
681
+						} elseif (('/*' === $substr_chrs_c_2)
682
+								  && in_array($top['what'], [SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ], true)) {
683
+							// found a comment start, and we are in an array, object, or slice
684
+							array_push($stk, ['what' => SERVICES_JSON_IN_CMT, 'where' => $c, 'delim' => false]);
685
+							++$c;
686
+							//print("Found start of comment at {$c}\n");
687
+						} elseif (('*/' === $substr_chrs_c_2) && (SERVICES_JSON_IN_CMT == $top['what'])) {
688
+							// found a comment end, and we're in one now
689
+							array_pop($stk);
690
+							++$c;
691
+
692
+							for ($i = $top['where']; $i <= $c; ++$i) {
693
+								$chrs = substr_replace($chrs, ' ', $i, 1);
694
+							}
695
+							//print("Found end of comment at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
696
+						}
697
+					}
698
+
699
+					if (SERVICES_JSON_IN_ARR == reset($stk)) {
700
+						return $arr;
701
+					}
702
+
703
+					if (SERVICES_JSON_IN_OBJ == reset($stk)) {
704
+						return $obj;
705
+					}
706
+				}
707
+		}
708
+	}
709
+
710
+	/**
711
+	 * @param      $data
712
+	 * @param null $code
713
+	 * @return bool
714
+	 * @todo Ultimately, this should just call PEAR::isError()
715
+	 */
716
+	public function isError($data, $code = null): bool
717
+	{
718
+		if (class_exists('pear')) {
719
+			return PEAR::isError($data, $code);
720
+		}
721
+
722
+		if (is_object($data)
723
+			&& ($data instanceof \services_json_error
724
+				|| $data instanceof \services_json_error)) {
725
+			return true;
726
+		}
727
+
728
+		return false;
729
+	}
730 730
 }
731 731
 
732 732
 if (class_exists('PEAR_Error')) {
733
-    /**
734
-     * Class ServicesJSON_Error
735
-     */
736
-    class ServicesJSON_Error extends PEAR_Error
737
-    {
738
-        /**
739
-         * ServicesJSON_Error constructor.
740
-         * @param string $message
741
-         * @param null   $code
742
-         * @param null   $mode
743
-         * @param null   $options
744
-         * @param null   $userinfo
745
-         */
746
-        public function __construct(
747
-            $message = 'unknown error',
748
-            $code = null,
749
-            $mode = null,
750
-            $options = null,
751
-            $userinfo = null
752
-        ) {
753
-            parent::__construct($message, $code, $mode, $options, $userinfo);
754
-        }
755
-    }
733
+	/**
734
+	 * Class ServicesJSON_Error
735
+	 */
736
+	class ServicesJSON_Error extends PEAR_Error
737
+	{
738
+		/**
739
+		 * ServicesJSON_Error constructor.
740
+		 * @param string $message
741
+		 * @param null   $code
742
+		 * @param null   $mode
743
+		 * @param null   $options
744
+		 * @param null   $userinfo
745
+		 */
746
+		public function __construct(
747
+			$message = 'unknown error',
748
+			$code = null,
749
+			$mode = null,
750
+			$options = null,
751
+			$userinfo = null
752
+		) {
753
+			parent::__construct($message, $code, $mode, $options, $userinfo);
754
+		}
755
+	}
756 756
 } else {
757
-    /**
758
-     * @todo Ultimately, this class shall be descended from PEAR_Error
759
-     */
760
-    class ServicesJSON_Error
761
-    {
762
-        /**
763
-         * ServicesJSON_Error constructor.
764
-         * @param string $message
765
-         * @param null   $code
766
-         * @param null   $mode
767
-         * @param null   $options
768
-         * @param null   $userinfo
769
-         */
770
-        public function __construct(
771
-            $message = 'unknown error',
772
-            $code = null,
773
-            $mode = null,
774
-            $options = null,
775
-            $userinfo = null
776
-        ) {
777
-        }
778
-    }
757
+	/**
758
+	 * @todo Ultimately, this class shall be descended from PEAR_Error
759
+	 */
760
+	class ServicesJSON_Error
761
+	{
762
+		/**
763
+		 * ServicesJSON_Error constructor.
764
+		 * @param string $message
765
+		 * @param null   $code
766
+		 * @param null   $mode
767
+		 * @param null   $options
768
+		 * @param null   $userinfo
769
+		 */
770
+		public function __construct(
771
+			$message = 'unknown error',
772
+			$code = null,
773
+			$mode = null,
774
+			$options = null,
775
+			$userinfo = null
776
+		) {
777
+		}
778
+	}
779 779
 }
Please login to merge, or discard this patch.
Spacing   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -117,18 +117,18 @@  discard block
 block discarded – undo
117 117
         $bytes = (ord($utf16[0]) << 8) | ord($utf16[1]);
118 118
 
119 119
         switch (true) {
120
-            case ((0x7F & $bytes) == $bytes):
120
+            case ((0x7F & $bytes)==$bytes):
121 121
                 // this case should never be reached, because we are in ASCII range
122 122
                 // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
123 123
                 return chr(0x7F & $bytes);
124
-            case (0x07FF & $bytes) == $bytes:
124
+            case (0x07FF & $bytes)==$bytes:
125 125
                 // return a 2-byte UTF-8 character
126 126
                 // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
127
-                return chr(0xC0 | (($bytes >> 6) & 0x1F)) . chr(0x80 | ($bytes & 0x3F));
128
-            case (0xFFFF & $bytes) == $bytes:
127
+                return chr(0xC0 | (($bytes >> 6) & 0x1F)).chr(0x80 | ($bytes & 0x3F));
128
+            case (0xFFFF & $bytes)==$bytes:
129 129
                 // return a 3-byte UTF-8 character
130 130
                 // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
131
-                return chr(0xE0 | (($bytes >> 12) & 0x0F)) . chr(0x80 | (($bytes >> 6) & 0x3F)) . chr(0x80 | ($bytes & 0x3F));
131
+                return chr(0xE0 | (($bytes >> 12) & 0x0F)).chr(0x80 | (($bytes >> 6) & 0x3F)).chr(0x80 | ($bytes & 0x3F));
132 132
         }
133 133
 
134 134
         // ignoring UTF-32 for now, sorry
@@ -160,11 +160,11 @@  discard block
 block discarded – undo
160 160
             case 2:
161 161
                 // return a UTF-16 character from a 2-byte UTF-8 char
162 162
                 // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
163
-                return chr(0x07 & (ord($utf8[0]) >> 2)) . chr((0xC0 & (ord($utf8[0]) << 6)) | (0x3F & ord($utf8[1])));
163
+                return chr(0x07 & (ord($utf8[0]) >> 2)).chr((0xC0 & (ord($utf8[0]) << 6)) | (0x3F & ord($utf8[1])));
164 164
             case 3:
165 165
                 // return a UTF-16 character from a 3-byte UTF-8 char
166 166
                 // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
167
-                return chr((0xF0 & (ord($utf8[0]) << 4)) | (0x0F & (ord($utf8[1]) >> 2))) . chr((0xC0 & (ord($utf8[1]) << 6)) | (0x7F & ord($utf8[2])));
167
+                return chr((0xF0 & (ord($utf8[0]) << 4)) | (0x0F & (ord($utf8[1]) >> 2))).chr((0xC0 & (ord($utf8[1]) << 6)) | (0x7F & ord($utf8[2])));
168 168
         }
169 169
 
170 170
         // ignoring UTF-32 for now, sorry
@@ -227,10 +227,10 @@  discard block
 block discarded – undo
227 227
             case 'NULL':
228 228
                 return 'null';
229 229
             case 'integer':
230
-                return (int)$var;
230
+                return (int) $var;
231 231
             case 'double':
232 232
             case 'float':
233
-                return (float)$var;
233
+                return (float) $var;
234 234
             case 'string':
235 235
                 // STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT
236 236
                 $ascii      = '';
@@ -240,97 +240,97 @@  discard block
 block discarded – undo
240 240
                  * Iterate over every character in the string,
241 241
                  * escaping with a slash or encoding to UTF-8 where necessary
242 242
                  */
243
-                for ($c = 0; $c < $strlen_var; ++$c) {
243
+                for ($c = 0; $c<$strlen_var; ++$c) {
244 244
                     $ord_var_c = ord($var[$c]);
245 245
 
246 246
                     switch (true) {
247
-                        case 0x08 == $ord_var_c:
247
+                        case 0x08==$ord_var_c:
248 248
                             $ascii .= '\b';
249 249
                             break;
250
-                        case 0x09 == $ord_var_c:
250
+                        case 0x09==$ord_var_c:
251 251
                             $ascii .= '\t';
252 252
                             break;
253
-                        case 0x0A == $ord_var_c:
253
+                        case 0x0A==$ord_var_c:
254 254
                             $ascii .= '\n';
255 255
                             break;
256
-                        case 0x0C == $ord_var_c:
256
+                        case 0x0C==$ord_var_c:
257 257
                             $ascii .= '\f';
258 258
                             break;
259
-                        case 0x0D == $ord_var_c:
259
+                        case 0x0D==$ord_var_c:
260 260
                             $ascii .= '\r';
261 261
                             break;
262
-                        case 0x22 == $ord_var_c:
263
-                        case 0x2F == $ord_var_c:
264
-                        case 0x5C == $ord_var_c:
262
+                        case 0x22==$ord_var_c:
263
+                        case 0x2F==$ord_var_c:
264
+                        case 0x5C==$ord_var_c:
265 265
                             // double quote, slash, slosh
266
-                            $ascii .= '\\' . $var[$c];
266
+                            $ascii .= '\\'.$var[$c];
267 267
                             break;
268
-                        case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)):
268
+                        case (($ord_var_c>=0x20) && ($ord_var_c<=0x7F)):
269 269
                             // characters U-00000000 - U-0000007F (same as ASCII)
270 270
                             $ascii .= $var[$c];
271 271
                             break;
272
-                        case (0xC0 == ($ord_var_c & 0xE0)):
272
+                        case (0xC0==($ord_var_c & 0xE0)):
273 273
                             // characters U-00000080 - U-000007FF, mask 110SONGLIST
274 274
                             // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
275
-                            if ($c + 1 >= $strlen_var) {
275
+                            if ($c+1>=$strlen_var) {
276 276
                                 ++$c;
277 277
                                 $ascii .= '?';
278 278
                                 break;
279 279
                             }
280 280
 
281
-                            $char = pack('C*', $ord_var_c, ord($var[$c + 1]));
281
+                            $char = pack('C*', $ord_var_c, ord($var[$c+1]));
282 282
                             ++$c;
283 283
                             $utf16 = $this->utf82utf16($char);
284 284
                             $ascii .= sprintf('\u%04s', bin2hex($utf16));
285 285
                             break;
286
-                        case (0xE0 == ($ord_var_c & 0xF0)):
287
-                            if ($c + 2 >= $strlen_var) {
286
+                        case (0xE0==($ord_var_c & 0xF0)):
287
+                            if ($c+2>=$strlen_var) {
288 288
                                 $c     += 2;
289 289
                                 $ascii .= '?';
290 290
                                 break;
291 291
                             }
292 292
                             // characters U-00000800 - U-0000FFFF, mask 1110XXXX
293 293
                             // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
294
-                            $char  = pack('C*', $ord_var_c, @ord($var[$c + 1]), @ord($var[$c + 2]));
294
+                            $char  = pack('C*', $ord_var_c, @ord($var[$c+1]), @ord($var[$c+2]));
295 295
                             $c     += 2;
296 296
                             $utf16 = $this->utf82utf16($char);
297 297
                             $ascii .= sprintf('\u%04s', bin2hex($utf16));
298 298
                             break;
299
-                        case (0xF0 == ($ord_var_c & 0xF8)):
300
-                            if ($c + 3 >= $strlen_var) {
299
+                        case (0xF0==($ord_var_c & 0xF8)):
300
+                            if ($c+3>=$strlen_var) {
301 301
                                 $c     += 3;
302 302
                                 $ascii .= '?';
303 303
                                 break;
304 304
                             }
305 305
                             // characters U-00010000 - U-001FFFFF, mask 11110XXX
306 306
                             // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
307
-                            $char  = pack('C*', $ord_var_c, ord($var[$c + 1]), ord($var[$c + 2]), ord($var[$c + 3]));
307
+                            $char  = pack('C*', $ord_var_c, ord($var[$c+1]), ord($var[$c+2]), ord($var[$c+3]));
308 308
                             $c     += 3;
309 309
                             $utf16 = $this->utf82utf16($char);
310 310
                             $ascii .= sprintf('\u%04s', bin2hex($utf16));
311 311
                             break;
312
-                        case (0xF8 == ($ord_var_c & 0xFC)):
312
+                        case (0xF8==($ord_var_c & 0xFC)):
313 313
                             // characters U-00200000 - U-03FFFFFF, mask 111110XX
314 314
                             // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
315
-                            if ($c + 4 >= $strlen_var) {
315
+                            if ($c+4>=$strlen_var) {
316 316
                                 $c     += 4;
317 317
                                 $ascii .= '?';
318 318
                                 break;
319 319
                             }
320
-                            $char  = pack('C*', $ord_var_c, ord($var[$c + 1]), ord($var[$c + 2]), ord($var[$c + 3]), ord($var[$c + 4]));
320
+                            $char  = pack('C*', $ord_var_c, ord($var[$c+1]), ord($var[$c+2]), ord($var[$c+3]), ord($var[$c+4]));
321 321
                             $c     += 4;
322 322
                             $utf16 = $this->utf82utf16($char);
323 323
                             $ascii .= sprintf('\u%04s', bin2hex($utf16));
324 324
                             break;
325
-                        case (0xFC == ($ord_var_c & 0xFE)):
326
-                            if ($c + 5 >= $strlen_var) {
325
+                        case (0xFC==($ord_var_c & 0xFE)):
326
+                            if ($c+5>=$strlen_var) {
327 327
                                 $c     += 5;
328 328
                                 $ascii .= '?';
329 329
                                 break;
330 330
                             }
331 331
                             // characters U-04000000 - U-7FFFFFFF, mask 1111110X
332 332
                             // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
333
-                            $char  = pack('C*', $ord_var_c, ord($var[$c + 1]), ord($var[$c + 2]), ord($var[$c + 3]), ord($var[$c + 4]), ord($var[$c + 5]));
333
+                            $char  = pack('C*', $ord_var_c, ord($var[$c+1]), ord($var[$c+2]), ord($var[$c+3]), ord($var[$c+4]), ord($var[$c+5]));
334 334
                             $c     += 5;
335 335
                             $utf16 = $this->utf82utf16($char);
336 336
                             $ascii .= sprintf('\u%04s', bin2hex($utf16));
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
                     }
339 339
                 }
340 340
 
341
-                return '"' . $ascii . '"';
341
+                return '"'.$ascii.'"';
342 342
             case 'array':
343 343
                 /*
344 344
                  * As per JSON spec if any array key is not an integer
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
                  */
360 360
 
361 361
                 // treat as a JSON object
362
-                if (is_array($var) && count($var) && (array_keys($var) !== range(0, count($var) - 1))) {
362
+                if (is_array($var) && count($var) && (array_keys($var)!==range(0, count($var)-1))) {
363 363
                     $properties = array_map([$this, 'name_value'], array_keys($var), array_values($var));
364 364
 
365 365
                     foreach ($properties as $property) {
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
                         }
369 369
                     }
370 370
 
371
-                    return '{' . implode(',', $properties) . '}';
371
+                    return '{'.implode(',', $properties).'}';
372 372
                 }
373 373
 
374 374
                 // treat it like a regular array
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
                     }
381 381
                 }
382 382
 
383
-                return '[' . implode(',', $elements) . ']';
383
+                return '['.implode(',', $elements).']';
384 384
             case 'object':
385 385
                 $vars = get_object_vars($var);
386 386
 
@@ -392,9 +392,9 @@  discard block
 block discarded – undo
392 392
                     }
393 393
                 }
394 394
 
395
-                return '{' . implode(',', $properties) . '}';
395
+                return '{'.implode(',', $properties).'}';
396 396
             default:
397
-                return ($this->use & SERVICES_JSON_SUPPRESS_ERRORS) ? 'null' : new ServicesJSON_Error(gettype($var) . ' can not be encoded as JSON string');
397
+                return ($this->use & SERVICES_JSON_SUPPRESS_ERRORS) ? 'null' : new ServicesJSON_Error(gettype($var).' can not be encoded as JSON string');
398 398
         }
399 399
     }
400 400
 
@@ -414,7 +414,7 @@  discard block
 block discarded – undo
414 414
             return $encoded_value;
415 415
         }
416 416
 
417
-        return $this->_encode((string)$name) . ':' . $encoded_value;
417
+        return $this->_encode((string) $name).':'.$encoded_value;
418 418
     }
419 419
 
420 420
     /**
@@ -478,84 +478,84 @@  discard block
 block discarded – undo
478 478
                     // return (float)$str;
479 479
 
480 480
                     // Return float or int, as appropriate
481
-                    return ((float)$str == (int)$str) ? (int)$str : (float)$str;
481
+                    return ((float) $str==(int) $str) ? (int) $str : (float) $str;
482 482
                 }
483 483
 
484
-                if (preg_match('/^("|\').*(\1)$/s', $str, $m) && $m[1] == $m[2]) {
484
+                if (preg_match('/^("|\').*(\1)$/s', $str, $m) && $m[1]==$m[2]) {
485 485
                     // STRINGS RETURNED IN UTF-8 FORMAT
486 486
                     $delim       = mb_substr($str, 0, 1);
487 487
                     $chrs        = mb_substr($str, 1, -1);
488 488
                     $utf8        = '';
489 489
                     $strlen_chrs = mb_strlen($chrs);
490 490
 
491
-                    for ($c = 0; $c < $strlen_chrs; ++$c) {
491
+                    for ($c = 0; $c<$strlen_chrs; ++$c) {
492 492
                         $substr_chrs_c_2 = mb_substr($chrs, $c, 2);
493 493
                         $ord_chrs_c      = ord($chrs[$c]);
494 494
 
495 495
                         switch (true) {
496
-                            case '\b' === $substr_chrs_c_2:
496
+                            case '\b'===$substr_chrs_c_2:
497 497
                                 $utf8 .= chr(0x08);
498 498
                                 ++$c;
499 499
                                 break;
500
-                            case '\t' === $substr_chrs_c_2:
500
+                            case '\t'===$substr_chrs_c_2:
501 501
                                 $utf8 .= chr(0x09);
502 502
                                 ++$c;
503 503
                                 break;
504
-                            case '\n' === $substr_chrs_c_2:
504
+                            case '\n'===$substr_chrs_c_2:
505 505
                                 $utf8 .= chr(0x0A);
506 506
                                 ++$c;
507 507
                                 break;
508
-                            case '\f' === $substr_chrs_c_2:
508
+                            case '\f'===$substr_chrs_c_2:
509 509
                                 $utf8 .= chr(0x0C);
510 510
                                 ++$c;
511 511
                                 break;
512
-                            case '\r' === $substr_chrs_c_2:
512
+                            case '\r'===$substr_chrs_c_2:
513 513
                                 $utf8 .= chr(0x0D);
514 514
                                 ++$c;
515 515
                                 break;
516
-                            case '\\"' === $substr_chrs_c_2:
517
-                            case '\\\'' === $substr_chrs_c_2:
518
-                            case '\\\\' === $substr_chrs_c_2:
519
-                            case '\\/' === $substr_chrs_c_2:
520
-                                if (('"' === $delim && '\\\'' !== $substr_chrs_c_2)
521
-                                    || ("'" === $delim && '\\"' !== $substr_chrs_c_2)) {
516
+                            case '\\"'===$substr_chrs_c_2:
517
+                            case '\\\''===$substr_chrs_c_2:
518
+                            case '\\\\'===$substr_chrs_c_2:
519
+                            case '\\/'===$substr_chrs_c_2:
520
+                                if (('"'===$delim && '\\\''!==$substr_chrs_c_2)
521
+                                    || ("'"===$delim && '\\"'!==$substr_chrs_c_2)) {
522 522
                                     $utf8 .= $chrs[++$c];
523 523
                                 }
524 524
                                 break;
525 525
                             case preg_match('/\\\u[0-9A-F]{4}/i', mb_substr($chrs, $c, 6)):
526 526
                                 // single, escaped unicode character
527
-                                $utf16 = chr(hexdec(mb_substr($chrs, $c + 2, 2))) . chr(hexdec(mb_substr($chrs, $c + 4, 2)));
527
+                                $utf16 = chr(hexdec(mb_substr($chrs, $c+2, 2))).chr(hexdec(mb_substr($chrs, $c+4, 2)));
528 528
                                 $utf8  .= $this->utf162utf8($utf16);
529 529
                                 $c     += 5;
530 530
                                 break;
531
-                            case ($ord_chrs_c >= 0x20) && ($ord_chrs_c <= 0x7F):
531
+                            case ($ord_chrs_c>=0x20) && ($ord_chrs_c<=0x7F):
532 532
                                 $utf8 .= $chrs[$c];
533 533
                                 break;
534
-                            case 0xC0 == ($ord_chrs_c & 0xE0):
534
+                            case 0xC0==($ord_chrs_c & 0xE0):
535 535
                                 // characters U-00000080 - U-000007FF, mask 110SONGLIST
536 536
                                 //see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
537 537
                                 $utf8 .= mb_substr($chrs, $c, 2);
538 538
                                 ++$c;
539 539
                                 break;
540
-                            case 0xE0 == ($ord_chrs_c & 0xF0):
540
+                            case 0xE0==($ord_chrs_c & 0xF0):
541 541
                                 // characters U-00000800 - U-0000FFFF, mask 1110XXXX
542 542
                                 // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
543 543
                                 $utf8 .= mb_substr($chrs, $c, 3);
544 544
                                 $c    += 2;
545 545
                                 break;
546
-                            case 0xF0 == ($ord_chrs_c & 0xF8):
546
+                            case 0xF0==($ord_chrs_c & 0xF8):
547 547
                                 // characters U-00010000 - U-001FFFFF, mask 11110XXX
548 548
                                 // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
549 549
                                 $utf8 .= mb_substr($chrs, $c, 4);
550 550
                                 $c    += 3;
551 551
                                 break;
552
-                            case 0xF8 == ($ord_chrs_c & 0xFC):
552
+                            case 0xF8==($ord_chrs_c & 0xFC):
553 553
                                 // characters U-00200000 - U-03FFFFFF, mask 111110XX
554 554
                                 // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
555 555
                                 $utf8 .= mb_substr($chrs, $c, 5);
556 556
                                 $c    += 4;
557 557
                                 break;
558
-                            case 0xFC == ($ord_chrs_c & 0xFE):
558
+                            case 0xFC==($ord_chrs_c & 0xFE):
559 559
                                 // characters U-04000000 - U-7FFFFFFF, mask 1111110X
560 560
                                 // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
561 561
                                 $utf8 .= mb_substr($chrs, $c, 6);
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
                 if (preg_match('/^\[.*\]$/s', $str) || preg_match('/^\{.*\}$/s', $str)) {
571 571
                     // array, or object notation
572 572
 
573
-                    if ('[' === $str[0]) {
573
+                    if ('['===$str[0]) {
574 574
                         $stk = [SERVICES_JSON_IN_ARR];
575 575
                         $arr = [];
576 576
                     } elseif ($this->use & SERVICES_JSON_LOOSE_TYPE) {
@@ -593,8 +593,8 @@  discard block
 block discarded – undo
593 593
                     $chrs = mb_substr($str, 1, -1);
594 594
                     $chrs = $this->reduce_string($chrs);
595 595
 
596
-                    if ('' == $chrs) {
597
-                        if (SERVICES_JSON_IN_ARR == reset($stk)) {
596
+                    if (''==$chrs) {
597
+                        if (SERVICES_JSON_IN_ARR==reset($stk)) {
598 598
                             return $arr;
599 599
                         }
600 600
 
@@ -605,21 +605,21 @@  discard block
 block discarded – undo
605 605
 
606 606
                     $strlen_chrs = mb_strlen($chrs);
607 607
 
608
-                    for ($c = 0; $c <= $strlen_chrs; ++$c) {
608
+                    for ($c = 0; $c<=$strlen_chrs; ++$c) {
609 609
                         $top             = end($stk);
610 610
                         $substr_chrs_c_2 = mb_substr($chrs, $c, 2);
611 611
 
612
-                        if (($c == $strlen_chrs) || ((',' === $chrs[$c]) && (SERVICES_JSON_SLICE == $top['what']))) {
612
+                        if (($c==$strlen_chrs) || ((','===$chrs[$c]) && (SERVICES_JSON_SLICE==$top['what']))) {
613 613
                             // found a comma that is not inside a string, array, etc.,
614 614
                             // OR we've reached the end of the character list
615
-                            $slice = mb_substr($chrs, $top['where'], $c - $top['where']);
616
-                            array_push($stk, ['what' => SERVICES_JSON_SLICE, 'where' => $c + 1, 'delim' => false]);
615
+                            $slice = mb_substr($chrs, $top['where'], $c-$top['where']);
616
+                            array_push($stk, ['what' => SERVICES_JSON_SLICE, 'where' => $c+1, 'delim' => false]);
617 617
                             //print("Found split at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
618 618
 
619
-                            if (SERVICES_JSON_IN_ARR == reset($stk)) {
619
+                            if (SERVICES_JSON_IN_ARR==reset($stk)) {
620 620
                                 // we are in an array, so just push an element onto the stack
621 621
                                 $arr[] = $this->decode($slice);
622
-                            } elseif (SERVICES_JSON_IN_OBJ == reset($stk)) {
622
+                            } elseif (SERVICES_JSON_IN_OBJ==reset($stk)) {
623 623
                                 // we are in an object, so figure
624 624
                                 // out the property name and set an
625 625
                                 // element in an associative array,
@@ -648,59 +648,59 @@  discard block
 block discarded – undo
648 648
                                     }
649 649
                                 }
650 650
                             }
651
-                        } elseif ((('"' === $chrs[$c]) || ("'" === $chrs[$c])) && (SERVICES_JSON_IN_STR != $top['what'])) {
651
+                        } elseif ((('"'===$chrs[$c]) || ("'"===$chrs[$c])) && (SERVICES_JSON_IN_STR!=$top['what'])) {
652 652
                             // found a quote, and we are not inside a string
653 653
                             array_push($stk, ['what' => SERVICES_JSON_IN_STR, 'where' => $c, 'delim' => $chrs[$c]]);
654 654
                             //print("Found start of string at {$c}\n");
655
-                        } elseif (($chrs[$c] == $top['delim'])
656
-                                  && (SERVICES_JSON_IN_STR == $top['what'])
657
-                                  && (1 != (mb_strlen(mb_substr($chrs, 0, $c)) - mb_strlen(rtrim(mb_substr($chrs, 0, $c), '\\'))) % 2)) {
655
+                        } elseif (($chrs[$c]==$top['delim'])
656
+                                  && (SERVICES_JSON_IN_STR==$top['what'])
657
+                                  && (1!=(mb_strlen(mb_substr($chrs, 0, $c))-mb_strlen(rtrim(mb_substr($chrs, 0, $c), '\\')))%2)) {
658 658
                             // found a quote, we're in a string, and it's not escaped
659 659
                             // we know that it's not escaped becase there is _not_ an
660 660
                             // odd number of backslashes at the end of the string so far
661 661
                             array_pop($stk);
662 662
                             //print("Found end of string at {$c}: ".substr($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n");
663
-                        } elseif (('[' === $chrs[$c])
663
+                        } elseif (('['===$chrs[$c])
664 664
                                   && in_array($top['what'], [SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ], true)) {
665 665
                             // found a left-bracket, and we are in an array, object, or slice
666 666
                             array_push($stk, ['what' => SERVICES_JSON_IN_ARR, 'where' => $c, 'delim' => false]);
667 667
                             //print("Found start of array at {$c}\n");
668
-                        } elseif ((']' === $chrs[$c]) && (SERVICES_JSON_IN_ARR == $top['what'])) {
668
+                        } elseif ((']'===$chrs[$c]) && (SERVICES_JSON_IN_ARR==$top['what'])) {
669 669
                             // found a right-bracket, and we're in an array
670 670
                             array_pop($stk);
671 671
                             //print("Found end of array at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
672
-                        } elseif (('{' === $chrs[$c])
672
+                        } elseif (('{'===$chrs[$c])
673 673
                                   && in_array($top['what'], [SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ], true)) {
674 674
                             // found a left-brace, and we are in an array, object, or slice
675 675
                             array_push($stk, ['what' => SERVICES_JSON_IN_OBJ, 'where' => $c, 'delim' => false]);
676 676
                             //print("Found start of object at {$c}\n");
677
-                        } elseif (('}' === $chrs[$c]) && (SERVICES_JSON_IN_OBJ == $top['what'])) {
677
+                        } elseif (('}'===$chrs[$c]) && (SERVICES_JSON_IN_OBJ==$top['what'])) {
678 678
                             // found a right-brace, and we're in an object
679 679
                             array_pop($stk);
680 680
                             //print("Found end of object at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
681
-                        } elseif (('/*' === $substr_chrs_c_2)
681
+                        } elseif (('/*'===$substr_chrs_c_2)
682 682
                                   && in_array($top['what'], [SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ], true)) {
683 683
                             // found a comment start, and we are in an array, object, or slice
684 684
                             array_push($stk, ['what' => SERVICES_JSON_IN_CMT, 'where' => $c, 'delim' => false]);
685 685
                             ++$c;
686 686
                             //print("Found start of comment at {$c}\n");
687
-                        } elseif (('*/' === $substr_chrs_c_2) && (SERVICES_JSON_IN_CMT == $top['what'])) {
687
+                        } elseif (('*/'===$substr_chrs_c_2) && (SERVICES_JSON_IN_CMT==$top['what'])) {
688 688
                             // found a comment end, and we're in one now
689 689
                             array_pop($stk);
690 690
                             ++$c;
691 691
 
692
-                            for ($i = $top['where']; $i <= $c; ++$i) {
692
+                            for ($i = $top['where']; $i<=$c; ++$i) {
693 693
                                 $chrs = substr_replace($chrs, ' ', $i, 1);
694 694
                             }
695 695
                             //print("Found end of comment at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
696 696
                         }
697 697
                     }
698 698
 
699
-                    if (SERVICES_JSON_IN_ARR == reset($stk)) {
699
+                    if (SERVICES_JSON_IN_ARR==reset($stk)) {
700 700
                         return $arr;
701 701
                     }
702 702
 
703
-                    if (SERVICES_JSON_IN_OBJ == reset($stk)) {
703
+                    if (SERVICES_JSON_IN_OBJ==reset($stk)) {
704 704
                         return $obj;
705 705
                     }
706 706
                 }
Please login to merge, or discard this patch.