@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | /** |
198 | 198 | * @param $val |
199 | 199 | * @param $separator |
200 | - * @param $trimFunction |
|
200 | + * @param false|string $trimFunction |
|
201 | 201 | * @return mixed|string |
202 | 202 | */ |
203 | 203 | public function valToCsvHelper($val, $separator, $trimFunction) |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | } |
249 | 249 | |
250 | 250 | /** |
251 | - * @param $content |
|
251 | + * @param string $content |
|
252 | 252 | */ |
253 | 253 | public function saveExportFile($content) |
254 | 254 | { |
@@ -41,186 +41,186 @@ |
||
41 | 41 | */ |
42 | 42 | class ExportRenderer |
43 | 43 | { |
44 | - public $data; |
|
45 | - public $format; |
|
46 | - public $filename; |
|
47 | - public $filepath; |
|
48 | - public $options; |
|
49 | - |
|
50 | - /** |
|
51 | - * Constructor |
|
52 | - * |
|
53 | - * @param array $data contains the data to be exported |
|
54 | - * @param bool|string $filename name of the file in which the exported data will be saved |
|
55 | - * @param bool|string $filepath path where the file will be saved |
|
56 | - * @param string $format format of the ouputed export. Currently only supports CSV |
|
57 | - * @param array $options options of the format to be exported in |
|
58 | - */ |
|
59 | - public function __construct( |
|
60 | - $data, |
|
61 | - $filename = false, |
|
62 | - $filepath = false, |
|
63 | - $format = 'csv', |
|
64 | - $options = ['separator' => ';'] |
|
65 | - ) { |
|
66 | - $this->data = $data; |
|
67 | - $this->format = $format; |
|
68 | - $this->filename = $filename; |
|
69 | - $this->filepath = $filepath; |
|
70 | - $this->options = $options; |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * @param $dataArray |
|
75 | - * @param $separator |
|
76 | - * @param string $trim |
|
77 | - * @param bool $removeEmptyLines |
|
78 | - * @return string |
|
79 | - */ |
|
80 | - public function arrayToCsvString($dataArray, $separator, $trim = 'both', $removeEmptyLines = true) |
|
81 | - { |
|
82 | - if (!is_array($dataArray) || empty($dataArray)) { |
|
83 | - return ''; |
|
84 | - } |
|
85 | - switch ($trim) { |
|
86 | - case 'none': |
|
87 | - $trimFunction = false; |
|
88 | - break; |
|
89 | - case 'left': |
|
90 | - $trimFunction = 'ltrim'; |
|
91 | - break; |
|
92 | - case 'right': |
|
93 | - $trimFunction = 'rtrim'; |
|
94 | - break; |
|
95 | - default: //'both': |
|
96 | - $trimFunction = 'trim'; |
|
97 | - break; |
|
98 | - } |
|
99 | - $ret = []; |
|
100 | - foreach ($dataArray as $key => $field) { |
|
101 | - $ret[$key] = $this->valToCsvHelper($field, $separator, $trimFunction); |
|
102 | - } |
|
103 | - |
|
104 | - return implode($separator, $ret); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * @param $val |
|
109 | - * @param $separator |
|
110 | - * @param $trimFunction |
|
111 | - * @return mixed|string |
|
112 | - */ |
|
113 | - public function valToCsvHelper($val, $separator, $trimFunction) |
|
114 | - { |
|
115 | - if ($trimFunction) { |
|
116 | - $val = $trimFunction($val); |
|
117 | - } |
|
118 | - //If there is a separator (;) or a quote (") or a linebreak in the string, we need to quote it. |
|
119 | - $needQuote = false; |
|
120 | - do { |
|
121 | - if (false !== strpos($val, '"')) { |
|
122 | - $val = str_replace('"', '""', $val); |
|
123 | - $needQuote = true; |
|
124 | - break; |
|
125 | - } |
|
126 | - if (false !== strpos($val, $separator)) { |
|
127 | - $needQuote = true; |
|
128 | - break; |
|
129 | - } |
|
130 | - if ((false !== strpos($val, "\n")) || (false !== strpos($val, "\r"))) { // \r is for mac |
|
131 | - $needQuote = true; |
|
132 | - break; |
|
133 | - } |
|
134 | - } while (false); |
|
135 | - if ($needQuote) { |
|
136 | - $val = '"' . $val . '"'; |
|
137 | - } |
|
138 | - |
|
139 | - return $val; |
|
140 | - } |
|
141 | - |
|
142 | - public function execute() |
|
143 | - { |
|
144 | - $exportFileData = ''; |
|
145 | - |
|
146 | - switch ($this->format) { |
|
147 | - case 'csv': |
|
148 | - $separator = isset($this->options['separator']) ? $this->options['separator'] : ';'; |
|
149 | - $firstRow = implode($separator, $this->data['columnsHeaders']); |
|
150 | - $exportFileData .= $firstRow . "\r\n"; |
|
151 | - |
|
152 | - foreach ($this->data['rows'] as $cols) { |
|
153 | - $exportFileData .= $this->arrayToCsvString($cols, $separator) . "\r\n"; |
|
154 | - } |
|
155 | - break; |
|
156 | - } |
|
157 | - $this->saveExportFile($exportFileData); |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * @param $content |
|
162 | - */ |
|
163 | - public function saveExportFile($content) |
|
164 | - { |
|
165 | - switch ($this->format) { |
|
166 | - case 'csv': |
|
167 | - $this->saveCsv($content); |
|
168 | - break; |
|
169 | - } |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * @param $content |
|
174 | - */ |
|
175 | - public function saveCsv($content) |
|
176 | - { |
|
177 | - if (!$this->filepath) { |
|
178 | - $this->filepath = XOOPS_UPLOAD_PATH . '/'; |
|
179 | - } |
|
180 | - if (!$this->filename) { |
|
181 | - $this->filename .= time(); |
|
182 | - $this->filename .= '.csv'; |
|
183 | - } |
|
184 | - |
|
185 | - $fullFileName = $this->filepath . $this->filename; |
|
186 | - |
|
187 | - if (!$handle = fopen($fullFileName, 'a+')) { |
|
188 | - trigger_error('Unable to open ' . $fullFileName, E_USER_WARNING); |
|
189 | - } elseif (false === fwrite($handle, $content)) { |
|
190 | - trigger_error('Unable to write in ' . $fullFileName, E_USER_WARNING); |
|
191 | - } else { |
|
192 | - $mimeType = 'text/csv'; |
|
193 | - $file = strrev($this->filename); |
|
194 | - $temp_name = strtolower(strrev(substr($file, 0, strpos($file, '--')))); |
|
195 | - if ('' === $temp_name) { |
|
196 | - $file_name = $this->filename; |
|
197 | - } else { |
|
198 | - $file_name = $temp_name; |
|
199 | - } |
|
200 | - $fullFileName = $this->filepath . stripslashes(trim($this->filename)); |
|
201 | - |
|
202 | - if (ini_get('zlib.output_compression')) { |
|
203 | - ini_set('zlib.output_compression', 'Off'); |
|
204 | - } |
|
205 | - |
|
206 | - header('Pragma: public'); |
|
207 | - header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
|
208 | - header('Cache-Control: private', false); |
|
209 | - header('Content-Transfer-Encoding: binary'); |
|
210 | - if (isset($mimeType)) { |
|
211 | - header('Content-Type: ' . $mimeType); |
|
212 | - } |
|
213 | - |
|
214 | - header('Content-Disposition: attachment; filename=' . $file_name); |
|
215 | - |
|
216 | - if (isset($mimeType) && false !== strpos($mimeType, 'text/')) { |
|
217 | - $fp = fopen($fullFileName, 'r'); |
|
218 | - } else { |
|
219 | - $fp = fopen($fullFileName, 'rb'); |
|
220 | - } |
|
221 | - fpassthru($fp); |
|
222 | - exit(); |
|
223 | - } |
|
224 | - fclose($handle); |
|
225 | - } |
|
44 | + public $data; |
|
45 | + public $format; |
|
46 | + public $filename; |
|
47 | + public $filepath; |
|
48 | + public $options; |
|
49 | + |
|
50 | + /** |
|
51 | + * Constructor |
|
52 | + * |
|
53 | + * @param array $data contains the data to be exported |
|
54 | + * @param bool|string $filename name of the file in which the exported data will be saved |
|
55 | + * @param bool|string $filepath path where the file will be saved |
|
56 | + * @param string $format format of the ouputed export. Currently only supports CSV |
|
57 | + * @param array $options options of the format to be exported in |
|
58 | + */ |
|
59 | + public function __construct( |
|
60 | + $data, |
|
61 | + $filename = false, |
|
62 | + $filepath = false, |
|
63 | + $format = 'csv', |
|
64 | + $options = ['separator' => ';'] |
|
65 | + ) { |
|
66 | + $this->data = $data; |
|
67 | + $this->format = $format; |
|
68 | + $this->filename = $filename; |
|
69 | + $this->filepath = $filepath; |
|
70 | + $this->options = $options; |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * @param $dataArray |
|
75 | + * @param $separator |
|
76 | + * @param string $trim |
|
77 | + * @param bool $removeEmptyLines |
|
78 | + * @return string |
|
79 | + */ |
|
80 | + public function arrayToCsvString($dataArray, $separator, $trim = 'both', $removeEmptyLines = true) |
|
81 | + { |
|
82 | + if (!is_array($dataArray) || empty($dataArray)) { |
|
83 | + return ''; |
|
84 | + } |
|
85 | + switch ($trim) { |
|
86 | + case 'none': |
|
87 | + $trimFunction = false; |
|
88 | + break; |
|
89 | + case 'left': |
|
90 | + $trimFunction = 'ltrim'; |
|
91 | + break; |
|
92 | + case 'right': |
|
93 | + $trimFunction = 'rtrim'; |
|
94 | + break; |
|
95 | + default: //'both': |
|
96 | + $trimFunction = 'trim'; |
|
97 | + break; |
|
98 | + } |
|
99 | + $ret = []; |
|
100 | + foreach ($dataArray as $key => $field) { |
|
101 | + $ret[$key] = $this->valToCsvHelper($field, $separator, $trimFunction); |
|
102 | + } |
|
103 | + |
|
104 | + return implode($separator, $ret); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * @param $val |
|
109 | + * @param $separator |
|
110 | + * @param $trimFunction |
|
111 | + * @return mixed|string |
|
112 | + */ |
|
113 | + public function valToCsvHelper($val, $separator, $trimFunction) |
|
114 | + { |
|
115 | + if ($trimFunction) { |
|
116 | + $val = $trimFunction($val); |
|
117 | + } |
|
118 | + //If there is a separator (;) or a quote (") or a linebreak in the string, we need to quote it. |
|
119 | + $needQuote = false; |
|
120 | + do { |
|
121 | + if (false !== strpos($val, '"')) { |
|
122 | + $val = str_replace('"', '""', $val); |
|
123 | + $needQuote = true; |
|
124 | + break; |
|
125 | + } |
|
126 | + if (false !== strpos($val, $separator)) { |
|
127 | + $needQuote = true; |
|
128 | + break; |
|
129 | + } |
|
130 | + if ((false !== strpos($val, "\n")) || (false !== strpos($val, "\r"))) { // \r is for mac |
|
131 | + $needQuote = true; |
|
132 | + break; |
|
133 | + } |
|
134 | + } while (false); |
|
135 | + if ($needQuote) { |
|
136 | + $val = '"' . $val . '"'; |
|
137 | + } |
|
138 | + |
|
139 | + return $val; |
|
140 | + } |
|
141 | + |
|
142 | + public function execute() |
|
143 | + { |
|
144 | + $exportFileData = ''; |
|
145 | + |
|
146 | + switch ($this->format) { |
|
147 | + case 'csv': |
|
148 | + $separator = isset($this->options['separator']) ? $this->options['separator'] : ';'; |
|
149 | + $firstRow = implode($separator, $this->data['columnsHeaders']); |
|
150 | + $exportFileData .= $firstRow . "\r\n"; |
|
151 | + |
|
152 | + foreach ($this->data['rows'] as $cols) { |
|
153 | + $exportFileData .= $this->arrayToCsvString($cols, $separator) . "\r\n"; |
|
154 | + } |
|
155 | + break; |
|
156 | + } |
|
157 | + $this->saveExportFile($exportFileData); |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * @param $content |
|
162 | + */ |
|
163 | + public function saveExportFile($content) |
|
164 | + { |
|
165 | + switch ($this->format) { |
|
166 | + case 'csv': |
|
167 | + $this->saveCsv($content); |
|
168 | + break; |
|
169 | + } |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * @param $content |
|
174 | + */ |
|
175 | + public function saveCsv($content) |
|
176 | + { |
|
177 | + if (!$this->filepath) { |
|
178 | + $this->filepath = XOOPS_UPLOAD_PATH . '/'; |
|
179 | + } |
|
180 | + if (!$this->filename) { |
|
181 | + $this->filename .= time(); |
|
182 | + $this->filename .= '.csv'; |
|
183 | + } |
|
184 | + |
|
185 | + $fullFileName = $this->filepath . $this->filename; |
|
186 | + |
|
187 | + if (!$handle = fopen($fullFileName, 'a+')) { |
|
188 | + trigger_error('Unable to open ' . $fullFileName, E_USER_WARNING); |
|
189 | + } elseif (false === fwrite($handle, $content)) { |
|
190 | + trigger_error('Unable to write in ' . $fullFileName, E_USER_WARNING); |
|
191 | + } else { |
|
192 | + $mimeType = 'text/csv'; |
|
193 | + $file = strrev($this->filename); |
|
194 | + $temp_name = strtolower(strrev(substr($file, 0, strpos($file, '--')))); |
|
195 | + if ('' === $temp_name) { |
|
196 | + $file_name = $this->filename; |
|
197 | + } else { |
|
198 | + $file_name = $temp_name; |
|
199 | + } |
|
200 | + $fullFileName = $this->filepath . stripslashes(trim($this->filename)); |
|
201 | + |
|
202 | + if (ini_get('zlib.output_compression')) { |
|
203 | + ini_set('zlib.output_compression', 'Off'); |
|
204 | + } |
|
205 | + |
|
206 | + header('Pragma: public'); |
|
207 | + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
|
208 | + header('Cache-Control: private', false); |
|
209 | + header('Content-Transfer-Encoding: binary'); |
|
210 | + if (isset($mimeType)) { |
|
211 | + header('Content-Type: ' . $mimeType); |
|
212 | + } |
|
213 | + |
|
214 | + header('Content-Disposition: attachment; filename=' . $file_name); |
|
215 | + |
|
216 | + if (isset($mimeType) && false !== strpos($mimeType, 'text/')) { |
|
217 | + $fp = fopen($fullFileName, 'r'); |
|
218 | + } else { |
|
219 | + $fp = fopen($fullFileName, 'rb'); |
|
220 | + } |
|
221 | + fpassthru($fp); |
|
222 | + exit(); |
|
223 | + } |
|
224 | + fclose($handle); |
|
225 | + } |
|
226 | 226 | } |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | } |
237 | 237 | } while (false); |
238 | 238 | if ($needQuote) { |
239 | - $val = '"' . $val . '"'; |
|
239 | + $val = '"'.$val.'"'; |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | return $val; |
@@ -250,10 +250,10 @@ discard block |
||
250 | 250 | case 'csv': |
251 | 251 | $separator = isset($this->options['separator']) ? $this->options['separator'] : ';'; |
252 | 252 | $firstRow = implode($separator, $this->data['columnsHeaders']); |
253 | - $exportFileData .= $firstRow . "\r\n"; |
|
253 | + $exportFileData .= $firstRow."\r\n"; |
|
254 | 254 | |
255 | 255 | foreach ($this->data['rows'] as $cols) { |
256 | - $exportFileData .= $this->arrayToCsvString($cols, $separator) . "\r\n"; |
|
256 | + $exportFileData .= $this->arrayToCsvString($cols, $separator)."\r\n"; |
|
257 | 257 | } |
258 | 258 | break; |
259 | 259 | } |
@@ -278,19 +278,19 @@ discard block |
||
278 | 278 | public function saveCsv($content) |
279 | 279 | { |
280 | 280 | if (!$this->filepath) { |
281 | - $this->filepath = XOOPS_UPLOAD_PATH . '/'; |
|
281 | + $this->filepath = XOOPS_UPLOAD_PATH.'/'; |
|
282 | 282 | } |
283 | 283 | if (!$this->filename) { |
284 | 284 | $this->filename .= time(); |
285 | 285 | $this->filename .= '.csv'; |
286 | 286 | } |
287 | 287 | |
288 | - $fullFileName = $this->filepath . $this->filename; |
|
288 | + $fullFileName = $this->filepath.$this->filename; |
|
289 | 289 | |
290 | 290 | if (!$handle = fopen($fullFileName, 'a+')) { |
291 | - trigger_error('Unable to open ' . $fullFileName, E_USER_WARNING); |
|
291 | + trigger_error('Unable to open '.$fullFileName, E_USER_WARNING); |
|
292 | 292 | } elseif (false === fwrite($handle, $content)) { |
293 | - trigger_error('Unable to write in ' . $fullFileName, E_USER_WARNING); |
|
293 | + trigger_error('Unable to write in '.$fullFileName, E_USER_WARNING); |
|
294 | 294 | } else { |
295 | 295 | $mimeType = 'text/csv'; |
296 | 296 | $file = strrev($this->filename); |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | } else { |
301 | 301 | $file_name = $temp_name; |
302 | 302 | } |
303 | - $fullFileName = $this->filepath . stripslashes(trim($this->filename)); |
|
303 | + $fullFileName = $this->filepath.stripslashes(trim($this->filename)); |
|
304 | 304 | |
305 | 305 | if (ini_get('zlib.output_compression')) { |
306 | 306 | ini_set('zlib.output_compression', 'Off'); |
@@ -311,10 +311,10 @@ discard block |
||
311 | 311 | header('Cache-Control: private', false); |
312 | 312 | header('Content-Transfer-Encoding: binary'); |
313 | 313 | if (isset($mimeType)) { |
314 | - header('Content-Type: ' . $mimeType); |
|
314 | + header('Content-Type: '.$mimeType); |
|
315 | 315 | } |
316 | 316 | |
317 | - header('Content-Disposition: attachment; filename=' . $file_name); |
|
317 | + header('Content-Disposition: attachment; filename='.$file_name); |
|
318 | 318 | |
319 | 319 | if (isset($mimeType) && false !== strpos($mimeType, 'text/')) { |
320 | 320 | $fp = fopen($fullFileName, 'r'); |
@@ -61,7 +61,7 @@ |
||
61 | 61 | * @access public |
62 | 62 | * @param string $key key of the object's variable to be returned |
63 | 63 | * @param string $format format to use for the output |
64 | - * @return mixed formatted value of the variable |
|
64 | + * @return integer formatted value of the variable |
|
65 | 65 | */ |
66 | 66 | public function getVar($key, $format = 's') |
67 | 67 | { |
@@ -29,152 +29,152 @@ |
||
29 | 29 | */ |
30 | 30 | class Link extends Smartobject\BaseSmartObject |
31 | 31 | { |
32 | - /** |
|
33 | - * Link constructor. |
|
34 | - */ |
|
35 | - public function __construct() |
|
36 | - { |
|
37 | - $this->initVar('linkid', XOBJ_DTYPE_INT, '', true); |
|
38 | - $this->initVar('date', XOBJ_DTYPE_INT, 0, false, null, '', false, _CO_SOBJECT_LINK_DATE, '', true, true, false); |
|
39 | - $this->initVar('from_uid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_FROM_UID, _CO_SOBJECT_LINK_FROM_UID_DSC); |
|
40 | - $this->initVar('from_email', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_FROM_EMAIL, _CO_SOBJECT_LINK_FROM_EMAIL_DSC, true); |
|
41 | - $this->initVar('from_name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_FROM_NAME, _CO_SOBJECT_LINK_FROM_NAME_DSC, true); |
|
42 | - $this->initVar('to_uid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_TO_UID, _CO_SOBJECT_LINK_TO_UID_DSC); |
|
43 | - $this->initVar('to_email', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_TO_EMAIL, _CO_SOBJECT_LINK_TO_EMAIL_DSC, true); |
|
44 | - $this->initVar('to_name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_TO_NAME, _CO_SOBJECT_LINK_TO_NAME_DSC, true); |
|
45 | - $this->initVar('link', XOBJ_DTYPE_TXTBOX, '', false, 255, '', false, _CO_SOBJECT_LINK_LINK, _CO_SOBJECT_LINK_LINK_DSC, true); |
|
46 | - $this->initVar('subject', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_SUBJECT, _CO_SOBJECT_LINK_SUBJECT_DSC, true); |
|
47 | - $this->initVar('body', XOBJ_DTYPE_TXTAREA, '', true, null, '', false, _CO_SOBJECT_LINK_BODY, _CO_SOBJECT_LINK_BODY_DSC); |
|
48 | - $this->initVar('mid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_MID, _CO_SOBJECT_LINK_MID_DSC); |
|
49 | - $this->initVar('mid_name', XOBJ_DTYPE_TXTBOX, '', false, 255, '', false, _CO_SOBJECT_LINK_MID_NAME, _CO_SOBJECT_LINK_MID_NAME_DSC, true); |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * returns a specific variable for the object in a proper format |
|
54 | - * |
|
55 | - * @access public |
|
56 | - * @param string $key key of the object's variable to be returned |
|
57 | - * @param string $format format to use for the output |
|
58 | - * @return mixed formatted value of the variable |
|
59 | - */ |
|
60 | - public function getVar($key, $format = 's') |
|
61 | - { |
|
62 | - if ('s' === $format && in_array($key, ['from_uid', 'to_uid', 'date', 'link'])) { |
|
63 | - // return call_user_func(array($this, $key)); |
|
64 | - return $this->{$key}(); |
|
65 | - } |
|
66 | - |
|
67 | - return parent::getVar($key, $format); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * @return string |
|
72 | - */ |
|
73 | - public function from_uid() |
|
74 | - { |
|
75 | - $ret = Smartobject\Utility::getLinkedUnameFromId($this->getVar('from_uid', 'e'), 1, null, true); |
|
76 | - |
|
77 | - return $ret; |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * @param bool $withContact |
|
82 | - * @return string |
|
83 | - */ |
|
84 | - public function to_uid($withContact = false) |
|
85 | - { |
|
86 | - $ret = Smartobject\Utility::getLinkedUnameFromId($this->getVar('to_uid', 'e'), 1, null, true); |
|
87 | - |
|
88 | - return $ret; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * @return string |
|
93 | - */ |
|
94 | - public function date() |
|
95 | - { |
|
96 | - $ret = formatTimestamp($this->getVar('date', 'e')); |
|
97 | - |
|
98 | - return $ret; |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * @param bool $full |
|
103 | - * @return mixed|string |
|
104 | - */ |
|
105 | - public function link($full = false) |
|
106 | - { |
|
107 | - $ret = $this->getVar('link', 'e'); |
|
108 | - if ($full) { |
|
109 | - $myts = \MyTextSanitizer::getInstance(); |
|
110 | - $ret = $myts->displayTarea($ret); |
|
111 | - |
|
112 | - return $ret; |
|
113 | - } else { |
|
114 | - $ret = '<a href="' . $ret . '" alt="' . $this->getVar('link', 'e') . '" title="' . $this->getVar('link', 'e') . '">' . _AM_SOBJECT_SENT_LINKS_GOTO . '</a>'; |
|
115 | - |
|
116 | - return $ret; |
|
117 | - } |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * @return string |
|
122 | - */ |
|
123 | - public function getViewItemLink() |
|
124 | - { |
|
125 | - $ret = '<a href="' . SMARTOBJECT_URL . 'admin/link.php?op=view&linkid=' . $this->getVar('linkid') . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'mail_find.png" alt="' . _AM_SOBJECT_SENT_LINK_VIEW . '" title="' . _AM_SOBJECT_SENT_LINK_VIEW . '"></a>'; |
|
126 | - |
|
127 | - return $ret; |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * @return string |
|
132 | - */ |
|
133 | - public function getFromInfo() |
|
134 | - { |
|
135 | - // check if from_uid represent a user |
|
136 | - |
|
137 | - if ($this->getVar('from_uid')) { |
|
138 | - $user = Smartobject\Utility::getLinkedUnameFromId($this->getVar('from_uid')); |
|
139 | - if ($user == $GLOBALS['xoopsConfig']['anonymous']) { |
|
140 | - $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>'; |
|
141 | - } |
|
142 | - } else { |
|
143 | - $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>'; |
|
144 | - } |
|
145 | - |
|
146 | - return $user; |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * @return array |
|
151 | - */ |
|
152 | - public function toArray() |
|
153 | - { |
|
154 | - $ret = parent::toArray(); |
|
155 | - $ret['fromInfo'] = $this->getFromInfo(); |
|
156 | - $ret['toInfo'] = $this->getToInfo(); |
|
157 | - $ret['fullLink'] = $this->link(true); |
|
158 | - |
|
159 | - return $ret; |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * @return string |
|
164 | - */ |
|
165 | - public function getToInfo() |
|
166 | - { |
|
167 | - // check if from_uid represent a user |
|
168 | - |
|
169 | - if ($this->getVar('to_uid')) { |
|
170 | - $user = Smartobject\Utility::getLinkedUnameFromId($this->getVar('to_uid')); |
|
171 | - if ($user == $GLOBALS['xoopsConfig']['anonymous']) { |
|
172 | - $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>'; |
|
173 | - } |
|
174 | - } else { |
|
175 | - $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>'; |
|
176 | - } |
|
177 | - |
|
178 | - return $user; |
|
179 | - } |
|
32 | + /** |
|
33 | + * Link constructor. |
|
34 | + */ |
|
35 | + public function __construct() |
|
36 | + { |
|
37 | + $this->initVar('linkid', XOBJ_DTYPE_INT, '', true); |
|
38 | + $this->initVar('date', XOBJ_DTYPE_INT, 0, false, null, '', false, _CO_SOBJECT_LINK_DATE, '', true, true, false); |
|
39 | + $this->initVar('from_uid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_FROM_UID, _CO_SOBJECT_LINK_FROM_UID_DSC); |
|
40 | + $this->initVar('from_email', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_FROM_EMAIL, _CO_SOBJECT_LINK_FROM_EMAIL_DSC, true); |
|
41 | + $this->initVar('from_name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_FROM_NAME, _CO_SOBJECT_LINK_FROM_NAME_DSC, true); |
|
42 | + $this->initVar('to_uid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_TO_UID, _CO_SOBJECT_LINK_TO_UID_DSC); |
|
43 | + $this->initVar('to_email', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_TO_EMAIL, _CO_SOBJECT_LINK_TO_EMAIL_DSC, true); |
|
44 | + $this->initVar('to_name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_TO_NAME, _CO_SOBJECT_LINK_TO_NAME_DSC, true); |
|
45 | + $this->initVar('link', XOBJ_DTYPE_TXTBOX, '', false, 255, '', false, _CO_SOBJECT_LINK_LINK, _CO_SOBJECT_LINK_LINK_DSC, true); |
|
46 | + $this->initVar('subject', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_SUBJECT, _CO_SOBJECT_LINK_SUBJECT_DSC, true); |
|
47 | + $this->initVar('body', XOBJ_DTYPE_TXTAREA, '', true, null, '', false, _CO_SOBJECT_LINK_BODY, _CO_SOBJECT_LINK_BODY_DSC); |
|
48 | + $this->initVar('mid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_MID, _CO_SOBJECT_LINK_MID_DSC); |
|
49 | + $this->initVar('mid_name', XOBJ_DTYPE_TXTBOX, '', false, 255, '', false, _CO_SOBJECT_LINK_MID_NAME, _CO_SOBJECT_LINK_MID_NAME_DSC, true); |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * returns a specific variable for the object in a proper format |
|
54 | + * |
|
55 | + * @access public |
|
56 | + * @param string $key key of the object's variable to be returned |
|
57 | + * @param string $format format to use for the output |
|
58 | + * @return mixed formatted value of the variable |
|
59 | + */ |
|
60 | + public function getVar($key, $format = 's') |
|
61 | + { |
|
62 | + if ('s' === $format && in_array($key, ['from_uid', 'to_uid', 'date', 'link'])) { |
|
63 | + // return call_user_func(array($this, $key)); |
|
64 | + return $this->{$key}(); |
|
65 | + } |
|
66 | + |
|
67 | + return parent::getVar($key, $format); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * @return string |
|
72 | + */ |
|
73 | + public function from_uid() |
|
74 | + { |
|
75 | + $ret = Smartobject\Utility::getLinkedUnameFromId($this->getVar('from_uid', 'e'), 1, null, true); |
|
76 | + |
|
77 | + return $ret; |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * @param bool $withContact |
|
82 | + * @return string |
|
83 | + */ |
|
84 | + public function to_uid($withContact = false) |
|
85 | + { |
|
86 | + $ret = Smartobject\Utility::getLinkedUnameFromId($this->getVar('to_uid', 'e'), 1, null, true); |
|
87 | + |
|
88 | + return $ret; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * @return string |
|
93 | + */ |
|
94 | + public function date() |
|
95 | + { |
|
96 | + $ret = formatTimestamp($this->getVar('date', 'e')); |
|
97 | + |
|
98 | + return $ret; |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * @param bool $full |
|
103 | + * @return mixed|string |
|
104 | + */ |
|
105 | + public function link($full = false) |
|
106 | + { |
|
107 | + $ret = $this->getVar('link', 'e'); |
|
108 | + if ($full) { |
|
109 | + $myts = \MyTextSanitizer::getInstance(); |
|
110 | + $ret = $myts->displayTarea($ret); |
|
111 | + |
|
112 | + return $ret; |
|
113 | + } else { |
|
114 | + $ret = '<a href="' . $ret . '" alt="' . $this->getVar('link', 'e') . '" title="' . $this->getVar('link', 'e') . '">' . _AM_SOBJECT_SENT_LINKS_GOTO . '</a>'; |
|
115 | + |
|
116 | + return $ret; |
|
117 | + } |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * @return string |
|
122 | + */ |
|
123 | + public function getViewItemLink() |
|
124 | + { |
|
125 | + $ret = '<a href="' . SMARTOBJECT_URL . 'admin/link.php?op=view&linkid=' . $this->getVar('linkid') . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'mail_find.png" alt="' . _AM_SOBJECT_SENT_LINK_VIEW . '" title="' . _AM_SOBJECT_SENT_LINK_VIEW . '"></a>'; |
|
126 | + |
|
127 | + return $ret; |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * @return string |
|
132 | + */ |
|
133 | + public function getFromInfo() |
|
134 | + { |
|
135 | + // check if from_uid represent a user |
|
136 | + |
|
137 | + if ($this->getVar('from_uid')) { |
|
138 | + $user = Smartobject\Utility::getLinkedUnameFromId($this->getVar('from_uid')); |
|
139 | + if ($user == $GLOBALS['xoopsConfig']['anonymous']) { |
|
140 | + $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>'; |
|
141 | + } |
|
142 | + } else { |
|
143 | + $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>'; |
|
144 | + } |
|
145 | + |
|
146 | + return $user; |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * @return array |
|
151 | + */ |
|
152 | + public function toArray() |
|
153 | + { |
|
154 | + $ret = parent::toArray(); |
|
155 | + $ret['fromInfo'] = $this->getFromInfo(); |
|
156 | + $ret['toInfo'] = $this->getToInfo(); |
|
157 | + $ret['fullLink'] = $this->link(true); |
|
158 | + |
|
159 | + return $ret; |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * @return string |
|
164 | + */ |
|
165 | + public function getToInfo() |
|
166 | + { |
|
167 | + // check if from_uid represent a user |
|
168 | + |
|
169 | + if ($this->getVar('to_uid')) { |
|
170 | + $user = Smartobject\Utility::getLinkedUnameFromId($this->getVar('to_uid')); |
|
171 | + if ($user == $GLOBALS['xoopsConfig']['anonymous']) { |
|
172 | + $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>'; |
|
173 | + } |
|
174 | + } else { |
|
175 | + $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>'; |
|
176 | + } |
|
177 | + |
|
178 | + return $user; |
|
179 | + } |
|
180 | 180 | } |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | |
112 | 112 | return $ret; |
113 | 113 | } else { |
114 | - $ret = '<a href="' . $ret . '" alt="' . $this->getVar('link', 'e') . '" title="' . $this->getVar('link', 'e') . '">' . _AM_SOBJECT_SENT_LINKS_GOTO . '</a>'; |
|
114 | + $ret = '<a href="'.$ret.'" alt="'.$this->getVar('link', 'e').'" title="'.$this->getVar('link', 'e').'">'._AM_SOBJECT_SENT_LINKS_GOTO.'</a>'; |
|
115 | 115 | |
116 | 116 | return $ret; |
117 | 117 | } |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | */ |
123 | 123 | public function getViewItemLink() |
124 | 124 | { |
125 | - $ret = '<a href="' . SMARTOBJECT_URL . 'admin/link.php?op=view&linkid=' . $this->getVar('linkid') . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'mail_find.png" alt="' . _AM_SOBJECT_SENT_LINK_VIEW . '" title="' . _AM_SOBJECT_SENT_LINK_VIEW . '"></a>'; |
|
125 | + $ret = '<a href="'.SMARTOBJECT_URL.'admin/link.php?op=view&linkid='.$this->getVar('linkid').'"><img src="'.SMARTOBJECT_IMAGES_ACTIONS_URL.'mail_find.png" alt="'._AM_SOBJECT_SENT_LINK_VIEW.'" title="'._AM_SOBJECT_SENT_LINK_VIEW.'"></a>'; |
|
126 | 126 | |
127 | 127 | return $ret; |
128 | 128 | } |
@@ -137,10 +137,10 @@ discard block |
||
137 | 137 | if ($this->getVar('from_uid')) { |
138 | 138 | $user = Smartobject\Utility::getLinkedUnameFromId($this->getVar('from_uid')); |
139 | 139 | if ($user == $GLOBALS['xoopsConfig']['anonymous']) { |
140 | - $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>'; |
|
140 | + $user = '<a href="mailto:'.$this->getVar('from_email').'">'.$this->getVar('from_email').'</a>'; |
|
141 | 141 | } |
142 | 142 | } else { |
143 | - $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>'; |
|
143 | + $user = '<a href="mailto:'.$this->getVar('from_email').'">'.$this->getVar('from_email').'</a>'; |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | return $user; |
@@ -169,10 +169,10 @@ discard block |
||
169 | 169 | if ($this->getVar('to_uid')) { |
170 | 170 | $user = Smartobject\Utility::getLinkedUnameFromId($this->getVar('to_uid')); |
171 | 171 | if ($user == $GLOBALS['xoopsConfig']['anonymous']) { |
172 | - $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>'; |
|
172 | + $user = '<a href="mailto:'.$this->getVar('to_email').'">'.$this->getVar('to_email').'</a>'; |
|
173 | 173 | } |
174 | 174 | } else { |
175 | - $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>'; |
|
175 | + $user = '<a href="mailto:'.$this->getVar('to_email').'">'.$this->getVar('to_email').'</a>'; |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | return $user; |
@@ -228,7 +228,7 @@ |
||
228 | 228 | * Creates a random number with a specified number of $digits |
229 | 229 | * |
230 | 230 | * @param int $digits number of digits |
231 | - * @return int random number |
|
231 | + * @return string random number |
|
232 | 232 | * @author xHelp Team |
233 | 233 | * |
234 | 234 | * @access public |
@@ -37,227 +37,227 @@ |
||
37 | 37 | */ |
38 | 38 | class MemberHandler extends \XoopsMemberHandler |
39 | 39 | { |
40 | - /** |
|
41 | - * constructor |
|
42 | - * @param \XoopsDatabase $db |
|
43 | - */ |
|
44 | - public function __construct(\XoopsDatabase $db) |
|
45 | - { |
|
46 | - parent::__construct($db); |
|
47 | - $this->_uHandler = Smartobject\Helper::getInstance()->getHandler('User'); |
|
48 | - } |
|
40 | + /** |
|
41 | + * constructor |
|
42 | + * @param \XoopsDatabase $db |
|
43 | + */ |
|
44 | + public function __construct(\XoopsDatabase $db) |
|
45 | + { |
|
46 | + parent::__construct($db); |
|
47 | + $this->_uHandler = Smartobject\Helper::getInstance()->getHandler('User'); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @param $userObj |
|
52 | - * @param bool $groups |
|
53 | - * @param bool $notifyUser |
|
54 | - * @param bool $password |
|
55 | - * @return bool |
|
56 | - */ |
|
57 | - public function addAndActivateUser($userObj, $groups = false, $notifyUser = true, &$password = false) |
|
58 | - { |
|
59 | - $email = $userObj->getVar('email'); |
|
60 | - if (!$userObj->getVar('email') || '' === $email) { |
|
61 | - $userObj->setErrors(_CO_SOBJECT_USER_NEED_EMAIL); |
|
50 | + /** |
|
51 | + * @param $userObj |
|
52 | + * @param bool $groups |
|
53 | + * @param bool $notifyUser |
|
54 | + * @param bool $password |
|
55 | + * @return bool |
|
56 | + */ |
|
57 | + public function addAndActivateUser($userObj, $groups = false, $notifyUser = true, &$password = false) |
|
58 | + { |
|
59 | + $email = $userObj->getVar('email'); |
|
60 | + if (!$userObj->getVar('email') || '' === $email) { |
|
61 | + $userObj->setErrors(_CO_SOBJECT_USER_NEED_EMAIL); |
|
62 | 62 | |
63 | - return false; |
|
64 | - } |
|
63 | + return false; |
|
64 | + } |
|
65 | 65 | |
66 | - $password = $userObj->getVar('pass'); |
|
67 | - // randomly generating the password if not already set |
|
68 | - if ('' === $password) { |
|
69 | - $password = substr(md5(uniqid(mt_rand(), 1)), 0, 6); |
|
70 | - } |
|
71 | - $userObj->setVar('pass', md5($password)); |
|
66 | + $password = $userObj->getVar('pass'); |
|
67 | + // randomly generating the password if not already set |
|
68 | + if ('' === $password) { |
|
69 | + $password = substr(md5(uniqid(mt_rand(), 1)), 0, 6); |
|
70 | + } |
|
71 | + $userObj->setVar('pass', md5($password)); |
|
72 | 72 | |
73 | - // if no username is set, let's generate one |
|
74 | - $unamecount = 20; |
|
75 | - $uname = $userObj->getVar('uname'); |
|
76 | - if (!$uname || '' === $uname) { |
|
77 | - $usernames = $this->genUserNames($email, $unamecount); |
|
78 | - $newuser = false; |
|
79 | - $i = 0; |
|
80 | - while (false === $newuser) { |
|
81 | - $crit = new \Criteria('uname', $usernames[$i]); |
|
82 | - $count = $this->getUserCount($crit); |
|
83 | - if (0 == $count) { |
|
84 | - $newuser = true; |
|
85 | - } else { |
|
86 | - //Move to next username |
|
87 | - ++$i; |
|
88 | - if ($i == $unamecount) { |
|
89 | - //Get next batch of usernames to try, reset counter |
|
90 | - $usernames = $this->genUserNames($email, $unamecount); |
|
91 | - $i = 0; |
|
92 | - } |
|
93 | - } |
|
94 | - } |
|
95 | - } |
|
73 | + // if no username is set, let's generate one |
|
74 | + $unamecount = 20; |
|
75 | + $uname = $userObj->getVar('uname'); |
|
76 | + if (!$uname || '' === $uname) { |
|
77 | + $usernames = $this->genUserNames($email, $unamecount); |
|
78 | + $newuser = false; |
|
79 | + $i = 0; |
|
80 | + while (false === $newuser) { |
|
81 | + $crit = new \Criteria('uname', $usernames[$i]); |
|
82 | + $count = $this->getUserCount($crit); |
|
83 | + if (0 == $count) { |
|
84 | + $newuser = true; |
|
85 | + } else { |
|
86 | + //Move to next username |
|
87 | + ++$i; |
|
88 | + if ($i == $unamecount) { |
|
89 | + //Get next batch of usernames to try, reset counter |
|
90 | + $usernames = $this->genUserNames($email, $unamecount); |
|
91 | + $i = 0; |
|
92 | + } |
|
93 | + } |
|
94 | + } |
|
95 | + } |
|
96 | 96 | |
97 | - global $xoopsConfig; |
|
97 | + global $xoopsConfig; |
|
98 | 98 | |
99 | - $configHandler = xoops_getHandler('config'); |
|
100 | - $xoopsConfigUser = $configHandler->getConfigsByCat(XOOPS_CONF_USER); |
|
101 | - switch ($xoopsConfigUser['activation_type']) { |
|
102 | - case 0: |
|
103 | - $level = 0; |
|
104 | - $mailtemplate = 'smartmail_activate_user.tpl'; |
|
105 | - $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_NEED_ACT, $user_email); |
|
106 | - break; |
|
107 | - case 1: |
|
108 | - $level = 1; |
|
109 | - $mailtemplate = 'smartmail_auto_activate_user.tpl'; |
|
110 | - $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_AUTO_ACT, $user_email); |
|
111 | - break; |
|
112 | - case 2: |
|
113 | - default: |
|
114 | - $level = 0; |
|
115 | - $mailtemplate = 'smartmail_admin_activate_user.tpl'; |
|
116 | - $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_ADMIN_ACT, $user_email); |
|
117 | - } |
|
99 | + $configHandler = xoops_getHandler('config'); |
|
100 | + $xoopsConfigUser = $configHandler->getConfigsByCat(XOOPS_CONF_USER); |
|
101 | + switch ($xoopsConfigUser['activation_type']) { |
|
102 | + case 0: |
|
103 | + $level = 0; |
|
104 | + $mailtemplate = 'smartmail_activate_user.tpl'; |
|
105 | + $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_NEED_ACT, $user_email); |
|
106 | + break; |
|
107 | + case 1: |
|
108 | + $level = 1; |
|
109 | + $mailtemplate = 'smartmail_auto_activate_user.tpl'; |
|
110 | + $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_AUTO_ACT, $user_email); |
|
111 | + break; |
|
112 | + case 2: |
|
113 | + default: |
|
114 | + $level = 0; |
|
115 | + $mailtemplate = 'smartmail_admin_activate_user.tpl'; |
|
116 | + $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_ADMIN_ACT, $user_email); |
|
117 | + } |
|
118 | 118 | |
119 | - $userObj->setVar('uname', $usernames[$i]); |
|
120 | - $userObj->setVar('user_avatar', 'blank.gif'); |
|
121 | - $userObj->setVar('user_regdate', time()); |
|
122 | - $userObj->setVar('timezone_offset', $xoopsConfig['default_TZ']); |
|
123 | - $actkey = substr(md5(uniqid(mt_rand(), 1)), 0, 8); |
|
124 | - $userObj->setVar('actkey', $actkey); |
|
125 | - $userObj->setVar('email', $email); |
|
126 | - $userObj->setVar('notify_method', 2); |
|
127 | - $userObj->setVar('level', $userObj); |
|
119 | + $userObj->setVar('uname', $usernames[$i]); |
|
120 | + $userObj->setVar('user_avatar', 'blank.gif'); |
|
121 | + $userObj->setVar('user_regdate', time()); |
|
122 | + $userObj->setVar('timezone_offset', $xoopsConfig['default_TZ']); |
|
123 | + $actkey = substr(md5(uniqid(mt_rand(), 1)), 0, 8); |
|
124 | + $userObj->setVar('actkey', $actkey); |
|
125 | + $userObj->setVar('email', $email); |
|
126 | + $userObj->setVar('notify_method', 2); |
|
127 | + $userObj->setVar('level', $userObj); |
|
128 | 128 | |
129 | - if ($this->insertUser($userObj)) { |
|
129 | + if ($this->insertUser($userObj)) { |
|
130 | 130 | |
131 | - // if $groups=false, Add the user to Registered Users group |
|
132 | - if (!$groups) { |
|
133 | - $this->addUserToGroup(XOOPS_GROUP_USERS, $userObj->getVar('uid')); |
|
134 | - } else { |
|
135 | - foreach ($groups as $groupid) { |
|
136 | - $this->addUserToGroup($groupid, $userObj->getVar('uid')); |
|
137 | - } |
|
138 | - } |
|
139 | - } else { |
|
140 | - return false; |
|
141 | - } |
|
131 | + // if $groups=false, Add the user to Registered Users group |
|
132 | + if (!$groups) { |
|
133 | + $this->addUserToGroup(XOOPS_GROUP_USERS, $userObj->getVar('uid')); |
|
134 | + } else { |
|
135 | + foreach ($groups as $groupid) { |
|
136 | + $this->addUserToGroup($groupid, $userObj->getVar('uid')); |
|
137 | + } |
|
138 | + } |
|
139 | + } else { |
|
140 | + return false; |
|
141 | + } |
|
142 | 142 | |
143 | - if ($notifyUser) { |
|
144 | - // send some notifications |
|
145 | - $xoopsMailer = xoops_getMailer(); |
|
146 | - $xoopsMailer->useMail(); |
|
147 | - $xoopsMailer->setTemplateDir(SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/mail_template'); |
|
148 | - $xoopsMailer->setTemplate('smartobject_notify_user_added_by_admin.tpl'); |
|
149 | - $xoopsMailer->assign('XOOPS_USER_PASSWORD', $password); |
|
150 | - $xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']); |
|
151 | - $xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']); |
|
152 | - $xoopsMailer->assign('SITEURL', XOOPS_URL . '/'); |
|
153 | - $xoopsMailer->assign('NAME', $userObj->getVar('name')); |
|
154 | - $xoopsMailer->assign('UNAME', $userObj->getVar('uname')); |
|
155 | - $xoopsMailer->setToUsers($userObj); |
|
156 | - $xoopsMailer->setFromEmail($xoopsConfig['adminmail']); |
|
157 | - $xoopsMailer->setFromName($xoopsConfig['sitename']); |
|
158 | - $xoopsMailer->setSubject(sprintf(_CO_SOBJECT_NEW_USER_NOTIFICATION_SUBJECT, $xoopsConfig['sitename'])); |
|
143 | + if ($notifyUser) { |
|
144 | + // send some notifications |
|
145 | + $xoopsMailer = xoops_getMailer(); |
|
146 | + $xoopsMailer->useMail(); |
|
147 | + $xoopsMailer->setTemplateDir(SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/mail_template'); |
|
148 | + $xoopsMailer->setTemplate('smartobject_notify_user_added_by_admin.tpl'); |
|
149 | + $xoopsMailer->assign('XOOPS_USER_PASSWORD', $password); |
|
150 | + $xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']); |
|
151 | + $xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']); |
|
152 | + $xoopsMailer->assign('SITEURL', XOOPS_URL . '/'); |
|
153 | + $xoopsMailer->assign('NAME', $userObj->getVar('name')); |
|
154 | + $xoopsMailer->assign('UNAME', $userObj->getVar('uname')); |
|
155 | + $xoopsMailer->setToUsers($userObj); |
|
156 | + $xoopsMailer->setFromEmail($xoopsConfig['adminmail']); |
|
157 | + $xoopsMailer->setFromName($xoopsConfig['sitename']); |
|
158 | + $xoopsMailer->setSubject(sprintf(_CO_SOBJECT_NEW_USER_NOTIFICATION_SUBJECT, $xoopsConfig['sitename'])); |
|
159 | 159 | |
160 | - if (!$xoopsMailer->send(true)) { |
|
161 | - /** |
|
162 | - * @todo trap error if email was not sent |
|
163 | - */ |
|
164 | - $xoopsMailer->getErrors(true); |
|
165 | - } |
|
166 | - } |
|
160 | + if (!$xoopsMailer->send(true)) { |
|
161 | + /** |
|
162 | + * @todo trap error if email was not sent |
|
163 | + */ |
|
164 | + $xoopsMailer->getErrors(true); |
|
165 | + } |
|
166 | + } |
|
167 | 167 | |
168 | - return true; |
|
169 | - } |
|
168 | + return true; |
|
169 | + } |
|
170 | 170 | |
171 | - /** |
|
172 | - * Generates an array of usernames |
|
173 | - * |
|
174 | - * @param string $email email of user |
|
175 | - * @param int $count number of names to generate |
|
176 | - * @return array $names |
|
177 | - * @internal param string $name name of user |
|
178 | - * @author xHelp Team |
|
179 | - * |
|
180 | - * @access public |
|
181 | - */ |
|
182 | - public function genUserNames($email, $count = 20) |
|
183 | - { |
|
184 | - $name = substr($email, 0, strpos($email, '@')); //Take the email adress without domain as username |
|
171 | + /** |
|
172 | + * Generates an array of usernames |
|
173 | + * |
|
174 | + * @param string $email email of user |
|
175 | + * @param int $count number of names to generate |
|
176 | + * @return array $names |
|
177 | + * @internal param string $name name of user |
|
178 | + * @author xHelp Team |
|
179 | + * |
|
180 | + * @access public |
|
181 | + */ |
|
182 | + public function genUserNames($email, $count = 20) |
|
183 | + { |
|
184 | + $name = substr($email, 0, strpos($email, '@')); //Take the email adress without domain as username |
|
185 | 185 | |
186 | - $names = []; |
|
187 | - $userid = explode('@', $email); |
|
186 | + $names = []; |
|
187 | + $userid = explode('@', $email); |
|
188 | 188 | |
189 | - $basename = ''; |
|
190 | - $hasbasename = false; |
|
191 | - $emailname = $userid[0]; |
|
189 | + $basename = ''; |
|
190 | + $hasbasename = false; |
|
191 | + $emailname = $userid[0]; |
|
192 | 192 | |
193 | - $names[] = $emailname; |
|
193 | + $names[] = $emailname; |
|
194 | 194 | |
195 | - if (strlen($name) > 0) { |
|
196 | - $name = explode(' ', trim($name)); |
|
197 | - if (count($name) > 1) { |
|
198 | - $basename = strtolower(substr($name[0], 0, 1) . $name[count($name) - 1]); |
|
199 | - } else { |
|
200 | - $basename = strtolower($name[0]); |
|
201 | - } |
|
202 | - $basename = xoops_substr($basename, 0, 60, ''); |
|
203 | - //Prevent Duplication of Email Username and Name |
|
204 | - if (!in_array($basename, $names)) { |
|
205 | - $names[] = $basename; |
|
206 | - $hasbasename = true; |
|
207 | - } |
|
208 | - } |
|
195 | + if (strlen($name) > 0) { |
|
196 | + $name = explode(' ', trim($name)); |
|
197 | + if (count($name) > 1) { |
|
198 | + $basename = strtolower(substr($name[0], 0, 1) . $name[count($name) - 1]); |
|
199 | + } else { |
|
200 | + $basename = strtolower($name[0]); |
|
201 | + } |
|
202 | + $basename = xoops_substr($basename, 0, 60, ''); |
|
203 | + //Prevent Duplication of Email Username and Name |
|
204 | + if (!in_array($basename, $names)) { |
|
205 | + $names[] = $basename; |
|
206 | + $hasbasename = true; |
|
207 | + } |
|
208 | + } |
|
209 | 209 | |
210 | - $i = count($names); |
|
211 | - $onbasename = 1; |
|
212 | - while ($i < $count) { |
|
213 | - $num = $this->genRandNumber(); |
|
214 | - if ($onbasename < 0 && $hasbasename) { |
|
215 | - $names[] = xoops_substr($basename, 0, 58, '') . $num; |
|
216 | - } else { |
|
217 | - $names[] = xoops_substr($emailname, 0, 58, '') . $num; |
|
218 | - } |
|
219 | - $i = count($names); |
|
220 | - $onbasename = ~$onbasename; |
|
221 | - $num = ''; |
|
222 | - } |
|
210 | + $i = count($names); |
|
211 | + $onbasename = 1; |
|
212 | + while ($i < $count) { |
|
213 | + $num = $this->genRandNumber(); |
|
214 | + if ($onbasename < 0 && $hasbasename) { |
|
215 | + $names[] = xoops_substr($basename, 0, 58, '') . $num; |
|
216 | + } else { |
|
217 | + $names[] = xoops_substr($emailname, 0, 58, '') . $num; |
|
218 | + } |
|
219 | + $i = count($names); |
|
220 | + $onbasename = ~$onbasename; |
|
221 | + $num = ''; |
|
222 | + } |
|
223 | 223 | |
224 | - return $names; |
|
225 | - } |
|
224 | + return $names; |
|
225 | + } |
|
226 | 226 | |
227 | - /** |
|
228 | - * Creates a random number with a specified number of $digits |
|
229 | - * |
|
230 | - * @param int $digits number of digits |
|
231 | - * @return int random number |
|
232 | - * @author xHelp Team |
|
233 | - * |
|
234 | - * @access public |
|
235 | - */ |
|
236 | - public function genRandNumber($digits = 2) |
|
237 | - { |
|
238 | - $this->initRand(); |
|
239 | - $tmp = []; |
|
227 | + /** |
|
228 | + * Creates a random number with a specified number of $digits |
|
229 | + * |
|
230 | + * @param int $digits number of digits |
|
231 | + * @return int random number |
|
232 | + * @author xHelp Team |
|
233 | + * |
|
234 | + * @access public |
|
235 | + */ |
|
236 | + public function genRandNumber($digits = 2) |
|
237 | + { |
|
238 | + $this->initRand(); |
|
239 | + $tmp = []; |
|
240 | 240 | |
241 | - for ($i = 0; $i < $digits; ++$i) { |
|
242 | - $tmp[$i] = (mt_rand() % 9); |
|
243 | - } |
|
241 | + for ($i = 0; $i < $digits; ++$i) { |
|
242 | + $tmp[$i] = (mt_rand() % 9); |
|
243 | + } |
|
244 | 244 | |
245 | - return implode('', $tmp); |
|
246 | - } |
|
245 | + return implode('', $tmp); |
|
246 | + } |
|
247 | 247 | |
248 | - /** |
|
249 | - * Gives the random number generator a seed to start from |
|
250 | - * |
|
251 | - * @return void |
|
252 | - * |
|
253 | - * @access public |
|
254 | - */ |
|
255 | - public function initRand() |
|
256 | - { |
|
257 | - static $randCalled = false; |
|
258 | - if (!$randCalled) { |
|
259 | - mt_srand((double)microtime() * 1000000); |
|
260 | - $randCalled = true; |
|
261 | - } |
|
262 | - } |
|
248 | + /** |
|
249 | + * Gives the random number generator a seed to start from |
|
250 | + * |
|
251 | + * @return void |
|
252 | + * |
|
253 | + * @access public |
|
254 | + */ |
|
255 | + public function initRand() |
|
256 | + { |
|
257 | + static $randCalled = false; |
|
258 | + if (!$randCalled) { |
|
259 | + mt_srand((double)microtime() * 1000000); |
|
260 | + $randCalled = true; |
|
261 | + } |
|
262 | + } |
|
263 | 263 | } |
@@ -21,9 +21,9 @@ discard block |
||
21 | 21 | use XoopsModules\Smartobject; |
22 | 22 | |
23 | 23 | // defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
24 | -require_once XOOPS_ROOT_PATH . '/kernel/user.php'; |
|
25 | -require_once XOOPS_ROOT_PATH . '/kernel/group.php'; |
|
26 | -require_once XOOPS_ROOT_PATH . '/kernel/member.php'; |
|
24 | +require_once XOOPS_ROOT_PATH.'/kernel/user.php'; |
|
25 | +require_once XOOPS_ROOT_PATH.'/kernel/group.php'; |
|
26 | +require_once XOOPS_ROOT_PATH.'/kernel/member.php'; |
|
27 | 27 | |
28 | 28 | /** |
29 | 29 | * XOOPS member handler class. |
@@ -144,12 +144,12 @@ discard block |
||
144 | 144 | // send some notifications |
145 | 145 | $xoopsMailer = xoops_getMailer(); |
146 | 146 | $xoopsMailer->useMail(); |
147 | - $xoopsMailer->setTemplateDir(SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/mail_template'); |
|
147 | + $xoopsMailer->setTemplateDir(SMARTOBJECT_ROOT_PATH.'language/'.$xoopsConfig['language'].'/mail_template'); |
|
148 | 148 | $xoopsMailer->setTemplate('smartobject_notify_user_added_by_admin.tpl'); |
149 | 149 | $xoopsMailer->assign('XOOPS_USER_PASSWORD', $password); |
150 | 150 | $xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']); |
151 | 151 | $xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']); |
152 | - $xoopsMailer->assign('SITEURL', XOOPS_URL . '/'); |
|
152 | + $xoopsMailer->assign('SITEURL', XOOPS_URL.'/'); |
|
153 | 153 | $xoopsMailer->assign('NAME', $userObj->getVar('name')); |
154 | 154 | $xoopsMailer->assign('UNAME', $userObj->getVar('uname')); |
155 | 155 | $xoopsMailer->setToUsers($userObj); |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | if (strlen($name) > 0) { |
196 | 196 | $name = explode(' ', trim($name)); |
197 | 197 | if (count($name) > 1) { |
198 | - $basename = strtolower(substr($name[0], 0, 1) . $name[count($name) - 1]); |
|
198 | + $basename = strtolower(substr($name[0], 0, 1).$name[count($name) - 1]); |
|
199 | 199 | } else { |
200 | 200 | $basename = strtolower($name[0]); |
201 | 201 | } |
@@ -212,9 +212,9 @@ discard block |
||
212 | 212 | while ($i < $count) { |
213 | 213 | $num = $this->genRandNumber(); |
214 | 214 | if ($onbasename < 0 && $hasbasename) { |
215 | - $names[] = xoops_substr($basename, 0, 58, '') . $num; |
|
215 | + $names[] = xoops_substr($basename, 0, 58, '').$num; |
|
216 | 216 | } else { |
217 | - $names[] = xoops_substr($emailname, 0, 58, '') . $num; |
|
217 | + $names[] = xoops_substr($emailname, 0, 58, '').$num; |
|
218 | 218 | } |
219 | 219 | $i = count($names); |
220 | 220 | $onbasename = ~$onbasename; |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | { |
257 | 257 | static $randCalled = false; |
258 | 258 | if (!$randCalled) { |
259 | - mt_srand((double)microtime() * 1000000); |
|
259 | + mt_srand((double) microtime() * 1000000); |
|
260 | 260 | $randCalled = true; |
261 | 261 | } |
262 | 262 | } |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | } |
166 | 166 | |
167 | 167 | /** |
168 | - * @param $keywords |
|
168 | + * @param string|boolean $keywords |
|
169 | 169 | */ |
170 | 170 | public function setKeywords($keywords) |
171 | 171 | { |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | } |
174 | 174 | |
175 | 175 | /** |
176 | - * @param $categoryPath |
|
176 | + * @param boolean $categoryPath |
|
177 | 177 | */ |
178 | 178 | public function setCategoryPath($categoryPath) |
179 | 179 | { |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
185 | - * @param $description |
|
185 | + * @param boolean $description |
|
186 | 186 | */ |
187 | 187 | public function setDescription($description) |
188 | 188 | { |
@@ -242,8 +242,8 @@ discard block |
||
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
245 | - * @param $text |
|
246 | - * @param $minChar |
|
245 | + * @param string $text |
|
246 | + * @param integer $minChar |
|
247 | 247 | * @return array |
248 | 248 | */ |
249 | 249 | public function findMetaKeywords($text, $minChar) |
@@ -22,357 +22,357 @@ discard block |
||
22 | 22 | */ |
23 | 23 | class MetaGen |
24 | 24 | { |
25 | - public $_myts; |
|
26 | - |
|
27 | - public $_title; |
|
28 | - public $_original_title; |
|
29 | - public $_keywords; |
|
30 | - public $_meta_description; |
|
31 | - public $_categoryPath; |
|
32 | - public $_description; |
|
33 | - public $_minChar = 4; |
|
34 | - |
|
35 | - /** |
|
36 | - * SmartMetaGen constructor. |
|
37 | - * @param $title |
|
38 | - * @param bool $keywords |
|
39 | - * @param bool $description |
|
40 | - * @param bool $categoryPath |
|
41 | - */ |
|
42 | - public function __construct($title, $keywords = false, $description = false, $categoryPath = false) |
|
43 | - { |
|
44 | - $this->_myts = \MyTextSanitizer::getInstance(); |
|
45 | - $this->setCategoryPath($categoryPath); |
|
46 | - $this->setTitle($title); |
|
47 | - $this->setDescription($description); |
|
48 | - |
|
49 | - if (!$keywords) { |
|
50 | - $keywords = $this->createMetaKeywords(); |
|
51 | - } |
|
52 | - |
|
53 | - /* $myts = \MyTextSanitizer::getInstance(); |
|
25 | + public $_myts; |
|
26 | + |
|
27 | + public $_title; |
|
28 | + public $_original_title; |
|
29 | + public $_keywords; |
|
30 | + public $_meta_description; |
|
31 | + public $_categoryPath; |
|
32 | + public $_description; |
|
33 | + public $_minChar = 4; |
|
34 | + |
|
35 | + /** |
|
36 | + * SmartMetaGen constructor. |
|
37 | + * @param $title |
|
38 | + * @param bool $keywords |
|
39 | + * @param bool $description |
|
40 | + * @param bool $categoryPath |
|
41 | + */ |
|
42 | + public function __construct($title, $keywords = false, $description = false, $categoryPath = false) |
|
43 | + { |
|
44 | + $this->_myts = \MyTextSanitizer::getInstance(); |
|
45 | + $this->setCategoryPath($categoryPath); |
|
46 | + $this->setTitle($title); |
|
47 | + $this->setDescription($description); |
|
48 | + |
|
49 | + if (!$keywords) { |
|
50 | + $keywords = $this->createMetaKeywords(); |
|
51 | + } |
|
52 | + |
|
53 | + /* $myts = \MyTextSanitizer::getInstance(); |
|
54 | 54 | if (method_exists($myts, 'formatForML')) { |
55 | 55 | $keywords = $myts->formatForML($keywords); |
56 | 56 | $description = $myts->formatForML($description); |
57 | 57 | } |
58 | 58 | */ |
59 | - $this->setKeywords($keywords); |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Return true if the string is length > 0 |
|
64 | - * |
|
65 | - * @credit psylove |
|
66 | - * |
|
67 | - * @var string $string Chaine de caract�re |
|
68 | - * @return boolean |
|
69 | - */ |
|
70 | - public function emptyString($var) |
|
71 | - { |
|
72 | - return (strlen($var) > 0); |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Create a title for the short_url field of an article |
|
77 | - * |
|
78 | - * @credit psylove |
|
79 | - * |
|
80 | - * @var string $title title of the article |
|
81 | - * @param bool|string $withExt |
|
82 | - * @return string sort_url for the article |
|
83 | - */ |
|
84 | - public function generateSeoTitle($title = '', $withExt = true) |
|
85 | - { |
|
86 | - // Transformation de la chaine en minuscule |
|
87 | - // Codage de la chaine afin d'éviter les erreurs 500 en cas de caractères imprévus |
|
88 | - $title = rawurlencode(strtolower($title)); |
|
89 | - |
|
90 | - // Transformation des ponctuations |
|
91 | - $pattern = [ |
|
92 | - '/%09/', // Tab |
|
93 | - '/%20/', // Space |
|
94 | - '/%21/', // ! |
|
95 | - '/%22/', // " |
|
96 | - '/%23/', // # |
|
97 | - '/%25/', // % |
|
98 | - '/%26/', // & |
|
99 | - '/%27/', // ' |
|
100 | - '/%28/', // ( |
|
101 | - '/%29/', // ) |
|
102 | - '/%2C/', // , |
|
103 | - '/%2F/', // / |
|
104 | - '/%3A/', // : |
|
105 | - '/%3B/', // ; |
|
106 | - '/%3C/', // < |
|
107 | - '/%3D/', // = |
|
108 | - '/%3E/', // > |
|
109 | - '/%3F/', // ? |
|
110 | - '/%40/', // @ |
|
111 | - '/%5B/', // [ |
|
112 | - '/%5C/', // \ |
|
113 | - '/%5D/', // ] |
|
114 | - '/%5E/', // ^ |
|
115 | - '/%7B/', // { |
|
116 | - '/%7C/', // | |
|
117 | - '/%7D/', // } |
|
118 | - '/%7E/', // ~ |
|
119 | - "/\./" // . |
|
120 | - ]; |
|
121 | - $rep_pat = [ |
|
122 | - '-', |
|
123 | - '-', |
|
124 | - '-', |
|
125 | - '-', |
|
126 | - '-', |
|
127 | - '-100', |
|
128 | - '-', |
|
129 | - '-', |
|
130 | - '-', |
|
131 | - '-', |
|
132 | - '-', |
|
133 | - '-', |
|
134 | - '-', |
|
135 | - '-', |
|
136 | - '-', |
|
137 | - '-', |
|
138 | - '-', |
|
139 | - '-', |
|
140 | - '-at-', |
|
141 | - '-', |
|
142 | - '-', |
|
143 | - '-', |
|
144 | - '-', |
|
145 | - '-', |
|
146 | - '-', |
|
147 | - '-', |
|
148 | - '-', |
|
149 | - '-' |
|
150 | - ]; |
|
151 | - $title = preg_replace($pattern, $rep_pat, $title); |
|
152 | - |
|
153 | - // Transformation des caractères accentués |
|
154 | - $pattern = [ |
|
155 | - '/%B0/', // ° |
|
156 | - '/%E8/', // è |
|
157 | - '/%E9/', // é |
|
158 | - '/%EA/', // ê |
|
159 | - '/%EB/', // ë |
|
160 | - '/%E7/', // ç |
|
161 | - '/%E0/', // à |
|
162 | - '/%E2/', // â |
|
163 | - '/%E4/', // ä |
|
164 | - '/%EE/', // î |
|
165 | - '/%EF/', // ï |
|
166 | - '/%F9/', // ù |
|
167 | - '/%FC/', // ü |
|
168 | - '/%FB/', // û |
|
169 | - '/%F4/', // ô |
|
170 | - '/%F6/', // ö |
|
171 | - ]; |
|
172 | - $rep_pat = ['-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o']; |
|
173 | - $title = preg_replace($pattern, $rep_pat, $title); |
|
174 | - |
|
175 | - $tableau = explode('-', $title); // Transforme la chaine de caract�res en tableau |
|
176 | - $tableau = array_filter($tableau, [$this, 'emptyString']); // Supprime les chaines vides du tableau |
|
177 | - $title = implode('-', $tableau); // Transforme un tableau en chaine de caract�res s�par� par un tiret |
|
178 | - |
|
179 | - if (count($title) > 0) { |
|
180 | - if ($withExt) { |
|
181 | - $title .= '.html'; |
|
182 | - } |
|
183 | - |
|
184 | - return $title; |
|
185 | - } else { |
|
186 | - return ''; |
|
187 | - } |
|
188 | - } |
|
189 | - |
|
190 | - /** |
|
191 | - * @param $document |
|
192 | - * @return mixed |
|
193 | - */ |
|
194 | - public function html2text($document) |
|
195 | - { |
|
196 | - return Smartobject\Utility::getHtml2text($document); |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * @param $title |
|
201 | - */ |
|
202 | - public function setTitle($title) |
|
203 | - { |
|
204 | - global $xoopsModule; |
|
205 | - /** @var Smartobject\Helper $helper */ |
|
206 | - $helper = Smartobject\Helper::getInstance(); |
|
207 | - |
|
208 | - $this->_title = $this->html2text($title); |
|
209 | - $this->_title = $this->purifyText($this->_title); |
|
210 | - $this->_original_title = $this->_title; |
|
211 | - |
|
212 | - $moduleName = $xoopsModule->getVar('name'); |
|
213 | - |
|
214 | - $titleTag = []; |
|
215 | - |
|
216 | - $show_mod_name_breadcrumb = null !==($helper->getConfig('show_mod_name_breadcrumb')) ? $helper->getConfig('show_mod_name_breadcrumb') : true; |
|
217 | - |
|
218 | - if ($moduleName && $show_mod_name_breadcrumb) { |
|
219 | - $titleTag['module'] = $moduleName; |
|
220 | - } |
|
221 | - |
|
222 | - if (isset($this->_title) && ('' !== $this->_title) && (strtoupper($this->_title) != strtoupper($moduleName))) { |
|
223 | - $titleTag['title'] = $this->_title; |
|
224 | - } |
|
225 | - |
|
226 | - if (isset($this->_categoryPath) && ('' !== $this->_categoryPath)) { |
|
227 | - $titleTag['category'] = $this->_categoryPath; |
|
228 | - } |
|
229 | - |
|
230 | - $ret = isset($titleTag['title']) ? $titleTag['title'] : ''; |
|
231 | - |
|
232 | - if (isset($titleTag['category']) && '' !== $titleTag['category']) { |
|
233 | - if ('' !== $ret) { |
|
234 | - $ret .= ' - '; |
|
235 | - } |
|
236 | - $ret .= $titleTag['category']; |
|
237 | - } |
|
238 | - if (isset($titleTag['module']) && '' !== $titleTag['module']) { |
|
239 | - if ('' !== $ret) { |
|
240 | - $ret .= ' - '; |
|
241 | - } |
|
242 | - $ret .= $titleTag['module']; |
|
243 | - } |
|
244 | - $this->_title = $ret; |
|
245 | - } |
|
246 | - |
|
247 | - /** |
|
248 | - * @param $keywords |
|
249 | - */ |
|
250 | - public function setKeywords($keywords) |
|
251 | - { |
|
252 | - $this->_keywords = $keywords; |
|
253 | - } |
|
254 | - |
|
255 | - /** |
|
256 | - * @param $categoryPath |
|
257 | - */ |
|
258 | - public function setCategoryPath($categoryPath) |
|
259 | - { |
|
260 | - $categoryPath = $this->html2text($categoryPath); |
|
261 | - $this->_categoryPath = $categoryPath; |
|
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * @param $description |
|
266 | - */ |
|
267 | - public function setDescription($description) |
|
268 | - { |
|
269 | - if (!$description) { |
|
270 | - /** @var Smartobject\Helper $helper */ |
|
271 | - $helper = Smartobject\Helper::getInstance(); |
|
272 | - |
|
273 | - if (null !== ($helper->getConfig('module_meta_description'))) { |
|
274 | - $description = $helper->getConfig('module_meta_description'); |
|
275 | - } |
|
276 | - } |
|
277 | - |
|
278 | - $description = $this->html2text($description); |
|
279 | - $description = $this->purifyText($description); |
|
280 | - |
|
281 | - $description = preg_replace("/([^\r\n])\r\n([^\r\n])/", "\\1 \\2", $description); |
|
282 | - $description = preg_replace("/[\r\n]*\r\n[\r\n]*/", "\r\n\r\n", $description); |
|
283 | - $description = preg_replace('/[ ]* [ ]*/', ' ', $description); |
|
284 | - $description = stripslashes($description); |
|
285 | - |
|
286 | - $this->_description = $description; |
|
287 | - $this->_meta_description = $this->createMetaDescription(); |
|
288 | - } |
|
289 | - |
|
290 | - public function createTitleTag() |
|
291 | - { |
|
292 | - } |
|
293 | - |
|
294 | - /** |
|
295 | - * @param $text |
|
296 | - * @param bool $keyword |
|
297 | - * @return mixed|string |
|
298 | - */ |
|
299 | - public function purifyText($text, $keyword = false) |
|
300 | - { |
|
301 | - return Smartobject\Utility::purifyText($text, $keyword); |
|
302 | - } |
|
303 | - |
|
304 | - /** |
|
305 | - * @param int $maxWords |
|
306 | - * @return string |
|
307 | - */ |
|
308 | - public function createMetaDescription($maxWords = 100) |
|
309 | - { |
|
310 | - $words = []; |
|
311 | - $words = explode(' ', $this->_description); |
|
312 | - |
|
313 | - // Only keep $maxWords words |
|
314 | - $newWords = []; |
|
315 | - $i = 0; |
|
316 | - |
|
317 | - while ($i < $maxWords - 1 && $i < count($words)) { |
|
318 | - $newWords[] = $words[$i]; |
|
319 | - ++$i; |
|
320 | - } |
|
321 | - $ret = implode(' ', $newWords); |
|
322 | - |
|
323 | - return $ret; |
|
324 | - } |
|
325 | - |
|
326 | - /** |
|
327 | - * @param $text |
|
328 | - * @param $minChar |
|
329 | - * @return array |
|
330 | - */ |
|
331 | - public function findMetaKeywords($text, $minChar) |
|
332 | - { |
|
333 | - $keywords = []; |
|
334 | - |
|
335 | - $text = $this->purifyText($text); |
|
336 | - $text = $this->html2text($text); |
|
337 | - |
|
338 | - $text = preg_replace("/([^\r\n])\r\n([^\r\n])/", "\\1 \\2", $text); |
|
339 | - $text = preg_replace("/[\r\n]*\r\n[\r\n]*/", "\r\n\r\n", $text); |
|
340 | - $text = preg_replace('/[ ]* [ ]*/', ' ', $text); |
|
341 | - $text = stripslashes($text); |
|
342 | - $text = |
|
343 | - |
|
344 | - $originalKeywords = preg_split('/[^a-zA-Z\'"-]+/', $text, -1, PREG_SPLIT_NO_EMPTY); |
|
345 | - |
|
346 | - foreach ($originalKeywords as $originalKeyword) { |
|
347 | - $secondRoundKeywords = explode("'", $originalKeyword); |
|
348 | - foreach ($secondRoundKeywords as $secondRoundKeyword) { |
|
349 | - if (strlen($secondRoundKeyword) >= $minChar) { |
|
350 | - if (!in_array($secondRoundKeyword, $keywords)) { |
|
351 | - $keywords[] = trim($secondRoundKeyword); |
|
352 | - } |
|
353 | - } |
|
354 | - } |
|
355 | - } |
|
356 | - |
|
357 | - return $keywords; |
|
358 | - } |
|
359 | - |
|
360 | - /** |
|
361 | - * @return string |
|
362 | - */ |
|
363 | - public function createMetaKeywords() |
|
364 | - { |
|
365 | - /** @var Smartobject\Helper $helper */ |
|
366 | - $helper = Smartobject\Helper::getInstance(); |
|
367 | - |
|
368 | - $keywords = $this->findMetaKeywords($this->_original_title . ' ' . $this->_description, $this->_minChar); |
|
369 | - if (null !== ($helper->getModule()) && null !== ($helper->getConfig('moduleMetaKeywords')) |
|
370 | - && '' !== $helper->getConfig('moduleMetaKeywords')) { |
|
371 | - $moduleKeywords = explode(',', $helper->getConfig('moduleMetaKeywords')); |
|
372 | - $keywords = array_merge($keywords, $moduleKeywords); |
|
373 | - } |
|
374 | - |
|
375 | - /* Commenting this out as it may cause problem on XOOPS ML websites |
|
59 | + $this->setKeywords($keywords); |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Return true if the string is length > 0 |
|
64 | + * |
|
65 | + * @credit psylove |
|
66 | + * |
|
67 | + * @var string $string Chaine de caract�re |
|
68 | + * @return boolean |
|
69 | + */ |
|
70 | + public function emptyString($var) |
|
71 | + { |
|
72 | + return (strlen($var) > 0); |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Create a title for the short_url field of an article |
|
77 | + * |
|
78 | + * @credit psylove |
|
79 | + * |
|
80 | + * @var string $title title of the article |
|
81 | + * @param bool|string $withExt |
|
82 | + * @return string sort_url for the article |
|
83 | + */ |
|
84 | + public function generateSeoTitle($title = '', $withExt = true) |
|
85 | + { |
|
86 | + // Transformation de la chaine en minuscule |
|
87 | + // Codage de la chaine afin d'éviter les erreurs 500 en cas de caractères imprévus |
|
88 | + $title = rawurlencode(strtolower($title)); |
|
89 | + |
|
90 | + // Transformation des ponctuations |
|
91 | + $pattern = [ |
|
92 | + '/%09/', // Tab |
|
93 | + '/%20/', // Space |
|
94 | + '/%21/', // ! |
|
95 | + '/%22/', // " |
|
96 | + '/%23/', // # |
|
97 | + '/%25/', // % |
|
98 | + '/%26/', // & |
|
99 | + '/%27/', // ' |
|
100 | + '/%28/', // ( |
|
101 | + '/%29/', // ) |
|
102 | + '/%2C/', // , |
|
103 | + '/%2F/', // / |
|
104 | + '/%3A/', // : |
|
105 | + '/%3B/', // ; |
|
106 | + '/%3C/', // < |
|
107 | + '/%3D/', // = |
|
108 | + '/%3E/', // > |
|
109 | + '/%3F/', // ? |
|
110 | + '/%40/', // @ |
|
111 | + '/%5B/', // [ |
|
112 | + '/%5C/', // \ |
|
113 | + '/%5D/', // ] |
|
114 | + '/%5E/', // ^ |
|
115 | + '/%7B/', // { |
|
116 | + '/%7C/', // | |
|
117 | + '/%7D/', // } |
|
118 | + '/%7E/', // ~ |
|
119 | + "/\./" // . |
|
120 | + ]; |
|
121 | + $rep_pat = [ |
|
122 | + '-', |
|
123 | + '-', |
|
124 | + '-', |
|
125 | + '-', |
|
126 | + '-', |
|
127 | + '-100', |
|
128 | + '-', |
|
129 | + '-', |
|
130 | + '-', |
|
131 | + '-', |
|
132 | + '-', |
|
133 | + '-', |
|
134 | + '-', |
|
135 | + '-', |
|
136 | + '-', |
|
137 | + '-', |
|
138 | + '-', |
|
139 | + '-', |
|
140 | + '-at-', |
|
141 | + '-', |
|
142 | + '-', |
|
143 | + '-', |
|
144 | + '-', |
|
145 | + '-', |
|
146 | + '-', |
|
147 | + '-', |
|
148 | + '-', |
|
149 | + '-' |
|
150 | + ]; |
|
151 | + $title = preg_replace($pattern, $rep_pat, $title); |
|
152 | + |
|
153 | + // Transformation des caractères accentués |
|
154 | + $pattern = [ |
|
155 | + '/%B0/', // ° |
|
156 | + '/%E8/', // è |
|
157 | + '/%E9/', // é |
|
158 | + '/%EA/', // ê |
|
159 | + '/%EB/', // ë |
|
160 | + '/%E7/', // ç |
|
161 | + '/%E0/', // à |
|
162 | + '/%E2/', // â |
|
163 | + '/%E4/', // ä |
|
164 | + '/%EE/', // î |
|
165 | + '/%EF/', // ï |
|
166 | + '/%F9/', // ù |
|
167 | + '/%FC/', // ü |
|
168 | + '/%FB/', // û |
|
169 | + '/%F4/', // ô |
|
170 | + '/%F6/', // ö |
|
171 | + ]; |
|
172 | + $rep_pat = ['-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o']; |
|
173 | + $title = preg_replace($pattern, $rep_pat, $title); |
|
174 | + |
|
175 | + $tableau = explode('-', $title); // Transforme la chaine de caract�res en tableau |
|
176 | + $tableau = array_filter($tableau, [$this, 'emptyString']); // Supprime les chaines vides du tableau |
|
177 | + $title = implode('-', $tableau); // Transforme un tableau en chaine de caract�res s�par� par un tiret |
|
178 | + |
|
179 | + if (count($title) > 0) { |
|
180 | + if ($withExt) { |
|
181 | + $title .= '.html'; |
|
182 | + } |
|
183 | + |
|
184 | + return $title; |
|
185 | + } else { |
|
186 | + return ''; |
|
187 | + } |
|
188 | + } |
|
189 | + |
|
190 | + /** |
|
191 | + * @param $document |
|
192 | + * @return mixed |
|
193 | + */ |
|
194 | + public function html2text($document) |
|
195 | + { |
|
196 | + return Smartobject\Utility::getHtml2text($document); |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * @param $title |
|
201 | + */ |
|
202 | + public function setTitle($title) |
|
203 | + { |
|
204 | + global $xoopsModule; |
|
205 | + /** @var Smartobject\Helper $helper */ |
|
206 | + $helper = Smartobject\Helper::getInstance(); |
|
207 | + |
|
208 | + $this->_title = $this->html2text($title); |
|
209 | + $this->_title = $this->purifyText($this->_title); |
|
210 | + $this->_original_title = $this->_title; |
|
211 | + |
|
212 | + $moduleName = $xoopsModule->getVar('name'); |
|
213 | + |
|
214 | + $titleTag = []; |
|
215 | + |
|
216 | + $show_mod_name_breadcrumb = null !==($helper->getConfig('show_mod_name_breadcrumb')) ? $helper->getConfig('show_mod_name_breadcrumb') : true; |
|
217 | + |
|
218 | + if ($moduleName && $show_mod_name_breadcrumb) { |
|
219 | + $titleTag['module'] = $moduleName; |
|
220 | + } |
|
221 | + |
|
222 | + if (isset($this->_title) && ('' !== $this->_title) && (strtoupper($this->_title) != strtoupper($moduleName))) { |
|
223 | + $titleTag['title'] = $this->_title; |
|
224 | + } |
|
225 | + |
|
226 | + if (isset($this->_categoryPath) && ('' !== $this->_categoryPath)) { |
|
227 | + $titleTag['category'] = $this->_categoryPath; |
|
228 | + } |
|
229 | + |
|
230 | + $ret = isset($titleTag['title']) ? $titleTag['title'] : ''; |
|
231 | + |
|
232 | + if (isset($titleTag['category']) && '' !== $titleTag['category']) { |
|
233 | + if ('' !== $ret) { |
|
234 | + $ret .= ' - '; |
|
235 | + } |
|
236 | + $ret .= $titleTag['category']; |
|
237 | + } |
|
238 | + if (isset($titleTag['module']) && '' !== $titleTag['module']) { |
|
239 | + if ('' !== $ret) { |
|
240 | + $ret .= ' - '; |
|
241 | + } |
|
242 | + $ret .= $titleTag['module']; |
|
243 | + } |
|
244 | + $this->_title = $ret; |
|
245 | + } |
|
246 | + |
|
247 | + /** |
|
248 | + * @param $keywords |
|
249 | + */ |
|
250 | + public function setKeywords($keywords) |
|
251 | + { |
|
252 | + $this->_keywords = $keywords; |
|
253 | + } |
|
254 | + |
|
255 | + /** |
|
256 | + * @param $categoryPath |
|
257 | + */ |
|
258 | + public function setCategoryPath($categoryPath) |
|
259 | + { |
|
260 | + $categoryPath = $this->html2text($categoryPath); |
|
261 | + $this->_categoryPath = $categoryPath; |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * @param $description |
|
266 | + */ |
|
267 | + public function setDescription($description) |
|
268 | + { |
|
269 | + if (!$description) { |
|
270 | + /** @var Smartobject\Helper $helper */ |
|
271 | + $helper = Smartobject\Helper::getInstance(); |
|
272 | + |
|
273 | + if (null !== ($helper->getConfig('module_meta_description'))) { |
|
274 | + $description = $helper->getConfig('module_meta_description'); |
|
275 | + } |
|
276 | + } |
|
277 | + |
|
278 | + $description = $this->html2text($description); |
|
279 | + $description = $this->purifyText($description); |
|
280 | + |
|
281 | + $description = preg_replace("/([^\r\n])\r\n([^\r\n])/", "\\1 \\2", $description); |
|
282 | + $description = preg_replace("/[\r\n]*\r\n[\r\n]*/", "\r\n\r\n", $description); |
|
283 | + $description = preg_replace('/[ ]* [ ]*/', ' ', $description); |
|
284 | + $description = stripslashes($description); |
|
285 | + |
|
286 | + $this->_description = $description; |
|
287 | + $this->_meta_description = $this->createMetaDescription(); |
|
288 | + } |
|
289 | + |
|
290 | + public function createTitleTag() |
|
291 | + { |
|
292 | + } |
|
293 | + |
|
294 | + /** |
|
295 | + * @param $text |
|
296 | + * @param bool $keyword |
|
297 | + * @return mixed|string |
|
298 | + */ |
|
299 | + public function purifyText($text, $keyword = false) |
|
300 | + { |
|
301 | + return Smartobject\Utility::purifyText($text, $keyword); |
|
302 | + } |
|
303 | + |
|
304 | + /** |
|
305 | + * @param int $maxWords |
|
306 | + * @return string |
|
307 | + */ |
|
308 | + public function createMetaDescription($maxWords = 100) |
|
309 | + { |
|
310 | + $words = []; |
|
311 | + $words = explode(' ', $this->_description); |
|
312 | + |
|
313 | + // Only keep $maxWords words |
|
314 | + $newWords = []; |
|
315 | + $i = 0; |
|
316 | + |
|
317 | + while ($i < $maxWords - 1 && $i < count($words)) { |
|
318 | + $newWords[] = $words[$i]; |
|
319 | + ++$i; |
|
320 | + } |
|
321 | + $ret = implode(' ', $newWords); |
|
322 | + |
|
323 | + return $ret; |
|
324 | + } |
|
325 | + |
|
326 | + /** |
|
327 | + * @param $text |
|
328 | + * @param $minChar |
|
329 | + * @return array |
|
330 | + */ |
|
331 | + public function findMetaKeywords($text, $minChar) |
|
332 | + { |
|
333 | + $keywords = []; |
|
334 | + |
|
335 | + $text = $this->purifyText($text); |
|
336 | + $text = $this->html2text($text); |
|
337 | + |
|
338 | + $text = preg_replace("/([^\r\n])\r\n([^\r\n])/", "\\1 \\2", $text); |
|
339 | + $text = preg_replace("/[\r\n]*\r\n[\r\n]*/", "\r\n\r\n", $text); |
|
340 | + $text = preg_replace('/[ ]* [ ]*/', ' ', $text); |
|
341 | + $text = stripslashes($text); |
|
342 | + $text = |
|
343 | + |
|
344 | + $originalKeywords = preg_split('/[^a-zA-Z\'"-]+/', $text, -1, PREG_SPLIT_NO_EMPTY); |
|
345 | + |
|
346 | + foreach ($originalKeywords as $originalKeyword) { |
|
347 | + $secondRoundKeywords = explode("'", $originalKeyword); |
|
348 | + foreach ($secondRoundKeywords as $secondRoundKeyword) { |
|
349 | + if (strlen($secondRoundKeyword) >= $minChar) { |
|
350 | + if (!in_array($secondRoundKeyword, $keywords)) { |
|
351 | + $keywords[] = trim($secondRoundKeyword); |
|
352 | + } |
|
353 | + } |
|
354 | + } |
|
355 | + } |
|
356 | + |
|
357 | + return $keywords; |
|
358 | + } |
|
359 | + |
|
360 | + /** |
|
361 | + * @return string |
|
362 | + */ |
|
363 | + public function createMetaKeywords() |
|
364 | + { |
|
365 | + /** @var Smartobject\Helper $helper */ |
|
366 | + $helper = Smartobject\Helper::getInstance(); |
|
367 | + |
|
368 | + $keywords = $this->findMetaKeywords($this->_original_title . ' ' . $this->_description, $this->_minChar); |
|
369 | + if (null !== ($helper->getModule()) && null !== ($helper->getConfig('moduleMetaKeywords')) |
|
370 | + && '' !== $helper->getConfig('moduleMetaKeywords')) { |
|
371 | + $moduleKeywords = explode(',', $helper->getConfig('moduleMetaKeywords')); |
|
372 | + $keywords = array_merge($keywords, $moduleKeywords); |
|
373 | + } |
|
374 | + |
|
375 | + /* Commenting this out as it may cause problem on XOOPS ML websites |
|
376 | 376 | $return_keywords = array(); |
377 | 377 | |
378 | 378 | // Cleaning for duplicate keywords |
@@ -382,45 +382,45 @@ discard block |
||
382 | 382 | } |
383 | 383 | }*/ |
384 | 384 | |
385 | - // Only take the first 90 keywords |
|
386 | - $newKeywords = []; |
|
387 | - $i = 0; |
|
388 | - while ($i < 90 - 1 && isset($keywords[$i])) { |
|
389 | - $newKeywords[] = $keywords[$i]; |
|
390 | - ++$i; |
|
391 | - } |
|
392 | - $ret = implode(', ', $newKeywords); |
|
393 | - |
|
394 | - return $ret; |
|
395 | - } |
|
396 | - |
|
397 | - public function autoBuildMeta_keywords() |
|
398 | - { |
|
399 | - } |
|
400 | - |
|
401 | - public function buildAutoMetaTags() |
|
402 | - { |
|
403 | - global $xoopsModule; |
|
404 | - /** @var Smartobject\Helper $helper */ |
|
405 | - $helper = Smartobject\Helper::getInstance(); |
|
406 | - |
|
407 | - $this->_keywords = $this->createMetaKeywords(); |
|
408 | - $this->_meta_description = $this->createMetaDescription(); |
|
409 | - $this->_title = $this->createTitleTag(); |
|
410 | - } |
|
411 | - |
|
412 | - public function createMetaTags() |
|
413 | - { |
|
414 | - global $xoopsTpl, $xoTheme; |
|
415 | - |
|
416 | - if (is_object($xoTheme)) { |
|
417 | - $xoTheme->addMeta('meta', 'keywords', $this->_keywords); |
|
418 | - $xoTheme->addMeta('meta', 'description', $this->_description); |
|
419 | - $xoTheme->addMeta('meta', 'title', $this->_title); |
|
420 | - } else { |
|
421 | - $xoopsTpl->assign('xoops_meta_keywords', $this->_keywords); |
|
422 | - $xoopsTpl->assign('xoops_meta_description', $this->_description); |
|
423 | - } |
|
424 | - $xoopsTpl->assign('xoops_pagetitle', $this->_title); |
|
425 | - } |
|
385 | + // Only take the first 90 keywords |
|
386 | + $newKeywords = []; |
|
387 | + $i = 0; |
|
388 | + while ($i < 90 - 1 && isset($keywords[$i])) { |
|
389 | + $newKeywords[] = $keywords[$i]; |
|
390 | + ++$i; |
|
391 | + } |
|
392 | + $ret = implode(', ', $newKeywords); |
|
393 | + |
|
394 | + return $ret; |
|
395 | + } |
|
396 | + |
|
397 | + public function autoBuildMeta_keywords() |
|
398 | + { |
|
399 | + } |
|
400 | + |
|
401 | + public function buildAutoMetaTags() |
|
402 | + { |
|
403 | + global $xoopsModule; |
|
404 | + /** @var Smartobject\Helper $helper */ |
|
405 | + $helper = Smartobject\Helper::getInstance(); |
|
406 | + |
|
407 | + $this->_keywords = $this->createMetaKeywords(); |
|
408 | + $this->_meta_description = $this->createMetaDescription(); |
|
409 | + $this->_title = $this->createTitleTag(); |
|
410 | + } |
|
411 | + |
|
412 | + public function createMetaTags() |
|
413 | + { |
|
414 | + global $xoopsTpl, $xoTheme; |
|
415 | + |
|
416 | + if (is_object($xoTheme)) { |
|
417 | + $xoTheme->addMeta('meta', 'keywords', $this->_keywords); |
|
418 | + $xoTheme->addMeta('meta', 'description', $this->_description); |
|
419 | + $xoTheme->addMeta('meta', 'title', $this->_title); |
|
420 | + } else { |
|
421 | + $xoopsTpl->assign('xoops_meta_keywords', $this->_keywords); |
|
422 | + $xoopsTpl->assign('xoops_meta_description', $this->_description); |
|
423 | + } |
|
424 | + $xoopsTpl->assign('xoops_pagetitle', $this->_title); |
|
425 | + } |
|
426 | 426 | } |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | |
214 | 214 | $titleTag = []; |
215 | 215 | |
216 | - $show_mod_name_breadcrumb = null !==($helper->getConfig('show_mod_name_breadcrumb')) ? $helper->getConfig('show_mod_name_breadcrumb') : true; |
|
216 | + $show_mod_name_breadcrumb = null !== ($helper->getConfig('show_mod_name_breadcrumb')) ? $helper->getConfig('show_mod_name_breadcrumb') : true; |
|
217 | 217 | |
218 | 218 | if ($moduleName && $show_mod_name_breadcrumb) { |
219 | 219 | $titleTag['module'] = $moduleName; |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | /** @var Smartobject\Helper $helper */ |
271 | 271 | $helper = Smartobject\Helper::getInstance(); |
272 | 272 | |
273 | - if (null !== ($helper->getConfig('module_meta_description'))) { |
|
273 | + if (null !== ($helper->getConfig('module_meta_description'))) { |
|
274 | 274 | $description = $helper->getConfig('module_meta_description'); |
275 | 275 | } |
276 | 276 | } |
@@ -365,7 +365,7 @@ discard block |
||
365 | 365 | /** @var Smartobject\Helper $helper */ |
366 | 366 | $helper = Smartobject\Helper::getInstance(); |
367 | 367 | |
368 | - $keywords = $this->findMetaKeywords($this->_original_title . ' ' . $this->_description, $this->_minChar); |
|
368 | + $keywords = $this->findMetaKeywords($this->_original_title.' '.$this->_description, $this->_minChar); |
|
369 | 369 | if (null !== ($helper->getModule()) && null !== ($helper->getConfig('moduleMetaKeywords')) |
370 | 370 | && '' !== $helper->getConfig('moduleMetaKeywords')) { |
371 | 371 | $moduleKeywords = explode(',', $helper->getConfig('moduleMetaKeywords')); |
@@ -33,7 +33,7 @@ |
||
33 | 33 | |
34 | 34 | /** |
35 | 35 | * SmartObjectColumn constructor. |
36 | - * @param $keyname |
|
36 | + * @param string $keyname |
|
37 | 37 | * @param string $align |
38 | 38 | * @param bool $width |
39 | 39 | * @param bool $customMethodForValue |
@@ -23,82 +23,82 @@ |
||
23 | 23 | */ |
24 | 24 | class ObjectColumn |
25 | 25 | { |
26 | - public $_keyname; |
|
27 | - public $_align; |
|
28 | - public $_width; |
|
29 | - public $_customMethodForValue; |
|
30 | - public $_extraParams; |
|
31 | - public $_sortable; |
|
32 | - public $_customCaption; |
|
26 | + public $_keyname; |
|
27 | + public $_align; |
|
28 | + public $_width; |
|
29 | + public $_customMethodForValue; |
|
30 | + public $_extraParams; |
|
31 | + public $_sortable; |
|
32 | + public $_customCaption; |
|
33 | 33 | |
34 | - /** |
|
35 | - * SmartObjectColumn constructor. |
|
36 | - * @param $keyname |
|
37 | - * @param string $align |
|
38 | - * @param bool $width |
|
39 | - * @param bool $customMethodForValue |
|
40 | - * @param bool $param |
|
41 | - * @param bool $customCaption |
|
42 | - * @param bool $sortable |
|
43 | - */ |
|
44 | - public function __construct( |
|
45 | - $keyname, |
|
46 | - $align = 'left', |
|
47 | - $width = false, |
|
48 | - $customMethodForValue = false, |
|
49 | - $param = false, |
|
50 | - $customCaption = false, |
|
51 | - $sortable = true |
|
52 | - ) { |
|
53 | - $this->_keyname = $keyname; |
|
54 | - $this->_align = $align; |
|
55 | - $this->_width = $width; |
|
56 | - $this->_customMethodForValue = $customMethodForValue; |
|
57 | - $this->_sortable = $sortable; |
|
58 | - $this->_param = $param; |
|
59 | - $this->_customCaption = $customCaption; |
|
60 | - } |
|
34 | + /** |
|
35 | + * SmartObjectColumn constructor. |
|
36 | + * @param $keyname |
|
37 | + * @param string $align |
|
38 | + * @param bool $width |
|
39 | + * @param bool $customMethodForValue |
|
40 | + * @param bool $param |
|
41 | + * @param bool $customCaption |
|
42 | + * @param bool $sortable |
|
43 | + */ |
|
44 | + public function __construct( |
|
45 | + $keyname, |
|
46 | + $align = 'left', |
|
47 | + $width = false, |
|
48 | + $customMethodForValue = false, |
|
49 | + $param = false, |
|
50 | + $customCaption = false, |
|
51 | + $sortable = true |
|
52 | + ) { |
|
53 | + $this->_keyname = $keyname; |
|
54 | + $this->_align = $align; |
|
55 | + $this->_width = $width; |
|
56 | + $this->_customMethodForValue = $customMethodForValue; |
|
57 | + $this->_sortable = $sortable; |
|
58 | + $this->_param = $param; |
|
59 | + $this->_customCaption = $customCaption; |
|
60 | + } |
|
61 | 61 | |
62 | - public function getKeyName() |
|
63 | - { |
|
64 | - return $this->_keyname; |
|
65 | - } |
|
62 | + public function getKeyName() |
|
63 | + { |
|
64 | + return $this->_keyname; |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * @return string |
|
69 | - */ |
|
70 | - public function getAlign() |
|
71 | - { |
|
72 | - return $this->_align; |
|
73 | - } |
|
67 | + /** |
|
68 | + * @return string |
|
69 | + */ |
|
70 | + public function getAlign() |
|
71 | + { |
|
72 | + return $this->_align; |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * @return bool |
|
77 | - */ |
|
78 | - public function isSortable() |
|
79 | - { |
|
80 | - return $this->_sortable; |
|
81 | - } |
|
75 | + /** |
|
76 | + * @return bool |
|
77 | + */ |
|
78 | + public function isSortable() |
|
79 | + { |
|
80 | + return $this->_sortable; |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * @return bool|string |
|
85 | - */ |
|
86 | - public function getWidth() |
|
87 | - { |
|
88 | - if ($this->_width) { |
|
89 | - $ret = $this->_width; |
|
90 | - } else { |
|
91 | - $ret = ''; |
|
92 | - } |
|
83 | + /** |
|
84 | + * @return bool|string |
|
85 | + */ |
|
86 | + public function getWidth() |
|
87 | + { |
|
88 | + if ($this->_width) { |
|
89 | + $ret = $this->_width; |
|
90 | + } else { |
|
91 | + $ret = ''; |
|
92 | + } |
|
93 | 93 | |
94 | - return $ret; |
|
95 | - } |
|
94 | + return $ret; |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * @return bool |
|
99 | - */ |
|
100 | - public function getCustomCaption() |
|
101 | - { |
|
102 | - return $this->_customCaption; |
|
103 | - } |
|
97 | + /** |
|
98 | + * @return bool |
|
99 | + */ |
|
100 | + public function getCustomCaption() |
|
101 | + { |
|
102 | + return $this->_customCaption; |
|
103 | + } |
|
104 | 104 | } |
@@ -126,9 +126,9 @@ discard block |
||
126 | 126 | |
127 | 127 | /** |
128 | 128 | * @param $smartObj |
129 | - * @param $objectid |
|
130 | - * @param $created_success_msg |
|
131 | - * @param $modified_success_msg |
|
129 | + * @param integer $objectid |
|
130 | + * @param string $created_success_msg |
|
131 | + * @param string $modified_success_msg |
|
132 | 132 | * @param bool $redirect_page |
133 | 133 | * @param bool $debug |
134 | 134 | * @return mixed |
@@ -440,7 +440,7 @@ discard block |
||
440 | 440 | } |
441 | 441 | |
442 | 442 | /** |
443 | - * @param $smartObj |
|
443 | + * @param MlObject $smartObj |
|
444 | 444 | * @param bool $onlyUrl |
445 | 445 | * @param bool $withimage |
446 | 446 | * @return string |
@@ -498,7 +498,7 @@ discard block |
||
498 | 498 | } |
499 | 499 | |
500 | 500 | /** |
501 | - * @param $smartObj |
|
501 | + * @param BaseSmartObject $smartObj |
|
502 | 502 | * @return string |
503 | 503 | */ |
504 | 504 | public function getPrintAndMailLink($smartObj) |
@@ -33,511 +33,511 @@ |
||
33 | 33 | */ |
34 | 34 | class ObjectController |
35 | 35 | { |
36 | - public $handler; |
|
37 | - |
|
38 | - /** |
|
39 | - * SmartObjectController constructor. |
|
40 | - * @param $handler |
|
41 | - */ |
|
42 | - public function __construct($handler) |
|
43 | - { |
|
44 | - $this->handler = $handler; |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * @param $smartObj |
|
49 | - */ |
|
50 | - public function postDataToObject(&$smartObj) |
|
51 | - { |
|
52 | - foreach (array_keys($smartObj->vars) as $key) { |
|
53 | - switch ($smartObj->vars[$key]['data_type']) { |
|
54 | - case XOBJ_DTYPE_IMAGE: |
|
55 | - if (isset($_POST['url_' . $key]) && '' !== $_POST['url_' . $key]) { |
|
56 | - $oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e'); |
|
57 | - $smartObj->setVar($key, $_POST['url_' . $key]); |
|
58 | - if (file_exists($oldFile)) { |
|
59 | - unlink($oldFile); |
|
60 | - } |
|
61 | - } |
|
62 | - if (isset($_POST['delete_' . $key]) && '1' == $_POST['delete_' . $key]) { |
|
63 | - $oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e'); |
|
64 | - $smartObj->setVar($key, ''); |
|
65 | - if (file_exists($oldFile)) { |
|
66 | - unlink($oldFile); |
|
67 | - } |
|
68 | - } |
|
69 | - break; |
|
70 | - |
|
71 | - case XOBJ_DTYPE_URLLINK: |
|
72 | - $linkObj = $smartObj->getUrlLinkObj($key); |
|
73 | - $linkObj->setVar('caption', $_POST['caption_' . $key]); |
|
74 | - $linkObj->setVar('description', $_POST['desc_' . $key]); |
|
75 | - $linkObj->setVar('target', $_POST['target_' . $key]); |
|
76 | - $linkObj->setVar('url', $_POST['url_' . $key]); |
|
77 | - if ('' !== $linkObj->getVar('url')) { |
|
78 | - $smartObj->storeUrlLinkObj($linkObj); |
|
79 | - } |
|
80 | - //todo: catch errors |
|
81 | - $smartObj->setVar($key, $linkObj->getVar('urllinkid')); |
|
82 | - break; |
|
83 | - |
|
84 | - case XOBJ_DTYPE_FILE: |
|
85 | - if (!isset($_FILES['upload_' . $key]['name']) || '' === $_FILES['upload_' . $key]['name']) { |
|
86 | - $fileObj = $smartObj->getFileObj($key); |
|
87 | - $fileObj->setVar('caption', $_POST['caption_' . $key]); |
|
88 | - $fileObj->setVar('description', $_POST['desc_' . $key]); |
|
89 | - $fileObj->setVar('url', $_POST['url_' . $key]); |
|
90 | - if (!('' === $fileObj->getVar('url') && '' === $fileObj->getVar('url') |
|
91 | - && '' === $fileObj->getVar('url'))) { |
|
92 | - $res = $smartObj->storeFileObj($fileObj); |
|
93 | - if ($res) { |
|
94 | - $smartObj->setVar($key, $fileObj->getVar('fileid')); |
|
95 | - } else { |
|
96 | - //error setted, but no error message (to be improved) |
|
97 | - $smartObj->setErrors($fileObj->getErrors()); |
|
98 | - } |
|
99 | - } |
|
100 | - } |
|
101 | - break; |
|
102 | - |
|
103 | - case XOBJ_DTYPE_STIME: |
|
104 | - case XOBJ_DTYPE_MTIME: |
|
105 | - case XOBJ_DTYPE_LTIME: |
|
106 | - // check if this field's value is available in the POST array |
|
107 | - if (is_array($_POST[$key]) && isset($_POST[$key]['date'])) { |
|
108 | - $value = strtotime($_POST[$key]['date']) + $_POST[$key]['time']; |
|
109 | - } else { |
|
110 | - $value = strtotime($_POST[$key]); |
|
111 | - //if strtotime returns false, the value is already a time stamp |
|
112 | - if (!$value) { |
|
113 | - $value = (int)$_POST[$key]; |
|
114 | - } |
|
115 | - } |
|
116 | - $smartObj->setVar($key, $value); |
|
117 | - |
|
118 | - break; |
|
119 | - |
|
120 | - default: |
|
121 | - $smartObj->setVar($key, $_POST[$key]); |
|
122 | - break; |
|
123 | - } |
|
124 | - } |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * @param $smartObj |
|
129 | - * @param $objectid |
|
130 | - * @param $created_success_msg |
|
131 | - * @param $modified_success_msg |
|
132 | - * @param bool $redirect_page |
|
133 | - * @param bool $debug |
|
134 | - * @return mixed |
|
135 | - */ |
|
136 | - public function doStoreFromDefaultForm( |
|
137 | - &$smartObj, |
|
138 | - $objectid, |
|
139 | - $created_success_msg, |
|
140 | - $modified_success_msg, |
|
141 | - $redirect_page = false, |
|
142 | - $debug = false |
|
143 | - ) { |
|
144 | - global $smart_previous_page; |
|
145 | - |
|
146 | - $this->postDataToObject($smartObj); |
|
147 | - |
|
148 | - if ($smartObj->isNew()) { |
|
149 | - $redirect_msg = $created_success_msg; |
|
150 | - } else { |
|
151 | - $redirect_msg = $modified_success_msg; |
|
152 | - } |
|
153 | - |
|
154 | - // Check if there were uploaded files |
|
155 | - if (isset($_POST['smart_upload_image']) || isset($_POST['smart_upload_file'])) { |
|
36 | + public $handler; |
|
37 | + |
|
38 | + /** |
|
39 | + * SmartObjectController constructor. |
|
40 | + * @param $handler |
|
41 | + */ |
|
42 | + public function __construct($handler) |
|
43 | + { |
|
44 | + $this->handler = $handler; |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * @param $smartObj |
|
49 | + */ |
|
50 | + public function postDataToObject(&$smartObj) |
|
51 | + { |
|
52 | + foreach (array_keys($smartObj->vars) as $key) { |
|
53 | + switch ($smartObj->vars[$key]['data_type']) { |
|
54 | + case XOBJ_DTYPE_IMAGE: |
|
55 | + if (isset($_POST['url_' . $key]) && '' !== $_POST['url_' . $key]) { |
|
56 | + $oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e'); |
|
57 | + $smartObj->setVar($key, $_POST['url_' . $key]); |
|
58 | + if (file_exists($oldFile)) { |
|
59 | + unlink($oldFile); |
|
60 | + } |
|
61 | + } |
|
62 | + if (isset($_POST['delete_' . $key]) && '1' == $_POST['delete_' . $key]) { |
|
63 | + $oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e'); |
|
64 | + $smartObj->setVar($key, ''); |
|
65 | + if (file_exists($oldFile)) { |
|
66 | + unlink($oldFile); |
|
67 | + } |
|
68 | + } |
|
69 | + break; |
|
70 | + |
|
71 | + case XOBJ_DTYPE_URLLINK: |
|
72 | + $linkObj = $smartObj->getUrlLinkObj($key); |
|
73 | + $linkObj->setVar('caption', $_POST['caption_' . $key]); |
|
74 | + $linkObj->setVar('description', $_POST['desc_' . $key]); |
|
75 | + $linkObj->setVar('target', $_POST['target_' . $key]); |
|
76 | + $linkObj->setVar('url', $_POST['url_' . $key]); |
|
77 | + if ('' !== $linkObj->getVar('url')) { |
|
78 | + $smartObj->storeUrlLinkObj($linkObj); |
|
79 | + } |
|
80 | + //todo: catch errors |
|
81 | + $smartObj->setVar($key, $linkObj->getVar('urllinkid')); |
|
82 | + break; |
|
83 | + |
|
84 | + case XOBJ_DTYPE_FILE: |
|
85 | + if (!isset($_FILES['upload_' . $key]['name']) || '' === $_FILES['upload_' . $key]['name']) { |
|
86 | + $fileObj = $smartObj->getFileObj($key); |
|
87 | + $fileObj->setVar('caption', $_POST['caption_' . $key]); |
|
88 | + $fileObj->setVar('description', $_POST['desc_' . $key]); |
|
89 | + $fileObj->setVar('url', $_POST['url_' . $key]); |
|
90 | + if (!('' === $fileObj->getVar('url') && '' === $fileObj->getVar('url') |
|
91 | + && '' === $fileObj->getVar('url'))) { |
|
92 | + $res = $smartObj->storeFileObj($fileObj); |
|
93 | + if ($res) { |
|
94 | + $smartObj->setVar($key, $fileObj->getVar('fileid')); |
|
95 | + } else { |
|
96 | + //error setted, but no error message (to be improved) |
|
97 | + $smartObj->setErrors($fileObj->getErrors()); |
|
98 | + } |
|
99 | + } |
|
100 | + } |
|
101 | + break; |
|
102 | + |
|
103 | + case XOBJ_DTYPE_STIME: |
|
104 | + case XOBJ_DTYPE_MTIME: |
|
105 | + case XOBJ_DTYPE_LTIME: |
|
106 | + // check if this field's value is available in the POST array |
|
107 | + if (is_array($_POST[$key]) && isset($_POST[$key]['date'])) { |
|
108 | + $value = strtotime($_POST[$key]['date']) + $_POST[$key]['time']; |
|
109 | + } else { |
|
110 | + $value = strtotime($_POST[$key]); |
|
111 | + //if strtotime returns false, the value is already a time stamp |
|
112 | + if (!$value) { |
|
113 | + $value = (int)$_POST[$key]; |
|
114 | + } |
|
115 | + } |
|
116 | + $smartObj->setVar($key, $value); |
|
117 | + |
|
118 | + break; |
|
119 | + |
|
120 | + default: |
|
121 | + $smartObj->setVar($key, $_POST[$key]); |
|
122 | + break; |
|
123 | + } |
|
124 | + } |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * @param $smartObj |
|
129 | + * @param $objectid |
|
130 | + * @param $created_success_msg |
|
131 | + * @param $modified_success_msg |
|
132 | + * @param bool $redirect_page |
|
133 | + * @param bool $debug |
|
134 | + * @return mixed |
|
135 | + */ |
|
136 | + public function doStoreFromDefaultForm( |
|
137 | + &$smartObj, |
|
138 | + $objectid, |
|
139 | + $created_success_msg, |
|
140 | + $modified_success_msg, |
|
141 | + $redirect_page = false, |
|
142 | + $debug = false |
|
143 | + ) { |
|
144 | + global $smart_previous_page; |
|
145 | + |
|
146 | + $this->postDataToObject($smartObj); |
|
147 | + |
|
148 | + if ($smartObj->isNew()) { |
|
149 | + $redirect_msg = $created_success_msg; |
|
150 | + } else { |
|
151 | + $redirect_msg = $modified_success_msg; |
|
152 | + } |
|
153 | + |
|
154 | + // Check if there were uploaded files |
|
155 | + if (isset($_POST['smart_upload_image']) || isset($_POST['smart_upload_file'])) { |
|
156 | 156 | // require_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartuploader.php'; |
157 | - $uploaderObj = new Uploader($smartObj->getImageDir(true), $this->handler->_allowedMimeTypes, $this->handler->_maxFileSize, $this->handler->_maxWidth, $this->handler->_maxHeight); |
|
158 | - foreach ($_FILES as $name => $file_array) { |
|
159 | - if (isset($file_array['name']) && '' !== $file_array['name'] |
|
160 | - && in_array(str_replace('upload_', '', $name), array_keys($smartObj->vars))) { |
|
161 | - if ($uploaderObj->fetchMedia($name)) { |
|
162 | - $uploaderObj->setTargetFileName(time() . '_' . $uploaderObj->getMediaName()); |
|
163 | - if ($uploaderObj->upload()) { |
|
164 | - // Find the related field in the SmartObject |
|
165 | - $related_field = str_replace('upload_', '', $name); |
|
166 | - $uploadedArray[] = $related_field; |
|
167 | - //si c'est un fichier Rich |
|
168 | - if (XOBJ_DTYPE_FILE === $smartObj->vars[$related_field]['data_type']) { |
|
169 | - $object_fileurl = $smartObj->getUploadDir(); |
|
170 | - $fileObj = $smartObj->getFileObj($related_field); |
|
171 | - $fileObj->setVar('url', $object_fileurl . $uploaderObj->getSavedFileName()); |
|
172 | - $fileObj->setVar('caption', $_POST['caption_' . $related_field]); |
|
173 | - $fileObj->setVar('description', $_POST['desc_' . $related_field]); |
|
174 | - $smartObj->storeFileObj($fileObj); |
|
175 | - //todo: catch errors |
|
176 | - $smartObj->setVar($related_field, $fileObj->getVar('fileid')); |
|
177 | - } else { |
|
178 | - $old_file = $smartObj->getUploadDir(true) . $smartObj->getVar($related_field); |
|
179 | - unlink($old_file); |
|
180 | - $smartObj->setVar($related_field, $uploaderObj->getSavedFileName()); |
|
181 | - } |
|
182 | - } else { |
|
183 | - $smartObj->setErrors($uploaderObj->getErrors(false)); |
|
184 | - } |
|
185 | - } else { |
|
186 | - $smartObj->setErrors($uploaderObj->getErrors(false)); |
|
187 | - } |
|
188 | - } |
|
189 | - } |
|
190 | - } |
|
191 | - |
|
192 | - if ($debug) { |
|
193 | - $storeResult = $this->handler->insertD($smartObj); |
|
194 | - } else { |
|
195 | - $storeResult = $this->handler->insert($smartObj); |
|
196 | - } |
|
197 | - |
|
198 | - if ($storeResult) { |
|
199 | - if ($this->handler->getPermissions()) { |
|
200 | - $smartPermissionsHandler = new PermissionHandler($this->handler); |
|
201 | - $smartPermissionsHandler->storeAllPermissionsForId($smartObj->id()); |
|
202 | - } |
|
203 | - } |
|
204 | - |
|
205 | - if (null === $redirect_page) { |
|
206 | - return $smartObj; |
|
207 | - } else { |
|
208 | - if (!$storeResult) { |
|
209 | - redirect_header($smart_previous_page, 3, _CO_SOBJECT_SAVE_ERROR . $smartObj->getHtmlErrors()); |
|
210 | - } |
|
211 | - |
|
212 | - $redirect_page = $redirect_page ?: Smartobject\Utility::getPageBeforeForm(); |
|
213 | - |
|
214 | - redirect_header($redirect_page, 2, $redirect_msg); |
|
215 | - } |
|
216 | - } |
|
217 | - |
|
218 | - /** |
|
219 | - * Store the object in the database autmatically from a form sending POST data |
|
220 | - * |
|
221 | - * @param string $created_success_msg message to display if new object was created |
|
222 | - * @param string $modified_success_msg message to display if object was successfully edited |
|
223 | - * @param bool|string $redirect_page redirect page, if not set, then we backup once |
|
224 | - * @param bool $debug |
|
225 | - * @param bool $x_param |
|
226 | - * @return bool |
|
227 | - * @internal param string $created_redir_page redirect page after creating the object |
|
228 | - * @internal param string $modified_redir_page redirect page after editing the object |
|
229 | - * @internal param bool $exit if set to TRUE then the script ends |
|
230 | - */ |
|
231 | - public function storeFromDefaultForm( |
|
232 | - $created_success_msg, |
|
233 | - $modified_success_msg, |
|
234 | - $redirect_page = false, |
|
235 | - $debug = false, |
|
236 | - $x_param = false |
|
237 | - ) { |
|
238 | - $objectid = isset($_POST[$this->handler->keyName]) ? (int)$_POST[$this->handler->keyName] : 0; |
|
239 | - if ($debug) { |
|
240 | - if ($x_param) { |
|
241 | - $smartObj = $this->handler->getD($objectid, true, $x_param); |
|
242 | - } else { |
|
243 | - $smartObj = $this->handler->getD($objectid); |
|
244 | - } |
|
245 | - } else { |
|
246 | - if ($x_param) { |
|
247 | - $smartObj = $this->handler->get($objectid, true, false, false, $x_param); |
|
248 | - } else { |
|
249 | - $smartObj = $this->handler->get($objectid); |
|
250 | - } |
|
251 | - } |
|
252 | - |
|
253 | - // if handler is the Multilanguage handler, we will need to treat this for multilanguage |
|
254 | - if (is_subclass_of($this->handler, 'smartpersistablemlobjecthandler')) { |
|
255 | - if ($smartObj->isNew()) { |
|
256 | - // This is a new object. We need to store the meta data and then the language data |
|
257 | - // First, we will get rid of the multilanguage data to only store the meta data |
|
258 | - $smartObj->stripMultilanguageFields(); |
|
259 | - $newObject = $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug); |
|
260 | - /** |
|
261 | - * @todo we need to trap potential errors here |
|
262 | - */ |
|
263 | - |
|
264 | - // ok, the meta daa is stored. Let's recreate the object and then |
|
265 | - // get rid of anything not multilanguage |
|
266 | - unset($smartObj); |
|
267 | - $smartObj = $this->handler->get($objectid); |
|
268 | - $smartObj->stripNonMultilanguageFields(); |
|
269 | - |
|
270 | - $smartObj->setVar($this->handler->keyName, $newObject->getVar($this->handler->keyName)); |
|
271 | - $this->handler->changeTableNameForML(); |
|
272 | - $ret = $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug); |
|
273 | - |
|
274 | - return $ret; |
|
275 | - } |
|
276 | - } else { |
|
277 | - return $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug); |
|
278 | - } |
|
279 | - } |
|
280 | - |
|
281 | - /** |
|
282 | - * @return bool |
|
283 | - */ |
|
284 | - public function storeSmartObjectD() |
|
285 | - { |
|
286 | - return $this->storeSmartObject(true); |
|
287 | - } |
|
288 | - |
|
289 | - /** |
|
290 | - * @param bool $debug |
|
291 | - * @param bool $xparam |
|
292 | - * @return bool |
|
293 | - */ |
|
294 | - public function storeSmartObject($debug = false, $xparam = false) |
|
295 | - { |
|
296 | - $ret = $this->storeFromDefaultForm('', '', null, $debug, $xparam); |
|
297 | - |
|
298 | - return $ret; |
|
299 | - } |
|
300 | - |
|
301 | - /** |
|
302 | - * Handles deletion of an object which keyid is passed as a GET param |
|
303 | - * |
|
304 | - * @param bool $confirm_msg |
|
305 | - * @param string $op |
|
306 | - * @param bool $userSide |
|
307 | - * @return void |
|
308 | - * @internal param string $redir_page redirect page after deleting the object |
|
309 | - */ |
|
310 | - public function handleObjectDeletion($confirm_msg = false, $op = 'del', $userSide = false) |
|
311 | - { |
|
312 | - global $smart_previous_page; |
|
313 | - |
|
314 | - $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0; |
|
315 | - $smartObj = $this->handler->get($objectid); |
|
316 | - |
|
317 | - if ($smartObj->isNew()) { |
|
318 | - redirect_header('javascript:history.go(-1)', 3, _CO_SOBJECT_NOT_SELECTED); |
|
319 | - } |
|
320 | - |
|
321 | - $confirm = \Xmf\Request::getInt('confirm', 0, POST); |
|
322 | - if ($confirm) { |
|
323 | - if (!$this->handler->delete($smartObj)) { |
|
324 | - redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors()); |
|
325 | - } |
|
326 | - |
|
327 | - redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS); |
|
328 | - } else { |
|
329 | - // no confirm: show deletion condition |
|
330 | - |
|
331 | - xoops_cp_header(); |
|
332 | - |
|
333 | - if (!$confirm_msg) { |
|
334 | - $confirm_msg = _CO_SOBJECT_DELETE_CONFIRM; |
|
335 | - } |
|
336 | - |
|
337 | - xoops_confirm([ |
|
338 | - 'op' => $op, |
|
339 | - $this->handler->keyName => $smartObj->getVar($this->handler->keyName), |
|
340 | - 'confirm' => 1, |
|
341 | - 'redirect_page' => $smart_previous_page |
|
342 | - ], xoops_getenv('PHP_SELF'), sprintf($confirm_msg, $smartObj->getVar($this->handler->identifierName)), _CO_SOBJECT_DELETE); |
|
343 | - |
|
344 | - xoops_cp_footer(); |
|
345 | - } |
|
346 | - exit(); |
|
347 | - } |
|
348 | - |
|
349 | - /** |
|
350 | - * @param bool $confirm_msg |
|
351 | - * @param string $op |
|
352 | - */ |
|
353 | - public function handleObjectDeletionFromUserSide($confirm_msg = false, $op = 'del') |
|
354 | - { |
|
355 | - global $smart_previous_page, $xoopsTpl; |
|
356 | - |
|
357 | - $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0; |
|
358 | - $smartObj = $this->handler->get($objectid); |
|
359 | - |
|
360 | - if ($smartObj->isNew()) { |
|
361 | - redirect_header('javascript:history.go(-1)', 3, _CO_SOBJECT_NOT_SELECTED); |
|
362 | - } |
|
363 | - |
|
364 | - $confirm = \Xmf\Request::getInt('confirm', 0, POST); |
|
365 | - if ($confirm) { |
|
366 | - if (!$this->handler->delete($smartObj)) { |
|
367 | - redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors()); |
|
368 | - } |
|
369 | - |
|
370 | - redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS); |
|
371 | - } else { |
|
372 | - // no confirm: show deletion condition |
|
373 | - if (!$confirm_msg) { |
|
374 | - $confirm_msg = _CO_SOBJECT_DELETE_CONFIRM; |
|
375 | - } |
|
376 | - |
|
377 | - ob_start(); |
|
378 | - xoops_confirm([ |
|
379 | - 'op' => $op, |
|
380 | - $this->handler->keyName => $smartObj->getVar($this->handler->keyName), |
|
381 | - 'confirm' => 1, |
|
382 | - 'redirect_page' => $smart_previous_page |
|
383 | - ], xoops_getenv('PHP_SELF'), sprintf($confirm_msg, $smartObj->getVar($this->handler->identifierName)), _CO_SOBJECT_DELETE); |
|
384 | - $smartobjectDeleteConfirm = ob_get_clean(); |
|
385 | - $xoopsTpl->assign('smartobject_delete_confirm', $smartobjectDeleteConfirm); |
|
386 | - } |
|
387 | - } |
|
388 | - |
|
389 | - /** |
|
390 | - * Retreive the object admin side link for a {@link SmartObjectSingleView} page |
|
391 | - * |
|
392 | - * @param SmartObject $smartObj reference to the object from which we want the user side link |
|
393 | - * @param bool $onlyUrl wether or not to return a simple URL or a full <a> link |
|
394 | - * @param bool $withimage |
|
395 | - * @return string admin side link to the object |
|
396 | - */ |
|
397 | - public function getAdminViewItemLink(SmartObject $smartObj, $onlyUrl = false, $withimage = false) |
|
398 | - { |
|
399 | - $ret = $this->handler->_moduleUrl . 'admin/' . $this->handler->_page . '?op=view&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
400 | - if ($onlyUrl) { |
|
401 | - return $ret; |
|
402 | - } elseif ($withimage) { |
|
403 | - return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "viewmag.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_ADMIN_VIEW . "' title='" . _CO_SOBJECT_ADMIN_VIEW . "'></a>"; |
|
404 | - } |
|
405 | - |
|
406 | - return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
407 | - } |
|
408 | - |
|
409 | - /** |
|
410 | - * Retreive the object user side link |
|
411 | - * |
|
412 | - * @param SmartObject $smartObj reference to the object from which we want the user side link |
|
413 | - * @param bool $onlyUrl wether or not to return a simple URL or a full <a> link |
|
414 | - * @return string user side link to the object |
|
415 | - */ |
|
416 | - public function getItemLink(SmartObject $smartObj, $onlyUrl = false) |
|
417 | - { |
|
418 | - $seoMode = Smartobject\Utility::getModuleModeSEO($this->handler->_moduleName); |
|
419 | - $seoModuleName = Smartobject\Utility::getModuleNameForSEO($this->handler->_moduleName); |
|
420 | - |
|
421 | - /** |
|
422 | - * $seoIncludeId feature is not finished yet, so let's put it always to true |
|
423 | - */ |
|
424 | - //$seoIncludeId = Smartobject\Utility::getModuleIncludeIdSEO($this->handler->_moduleName); |
|
425 | - $seoIncludeId = true; |
|
426 | - |
|
427 | - if ('rewrite' === $seoMode) { |
|
428 | - $ret = XOOPS_URL . '/' . $seoModuleName . '.' . $this->handler->_itemname . ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') . '/' . $smartObj->getVar('short_url') . '.html'; |
|
429 | - } elseif ('pathinfo' === $seoMode) { |
|
430 | - $ret = SMARTOBJECT_URL . 'seo.php/' . $seoModuleName . '.' . $this->handler->_itemname . ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') . '/' . $smartObj->getVar('short_url') . '.html'; |
|
431 | - } else { |
|
432 | - $ret = $this->handler->_moduleUrl . $this->handler->_page . '?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
433 | - } |
|
434 | - |
|
435 | - if (!$onlyUrl) { |
|
436 | - $ret = "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
437 | - } |
|
438 | - |
|
439 | - return $ret; |
|
440 | - } |
|
441 | - |
|
442 | - /** |
|
443 | - * @param $smartObj |
|
444 | - * @param bool $onlyUrl |
|
445 | - * @param bool $withimage |
|
446 | - * @return string |
|
447 | - */ |
|
448 | - public function getEditLanguageLink($smartObj, $onlyUrl = false, $withimage = true) |
|
449 | - { |
|
450 | - $ret = $this->handler->_moduleUrl . 'admin/' . $this->handler->_page . '?op=mod&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName) . '&language=' . $smartObj->getVar('language'); |
|
451 | - if ($onlyUrl) { |
|
452 | - return $ret; |
|
453 | - } elseif ($withimage) { |
|
454 | - return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "wizard.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_LANGUAGE_MODIFY . "' title='" . _CO_SOBJECT_LANGUAGE_MODIFY . "'></a>"; |
|
455 | - } |
|
456 | - |
|
457 | - return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
458 | - } |
|
459 | - |
|
460 | - /** |
|
461 | - * @param $smartObj |
|
462 | - * @param bool $onlyUrl |
|
463 | - * @param bool $withimage |
|
464 | - * @param bool $userSide |
|
465 | - * @return string |
|
466 | - */ |
|
467 | - public function getEditItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false) |
|
468 | - { |
|
469 | - $admin_side = $userSide ? '' : 'admin/'; |
|
470 | - $ret = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=mod&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
471 | - if ($onlyUrl) { |
|
472 | - return $ret; |
|
473 | - } elseif ($withimage) { |
|
474 | - return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "edit.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_MODIFY . "' title='" . _CO_SOBJECT_MODIFY . "'></a>"; |
|
475 | - } |
|
476 | - |
|
477 | - return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
478 | - } |
|
479 | - |
|
480 | - /** |
|
481 | - * @param $smartObj |
|
482 | - * @param bool $onlyUrl |
|
483 | - * @param bool $withimage |
|
484 | - * @param bool $userSide |
|
485 | - * @return string |
|
486 | - */ |
|
487 | - public function getDeleteItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false) |
|
488 | - { |
|
489 | - $admin_side = $userSide ? '' : 'admin/'; |
|
490 | - $ret = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=del&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
491 | - if ($onlyUrl) { |
|
492 | - return $ret; |
|
493 | - } elseif ($withimage) { |
|
494 | - return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "editdelete.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_DELETE . "' title='" . _CO_SOBJECT_DELETE . "'></a>"; |
|
495 | - } |
|
496 | - |
|
497 | - return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
498 | - } |
|
499 | - |
|
500 | - /** |
|
501 | - * @param $smartObj |
|
502 | - * @return string |
|
503 | - */ |
|
504 | - public function getPrintAndMailLink($smartObj) |
|
505 | - { |
|
506 | - global $xoopsConfig; |
|
507 | - |
|
508 | - $printlink = $this->handler->_moduleUrl . 'print.php?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
509 | - $js = "javascript:openWithSelfMain('" . $printlink . "', 'smartpopup', 700, 519);"; |
|
510 | - $printlink = '<a href="' . $js . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'fileprint.png" alt="" style="vertical-align: middle;"></a>'; |
|
511 | - |
|
512 | - $smartModule = Smartobject\Utility::getModuleInfo($smartObj->handler->_moduleName); |
|
513 | - $link = Smartobject\Utility::getCurrentPage(); |
|
514 | - $mid = $smartModule->getVar('mid'); |
|
515 | - $friendlink = "<a href=\"javascript:openWithSelfMain('" |
|
516 | - . SMARTOBJECT_URL |
|
517 | - . 'sendlink.php?link=' |
|
518 | - . $link |
|
519 | - . '&mid=' |
|
520 | - . $mid |
|
521 | - . "', ',',',',',','sendmessage', 674, 500);\"><img src=\"" |
|
522 | - . SMARTOBJECT_IMAGES_ACTIONS_URL |
|
523 | - . 'mail_send.png" alt="' |
|
524 | - . _CO_SOBJECT_EMAIL |
|
525 | - . '" title="' |
|
526 | - . _CO_SOBJECT_EMAIL |
|
527 | - . '" style="vertical-align: middle;"></a>'; |
|
528 | - |
|
529 | - $ret = '<span id="smartobject_print_button">' . $printlink . ' </span>' . '<span id="smartobject_mail_button">' . $friendlink . '</span>'; |
|
530 | - |
|
531 | - return $ret; |
|
532 | - } |
|
533 | - |
|
534 | - /** |
|
535 | - * @return string |
|
536 | - */ |
|
537 | - public function getModuleItemString() |
|
538 | - { |
|
539 | - $ret = $this->handler->_moduleName . '_' . $this->handler->_itemname; |
|
540 | - |
|
541 | - return $ret; |
|
542 | - } |
|
157 | + $uploaderObj = new Uploader($smartObj->getImageDir(true), $this->handler->_allowedMimeTypes, $this->handler->_maxFileSize, $this->handler->_maxWidth, $this->handler->_maxHeight); |
|
158 | + foreach ($_FILES as $name => $file_array) { |
|
159 | + if (isset($file_array['name']) && '' !== $file_array['name'] |
|
160 | + && in_array(str_replace('upload_', '', $name), array_keys($smartObj->vars))) { |
|
161 | + if ($uploaderObj->fetchMedia($name)) { |
|
162 | + $uploaderObj->setTargetFileName(time() . '_' . $uploaderObj->getMediaName()); |
|
163 | + if ($uploaderObj->upload()) { |
|
164 | + // Find the related field in the SmartObject |
|
165 | + $related_field = str_replace('upload_', '', $name); |
|
166 | + $uploadedArray[] = $related_field; |
|
167 | + //si c'est un fichier Rich |
|
168 | + if (XOBJ_DTYPE_FILE === $smartObj->vars[$related_field]['data_type']) { |
|
169 | + $object_fileurl = $smartObj->getUploadDir(); |
|
170 | + $fileObj = $smartObj->getFileObj($related_field); |
|
171 | + $fileObj->setVar('url', $object_fileurl . $uploaderObj->getSavedFileName()); |
|
172 | + $fileObj->setVar('caption', $_POST['caption_' . $related_field]); |
|
173 | + $fileObj->setVar('description', $_POST['desc_' . $related_field]); |
|
174 | + $smartObj->storeFileObj($fileObj); |
|
175 | + //todo: catch errors |
|
176 | + $smartObj->setVar($related_field, $fileObj->getVar('fileid')); |
|
177 | + } else { |
|
178 | + $old_file = $smartObj->getUploadDir(true) . $smartObj->getVar($related_field); |
|
179 | + unlink($old_file); |
|
180 | + $smartObj->setVar($related_field, $uploaderObj->getSavedFileName()); |
|
181 | + } |
|
182 | + } else { |
|
183 | + $smartObj->setErrors($uploaderObj->getErrors(false)); |
|
184 | + } |
|
185 | + } else { |
|
186 | + $smartObj->setErrors($uploaderObj->getErrors(false)); |
|
187 | + } |
|
188 | + } |
|
189 | + } |
|
190 | + } |
|
191 | + |
|
192 | + if ($debug) { |
|
193 | + $storeResult = $this->handler->insertD($smartObj); |
|
194 | + } else { |
|
195 | + $storeResult = $this->handler->insert($smartObj); |
|
196 | + } |
|
197 | + |
|
198 | + if ($storeResult) { |
|
199 | + if ($this->handler->getPermissions()) { |
|
200 | + $smartPermissionsHandler = new PermissionHandler($this->handler); |
|
201 | + $smartPermissionsHandler->storeAllPermissionsForId($smartObj->id()); |
|
202 | + } |
|
203 | + } |
|
204 | + |
|
205 | + if (null === $redirect_page) { |
|
206 | + return $smartObj; |
|
207 | + } else { |
|
208 | + if (!$storeResult) { |
|
209 | + redirect_header($smart_previous_page, 3, _CO_SOBJECT_SAVE_ERROR . $smartObj->getHtmlErrors()); |
|
210 | + } |
|
211 | + |
|
212 | + $redirect_page = $redirect_page ?: Smartobject\Utility::getPageBeforeForm(); |
|
213 | + |
|
214 | + redirect_header($redirect_page, 2, $redirect_msg); |
|
215 | + } |
|
216 | + } |
|
217 | + |
|
218 | + /** |
|
219 | + * Store the object in the database autmatically from a form sending POST data |
|
220 | + * |
|
221 | + * @param string $created_success_msg message to display if new object was created |
|
222 | + * @param string $modified_success_msg message to display if object was successfully edited |
|
223 | + * @param bool|string $redirect_page redirect page, if not set, then we backup once |
|
224 | + * @param bool $debug |
|
225 | + * @param bool $x_param |
|
226 | + * @return bool |
|
227 | + * @internal param string $created_redir_page redirect page after creating the object |
|
228 | + * @internal param string $modified_redir_page redirect page after editing the object |
|
229 | + * @internal param bool $exit if set to TRUE then the script ends |
|
230 | + */ |
|
231 | + public function storeFromDefaultForm( |
|
232 | + $created_success_msg, |
|
233 | + $modified_success_msg, |
|
234 | + $redirect_page = false, |
|
235 | + $debug = false, |
|
236 | + $x_param = false |
|
237 | + ) { |
|
238 | + $objectid = isset($_POST[$this->handler->keyName]) ? (int)$_POST[$this->handler->keyName] : 0; |
|
239 | + if ($debug) { |
|
240 | + if ($x_param) { |
|
241 | + $smartObj = $this->handler->getD($objectid, true, $x_param); |
|
242 | + } else { |
|
243 | + $smartObj = $this->handler->getD($objectid); |
|
244 | + } |
|
245 | + } else { |
|
246 | + if ($x_param) { |
|
247 | + $smartObj = $this->handler->get($objectid, true, false, false, $x_param); |
|
248 | + } else { |
|
249 | + $smartObj = $this->handler->get($objectid); |
|
250 | + } |
|
251 | + } |
|
252 | + |
|
253 | + // if handler is the Multilanguage handler, we will need to treat this for multilanguage |
|
254 | + if (is_subclass_of($this->handler, 'smartpersistablemlobjecthandler')) { |
|
255 | + if ($smartObj->isNew()) { |
|
256 | + // This is a new object. We need to store the meta data and then the language data |
|
257 | + // First, we will get rid of the multilanguage data to only store the meta data |
|
258 | + $smartObj->stripMultilanguageFields(); |
|
259 | + $newObject = $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug); |
|
260 | + /** |
|
261 | + * @todo we need to trap potential errors here |
|
262 | + */ |
|
263 | + |
|
264 | + // ok, the meta daa is stored. Let's recreate the object and then |
|
265 | + // get rid of anything not multilanguage |
|
266 | + unset($smartObj); |
|
267 | + $smartObj = $this->handler->get($objectid); |
|
268 | + $smartObj->stripNonMultilanguageFields(); |
|
269 | + |
|
270 | + $smartObj->setVar($this->handler->keyName, $newObject->getVar($this->handler->keyName)); |
|
271 | + $this->handler->changeTableNameForML(); |
|
272 | + $ret = $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug); |
|
273 | + |
|
274 | + return $ret; |
|
275 | + } |
|
276 | + } else { |
|
277 | + return $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug); |
|
278 | + } |
|
279 | + } |
|
280 | + |
|
281 | + /** |
|
282 | + * @return bool |
|
283 | + */ |
|
284 | + public function storeSmartObjectD() |
|
285 | + { |
|
286 | + return $this->storeSmartObject(true); |
|
287 | + } |
|
288 | + |
|
289 | + /** |
|
290 | + * @param bool $debug |
|
291 | + * @param bool $xparam |
|
292 | + * @return bool |
|
293 | + */ |
|
294 | + public function storeSmartObject($debug = false, $xparam = false) |
|
295 | + { |
|
296 | + $ret = $this->storeFromDefaultForm('', '', null, $debug, $xparam); |
|
297 | + |
|
298 | + return $ret; |
|
299 | + } |
|
300 | + |
|
301 | + /** |
|
302 | + * Handles deletion of an object which keyid is passed as a GET param |
|
303 | + * |
|
304 | + * @param bool $confirm_msg |
|
305 | + * @param string $op |
|
306 | + * @param bool $userSide |
|
307 | + * @return void |
|
308 | + * @internal param string $redir_page redirect page after deleting the object |
|
309 | + */ |
|
310 | + public function handleObjectDeletion($confirm_msg = false, $op = 'del', $userSide = false) |
|
311 | + { |
|
312 | + global $smart_previous_page; |
|
313 | + |
|
314 | + $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0; |
|
315 | + $smartObj = $this->handler->get($objectid); |
|
316 | + |
|
317 | + if ($smartObj->isNew()) { |
|
318 | + redirect_header('javascript:history.go(-1)', 3, _CO_SOBJECT_NOT_SELECTED); |
|
319 | + } |
|
320 | + |
|
321 | + $confirm = \Xmf\Request::getInt('confirm', 0, POST); |
|
322 | + if ($confirm) { |
|
323 | + if (!$this->handler->delete($smartObj)) { |
|
324 | + redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors()); |
|
325 | + } |
|
326 | + |
|
327 | + redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS); |
|
328 | + } else { |
|
329 | + // no confirm: show deletion condition |
|
330 | + |
|
331 | + xoops_cp_header(); |
|
332 | + |
|
333 | + if (!$confirm_msg) { |
|
334 | + $confirm_msg = _CO_SOBJECT_DELETE_CONFIRM; |
|
335 | + } |
|
336 | + |
|
337 | + xoops_confirm([ |
|
338 | + 'op' => $op, |
|
339 | + $this->handler->keyName => $smartObj->getVar($this->handler->keyName), |
|
340 | + 'confirm' => 1, |
|
341 | + 'redirect_page' => $smart_previous_page |
|
342 | + ], xoops_getenv('PHP_SELF'), sprintf($confirm_msg, $smartObj->getVar($this->handler->identifierName)), _CO_SOBJECT_DELETE); |
|
343 | + |
|
344 | + xoops_cp_footer(); |
|
345 | + } |
|
346 | + exit(); |
|
347 | + } |
|
348 | + |
|
349 | + /** |
|
350 | + * @param bool $confirm_msg |
|
351 | + * @param string $op |
|
352 | + */ |
|
353 | + public function handleObjectDeletionFromUserSide($confirm_msg = false, $op = 'del') |
|
354 | + { |
|
355 | + global $smart_previous_page, $xoopsTpl; |
|
356 | + |
|
357 | + $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0; |
|
358 | + $smartObj = $this->handler->get($objectid); |
|
359 | + |
|
360 | + if ($smartObj->isNew()) { |
|
361 | + redirect_header('javascript:history.go(-1)', 3, _CO_SOBJECT_NOT_SELECTED); |
|
362 | + } |
|
363 | + |
|
364 | + $confirm = \Xmf\Request::getInt('confirm', 0, POST); |
|
365 | + if ($confirm) { |
|
366 | + if (!$this->handler->delete($smartObj)) { |
|
367 | + redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors()); |
|
368 | + } |
|
369 | + |
|
370 | + redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS); |
|
371 | + } else { |
|
372 | + // no confirm: show deletion condition |
|
373 | + if (!$confirm_msg) { |
|
374 | + $confirm_msg = _CO_SOBJECT_DELETE_CONFIRM; |
|
375 | + } |
|
376 | + |
|
377 | + ob_start(); |
|
378 | + xoops_confirm([ |
|
379 | + 'op' => $op, |
|
380 | + $this->handler->keyName => $smartObj->getVar($this->handler->keyName), |
|
381 | + 'confirm' => 1, |
|
382 | + 'redirect_page' => $smart_previous_page |
|
383 | + ], xoops_getenv('PHP_SELF'), sprintf($confirm_msg, $smartObj->getVar($this->handler->identifierName)), _CO_SOBJECT_DELETE); |
|
384 | + $smartobjectDeleteConfirm = ob_get_clean(); |
|
385 | + $xoopsTpl->assign('smartobject_delete_confirm', $smartobjectDeleteConfirm); |
|
386 | + } |
|
387 | + } |
|
388 | + |
|
389 | + /** |
|
390 | + * Retreive the object admin side link for a {@link SmartObjectSingleView} page |
|
391 | + * |
|
392 | + * @param SmartObject $smartObj reference to the object from which we want the user side link |
|
393 | + * @param bool $onlyUrl wether or not to return a simple URL or a full <a> link |
|
394 | + * @param bool $withimage |
|
395 | + * @return string admin side link to the object |
|
396 | + */ |
|
397 | + public function getAdminViewItemLink(SmartObject $smartObj, $onlyUrl = false, $withimage = false) |
|
398 | + { |
|
399 | + $ret = $this->handler->_moduleUrl . 'admin/' . $this->handler->_page . '?op=view&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
400 | + if ($onlyUrl) { |
|
401 | + return $ret; |
|
402 | + } elseif ($withimage) { |
|
403 | + return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "viewmag.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_ADMIN_VIEW . "' title='" . _CO_SOBJECT_ADMIN_VIEW . "'></a>"; |
|
404 | + } |
|
405 | + |
|
406 | + return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
407 | + } |
|
408 | + |
|
409 | + /** |
|
410 | + * Retreive the object user side link |
|
411 | + * |
|
412 | + * @param SmartObject $smartObj reference to the object from which we want the user side link |
|
413 | + * @param bool $onlyUrl wether or not to return a simple URL or a full <a> link |
|
414 | + * @return string user side link to the object |
|
415 | + */ |
|
416 | + public function getItemLink(SmartObject $smartObj, $onlyUrl = false) |
|
417 | + { |
|
418 | + $seoMode = Smartobject\Utility::getModuleModeSEO($this->handler->_moduleName); |
|
419 | + $seoModuleName = Smartobject\Utility::getModuleNameForSEO($this->handler->_moduleName); |
|
420 | + |
|
421 | + /** |
|
422 | + * $seoIncludeId feature is not finished yet, so let's put it always to true |
|
423 | + */ |
|
424 | + //$seoIncludeId = Smartobject\Utility::getModuleIncludeIdSEO($this->handler->_moduleName); |
|
425 | + $seoIncludeId = true; |
|
426 | + |
|
427 | + if ('rewrite' === $seoMode) { |
|
428 | + $ret = XOOPS_URL . '/' . $seoModuleName . '.' . $this->handler->_itemname . ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') . '/' . $smartObj->getVar('short_url') . '.html'; |
|
429 | + } elseif ('pathinfo' === $seoMode) { |
|
430 | + $ret = SMARTOBJECT_URL . 'seo.php/' . $seoModuleName . '.' . $this->handler->_itemname . ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') . '/' . $smartObj->getVar('short_url') . '.html'; |
|
431 | + } else { |
|
432 | + $ret = $this->handler->_moduleUrl . $this->handler->_page . '?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
433 | + } |
|
434 | + |
|
435 | + if (!$onlyUrl) { |
|
436 | + $ret = "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
437 | + } |
|
438 | + |
|
439 | + return $ret; |
|
440 | + } |
|
441 | + |
|
442 | + /** |
|
443 | + * @param $smartObj |
|
444 | + * @param bool $onlyUrl |
|
445 | + * @param bool $withimage |
|
446 | + * @return string |
|
447 | + */ |
|
448 | + public function getEditLanguageLink($smartObj, $onlyUrl = false, $withimage = true) |
|
449 | + { |
|
450 | + $ret = $this->handler->_moduleUrl . 'admin/' . $this->handler->_page . '?op=mod&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName) . '&language=' . $smartObj->getVar('language'); |
|
451 | + if ($onlyUrl) { |
|
452 | + return $ret; |
|
453 | + } elseif ($withimage) { |
|
454 | + return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "wizard.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_LANGUAGE_MODIFY . "' title='" . _CO_SOBJECT_LANGUAGE_MODIFY . "'></a>"; |
|
455 | + } |
|
456 | + |
|
457 | + return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
458 | + } |
|
459 | + |
|
460 | + /** |
|
461 | + * @param $smartObj |
|
462 | + * @param bool $onlyUrl |
|
463 | + * @param bool $withimage |
|
464 | + * @param bool $userSide |
|
465 | + * @return string |
|
466 | + */ |
|
467 | + public function getEditItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false) |
|
468 | + { |
|
469 | + $admin_side = $userSide ? '' : 'admin/'; |
|
470 | + $ret = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=mod&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
471 | + if ($onlyUrl) { |
|
472 | + return $ret; |
|
473 | + } elseif ($withimage) { |
|
474 | + return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "edit.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_MODIFY . "' title='" . _CO_SOBJECT_MODIFY . "'></a>"; |
|
475 | + } |
|
476 | + |
|
477 | + return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
478 | + } |
|
479 | + |
|
480 | + /** |
|
481 | + * @param $smartObj |
|
482 | + * @param bool $onlyUrl |
|
483 | + * @param bool $withimage |
|
484 | + * @param bool $userSide |
|
485 | + * @return string |
|
486 | + */ |
|
487 | + public function getDeleteItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false) |
|
488 | + { |
|
489 | + $admin_side = $userSide ? '' : 'admin/'; |
|
490 | + $ret = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=del&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
491 | + if ($onlyUrl) { |
|
492 | + return $ret; |
|
493 | + } elseif ($withimage) { |
|
494 | + return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "editdelete.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_DELETE . "' title='" . _CO_SOBJECT_DELETE . "'></a>"; |
|
495 | + } |
|
496 | + |
|
497 | + return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
498 | + } |
|
499 | + |
|
500 | + /** |
|
501 | + * @param $smartObj |
|
502 | + * @return string |
|
503 | + */ |
|
504 | + public function getPrintAndMailLink($smartObj) |
|
505 | + { |
|
506 | + global $xoopsConfig; |
|
507 | + |
|
508 | + $printlink = $this->handler->_moduleUrl . 'print.php?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
509 | + $js = "javascript:openWithSelfMain('" . $printlink . "', 'smartpopup', 700, 519);"; |
|
510 | + $printlink = '<a href="' . $js . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'fileprint.png" alt="" style="vertical-align: middle;"></a>'; |
|
511 | + |
|
512 | + $smartModule = Smartobject\Utility::getModuleInfo($smartObj->handler->_moduleName); |
|
513 | + $link = Smartobject\Utility::getCurrentPage(); |
|
514 | + $mid = $smartModule->getVar('mid'); |
|
515 | + $friendlink = "<a href=\"javascript:openWithSelfMain('" |
|
516 | + . SMARTOBJECT_URL |
|
517 | + . 'sendlink.php?link=' |
|
518 | + . $link |
|
519 | + . '&mid=' |
|
520 | + . $mid |
|
521 | + . "', ',',',',',','sendmessage', 674, 500);\"><img src=\"" |
|
522 | + . SMARTOBJECT_IMAGES_ACTIONS_URL |
|
523 | + . 'mail_send.png" alt="' |
|
524 | + . _CO_SOBJECT_EMAIL |
|
525 | + . '" title="' |
|
526 | + . _CO_SOBJECT_EMAIL |
|
527 | + . '" style="vertical-align: middle;"></a>'; |
|
528 | + |
|
529 | + $ret = '<span id="smartobject_print_button">' . $printlink . ' </span>' . '<span id="smartobject_mail_button">' . $friendlink . '</span>'; |
|
530 | + |
|
531 | + return $ret; |
|
532 | + } |
|
533 | + |
|
534 | + /** |
|
535 | + * @return string |
|
536 | + */ |
|
537 | + public function getModuleItemString() |
|
538 | + { |
|
539 | + $ret = $this->handler->_moduleName . '_' . $this->handler->_itemname; |
|
540 | + |
|
541 | + return $ret; |
|
542 | + } |
|
543 | 543 | } |
@@ -52,15 +52,15 @@ discard block |
||
52 | 52 | foreach (array_keys($smartObj->vars) as $key) { |
53 | 53 | switch ($smartObj->vars[$key]['data_type']) { |
54 | 54 | case XOBJ_DTYPE_IMAGE: |
55 | - if (isset($_POST['url_' . $key]) && '' !== $_POST['url_' . $key]) { |
|
56 | - $oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e'); |
|
57 | - $smartObj->setVar($key, $_POST['url_' . $key]); |
|
55 | + if (isset($_POST['url_'.$key]) && '' !== $_POST['url_'.$key]) { |
|
56 | + $oldFile = $smartObj->getUploadDir(true).$smartObj->getVar($key, 'e'); |
|
57 | + $smartObj->setVar($key, $_POST['url_'.$key]); |
|
58 | 58 | if (file_exists($oldFile)) { |
59 | 59 | unlink($oldFile); |
60 | 60 | } |
61 | 61 | } |
62 | - if (isset($_POST['delete_' . $key]) && '1' == $_POST['delete_' . $key]) { |
|
63 | - $oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e'); |
|
62 | + if (isset($_POST['delete_'.$key]) && '1' == $_POST['delete_'.$key]) { |
|
63 | + $oldFile = $smartObj->getUploadDir(true).$smartObj->getVar($key, 'e'); |
|
64 | 64 | $smartObj->setVar($key, ''); |
65 | 65 | if (file_exists($oldFile)) { |
66 | 66 | unlink($oldFile); |
@@ -70,10 +70,10 @@ discard block |
||
70 | 70 | |
71 | 71 | case XOBJ_DTYPE_URLLINK: |
72 | 72 | $linkObj = $smartObj->getUrlLinkObj($key); |
73 | - $linkObj->setVar('caption', $_POST['caption_' . $key]); |
|
74 | - $linkObj->setVar('description', $_POST['desc_' . $key]); |
|
75 | - $linkObj->setVar('target', $_POST['target_' . $key]); |
|
76 | - $linkObj->setVar('url', $_POST['url_' . $key]); |
|
73 | + $linkObj->setVar('caption', $_POST['caption_'.$key]); |
|
74 | + $linkObj->setVar('description', $_POST['desc_'.$key]); |
|
75 | + $linkObj->setVar('target', $_POST['target_'.$key]); |
|
76 | + $linkObj->setVar('url', $_POST['url_'.$key]); |
|
77 | 77 | if ('' !== $linkObj->getVar('url')) { |
78 | 78 | $smartObj->storeUrlLinkObj($linkObj); |
79 | 79 | } |
@@ -82,11 +82,11 @@ discard block |
||
82 | 82 | break; |
83 | 83 | |
84 | 84 | case XOBJ_DTYPE_FILE: |
85 | - if (!isset($_FILES['upload_' . $key]['name']) || '' === $_FILES['upload_' . $key]['name']) { |
|
85 | + if (!isset($_FILES['upload_'.$key]['name']) || '' === $_FILES['upload_'.$key]['name']) { |
|
86 | 86 | $fileObj = $smartObj->getFileObj($key); |
87 | - $fileObj->setVar('caption', $_POST['caption_' . $key]); |
|
88 | - $fileObj->setVar('description', $_POST['desc_' . $key]); |
|
89 | - $fileObj->setVar('url', $_POST['url_' . $key]); |
|
87 | + $fileObj->setVar('caption', $_POST['caption_'.$key]); |
|
88 | + $fileObj->setVar('description', $_POST['desc_'.$key]); |
|
89 | + $fileObj->setVar('url', $_POST['url_'.$key]); |
|
90 | 90 | if (!('' === $fileObj->getVar('url') && '' === $fileObj->getVar('url') |
91 | 91 | && '' === $fileObj->getVar('url'))) { |
92 | 92 | $res = $smartObj->storeFileObj($fileObj); |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | $value = strtotime($_POST[$key]); |
111 | 111 | //if strtotime returns false, the value is already a time stamp |
112 | 112 | if (!$value) { |
113 | - $value = (int)$_POST[$key]; |
|
113 | + $value = (int) $_POST[$key]; |
|
114 | 114 | } |
115 | 115 | } |
116 | 116 | $smartObj->setVar($key, $value); |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | if (isset($file_array['name']) && '' !== $file_array['name'] |
160 | 160 | && in_array(str_replace('upload_', '', $name), array_keys($smartObj->vars))) { |
161 | 161 | if ($uploaderObj->fetchMedia($name)) { |
162 | - $uploaderObj->setTargetFileName(time() . '_' . $uploaderObj->getMediaName()); |
|
162 | + $uploaderObj->setTargetFileName(time().'_'.$uploaderObj->getMediaName()); |
|
163 | 163 | if ($uploaderObj->upload()) { |
164 | 164 | // Find the related field in the SmartObject |
165 | 165 | $related_field = str_replace('upload_', '', $name); |
@@ -168,14 +168,14 @@ discard block |
||
168 | 168 | if (XOBJ_DTYPE_FILE === $smartObj->vars[$related_field]['data_type']) { |
169 | 169 | $object_fileurl = $smartObj->getUploadDir(); |
170 | 170 | $fileObj = $smartObj->getFileObj($related_field); |
171 | - $fileObj->setVar('url', $object_fileurl . $uploaderObj->getSavedFileName()); |
|
172 | - $fileObj->setVar('caption', $_POST['caption_' . $related_field]); |
|
173 | - $fileObj->setVar('description', $_POST['desc_' . $related_field]); |
|
171 | + $fileObj->setVar('url', $object_fileurl.$uploaderObj->getSavedFileName()); |
|
172 | + $fileObj->setVar('caption', $_POST['caption_'.$related_field]); |
|
173 | + $fileObj->setVar('description', $_POST['desc_'.$related_field]); |
|
174 | 174 | $smartObj->storeFileObj($fileObj); |
175 | 175 | //todo: catch errors |
176 | 176 | $smartObj->setVar($related_field, $fileObj->getVar('fileid')); |
177 | 177 | } else { |
178 | - $old_file = $smartObj->getUploadDir(true) . $smartObj->getVar($related_field); |
|
178 | + $old_file = $smartObj->getUploadDir(true).$smartObj->getVar($related_field); |
|
179 | 179 | unlink($old_file); |
180 | 180 | $smartObj->setVar($related_field, $uploaderObj->getSavedFileName()); |
181 | 181 | } |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | return $smartObj; |
207 | 207 | } else { |
208 | 208 | if (!$storeResult) { |
209 | - redirect_header($smart_previous_page, 3, _CO_SOBJECT_SAVE_ERROR . $smartObj->getHtmlErrors()); |
|
209 | + redirect_header($smart_previous_page, 3, _CO_SOBJECT_SAVE_ERROR.$smartObj->getHtmlErrors()); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | $redirect_page = $redirect_page ?: Smartobject\Utility::getPageBeforeForm(); |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | $debug = false, |
236 | 236 | $x_param = false |
237 | 237 | ) { |
238 | - $objectid = isset($_POST[$this->handler->keyName]) ? (int)$_POST[$this->handler->keyName] : 0; |
|
238 | + $objectid = isset($_POST[$this->handler->keyName]) ? (int) $_POST[$this->handler->keyName] : 0; |
|
239 | 239 | if ($debug) { |
240 | 240 | if ($x_param) { |
241 | 241 | $smartObj = $this->handler->getD($objectid, true, $x_param); |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | { |
312 | 312 | global $smart_previous_page; |
313 | 313 | |
314 | - $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0; |
|
314 | + $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int) $_REQUEST[$this->handler->keyName] : 0; |
|
315 | 315 | $smartObj = $this->handler->get($objectid); |
316 | 316 | |
317 | 317 | if ($smartObj->isNew()) { |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | $confirm = \Xmf\Request::getInt('confirm', 0, POST); |
322 | 322 | if ($confirm) { |
323 | 323 | if (!$this->handler->delete($smartObj)) { |
324 | - redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors()); |
|
324 | + redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR.$smartObj->getHtmlErrors()); |
|
325 | 325 | } |
326 | 326 | |
327 | 327 | redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS); |
@@ -354,7 +354,7 @@ discard block |
||
354 | 354 | { |
355 | 355 | global $smart_previous_page, $xoopsTpl; |
356 | 356 | |
357 | - $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0; |
|
357 | + $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int) $_REQUEST[$this->handler->keyName] : 0; |
|
358 | 358 | $smartObj = $this->handler->get($objectid); |
359 | 359 | |
360 | 360 | if ($smartObj->isNew()) { |
@@ -364,7 +364,7 @@ discard block |
||
364 | 364 | $confirm = \Xmf\Request::getInt('confirm', 0, POST); |
365 | 365 | if ($confirm) { |
366 | 366 | if (!$this->handler->delete($smartObj)) { |
367 | - redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors()); |
|
367 | + redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR.$smartObj->getHtmlErrors()); |
|
368 | 368 | } |
369 | 369 | |
370 | 370 | redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS); |
@@ -396,14 +396,14 @@ discard block |
||
396 | 396 | */ |
397 | 397 | public function getAdminViewItemLink(SmartObject $smartObj, $onlyUrl = false, $withimage = false) |
398 | 398 | { |
399 | - $ret = $this->handler->_moduleUrl . 'admin/' . $this->handler->_page . '?op=view&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
399 | + $ret = $this->handler->_moduleUrl.'admin/'.$this->handler->_page.'?op=view&'.$this->handler->keyName.'='.$smartObj->getVar($this->handler->keyName); |
|
400 | 400 | if ($onlyUrl) { |
401 | 401 | return $ret; |
402 | 402 | } elseif ($withimage) { |
403 | - return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "viewmag.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_ADMIN_VIEW . "' title='" . _CO_SOBJECT_ADMIN_VIEW . "'></a>"; |
|
403 | + return "<a href='".$ret."'><img src='".SMARTOBJECT_IMAGES_ACTIONS_URL."viewmag.png' style='vertical-align: middle;' alt='"._CO_SOBJECT_ADMIN_VIEW."' title='"._CO_SOBJECT_ADMIN_VIEW."'></a>"; |
|
404 | 404 | } |
405 | 405 | |
406 | - return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
406 | + return "<a href='".$ret."'>".$smartObj->getVar($this->handler->identifierName).'</a>'; |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | /** |
@@ -425,15 +425,15 @@ discard block |
||
425 | 425 | $seoIncludeId = true; |
426 | 426 | |
427 | 427 | if ('rewrite' === $seoMode) { |
428 | - $ret = XOOPS_URL . '/' . $seoModuleName . '.' . $this->handler->_itemname . ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') . '/' . $smartObj->getVar('short_url') . '.html'; |
|
428 | + $ret = XOOPS_URL.'/'.$seoModuleName.'.'.$this->handler->_itemname.($seoIncludeId ? '.'.$smartObj->getVar($this->handler->keyName) : '').'/'.$smartObj->getVar('short_url').'.html'; |
|
429 | 429 | } elseif ('pathinfo' === $seoMode) { |
430 | - $ret = SMARTOBJECT_URL . 'seo.php/' . $seoModuleName . '.' . $this->handler->_itemname . ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') . '/' . $smartObj->getVar('short_url') . '.html'; |
|
430 | + $ret = SMARTOBJECT_URL.'seo.php/'.$seoModuleName.'.'.$this->handler->_itemname.($seoIncludeId ? '.'.$smartObj->getVar($this->handler->keyName) : '').'/'.$smartObj->getVar('short_url').'.html'; |
|
431 | 431 | } else { |
432 | - $ret = $this->handler->_moduleUrl . $this->handler->_page . '?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
432 | + $ret = $this->handler->_moduleUrl.$this->handler->_page.'?'.$this->handler->keyName.'='.$smartObj->getVar($this->handler->keyName); |
|
433 | 433 | } |
434 | 434 | |
435 | 435 | if (!$onlyUrl) { |
436 | - $ret = "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
436 | + $ret = "<a href='".$ret."'>".$smartObj->getVar($this->handler->identifierName).'</a>'; |
|
437 | 437 | } |
438 | 438 | |
439 | 439 | return $ret; |
@@ -447,14 +447,14 @@ discard block |
||
447 | 447 | */ |
448 | 448 | public function getEditLanguageLink($smartObj, $onlyUrl = false, $withimage = true) |
449 | 449 | { |
450 | - $ret = $this->handler->_moduleUrl . 'admin/' . $this->handler->_page . '?op=mod&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName) . '&language=' . $smartObj->getVar('language'); |
|
450 | + $ret = $this->handler->_moduleUrl.'admin/'.$this->handler->_page.'?op=mod&'.$this->handler->keyName.'='.$smartObj->getVar($this->handler->keyName).'&language='.$smartObj->getVar('language'); |
|
451 | 451 | if ($onlyUrl) { |
452 | 452 | return $ret; |
453 | 453 | } elseif ($withimage) { |
454 | - return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "wizard.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_LANGUAGE_MODIFY . "' title='" . _CO_SOBJECT_LANGUAGE_MODIFY . "'></a>"; |
|
454 | + return "<a href='".$ret."'><img src='".SMARTOBJECT_IMAGES_ACTIONS_URL."wizard.png' style='vertical-align: middle;' alt='"._CO_SOBJECT_LANGUAGE_MODIFY."' title='"._CO_SOBJECT_LANGUAGE_MODIFY."'></a>"; |
|
455 | 455 | } |
456 | 456 | |
457 | - return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
457 | + return "<a href='".$ret."'>".$smartObj->getVar($this->handler->identifierName).'</a>'; |
|
458 | 458 | } |
459 | 459 | |
460 | 460 | /** |
@@ -467,14 +467,14 @@ discard block |
||
467 | 467 | public function getEditItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false) |
468 | 468 | { |
469 | 469 | $admin_side = $userSide ? '' : 'admin/'; |
470 | - $ret = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=mod&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
470 | + $ret = $this->handler->_moduleUrl.$admin_side.$this->handler->_page.'?op=mod&'.$this->handler->keyName.'='.$smartObj->getVar($this->handler->keyName); |
|
471 | 471 | if ($onlyUrl) { |
472 | 472 | return $ret; |
473 | 473 | } elseif ($withimage) { |
474 | - return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "edit.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_MODIFY . "' title='" . _CO_SOBJECT_MODIFY . "'></a>"; |
|
474 | + return "<a href='".$ret."'><img src='".SMARTOBJECT_IMAGES_ACTIONS_URL."edit.png' style='vertical-align: middle;' alt='"._CO_SOBJECT_MODIFY."' title='"._CO_SOBJECT_MODIFY."'></a>"; |
|
475 | 475 | } |
476 | 476 | |
477 | - return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
477 | + return "<a href='".$ret."'>".$smartObj->getVar($this->handler->identifierName).'</a>'; |
|
478 | 478 | } |
479 | 479 | |
480 | 480 | /** |
@@ -487,14 +487,14 @@ discard block |
||
487 | 487 | public function getDeleteItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false) |
488 | 488 | { |
489 | 489 | $admin_side = $userSide ? '' : 'admin/'; |
490 | - $ret = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=del&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
490 | + $ret = $this->handler->_moduleUrl.$admin_side.$this->handler->_page.'?op=del&'.$this->handler->keyName.'='.$smartObj->getVar($this->handler->keyName); |
|
491 | 491 | if ($onlyUrl) { |
492 | 492 | return $ret; |
493 | 493 | } elseif ($withimage) { |
494 | - return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "editdelete.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_DELETE . "' title='" . _CO_SOBJECT_DELETE . "'></a>"; |
|
494 | + return "<a href='".$ret."'><img src='".SMARTOBJECT_IMAGES_ACTIONS_URL."editdelete.png' style='vertical-align: middle;' alt='"._CO_SOBJECT_DELETE."' title='"._CO_SOBJECT_DELETE."'></a>"; |
|
495 | 495 | } |
496 | 496 | |
497 | - return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
497 | + return "<a href='".$ret."'>".$smartObj->getVar($this->handler->identifierName).'</a>'; |
|
498 | 498 | } |
499 | 499 | |
500 | 500 | /** |
@@ -505,9 +505,9 @@ discard block |
||
505 | 505 | { |
506 | 506 | global $xoopsConfig; |
507 | 507 | |
508 | - $printlink = $this->handler->_moduleUrl . 'print.php?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
509 | - $js = "javascript:openWithSelfMain('" . $printlink . "', 'smartpopup', 700, 519);"; |
|
510 | - $printlink = '<a href="' . $js . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'fileprint.png" alt="" style="vertical-align: middle;"></a>'; |
|
508 | + $printlink = $this->handler->_moduleUrl.'print.php?'.$this->handler->keyName.'='.$smartObj->getVar($this->handler->keyName); |
|
509 | + $js = "javascript:openWithSelfMain('".$printlink."', 'smartpopup', 700, 519);"; |
|
510 | + $printlink = '<a href="'.$js.'"><img src="'.SMARTOBJECT_IMAGES_ACTIONS_URL.'fileprint.png" alt="" style="vertical-align: middle;"></a>'; |
|
511 | 511 | |
512 | 512 | $smartModule = Smartobject\Utility::getModuleInfo($smartObj->handler->_moduleName); |
513 | 513 | $link = Smartobject\Utility::getCurrentPage(); |
@@ -526,7 +526,7 @@ discard block |
||
526 | 526 | . _CO_SOBJECT_EMAIL |
527 | 527 | . '" style="vertical-align: middle;"></a>'; |
528 | 528 | |
529 | - $ret = '<span id="smartobject_print_button">' . $printlink . ' </span>' . '<span id="smartobject_mail_button">' . $friendlink . '</span>'; |
|
529 | + $ret = '<span id="smartobject_print_button">'.$printlink.' </span>'.'<span id="smartobject_mail_button">'.$friendlink.'</span>'; |
|
530 | 530 | |
531 | 531 | return $ret; |
532 | 532 | } |
@@ -536,7 +536,7 @@ discard block |
||
536 | 536 | */ |
537 | 537 | public function getModuleItemString() |
538 | 538 | { |
539 | - $ret = $this->handler->_moduleName . '_' . $this->handler->_itemname; |
|
539 | + $ret = $this->handler->_moduleName.'_'.$this->handler->_itemname; |
|
540 | 540 | |
541 | 541 | return $ret; |
542 | 542 | } |
@@ -32,7 +32,7 @@ |
||
32 | 32 | */ |
33 | 33 | /** |
34 | 34 | * @param $gperm_name |
35 | - * @param null $id |
|
35 | + * @param integer $id |
|
36 | 36 | * @return array |
37 | 37 | */ |
38 | 38 | public function getGrantedGroups($gperm_name, $id = null) |
@@ -19,18 +19,18 @@ discard block |
||
19 | 19 | */ |
20 | 20 | class PermissionHandler extends \XoopsObjectHandler |
21 | 21 | { |
22 | - public $handler; |
|
23 | - |
|
24 | - /** |
|
25 | - * SmartobjectPermissionHandler constructor. |
|
26 | - * @param \XoopsDatabase $handler |
|
27 | - */ |
|
28 | - public function __construct($handler) |
|
29 | - { |
|
30 | - $this->handler = $handler; |
|
31 | - } |
|
32 | - |
|
33 | - /* |
|
22 | + public $handler; |
|
23 | + |
|
24 | + /** |
|
25 | + * SmartobjectPermissionHandler constructor. |
|
26 | + * @param \XoopsDatabase $handler |
|
27 | + */ |
|
28 | + public function __construct($handler) |
|
29 | + { |
|
30 | + $this->handler = $handler; |
|
31 | + } |
|
32 | + |
|
33 | + /* |
|
34 | 34 | * Returns permissions for a certain type |
35 | 35 | * |
36 | 36 | * @param string $type "global", "forum" or "topic" (should perhaps have "post" as well - but I don't know) |
@@ -38,74 +38,74 @@ discard block |
||
38 | 38 | * |
39 | 39 | * @return array |
40 | 40 | */ |
41 | - /** |
|
42 | - * @param $gperm_name |
|
43 | - * @param null $id |
|
44 | - * @return array |
|
45 | - */ |
|
46 | - public function getGrantedGroups($gperm_name, $id = null) |
|
47 | - { |
|
48 | - static $groups; |
|
49 | - |
|
50 | - if (!isset($groups[$gperm_name]) || (null !== $id && !isset($groups[$gperm_name][$id]))) { |
|
51 | - $smartModule = $this->handler->getModuleInfo(); |
|
52 | - //Get group permissions handler |
|
53 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
54 | - |
|
55 | - //Get groups allowed for an item id |
|
56 | - $allowedgroups = $gpermHandler->getGroupIds($gperm_name, $id, $smartModule->getVar('mid')); |
|
57 | - $groups[$gperm_name][$id] = $allowedgroups; |
|
58 | - } |
|
59 | - |
|
60 | - //Return the permission array |
|
61 | - return isset($groups[$gperm_name][$id]) ? $groups[$gperm_name][$id] : []; |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * @param $item_ids_array |
|
66 | - * @param bool $gperm_name |
|
67 | - * @return array |
|
68 | - */ |
|
69 | - public function getGrantedGroupsForIds($item_ids_array, $gperm_name = false) |
|
70 | - { |
|
71 | - static $groups; |
|
72 | - |
|
73 | - if ($gperm_name) { |
|
74 | - if (isset($groups[$gperm_name])) { |
|
75 | - return $groups[$gperm_name]; |
|
76 | - } |
|
77 | - } else { |
|
78 | - // if !$gperm_name then we will fetch all permissions in the module so we don't need them again |
|
79 | - return $groups; |
|
80 | - } |
|
81 | - |
|
82 | - $smartModule = $this->handler->getModuleInfo(); |
|
83 | - |
|
84 | - $criteria = new \CriteriaCompo(); |
|
85 | - $criteria->add(new \Criteria('gperm_modid', $smartModule->getVar('mid'))); |
|
86 | - |
|
87 | - if ($gperm_name) { |
|
88 | - $criteria->add(new \Criteria('gperm_name', $gperm_name)); |
|
89 | - } |
|
90 | - |
|
91 | - //Get group permissions handler |
|
92 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
93 | - |
|
94 | - $permissionsObj = $gpermHandler->getObjects($criteria); |
|
95 | - |
|
96 | - foreach ($permissionsObj as $permissionObj) { |
|
97 | - $groups[$permissionObj->getVar('gperm_name')][$permissionObj->getVar('gperm_itemid')][] = $permissionObj->getVar('gperm_groupid'); |
|
98 | - } |
|
99 | - |
|
100 | - //Return the permission array |
|
101 | - if ($gperm_name) { |
|
102 | - return isset($groups[$gperm_name]) ? $groups[$gperm_name] : []; |
|
103 | - } else { |
|
104 | - return isset($groups) ? $groups : []; |
|
105 | - } |
|
106 | - } |
|
107 | - |
|
108 | - /* |
|
41 | + /** |
|
42 | + * @param $gperm_name |
|
43 | + * @param null $id |
|
44 | + * @return array |
|
45 | + */ |
|
46 | + public function getGrantedGroups($gperm_name, $id = null) |
|
47 | + { |
|
48 | + static $groups; |
|
49 | + |
|
50 | + if (!isset($groups[$gperm_name]) || (null !== $id && !isset($groups[$gperm_name][$id]))) { |
|
51 | + $smartModule = $this->handler->getModuleInfo(); |
|
52 | + //Get group permissions handler |
|
53 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
54 | + |
|
55 | + //Get groups allowed for an item id |
|
56 | + $allowedgroups = $gpermHandler->getGroupIds($gperm_name, $id, $smartModule->getVar('mid')); |
|
57 | + $groups[$gperm_name][$id] = $allowedgroups; |
|
58 | + } |
|
59 | + |
|
60 | + //Return the permission array |
|
61 | + return isset($groups[$gperm_name][$id]) ? $groups[$gperm_name][$id] : []; |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * @param $item_ids_array |
|
66 | + * @param bool $gperm_name |
|
67 | + * @return array |
|
68 | + */ |
|
69 | + public function getGrantedGroupsForIds($item_ids_array, $gperm_name = false) |
|
70 | + { |
|
71 | + static $groups; |
|
72 | + |
|
73 | + if ($gperm_name) { |
|
74 | + if (isset($groups[$gperm_name])) { |
|
75 | + return $groups[$gperm_name]; |
|
76 | + } |
|
77 | + } else { |
|
78 | + // if !$gperm_name then we will fetch all permissions in the module so we don't need them again |
|
79 | + return $groups; |
|
80 | + } |
|
81 | + |
|
82 | + $smartModule = $this->handler->getModuleInfo(); |
|
83 | + |
|
84 | + $criteria = new \CriteriaCompo(); |
|
85 | + $criteria->add(new \Criteria('gperm_modid', $smartModule->getVar('mid'))); |
|
86 | + |
|
87 | + if ($gperm_name) { |
|
88 | + $criteria->add(new \Criteria('gperm_name', $gperm_name)); |
|
89 | + } |
|
90 | + |
|
91 | + //Get group permissions handler |
|
92 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
93 | + |
|
94 | + $permissionsObj = $gpermHandler->getObjects($criteria); |
|
95 | + |
|
96 | + foreach ($permissionsObj as $permissionObj) { |
|
97 | + $groups[$permissionObj->getVar('gperm_name')][$permissionObj->getVar('gperm_itemid')][] = $permissionObj->getVar('gperm_groupid'); |
|
98 | + } |
|
99 | + |
|
100 | + //Return the permission array |
|
101 | + if ($gperm_name) { |
|
102 | + return isset($groups[$gperm_name]) ? $groups[$gperm_name] : []; |
|
103 | + } else { |
|
104 | + return isset($groups) ? $groups : []; |
|
105 | + } |
|
106 | + } |
|
107 | + |
|
108 | + /* |
|
109 | 109 | * Returns permissions for a certain type |
110 | 110 | * |
111 | 111 | * @param string $type "global", "forum" or "topic" (should perhaps have "post" as well - but I don't know) |
@@ -113,123 +113,123 @@ discard block |
||
113 | 113 | * |
114 | 114 | * @return array |
115 | 115 | */ |
116 | - /** |
|
117 | - * @param $gperm_name |
|
118 | - * @param null $id |
|
119 | - * @return array |
|
120 | - */ |
|
121 | - public function getGrantedItems($gperm_name, $id = null) |
|
122 | - { |
|
123 | - global $xoopsUser; |
|
124 | - static $permissions; |
|
125 | - |
|
126 | - if (!isset($permissions[$gperm_name]) || (null !== $id && !isset($permissions[$gperm_name][$id]))) { |
|
127 | - $smartModule = $this->handler->getModuleInfo(); |
|
128 | - |
|
129 | - if (is_object($smartModule)) { |
|
130 | - |
|
131 | - //Get group permissions handler |
|
132 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
133 | - |
|
134 | - //Get user's groups |
|
135 | - $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : [XOOPS_GROUP_ANONYMOUS]; |
|
136 | - |
|
137 | - //Get all allowed item ids in this module and for this user's groups |
|
138 | - $userpermissions = $gpermHandler->getItemIds($gperm_name, $groups, $smartModule->getVar('mid')); |
|
139 | - $permissions[$gperm_name] = $userpermissions; |
|
140 | - } |
|
141 | - } |
|
142 | - |
|
143 | - //Return the permission array |
|
144 | - return isset($permissions[$gperm_name]) ? $permissions[$gperm_name] : []; |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * @param $id |
|
149 | - */ |
|
150 | - public function storeAllPermissionsForId($id) |
|
151 | - { |
|
152 | - foreach ($this->handler->getPermissions() as $permission) { |
|
153 | - $this->saveItem_Permissions($_POST[$permission['perm_name']], $id, $permission['perm_name']); |
|
154 | - } |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * Saves permissions for the selected item |
|
159 | - * |
|
160 | - * saveItem_Permissions() |
|
161 | - * |
|
162 | - * @param array $groups : group with granted permission |
|
163 | - * @param int $itemid categoryID on which we are setting permissions for Categories and Forums |
|
164 | - * @param string $perm_name : name of the permission |
|
165 | - * @return bool : TRUE if the no errors occured |
|
166 | - */ |
|
167 | - |
|
168 | - public function saveItem_Permissions($groups, $itemid, $perm_name) |
|
169 | - { |
|
170 | - $smartModule = $this->handler->getModuleInfo(); |
|
171 | - |
|
172 | - $result = true; |
|
173 | - $module_id = $smartModule->getVar('mid'); |
|
174 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
175 | - |
|
176 | - // First, if the permissions are already there, delete them |
|
177 | - $gpermHandler->deleteByModule($module_id, $perm_name, $itemid); |
|
178 | - //echo "itemid: $itemid - perm: $perm_name - modid: $module_id"; |
|
179 | - //exit; |
|
180 | - // Save the new permissions |
|
181 | - |
|
182 | - if (count($groups) > 0) { |
|
183 | - foreach ($groups as $group_id) { |
|
184 | - $gpermHandler->addRight($perm_name, $itemid, $group_id, $module_id); |
|
185 | - } |
|
186 | - } |
|
187 | - |
|
188 | - return $result; |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * Delete all permission for a specific item |
|
193 | - * |
|
194 | - * deletePermissions() |
|
195 | - * |
|
196 | - * @param integer $itemid : id of the item for which to delete the permissions |
|
197 | - * @param $gperm_name |
|
198 | - * @return bool: TRUE if the no errors occured |
|
199 | - */ |
|
200 | - public function deletePermissions($itemid, $gperm_name) |
|
201 | - { |
|
202 | - global $xoopsModule; |
|
203 | - |
|
204 | - $smartModule = smartsection_getModuleInfo(); |
|
205 | - |
|
206 | - $result = true; |
|
207 | - $module_id = $smartModule->getVar('mid'); |
|
208 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
209 | - |
|
210 | - $gpermHandler->deleteByModule($module_id, $gperm_name, $itemid); |
|
211 | - |
|
212 | - return $result; |
|
213 | - } |
|
214 | - |
|
215 | - /** |
|
216 | - * Checks if the user has access to a specific permission on a given object |
|
217 | - * |
|
218 | - * @param string $gperm_name name of the permission to test |
|
219 | - * @param int $gperm_itemid id of the object to check |
|
220 | - * @return boolean: TRUE if user has access, FALSE if not |
|
221 | - **/ |
|
222 | - public function accessGranted($gperm_name, $gperm_itemid) |
|
223 | - { |
|
224 | - global $xoopsUser; |
|
225 | - |
|
226 | - $gperm_groupid = is_object($xoopsUser) ? $xoopsUser->getGroups() : [XOOPS_GROUP_ANONYMOUS]; |
|
227 | - $smartModule = $this->handler->getModuleInfo(); |
|
228 | - $gperm_modid = $smartModule->getVar('mid'); |
|
229 | - |
|
230 | - //Get group permissions handler |
|
231 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
232 | - |
|
233 | - return $gpermHandler->checkRight($gperm_name, $gperm_itemid, $gperm_groupid, $gperm_modid); |
|
234 | - } |
|
116 | + /** |
|
117 | + * @param $gperm_name |
|
118 | + * @param null $id |
|
119 | + * @return array |
|
120 | + */ |
|
121 | + public function getGrantedItems($gperm_name, $id = null) |
|
122 | + { |
|
123 | + global $xoopsUser; |
|
124 | + static $permissions; |
|
125 | + |
|
126 | + if (!isset($permissions[$gperm_name]) || (null !== $id && !isset($permissions[$gperm_name][$id]))) { |
|
127 | + $smartModule = $this->handler->getModuleInfo(); |
|
128 | + |
|
129 | + if (is_object($smartModule)) { |
|
130 | + |
|
131 | + //Get group permissions handler |
|
132 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
133 | + |
|
134 | + //Get user's groups |
|
135 | + $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : [XOOPS_GROUP_ANONYMOUS]; |
|
136 | + |
|
137 | + //Get all allowed item ids in this module and for this user's groups |
|
138 | + $userpermissions = $gpermHandler->getItemIds($gperm_name, $groups, $smartModule->getVar('mid')); |
|
139 | + $permissions[$gperm_name] = $userpermissions; |
|
140 | + } |
|
141 | + } |
|
142 | + |
|
143 | + //Return the permission array |
|
144 | + return isset($permissions[$gperm_name]) ? $permissions[$gperm_name] : []; |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * @param $id |
|
149 | + */ |
|
150 | + public function storeAllPermissionsForId($id) |
|
151 | + { |
|
152 | + foreach ($this->handler->getPermissions() as $permission) { |
|
153 | + $this->saveItem_Permissions($_POST[$permission['perm_name']], $id, $permission['perm_name']); |
|
154 | + } |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * Saves permissions for the selected item |
|
159 | + * |
|
160 | + * saveItem_Permissions() |
|
161 | + * |
|
162 | + * @param array $groups : group with granted permission |
|
163 | + * @param int $itemid categoryID on which we are setting permissions for Categories and Forums |
|
164 | + * @param string $perm_name : name of the permission |
|
165 | + * @return bool : TRUE if the no errors occured |
|
166 | + */ |
|
167 | + |
|
168 | + public function saveItem_Permissions($groups, $itemid, $perm_name) |
|
169 | + { |
|
170 | + $smartModule = $this->handler->getModuleInfo(); |
|
171 | + |
|
172 | + $result = true; |
|
173 | + $module_id = $smartModule->getVar('mid'); |
|
174 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
175 | + |
|
176 | + // First, if the permissions are already there, delete them |
|
177 | + $gpermHandler->deleteByModule($module_id, $perm_name, $itemid); |
|
178 | + //echo "itemid: $itemid - perm: $perm_name - modid: $module_id"; |
|
179 | + //exit; |
|
180 | + // Save the new permissions |
|
181 | + |
|
182 | + if (count($groups) > 0) { |
|
183 | + foreach ($groups as $group_id) { |
|
184 | + $gpermHandler->addRight($perm_name, $itemid, $group_id, $module_id); |
|
185 | + } |
|
186 | + } |
|
187 | + |
|
188 | + return $result; |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * Delete all permission for a specific item |
|
193 | + * |
|
194 | + * deletePermissions() |
|
195 | + * |
|
196 | + * @param integer $itemid : id of the item for which to delete the permissions |
|
197 | + * @param $gperm_name |
|
198 | + * @return bool: TRUE if the no errors occured |
|
199 | + */ |
|
200 | + public function deletePermissions($itemid, $gperm_name) |
|
201 | + { |
|
202 | + global $xoopsModule; |
|
203 | + |
|
204 | + $smartModule = smartsection_getModuleInfo(); |
|
205 | + |
|
206 | + $result = true; |
|
207 | + $module_id = $smartModule->getVar('mid'); |
|
208 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
209 | + |
|
210 | + $gpermHandler->deleteByModule($module_id, $gperm_name, $itemid); |
|
211 | + |
|
212 | + return $result; |
|
213 | + } |
|
214 | + |
|
215 | + /** |
|
216 | + * Checks if the user has access to a specific permission on a given object |
|
217 | + * |
|
218 | + * @param string $gperm_name name of the permission to test |
|
219 | + * @param int $gperm_itemid id of the object to check |
|
220 | + * @return boolean: TRUE if user has access, FALSE if not |
|
221 | + **/ |
|
222 | + public function accessGranted($gperm_name, $gperm_itemid) |
|
223 | + { |
|
224 | + global $xoopsUser; |
|
225 | + |
|
226 | + $gperm_groupid = is_object($xoopsUser) ? $xoopsUser->getGroups() : [XOOPS_GROUP_ANONYMOUS]; |
|
227 | + $smartModule = $this->handler->getModuleInfo(); |
|
228 | + $gperm_modid = $smartModule->getVar('mid'); |
|
229 | + |
|
230 | + //Get group permissions handler |
|
231 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
232 | + |
|
233 | + return $gpermHandler->checkRight($gperm_name, $gperm_itemid, $gperm_groupid, $gperm_modid); |
|
234 | + } |
|
235 | 235 | } |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | |
194 | 194 | /** |
195 | 195 | * @param $criteria |
196 | - * @param $perm_name |
|
196 | + * @param boolean $perm_name |
|
197 | 197 | * @return bool |
198 | 198 | */ |
199 | 199 | public function setGrantedObjectsCriteria($criteria, $perm_name) |
@@ -387,7 +387,7 @@ discard block |
||
387 | 387 | } |
388 | 388 | |
389 | 389 | /** |
390 | - * @param $sql |
|
390 | + * @param string $sql |
|
391 | 391 | * @param $criteria |
392 | 392 | * @param bool $force |
393 | 393 | * @param bool $debug |
@@ -29,985 +29,985 @@ |
||
29 | 29 | |
30 | 30 | class PersistableObjectHandler extends \XoopsObjectHandler |
31 | 31 | { |
32 | - public $_itemname; |
|
33 | - |
|
34 | - /** |
|
35 | - * Name of the table use to store this {@link SmartObject} |
|
36 | - * |
|
37 | - * Note that the name of the table needs to be free of the database prefix. |
|
38 | - * For example "smartsection_categories" |
|
39 | - * @var string |
|
40 | - */ |
|
41 | - public $table; |
|
42 | - |
|
43 | - /** |
|
44 | - * Name of the table key that uniquely identify each {@link SmartObject} |
|
45 | - * |
|
46 | - * For example: "categoryid" |
|
47 | - * @var string |
|
48 | - */ |
|
49 | - public $keyName; |
|
50 | - |
|
51 | - /** |
|
52 | - * Name of the class derived from {@link BaseSmartObject} and which this handler is handling |
|
53 | - * |
|
54 | - * Note that this string needs to be lowercase |
|
55 | - * |
|
56 | - * For example: "smartsectioncategory" |
|
57 | - * @var string |
|
58 | - */ |
|
59 | - public $className; |
|
60 | - |
|
61 | - /** |
|
62 | - * Name of the field which properly identify the {@link SmartObject} |
|
63 | - * |
|
64 | - * For example: "name" (this will be the category's name) |
|
65 | - * @var string |
|
66 | - */ |
|
67 | - public $identifierName; |
|
68 | - |
|
69 | - /** |
|
70 | - * Name of the field which will be use as a summary for the object |
|
71 | - * |
|
72 | - * For example: "summary" |
|
73 | - * @var string |
|
74 | - */ |
|
75 | - public $summaryName; |
|
76 | - |
|
77 | - /** |
|
78 | - * Page name use to basically manage and display the {@link SmartObject} |
|
79 | - * |
|
80 | - * This page needs to be the same in user side and admin side |
|
81 | - * |
|
82 | - * For example category.php - we will deduct smartsection/category.php as well as smartsection/admin/category.php |
|
83 | - * @todo this could probably be automatically deducted from the class name - for example, the class SmartsectionCategory will have "category.php" as it's managing page |
|
84 | - * @var string |
|
85 | - */ |
|
86 | - public $_page; |
|
87 | - |
|
88 | - /** |
|
89 | - * Full path of the module using this {@link SmartObject} |
|
90 | - * |
|
91 | - * <code>XOOPS_URL . "/modules/smartsection/"</code> |
|
92 | - * @todo this could probably be automatically deducted from the class name as it is always prefixed with the module name |
|
93 | - * @var string |
|
94 | - */ |
|
95 | - public $_modulePath; |
|
96 | - |
|
97 | - public $_moduleUrl; |
|
98 | - |
|
99 | - public $_moduleName; |
|
100 | - |
|
101 | - public $_uploadUrl; |
|
102 | - |
|
103 | - public $_uploadPath; |
|
104 | - |
|
105 | - public $_allowedMimeTypes = 0; |
|
106 | - |
|
107 | - public $_maxFileSize = 1000000; |
|
108 | - |
|
109 | - public $_maxWidth = 500; |
|
110 | - |
|
111 | - public $_maxHeight = 500; |
|
112 | - |
|
113 | - public $highlightFields = []; |
|
114 | - |
|
115 | - /** |
|
116 | - * Array containing the events name and functions |
|
117 | - * |
|
118 | - * @var array |
|
119 | - */ |
|
120 | - public $eventArray = []; |
|
121 | - |
|
122 | - /** |
|
123 | - * Array containing the permissions that this handler will manage on the objects |
|
124 | - * |
|
125 | - * @var array |
|
126 | - */ |
|
127 | - public $permissionsArray = false; |
|
128 | - |
|
129 | - public $generalSQL = false; |
|
130 | - |
|
131 | - public $_eventHooks = []; |
|
132 | - public $_disabledEvents = []; |
|
133 | - |
|
134 | - /** |
|
135 | - * Constructor - called from child classes |
|
136 | - * |
|
137 | - * @param \XoopsDatabase $db {@link XoopsDatabase} |
|
138 | - * @param string $itemname Name of the class derived from <a href='psi_element://SmartObject'>SmartObject</a> and which this handler is handling and which this handler is handling |
|
139 | - * @param string $keyname Name of the table key that uniquely identify each {@link SmartObject} |
|
140 | - * @param string $idenfierName Name of the field which properly identify the {@link SmartObject} |
|
141 | - * @param string $summaryName |
|
142 | - * @param string $modulename |
|
143 | - * @internal param string $tablename Name of the table use to store this <a href='psi_element://SmartObject'>SmartObject</a> |
|
144 | - * @internal param string $page Page name use to basically manage and display the <a href='psi_element://SmartObject'>SmartObject</a> |
|
145 | - * @internal param string $moduleName name of the module |
|
146 | - */ |
|
147 | - public function __construct(\XoopsDatabase $db, $itemname, $keyname, $idenfierName, $summaryName, $modulename) |
|
148 | - { |
|
149 | - parent::__construct($db); |
|
150 | - |
|
151 | - $this->_itemname = $itemname; |
|
152 | - $this->_moduleName = $modulename; |
|
153 | - $this->table = $db->prefix($modulename . '_' . $itemname); |
|
154 | - $this->keyName = $keyname; |
|
32 | + public $_itemname; |
|
33 | + |
|
34 | + /** |
|
35 | + * Name of the table use to store this {@link SmartObject} |
|
36 | + * |
|
37 | + * Note that the name of the table needs to be free of the database prefix. |
|
38 | + * For example "smartsection_categories" |
|
39 | + * @var string |
|
40 | + */ |
|
41 | + public $table; |
|
42 | + |
|
43 | + /** |
|
44 | + * Name of the table key that uniquely identify each {@link SmartObject} |
|
45 | + * |
|
46 | + * For example: "categoryid" |
|
47 | + * @var string |
|
48 | + */ |
|
49 | + public $keyName; |
|
50 | + |
|
51 | + /** |
|
52 | + * Name of the class derived from {@link BaseSmartObject} and which this handler is handling |
|
53 | + * |
|
54 | + * Note that this string needs to be lowercase |
|
55 | + * |
|
56 | + * For example: "smartsectioncategory" |
|
57 | + * @var string |
|
58 | + */ |
|
59 | + public $className; |
|
60 | + |
|
61 | + /** |
|
62 | + * Name of the field which properly identify the {@link SmartObject} |
|
63 | + * |
|
64 | + * For example: "name" (this will be the category's name) |
|
65 | + * @var string |
|
66 | + */ |
|
67 | + public $identifierName; |
|
68 | + |
|
69 | + /** |
|
70 | + * Name of the field which will be use as a summary for the object |
|
71 | + * |
|
72 | + * For example: "summary" |
|
73 | + * @var string |
|
74 | + */ |
|
75 | + public $summaryName; |
|
76 | + |
|
77 | + /** |
|
78 | + * Page name use to basically manage and display the {@link SmartObject} |
|
79 | + * |
|
80 | + * This page needs to be the same in user side and admin side |
|
81 | + * |
|
82 | + * For example category.php - we will deduct smartsection/category.php as well as smartsection/admin/category.php |
|
83 | + * @todo this could probably be automatically deducted from the class name - for example, the class SmartsectionCategory will have "category.php" as it's managing page |
|
84 | + * @var string |
|
85 | + */ |
|
86 | + public $_page; |
|
87 | + |
|
88 | + /** |
|
89 | + * Full path of the module using this {@link SmartObject} |
|
90 | + * |
|
91 | + * <code>XOOPS_URL . "/modules/smartsection/"</code> |
|
92 | + * @todo this could probably be automatically deducted from the class name as it is always prefixed with the module name |
|
93 | + * @var string |
|
94 | + */ |
|
95 | + public $_modulePath; |
|
96 | + |
|
97 | + public $_moduleUrl; |
|
98 | + |
|
99 | + public $_moduleName; |
|
100 | + |
|
101 | + public $_uploadUrl; |
|
102 | + |
|
103 | + public $_uploadPath; |
|
104 | + |
|
105 | + public $_allowedMimeTypes = 0; |
|
106 | + |
|
107 | + public $_maxFileSize = 1000000; |
|
108 | + |
|
109 | + public $_maxWidth = 500; |
|
110 | + |
|
111 | + public $_maxHeight = 500; |
|
112 | + |
|
113 | + public $highlightFields = []; |
|
114 | + |
|
115 | + /** |
|
116 | + * Array containing the events name and functions |
|
117 | + * |
|
118 | + * @var array |
|
119 | + */ |
|
120 | + public $eventArray = []; |
|
121 | + |
|
122 | + /** |
|
123 | + * Array containing the permissions that this handler will manage on the objects |
|
124 | + * |
|
125 | + * @var array |
|
126 | + */ |
|
127 | + public $permissionsArray = false; |
|
128 | + |
|
129 | + public $generalSQL = false; |
|
130 | + |
|
131 | + public $_eventHooks = []; |
|
132 | + public $_disabledEvents = []; |
|
133 | + |
|
134 | + /** |
|
135 | + * Constructor - called from child classes |
|
136 | + * |
|
137 | + * @param \XoopsDatabase $db {@link XoopsDatabase} |
|
138 | + * @param string $itemname Name of the class derived from <a href='psi_element://SmartObject'>SmartObject</a> and which this handler is handling and which this handler is handling |
|
139 | + * @param string $keyname Name of the table key that uniquely identify each {@link SmartObject} |
|
140 | + * @param string $idenfierName Name of the field which properly identify the {@link SmartObject} |
|
141 | + * @param string $summaryName |
|
142 | + * @param string $modulename |
|
143 | + * @internal param string $tablename Name of the table use to store this <a href='psi_element://SmartObject'>SmartObject</a> |
|
144 | + * @internal param string $page Page name use to basically manage and display the <a href='psi_element://SmartObject'>SmartObject</a> |
|
145 | + * @internal param string $moduleName name of the module |
|
146 | + */ |
|
147 | + public function __construct(\XoopsDatabase $db, $itemname, $keyname, $idenfierName, $summaryName, $modulename) |
|
148 | + { |
|
149 | + parent::__construct($db); |
|
150 | + |
|
151 | + $this->_itemname = $itemname; |
|
152 | + $this->_moduleName = $modulename; |
|
153 | + $this->table = $db->prefix($modulename . '_' . $itemname); |
|
154 | + $this->keyName = $keyname; |
|
155 | 155 | // $this->className = ucfirst($modulename) . ucfirst($itemname); |
156 | - $this->className = $itemname; |
|
157 | - |
|
158 | - $this->identifierName = $idenfierName; |
|
159 | - $this->summaryName = $summaryName; |
|
160 | - $this->_page = $itemname . '.php'; |
|
161 | - $this->_modulePath = XOOPS_ROOT_PATH . '/modules/' . $this->_moduleName . '/'; |
|
162 | - $this->_moduleUrl = XOOPS_URL . '/modules/' . $this->_moduleName . '/'; |
|
163 | - $this->_uploadPath = XOOPS_UPLOAD_PATH . '/' . $this->_moduleName . '/'; |
|
164 | - $this->_uploadUrl = XOOPS_UPLOAD_URL . '/' . $this->_moduleName . '/'; |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * @param $event |
|
169 | - * @param $method |
|
170 | - */ |
|
171 | - public function addEventHook($event, $method) |
|
172 | - { |
|
173 | - $this->_eventHooks[$event] = $method; |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * Add a permission that this handler will manage for its objects |
|
178 | - * |
|
179 | - * Example: $this->addPermission('view', _AM_SSHOP_CAT_PERM_READ, _AM_SSHOP_CAT_PERM_READ_DSC); |
|
180 | - * |
|
181 | - * @param string $perm_name name of the permission |
|
182 | - * @param string $caption caption of the control that will be displayed in the form |
|
183 | - * @param bool|string $description description of the control that will be displayed in the form |
|
184 | - */ |
|
185 | - public function addPermission($perm_name, $caption, $description = false) |
|
186 | - { |
|
156 | + $this->className = $itemname; |
|
157 | + |
|
158 | + $this->identifierName = $idenfierName; |
|
159 | + $this->summaryName = $summaryName; |
|
160 | + $this->_page = $itemname . '.php'; |
|
161 | + $this->_modulePath = XOOPS_ROOT_PATH . '/modules/' . $this->_moduleName . '/'; |
|
162 | + $this->_moduleUrl = XOOPS_URL . '/modules/' . $this->_moduleName . '/'; |
|
163 | + $this->_uploadPath = XOOPS_UPLOAD_PATH . '/' . $this->_moduleName . '/'; |
|
164 | + $this->_uploadUrl = XOOPS_UPLOAD_URL . '/' . $this->_moduleName . '/'; |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * @param $event |
|
169 | + * @param $method |
|
170 | + */ |
|
171 | + public function addEventHook($event, $method) |
|
172 | + { |
|
173 | + $this->_eventHooks[$event] = $method; |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * Add a permission that this handler will manage for its objects |
|
178 | + * |
|
179 | + * Example: $this->addPermission('view', _AM_SSHOP_CAT_PERM_READ, _AM_SSHOP_CAT_PERM_READ_DSC); |
|
180 | + * |
|
181 | + * @param string $perm_name name of the permission |
|
182 | + * @param string $caption caption of the control that will be displayed in the form |
|
183 | + * @param bool|string $description description of the control that will be displayed in the form |
|
184 | + */ |
|
185 | + public function addPermission($perm_name, $caption, $description = false) |
|
186 | + { |
|
187 | 187 | // require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectpermission.php'; |
188 | 188 | |
189 | - $this->permissionsArray[] = [ |
|
190 | - 'perm_name' => $perm_name, |
|
191 | - 'caption' => $caption, |
|
192 | - 'description' => $description |
|
193 | - ]; |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * @param $criteria |
|
198 | - * @param $perm_name |
|
199 | - * @return bool |
|
200 | - */ |
|
201 | - public function setGrantedObjectsCriteria($criteria, $perm_name) |
|
202 | - { |
|
203 | - $smartPermissionsHandler = new PermissionHandler($this); |
|
204 | - $grantedItems = $smartPermissionsHandler->getGrantedItems($perm_name); |
|
205 | - if (count($grantedItems) > 0) { |
|
206 | - $criteria->add(new \Criteria($this->keyName, '(' . implode(', ', $grantedItems) . ')', 'IN')); |
|
207 | - |
|
208 | - return true; |
|
209 | - } else { |
|
210 | - return false; |
|
211 | - } |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * @param bool $_uploadPath |
|
216 | - * @param bool $_allowedMimeTypes |
|
217 | - * @param bool $_maxFileSize |
|
218 | - * @param bool $_maxWidth |
|
219 | - * @param bool $_maxHeight |
|
220 | - */ |
|
221 | - public function setUploaderConfig( |
|
222 | - $_uploadPath = false, |
|
223 | - $_allowedMimeTypes = false, |
|
224 | - $_maxFileSize = false, |
|
225 | - $_maxWidth = false, |
|
226 | - $_maxHeight = false |
|
227 | - ) { |
|
228 | - $this->_uploadPath = $_uploadPath ?: $this->_uploadPath; |
|
229 | - $this->_allowedMimeTypes = $_allowedMimeTypes ?: $this->_allowedMimeTypes; |
|
230 | - $this->_maxFileSize = $_maxFileSize ?: $this->_maxFileSize; |
|
231 | - $this->_maxWidth = $_maxWidth ?: $this->_maxWidth; |
|
232 | - $this->_maxHeight = $_maxHeight ?: $this->_maxHeight; |
|
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * create a new {@link Smartobject\BaseSmartObject} |
|
237 | - * |
|
238 | - * @param bool $isNew Flag the new objects as "new"? |
|
239 | - * |
|
240 | - * @return Smartobject\BaseSmartObject {@link Smartobject\BaseSmartObject} |
|
241 | - */ |
|
242 | - public function create($isNew = true) |
|
243 | - { |
|
189 | + $this->permissionsArray[] = [ |
|
190 | + 'perm_name' => $perm_name, |
|
191 | + 'caption' => $caption, |
|
192 | + 'description' => $description |
|
193 | + ]; |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * @param $criteria |
|
198 | + * @param $perm_name |
|
199 | + * @return bool |
|
200 | + */ |
|
201 | + public function setGrantedObjectsCriteria($criteria, $perm_name) |
|
202 | + { |
|
203 | + $smartPermissionsHandler = new PermissionHandler($this); |
|
204 | + $grantedItems = $smartPermissionsHandler->getGrantedItems($perm_name); |
|
205 | + if (count($grantedItems) > 0) { |
|
206 | + $criteria->add(new \Criteria($this->keyName, '(' . implode(', ', $grantedItems) . ')', 'IN')); |
|
207 | + |
|
208 | + return true; |
|
209 | + } else { |
|
210 | + return false; |
|
211 | + } |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * @param bool $_uploadPath |
|
216 | + * @param bool $_allowedMimeTypes |
|
217 | + * @param bool $_maxFileSize |
|
218 | + * @param bool $_maxWidth |
|
219 | + * @param bool $_maxHeight |
|
220 | + */ |
|
221 | + public function setUploaderConfig( |
|
222 | + $_uploadPath = false, |
|
223 | + $_allowedMimeTypes = false, |
|
224 | + $_maxFileSize = false, |
|
225 | + $_maxWidth = false, |
|
226 | + $_maxHeight = false |
|
227 | + ) { |
|
228 | + $this->_uploadPath = $_uploadPath ?: $this->_uploadPath; |
|
229 | + $this->_allowedMimeTypes = $_allowedMimeTypes ?: $this->_allowedMimeTypes; |
|
230 | + $this->_maxFileSize = $_maxFileSize ?: $this->_maxFileSize; |
|
231 | + $this->_maxWidth = $_maxWidth ?: $this->_maxWidth; |
|
232 | + $this->_maxHeight = $_maxHeight ?: $this->_maxHeight; |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * create a new {@link Smartobject\BaseSmartObject} |
|
237 | + * |
|
238 | + * @param bool $isNew Flag the new objects as "new"? |
|
239 | + * |
|
240 | + * @return Smartobject\BaseSmartObject {@link Smartobject\BaseSmartObject} |
|
241 | + */ |
|
242 | + public function create($isNew = true) |
|
243 | + { |
|
244 | 244 | // $obj0 = new $this->className($this); |
245 | 245 | |
246 | - $obj = new $this->className; |
|
247 | - |
|
248 | - $obj->setImageDir($this->getImageUrl(), $this->getImagePath()); |
|
249 | - if (!$obj->handler) { |
|
250 | - $obj->Handler = $this; |
|
251 | - } |
|
252 | - |
|
253 | - if (true === $isNew) { |
|
254 | - $obj->setNew(); |
|
255 | - } |
|
256 | - |
|
257 | - return $obj; |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * @return string |
|
262 | - */ |
|
263 | - public function getImageUrl() |
|
264 | - { |
|
265 | - return $this->_uploadUrl . $this->_itemname . '/'; |
|
266 | - } |
|
267 | - |
|
268 | - /** |
|
269 | - * @return string |
|
270 | - */ |
|
271 | - public function getImagePath() |
|
272 | - { |
|
273 | - $dir = $this->_uploadPath . $this->_itemname; |
|
274 | - if (!file_exists($dir)) { |
|
275 | - Smartobject\Utility::mkdirAsAdmin($dir); |
|
276 | - } |
|
277 | - |
|
278 | - return $dir . '/'; |
|
279 | - } |
|
280 | - |
|
281 | - /** |
|
282 | - * retrieve a {@link SmartObject} |
|
283 | - * |
|
284 | - * @param mixed $id ID of the object - or array of ids for joint keys. Joint keys MUST be given in the same order as in the constructor |
|
285 | - * @param bool $as_object whether to return an object or an array |
|
286 | - * @param bool $debug |
|
287 | - * @param bool $criteria |
|
288 | - * @return mixed reference to the <a href='psi_element://SmartObject'>SmartObject</a>, FALSE if failed |
|
289 | - * FALSE if failed |
|
290 | - */ |
|
291 | - public function get($id, $as_object = true, $debug = false, $criteria = false) |
|
292 | - { |
|
293 | - if (!$criteria) { |
|
294 | - $criteria = new \CriteriaCompo(); |
|
295 | - } |
|
296 | - if (is_array($this->keyName)) { |
|
297 | - for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) { |
|
298 | - /** |
|
299 | - * In some situations, the $id is not an INTEGER. SmartObjectTag is an example. |
|
300 | - * Is the fact that we removed the (int)() represents a security risk ? |
|
301 | - */ |
|
302 | - //$criteria->add(new \Criteria($this->keyName[$i], ($id[$i]), '=', $this->_itemname)); |
|
303 | - $criteria->add(new \Criteria($this->keyName[$i], $id[$i], '=', $this->_itemname)); |
|
304 | - } |
|
305 | - } else { |
|
306 | - //$criteria = new \Criteria($this->keyName, (int)($id), '=', $this->_itemname); |
|
307 | - /** |
|
308 | - * In some situations, the $id is not an INTEGER. SmartObjectTag is an example. |
|
309 | - * Is the fact that we removed the (int)() represents a security risk ? |
|
310 | - */ |
|
311 | - $criteria->add(new \Criteria($this->keyName, $id, '=', $this->_itemname)); |
|
312 | - } |
|
313 | - $criteria->setLimit(1); |
|
314 | - if ($debug) { |
|
315 | - $obj_array = $this->getObjectsD($criteria, false, $as_object); |
|
316 | - } else { |
|
317 | - $obj_array =& $this->getObjects($criteria, false, $as_object); |
|
318 | - //patch: weird bug of indexing by id even if id_as_key = false; |
|
319 | - if (!isset($obj_array[0]) && is_object($obj_array[$id])) { |
|
320 | - $obj_array[0] = $obj_array[$id]; |
|
321 | - unset($obj_array[$id]); |
|
322 | - $obj_array[0]->unsetNew(); |
|
323 | - } |
|
324 | - } |
|
325 | - |
|
326 | - if (1 != count($obj_array)) { |
|
327 | - $obj = $this->create(); |
|
328 | - |
|
329 | - return $obj; |
|
330 | - } |
|
331 | - |
|
332 | - return $obj_array[0]; |
|
333 | - } |
|
334 | - |
|
335 | - /** |
|
336 | - * retrieve a {@link SmartObject} |
|
337 | - * |
|
338 | - * @param mixed $id ID of the object - or array of ids for joint keys. Joint keys MUST be given in the same order as in the constructor |
|
339 | - * @param bool $as_object whether to return an object or an array |
|
340 | - * @return mixed reference to the {@link SmartObject}, FALSE if failed |
|
341 | - */ |
|
342 | - public function &getD($id, $as_object = true) |
|
343 | - { |
|
344 | - return $this->get($id, $as_object, true); |
|
345 | - } |
|
346 | - |
|
347 | - /** |
|
348 | - * retrieve objects from the database |
|
349 | - * |
|
350 | - * @param null|\CriteriaElement $criteria {@link CriteriaElement} conditions to be met |
|
351 | - * @param bool $id_as_key use the ID as key for the array? |
|
352 | - * @param bool $as_object return an array of objects? |
|
353 | - * |
|
354 | - * @param bool $sql |
|
355 | - * @param bool $debug |
|
356 | - * @return array |
|
357 | - */ |
|
358 | - public function getObjects( |
|
359 | - \CriteriaElement $criteria = null, |
|
360 | - $id_as_key = false, |
|
361 | - $as_object = true, |
|
362 | - $sql = false, |
|
363 | - $debug = false |
|
364 | - ) { |
|
365 | - $ret = []; |
|
366 | - $limit = $start = 0; |
|
367 | - |
|
368 | - if ($this->generalSQL) { |
|
369 | - $sql = $this->generalSQL; |
|
370 | - } elseif (!$sql) { |
|
371 | - $sql = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
372 | - } |
|
373 | - |
|
374 | - if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
|
375 | - $sql .= ' ' . $criteria->renderWhere(); |
|
376 | - if ('' !== $criteria->getSort()) { |
|
377 | - $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
378 | - } |
|
379 | - $limit = $criteria->getLimit(); |
|
380 | - $start = $criteria->getStart(); |
|
381 | - } |
|
382 | - if ($debug) { |
|
383 | - xoops_debug($sql); |
|
384 | - } |
|
385 | - |
|
386 | - $result = $this->db->query($sql, $limit, $start); |
|
387 | - if (!$result) { |
|
388 | - return $ret; |
|
389 | - } |
|
390 | - |
|
391 | - return $this->convertResultSet($result, $id_as_key, $as_object); |
|
392 | - } |
|
393 | - |
|
394 | - /** |
|
395 | - * @param $sql |
|
396 | - * @param $criteria |
|
397 | - * @param bool $force |
|
398 | - * @param bool $debug |
|
399 | - * @return array |
|
400 | - */ |
|
401 | - public function query($sql, $criteria, $force = false, $debug = false) |
|
402 | - { |
|
403 | - $ret = []; |
|
404 | - |
|
405 | - if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
|
406 | - $sql .= ' ' . $criteria->renderWhere(); |
|
407 | - if ($criteria->groupby) { |
|
408 | - $sql .= $criteria->getGroupby(); |
|
409 | - } |
|
410 | - if ('' !== $criteria->getSort()) { |
|
411 | - $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
412 | - } |
|
413 | - } |
|
414 | - if ($debug) { |
|
415 | - xoops_debug($sql); |
|
416 | - } |
|
417 | - |
|
418 | - if ($force) { |
|
419 | - $result = $this->db->queryF($sql); |
|
420 | - } else { |
|
421 | - $result = $this->db->query($sql); |
|
422 | - } |
|
423 | - |
|
424 | - if (!$result) { |
|
425 | - return $ret; |
|
426 | - } |
|
427 | - |
|
428 | - while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
429 | - $ret[] = $myrow; |
|
430 | - } |
|
431 | - |
|
432 | - return $ret; |
|
433 | - } |
|
434 | - |
|
435 | - /** |
|
436 | - * retrieve objects with debug mode - so will show the query |
|
437 | - * |
|
438 | - * @param CriteriaElement $criteria {@link CriteriaElement} conditions to be met |
|
439 | - * @param bool $id_as_key use the ID as key for the array? |
|
440 | - * @param bool $as_object return an array of objects? |
|
441 | - * |
|
442 | - * @param bool $sql |
|
443 | - * @return array |
|
444 | - */ |
|
445 | - public function getObjectsD(CriteriaElement $criteria = null, $id_as_key = false, $as_object = true, $sql = false) |
|
446 | - { |
|
447 | - return $this->getObjects($criteria, $id_as_key, $as_object, $sql, true); |
|
448 | - } |
|
449 | - |
|
450 | - /** |
|
451 | - * @param $arrayObjects |
|
452 | - * @return array|bool |
|
453 | - */ |
|
454 | - public function getObjectsAsArray($arrayObjects) |
|
455 | - { |
|
456 | - $ret = []; |
|
457 | - foreach ($arrayObjects as $key => $object) { |
|
458 | - $ret[$key] = $object->toArray(); |
|
459 | - } |
|
460 | - if (count($ret > 0)) { |
|
461 | - return $ret; |
|
462 | - } else { |
|
463 | - return false; |
|
464 | - } |
|
465 | - } |
|
466 | - |
|
467 | - /** |
|
468 | - * Convert a database resultset to a returnable array |
|
469 | - * |
|
470 | - * @param object $result database resultset |
|
471 | - * @param bool $id_as_key - should NOT be used with joint keys |
|
472 | - * @param bool $as_object |
|
473 | - * |
|
474 | - * @return array |
|
475 | - */ |
|
476 | - public function convertResultSet($result, $id_as_key = false, $as_object = true) |
|
477 | - { |
|
478 | - $ret = []; |
|
479 | - while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
480 | - $obj = $this->create(false); |
|
481 | - $obj->assignVars($myrow); |
|
482 | - if (!$id_as_key) { |
|
483 | - if ($as_object) { |
|
484 | - $ret[] =& $obj; |
|
485 | - } else { |
|
486 | - $ret[] = $obj->toArray(); |
|
487 | - } |
|
488 | - } else { |
|
489 | - if ($as_object) { |
|
490 | - $value =& $obj; |
|
491 | - } else { |
|
492 | - $value = $obj->toArray(); |
|
493 | - } |
|
494 | - if ('parentid' === $id_as_key) { |
|
495 | - $ret[$obj->getVar('parentid', 'e')][$obj->getVar($this->keyName)] =& $value; |
|
496 | - } else { |
|
497 | - $ret[$obj->getVar($this->keyName)] = $value; |
|
498 | - } |
|
499 | - } |
|
500 | - unset($obj); |
|
501 | - } |
|
502 | - |
|
503 | - return $ret; |
|
504 | - } |
|
505 | - |
|
506 | - /** |
|
507 | - * @param null $criteria |
|
508 | - * @param int $limit |
|
509 | - * @param int $start |
|
510 | - * @return array |
|
511 | - */ |
|
512 | - public function getListD($criteria = null, $limit = 0, $start = 0) |
|
513 | - { |
|
514 | - return $this->getList($criteria, $limit, $start, true); |
|
515 | - } |
|
516 | - |
|
517 | - /** |
|
518 | - * Retrieve a list of objects as arrays - DON'T USE WITH JOINT KEYS |
|
519 | - * |
|
520 | - * @param CriteriaElement $criteria {@link CriteriaElement} conditions to be met |
|
521 | - * @param int $limit Max number of objects to fetch |
|
522 | - * @param int $start Which record to start at |
|
523 | - * |
|
524 | - * @param bool $debug |
|
525 | - * @return array |
|
526 | - */ |
|
527 | - public function getList(CriteriaElement $criteria = null, $limit = 0, $start = 0, $debug = false) |
|
528 | - { |
|
529 | - $ret = []; |
|
530 | - if (null === $criteria) { |
|
531 | - $criteria = new \CriteriaCompo(); |
|
532 | - } |
|
533 | - |
|
534 | - if ('' === $criteria->getSort()) { |
|
535 | - $criteria->setSort($this->getIdentifierName()); |
|
536 | - } |
|
537 | - |
|
538 | - $sql = 'SELECT ' . (is_array($this->keyName) ? implode(', ', $this->keyName) : $this->keyName); |
|
539 | - if (!empty($this->identifierName)) { |
|
540 | - $sql .= ', ' . $this->getIdentifierName(); |
|
541 | - } |
|
542 | - $sql .= ' FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
543 | - if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
|
544 | - $sql .= ' ' . $criteria->renderWhere(); |
|
545 | - if ('' !== $criteria->getSort()) { |
|
546 | - $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
547 | - } |
|
548 | - $limit = $criteria->getLimit(); |
|
549 | - $start = $criteria->getStart(); |
|
550 | - } |
|
551 | - |
|
552 | - if ($debug) { |
|
553 | - xoops_debug($sql); |
|
554 | - } |
|
555 | - |
|
556 | - $result = $this->db->query($sql, $limit, $start); |
|
557 | - if (!$result) { |
|
558 | - return $ret; |
|
559 | - } |
|
560 | - |
|
561 | - $myts = \MyTextSanitizer::getInstance(); |
|
562 | - while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
563 | - //identifiers should be textboxes, so sanitize them like that |
|
564 | - $ret[$myrow[$this->keyName]] = empty($this->identifierName) ? 1 : $myts->displayTarea($myrow[$this->identifierName]); |
|
565 | - } |
|
566 | - |
|
567 | - return $ret; |
|
568 | - } |
|
569 | - |
|
570 | - /** |
|
571 | - * count objects matching a condition |
|
572 | - * |
|
573 | - * @param CriteriaElement $criteria {@link CriteriaElement} to match |
|
574 | - * @return int count of objects |
|
575 | - */ |
|
576 | - public function getCount(CriteriaElement $criteria = null) |
|
577 | - { |
|
578 | - $field = ''; |
|
579 | - $groupby = false; |
|
580 | - if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
|
581 | - if ('' !== $criteria->groupby) { |
|
582 | - $groupby = true; |
|
583 | - $field = $criteria->groupby . ', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used |
|
584 | - } |
|
585 | - } |
|
586 | - /** |
|
587 | - * if we have a generalSQL, lets used this one. |
|
588 | - * This needs to be improved... |
|
589 | - */ |
|
590 | - if ($this->generalSQL) { |
|
591 | - $sql = $this->generalSQL; |
|
592 | - $sql = str_replace('SELECT *', 'SELECT COUNT(*)', $sql); |
|
593 | - } else { |
|
594 | - $sql = 'SELECT ' . $field . 'COUNT(*) FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
595 | - } |
|
596 | - if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
|
597 | - $sql .= ' ' . $criteria->renderWhere(); |
|
598 | - if ('' !== $criteria->groupby) { |
|
599 | - $sql .= $criteria->getGroupby(); |
|
600 | - } |
|
601 | - } |
|
602 | - |
|
603 | - $result = $this->db->query($sql); |
|
604 | - if (!$result) { |
|
605 | - return 0; |
|
606 | - } |
|
607 | - if (false === $groupby) { |
|
608 | - list($count) = $this->db->fetchRow($result); |
|
609 | - |
|
610 | - return $count; |
|
611 | - } else { |
|
612 | - $ret = []; |
|
613 | - while (false !== (list($id, $count) = $this->db->fetchRow($result))) { |
|
614 | - $ret[$id] = $count; |
|
615 | - } |
|
616 | - |
|
617 | - return $ret; |
|
618 | - } |
|
619 | - } |
|
620 | - |
|
621 | - /** |
|
622 | - * delete an object from the database |
|
623 | - * |
|
624 | - * @param \XoopsObject $obj reference to the object to delete |
|
625 | - * @param bool $force |
|
626 | - * @return bool FALSE if failed. |
|
627 | - */ |
|
628 | - public function delete(\XoopsObject $obj, $force = false) |
|
629 | - { |
|
630 | - $eventResult = $this->executeEvent('beforeDelete', $obj); |
|
631 | - if (!$eventResult) { |
|
632 | - $obj->setErrors('An error occured during the BeforeDelete event'); |
|
633 | - |
|
634 | - return false; |
|
635 | - } |
|
636 | - |
|
637 | - if (is_array($this->keyName)) { |
|
638 | - $clause = []; |
|
639 | - for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) { |
|
640 | - $clause[] = $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]); |
|
641 | - } |
|
642 | - $whereclause = implode(' AND ', $clause); |
|
643 | - } else { |
|
644 | - $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName); |
|
645 | - } |
|
646 | - $sql = 'DELETE FROM ' . $this->table . ' WHERE ' . $whereclause; |
|
647 | - if (false !== $force) { |
|
648 | - $result = $this->db->queryF($sql); |
|
649 | - } else { |
|
650 | - $result = $this->db->query($sql); |
|
651 | - } |
|
652 | - if (!$result) { |
|
653 | - return false; |
|
654 | - } |
|
655 | - |
|
656 | - $eventResult = $this->executeEvent('afterDelete', $obj); |
|
657 | - if (!$eventResult) { |
|
658 | - $obj->setErrors('An error occured during the AfterDelete event'); |
|
659 | - |
|
660 | - return false; |
|
661 | - } |
|
662 | - |
|
663 | - return true; |
|
664 | - } |
|
665 | - |
|
666 | - /** |
|
667 | - * @param $event |
|
668 | - */ |
|
669 | - public function disableEvent($event) |
|
670 | - { |
|
671 | - if (is_array($event)) { |
|
672 | - foreach ($event as $v) { |
|
673 | - $this->_disabledEvents[] = $v; |
|
674 | - } |
|
675 | - } else { |
|
676 | - $this->_disabledEvents[] = $event; |
|
677 | - } |
|
678 | - } |
|
679 | - |
|
680 | - /** |
|
681 | - * @return array |
|
682 | - */ |
|
683 | - public function getPermissions() |
|
684 | - { |
|
685 | - return $this->permissionsArray; |
|
686 | - } |
|
687 | - |
|
688 | - /** |
|
689 | - * insert a new object in the database |
|
690 | - * |
|
691 | - * @param \XoopsObject $obj reference to the object |
|
692 | - * @param bool $force whether to force the query execution despite security settings |
|
693 | - * @param bool $checkObject check if the object is dirty and clean the attributes |
|
694 | - * @param bool $debug |
|
695 | - * @return bool FALSE if failed, TRUE if already present and unchanged or successful |
|
696 | - */ |
|
697 | - public function insert(\XoopsObject $obj, $force = false, $checkObject = true, $debug = false) |
|
698 | - { |
|
699 | - if (false !== $checkObject) { |
|
700 | - if (!is_object($obj)) { |
|
701 | - return false; |
|
702 | - } |
|
703 | - /** |
|
704 | - * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5 |
|
705 | - */ |
|
706 | - if (!is_a($obj, $this->className)) { |
|
707 | - $obj->setError(get_class($obj) . ' Differs from ' . $this->className); |
|
708 | - |
|
709 | - return false; |
|
710 | - } |
|
711 | - if (!$obj->isDirty()) { |
|
712 | - $obj->setErrors('Not dirty'); //will usually not be outputted as errors are not displayed when the method returns true, but it can be helpful when troubleshooting code - Mith |
|
713 | - |
|
714 | - return true; |
|
715 | - } |
|
716 | - } |
|
717 | - |
|
718 | - if ($obj->seoEnabled) { |
|
719 | - // Auto create meta tags if empty |
|
720 | - $smartobjectMetagen = new MetaGen($obj->title(), $obj->getVar('meta_keywords'), $obj->summary()); |
|
721 | - |
|
722 | - if (!$obj->getVar('meta_keywords') || !$obj->getVar('meta_description')) { |
|
723 | - if (!$obj->meta_keywords()) { |
|
724 | - $obj->setVar('meta_keywords', $smartobjectMetagen->_keywords); |
|
725 | - } |
|
726 | - |
|
727 | - if (!$obj->meta_description()) { |
|
728 | - $obj->setVar('meta_description', $smartobjectMetagen->_meta_description); |
|
729 | - } |
|
730 | - } |
|
731 | - |
|
732 | - // Auto create short_url if empty |
|
733 | - if (!$obj->short_url()) { |
|
734 | - $obj->setVar('short_url', $smartobjectMetagen->generateSeoTitle($obj->title('n'), false)); |
|
735 | - } |
|
736 | - } |
|
737 | - |
|
738 | - $eventResult = $this->executeEvent('beforeSave', $obj); |
|
739 | - if (!$eventResult) { |
|
740 | - $obj->setErrors('An error occured during the BeforeSave event'); |
|
741 | - |
|
742 | - return false; |
|
743 | - } |
|
744 | - |
|
745 | - if ($obj->isNew()) { |
|
746 | - $eventResult = $this->executeEvent('beforeInsert', $obj); |
|
747 | - if (!$eventResult) { |
|
748 | - $obj->setErrors('An error occured during the BeforeInsert event'); |
|
749 | - |
|
750 | - return false; |
|
751 | - } |
|
752 | - } else { |
|
753 | - $eventResult = $this->executeEvent('beforeUpdate', $obj); |
|
754 | - if (!$eventResult) { |
|
755 | - $obj->setErrors('An error occured during the BeforeUpdate event'); |
|
756 | - |
|
757 | - return false; |
|
758 | - } |
|
759 | - } |
|
760 | - if (!$obj->cleanVars()) { |
|
761 | - $obj->setErrors('Variables were not cleaned properly.'); |
|
762 | - |
|
763 | - return false; |
|
764 | - } |
|
765 | - $fieldsToStoreInDB = []; |
|
766 | - foreach ($obj->cleanVars as $k => $v) { |
|
767 | - if (XOBJ_DTYPE_INT == $obj->vars[$k]['data_type']) { |
|
768 | - $cleanvars[$k] = (int)$v; |
|
769 | - } elseif (is_array($v)) { |
|
770 | - $cleanvars[$k] = $this->db->quoteString(implode(',', $v)); |
|
771 | - } else { |
|
772 | - $cleanvars[$k] = $this->db->quoteString($v); |
|
773 | - } |
|
774 | - if ($obj->vars[$k]['persistent']) { |
|
775 | - $fieldsToStoreInDB[$k] = $cleanvars[$k]; |
|
776 | - } |
|
777 | - } |
|
778 | - if ($obj->isNew()) { |
|
779 | - if (!is_array($this->keyName)) { |
|
780 | - if ($cleanvars[$this->keyName] < 1) { |
|
781 | - $cleanvars[$this->keyName] = $this->db->genId($this->table . '_' . $this->keyName . '_seq'); |
|
782 | - } |
|
783 | - } |
|
784 | - |
|
785 | - $sql = 'INSERT INTO ' . $this->table . ' (' . implode(',', array_keys($fieldsToStoreInDB)) . ') VALUES (' . implode(',', array_values($fieldsToStoreInDB)) . ')'; |
|
786 | - } else { |
|
787 | - $sql = 'UPDATE ' . $this->table . ' SET'; |
|
788 | - foreach ($fieldsToStoreInDB as $key => $value) { |
|
789 | - if ((!is_array($this->keyName) && $key == $this->keyName) |
|
790 | - || (is_array($this->keyName) |
|
791 | - && in_array($key, $this->keyName))) { |
|
792 | - continue; |
|
793 | - } |
|
794 | - if (isset($notfirst)) { |
|
795 | - $sql .= ','; |
|
796 | - } |
|
797 | - $sql .= ' ' . $key . ' = ' . $value; |
|
798 | - $notfirst = true; |
|
799 | - } |
|
800 | - if (is_array($this->keyName)) { |
|
801 | - $whereclause = ''; |
|
802 | - for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) { |
|
803 | - if ($i > 0) { |
|
804 | - $whereclause .= ' AND '; |
|
805 | - } |
|
806 | - $whereclause .= $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]); |
|
807 | - } |
|
808 | - } else { |
|
809 | - $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName); |
|
810 | - } |
|
811 | - $sql .= ' WHERE ' . $whereclause; |
|
812 | - } |
|
813 | - |
|
814 | - if ($debug) { |
|
815 | - xoops_debug($sql); |
|
816 | - } |
|
817 | - |
|
818 | - if (false !== $force) { |
|
819 | - $result = $this->db->queryF($sql); |
|
820 | - } else { |
|
821 | - $result = $this->db->query($sql); |
|
822 | - } |
|
823 | - |
|
824 | - if (!$result) { |
|
825 | - $obj->setErrors($this->db->error()); |
|
826 | - |
|
827 | - return false; |
|
828 | - } |
|
829 | - |
|
830 | - if ($obj->isNew() && !is_array($this->keyName)) { |
|
831 | - $obj->assignVar($this->keyName, $this->db->getInsertId()); |
|
832 | - } |
|
833 | - $eventResult = $this->executeEvent('afterSave', $obj); |
|
834 | - if (!$eventResult) { |
|
835 | - $obj->setErrors('An error occured during the AfterSave event'); |
|
836 | - |
|
837 | - return false; |
|
838 | - } |
|
839 | - |
|
840 | - if ($obj->isNew()) { |
|
841 | - $obj->unsetNew(); |
|
842 | - $eventResult = $this->executeEvent('afterInsert', $obj); |
|
843 | - if (!$eventResult) { |
|
844 | - $obj->setErrors('An error occured during the AfterInsert event'); |
|
845 | - |
|
846 | - return false; |
|
847 | - } |
|
848 | - } else { |
|
849 | - $eventResult = $this->executeEvent('afterUpdate', $obj); |
|
850 | - if (!$eventResult) { |
|
851 | - $obj->setErrors('An error occured during the AfterUpdate event'); |
|
852 | - |
|
853 | - return false; |
|
854 | - } |
|
855 | - } |
|
856 | - |
|
857 | - return true; |
|
858 | - } |
|
859 | - |
|
860 | - /** |
|
861 | - * @param $obj |
|
862 | - * @param bool $force |
|
863 | - * @param bool $checkObject |
|
864 | - * @param bool $debug |
|
865 | - * @return bool |
|
866 | - */ |
|
867 | - public function insertD($obj, $force = false, $checkObject = true, $debug = false) |
|
868 | - { |
|
869 | - return $this->insert($obj, $force, $checkObject, true); |
|
870 | - } |
|
871 | - |
|
872 | - /** |
|
873 | - * Change a value for objects with a certain criteria |
|
874 | - * |
|
875 | - * @param string $fieldname Name of the field |
|
876 | - * @param string $fieldvalue Value to write |
|
877 | - * @param CriteriaElement $criteria {@link CriteriaElement} |
|
878 | - * |
|
879 | - * @param bool $force |
|
880 | - * @return bool |
|
881 | - */ |
|
882 | - public function updateAll($fieldname, $fieldvalue, CriteriaElement $criteria = null, $force = false) |
|
883 | - { |
|
884 | - $set_clause = $fieldname . ' = '; |
|
885 | - if (is_numeric($fieldvalue)) { |
|
886 | - $set_clause .= $fieldvalue; |
|
887 | - } elseif (is_array($fieldvalue)) { |
|
888 | - $set_clause .= $this->db->quoteString(implode(',', $fieldvalue)); |
|
889 | - } else { |
|
890 | - $set_clause .= $this->db->quoteString($fieldvalue); |
|
891 | - } |
|
892 | - $sql = 'UPDATE ' . $this->table . ' SET ' . $set_clause; |
|
893 | - if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
|
894 | - $sql .= ' ' . $criteria->renderWhere(); |
|
895 | - } |
|
896 | - if (false !== $force) { |
|
897 | - $result = $this->db->queryF($sql); |
|
898 | - } else { |
|
899 | - $result = $this->db->query($sql); |
|
900 | - } |
|
901 | - if (!$result) { |
|
902 | - return false; |
|
903 | - } |
|
904 | - |
|
905 | - return true; |
|
906 | - } |
|
907 | - |
|
908 | - /** |
|
909 | - * delete all objects meeting the conditions |
|
910 | - * |
|
911 | - * @param CriteriaElement $criteria {@link CriteriaElement} with conditions to meet |
|
912 | - * @return bool |
|
913 | - */ |
|
914 | - |
|
915 | - public function deleteAll(CriteriaElement $criteria = null) |
|
916 | - { |
|
917 | - if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
|
918 | - $sql = 'DELETE FROM ' . $this->table; |
|
919 | - $sql .= ' ' . $criteria->renderWhere(); |
|
920 | - if (!$this->db->query($sql)) { |
|
921 | - return false; |
|
922 | - } |
|
923 | - $rows = $this->db->getAffectedRows(); |
|
924 | - |
|
925 | - return $rows > 0 ? $rows : true; |
|
926 | - } |
|
927 | - |
|
928 | - return false; |
|
929 | - } |
|
930 | - |
|
931 | - /** |
|
932 | - * @return mixed |
|
933 | - */ |
|
934 | - public function getModuleInfo() |
|
935 | - { |
|
936 | - return Smartobject\Utility::getModuleInfo($this->_moduleName); |
|
937 | - } |
|
938 | - |
|
939 | - /** |
|
940 | - * @return bool |
|
941 | - */ |
|
942 | - public function getModuleConfig() |
|
943 | - { |
|
944 | - return Smartobject\Utility::getModuleConfig($this->_moduleName); |
|
945 | - } |
|
946 | - |
|
947 | - /** |
|
948 | - * @return string |
|
949 | - */ |
|
950 | - public function getModuleItemString() |
|
951 | - { |
|
952 | - $ret = $this->_moduleName . '_' . $this->_itemname; |
|
953 | - |
|
954 | - return $ret; |
|
955 | - } |
|
956 | - |
|
957 | - /** |
|
958 | - * @param $object |
|
959 | - */ |
|
960 | - public function updateCounter($object) |
|
961 | - { |
|
962 | - if (isset($object->vars['counter'])) { |
|
963 | - $new_counter = $object->getVar('counter') + 1; |
|
964 | - $sql = 'UPDATE ' . $this->table . ' SET counter=' . $new_counter . ' WHERE ' . $this->keyName . '=' . $object->id(); |
|
965 | - $this->query($sql, null, true); |
|
966 | - } |
|
967 | - } |
|
968 | - |
|
969 | - /** |
|
970 | - * Execute the function associated with an event |
|
971 | - * This method will check if the function is available |
|
972 | - * |
|
973 | - * @param string $event name of the event |
|
974 | - * @param $executeEventObj |
|
975 | - * @return mixed result of the execution of the function or FALSE if the function was not executed |
|
976 | - * @internal param object $obj $object on which is performed the event |
|
977 | - */ |
|
978 | - public function executeEvent($event, &$executeEventObj) |
|
979 | - { |
|
980 | - if (!in_array($event, $this->_disabledEvents)) { |
|
981 | - if (method_exists($this, $event)) { |
|
982 | - $ret = $this->$event($executeEventObj); |
|
983 | - } else { |
|
984 | - // check to see if there is a hook for this event |
|
985 | - if (isset($this->_eventHooks[$event])) { |
|
986 | - $method = $this->_eventHooks[$event]; |
|
987 | - // check to see if the method specified by this hook exists |
|
988 | - if (method_exists($this, $method)) { |
|
989 | - $ret = $this->$method($executeEventObj); |
|
990 | - } |
|
991 | - } |
|
992 | - $ret = true; |
|
993 | - } |
|
994 | - |
|
995 | - return $ret; |
|
996 | - } |
|
997 | - |
|
998 | - return true; |
|
999 | - } |
|
1000 | - |
|
1001 | - /** |
|
1002 | - * @param bool $withprefix |
|
1003 | - * @return string |
|
1004 | - */ |
|
1005 | - public function getIdentifierName($withprefix = true) |
|
1006 | - { |
|
1007 | - if ($withprefix) { |
|
1008 | - return $this->_itemname . '.' . $this->identifierName; |
|
1009 | - } else { |
|
1010 | - return $this->identifierName; |
|
1011 | - } |
|
1012 | - } |
|
246 | + $obj = new $this->className; |
|
247 | + |
|
248 | + $obj->setImageDir($this->getImageUrl(), $this->getImagePath()); |
|
249 | + if (!$obj->handler) { |
|
250 | + $obj->Handler = $this; |
|
251 | + } |
|
252 | + |
|
253 | + if (true === $isNew) { |
|
254 | + $obj->setNew(); |
|
255 | + } |
|
256 | + |
|
257 | + return $obj; |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * @return string |
|
262 | + */ |
|
263 | + public function getImageUrl() |
|
264 | + { |
|
265 | + return $this->_uploadUrl . $this->_itemname . '/'; |
|
266 | + } |
|
267 | + |
|
268 | + /** |
|
269 | + * @return string |
|
270 | + */ |
|
271 | + public function getImagePath() |
|
272 | + { |
|
273 | + $dir = $this->_uploadPath . $this->_itemname; |
|
274 | + if (!file_exists($dir)) { |
|
275 | + Smartobject\Utility::mkdirAsAdmin($dir); |
|
276 | + } |
|
277 | + |
|
278 | + return $dir . '/'; |
|
279 | + } |
|
280 | + |
|
281 | + /** |
|
282 | + * retrieve a {@link SmartObject} |
|
283 | + * |
|
284 | + * @param mixed $id ID of the object - or array of ids for joint keys. Joint keys MUST be given in the same order as in the constructor |
|
285 | + * @param bool $as_object whether to return an object or an array |
|
286 | + * @param bool $debug |
|
287 | + * @param bool $criteria |
|
288 | + * @return mixed reference to the <a href='psi_element://SmartObject'>SmartObject</a>, FALSE if failed |
|
289 | + * FALSE if failed |
|
290 | + */ |
|
291 | + public function get($id, $as_object = true, $debug = false, $criteria = false) |
|
292 | + { |
|
293 | + if (!$criteria) { |
|
294 | + $criteria = new \CriteriaCompo(); |
|
295 | + } |
|
296 | + if (is_array($this->keyName)) { |
|
297 | + for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) { |
|
298 | + /** |
|
299 | + * In some situations, the $id is not an INTEGER. SmartObjectTag is an example. |
|
300 | + * Is the fact that we removed the (int)() represents a security risk ? |
|
301 | + */ |
|
302 | + //$criteria->add(new \Criteria($this->keyName[$i], ($id[$i]), '=', $this->_itemname)); |
|
303 | + $criteria->add(new \Criteria($this->keyName[$i], $id[$i], '=', $this->_itemname)); |
|
304 | + } |
|
305 | + } else { |
|
306 | + //$criteria = new \Criteria($this->keyName, (int)($id), '=', $this->_itemname); |
|
307 | + /** |
|
308 | + * In some situations, the $id is not an INTEGER. SmartObjectTag is an example. |
|
309 | + * Is the fact that we removed the (int)() represents a security risk ? |
|
310 | + */ |
|
311 | + $criteria->add(new \Criteria($this->keyName, $id, '=', $this->_itemname)); |
|
312 | + } |
|
313 | + $criteria->setLimit(1); |
|
314 | + if ($debug) { |
|
315 | + $obj_array = $this->getObjectsD($criteria, false, $as_object); |
|
316 | + } else { |
|
317 | + $obj_array =& $this->getObjects($criteria, false, $as_object); |
|
318 | + //patch: weird bug of indexing by id even if id_as_key = false; |
|
319 | + if (!isset($obj_array[0]) && is_object($obj_array[$id])) { |
|
320 | + $obj_array[0] = $obj_array[$id]; |
|
321 | + unset($obj_array[$id]); |
|
322 | + $obj_array[0]->unsetNew(); |
|
323 | + } |
|
324 | + } |
|
325 | + |
|
326 | + if (1 != count($obj_array)) { |
|
327 | + $obj = $this->create(); |
|
328 | + |
|
329 | + return $obj; |
|
330 | + } |
|
331 | + |
|
332 | + return $obj_array[0]; |
|
333 | + } |
|
334 | + |
|
335 | + /** |
|
336 | + * retrieve a {@link SmartObject} |
|
337 | + * |
|
338 | + * @param mixed $id ID of the object - or array of ids for joint keys. Joint keys MUST be given in the same order as in the constructor |
|
339 | + * @param bool $as_object whether to return an object or an array |
|
340 | + * @return mixed reference to the {@link SmartObject}, FALSE if failed |
|
341 | + */ |
|
342 | + public function &getD($id, $as_object = true) |
|
343 | + { |
|
344 | + return $this->get($id, $as_object, true); |
|
345 | + } |
|
346 | + |
|
347 | + /** |
|
348 | + * retrieve objects from the database |
|
349 | + * |
|
350 | + * @param null|\CriteriaElement $criteria {@link CriteriaElement} conditions to be met |
|
351 | + * @param bool $id_as_key use the ID as key for the array? |
|
352 | + * @param bool $as_object return an array of objects? |
|
353 | + * |
|
354 | + * @param bool $sql |
|
355 | + * @param bool $debug |
|
356 | + * @return array |
|
357 | + */ |
|
358 | + public function getObjects( |
|
359 | + \CriteriaElement $criteria = null, |
|
360 | + $id_as_key = false, |
|
361 | + $as_object = true, |
|
362 | + $sql = false, |
|
363 | + $debug = false |
|
364 | + ) { |
|
365 | + $ret = []; |
|
366 | + $limit = $start = 0; |
|
367 | + |
|
368 | + if ($this->generalSQL) { |
|
369 | + $sql = $this->generalSQL; |
|
370 | + } elseif (!$sql) { |
|
371 | + $sql = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
372 | + } |
|
373 | + |
|
374 | + if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
|
375 | + $sql .= ' ' . $criteria->renderWhere(); |
|
376 | + if ('' !== $criteria->getSort()) { |
|
377 | + $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
378 | + } |
|
379 | + $limit = $criteria->getLimit(); |
|
380 | + $start = $criteria->getStart(); |
|
381 | + } |
|
382 | + if ($debug) { |
|
383 | + xoops_debug($sql); |
|
384 | + } |
|
385 | + |
|
386 | + $result = $this->db->query($sql, $limit, $start); |
|
387 | + if (!$result) { |
|
388 | + return $ret; |
|
389 | + } |
|
390 | + |
|
391 | + return $this->convertResultSet($result, $id_as_key, $as_object); |
|
392 | + } |
|
393 | + |
|
394 | + /** |
|
395 | + * @param $sql |
|
396 | + * @param $criteria |
|
397 | + * @param bool $force |
|
398 | + * @param bool $debug |
|
399 | + * @return array |
|
400 | + */ |
|
401 | + public function query($sql, $criteria, $force = false, $debug = false) |
|
402 | + { |
|
403 | + $ret = []; |
|
404 | + |
|
405 | + if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
|
406 | + $sql .= ' ' . $criteria->renderWhere(); |
|
407 | + if ($criteria->groupby) { |
|
408 | + $sql .= $criteria->getGroupby(); |
|
409 | + } |
|
410 | + if ('' !== $criteria->getSort()) { |
|
411 | + $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
412 | + } |
|
413 | + } |
|
414 | + if ($debug) { |
|
415 | + xoops_debug($sql); |
|
416 | + } |
|
417 | + |
|
418 | + if ($force) { |
|
419 | + $result = $this->db->queryF($sql); |
|
420 | + } else { |
|
421 | + $result = $this->db->query($sql); |
|
422 | + } |
|
423 | + |
|
424 | + if (!$result) { |
|
425 | + return $ret; |
|
426 | + } |
|
427 | + |
|
428 | + while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
429 | + $ret[] = $myrow; |
|
430 | + } |
|
431 | + |
|
432 | + return $ret; |
|
433 | + } |
|
434 | + |
|
435 | + /** |
|
436 | + * retrieve objects with debug mode - so will show the query |
|
437 | + * |
|
438 | + * @param CriteriaElement $criteria {@link CriteriaElement} conditions to be met |
|
439 | + * @param bool $id_as_key use the ID as key for the array? |
|
440 | + * @param bool $as_object return an array of objects? |
|
441 | + * |
|
442 | + * @param bool $sql |
|
443 | + * @return array |
|
444 | + */ |
|
445 | + public function getObjectsD(CriteriaElement $criteria = null, $id_as_key = false, $as_object = true, $sql = false) |
|
446 | + { |
|
447 | + return $this->getObjects($criteria, $id_as_key, $as_object, $sql, true); |
|
448 | + } |
|
449 | + |
|
450 | + /** |
|
451 | + * @param $arrayObjects |
|
452 | + * @return array|bool |
|
453 | + */ |
|
454 | + public function getObjectsAsArray($arrayObjects) |
|
455 | + { |
|
456 | + $ret = []; |
|
457 | + foreach ($arrayObjects as $key => $object) { |
|
458 | + $ret[$key] = $object->toArray(); |
|
459 | + } |
|
460 | + if (count($ret > 0)) { |
|
461 | + return $ret; |
|
462 | + } else { |
|
463 | + return false; |
|
464 | + } |
|
465 | + } |
|
466 | + |
|
467 | + /** |
|
468 | + * Convert a database resultset to a returnable array |
|
469 | + * |
|
470 | + * @param object $result database resultset |
|
471 | + * @param bool $id_as_key - should NOT be used with joint keys |
|
472 | + * @param bool $as_object |
|
473 | + * |
|
474 | + * @return array |
|
475 | + */ |
|
476 | + public function convertResultSet($result, $id_as_key = false, $as_object = true) |
|
477 | + { |
|
478 | + $ret = []; |
|
479 | + while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
480 | + $obj = $this->create(false); |
|
481 | + $obj->assignVars($myrow); |
|
482 | + if (!$id_as_key) { |
|
483 | + if ($as_object) { |
|
484 | + $ret[] =& $obj; |
|
485 | + } else { |
|
486 | + $ret[] = $obj->toArray(); |
|
487 | + } |
|
488 | + } else { |
|
489 | + if ($as_object) { |
|
490 | + $value =& $obj; |
|
491 | + } else { |
|
492 | + $value = $obj->toArray(); |
|
493 | + } |
|
494 | + if ('parentid' === $id_as_key) { |
|
495 | + $ret[$obj->getVar('parentid', 'e')][$obj->getVar($this->keyName)] =& $value; |
|
496 | + } else { |
|
497 | + $ret[$obj->getVar($this->keyName)] = $value; |
|
498 | + } |
|
499 | + } |
|
500 | + unset($obj); |
|
501 | + } |
|
502 | + |
|
503 | + return $ret; |
|
504 | + } |
|
505 | + |
|
506 | + /** |
|
507 | + * @param null $criteria |
|
508 | + * @param int $limit |
|
509 | + * @param int $start |
|
510 | + * @return array |
|
511 | + */ |
|
512 | + public function getListD($criteria = null, $limit = 0, $start = 0) |
|
513 | + { |
|
514 | + return $this->getList($criteria, $limit, $start, true); |
|
515 | + } |
|
516 | + |
|
517 | + /** |
|
518 | + * Retrieve a list of objects as arrays - DON'T USE WITH JOINT KEYS |
|
519 | + * |
|
520 | + * @param CriteriaElement $criteria {@link CriteriaElement} conditions to be met |
|
521 | + * @param int $limit Max number of objects to fetch |
|
522 | + * @param int $start Which record to start at |
|
523 | + * |
|
524 | + * @param bool $debug |
|
525 | + * @return array |
|
526 | + */ |
|
527 | + public function getList(CriteriaElement $criteria = null, $limit = 0, $start = 0, $debug = false) |
|
528 | + { |
|
529 | + $ret = []; |
|
530 | + if (null === $criteria) { |
|
531 | + $criteria = new \CriteriaCompo(); |
|
532 | + } |
|
533 | + |
|
534 | + if ('' === $criteria->getSort()) { |
|
535 | + $criteria->setSort($this->getIdentifierName()); |
|
536 | + } |
|
537 | + |
|
538 | + $sql = 'SELECT ' . (is_array($this->keyName) ? implode(', ', $this->keyName) : $this->keyName); |
|
539 | + if (!empty($this->identifierName)) { |
|
540 | + $sql .= ', ' . $this->getIdentifierName(); |
|
541 | + } |
|
542 | + $sql .= ' FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
543 | + if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
|
544 | + $sql .= ' ' . $criteria->renderWhere(); |
|
545 | + if ('' !== $criteria->getSort()) { |
|
546 | + $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
547 | + } |
|
548 | + $limit = $criteria->getLimit(); |
|
549 | + $start = $criteria->getStart(); |
|
550 | + } |
|
551 | + |
|
552 | + if ($debug) { |
|
553 | + xoops_debug($sql); |
|
554 | + } |
|
555 | + |
|
556 | + $result = $this->db->query($sql, $limit, $start); |
|
557 | + if (!$result) { |
|
558 | + return $ret; |
|
559 | + } |
|
560 | + |
|
561 | + $myts = \MyTextSanitizer::getInstance(); |
|
562 | + while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
563 | + //identifiers should be textboxes, so sanitize them like that |
|
564 | + $ret[$myrow[$this->keyName]] = empty($this->identifierName) ? 1 : $myts->displayTarea($myrow[$this->identifierName]); |
|
565 | + } |
|
566 | + |
|
567 | + return $ret; |
|
568 | + } |
|
569 | + |
|
570 | + /** |
|
571 | + * count objects matching a condition |
|
572 | + * |
|
573 | + * @param CriteriaElement $criteria {@link CriteriaElement} to match |
|
574 | + * @return int count of objects |
|
575 | + */ |
|
576 | + public function getCount(CriteriaElement $criteria = null) |
|
577 | + { |
|
578 | + $field = ''; |
|
579 | + $groupby = false; |
|
580 | + if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
|
581 | + if ('' !== $criteria->groupby) { |
|
582 | + $groupby = true; |
|
583 | + $field = $criteria->groupby . ', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used |
|
584 | + } |
|
585 | + } |
|
586 | + /** |
|
587 | + * if we have a generalSQL, lets used this one. |
|
588 | + * This needs to be improved... |
|
589 | + */ |
|
590 | + if ($this->generalSQL) { |
|
591 | + $sql = $this->generalSQL; |
|
592 | + $sql = str_replace('SELECT *', 'SELECT COUNT(*)', $sql); |
|
593 | + } else { |
|
594 | + $sql = 'SELECT ' . $field . 'COUNT(*) FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
595 | + } |
|
596 | + if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
|
597 | + $sql .= ' ' . $criteria->renderWhere(); |
|
598 | + if ('' !== $criteria->groupby) { |
|
599 | + $sql .= $criteria->getGroupby(); |
|
600 | + } |
|
601 | + } |
|
602 | + |
|
603 | + $result = $this->db->query($sql); |
|
604 | + if (!$result) { |
|
605 | + return 0; |
|
606 | + } |
|
607 | + if (false === $groupby) { |
|
608 | + list($count) = $this->db->fetchRow($result); |
|
609 | + |
|
610 | + return $count; |
|
611 | + } else { |
|
612 | + $ret = []; |
|
613 | + while (false !== (list($id, $count) = $this->db->fetchRow($result))) { |
|
614 | + $ret[$id] = $count; |
|
615 | + } |
|
616 | + |
|
617 | + return $ret; |
|
618 | + } |
|
619 | + } |
|
620 | + |
|
621 | + /** |
|
622 | + * delete an object from the database |
|
623 | + * |
|
624 | + * @param \XoopsObject $obj reference to the object to delete |
|
625 | + * @param bool $force |
|
626 | + * @return bool FALSE if failed. |
|
627 | + */ |
|
628 | + public function delete(\XoopsObject $obj, $force = false) |
|
629 | + { |
|
630 | + $eventResult = $this->executeEvent('beforeDelete', $obj); |
|
631 | + if (!$eventResult) { |
|
632 | + $obj->setErrors('An error occured during the BeforeDelete event'); |
|
633 | + |
|
634 | + return false; |
|
635 | + } |
|
636 | + |
|
637 | + if (is_array($this->keyName)) { |
|
638 | + $clause = []; |
|
639 | + for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) { |
|
640 | + $clause[] = $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]); |
|
641 | + } |
|
642 | + $whereclause = implode(' AND ', $clause); |
|
643 | + } else { |
|
644 | + $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName); |
|
645 | + } |
|
646 | + $sql = 'DELETE FROM ' . $this->table . ' WHERE ' . $whereclause; |
|
647 | + if (false !== $force) { |
|
648 | + $result = $this->db->queryF($sql); |
|
649 | + } else { |
|
650 | + $result = $this->db->query($sql); |
|
651 | + } |
|
652 | + if (!$result) { |
|
653 | + return false; |
|
654 | + } |
|
655 | + |
|
656 | + $eventResult = $this->executeEvent('afterDelete', $obj); |
|
657 | + if (!$eventResult) { |
|
658 | + $obj->setErrors('An error occured during the AfterDelete event'); |
|
659 | + |
|
660 | + return false; |
|
661 | + } |
|
662 | + |
|
663 | + return true; |
|
664 | + } |
|
665 | + |
|
666 | + /** |
|
667 | + * @param $event |
|
668 | + */ |
|
669 | + public function disableEvent($event) |
|
670 | + { |
|
671 | + if (is_array($event)) { |
|
672 | + foreach ($event as $v) { |
|
673 | + $this->_disabledEvents[] = $v; |
|
674 | + } |
|
675 | + } else { |
|
676 | + $this->_disabledEvents[] = $event; |
|
677 | + } |
|
678 | + } |
|
679 | + |
|
680 | + /** |
|
681 | + * @return array |
|
682 | + */ |
|
683 | + public function getPermissions() |
|
684 | + { |
|
685 | + return $this->permissionsArray; |
|
686 | + } |
|
687 | + |
|
688 | + /** |
|
689 | + * insert a new object in the database |
|
690 | + * |
|
691 | + * @param \XoopsObject $obj reference to the object |
|
692 | + * @param bool $force whether to force the query execution despite security settings |
|
693 | + * @param bool $checkObject check if the object is dirty and clean the attributes |
|
694 | + * @param bool $debug |
|
695 | + * @return bool FALSE if failed, TRUE if already present and unchanged or successful |
|
696 | + */ |
|
697 | + public function insert(\XoopsObject $obj, $force = false, $checkObject = true, $debug = false) |
|
698 | + { |
|
699 | + if (false !== $checkObject) { |
|
700 | + if (!is_object($obj)) { |
|
701 | + return false; |
|
702 | + } |
|
703 | + /** |
|
704 | + * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5 |
|
705 | + */ |
|
706 | + if (!is_a($obj, $this->className)) { |
|
707 | + $obj->setError(get_class($obj) . ' Differs from ' . $this->className); |
|
708 | + |
|
709 | + return false; |
|
710 | + } |
|
711 | + if (!$obj->isDirty()) { |
|
712 | + $obj->setErrors('Not dirty'); //will usually not be outputted as errors are not displayed when the method returns true, but it can be helpful when troubleshooting code - Mith |
|
713 | + |
|
714 | + return true; |
|
715 | + } |
|
716 | + } |
|
717 | + |
|
718 | + if ($obj->seoEnabled) { |
|
719 | + // Auto create meta tags if empty |
|
720 | + $smartobjectMetagen = new MetaGen($obj->title(), $obj->getVar('meta_keywords'), $obj->summary()); |
|
721 | + |
|
722 | + if (!$obj->getVar('meta_keywords') || !$obj->getVar('meta_description')) { |
|
723 | + if (!$obj->meta_keywords()) { |
|
724 | + $obj->setVar('meta_keywords', $smartobjectMetagen->_keywords); |
|
725 | + } |
|
726 | + |
|
727 | + if (!$obj->meta_description()) { |
|
728 | + $obj->setVar('meta_description', $smartobjectMetagen->_meta_description); |
|
729 | + } |
|
730 | + } |
|
731 | + |
|
732 | + // Auto create short_url if empty |
|
733 | + if (!$obj->short_url()) { |
|
734 | + $obj->setVar('short_url', $smartobjectMetagen->generateSeoTitle($obj->title('n'), false)); |
|
735 | + } |
|
736 | + } |
|
737 | + |
|
738 | + $eventResult = $this->executeEvent('beforeSave', $obj); |
|
739 | + if (!$eventResult) { |
|
740 | + $obj->setErrors('An error occured during the BeforeSave event'); |
|
741 | + |
|
742 | + return false; |
|
743 | + } |
|
744 | + |
|
745 | + if ($obj->isNew()) { |
|
746 | + $eventResult = $this->executeEvent('beforeInsert', $obj); |
|
747 | + if (!$eventResult) { |
|
748 | + $obj->setErrors('An error occured during the BeforeInsert event'); |
|
749 | + |
|
750 | + return false; |
|
751 | + } |
|
752 | + } else { |
|
753 | + $eventResult = $this->executeEvent('beforeUpdate', $obj); |
|
754 | + if (!$eventResult) { |
|
755 | + $obj->setErrors('An error occured during the BeforeUpdate event'); |
|
756 | + |
|
757 | + return false; |
|
758 | + } |
|
759 | + } |
|
760 | + if (!$obj->cleanVars()) { |
|
761 | + $obj->setErrors('Variables were not cleaned properly.'); |
|
762 | + |
|
763 | + return false; |
|
764 | + } |
|
765 | + $fieldsToStoreInDB = []; |
|
766 | + foreach ($obj->cleanVars as $k => $v) { |
|
767 | + if (XOBJ_DTYPE_INT == $obj->vars[$k]['data_type']) { |
|
768 | + $cleanvars[$k] = (int)$v; |
|
769 | + } elseif (is_array($v)) { |
|
770 | + $cleanvars[$k] = $this->db->quoteString(implode(',', $v)); |
|
771 | + } else { |
|
772 | + $cleanvars[$k] = $this->db->quoteString($v); |
|
773 | + } |
|
774 | + if ($obj->vars[$k]['persistent']) { |
|
775 | + $fieldsToStoreInDB[$k] = $cleanvars[$k]; |
|
776 | + } |
|
777 | + } |
|
778 | + if ($obj->isNew()) { |
|
779 | + if (!is_array($this->keyName)) { |
|
780 | + if ($cleanvars[$this->keyName] < 1) { |
|
781 | + $cleanvars[$this->keyName] = $this->db->genId($this->table . '_' . $this->keyName . '_seq'); |
|
782 | + } |
|
783 | + } |
|
784 | + |
|
785 | + $sql = 'INSERT INTO ' . $this->table . ' (' . implode(',', array_keys($fieldsToStoreInDB)) . ') VALUES (' . implode(',', array_values($fieldsToStoreInDB)) . ')'; |
|
786 | + } else { |
|
787 | + $sql = 'UPDATE ' . $this->table . ' SET'; |
|
788 | + foreach ($fieldsToStoreInDB as $key => $value) { |
|
789 | + if ((!is_array($this->keyName) && $key == $this->keyName) |
|
790 | + || (is_array($this->keyName) |
|
791 | + && in_array($key, $this->keyName))) { |
|
792 | + continue; |
|
793 | + } |
|
794 | + if (isset($notfirst)) { |
|
795 | + $sql .= ','; |
|
796 | + } |
|
797 | + $sql .= ' ' . $key . ' = ' . $value; |
|
798 | + $notfirst = true; |
|
799 | + } |
|
800 | + if (is_array($this->keyName)) { |
|
801 | + $whereclause = ''; |
|
802 | + for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) { |
|
803 | + if ($i > 0) { |
|
804 | + $whereclause .= ' AND '; |
|
805 | + } |
|
806 | + $whereclause .= $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]); |
|
807 | + } |
|
808 | + } else { |
|
809 | + $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName); |
|
810 | + } |
|
811 | + $sql .= ' WHERE ' . $whereclause; |
|
812 | + } |
|
813 | + |
|
814 | + if ($debug) { |
|
815 | + xoops_debug($sql); |
|
816 | + } |
|
817 | + |
|
818 | + if (false !== $force) { |
|
819 | + $result = $this->db->queryF($sql); |
|
820 | + } else { |
|
821 | + $result = $this->db->query($sql); |
|
822 | + } |
|
823 | + |
|
824 | + if (!$result) { |
|
825 | + $obj->setErrors($this->db->error()); |
|
826 | + |
|
827 | + return false; |
|
828 | + } |
|
829 | + |
|
830 | + if ($obj->isNew() && !is_array($this->keyName)) { |
|
831 | + $obj->assignVar($this->keyName, $this->db->getInsertId()); |
|
832 | + } |
|
833 | + $eventResult = $this->executeEvent('afterSave', $obj); |
|
834 | + if (!$eventResult) { |
|
835 | + $obj->setErrors('An error occured during the AfterSave event'); |
|
836 | + |
|
837 | + return false; |
|
838 | + } |
|
839 | + |
|
840 | + if ($obj->isNew()) { |
|
841 | + $obj->unsetNew(); |
|
842 | + $eventResult = $this->executeEvent('afterInsert', $obj); |
|
843 | + if (!$eventResult) { |
|
844 | + $obj->setErrors('An error occured during the AfterInsert event'); |
|
845 | + |
|
846 | + return false; |
|
847 | + } |
|
848 | + } else { |
|
849 | + $eventResult = $this->executeEvent('afterUpdate', $obj); |
|
850 | + if (!$eventResult) { |
|
851 | + $obj->setErrors('An error occured during the AfterUpdate event'); |
|
852 | + |
|
853 | + return false; |
|
854 | + } |
|
855 | + } |
|
856 | + |
|
857 | + return true; |
|
858 | + } |
|
859 | + |
|
860 | + /** |
|
861 | + * @param $obj |
|
862 | + * @param bool $force |
|
863 | + * @param bool $checkObject |
|
864 | + * @param bool $debug |
|
865 | + * @return bool |
|
866 | + */ |
|
867 | + public function insertD($obj, $force = false, $checkObject = true, $debug = false) |
|
868 | + { |
|
869 | + return $this->insert($obj, $force, $checkObject, true); |
|
870 | + } |
|
871 | + |
|
872 | + /** |
|
873 | + * Change a value for objects with a certain criteria |
|
874 | + * |
|
875 | + * @param string $fieldname Name of the field |
|
876 | + * @param string $fieldvalue Value to write |
|
877 | + * @param CriteriaElement $criteria {@link CriteriaElement} |
|
878 | + * |
|
879 | + * @param bool $force |
|
880 | + * @return bool |
|
881 | + */ |
|
882 | + public function updateAll($fieldname, $fieldvalue, CriteriaElement $criteria = null, $force = false) |
|
883 | + { |
|
884 | + $set_clause = $fieldname . ' = '; |
|
885 | + if (is_numeric($fieldvalue)) { |
|
886 | + $set_clause .= $fieldvalue; |
|
887 | + } elseif (is_array($fieldvalue)) { |
|
888 | + $set_clause .= $this->db->quoteString(implode(',', $fieldvalue)); |
|
889 | + } else { |
|
890 | + $set_clause .= $this->db->quoteString($fieldvalue); |
|
891 | + } |
|
892 | + $sql = 'UPDATE ' . $this->table . ' SET ' . $set_clause; |
|
893 | + if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
|
894 | + $sql .= ' ' . $criteria->renderWhere(); |
|
895 | + } |
|
896 | + if (false !== $force) { |
|
897 | + $result = $this->db->queryF($sql); |
|
898 | + } else { |
|
899 | + $result = $this->db->query($sql); |
|
900 | + } |
|
901 | + if (!$result) { |
|
902 | + return false; |
|
903 | + } |
|
904 | + |
|
905 | + return true; |
|
906 | + } |
|
907 | + |
|
908 | + /** |
|
909 | + * delete all objects meeting the conditions |
|
910 | + * |
|
911 | + * @param CriteriaElement $criteria {@link CriteriaElement} with conditions to meet |
|
912 | + * @return bool |
|
913 | + */ |
|
914 | + |
|
915 | + public function deleteAll(CriteriaElement $criteria = null) |
|
916 | + { |
|
917 | + if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
|
918 | + $sql = 'DELETE FROM ' . $this->table; |
|
919 | + $sql .= ' ' . $criteria->renderWhere(); |
|
920 | + if (!$this->db->query($sql)) { |
|
921 | + return false; |
|
922 | + } |
|
923 | + $rows = $this->db->getAffectedRows(); |
|
924 | + |
|
925 | + return $rows > 0 ? $rows : true; |
|
926 | + } |
|
927 | + |
|
928 | + return false; |
|
929 | + } |
|
930 | + |
|
931 | + /** |
|
932 | + * @return mixed |
|
933 | + */ |
|
934 | + public function getModuleInfo() |
|
935 | + { |
|
936 | + return Smartobject\Utility::getModuleInfo($this->_moduleName); |
|
937 | + } |
|
938 | + |
|
939 | + /** |
|
940 | + * @return bool |
|
941 | + */ |
|
942 | + public function getModuleConfig() |
|
943 | + { |
|
944 | + return Smartobject\Utility::getModuleConfig($this->_moduleName); |
|
945 | + } |
|
946 | + |
|
947 | + /** |
|
948 | + * @return string |
|
949 | + */ |
|
950 | + public function getModuleItemString() |
|
951 | + { |
|
952 | + $ret = $this->_moduleName . '_' . $this->_itemname; |
|
953 | + |
|
954 | + return $ret; |
|
955 | + } |
|
956 | + |
|
957 | + /** |
|
958 | + * @param $object |
|
959 | + */ |
|
960 | + public function updateCounter($object) |
|
961 | + { |
|
962 | + if (isset($object->vars['counter'])) { |
|
963 | + $new_counter = $object->getVar('counter') + 1; |
|
964 | + $sql = 'UPDATE ' . $this->table . ' SET counter=' . $new_counter . ' WHERE ' . $this->keyName . '=' . $object->id(); |
|
965 | + $this->query($sql, null, true); |
|
966 | + } |
|
967 | + } |
|
968 | + |
|
969 | + /** |
|
970 | + * Execute the function associated with an event |
|
971 | + * This method will check if the function is available |
|
972 | + * |
|
973 | + * @param string $event name of the event |
|
974 | + * @param $executeEventObj |
|
975 | + * @return mixed result of the execution of the function or FALSE if the function was not executed |
|
976 | + * @internal param object $obj $object on which is performed the event |
|
977 | + */ |
|
978 | + public function executeEvent($event, &$executeEventObj) |
|
979 | + { |
|
980 | + if (!in_array($event, $this->_disabledEvents)) { |
|
981 | + if (method_exists($this, $event)) { |
|
982 | + $ret = $this->$event($executeEventObj); |
|
983 | + } else { |
|
984 | + // check to see if there is a hook for this event |
|
985 | + if (isset($this->_eventHooks[$event])) { |
|
986 | + $method = $this->_eventHooks[$event]; |
|
987 | + // check to see if the method specified by this hook exists |
|
988 | + if (method_exists($this, $method)) { |
|
989 | + $ret = $this->$method($executeEventObj); |
|
990 | + } |
|
991 | + } |
|
992 | + $ret = true; |
|
993 | + } |
|
994 | + |
|
995 | + return $ret; |
|
996 | + } |
|
997 | + |
|
998 | + return true; |
|
999 | + } |
|
1000 | + |
|
1001 | + /** |
|
1002 | + * @param bool $withprefix |
|
1003 | + * @return string |
|
1004 | + */ |
|
1005 | + public function getIdentifierName($withprefix = true) |
|
1006 | + { |
|
1007 | + if ($withprefix) { |
|
1008 | + return $this->_itemname . '.' . $this->identifierName; |
|
1009 | + } else { |
|
1010 | + return $this->identifierName; |
|
1011 | + } |
|
1012 | + } |
|
1013 | 1013 | } |
@@ -150,18 +150,18 @@ discard block |
||
150 | 150 | |
151 | 151 | $this->_itemname = $itemname; |
152 | 152 | $this->_moduleName = $modulename; |
153 | - $this->table = $db->prefix($modulename . '_' . $itemname); |
|
153 | + $this->table = $db->prefix($modulename.'_'.$itemname); |
|
154 | 154 | $this->keyName = $keyname; |
155 | 155 | // $this->className = ucfirst($modulename) . ucfirst($itemname); |
156 | 156 | $this->className = $itemname; |
157 | 157 | |
158 | 158 | $this->identifierName = $idenfierName; |
159 | 159 | $this->summaryName = $summaryName; |
160 | - $this->_page = $itemname . '.php'; |
|
161 | - $this->_modulePath = XOOPS_ROOT_PATH . '/modules/' . $this->_moduleName . '/'; |
|
162 | - $this->_moduleUrl = XOOPS_URL . '/modules/' . $this->_moduleName . '/'; |
|
163 | - $this->_uploadPath = XOOPS_UPLOAD_PATH . '/' . $this->_moduleName . '/'; |
|
164 | - $this->_uploadUrl = XOOPS_UPLOAD_URL . '/' . $this->_moduleName . '/'; |
|
160 | + $this->_page = $itemname.'.php'; |
|
161 | + $this->_modulePath = XOOPS_ROOT_PATH.'/modules/'.$this->_moduleName.'/'; |
|
162 | + $this->_moduleUrl = XOOPS_URL.'/modules/'.$this->_moduleName.'/'; |
|
163 | + $this->_uploadPath = XOOPS_UPLOAD_PATH.'/'.$this->_moduleName.'/'; |
|
164 | + $this->_uploadUrl = XOOPS_UPLOAD_URL.'/'.$this->_moduleName.'/'; |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | /** |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | $smartPermissionsHandler = new PermissionHandler($this); |
204 | 204 | $grantedItems = $smartPermissionsHandler->getGrantedItems($perm_name); |
205 | 205 | if (count($grantedItems) > 0) { |
206 | - $criteria->add(new \Criteria($this->keyName, '(' . implode(', ', $grantedItems) . ')', 'IN')); |
|
206 | + $criteria->add(new \Criteria($this->keyName, '('.implode(', ', $grantedItems).')', 'IN')); |
|
207 | 207 | |
208 | 208 | return true; |
209 | 209 | } else { |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | { |
244 | 244 | // $obj0 = new $this->className($this); |
245 | 245 | |
246 | - $obj = new $this->className; |
|
246 | + $obj = new $this->className; |
|
247 | 247 | |
248 | 248 | $obj->setImageDir($this->getImageUrl(), $this->getImagePath()); |
249 | 249 | if (!$obj->handler) { |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | */ |
263 | 263 | public function getImageUrl() |
264 | 264 | { |
265 | - return $this->_uploadUrl . $this->_itemname . '/'; |
|
265 | + return $this->_uploadUrl.$this->_itemname.'/'; |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | /** |
@@ -270,12 +270,12 @@ discard block |
||
270 | 270 | */ |
271 | 271 | public function getImagePath() |
272 | 272 | { |
273 | - $dir = $this->_uploadPath . $this->_itemname; |
|
273 | + $dir = $this->_uploadPath.$this->_itemname; |
|
274 | 274 | if (!file_exists($dir)) { |
275 | 275 | Smartobject\Utility::mkdirAsAdmin($dir); |
276 | 276 | } |
277 | 277 | |
278 | - return $dir . '/'; |
|
278 | + return $dir.'/'; |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | /** |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | if ($debug) { |
315 | 315 | $obj_array = $this->getObjectsD($criteria, false, $as_object); |
316 | 316 | } else { |
317 | - $obj_array =& $this->getObjects($criteria, false, $as_object); |
|
317 | + $obj_array = & $this->getObjects($criteria, false, $as_object); |
|
318 | 318 | //patch: weird bug of indexing by id even if id_as_key = false; |
319 | 319 | if (!isset($obj_array[0]) && is_object($obj_array[$id])) { |
320 | 320 | $obj_array[0] = $obj_array[$id]; |
@@ -368,13 +368,13 @@ discard block |
||
368 | 368 | if ($this->generalSQL) { |
369 | 369 | $sql = $this->generalSQL; |
370 | 370 | } elseif (!$sql) { |
371 | - $sql = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
371 | + $sql = 'SELECT * FROM '.$this->table.' AS '.$this->_itemname; |
|
372 | 372 | } |
373 | 373 | |
374 | 374 | if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
375 | - $sql .= ' ' . $criteria->renderWhere(); |
|
375 | + $sql .= ' '.$criteria->renderWhere(); |
|
376 | 376 | if ('' !== $criteria->getSort()) { |
377 | - $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
377 | + $sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder(); |
|
378 | 378 | } |
379 | 379 | $limit = $criteria->getLimit(); |
380 | 380 | $start = $criteria->getStart(); |
@@ -403,12 +403,12 @@ discard block |
||
403 | 403 | $ret = []; |
404 | 404 | |
405 | 405 | if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
406 | - $sql .= ' ' . $criteria->renderWhere(); |
|
406 | + $sql .= ' '.$criteria->renderWhere(); |
|
407 | 407 | if ($criteria->groupby) { |
408 | 408 | $sql .= $criteria->getGroupby(); |
409 | 409 | } |
410 | 410 | if ('' !== $criteria->getSort()) { |
411 | - $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
411 | + $sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder(); |
|
412 | 412 | } |
413 | 413 | } |
414 | 414 | if ($debug) { |
@@ -481,18 +481,18 @@ discard block |
||
481 | 481 | $obj->assignVars($myrow); |
482 | 482 | if (!$id_as_key) { |
483 | 483 | if ($as_object) { |
484 | - $ret[] =& $obj; |
|
484 | + $ret[] = & $obj; |
|
485 | 485 | } else { |
486 | 486 | $ret[] = $obj->toArray(); |
487 | 487 | } |
488 | 488 | } else { |
489 | 489 | if ($as_object) { |
490 | - $value =& $obj; |
|
490 | + $value = & $obj; |
|
491 | 491 | } else { |
492 | 492 | $value = $obj->toArray(); |
493 | 493 | } |
494 | 494 | if ('parentid' === $id_as_key) { |
495 | - $ret[$obj->getVar('parentid', 'e')][$obj->getVar($this->keyName)] =& $value; |
|
495 | + $ret[$obj->getVar('parentid', 'e')][$obj->getVar($this->keyName)] = & $value; |
|
496 | 496 | } else { |
497 | 497 | $ret[$obj->getVar($this->keyName)] = $value; |
498 | 498 | } |
@@ -535,15 +535,15 @@ discard block |
||
535 | 535 | $criteria->setSort($this->getIdentifierName()); |
536 | 536 | } |
537 | 537 | |
538 | - $sql = 'SELECT ' . (is_array($this->keyName) ? implode(', ', $this->keyName) : $this->keyName); |
|
538 | + $sql = 'SELECT '.(is_array($this->keyName) ? implode(', ', $this->keyName) : $this->keyName); |
|
539 | 539 | if (!empty($this->identifierName)) { |
540 | - $sql .= ', ' . $this->getIdentifierName(); |
|
540 | + $sql .= ', '.$this->getIdentifierName(); |
|
541 | 541 | } |
542 | - $sql .= ' FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
542 | + $sql .= ' FROM '.$this->table.' AS '.$this->_itemname; |
|
543 | 543 | if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
544 | - $sql .= ' ' . $criteria->renderWhere(); |
|
544 | + $sql .= ' '.$criteria->renderWhere(); |
|
545 | 545 | if ('' !== $criteria->getSort()) { |
546 | - $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
546 | + $sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder(); |
|
547 | 547 | } |
548 | 548 | $limit = $criteria->getLimit(); |
549 | 549 | $start = $criteria->getStart(); |
@@ -580,7 +580,7 @@ discard block |
||
580 | 580 | if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
581 | 581 | if ('' !== $criteria->groupby) { |
582 | 582 | $groupby = true; |
583 | - $field = $criteria->groupby . ', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used |
|
583 | + $field = $criteria->groupby.', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used |
|
584 | 584 | } |
585 | 585 | } |
586 | 586 | /** |
@@ -591,10 +591,10 @@ discard block |
||
591 | 591 | $sql = $this->generalSQL; |
592 | 592 | $sql = str_replace('SELECT *', 'SELECT COUNT(*)', $sql); |
593 | 593 | } else { |
594 | - $sql = 'SELECT ' . $field . 'COUNT(*) FROM ' . $this->table . ' AS ' . $this->_itemname; |
|
594 | + $sql = 'SELECT '.$field.'COUNT(*) FROM '.$this->table.' AS '.$this->_itemname; |
|
595 | 595 | } |
596 | 596 | if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
597 | - $sql .= ' ' . $criteria->renderWhere(); |
|
597 | + $sql .= ' '.$criteria->renderWhere(); |
|
598 | 598 | if ('' !== $criteria->groupby) { |
599 | 599 | $sql .= $criteria->getGroupby(); |
600 | 600 | } |
@@ -637,13 +637,13 @@ discard block |
||
637 | 637 | if (is_array($this->keyName)) { |
638 | 638 | $clause = []; |
639 | 639 | for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) { |
640 | - $clause[] = $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]); |
|
640 | + $clause[] = $this->keyName[$i].' = '.$obj->getVar($this->keyName[$i]); |
|
641 | 641 | } |
642 | 642 | $whereclause = implode(' AND ', $clause); |
643 | 643 | } else { |
644 | - $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName); |
|
644 | + $whereclause = $this->keyName.' = '.$obj->getVar($this->keyName); |
|
645 | 645 | } |
646 | - $sql = 'DELETE FROM ' . $this->table . ' WHERE ' . $whereclause; |
|
646 | + $sql = 'DELETE FROM '.$this->table.' WHERE '.$whereclause; |
|
647 | 647 | if (false !== $force) { |
648 | 648 | $result = $this->db->queryF($sql); |
649 | 649 | } else { |
@@ -704,7 +704,7 @@ discard block |
||
704 | 704 | * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5 |
705 | 705 | */ |
706 | 706 | if (!is_a($obj, $this->className)) { |
707 | - $obj->setError(get_class($obj) . ' Differs from ' . $this->className); |
|
707 | + $obj->setError(get_class($obj).' Differs from '.$this->className); |
|
708 | 708 | |
709 | 709 | return false; |
710 | 710 | } |
@@ -765,7 +765,7 @@ discard block |
||
765 | 765 | $fieldsToStoreInDB = []; |
766 | 766 | foreach ($obj->cleanVars as $k => $v) { |
767 | 767 | if (XOBJ_DTYPE_INT == $obj->vars[$k]['data_type']) { |
768 | - $cleanvars[$k] = (int)$v; |
|
768 | + $cleanvars[$k] = (int) $v; |
|
769 | 769 | } elseif (is_array($v)) { |
770 | 770 | $cleanvars[$k] = $this->db->quoteString(implode(',', $v)); |
771 | 771 | } else { |
@@ -778,13 +778,13 @@ discard block |
||
778 | 778 | if ($obj->isNew()) { |
779 | 779 | if (!is_array($this->keyName)) { |
780 | 780 | if ($cleanvars[$this->keyName] < 1) { |
781 | - $cleanvars[$this->keyName] = $this->db->genId($this->table . '_' . $this->keyName . '_seq'); |
|
781 | + $cleanvars[$this->keyName] = $this->db->genId($this->table.'_'.$this->keyName.'_seq'); |
|
782 | 782 | } |
783 | 783 | } |
784 | 784 | |
785 | - $sql = 'INSERT INTO ' . $this->table . ' (' . implode(',', array_keys($fieldsToStoreInDB)) . ') VALUES (' . implode(',', array_values($fieldsToStoreInDB)) . ')'; |
|
785 | + $sql = 'INSERT INTO '.$this->table.' ('.implode(',', array_keys($fieldsToStoreInDB)).') VALUES ('.implode(',', array_values($fieldsToStoreInDB)).')'; |
|
786 | 786 | } else { |
787 | - $sql = 'UPDATE ' . $this->table . ' SET'; |
|
787 | + $sql = 'UPDATE '.$this->table.' SET'; |
|
788 | 788 | foreach ($fieldsToStoreInDB as $key => $value) { |
789 | 789 | if ((!is_array($this->keyName) && $key == $this->keyName) |
790 | 790 | || (is_array($this->keyName) |
@@ -794,7 +794,7 @@ discard block |
||
794 | 794 | if (isset($notfirst)) { |
795 | 795 | $sql .= ','; |
796 | 796 | } |
797 | - $sql .= ' ' . $key . ' = ' . $value; |
|
797 | + $sql .= ' '.$key.' = '.$value; |
|
798 | 798 | $notfirst = true; |
799 | 799 | } |
800 | 800 | if (is_array($this->keyName)) { |
@@ -803,12 +803,12 @@ discard block |
||
803 | 803 | if ($i > 0) { |
804 | 804 | $whereclause .= ' AND '; |
805 | 805 | } |
806 | - $whereclause .= $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]); |
|
806 | + $whereclause .= $this->keyName[$i].' = '.$obj->getVar($this->keyName[$i]); |
|
807 | 807 | } |
808 | 808 | } else { |
809 | - $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName); |
|
809 | + $whereclause = $this->keyName.' = '.$obj->getVar($this->keyName); |
|
810 | 810 | } |
811 | - $sql .= ' WHERE ' . $whereclause; |
|
811 | + $sql .= ' WHERE '.$whereclause; |
|
812 | 812 | } |
813 | 813 | |
814 | 814 | if ($debug) { |
@@ -881,7 +881,7 @@ discard block |
||
881 | 881 | */ |
882 | 882 | public function updateAll($fieldname, $fieldvalue, CriteriaElement $criteria = null, $force = false) |
883 | 883 | { |
884 | - $set_clause = $fieldname . ' = '; |
|
884 | + $set_clause = $fieldname.' = '; |
|
885 | 885 | if (is_numeric($fieldvalue)) { |
886 | 886 | $set_clause .= $fieldvalue; |
887 | 887 | } elseif (is_array($fieldvalue)) { |
@@ -889,9 +889,9 @@ discard block |
||
889 | 889 | } else { |
890 | 890 | $set_clause .= $this->db->quoteString($fieldvalue); |
891 | 891 | } |
892 | - $sql = 'UPDATE ' . $this->table . ' SET ' . $set_clause; |
|
892 | + $sql = 'UPDATE '.$this->table.' SET '.$set_clause; |
|
893 | 893 | if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
894 | - $sql .= ' ' . $criteria->renderWhere(); |
|
894 | + $sql .= ' '.$criteria->renderWhere(); |
|
895 | 895 | } |
896 | 896 | if (false !== $force) { |
897 | 897 | $result = $this->db->queryF($sql); |
@@ -915,8 +915,8 @@ discard block |
||
915 | 915 | public function deleteAll(CriteriaElement $criteria = null) |
916 | 916 | { |
917 | 917 | if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
918 | - $sql = 'DELETE FROM ' . $this->table; |
|
919 | - $sql .= ' ' . $criteria->renderWhere(); |
|
918 | + $sql = 'DELETE FROM '.$this->table; |
|
919 | + $sql .= ' '.$criteria->renderWhere(); |
|
920 | 920 | if (!$this->db->query($sql)) { |
921 | 921 | return false; |
922 | 922 | } |
@@ -949,7 +949,7 @@ discard block |
||
949 | 949 | */ |
950 | 950 | public function getModuleItemString() |
951 | 951 | { |
952 | - $ret = $this->_moduleName . '_' . $this->_itemname; |
|
952 | + $ret = $this->_moduleName.'_'.$this->_itemname; |
|
953 | 953 | |
954 | 954 | return $ret; |
955 | 955 | } |
@@ -961,7 +961,7 @@ discard block |
||
961 | 961 | { |
962 | 962 | if (isset($object->vars['counter'])) { |
963 | 963 | $new_counter = $object->getVar('counter') + 1; |
964 | - $sql = 'UPDATE ' . $this->table . ' SET counter=' . $new_counter . ' WHERE ' . $this->keyName . '=' . $object->id(); |
|
964 | + $sql = 'UPDATE '.$this->table.' SET counter='.$new_counter.' WHERE '.$this->keyName.'='.$object->id(); |
|
965 | 965 | $this->query($sql, null, true); |
966 | 966 | } |
967 | 967 | } |
@@ -1005,7 +1005,7 @@ discard block |
||
1005 | 1005 | public function getIdentifierName($withprefix = true) |
1006 | 1006 | { |
1007 | 1007 | if ($withprefix) { |
1008 | - return $this->_itemname . '.' . $this->identifierName; |
|
1008 | + return $this->_itemname.'.'.$this->identifierName; |
|
1009 | 1009 | } else { |
1010 | 1010 | return $this->identifierName; |
1011 | 1011 | } |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | |
33 | 33 | /** |
34 | 34 | * Constructor |
35 | - * @param $object |
|
35 | + * @param BaseSmartObject $object |
|
36 | 36 | * @param bool $userSide |
37 | 37 | * @param array $actions |
38 | 38 | * @param bool $headerAsRow |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
49 | - * @param $rowObj |
|
49 | + * @param ObjectRow $rowObj |
|
50 | 50 | */ |
51 | 51 | public function addRow($rowObj) |
52 | 52 | { |
@@ -23,94 +23,94 @@ |
||
23 | 23 | */ |
24 | 24 | class SingleView |
25 | 25 | { |
26 | - public $_object; |
|
27 | - public $_userSide; |
|
28 | - public $_tpl; |
|
29 | - public $_rows; |
|
30 | - public $_actions; |
|
31 | - public $_headerAsRow = true; |
|
26 | + public $_object; |
|
27 | + public $_userSide; |
|
28 | + public $_tpl; |
|
29 | + public $_rows; |
|
30 | + public $_actions; |
|
31 | + public $_headerAsRow = true; |
|
32 | 32 | |
33 | - /** |
|
34 | - * Constructor |
|
35 | - * @param $object |
|
36 | - * @param bool $userSide |
|
37 | - * @param array $actions |
|
38 | - * @param bool $headerAsRow |
|
39 | - */ |
|
40 | - public function __construct($object, $userSide = false, $actions = [], $headerAsRow = true) |
|
41 | - { |
|
42 | - $this->_object = $object; |
|
43 | - $this->_userSide = $userSide; |
|
44 | - $this->_actions = $actions; |
|
45 | - $this->_headerAsRow = $headerAsRow; |
|
46 | - } |
|
33 | + /** |
|
34 | + * Constructor |
|
35 | + * @param $object |
|
36 | + * @param bool $userSide |
|
37 | + * @param array $actions |
|
38 | + * @param bool $headerAsRow |
|
39 | + */ |
|
40 | + public function __construct($object, $userSide = false, $actions = [], $headerAsRow = true) |
|
41 | + { |
|
42 | + $this->_object = $object; |
|
43 | + $this->_userSide = $userSide; |
|
44 | + $this->_actions = $actions; |
|
45 | + $this->_headerAsRow = $headerAsRow; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * @param $rowObj |
|
50 | - */ |
|
51 | - public function addRow($rowObj) |
|
52 | - { |
|
53 | - $this->_rows[] = $rowObj; |
|
54 | - } |
|
48 | + /** |
|
49 | + * @param $rowObj |
|
50 | + */ |
|
51 | + public function addRow($rowObj) |
|
52 | + { |
|
53 | + $this->_rows[] = $rowObj; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * @param bool $fetchOnly |
|
58 | - * @param bool $debug |
|
59 | - * @return mixed|string|void |
|
60 | - */ |
|
61 | - public function render($fetchOnly = false, $debug = false) |
|
62 | - { |
|
63 | - require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
56 | + /** |
|
57 | + * @param bool $fetchOnly |
|
58 | + * @param bool $debug |
|
59 | + * @return mixed|string|void |
|
60 | + */ |
|
61 | + public function render($fetchOnly = false, $debug = false) |
|
62 | + { |
|
63 | + require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
64 | 64 | |
65 | - $this->_tpl = new \XoopsTpl(); |
|
66 | - $vars = $this->_object->vars; |
|
67 | - $smartobjectObjectArray = []; |
|
65 | + $this->_tpl = new \XoopsTpl(); |
|
66 | + $vars = $this->_object->vars; |
|
67 | + $smartobjectObjectArray = []; |
|
68 | 68 | |
69 | - foreach ($this->_rows as $row) { |
|
70 | - $key = $row->getKeyName(); |
|
71 | - if ($row->_customMethodForValue && method_exists($this->_object, $row->_customMethodForValue)) { |
|
72 | - $method = $row->_customMethodForValue; |
|
73 | - $value = $this->_object->$method(); |
|
74 | - } else { |
|
75 | - $value = $this->_object->getVar($row->getKeyName()); |
|
76 | - } |
|
77 | - if ($row->isHeader()) { |
|
78 | - $this->_tpl->assign('smartobject_single_view_header_caption', $this->_object->vars[$key]['form_caption']); |
|
79 | - $this->_tpl->assign('smartobject_single_view_header_value', $value); |
|
80 | - } else { |
|
81 | - $smartobjectObjectArray[$key]['value'] = $value; |
|
82 | - $smartobjectObjectArray[$key]['header'] = $row->isHeader(); |
|
83 | - $smartobjectObjectArray[$key]['caption'] = $this->_object->vars[$key]['form_caption']; |
|
84 | - } |
|
85 | - } |
|
86 | - $action_row = ''; |
|
87 | - if (in_array('edit', $this->_actions)) { |
|
88 | - $action_row .= $this->_object->getEditItemLink(false, true, true); |
|
89 | - } |
|
90 | - if (in_array('delete', $this->_actions)) { |
|
91 | - $action_row .= $this->_object->getDeleteItemLink(false, true, true); |
|
92 | - } |
|
93 | - if ($action_row) { |
|
94 | - $smartobjectObjectArray['zaction']['value'] = $action_row; |
|
95 | - $smartobjectObjectArray['zaction']['caption'] = _CO_SOBJECT_ACTIONS; |
|
96 | - } |
|
69 | + foreach ($this->_rows as $row) { |
|
70 | + $key = $row->getKeyName(); |
|
71 | + if ($row->_customMethodForValue && method_exists($this->_object, $row->_customMethodForValue)) { |
|
72 | + $method = $row->_customMethodForValue; |
|
73 | + $value = $this->_object->$method(); |
|
74 | + } else { |
|
75 | + $value = $this->_object->getVar($row->getKeyName()); |
|
76 | + } |
|
77 | + if ($row->isHeader()) { |
|
78 | + $this->_tpl->assign('smartobject_single_view_header_caption', $this->_object->vars[$key]['form_caption']); |
|
79 | + $this->_tpl->assign('smartobject_single_view_header_value', $value); |
|
80 | + } else { |
|
81 | + $smartobjectObjectArray[$key]['value'] = $value; |
|
82 | + $smartobjectObjectArray[$key]['header'] = $row->isHeader(); |
|
83 | + $smartobjectObjectArray[$key]['caption'] = $this->_object->vars[$key]['form_caption']; |
|
84 | + } |
|
85 | + } |
|
86 | + $action_row = ''; |
|
87 | + if (in_array('edit', $this->_actions)) { |
|
88 | + $action_row .= $this->_object->getEditItemLink(false, true, true); |
|
89 | + } |
|
90 | + if (in_array('delete', $this->_actions)) { |
|
91 | + $action_row .= $this->_object->getDeleteItemLink(false, true, true); |
|
92 | + } |
|
93 | + if ($action_row) { |
|
94 | + $smartobjectObjectArray['zaction']['value'] = $action_row; |
|
95 | + $smartobjectObjectArray['zaction']['caption'] = _CO_SOBJECT_ACTIONS; |
|
96 | + } |
|
97 | 97 | |
98 | - $this->_tpl->assign('smartobject_header_as_row', $this->_headerAsRow); |
|
99 | - $this->_tpl->assign('smartobject_object_array', $smartobjectObjectArray); |
|
98 | + $this->_tpl->assign('smartobject_header_as_row', $this->_headerAsRow); |
|
99 | + $this->_tpl->assign('smartobject_object_array', $smartobjectObjectArray); |
|
100 | 100 | |
101 | - if ($fetchOnly) { |
|
102 | - return $this->_tpl->fetch('db:smartobject_singleview_display.tpl'); |
|
103 | - } else { |
|
104 | - $this->_tpl->display('db:smartobject_singleview_display.tpl'); |
|
105 | - } |
|
106 | - } |
|
101 | + if ($fetchOnly) { |
|
102 | + return $this->_tpl->fetch('db:smartobject_singleview_display.tpl'); |
|
103 | + } else { |
|
104 | + $this->_tpl->display('db:smartobject_singleview_display.tpl'); |
|
105 | + } |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * @param bool $debug |
|
110 | - * @return mixed|string|void |
|
111 | - */ |
|
112 | - public function fetch($debug = false) |
|
113 | - { |
|
114 | - return $this->render(true, $debug); |
|
115 | - } |
|
108 | + /** |
|
109 | + * @param bool $debug |
|
110 | + * @return mixed|string|void |
|
111 | + */ |
|
112 | + public function fetch($debug = false) |
|
113 | + { |
|
114 | + return $this->render(true, $debug); |
|
115 | + } |
|
116 | 116 | } |
@@ -60,7 +60,7 @@ |
||
60 | 60 | */ |
61 | 61 | public function render($fetchOnly = false, $debug = false) |
62 | 62 | { |
63 | - require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
63 | + require_once XOOPS_ROOT_PATH.'/class/template.php'; |
|
64 | 64 | |
65 | 65 | $this->_tpl = new \XoopsTpl(); |
66 | 66 | $vars = $this->_object->vars; |