@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | |
32 | 32 | /** |
33 | 33 | * SmartObjectColumn constructor. |
34 | - * @param $keyname |
|
34 | + * @param string $keyname |
|
35 | 35 | * @param string $align |
36 | 36 | * @param bool $width |
37 | 37 | * @param bool $customMethodForValue |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
186 | - * @param $columnObj |
|
186 | + * @param SmartObjectColumn $columnObj |
|
187 | 187 | */ |
188 | 188 | public function addColumn($columnObj) |
189 | 189 | { |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | |
193 | 193 | /** |
194 | 194 | * @param $name |
195 | - * @param $location |
|
195 | + * @param string $location |
|
196 | 196 | * @param $value |
197 | 197 | */ |
198 | 198 | public function addIntroButton($name, $location, $value) |
@@ -21,77 +21,77 @@ discard block |
||
21 | 21 | */ |
22 | 22 | class SmartObjectColumn |
23 | 23 | { |
24 | - public $_keyname; |
|
25 | - public $_align; |
|
26 | - public $_width; |
|
27 | - public $_customMethodForValue; |
|
28 | - public $_extraParams; |
|
29 | - public $_sortable; |
|
30 | - public $_customCaption; |
|
31 | - |
|
32 | - /** |
|
33 | - * SmartObjectColumn constructor. |
|
34 | - * @param $keyname |
|
35 | - * @param string $align |
|
36 | - * @param bool $width |
|
37 | - * @param bool $customMethodForValue |
|
38 | - * @param bool $param |
|
39 | - * @param bool $customCaption |
|
40 | - * @param bool $sortable |
|
41 | - */ |
|
42 | - public function __construct($keyname, $align = 'left', $width = false, $customMethodForValue = false, $param = false, $customCaption = false, $sortable = true) |
|
43 | - { |
|
44 | - $this->_keyname = $keyname; |
|
45 | - $this->_align = $align; |
|
46 | - $this->_width = $width; |
|
47 | - $this->_customMethodForValue = $customMethodForValue; |
|
48 | - $this->_sortable = $sortable; |
|
49 | - $this->_param = $param; |
|
50 | - $this->_customCaption = $customCaption; |
|
51 | - } |
|
52 | - |
|
53 | - public function getKeyName() |
|
54 | - { |
|
55 | - return $this->_keyname; |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * @return string |
|
60 | - */ |
|
61 | - public function getAlign() |
|
62 | - { |
|
63 | - return $this->_align; |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * @return bool |
|
68 | - */ |
|
69 | - public function isSortable() |
|
70 | - { |
|
71 | - return $this->_sortable; |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * @return bool|string |
|
76 | - */ |
|
77 | - public function getWidth() |
|
78 | - { |
|
79 | - if ($this->_width) { |
|
80 | - $ret = $this->_width; |
|
81 | - } else { |
|
82 | - $ret = ''; |
|
83 | - } |
|
84 | - |
|
85 | - return $ret; |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * @return bool |
|
90 | - */ |
|
91 | - public function getCustomCaption() |
|
92 | - { |
|
93 | - return $this->_customCaption; |
|
94 | - } |
|
24 | + public $_keyname; |
|
25 | + public $_align; |
|
26 | + public $_width; |
|
27 | + public $_customMethodForValue; |
|
28 | + public $_extraParams; |
|
29 | + public $_sortable; |
|
30 | + public $_customCaption; |
|
31 | + |
|
32 | + /** |
|
33 | + * SmartObjectColumn constructor. |
|
34 | + * @param $keyname |
|
35 | + * @param string $align |
|
36 | + * @param bool $width |
|
37 | + * @param bool $customMethodForValue |
|
38 | + * @param bool $param |
|
39 | + * @param bool $customCaption |
|
40 | + * @param bool $sortable |
|
41 | + */ |
|
42 | + public function __construct($keyname, $align = 'left', $width = false, $customMethodForValue = false, $param = false, $customCaption = false, $sortable = true) |
|
43 | + { |
|
44 | + $this->_keyname = $keyname; |
|
45 | + $this->_align = $align; |
|
46 | + $this->_width = $width; |
|
47 | + $this->_customMethodForValue = $customMethodForValue; |
|
48 | + $this->_sortable = $sortable; |
|
49 | + $this->_param = $param; |
|
50 | + $this->_customCaption = $customCaption; |
|
51 | + } |
|
52 | + |
|
53 | + public function getKeyName() |
|
54 | + { |
|
55 | + return $this->_keyname; |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * @return string |
|
60 | + */ |
|
61 | + public function getAlign() |
|
62 | + { |
|
63 | + return $this->_align; |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * @return bool |
|
68 | + */ |
|
69 | + public function isSortable() |
|
70 | + { |
|
71 | + return $this->_sortable; |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * @return bool|string |
|
76 | + */ |
|
77 | + public function getWidth() |
|
78 | + { |
|
79 | + if ($this->_width) { |
|
80 | + $ret = $this->_width; |
|
81 | + } else { |
|
82 | + $ret = ''; |
|
83 | + } |
|
84 | + |
|
85 | + return $ret; |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * @return bool |
|
90 | + */ |
|
91 | + public function getCustomCaption() |
|
92 | + { |
|
93 | + return $this->_customCaption; |
|
94 | + } |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
@@ -105,819 +105,819 @@ discard block |
||
105 | 105 | */ |
106 | 106 | class SmartObjectTable |
107 | 107 | { |
108 | - public $_id; |
|
109 | - public $_objectHandler; |
|
110 | - public $_columns; |
|
111 | - public $_criteria; |
|
112 | - public $_actions; |
|
113 | - public $_objects = false; |
|
114 | - public $_aObjects; |
|
115 | - public $_custom_actions; |
|
116 | - public $_sortsel; |
|
117 | - public $_ordersel; |
|
118 | - public $_limitsel; |
|
119 | - public $_filtersel; |
|
120 | - public $_filterseloptions; |
|
121 | - public $_filtersel2; |
|
122 | - public $_filtersel2options; |
|
123 | - public $_filtersel2optionsDefault; |
|
124 | - |
|
125 | - public $_tempObject; |
|
126 | - public $_tpl; |
|
127 | - public $_introButtons; |
|
128 | - public $_quickSearch = false; |
|
129 | - public $_actionButtons = false; |
|
130 | - public $_head_css_class = 'bg3'; |
|
131 | - public $_hasActions = false; |
|
132 | - public $_userSide = false; |
|
133 | - public $_printerFriendlyPage = false; |
|
134 | - public $_tableHeader = false; |
|
135 | - public $_tableFooter = false; |
|
136 | - public $_showActionsColumnTitle = true; |
|
137 | - public $_isTree = false; |
|
138 | - public $_showFilterAndLimit = true; |
|
139 | - public $_enableColumnsSorting = true; |
|
140 | - public $_customTemplate = false; |
|
141 | - public $_withSelectedActions = array(); |
|
142 | - |
|
143 | - /** |
|
144 | - * Constructor |
|
145 | - * |
|
146 | - * @param SmartPersistableObjectHandler $objectHandler {@link SmartPersistableObjectHandler} |
|
147 | - * @param CriteriaElement $criteria |
|
148 | - * @param array $actions array representing the actions to offer |
|
149 | - * |
|
150 | - * @param bool $userSide |
|
151 | - * @internal param array $columns array representing the columns to display in the table |
|
152 | - */ |
|
153 | - public function __construct(SmartPersistableObjectHandler $objectHandler, CriteriaElement $criteria = null, $actions = array('edit', 'delete'), $userSide = false) |
|
154 | - { |
|
155 | - $this->_id = $objectHandler->className; |
|
156 | - $this->_objectHandler = $objectHandler; |
|
157 | - |
|
158 | - if (!$criteria) { |
|
159 | - $criteria = new CriteriaCompo(); |
|
160 | - } |
|
161 | - $this->_criteria = $criteria; |
|
162 | - $this->_actions = $actions; |
|
163 | - $this->_custom_actions = array(); |
|
164 | - $this->_userSide = $userSide; |
|
165 | - if ($userSide) { |
|
166 | - $this->_head_css_class = 'head'; |
|
167 | - } |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * @param $op |
|
172 | - * @param bool $caption |
|
173 | - * @param bool $text |
|
174 | - */ |
|
175 | - public function addActionButton($op, $caption = false, $text = false) |
|
176 | - { |
|
177 | - $action = array( |
|
178 | - 'op' => $op, |
|
179 | - 'caption' => $caption, |
|
180 | - 'text' => $text |
|
181 | - ); |
|
182 | - $this->_actionButtons[] = $action; |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * @param $columnObj |
|
187 | - */ |
|
188 | - public function addColumn($columnObj) |
|
189 | - { |
|
190 | - $this->_columns[] = $columnObj; |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * @param $name |
|
195 | - * @param $location |
|
196 | - * @param $value |
|
197 | - */ |
|
198 | - public function addIntroButton($name, $location, $value) |
|
199 | - { |
|
200 | - $introButton = array(); |
|
201 | - $introButton['name'] = $name; |
|
202 | - $introButton['location'] = $location; |
|
203 | - $introButton['value'] = $value; |
|
204 | - $this->_introButtons[] = $introButton; |
|
205 | - unset($introButton); |
|
206 | - } |
|
207 | - |
|
208 | - public function addPrinterFriendlyLink() |
|
209 | - { |
|
210 | - $current_urls = smart_getCurrentUrls(); |
|
211 | - $current_url = $current_urls['full']; |
|
212 | - $this->_printerFriendlyPage = $current_url . '&print'; |
|
213 | - } |
|
214 | - |
|
215 | - /** |
|
216 | - * @param $fields |
|
217 | - * @param string $caption |
|
218 | - */ |
|
219 | - public function addQuickSearch($fields, $caption = _CO_SOBJECT_QUICK_SEARCH) |
|
220 | - { |
|
221 | - $this->_quickSearch = array('fields' => $fields, 'caption' => $caption); |
|
222 | - } |
|
223 | - |
|
224 | - /** |
|
225 | - * @param $content |
|
226 | - */ |
|
227 | - public function addHeader($content) |
|
228 | - { |
|
229 | - $this->_tableHeader = $content; |
|
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * @param $content |
|
234 | - */ |
|
235 | - public function addFooter($content) |
|
236 | - { |
|
237 | - $this->_tableFooter = $content; |
|
238 | - } |
|
239 | - |
|
240 | - /** |
|
241 | - * @param $caption |
|
242 | - */ |
|
243 | - public function addDefaultIntroButton($caption) |
|
244 | - { |
|
245 | - $this->addIntroButton($this->_objectHandler->_itemname, $this->_objectHandler->_page . '?op=mod', $caption); |
|
246 | - } |
|
247 | - |
|
248 | - /** |
|
249 | - * @param $method |
|
250 | - */ |
|
251 | - public function addCustomAction($method) |
|
252 | - { |
|
253 | - $this->_custom_actions[] = $method; |
|
254 | - } |
|
255 | - |
|
256 | - /** |
|
257 | - * @param $default_sort |
|
258 | - */ |
|
259 | - public function setDefaultSort($default_sort) |
|
260 | - { |
|
261 | - $this->_sortsel = $default_sort; |
|
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * @return string |
|
266 | - */ |
|
267 | - public function getDefaultSort() |
|
268 | - { |
|
269 | - if ($this->_sortsel) { |
|
270 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
271 | - } else { |
|
272 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_objectHandler->identifierName); |
|
273 | - } |
|
274 | - } |
|
275 | - |
|
276 | - /** |
|
277 | - * @param $default_order |
|
278 | - */ |
|
279 | - public function setDefaultOrder($default_order) |
|
280 | - { |
|
281 | - $this->_ordersel = $default_order; |
|
282 | - } |
|
283 | - |
|
284 | - /** |
|
285 | - * @return string |
|
286 | - */ |
|
287 | - public function getDefaultOrder() |
|
288 | - { |
|
289 | - if ($this->_ordersel) { |
|
290 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
291 | - } else { |
|
292 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', 'ASC'); |
|
293 | - } |
|
294 | - } |
|
295 | - |
|
296 | - /** |
|
297 | - * @param array $actions |
|
298 | - */ |
|
299 | - public function addWithSelectedActions($actions = array()) |
|
300 | - { |
|
301 | - $this->addColumn(new SmartObjectColumn('checked', 'center', 20, false, false, ' ')); |
|
302 | - $this->_withSelectedActions = $actions; |
|
303 | - } |
|
304 | - |
|
305 | - /** |
|
306 | - * Adding a filter in the table |
|
307 | - * |
|
308 | - * @param string $key key to the field that will be used for sorting |
|
309 | - * @param string $method method of the handler that will be called to populate the options when this filter is selected |
|
310 | - * @param bool $default |
|
311 | - */ |
|
312 | - public function addFilter($key, $method, $default = false) |
|
313 | - { |
|
314 | - $this->_filterseloptions[$key] = $method; |
|
315 | - $this->_filtersel2optionsDefault = $default; |
|
316 | - } |
|
317 | - |
|
318 | - /** |
|
319 | - * @param $default_filter |
|
320 | - */ |
|
321 | - public function setDefaultFilter($default_filter) |
|
322 | - { |
|
323 | - $this->_filtersel = $default_filter; |
|
324 | - } |
|
325 | - |
|
326 | - public function isForUserSide() |
|
327 | - { |
|
328 | - $this->_userSide = true; |
|
329 | - } |
|
330 | - |
|
331 | - /** |
|
332 | - * @param $template |
|
333 | - */ |
|
334 | - public function setCustomTemplate($template) |
|
335 | - { |
|
336 | - $this->_customTemplate = $template; |
|
337 | - } |
|
338 | - |
|
339 | - public function setSortOrder() |
|
340 | - { |
|
341 | - $this->_sortsel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] : $this->getDefaultSort(); |
|
342 | - //$this->_sortsel = isset($_POST['sortsel']) ? $_POST['sortsel']: $this->_sortsel; |
|
343 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
344 | - $fieldsForSorting = $this->_tempObject->getFieldsForSorting($this->_sortsel); |
|
345 | - |
|
346 | - if (isset($this->_tempObject->vars[$this->_sortsel]['itemName']) && $this->_tempObject->vars[$this->_sortsel]['itemName']) { |
|
347 | - $this->_criteria->setSort($this->_tempObject->vars[$this->_sortsel]['itemName'] . '.' . $this->_sortsel); |
|
348 | - } else { |
|
349 | - $this->_criteria->setSort($this->_objectHandler->_itemname . '.' . $this->_sortsel); |
|
350 | - } |
|
351 | - |
|
352 | - $this->_ordersel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : $this->getDefaultOrder(); |
|
353 | - //$this->_ordersel = isset($_POST['ordersel']) ? $_POST['ordersel']:$this->_ordersel; |
|
354 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
355 | - $ordersArray = $this->getOrdersArray(); |
|
356 | - $this->_criteria->setOrder($this->_ordersel); |
|
357 | - } |
|
358 | - |
|
359 | - /** |
|
360 | - * @param $id |
|
361 | - */ |
|
362 | - public function setTableId($id) |
|
363 | - { |
|
364 | - $this->_id = $id; |
|
365 | - } |
|
366 | - |
|
367 | - /** |
|
368 | - * @param $objects |
|
369 | - */ |
|
370 | - public function setObjects($objects) |
|
371 | - { |
|
372 | - $this->_objects = $objects; |
|
373 | - } |
|
374 | - |
|
375 | - public function createTableRows() |
|
376 | - { |
|
377 | - $this->_aObjects = array(); |
|
378 | - |
|
379 | - $doWeHaveActions = false; |
|
380 | - |
|
381 | - $objectclass = 'odd'; |
|
382 | - if (count($this->_objects) > 0) { |
|
383 | - foreach ($this->_objects as $object) { |
|
384 | - $aObject = array(); |
|
385 | - |
|
386 | - $i = 0; |
|
387 | - |
|
388 | - $aColumns = array(); |
|
389 | - |
|
390 | - foreach ($this->_columns as $column) { |
|
391 | - $aColumn = array(); |
|
392 | - |
|
393 | - if ($i == 0) { |
|
394 | - $class = 'head'; |
|
395 | - } elseif ($i % 2 == 0) { |
|
396 | - $class = 'even'; |
|
397 | - } else { |
|
398 | - $class = 'odd'; |
|
399 | - } |
|
400 | - if (method_exists($object, 'initiateCustomFields')) { |
|
401 | - //$object->initiateCustomFields(); |
|
402 | - } |
|
403 | - if ($column->_keyname === 'checked') { |
|
404 | - $value = '<input type ="checkbox" name="selected_smartobjects[]" value="' . $object->id() . '" />'; |
|
405 | - } elseif ($column->_customMethodForValue && method_exists($object, $column->_customMethodForValue)) { |
|
406 | - $method = $column->_customMethodForValue; |
|
407 | - if ($column->_param) { |
|
408 | - $value = $object->$method($column->_param); |
|
409 | - } else { |
|
410 | - $value = $object->$method(); |
|
411 | - } |
|
412 | - } else { |
|
413 | - /** |
|
414 | - * If the column is the identifier, then put a link on it |
|
415 | - */ |
|
416 | - if ($column->getKeyName() == $this->_objectHandler->identifierName) { |
|
417 | - $value = $object->getItemLink(); |
|
418 | - } else { |
|
419 | - $value = $object->getVar($column->getKeyName()); |
|
420 | - } |
|
421 | - } |
|
422 | - |
|
423 | - $aColumn['value'] = $value; |
|
424 | - $aColumn['class'] = $class; |
|
425 | - $aColumn['width'] = $column->getWidth(); |
|
426 | - $aColumn['align'] = $column->getAlign(); |
|
427 | - |
|
428 | - $aColumns[] = $aColumn; |
|
429 | - ++$i; |
|
430 | - } |
|
431 | - |
|
432 | - $aObject['columns'] = $aColumns; |
|
433 | - $aObject['id'] = $object->id(); |
|
434 | - |
|
435 | - $objectclass = ($objectclass === 'even') ? 'odd' : 'even'; |
|
436 | - |
|
437 | - $aObject['class'] = $objectclass; |
|
438 | - |
|
439 | - $actions = array(); |
|
440 | - |
|
441 | - // Adding the custom actions if any |
|
442 | - foreach ($this->_custom_actions as $action) { |
|
443 | - if (method_exists($object, $action)) { |
|
444 | - $actions[] = $object->$action(); |
|
445 | - } |
|
446 | - } |
|
447 | - |
|
448 | - include_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
|
449 | - $controller = new SmartObjectController($this->_objectHandler); |
|
450 | - |
|
451 | - if ((!is_array($this->_actions)) || in_array('edit', $this->_actions)) { |
|
452 | - $actions[] = $controller->getEditItemLink($object, false, true, $this->_userSide); |
|
453 | - } |
|
454 | - if ((!is_array($this->_actions)) || in_array('delete', $this->_actions)) { |
|
455 | - $actions[] = $controller->getDeleteItemLink($object, false, true, $this->_userSide); |
|
456 | - } |
|
457 | - $aObject['actions'] = $actions; |
|
458 | - |
|
459 | - $this->_tpl->assign('smartobject_actions_column_width', count($actions) * 30); |
|
460 | - |
|
461 | - $doWeHaveActions = $doWeHaveActions ? true : count($actions) > 0; |
|
462 | - |
|
463 | - $this->_aObjects[] = $aObject; |
|
464 | - } |
|
465 | - $this->_tpl->assign('smartobject_objects', $this->_aObjects); |
|
466 | - } else { |
|
467 | - $colspan = count($this->_columns) + 1; |
|
468 | - $this->_tpl->assign('smartobject_colspan', $colspan); |
|
469 | - } |
|
470 | - $this->_hasActions = $doWeHaveActions; |
|
471 | - } |
|
472 | - |
|
473 | - /** |
|
474 | - * @param bool $debug |
|
475 | - * @return mixed |
|
476 | - */ |
|
477 | - public function fetchObjects($debug = false) |
|
478 | - { |
|
479 | - return $this->_objectHandler->getObjects($this->_criteria, true, true, false, $debug); |
|
480 | - } |
|
481 | - |
|
482 | - /** |
|
483 | - * @return string |
|
484 | - */ |
|
485 | - public function getDefaultFilter() |
|
486 | - { |
|
487 | - if ($this->_filtersel) { |
|
488 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
489 | - } else { |
|
490 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', 'default'); |
|
491 | - } |
|
492 | - } |
|
493 | - |
|
494 | - /** |
|
495 | - * @return array|bool |
|
496 | - */ |
|
497 | - public function getFiltersArray() |
|
498 | - { |
|
499 | - $ret = array(); |
|
500 | - $field = array(); |
|
501 | - $field['caption'] = _CO_OBJ_NONE; |
|
502 | - $field['selected'] = ''; |
|
503 | - $ret['default'] = $field; |
|
504 | - unset($field); |
|
505 | - |
|
506 | - if ($this->_filterseloptions) { |
|
507 | - foreach ($this->_filterseloptions as $key => $value) { |
|
508 | - $field = array(); |
|
509 | - if (is_array($value)) { |
|
510 | - $field['caption'] = $key; |
|
511 | - $field['selected'] = $this->_filtersel == $key ? "selected='selected'" : ''; |
|
512 | - } else { |
|
513 | - $field['caption'] = $this->_tempObject->vars[$key]['form_caption']; |
|
514 | - $field['selected'] = $this->_filtersel == $key ? "selected='selected'" : ''; |
|
515 | - } |
|
516 | - $ret[$key] = $field; |
|
517 | - unset($field); |
|
518 | - } |
|
519 | - } else { |
|
520 | - $ret = false; |
|
521 | - } |
|
522 | - |
|
523 | - return $ret; |
|
524 | - } |
|
525 | - |
|
526 | - /** |
|
527 | - * @param $default_filter2 |
|
528 | - */ |
|
529 | - public function setDefaultFilter2($default_filter2) |
|
530 | - { |
|
531 | - $this->_filtersel2 = $default_filter2; |
|
532 | - } |
|
533 | - |
|
534 | - /** |
|
535 | - * @return string |
|
536 | - */ |
|
537 | - public function getDefaultFilter2() |
|
538 | - { |
|
539 | - if ($this->_filtersel2) { |
|
540 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
541 | - } else { |
|
542 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', 'default'); |
|
543 | - } |
|
544 | - } |
|
545 | - |
|
546 | - /** |
|
547 | - * @return array |
|
548 | - */ |
|
549 | - public function getFilters2Array() |
|
550 | - { |
|
551 | - $ret = array(); |
|
552 | - |
|
553 | - foreach ($this->_filtersel2options as $key => $value) { |
|
554 | - $field = array(); |
|
555 | - $field['caption'] = $value; |
|
556 | - $field['selected'] = $this->_filtersel2 == $key ? "selected='selected'" : ''; |
|
557 | - $ret[$key] = $field; |
|
558 | - unset($field); |
|
559 | - } |
|
560 | - |
|
561 | - return $ret; |
|
562 | - } |
|
563 | - |
|
564 | - /** |
|
565 | - * @param $limitsArray |
|
566 | - * @param $params_of_the_options_sel |
|
567 | - */ |
|
568 | - public function renderOptionSelection($limitsArray, $params_of_the_options_sel) |
|
569 | - { |
|
570 | - // Rendering the form to select options on the table |
|
571 | - $current_urls = smart_getCurrentUrls(); |
|
572 | - $current_url = $current_urls['full']; |
|
573 | - |
|
574 | - /** |
|
575 | - * What was $params_of_the_options_sel doing again ? |
|
576 | - */ |
|
577 | - //$this->_tpl->assign('smartobject_optionssel_action', $_SERVER['PHP_SELF'] . "?" . implode('&', $params_of_the_options_sel)); |
|
578 | - $this->_tpl->assign('smartobject_optionssel_action', $current_url); |
|
579 | - $this->_tpl->assign('smartobject_optionssel_limitsArray', $limitsArray); |
|
580 | - } |
|
581 | - |
|
582 | - /** |
|
583 | - * @return array |
|
584 | - */ |
|
585 | - public function getLimitsArray() |
|
586 | - { |
|
587 | - $ret = array(); |
|
588 | - $ret['all']['caption'] = _CO_SOBJECT_LIMIT_ALL; |
|
589 | - $ret['all']['selected'] = ('all' === $this->_limitsel) ? "selected='selected'" : ''; |
|
590 | - |
|
591 | - $ret['5']['caption'] = '5'; |
|
592 | - $ret['5']['selected'] = ('5' == $this->_limitsel) ? "selected='selected'" : ''; |
|
593 | - |
|
594 | - $ret['10']['caption'] = '10'; |
|
595 | - $ret['10']['selected'] = ('10' == $this->_limitsel) ? "selected='selected'" : ''; |
|
596 | - |
|
597 | - $ret['15']['caption'] = '15'; |
|
598 | - $ret['15']['selected'] = ('15' == $this->_limitsel) ? "selected='selected'" : ''; |
|
599 | - |
|
600 | - $ret['20']['caption'] = '20'; |
|
601 | - $ret['20']['selected'] = ('20' == $this->_limitsel) ? "selected='selected'" : ''; |
|
602 | - |
|
603 | - $ret['25']['caption'] = '25'; |
|
604 | - $ret['25']['selected'] = ('25' == $this->_limitsel) ? "selected='selected'" : ''; |
|
605 | - |
|
606 | - $ret['30']['caption'] = '30'; |
|
607 | - $ret['30']['selected'] = ('30' == $this->_limitsel) ? "selected='selected'" : ''; |
|
608 | - |
|
609 | - $ret['35']['caption'] = '35'; |
|
610 | - $ret['35']['selected'] = ('35' == $this->_limitsel) ? "selected='selected'" : ''; |
|
611 | - |
|
612 | - $ret['40']['caption'] = '40'; |
|
613 | - $ret['40']['selected'] = ('40' == $this->_limitsel) ? "selected='selected'" : ''; |
|
614 | - |
|
615 | - return $ret; |
|
616 | - } |
|
617 | - |
|
618 | - /** |
|
619 | - * @return bool |
|
620 | - */ |
|
621 | - public function getObjects() |
|
622 | - { |
|
623 | - return $this->_objects; |
|
624 | - } |
|
625 | - |
|
626 | - public function hideActionColumnTitle() |
|
627 | - { |
|
628 | - $this->_showActionsColumnTitle = false; |
|
629 | - } |
|
630 | - |
|
631 | - public function hideFilterAndLimit() |
|
632 | - { |
|
633 | - $this->_showFilterAndLimit = false; |
|
634 | - } |
|
635 | - |
|
636 | - /** |
|
637 | - * @return array |
|
638 | - */ |
|
639 | - public function getOrdersArray() |
|
640 | - { |
|
641 | - $ret = array(); |
|
642 | - $ret['ASC']['caption'] = _CO_SOBJECT_SORT_ASC; |
|
643 | - $ret['ASC']['selected'] = ('ASC' === $this->_ordersel) ? "selected='selected'" : ''; |
|
644 | - |
|
645 | - $ret['DESC']['caption'] = _CO_SOBJECT_SORT_DESC; |
|
646 | - $ret['DESC']['selected'] = ('DESC' === $this->_ordersel) ? "selected='selected'" : ''; |
|
647 | - |
|
648 | - return $ret; |
|
649 | - } |
|
650 | - |
|
651 | - /** |
|
652 | - * @return mixed|string|void |
|
653 | - */ |
|
654 | - public function renderD() |
|
655 | - { |
|
656 | - return $this->render(false, true); |
|
657 | - } |
|
658 | - |
|
659 | - public function renderForPrint() |
|
660 | - { |
|
661 | - } |
|
662 | - |
|
663 | - /** |
|
664 | - * @param bool $fetchOnly |
|
665 | - * @param bool $debug |
|
666 | - * @return mixed|string|void |
|
667 | - */ |
|
668 | - public function render($fetchOnly = false, $debug = false) |
|
669 | - { |
|
670 | - include_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
671 | - |
|
672 | - $this->_tpl = new XoopsTpl(); |
|
673 | - |
|
674 | - /** |
|
675 | - * We need access to the vars of the SmartObject for a few things in the table creation. |
|
676 | - * Since we may not have a SmartObject to look into now, let's create one for this purpose |
|
677 | - * and we will free it after |
|
678 | - */ |
|
679 | - $this->_tempObject = $this->_objectHandler->create(); |
|
680 | - |
|
681 | - $this->_criteria->setStart(isset($_GET['start' . $this->_objectHandler->keyName]) ? (int)$_GET['start' . $this->_objectHandler->keyName] : 0); |
|
682 | - |
|
683 | - $this->setSortOrder(); |
|
684 | - |
|
685 | - if (!$this->_isTree) { |
|
686 | - $this->_limitsel = isset($_GET['limitsel']) ? $_GET['limitsel'] : smart_getCookieVar($_SERVER['PHP_SELF'] . '_limitsel', '15'); |
|
687 | - } else { |
|
688 | - $this->_limitsel = 'all'; |
|
689 | - } |
|
690 | - |
|
691 | - $this->_limitsel = isset($_POST['limitsel']) ? $_POST['limitsel'] : $this->_limitsel; |
|
692 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_limitsel', $this->_limitsel); |
|
693 | - $limitsArray = $this->getLimitsArray(); |
|
694 | - $this->_criteria->setLimit($this->_limitsel); |
|
695 | - |
|
696 | - $this->_filtersel = isset($_GET['filtersel']) ? $_GET['filtersel'] : $this->getDefaultFilter(); |
|
697 | - $this->_filtersel = isset($_POST['filtersel']) ? $_POST['filtersel'] : $this->_filtersel; |
|
698 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
699 | - $filtersArray = $this->getFiltersArray(); |
|
700 | - |
|
701 | - if ($filtersArray) { |
|
702 | - $this->_tpl->assign('smartobject_optionssel_filtersArray', $filtersArray); |
|
703 | - } |
|
704 | - |
|
705 | - // Check if the selected filter is defined and if so, create the selfilter2 |
|
706 | - if (isset($this->_filterseloptions[$this->_filtersel])) { |
|
707 | - // check if method associate with this filter exists in the handler |
|
708 | - if (is_array($this->_filterseloptions[$this->_filtersel])) { |
|
709 | - $filter = $this->_filterseloptions[$this->_filtersel]; |
|
710 | - $this->_criteria->add($filter['criteria']); |
|
711 | - } else { |
|
712 | - if (method_exists($this->_objectHandler, $this->_filterseloptions[$this->_filtersel])) { |
|
713 | - |
|
714 | - // then we will create the selfilter2 options by calling this method |
|
715 | - $method = $this->_filterseloptions[$this->_filtersel]; |
|
716 | - $this->_filtersel2options = $this->_objectHandler->$method(); |
|
717 | - |
|
718 | - $this->_filtersel2 = isset($_GET['filtersel2']) ? $_GET['filtersel2'] : $this->getDefaultFilter2(); |
|
719 | - $this->_filtersel2 = isset($_POST['filtersel2']) ? $_POST['filtersel2'] : $this->_filtersel2; |
|
720 | - |
|
721 | - $filters2Array = $this->getFilters2Array(); |
|
722 | - $this->_tpl->assign('smartobject_optionssel_filters2Array', $filters2Array); |
|
723 | - |
|
724 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
725 | - if ($this->_filtersel2 !== 'default') { |
|
726 | - $this->_criteria->add(new Criteria($this->_filtersel, $this->_filtersel2)); |
|
727 | - } |
|
728 | - } |
|
729 | - } |
|
730 | - } |
|
731 | - // Check if we have a quicksearch |
|
732 | - |
|
733 | - if (isset($_POST['quicksearch_' . $this->_id]) && $_POST['quicksearch_' . $this->_id] != '') { |
|
734 | - $quicksearch_criteria = new CriteriaCompo(); |
|
735 | - if (is_array($this->_quickSearch['fields'])) { |
|
736 | - foreach ($this->_quickSearch['fields'] as $v) { |
|
737 | - $quicksearch_criteria->add(new Criteria($v, '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE'), 'OR'); |
|
738 | - } |
|
739 | - } else { |
|
740 | - $quicksearch_criteria->add(new Criteria($this->_quickSearch['fields'], '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE')); |
|
741 | - } |
|
742 | - $this->_criteria->add($quicksearch_criteria); |
|
743 | - } |
|
744 | - |
|
745 | - $this->_objects = $this->fetchObjects($debug); |
|
746 | - |
|
747 | - include_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
|
748 | - if ($this->_criteria->getLimit() > 0) { |
|
749 | - |
|
750 | - /** |
|
751 | - * Geeting rid of the old params |
|
752 | - * $new_get_array is an array containing the new GET parameters |
|
753 | - */ |
|
754 | - $new_get_array = array(); |
|
755 | - |
|
756 | - /** |
|
757 | - * $params_of_the_options_sel is an array with all the parameters of the page |
|
758 | - * but without the pagenave parameters. This array will be used in the |
|
759 | - * OptionsSelection |
|
760 | - */ |
|
761 | - $params_of_the_options_sel = array(); |
|
762 | - |
|
763 | - $not_needed_params = array('sortsel', 'limitsel', 'ordersel', 'start' . $this->_objectHandler->keyName); |
|
764 | - foreach ($_GET as $k => $v) { |
|
765 | - if (!in_array($k, $not_needed_params)) { |
|
766 | - $new_get_array[] = "$k=$v"; |
|
767 | - $params_of_the_options_sel[] = "$k=$v"; |
|
768 | - } |
|
769 | - } |
|
770 | - |
|
771 | - /** |
|
772 | - * Adding the new params of the pagenav |
|
773 | - */ |
|
774 | - $new_get_array[] = 'sortsel=' . $this->_sortsel; |
|
775 | - $new_get_array[] = 'ordersel=' . $this->_ordersel; |
|
776 | - $new_get_array[] = 'limitsel=' . $this->_limitsel; |
|
777 | - $otherParams = implode('&', $new_get_array); |
|
778 | - |
|
779 | - $pagenav = |
|
780 | - new XoopsPageNav($this->_objectHandler->getCount($this->_criteria), $this->_criteria->getLimit(), $this->_criteria->getStart(), 'start' . $this->_objectHandler->keyName, $otherParams); |
|
781 | - $this->_tpl->assign('smartobject_pagenav', $pagenav->renderNav()); |
|
782 | - } |
|
783 | - $this->renderOptionSelection($limitsArray, $params_of_the_options_sel); |
|
784 | - |
|
785 | - // retreive the current url and the query string |
|
786 | - $current_urls = smart_getCurrentUrls(); |
|
787 | - $current_url = $current_urls['full_phpself']; |
|
788 | - $query_string = $current_urls['querystring']; |
|
789 | - if ($query_string) { |
|
790 | - $query_string = str_replace('?', '', $query_string); |
|
791 | - } |
|
792 | - $query_stringArray = explode('&', $query_string); |
|
793 | - $new_query_stringArray = array(); |
|
794 | - foreach ($query_stringArray as $query_string) { |
|
795 | - if (strpos($query_string, 'sortsel') == false && strpos($query_string, 'ordersel') == false) { |
|
796 | - $new_query_stringArray[] = $query_string; |
|
797 | - } |
|
798 | - } |
|
799 | - $new_query_string = implode('&', $new_query_stringArray); |
|
800 | - |
|
801 | - $orderArray = array(); |
|
802 | - $orderArray['ASC']['image'] = 'desc.png'; |
|
803 | - $orderArray['ASC']['neworder'] = 'DESC'; |
|
804 | - $orderArray['DESC']['image'] = 'asc.png'; |
|
805 | - $orderArray['DESC']['neworder'] = 'ASC'; |
|
806 | - |
|
807 | - $aColumns = array(); |
|
808 | - |
|
809 | - foreach ($this->_columns as $column) { |
|
810 | - $qs_param = ''; |
|
811 | - $aColumn = array(); |
|
812 | - $aColumn['width'] = $column->getWidth(); |
|
813 | - $aColumn['align'] = $column->getAlign(); |
|
814 | - $aColumn['key'] = $column->getKeyName(); |
|
815 | - if ($column->_keyname === 'checked') { |
|
816 | - $aColumn['caption'] = '<input type ="checkbox" id="checkall_smartobjects" name="checkall_smartobjects"' |
|
817 | - . ' value="checkall_smartobjects" onclick="smartobject_checkall(window.document.form_' |
|
818 | - . $this->_id |
|
819 | - . ', \'selected_smartobjects\');" />'; |
|
820 | - } elseif ($column->getCustomCaption()) { |
|
821 | - $aColumn['caption'] = $column->getCustomCaption(); |
|
822 | - } else { |
|
823 | - $aColumn['caption'] = isset($this->_tempObject->vars[$column->getKeyName()]['form_caption']) ? $this->_tempObject->vars[$column->getKeyName()]['form_caption'] : $column->getKeyName(); |
|
824 | - } |
|
825 | - // Are we doing a GET sort on this column ? |
|
826 | - $getSort = (isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) && $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] == $column->getKeyName()) |
|
827 | - || ($this->_sortsel == $column->getKeyName()); |
|
828 | - $order = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : 'DESC'; |
|
829 | - |
|
830 | - if (isset($_REQUEST['quicksearch_' . $this->_id]) && $_REQUEST['quicksearch_' . $this->_id] != '') { |
|
831 | - $qs_param = '&quicksearch_' . $this->_id . '=' . $_REQUEST['quicksearch_' . $this->_id]; |
|
832 | - } |
|
833 | - if (!$this->_enableColumnsSorting || $column->_keyname === 'checked' || !$column->isSortable()) { |
|
834 | - $aColumn['caption'] = $aColumn['caption']; |
|
835 | - } elseif ($getSort) { |
|
836 | - $aColumn['caption'] = '<a href="' |
|
837 | - . $current_url |
|
838 | - . '?' |
|
839 | - . $this->_objectHandler->_itemname |
|
840 | - . '_' |
|
841 | - . 'sortsel=' |
|
842 | - . $column->getKeyName() |
|
843 | - . '&' |
|
844 | - . $this->_objectHandler->_itemname |
|
845 | - . '_' |
|
846 | - . 'ordersel=' |
|
847 | - . $orderArray[$order]['neworder'] |
|
848 | - . $qs_param |
|
849 | - . '&' |
|
850 | - . $new_query_string |
|
851 | - . '">' |
|
852 | - . $aColumn['caption'] |
|
853 | - . ' <img src="' |
|
854 | - . SMARTOBJECT_IMAGES_ACTIONS_URL |
|
855 | - . $orderArray[$order]['image'] |
|
856 | - . '" alt="ASC" /></a>'; |
|
857 | - } else { |
|
858 | - $aColumn['caption'] = '<a href="' |
|
859 | - . $current_url |
|
860 | - . '?' |
|
861 | - . $this->_objectHandler->_itemname |
|
862 | - . '_' |
|
863 | - . 'sortsel=' |
|
864 | - . $column->getKeyName() |
|
865 | - . '&' |
|
866 | - . $this->_objectHandler->_itemname |
|
867 | - . '_' |
|
868 | - . 'ordersel=ASC' |
|
869 | - . $qs_param |
|
870 | - . '&' |
|
871 | - . $new_query_string |
|
872 | - . '">' |
|
873 | - . $aColumn['caption'] |
|
874 | - . '</a>'; |
|
875 | - } |
|
876 | - $aColumns[] = $aColumn; |
|
877 | - } |
|
878 | - $this->_tpl->assign('smartobject_columns', $aColumns); |
|
879 | - |
|
880 | - if ($this->_quickSearch) { |
|
881 | - $this->_tpl->assign('smartobject_quicksearch', $this->_quickSearch['caption']); |
|
882 | - } |
|
883 | - |
|
884 | - $this->createTableRows(); |
|
885 | - |
|
886 | - $this->_tpl->assign('smartobject_showFilterAndLimit', $this->_showFilterAndLimit); |
|
887 | - $this->_tpl->assign('smartobject_isTree', $this->_isTree); |
|
888 | - $this->_tpl->assign('smartobject_show_action_column_title', $this->_showActionsColumnTitle); |
|
889 | - $this->_tpl->assign('smartobject_table_header', $this->_tableHeader); |
|
890 | - $this->_tpl->assign('smartobject_table_footer', $this->_tableFooter); |
|
891 | - $this->_tpl->assign('smartobject_printer_friendly_page', $this->_printerFriendlyPage); |
|
892 | - $this->_tpl->assign('smartobject_user_side', $this->_userSide); |
|
893 | - $this->_tpl->assign('smartobject_has_actions', $this->_hasActions); |
|
894 | - $this->_tpl->assign('smartobject_head_css_class', $this->_head_css_class); |
|
895 | - $this->_tpl->assign('smartobject_actionButtons', $this->_actionButtons); |
|
896 | - $this->_tpl->assign('smartobject_introButtons', $this->_introButtons); |
|
897 | - $this->_tpl->assign('smartobject_id', $this->_id); |
|
898 | - if (!empty($this->_withSelectedActions)) { |
|
899 | - $this->_tpl->assign('smartobject_withSelectedActions', $this->_withSelectedActions); |
|
900 | - } |
|
901 | - |
|
902 | - $smartobjectTable_template = $this->_customTemplate ?: 'smartobject_smarttable_display.tpl'; |
|
903 | - if ($fetchOnly) { |
|
904 | - return $this->_tpl->fetch('db:' . $smartobjectTable_template); |
|
905 | - } else { |
|
906 | - $this->_tpl->display('db:' . $smartobjectTable_template); |
|
907 | - } |
|
908 | - } |
|
909 | - |
|
910 | - public function disableColumnsSorting() |
|
911 | - { |
|
912 | - $this->_enableColumnsSorting = false; |
|
913 | - } |
|
914 | - |
|
915 | - /** |
|
916 | - * @param bool $debug |
|
917 | - * @return mixed|string|void |
|
918 | - */ |
|
919 | - public function fetch($debug = false) |
|
920 | - { |
|
921 | - return $this->render(true, $debug); |
|
922 | - } |
|
108 | + public $_id; |
|
109 | + public $_objectHandler; |
|
110 | + public $_columns; |
|
111 | + public $_criteria; |
|
112 | + public $_actions; |
|
113 | + public $_objects = false; |
|
114 | + public $_aObjects; |
|
115 | + public $_custom_actions; |
|
116 | + public $_sortsel; |
|
117 | + public $_ordersel; |
|
118 | + public $_limitsel; |
|
119 | + public $_filtersel; |
|
120 | + public $_filterseloptions; |
|
121 | + public $_filtersel2; |
|
122 | + public $_filtersel2options; |
|
123 | + public $_filtersel2optionsDefault; |
|
124 | + |
|
125 | + public $_tempObject; |
|
126 | + public $_tpl; |
|
127 | + public $_introButtons; |
|
128 | + public $_quickSearch = false; |
|
129 | + public $_actionButtons = false; |
|
130 | + public $_head_css_class = 'bg3'; |
|
131 | + public $_hasActions = false; |
|
132 | + public $_userSide = false; |
|
133 | + public $_printerFriendlyPage = false; |
|
134 | + public $_tableHeader = false; |
|
135 | + public $_tableFooter = false; |
|
136 | + public $_showActionsColumnTitle = true; |
|
137 | + public $_isTree = false; |
|
138 | + public $_showFilterAndLimit = true; |
|
139 | + public $_enableColumnsSorting = true; |
|
140 | + public $_customTemplate = false; |
|
141 | + public $_withSelectedActions = array(); |
|
142 | + |
|
143 | + /** |
|
144 | + * Constructor |
|
145 | + * |
|
146 | + * @param SmartPersistableObjectHandler $objectHandler {@link SmartPersistableObjectHandler} |
|
147 | + * @param CriteriaElement $criteria |
|
148 | + * @param array $actions array representing the actions to offer |
|
149 | + * |
|
150 | + * @param bool $userSide |
|
151 | + * @internal param array $columns array representing the columns to display in the table |
|
152 | + */ |
|
153 | + public function __construct(SmartPersistableObjectHandler $objectHandler, CriteriaElement $criteria = null, $actions = array('edit', 'delete'), $userSide = false) |
|
154 | + { |
|
155 | + $this->_id = $objectHandler->className; |
|
156 | + $this->_objectHandler = $objectHandler; |
|
157 | + |
|
158 | + if (!$criteria) { |
|
159 | + $criteria = new CriteriaCompo(); |
|
160 | + } |
|
161 | + $this->_criteria = $criteria; |
|
162 | + $this->_actions = $actions; |
|
163 | + $this->_custom_actions = array(); |
|
164 | + $this->_userSide = $userSide; |
|
165 | + if ($userSide) { |
|
166 | + $this->_head_css_class = 'head'; |
|
167 | + } |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * @param $op |
|
172 | + * @param bool $caption |
|
173 | + * @param bool $text |
|
174 | + */ |
|
175 | + public function addActionButton($op, $caption = false, $text = false) |
|
176 | + { |
|
177 | + $action = array( |
|
178 | + 'op' => $op, |
|
179 | + 'caption' => $caption, |
|
180 | + 'text' => $text |
|
181 | + ); |
|
182 | + $this->_actionButtons[] = $action; |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * @param $columnObj |
|
187 | + */ |
|
188 | + public function addColumn($columnObj) |
|
189 | + { |
|
190 | + $this->_columns[] = $columnObj; |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * @param $name |
|
195 | + * @param $location |
|
196 | + * @param $value |
|
197 | + */ |
|
198 | + public function addIntroButton($name, $location, $value) |
|
199 | + { |
|
200 | + $introButton = array(); |
|
201 | + $introButton['name'] = $name; |
|
202 | + $introButton['location'] = $location; |
|
203 | + $introButton['value'] = $value; |
|
204 | + $this->_introButtons[] = $introButton; |
|
205 | + unset($introButton); |
|
206 | + } |
|
207 | + |
|
208 | + public function addPrinterFriendlyLink() |
|
209 | + { |
|
210 | + $current_urls = smart_getCurrentUrls(); |
|
211 | + $current_url = $current_urls['full']; |
|
212 | + $this->_printerFriendlyPage = $current_url . '&print'; |
|
213 | + } |
|
214 | + |
|
215 | + /** |
|
216 | + * @param $fields |
|
217 | + * @param string $caption |
|
218 | + */ |
|
219 | + public function addQuickSearch($fields, $caption = _CO_SOBJECT_QUICK_SEARCH) |
|
220 | + { |
|
221 | + $this->_quickSearch = array('fields' => $fields, 'caption' => $caption); |
|
222 | + } |
|
223 | + |
|
224 | + /** |
|
225 | + * @param $content |
|
226 | + */ |
|
227 | + public function addHeader($content) |
|
228 | + { |
|
229 | + $this->_tableHeader = $content; |
|
230 | + } |
|
231 | + |
|
232 | + /** |
|
233 | + * @param $content |
|
234 | + */ |
|
235 | + public function addFooter($content) |
|
236 | + { |
|
237 | + $this->_tableFooter = $content; |
|
238 | + } |
|
239 | + |
|
240 | + /** |
|
241 | + * @param $caption |
|
242 | + */ |
|
243 | + public function addDefaultIntroButton($caption) |
|
244 | + { |
|
245 | + $this->addIntroButton($this->_objectHandler->_itemname, $this->_objectHandler->_page . '?op=mod', $caption); |
|
246 | + } |
|
247 | + |
|
248 | + /** |
|
249 | + * @param $method |
|
250 | + */ |
|
251 | + public function addCustomAction($method) |
|
252 | + { |
|
253 | + $this->_custom_actions[] = $method; |
|
254 | + } |
|
255 | + |
|
256 | + /** |
|
257 | + * @param $default_sort |
|
258 | + */ |
|
259 | + public function setDefaultSort($default_sort) |
|
260 | + { |
|
261 | + $this->_sortsel = $default_sort; |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * @return string |
|
266 | + */ |
|
267 | + public function getDefaultSort() |
|
268 | + { |
|
269 | + if ($this->_sortsel) { |
|
270 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
271 | + } else { |
|
272 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_objectHandler->identifierName); |
|
273 | + } |
|
274 | + } |
|
275 | + |
|
276 | + /** |
|
277 | + * @param $default_order |
|
278 | + */ |
|
279 | + public function setDefaultOrder($default_order) |
|
280 | + { |
|
281 | + $this->_ordersel = $default_order; |
|
282 | + } |
|
283 | + |
|
284 | + /** |
|
285 | + * @return string |
|
286 | + */ |
|
287 | + public function getDefaultOrder() |
|
288 | + { |
|
289 | + if ($this->_ordersel) { |
|
290 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
291 | + } else { |
|
292 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', 'ASC'); |
|
293 | + } |
|
294 | + } |
|
295 | + |
|
296 | + /** |
|
297 | + * @param array $actions |
|
298 | + */ |
|
299 | + public function addWithSelectedActions($actions = array()) |
|
300 | + { |
|
301 | + $this->addColumn(new SmartObjectColumn('checked', 'center', 20, false, false, ' ')); |
|
302 | + $this->_withSelectedActions = $actions; |
|
303 | + } |
|
304 | + |
|
305 | + /** |
|
306 | + * Adding a filter in the table |
|
307 | + * |
|
308 | + * @param string $key key to the field that will be used for sorting |
|
309 | + * @param string $method method of the handler that will be called to populate the options when this filter is selected |
|
310 | + * @param bool $default |
|
311 | + */ |
|
312 | + public function addFilter($key, $method, $default = false) |
|
313 | + { |
|
314 | + $this->_filterseloptions[$key] = $method; |
|
315 | + $this->_filtersel2optionsDefault = $default; |
|
316 | + } |
|
317 | + |
|
318 | + /** |
|
319 | + * @param $default_filter |
|
320 | + */ |
|
321 | + public function setDefaultFilter($default_filter) |
|
322 | + { |
|
323 | + $this->_filtersel = $default_filter; |
|
324 | + } |
|
325 | + |
|
326 | + public function isForUserSide() |
|
327 | + { |
|
328 | + $this->_userSide = true; |
|
329 | + } |
|
330 | + |
|
331 | + /** |
|
332 | + * @param $template |
|
333 | + */ |
|
334 | + public function setCustomTemplate($template) |
|
335 | + { |
|
336 | + $this->_customTemplate = $template; |
|
337 | + } |
|
338 | + |
|
339 | + public function setSortOrder() |
|
340 | + { |
|
341 | + $this->_sortsel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] : $this->getDefaultSort(); |
|
342 | + //$this->_sortsel = isset($_POST['sortsel']) ? $_POST['sortsel']: $this->_sortsel; |
|
343 | + smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
344 | + $fieldsForSorting = $this->_tempObject->getFieldsForSorting($this->_sortsel); |
|
345 | + |
|
346 | + if (isset($this->_tempObject->vars[$this->_sortsel]['itemName']) && $this->_tempObject->vars[$this->_sortsel]['itemName']) { |
|
347 | + $this->_criteria->setSort($this->_tempObject->vars[$this->_sortsel]['itemName'] . '.' . $this->_sortsel); |
|
348 | + } else { |
|
349 | + $this->_criteria->setSort($this->_objectHandler->_itemname . '.' . $this->_sortsel); |
|
350 | + } |
|
351 | + |
|
352 | + $this->_ordersel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : $this->getDefaultOrder(); |
|
353 | + //$this->_ordersel = isset($_POST['ordersel']) ? $_POST['ordersel']:$this->_ordersel; |
|
354 | + smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
355 | + $ordersArray = $this->getOrdersArray(); |
|
356 | + $this->_criteria->setOrder($this->_ordersel); |
|
357 | + } |
|
358 | + |
|
359 | + /** |
|
360 | + * @param $id |
|
361 | + */ |
|
362 | + public function setTableId($id) |
|
363 | + { |
|
364 | + $this->_id = $id; |
|
365 | + } |
|
366 | + |
|
367 | + /** |
|
368 | + * @param $objects |
|
369 | + */ |
|
370 | + public function setObjects($objects) |
|
371 | + { |
|
372 | + $this->_objects = $objects; |
|
373 | + } |
|
374 | + |
|
375 | + public function createTableRows() |
|
376 | + { |
|
377 | + $this->_aObjects = array(); |
|
378 | + |
|
379 | + $doWeHaveActions = false; |
|
380 | + |
|
381 | + $objectclass = 'odd'; |
|
382 | + if (count($this->_objects) > 0) { |
|
383 | + foreach ($this->_objects as $object) { |
|
384 | + $aObject = array(); |
|
385 | + |
|
386 | + $i = 0; |
|
387 | + |
|
388 | + $aColumns = array(); |
|
389 | + |
|
390 | + foreach ($this->_columns as $column) { |
|
391 | + $aColumn = array(); |
|
392 | + |
|
393 | + if ($i == 0) { |
|
394 | + $class = 'head'; |
|
395 | + } elseif ($i % 2 == 0) { |
|
396 | + $class = 'even'; |
|
397 | + } else { |
|
398 | + $class = 'odd'; |
|
399 | + } |
|
400 | + if (method_exists($object, 'initiateCustomFields')) { |
|
401 | + //$object->initiateCustomFields(); |
|
402 | + } |
|
403 | + if ($column->_keyname === 'checked') { |
|
404 | + $value = '<input type ="checkbox" name="selected_smartobjects[]" value="' . $object->id() . '" />'; |
|
405 | + } elseif ($column->_customMethodForValue && method_exists($object, $column->_customMethodForValue)) { |
|
406 | + $method = $column->_customMethodForValue; |
|
407 | + if ($column->_param) { |
|
408 | + $value = $object->$method($column->_param); |
|
409 | + } else { |
|
410 | + $value = $object->$method(); |
|
411 | + } |
|
412 | + } else { |
|
413 | + /** |
|
414 | + * If the column is the identifier, then put a link on it |
|
415 | + */ |
|
416 | + if ($column->getKeyName() == $this->_objectHandler->identifierName) { |
|
417 | + $value = $object->getItemLink(); |
|
418 | + } else { |
|
419 | + $value = $object->getVar($column->getKeyName()); |
|
420 | + } |
|
421 | + } |
|
422 | + |
|
423 | + $aColumn['value'] = $value; |
|
424 | + $aColumn['class'] = $class; |
|
425 | + $aColumn['width'] = $column->getWidth(); |
|
426 | + $aColumn['align'] = $column->getAlign(); |
|
427 | + |
|
428 | + $aColumns[] = $aColumn; |
|
429 | + ++$i; |
|
430 | + } |
|
431 | + |
|
432 | + $aObject['columns'] = $aColumns; |
|
433 | + $aObject['id'] = $object->id(); |
|
434 | + |
|
435 | + $objectclass = ($objectclass === 'even') ? 'odd' : 'even'; |
|
436 | + |
|
437 | + $aObject['class'] = $objectclass; |
|
438 | + |
|
439 | + $actions = array(); |
|
440 | + |
|
441 | + // Adding the custom actions if any |
|
442 | + foreach ($this->_custom_actions as $action) { |
|
443 | + if (method_exists($object, $action)) { |
|
444 | + $actions[] = $object->$action(); |
|
445 | + } |
|
446 | + } |
|
447 | + |
|
448 | + include_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
|
449 | + $controller = new SmartObjectController($this->_objectHandler); |
|
450 | + |
|
451 | + if ((!is_array($this->_actions)) || in_array('edit', $this->_actions)) { |
|
452 | + $actions[] = $controller->getEditItemLink($object, false, true, $this->_userSide); |
|
453 | + } |
|
454 | + if ((!is_array($this->_actions)) || in_array('delete', $this->_actions)) { |
|
455 | + $actions[] = $controller->getDeleteItemLink($object, false, true, $this->_userSide); |
|
456 | + } |
|
457 | + $aObject['actions'] = $actions; |
|
458 | + |
|
459 | + $this->_tpl->assign('smartobject_actions_column_width', count($actions) * 30); |
|
460 | + |
|
461 | + $doWeHaveActions = $doWeHaveActions ? true : count($actions) > 0; |
|
462 | + |
|
463 | + $this->_aObjects[] = $aObject; |
|
464 | + } |
|
465 | + $this->_tpl->assign('smartobject_objects', $this->_aObjects); |
|
466 | + } else { |
|
467 | + $colspan = count($this->_columns) + 1; |
|
468 | + $this->_tpl->assign('smartobject_colspan', $colspan); |
|
469 | + } |
|
470 | + $this->_hasActions = $doWeHaveActions; |
|
471 | + } |
|
472 | + |
|
473 | + /** |
|
474 | + * @param bool $debug |
|
475 | + * @return mixed |
|
476 | + */ |
|
477 | + public function fetchObjects($debug = false) |
|
478 | + { |
|
479 | + return $this->_objectHandler->getObjects($this->_criteria, true, true, false, $debug); |
|
480 | + } |
|
481 | + |
|
482 | + /** |
|
483 | + * @return string |
|
484 | + */ |
|
485 | + public function getDefaultFilter() |
|
486 | + { |
|
487 | + if ($this->_filtersel) { |
|
488 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
489 | + } else { |
|
490 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', 'default'); |
|
491 | + } |
|
492 | + } |
|
493 | + |
|
494 | + /** |
|
495 | + * @return array|bool |
|
496 | + */ |
|
497 | + public function getFiltersArray() |
|
498 | + { |
|
499 | + $ret = array(); |
|
500 | + $field = array(); |
|
501 | + $field['caption'] = _CO_OBJ_NONE; |
|
502 | + $field['selected'] = ''; |
|
503 | + $ret['default'] = $field; |
|
504 | + unset($field); |
|
505 | + |
|
506 | + if ($this->_filterseloptions) { |
|
507 | + foreach ($this->_filterseloptions as $key => $value) { |
|
508 | + $field = array(); |
|
509 | + if (is_array($value)) { |
|
510 | + $field['caption'] = $key; |
|
511 | + $field['selected'] = $this->_filtersel == $key ? "selected='selected'" : ''; |
|
512 | + } else { |
|
513 | + $field['caption'] = $this->_tempObject->vars[$key]['form_caption']; |
|
514 | + $field['selected'] = $this->_filtersel == $key ? "selected='selected'" : ''; |
|
515 | + } |
|
516 | + $ret[$key] = $field; |
|
517 | + unset($field); |
|
518 | + } |
|
519 | + } else { |
|
520 | + $ret = false; |
|
521 | + } |
|
522 | + |
|
523 | + return $ret; |
|
524 | + } |
|
525 | + |
|
526 | + /** |
|
527 | + * @param $default_filter2 |
|
528 | + */ |
|
529 | + public function setDefaultFilter2($default_filter2) |
|
530 | + { |
|
531 | + $this->_filtersel2 = $default_filter2; |
|
532 | + } |
|
533 | + |
|
534 | + /** |
|
535 | + * @return string |
|
536 | + */ |
|
537 | + public function getDefaultFilter2() |
|
538 | + { |
|
539 | + if ($this->_filtersel2) { |
|
540 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
541 | + } else { |
|
542 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', 'default'); |
|
543 | + } |
|
544 | + } |
|
545 | + |
|
546 | + /** |
|
547 | + * @return array |
|
548 | + */ |
|
549 | + public function getFilters2Array() |
|
550 | + { |
|
551 | + $ret = array(); |
|
552 | + |
|
553 | + foreach ($this->_filtersel2options as $key => $value) { |
|
554 | + $field = array(); |
|
555 | + $field['caption'] = $value; |
|
556 | + $field['selected'] = $this->_filtersel2 == $key ? "selected='selected'" : ''; |
|
557 | + $ret[$key] = $field; |
|
558 | + unset($field); |
|
559 | + } |
|
560 | + |
|
561 | + return $ret; |
|
562 | + } |
|
563 | + |
|
564 | + /** |
|
565 | + * @param $limitsArray |
|
566 | + * @param $params_of_the_options_sel |
|
567 | + */ |
|
568 | + public function renderOptionSelection($limitsArray, $params_of_the_options_sel) |
|
569 | + { |
|
570 | + // Rendering the form to select options on the table |
|
571 | + $current_urls = smart_getCurrentUrls(); |
|
572 | + $current_url = $current_urls['full']; |
|
573 | + |
|
574 | + /** |
|
575 | + * What was $params_of_the_options_sel doing again ? |
|
576 | + */ |
|
577 | + //$this->_tpl->assign('smartobject_optionssel_action', $_SERVER['PHP_SELF'] . "?" . implode('&', $params_of_the_options_sel)); |
|
578 | + $this->_tpl->assign('smartobject_optionssel_action', $current_url); |
|
579 | + $this->_tpl->assign('smartobject_optionssel_limitsArray', $limitsArray); |
|
580 | + } |
|
581 | + |
|
582 | + /** |
|
583 | + * @return array |
|
584 | + */ |
|
585 | + public function getLimitsArray() |
|
586 | + { |
|
587 | + $ret = array(); |
|
588 | + $ret['all']['caption'] = _CO_SOBJECT_LIMIT_ALL; |
|
589 | + $ret['all']['selected'] = ('all' === $this->_limitsel) ? "selected='selected'" : ''; |
|
590 | + |
|
591 | + $ret['5']['caption'] = '5'; |
|
592 | + $ret['5']['selected'] = ('5' == $this->_limitsel) ? "selected='selected'" : ''; |
|
593 | + |
|
594 | + $ret['10']['caption'] = '10'; |
|
595 | + $ret['10']['selected'] = ('10' == $this->_limitsel) ? "selected='selected'" : ''; |
|
596 | + |
|
597 | + $ret['15']['caption'] = '15'; |
|
598 | + $ret['15']['selected'] = ('15' == $this->_limitsel) ? "selected='selected'" : ''; |
|
599 | + |
|
600 | + $ret['20']['caption'] = '20'; |
|
601 | + $ret['20']['selected'] = ('20' == $this->_limitsel) ? "selected='selected'" : ''; |
|
602 | + |
|
603 | + $ret['25']['caption'] = '25'; |
|
604 | + $ret['25']['selected'] = ('25' == $this->_limitsel) ? "selected='selected'" : ''; |
|
605 | + |
|
606 | + $ret['30']['caption'] = '30'; |
|
607 | + $ret['30']['selected'] = ('30' == $this->_limitsel) ? "selected='selected'" : ''; |
|
608 | + |
|
609 | + $ret['35']['caption'] = '35'; |
|
610 | + $ret['35']['selected'] = ('35' == $this->_limitsel) ? "selected='selected'" : ''; |
|
611 | + |
|
612 | + $ret['40']['caption'] = '40'; |
|
613 | + $ret['40']['selected'] = ('40' == $this->_limitsel) ? "selected='selected'" : ''; |
|
614 | + |
|
615 | + return $ret; |
|
616 | + } |
|
617 | + |
|
618 | + /** |
|
619 | + * @return bool |
|
620 | + */ |
|
621 | + public function getObjects() |
|
622 | + { |
|
623 | + return $this->_objects; |
|
624 | + } |
|
625 | + |
|
626 | + public function hideActionColumnTitle() |
|
627 | + { |
|
628 | + $this->_showActionsColumnTitle = false; |
|
629 | + } |
|
630 | + |
|
631 | + public function hideFilterAndLimit() |
|
632 | + { |
|
633 | + $this->_showFilterAndLimit = false; |
|
634 | + } |
|
635 | + |
|
636 | + /** |
|
637 | + * @return array |
|
638 | + */ |
|
639 | + public function getOrdersArray() |
|
640 | + { |
|
641 | + $ret = array(); |
|
642 | + $ret['ASC']['caption'] = _CO_SOBJECT_SORT_ASC; |
|
643 | + $ret['ASC']['selected'] = ('ASC' === $this->_ordersel) ? "selected='selected'" : ''; |
|
644 | + |
|
645 | + $ret['DESC']['caption'] = _CO_SOBJECT_SORT_DESC; |
|
646 | + $ret['DESC']['selected'] = ('DESC' === $this->_ordersel) ? "selected='selected'" : ''; |
|
647 | + |
|
648 | + return $ret; |
|
649 | + } |
|
650 | + |
|
651 | + /** |
|
652 | + * @return mixed|string|void |
|
653 | + */ |
|
654 | + public function renderD() |
|
655 | + { |
|
656 | + return $this->render(false, true); |
|
657 | + } |
|
658 | + |
|
659 | + public function renderForPrint() |
|
660 | + { |
|
661 | + } |
|
662 | + |
|
663 | + /** |
|
664 | + * @param bool $fetchOnly |
|
665 | + * @param bool $debug |
|
666 | + * @return mixed|string|void |
|
667 | + */ |
|
668 | + public function render($fetchOnly = false, $debug = false) |
|
669 | + { |
|
670 | + include_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
671 | + |
|
672 | + $this->_tpl = new XoopsTpl(); |
|
673 | + |
|
674 | + /** |
|
675 | + * We need access to the vars of the SmartObject for a few things in the table creation. |
|
676 | + * Since we may not have a SmartObject to look into now, let's create one for this purpose |
|
677 | + * and we will free it after |
|
678 | + */ |
|
679 | + $this->_tempObject = $this->_objectHandler->create(); |
|
680 | + |
|
681 | + $this->_criteria->setStart(isset($_GET['start' . $this->_objectHandler->keyName]) ? (int)$_GET['start' . $this->_objectHandler->keyName] : 0); |
|
682 | + |
|
683 | + $this->setSortOrder(); |
|
684 | + |
|
685 | + if (!$this->_isTree) { |
|
686 | + $this->_limitsel = isset($_GET['limitsel']) ? $_GET['limitsel'] : smart_getCookieVar($_SERVER['PHP_SELF'] . '_limitsel', '15'); |
|
687 | + } else { |
|
688 | + $this->_limitsel = 'all'; |
|
689 | + } |
|
690 | + |
|
691 | + $this->_limitsel = isset($_POST['limitsel']) ? $_POST['limitsel'] : $this->_limitsel; |
|
692 | + smart_setCookieVar($_SERVER['PHP_SELF'] . '_limitsel', $this->_limitsel); |
|
693 | + $limitsArray = $this->getLimitsArray(); |
|
694 | + $this->_criteria->setLimit($this->_limitsel); |
|
695 | + |
|
696 | + $this->_filtersel = isset($_GET['filtersel']) ? $_GET['filtersel'] : $this->getDefaultFilter(); |
|
697 | + $this->_filtersel = isset($_POST['filtersel']) ? $_POST['filtersel'] : $this->_filtersel; |
|
698 | + smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
699 | + $filtersArray = $this->getFiltersArray(); |
|
700 | + |
|
701 | + if ($filtersArray) { |
|
702 | + $this->_tpl->assign('smartobject_optionssel_filtersArray', $filtersArray); |
|
703 | + } |
|
704 | + |
|
705 | + // Check if the selected filter is defined and if so, create the selfilter2 |
|
706 | + if (isset($this->_filterseloptions[$this->_filtersel])) { |
|
707 | + // check if method associate with this filter exists in the handler |
|
708 | + if (is_array($this->_filterseloptions[$this->_filtersel])) { |
|
709 | + $filter = $this->_filterseloptions[$this->_filtersel]; |
|
710 | + $this->_criteria->add($filter['criteria']); |
|
711 | + } else { |
|
712 | + if (method_exists($this->_objectHandler, $this->_filterseloptions[$this->_filtersel])) { |
|
713 | + |
|
714 | + // then we will create the selfilter2 options by calling this method |
|
715 | + $method = $this->_filterseloptions[$this->_filtersel]; |
|
716 | + $this->_filtersel2options = $this->_objectHandler->$method(); |
|
717 | + |
|
718 | + $this->_filtersel2 = isset($_GET['filtersel2']) ? $_GET['filtersel2'] : $this->getDefaultFilter2(); |
|
719 | + $this->_filtersel2 = isset($_POST['filtersel2']) ? $_POST['filtersel2'] : $this->_filtersel2; |
|
720 | + |
|
721 | + $filters2Array = $this->getFilters2Array(); |
|
722 | + $this->_tpl->assign('smartobject_optionssel_filters2Array', $filters2Array); |
|
723 | + |
|
724 | + smart_setCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
725 | + if ($this->_filtersel2 !== 'default') { |
|
726 | + $this->_criteria->add(new Criteria($this->_filtersel, $this->_filtersel2)); |
|
727 | + } |
|
728 | + } |
|
729 | + } |
|
730 | + } |
|
731 | + // Check if we have a quicksearch |
|
732 | + |
|
733 | + if (isset($_POST['quicksearch_' . $this->_id]) && $_POST['quicksearch_' . $this->_id] != '') { |
|
734 | + $quicksearch_criteria = new CriteriaCompo(); |
|
735 | + if (is_array($this->_quickSearch['fields'])) { |
|
736 | + foreach ($this->_quickSearch['fields'] as $v) { |
|
737 | + $quicksearch_criteria->add(new Criteria($v, '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE'), 'OR'); |
|
738 | + } |
|
739 | + } else { |
|
740 | + $quicksearch_criteria->add(new Criteria($this->_quickSearch['fields'], '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE')); |
|
741 | + } |
|
742 | + $this->_criteria->add($quicksearch_criteria); |
|
743 | + } |
|
744 | + |
|
745 | + $this->_objects = $this->fetchObjects($debug); |
|
746 | + |
|
747 | + include_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
|
748 | + if ($this->_criteria->getLimit() > 0) { |
|
749 | + |
|
750 | + /** |
|
751 | + * Geeting rid of the old params |
|
752 | + * $new_get_array is an array containing the new GET parameters |
|
753 | + */ |
|
754 | + $new_get_array = array(); |
|
755 | + |
|
756 | + /** |
|
757 | + * $params_of_the_options_sel is an array with all the parameters of the page |
|
758 | + * but without the pagenave parameters. This array will be used in the |
|
759 | + * OptionsSelection |
|
760 | + */ |
|
761 | + $params_of_the_options_sel = array(); |
|
762 | + |
|
763 | + $not_needed_params = array('sortsel', 'limitsel', 'ordersel', 'start' . $this->_objectHandler->keyName); |
|
764 | + foreach ($_GET as $k => $v) { |
|
765 | + if (!in_array($k, $not_needed_params)) { |
|
766 | + $new_get_array[] = "$k=$v"; |
|
767 | + $params_of_the_options_sel[] = "$k=$v"; |
|
768 | + } |
|
769 | + } |
|
770 | + |
|
771 | + /** |
|
772 | + * Adding the new params of the pagenav |
|
773 | + */ |
|
774 | + $new_get_array[] = 'sortsel=' . $this->_sortsel; |
|
775 | + $new_get_array[] = 'ordersel=' . $this->_ordersel; |
|
776 | + $new_get_array[] = 'limitsel=' . $this->_limitsel; |
|
777 | + $otherParams = implode('&', $new_get_array); |
|
778 | + |
|
779 | + $pagenav = |
|
780 | + new XoopsPageNav($this->_objectHandler->getCount($this->_criteria), $this->_criteria->getLimit(), $this->_criteria->getStart(), 'start' . $this->_objectHandler->keyName, $otherParams); |
|
781 | + $this->_tpl->assign('smartobject_pagenav', $pagenav->renderNav()); |
|
782 | + } |
|
783 | + $this->renderOptionSelection($limitsArray, $params_of_the_options_sel); |
|
784 | + |
|
785 | + // retreive the current url and the query string |
|
786 | + $current_urls = smart_getCurrentUrls(); |
|
787 | + $current_url = $current_urls['full_phpself']; |
|
788 | + $query_string = $current_urls['querystring']; |
|
789 | + if ($query_string) { |
|
790 | + $query_string = str_replace('?', '', $query_string); |
|
791 | + } |
|
792 | + $query_stringArray = explode('&', $query_string); |
|
793 | + $new_query_stringArray = array(); |
|
794 | + foreach ($query_stringArray as $query_string) { |
|
795 | + if (strpos($query_string, 'sortsel') == false && strpos($query_string, 'ordersel') == false) { |
|
796 | + $new_query_stringArray[] = $query_string; |
|
797 | + } |
|
798 | + } |
|
799 | + $new_query_string = implode('&', $new_query_stringArray); |
|
800 | + |
|
801 | + $orderArray = array(); |
|
802 | + $orderArray['ASC']['image'] = 'desc.png'; |
|
803 | + $orderArray['ASC']['neworder'] = 'DESC'; |
|
804 | + $orderArray['DESC']['image'] = 'asc.png'; |
|
805 | + $orderArray['DESC']['neworder'] = 'ASC'; |
|
806 | + |
|
807 | + $aColumns = array(); |
|
808 | + |
|
809 | + foreach ($this->_columns as $column) { |
|
810 | + $qs_param = ''; |
|
811 | + $aColumn = array(); |
|
812 | + $aColumn['width'] = $column->getWidth(); |
|
813 | + $aColumn['align'] = $column->getAlign(); |
|
814 | + $aColumn['key'] = $column->getKeyName(); |
|
815 | + if ($column->_keyname === 'checked') { |
|
816 | + $aColumn['caption'] = '<input type ="checkbox" id="checkall_smartobjects" name="checkall_smartobjects"' |
|
817 | + . ' value="checkall_smartobjects" onclick="smartobject_checkall(window.document.form_' |
|
818 | + . $this->_id |
|
819 | + . ', \'selected_smartobjects\');" />'; |
|
820 | + } elseif ($column->getCustomCaption()) { |
|
821 | + $aColumn['caption'] = $column->getCustomCaption(); |
|
822 | + } else { |
|
823 | + $aColumn['caption'] = isset($this->_tempObject->vars[$column->getKeyName()]['form_caption']) ? $this->_tempObject->vars[$column->getKeyName()]['form_caption'] : $column->getKeyName(); |
|
824 | + } |
|
825 | + // Are we doing a GET sort on this column ? |
|
826 | + $getSort = (isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) && $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] == $column->getKeyName()) |
|
827 | + || ($this->_sortsel == $column->getKeyName()); |
|
828 | + $order = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : 'DESC'; |
|
829 | + |
|
830 | + if (isset($_REQUEST['quicksearch_' . $this->_id]) && $_REQUEST['quicksearch_' . $this->_id] != '') { |
|
831 | + $qs_param = '&quicksearch_' . $this->_id . '=' . $_REQUEST['quicksearch_' . $this->_id]; |
|
832 | + } |
|
833 | + if (!$this->_enableColumnsSorting || $column->_keyname === 'checked' || !$column->isSortable()) { |
|
834 | + $aColumn['caption'] = $aColumn['caption']; |
|
835 | + } elseif ($getSort) { |
|
836 | + $aColumn['caption'] = '<a href="' |
|
837 | + . $current_url |
|
838 | + . '?' |
|
839 | + . $this->_objectHandler->_itemname |
|
840 | + . '_' |
|
841 | + . 'sortsel=' |
|
842 | + . $column->getKeyName() |
|
843 | + . '&' |
|
844 | + . $this->_objectHandler->_itemname |
|
845 | + . '_' |
|
846 | + . 'ordersel=' |
|
847 | + . $orderArray[$order]['neworder'] |
|
848 | + . $qs_param |
|
849 | + . '&' |
|
850 | + . $new_query_string |
|
851 | + . '">' |
|
852 | + . $aColumn['caption'] |
|
853 | + . ' <img src="' |
|
854 | + . SMARTOBJECT_IMAGES_ACTIONS_URL |
|
855 | + . $orderArray[$order]['image'] |
|
856 | + . '" alt="ASC" /></a>'; |
|
857 | + } else { |
|
858 | + $aColumn['caption'] = '<a href="' |
|
859 | + . $current_url |
|
860 | + . '?' |
|
861 | + . $this->_objectHandler->_itemname |
|
862 | + . '_' |
|
863 | + . 'sortsel=' |
|
864 | + . $column->getKeyName() |
|
865 | + . '&' |
|
866 | + . $this->_objectHandler->_itemname |
|
867 | + . '_' |
|
868 | + . 'ordersel=ASC' |
|
869 | + . $qs_param |
|
870 | + . '&' |
|
871 | + . $new_query_string |
|
872 | + . '">' |
|
873 | + . $aColumn['caption'] |
|
874 | + . '</a>'; |
|
875 | + } |
|
876 | + $aColumns[] = $aColumn; |
|
877 | + } |
|
878 | + $this->_tpl->assign('smartobject_columns', $aColumns); |
|
879 | + |
|
880 | + if ($this->_quickSearch) { |
|
881 | + $this->_tpl->assign('smartobject_quicksearch', $this->_quickSearch['caption']); |
|
882 | + } |
|
883 | + |
|
884 | + $this->createTableRows(); |
|
885 | + |
|
886 | + $this->_tpl->assign('smartobject_showFilterAndLimit', $this->_showFilterAndLimit); |
|
887 | + $this->_tpl->assign('smartobject_isTree', $this->_isTree); |
|
888 | + $this->_tpl->assign('smartobject_show_action_column_title', $this->_showActionsColumnTitle); |
|
889 | + $this->_tpl->assign('smartobject_table_header', $this->_tableHeader); |
|
890 | + $this->_tpl->assign('smartobject_table_footer', $this->_tableFooter); |
|
891 | + $this->_tpl->assign('smartobject_printer_friendly_page', $this->_printerFriendlyPage); |
|
892 | + $this->_tpl->assign('smartobject_user_side', $this->_userSide); |
|
893 | + $this->_tpl->assign('smartobject_has_actions', $this->_hasActions); |
|
894 | + $this->_tpl->assign('smartobject_head_css_class', $this->_head_css_class); |
|
895 | + $this->_tpl->assign('smartobject_actionButtons', $this->_actionButtons); |
|
896 | + $this->_tpl->assign('smartobject_introButtons', $this->_introButtons); |
|
897 | + $this->_tpl->assign('smartobject_id', $this->_id); |
|
898 | + if (!empty($this->_withSelectedActions)) { |
|
899 | + $this->_tpl->assign('smartobject_withSelectedActions', $this->_withSelectedActions); |
|
900 | + } |
|
901 | + |
|
902 | + $smartobjectTable_template = $this->_customTemplate ?: 'smartobject_smarttable_display.tpl'; |
|
903 | + if ($fetchOnly) { |
|
904 | + return $this->_tpl->fetch('db:' . $smartobjectTable_template); |
|
905 | + } else { |
|
906 | + $this->_tpl->display('db:' . $smartobjectTable_template); |
|
907 | + } |
|
908 | + } |
|
909 | + |
|
910 | + public function disableColumnsSorting() |
|
911 | + { |
|
912 | + $this->_enableColumnsSorting = false; |
|
913 | + } |
|
914 | + |
|
915 | + /** |
|
916 | + * @param bool $debug |
|
917 | + * @return mixed|string|void |
|
918 | + */ |
|
919 | + public function fetch($debug = false) |
|
920 | + { |
|
921 | + return $this->render(true, $debug); |
|
922 | + } |
|
923 | 923 | } |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | */ |
175 | 175 | public function addActionButton($op, $caption = false, $text = false) |
176 | 176 | { |
177 | - $action = array( |
|
177 | + $action = array( |
|
178 | 178 | 'op' => $op, |
179 | 179 | 'caption' => $caption, |
180 | 180 | 'text' => $text |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | { |
210 | 210 | $current_urls = smart_getCurrentUrls(); |
211 | 211 | $current_url = $current_urls['full']; |
212 | - $this->_printerFriendlyPage = $current_url . '&print'; |
|
212 | + $this->_printerFriendlyPage = $current_url.'&print'; |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | /** |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | */ |
243 | 243 | public function addDefaultIntroButton($caption) |
244 | 244 | { |
245 | - $this->addIntroButton($this->_objectHandler->_itemname, $this->_objectHandler->_page . '?op=mod', $caption); |
|
245 | + $this->addIntroButton($this->_objectHandler->_itemname, $this->_objectHandler->_page.'?op=mod', $caption); |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | /** |
@@ -267,9 +267,9 @@ discard block |
||
267 | 267 | public function getDefaultSort() |
268 | 268 | { |
269 | 269 | if ($this->_sortsel) { |
270 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
270 | + return smart_getCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_sortsel', $this->_sortsel); |
|
271 | 271 | } else { |
272 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_objectHandler->identifierName); |
|
272 | + return smart_getCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_sortsel', $this->_objectHandler->identifierName); |
|
273 | 273 | } |
274 | 274 | } |
275 | 275 | |
@@ -287,9 +287,9 @@ discard block |
||
287 | 287 | public function getDefaultOrder() |
288 | 288 | { |
289 | 289 | if ($this->_ordersel) { |
290 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
290 | + return smart_getCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_ordersel', $this->_ordersel); |
|
291 | 291 | } else { |
292 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', 'ASC'); |
|
292 | + return smart_getCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_ordersel', 'ASC'); |
|
293 | 293 | } |
294 | 294 | } |
295 | 295 | |
@@ -338,20 +338,20 @@ discard block |
||
338 | 338 | |
339 | 339 | public function setSortOrder() |
340 | 340 | { |
341 | - $this->_sortsel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] : $this->getDefaultSort(); |
|
341 | + $this->_sortsel = isset($_GET[$this->_objectHandler->_itemname.'_'.'sortsel']) ? $_GET[$this->_objectHandler->_itemname.'_'.'sortsel'] : $this->getDefaultSort(); |
|
342 | 342 | //$this->_sortsel = isset($_POST['sortsel']) ? $_POST['sortsel']: $this->_sortsel; |
343 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
343 | + smart_setCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_sortsel', $this->_sortsel); |
|
344 | 344 | $fieldsForSorting = $this->_tempObject->getFieldsForSorting($this->_sortsel); |
345 | 345 | |
346 | 346 | if (isset($this->_tempObject->vars[$this->_sortsel]['itemName']) && $this->_tempObject->vars[$this->_sortsel]['itemName']) { |
347 | - $this->_criteria->setSort($this->_tempObject->vars[$this->_sortsel]['itemName'] . '.' . $this->_sortsel); |
|
347 | + $this->_criteria->setSort($this->_tempObject->vars[$this->_sortsel]['itemName'].'.'.$this->_sortsel); |
|
348 | 348 | } else { |
349 | - $this->_criteria->setSort($this->_objectHandler->_itemname . '.' . $this->_sortsel); |
|
349 | + $this->_criteria->setSort($this->_objectHandler->_itemname.'.'.$this->_sortsel); |
|
350 | 350 | } |
351 | 351 | |
352 | - $this->_ordersel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : $this->getDefaultOrder(); |
|
352 | + $this->_ordersel = isset($_GET[$this->_objectHandler->_itemname.'_'.'ordersel']) ? $_GET[$this->_objectHandler->_itemname.'_'.'ordersel'] : $this->getDefaultOrder(); |
|
353 | 353 | //$this->_ordersel = isset($_POST['ordersel']) ? $_POST['ordersel']:$this->_ordersel; |
354 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
354 | + smart_setCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_ordersel', $this->_ordersel); |
|
355 | 355 | $ordersArray = $this->getOrdersArray(); |
356 | 356 | $this->_criteria->setOrder($this->_ordersel); |
357 | 357 | } |
@@ -401,7 +401,7 @@ discard block |
||
401 | 401 | //$object->initiateCustomFields(); |
402 | 402 | } |
403 | 403 | if ($column->_keyname === 'checked') { |
404 | - $value = '<input type ="checkbox" name="selected_smartobjects[]" value="' . $object->id() . '" />'; |
|
404 | + $value = '<input type ="checkbox" name="selected_smartobjects[]" value="'.$object->id().'" />'; |
|
405 | 405 | } elseif ($column->_customMethodForValue && method_exists($object, $column->_customMethodForValue)) { |
406 | 406 | $method = $column->_customMethodForValue; |
407 | 407 | if ($column->_param) { |
@@ -445,7 +445,7 @@ discard block |
||
445 | 445 | } |
446 | 446 | } |
447 | 447 | |
448 | - include_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
|
448 | + include_once SMARTOBJECT_ROOT_PATH.'class/smartobjectcontroller.php'; |
|
449 | 449 | $controller = new SmartObjectController($this->_objectHandler); |
450 | 450 | |
451 | 451 | if ((!is_array($this->_actions)) || in_array('edit', $this->_actions)) { |
@@ -485,9 +485,9 @@ discard block |
||
485 | 485 | public function getDefaultFilter() |
486 | 486 | { |
487 | 487 | if ($this->_filtersel) { |
488 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
488 | + return smart_getCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_filtersel', $this->_filtersel); |
|
489 | 489 | } else { |
490 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', 'default'); |
|
490 | + return smart_getCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_filtersel', 'default'); |
|
491 | 491 | } |
492 | 492 | } |
493 | 493 | |
@@ -537,9 +537,9 @@ discard block |
||
537 | 537 | public function getDefaultFilter2() |
538 | 538 | { |
539 | 539 | if ($this->_filtersel2) { |
540 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
540 | + return smart_getCookieVar($_SERVER['PHP_SELF'].'_filtersel2', $this->_filtersel2); |
|
541 | 541 | } else { |
542 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', 'default'); |
|
542 | + return smart_getCookieVar($_SERVER['PHP_SELF'].'_filtersel2', 'default'); |
|
543 | 543 | } |
544 | 544 | } |
545 | 545 | |
@@ -667,7 +667,7 @@ discard block |
||
667 | 667 | */ |
668 | 668 | public function render($fetchOnly = false, $debug = false) |
669 | 669 | { |
670 | - include_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
670 | + include_once XOOPS_ROOT_PATH.'/class/template.php'; |
|
671 | 671 | |
672 | 672 | $this->_tpl = new XoopsTpl(); |
673 | 673 | |
@@ -678,24 +678,24 @@ discard block |
||
678 | 678 | */ |
679 | 679 | $this->_tempObject = $this->_objectHandler->create(); |
680 | 680 | |
681 | - $this->_criteria->setStart(isset($_GET['start' . $this->_objectHandler->keyName]) ? (int)$_GET['start' . $this->_objectHandler->keyName] : 0); |
|
681 | + $this->_criteria->setStart(isset($_GET['start'.$this->_objectHandler->keyName]) ? (int) $_GET['start'.$this->_objectHandler->keyName] : 0); |
|
682 | 682 | |
683 | 683 | $this->setSortOrder(); |
684 | 684 | |
685 | 685 | if (!$this->_isTree) { |
686 | - $this->_limitsel = isset($_GET['limitsel']) ? $_GET['limitsel'] : smart_getCookieVar($_SERVER['PHP_SELF'] . '_limitsel', '15'); |
|
686 | + $this->_limitsel = isset($_GET['limitsel']) ? $_GET['limitsel'] : smart_getCookieVar($_SERVER['PHP_SELF'].'_limitsel', '15'); |
|
687 | 687 | } else { |
688 | 688 | $this->_limitsel = 'all'; |
689 | 689 | } |
690 | 690 | |
691 | 691 | $this->_limitsel = isset($_POST['limitsel']) ? $_POST['limitsel'] : $this->_limitsel; |
692 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_limitsel', $this->_limitsel); |
|
692 | + smart_setCookieVar($_SERVER['PHP_SELF'].'_limitsel', $this->_limitsel); |
|
693 | 693 | $limitsArray = $this->getLimitsArray(); |
694 | 694 | $this->_criteria->setLimit($this->_limitsel); |
695 | 695 | |
696 | 696 | $this->_filtersel = isset($_GET['filtersel']) ? $_GET['filtersel'] : $this->getDefaultFilter(); |
697 | 697 | $this->_filtersel = isset($_POST['filtersel']) ? $_POST['filtersel'] : $this->_filtersel; |
698 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
698 | + smart_setCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_filtersel', $this->_filtersel); |
|
699 | 699 | $filtersArray = $this->getFiltersArray(); |
700 | 700 | |
701 | 701 | if ($filtersArray) { |
@@ -721,7 +721,7 @@ discard block |
||
721 | 721 | $filters2Array = $this->getFilters2Array(); |
722 | 722 | $this->_tpl->assign('smartobject_optionssel_filters2Array', $filters2Array); |
723 | 723 | |
724 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
724 | + smart_setCookieVar($_SERVER['PHP_SELF'].'_filtersel2', $this->_filtersel2); |
|
725 | 725 | if ($this->_filtersel2 !== 'default') { |
726 | 726 | $this->_criteria->add(new Criteria($this->_filtersel, $this->_filtersel2)); |
727 | 727 | } |
@@ -730,21 +730,21 @@ discard block |
||
730 | 730 | } |
731 | 731 | // Check if we have a quicksearch |
732 | 732 | |
733 | - if (isset($_POST['quicksearch_' . $this->_id]) && $_POST['quicksearch_' . $this->_id] != '') { |
|
733 | + if (isset($_POST['quicksearch_'.$this->_id]) && $_POST['quicksearch_'.$this->_id] != '') { |
|
734 | 734 | $quicksearch_criteria = new CriteriaCompo(); |
735 | 735 | if (is_array($this->_quickSearch['fields'])) { |
736 | 736 | foreach ($this->_quickSearch['fields'] as $v) { |
737 | - $quicksearch_criteria->add(new Criteria($v, '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE'), 'OR'); |
|
737 | + $quicksearch_criteria->add(new Criteria($v, '%'.$_POST['quicksearch_'.$this->_id].'%', 'LIKE'), 'OR'); |
|
738 | 738 | } |
739 | 739 | } else { |
740 | - $quicksearch_criteria->add(new Criteria($this->_quickSearch['fields'], '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE')); |
|
740 | + $quicksearch_criteria->add(new Criteria($this->_quickSearch['fields'], '%'.$_POST['quicksearch_'.$this->_id].'%', 'LIKE')); |
|
741 | 741 | } |
742 | 742 | $this->_criteria->add($quicksearch_criteria); |
743 | 743 | } |
744 | 744 | |
745 | 745 | $this->_objects = $this->fetchObjects($debug); |
746 | 746 | |
747 | - include_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
|
747 | + include_once XOOPS_ROOT_PATH.'/class/pagenav.php'; |
|
748 | 748 | if ($this->_criteria->getLimit() > 0) { |
749 | 749 | |
750 | 750 | /** |
@@ -760,7 +760,7 @@ discard block |
||
760 | 760 | */ |
761 | 761 | $params_of_the_options_sel = array(); |
762 | 762 | |
763 | - $not_needed_params = array('sortsel', 'limitsel', 'ordersel', 'start' . $this->_objectHandler->keyName); |
|
763 | + $not_needed_params = array('sortsel', 'limitsel', 'ordersel', 'start'.$this->_objectHandler->keyName); |
|
764 | 764 | foreach ($_GET as $k => $v) { |
765 | 765 | if (!in_array($k, $not_needed_params)) { |
766 | 766 | $new_get_array[] = "$k=$v"; |
@@ -771,13 +771,13 @@ discard block |
||
771 | 771 | /** |
772 | 772 | * Adding the new params of the pagenav |
773 | 773 | */ |
774 | - $new_get_array[] = 'sortsel=' . $this->_sortsel; |
|
775 | - $new_get_array[] = 'ordersel=' . $this->_ordersel; |
|
776 | - $new_get_array[] = 'limitsel=' . $this->_limitsel; |
|
774 | + $new_get_array[] = 'sortsel='.$this->_sortsel; |
|
775 | + $new_get_array[] = 'ordersel='.$this->_ordersel; |
|
776 | + $new_get_array[] = 'limitsel='.$this->_limitsel; |
|
777 | 777 | $otherParams = implode('&', $new_get_array); |
778 | 778 | |
779 | 779 | $pagenav = |
780 | - new XoopsPageNav($this->_objectHandler->getCount($this->_criteria), $this->_criteria->getLimit(), $this->_criteria->getStart(), 'start' . $this->_objectHandler->keyName, $otherParams); |
|
780 | + new XoopsPageNav($this->_objectHandler->getCount($this->_criteria), $this->_criteria->getLimit(), $this->_criteria->getStart(), 'start'.$this->_objectHandler->keyName, $otherParams); |
|
781 | 781 | $this->_tpl->assign('smartobject_pagenav', $pagenav->renderNav()); |
782 | 782 | } |
783 | 783 | $this->renderOptionSelection($limitsArray, $params_of_the_options_sel); |
@@ -823,12 +823,12 @@ discard block |
||
823 | 823 | $aColumn['caption'] = isset($this->_tempObject->vars[$column->getKeyName()]['form_caption']) ? $this->_tempObject->vars[$column->getKeyName()]['form_caption'] : $column->getKeyName(); |
824 | 824 | } |
825 | 825 | // Are we doing a GET sort on this column ? |
826 | - $getSort = (isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) && $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] == $column->getKeyName()) |
|
826 | + $getSort = (isset($_GET[$this->_objectHandler->_itemname.'_'.'sortsel']) && $_GET[$this->_objectHandler->_itemname.'_'.'sortsel'] == $column->getKeyName()) |
|
827 | 827 | || ($this->_sortsel == $column->getKeyName()); |
828 | - $order = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : 'DESC'; |
|
828 | + $order = isset($_GET[$this->_objectHandler->_itemname.'_'.'ordersel']) ? $_GET[$this->_objectHandler->_itemname.'_'.'ordersel'] : 'DESC'; |
|
829 | 829 | |
830 | - if (isset($_REQUEST['quicksearch_' . $this->_id]) && $_REQUEST['quicksearch_' . $this->_id] != '') { |
|
831 | - $qs_param = '&quicksearch_' . $this->_id . '=' . $_REQUEST['quicksearch_' . $this->_id]; |
|
830 | + if (isset($_REQUEST['quicksearch_'.$this->_id]) && $_REQUEST['quicksearch_'.$this->_id] != '') { |
|
831 | + $qs_param = '&quicksearch_'.$this->_id.'='.$_REQUEST['quicksearch_'.$this->_id]; |
|
832 | 832 | } |
833 | 833 | if (!$this->_enableColumnsSorting || $column->_keyname === 'checked' || !$column->isSortable()) { |
834 | 834 | $aColumn['caption'] = $aColumn['caption']; |
@@ -901,9 +901,9 @@ discard block |
||
901 | 901 | |
902 | 902 | $smartobjectTable_template = $this->_customTemplate ?: 'smartobject_smarttable_display.tpl'; |
903 | 903 | if ($fetchOnly) { |
904 | - return $this->_tpl->fetch('db:' . $smartobjectTable_template); |
|
904 | + return $this->_tpl->fetch('db:'.$smartobjectTable_template); |
|
905 | 905 | } else { |
906 | - $this->_tpl->display('db:' . $smartobjectTable_template); |
|
906 | + $this->_tpl->display('db:'.$smartobjectTable_template); |
|
907 | 907 | } |
908 | 908 | } |
909 | 909 |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | } |
190 | 190 | |
191 | 191 | /** |
192 | - * @param $name |
|
192 | + * @param string $name |
|
193 | 193 | * @param string $extension |
194 | 194 | * @return array |
195 | 195 | */ |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | /** |
256 | 256 | * Return random background |
257 | 257 | * |
258 | - * @return array |
|
258 | + * @return string|null |
|
259 | 259 | */ |
260 | 260 | public function loadBackground() |
261 | 261 | { |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | $xoopsLogger->activated = false; |
11 | 11 | |
12 | 12 | if (empty($_SERVER['HTTP_REFERER']) || !preg_match('/^' . preg_quote(XOOPS_URL, '/') . '/', $_SERVER['HTTP_REFERER'])) { |
13 | - exit(); |
|
13 | + exit(); |
|
14 | 14 | } |
15 | 15 | |
16 | 16 | /** |
@@ -18,185 +18,185 @@ discard block |
||
18 | 18 | */ |
19 | 19 | class XoopsCaptchaImageHandler |
20 | 20 | { |
21 | - public $config = array(); |
|
22 | - //var $mode = "gd"; // GD or bmp |
|
23 | - public $code; |
|
24 | - public $invalid = false; |
|
25 | - |
|
26 | - public $font; |
|
27 | - public $spacing; |
|
28 | - public $width; |
|
29 | - public $height; |
|
30 | - |
|
31 | - /** |
|
32 | - * XoopsCaptchaImageHandler constructor. |
|
33 | - */ |
|
34 | - public function __construct() |
|
35 | - { |
|
36 | - if (empty($_SESSION['XoopsCaptcha_name'])) { |
|
37 | - $this->invalid = true; |
|
38 | - } |
|
39 | - |
|
40 | - if (!extension_loaded('gd')) { |
|
41 | - $this->mode = 'bmp'; |
|
42 | - } else { |
|
43 | - $required_functions = array('imagecreatetruecolor', 'imagecolorallocate', 'imagefilledrectangle', 'imagejpeg', 'imagedestroy', 'imageftbbox'); |
|
44 | - foreach ($required_functions as $func) { |
|
45 | - if (!function_exists($func)) { |
|
46 | - $this->mode = 'bmp'; |
|
47 | - break; |
|
48 | - } |
|
49 | - } |
|
50 | - } |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * Loading configs from CAPTCHA class |
|
55 | - * @param array $config |
|
56 | - */ |
|
57 | - public function setConfig($config = array()) |
|
58 | - { |
|
59 | - // Loading default preferences |
|
60 | - $this->config = $config; |
|
61 | - } |
|
62 | - |
|
63 | - public function loadImage() |
|
64 | - { |
|
65 | - $this->createCode(); |
|
66 | - $this->setCode(); |
|
67 | - $this->createImage(); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Create Code |
|
72 | - */ |
|
73 | - public function createCode() |
|
74 | - { |
|
75 | - if ($this->invalid) { |
|
76 | - return; |
|
77 | - } |
|
78 | - |
|
79 | - if ($this->mode === 'bmp') { |
|
80 | - $this->config['num_chars'] = 4; |
|
81 | - $this->code = mt_rand(pow(10, $this->config['num_chars'] - 1), (int)str_pad('9', $this->config['num_chars'], '9')); |
|
82 | - } else { |
|
83 | - $this->code = substr(md5(uniqid(mt_rand(), 1)), 0, $this->config['num_chars']); |
|
84 | - if (!$this->config['casesensitive']) { |
|
85 | - $this->code = strtoupper($this->code); |
|
86 | - } |
|
87 | - } |
|
88 | - } |
|
89 | - |
|
90 | - public function setCode() |
|
91 | - { |
|
92 | - if ($this->invalid) { |
|
93 | - return; |
|
94 | - } |
|
95 | - |
|
96 | - $_SESSION['XoopsCaptcha_sessioncode'] = (string)$this->code; |
|
97 | - $maxAttempts = (int)(@$_SESSION['XoopsCaptcha_maxattempts']); |
|
98 | - |
|
99 | - // Increase the attempt records on refresh |
|
100 | - if (!empty($maxAttempts)) { |
|
101 | - $_SESSION['XoopsCaptcha_attempt_' . $_SESSION['XoopsCaptcha_name']]++; |
|
102 | - if ($_SESSION['XoopsCaptcha_attempt_' . $_SESSION['XoopsCaptcha_name']] > $maxAttempts) { |
|
103 | - $this->invalid = true; |
|
104 | - } |
|
105 | - } |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * @param string $file |
|
110 | - * @return string|void |
|
111 | - */ |
|
112 | - public function createImage($file = '') |
|
113 | - { |
|
114 | - if ($this->invalid) { |
|
115 | - header('Content-type: image/gif'); |
|
116 | - readfile(XOOPS_ROOT_PATH . '/images/subject/icon2.gif'); |
|
117 | - |
|
118 | - return; |
|
119 | - } |
|
120 | - |
|
121 | - if ($this->mode === 'bmp') { |
|
122 | - return $this->createImageBmp(); |
|
123 | - } else { |
|
124 | - return $this->createImageGd(); |
|
125 | - } |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * Create CAPTCHA iamge with GD |
|
130 | - * Originated from DuGris' SecurityImage |
|
131 | - * @param string $file |
|
132 | - */ |
|
133 | - // --------------------------------------------------------------------------- // |
|
134 | - // Class: SecurityImage 1.5 // |
|
135 | - // Author: DuGris aka L. Jen <http://www.dugris.info> // |
|
136 | - // Email: [email protected] // |
|
137 | - // Licence: GNU // |
|
138 | - // Project: XOOPS Project // |
|
139 | - // --------------------------------------------------------------------------- // |
|
140 | - public function createImageGd($file = '') |
|
141 | - { |
|
142 | - $this->loadFont(); |
|
143 | - $this->setImageSize(); |
|
144 | - |
|
145 | - $this->oImage = imagecreatetruecolor($this->width, $this->height); |
|
146 | - $background = imagecolorallocate($this->oImage, 255, 255, 255); |
|
147 | - imagefilledrectangle($this->oImage, 0, 0, $this->width, $this->height, $background); |
|
148 | - |
|
149 | - switch ($this->config['background_type']) { |
|
150 | - default: |
|
151 | - case 0: |
|
152 | - $this->drawBars(); |
|
153 | - break; |
|
154 | - |
|
155 | - case 1: |
|
156 | - $this->drawCircles(); |
|
157 | - break; |
|
158 | - |
|
159 | - case 2: |
|
160 | - $this->drawLines(); |
|
161 | - break; |
|
162 | - |
|
163 | - case 3: |
|
164 | - $this->drawRectangles(); |
|
165 | - break; |
|
166 | - |
|
167 | - case 4: |
|
168 | - $this->drawEllipses(); |
|
169 | - break; |
|
170 | - |
|
171 | - case 5: |
|
172 | - $this->drawPolygons(); |
|
173 | - break; |
|
174 | - |
|
175 | - case 100: |
|
176 | - $this->createFromFile(); |
|
177 | - break; |
|
178 | - } |
|
179 | - $this->drawBorder(); |
|
180 | - $this->drawCode(); |
|
181 | - |
|
182 | - if (empty($file)) { |
|
183 | - header('Content-type: image/jpeg'); |
|
184 | - imagejpeg($this->oImage); |
|
185 | - } else { |
|
186 | - imagejpeg($this->oImage, XOOPS_ROOT_PATH . '/' . $this->config['imagepath'] . '/' . $file . '.jpg'); |
|
187 | - } |
|
188 | - imagedestroy($this->oImage); |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * @param $name |
|
193 | - * @param string $extension |
|
194 | - * @return array |
|
195 | - */ |
|
196 | - public function _getList($name, $extension = '') |
|
197 | - { |
|
198 | - $items = array(); |
|
199 | - /* |
|
21 | + public $config = array(); |
|
22 | + //var $mode = "gd"; // GD or bmp |
|
23 | + public $code; |
|
24 | + public $invalid = false; |
|
25 | + |
|
26 | + public $font; |
|
27 | + public $spacing; |
|
28 | + public $width; |
|
29 | + public $height; |
|
30 | + |
|
31 | + /** |
|
32 | + * XoopsCaptchaImageHandler constructor. |
|
33 | + */ |
|
34 | + public function __construct() |
|
35 | + { |
|
36 | + if (empty($_SESSION['XoopsCaptcha_name'])) { |
|
37 | + $this->invalid = true; |
|
38 | + } |
|
39 | + |
|
40 | + if (!extension_loaded('gd')) { |
|
41 | + $this->mode = 'bmp'; |
|
42 | + } else { |
|
43 | + $required_functions = array('imagecreatetruecolor', 'imagecolorallocate', 'imagefilledrectangle', 'imagejpeg', 'imagedestroy', 'imageftbbox'); |
|
44 | + foreach ($required_functions as $func) { |
|
45 | + if (!function_exists($func)) { |
|
46 | + $this->mode = 'bmp'; |
|
47 | + break; |
|
48 | + } |
|
49 | + } |
|
50 | + } |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * Loading configs from CAPTCHA class |
|
55 | + * @param array $config |
|
56 | + */ |
|
57 | + public function setConfig($config = array()) |
|
58 | + { |
|
59 | + // Loading default preferences |
|
60 | + $this->config = $config; |
|
61 | + } |
|
62 | + |
|
63 | + public function loadImage() |
|
64 | + { |
|
65 | + $this->createCode(); |
|
66 | + $this->setCode(); |
|
67 | + $this->createImage(); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Create Code |
|
72 | + */ |
|
73 | + public function createCode() |
|
74 | + { |
|
75 | + if ($this->invalid) { |
|
76 | + return; |
|
77 | + } |
|
78 | + |
|
79 | + if ($this->mode === 'bmp') { |
|
80 | + $this->config['num_chars'] = 4; |
|
81 | + $this->code = mt_rand(pow(10, $this->config['num_chars'] - 1), (int)str_pad('9', $this->config['num_chars'], '9')); |
|
82 | + } else { |
|
83 | + $this->code = substr(md5(uniqid(mt_rand(), 1)), 0, $this->config['num_chars']); |
|
84 | + if (!$this->config['casesensitive']) { |
|
85 | + $this->code = strtoupper($this->code); |
|
86 | + } |
|
87 | + } |
|
88 | + } |
|
89 | + |
|
90 | + public function setCode() |
|
91 | + { |
|
92 | + if ($this->invalid) { |
|
93 | + return; |
|
94 | + } |
|
95 | + |
|
96 | + $_SESSION['XoopsCaptcha_sessioncode'] = (string)$this->code; |
|
97 | + $maxAttempts = (int)(@$_SESSION['XoopsCaptcha_maxattempts']); |
|
98 | + |
|
99 | + // Increase the attempt records on refresh |
|
100 | + if (!empty($maxAttempts)) { |
|
101 | + $_SESSION['XoopsCaptcha_attempt_' . $_SESSION['XoopsCaptcha_name']]++; |
|
102 | + if ($_SESSION['XoopsCaptcha_attempt_' . $_SESSION['XoopsCaptcha_name']] > $maxAttempts) { |
|
103 | + $this->invalid = true; |
|
104 | + } |
|
105 | + } |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * @param string $file |
|
110 | + * @return string|void |
|
111 | + */ |
|
112 | + public function createImage($file = '') |
|
113 | + { |
|
114 | + if ($this->invalid) { |
|
115 | + header('Content-type: image/gif'); |
|
116 | + readfile(XOOPS_ROOT_PATH . '/images/subject/icon2.gif'); |
|
117 | + |
|
118 | + return; |
|
119 | + } |
|
120 | + |
|
121 | + if ($this->mode === 'bmp') { |
|
122 | + return $this->createImageBmp(); |
|
123 | + } else { |
|
124 | + return $this->createImageGd(); |
|
125 | + } |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * Create CAPTCHA iamge with GD |
|
130 | + * Originated from DuGris' SecurityImage |
|
131 | + * @param string $file |
|
132 | + */ |
|
133 | + // --------------------------------------------------------------------------- // |
|
134 | + // Class: SecurityImage 1.5 // |
|
135 | + // Author: DuGris aka L. Jen <http://www.dugris.info> // |
|
136 | + // Email: [email protected] // |
|
137 | + // Licence: GNU // |
|
138 | + // Project: XOOPS Project // |
|
139 | + // --------------------------------------------------------------------------- // |
|
140 | + public function createImageGd($file = '') |
|
141 | + { |
|
142 | + $this->loadFont(); |
|
143 | + $this->setImageSize(); |
|
144 | + |
|
145 | + $this->oImage = imagecreatetruecolor($this->width, $this->height); |
|
146 | + $background = imagecolorallocate($this->oImage, 255, 255, 255); |
|
147 | + imagefilledrectangle($this->oImage, 0, 0, $this->width, $this->height, $background); |
|
148 | + |
|
149 | + switch ($this->config['background_type']) { |
|
150 | + default: |
|
151 | + case 0: |
|
152 | + $this->drawBars(); |
|
153 | + break; |
|
154 | + |
|
155 | + case 1: |
|
156 | + $this->drawCircles(); |
|
157 | + break; |
|
158 | + |
|
159 | + case 2: |
|
160 | + $this->drawLines(); |
|
161 | + break; |
|
162 | + |
|
163 | + case 3: |
|
164 | + $this->drawRectangles(); |
|
165 | + break; |
|
166 | + |
|
167 | + case 4: |
|
168 | + $this->drawEllipses(); |
|
169 | + break; |
|
170 | + |
|
171 | + case 5: |
|
172 | + $this->drawPolygons(); |
|
173 | + break; |
|
174 | + |
|
175 | + case 100: |
|
176 | + $this->createFromFile(); |
|
177 | + break; |
|
178 | + } |
|
179 | + $this->drawBorder(); |
|
180 | + $this->drawCode(); |
|
181 | + |
|
182 | + if (empty($file)) { |
|
183 | + header('Content-type: image/jpeg'); |
|
184 | + imagejpeg($this->oImage); |
|
185 | + } else { |
|
186 | + imagejpeg($this->oImage, XOOPS_ROOT_PATH . '/' . $this->config['imagepath'] . '/' . $file . '.jpg'); |
|
187 | + } |
|
188 | + imagedestroy($this->oImage); |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * @param $name |
|
193 | + * @param string $extension |
|
194 | + * @return array |
|
195 | + */ |
|
196 | + public function _getList($name, $extension = '') |
|
197 | + { |
|
198 | + $items = array(); |
|
199 | + /* |
|
200 | 200 | if (@ include_once XOOPS_ROOT_PATH."/Frameworks/art/functions.ini.php") { |
201 | 201 | load_functions("cache"); |
202 | 202 | if ($items = mod_loadCacheFile("captcha_{$name}", "captcha")) { |
@@ -204,231 +204,231 @@ discard block |
||
204 | 204 | } |
205 | 205 | } |
206 | 206 | */ |
207 | - require_once XOOPS_ROOT_PATH . '/class/xoopslists.php'; |
|
208 | - $file_path = $this->config['rootpath'] . "/{$name}"; |
|
209 | - $files = XoopsLists::getFileListAsArray($file_path); |
|
210 | - foreach ($files as $item) { |
|
211 | - if (empty($extension) || preg_match("/(\.{$extension})$/i", $item)) { |
|
212 | - $items[] = $item; |
|
213 | - } |
|
214 | - } |
|
215 | - if (function_exists('mod_createCacheFile')) { |
|
216 | - mod_createCacheFile($items, "captcha_{$name}", 'captcha'); |
|
217 | - } |
|
218 | - |
|
219 | - return $items; |
|
220 | - } |
|
221 | - |
|
222 | - public function loadFont() |
|
223 | - { |
|
224 | - $fonts = $this->_getList('fonts', 'ttf'); |
|
225 | - $this->font = $this->config['rootpath'] . '/fonts/' . $fonts[array_rand($fonts)]; |
|
226 | - } |
|
227 | - |
|
228 | - public function setImageSize() |
|
229 | - { |
|
230 | - $MaxCharWidth = 0; |
|
231 | - $MaxCharHeight = 0; |
|
232 | - $oImage = imagecreatetruecolor(100, 100); |
|
233 | - $text_color = imagecolorallocate($oImage, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100)); |
|
234 | - $FontSize = $this->config['fontsize_max']; |
|
235 | - for ($Angle = -30; $Angle <= 30; ++$Angle) { |
|
236 | - for ($i = 65; $i <= 90; ++$i) { |
|
237 | - $CharDetails = imageftbbox($FontSize, $Angle, $this->font, chr($i), array()); |
|
238 | - $_MaxCharWidth = abs($CharDetails[0] + $CharDetails[2]); |
|
239 | - if ($_MaxCharWidth > $MaxCharWidth) { |
|
240 | - $MaxCharWidth = $_MaxCharWidth; |
|
241 | - } |
|
242 | - $_MaxCharHeight = abs($CharDetails[1] + $CharDetails[5]); |
|
243 | - if ($_MaxCharHeight > $MaxCharHeight) { |
|
244 | - $MaxCharHeight = $_MaxCharHeight; |
|
245 | - } |
|
246 | - } |
|
247 | - } |
|
248 | - imagedestroy($oImage); |
|
249 | - |
|
250 | - $this->height = $MaxCharHeight + 2; |
|
251 | - $this->spacing = (int)(($this->config['num_chars'] * $MaxCharWidth) / $this->config['num_chars']); |
|
252 | - $this->width = ($this->config['num_chars'] * $MaxCharWidth) + ($this->spacing / 2); |
|
253 | - } |
|
254 | - |
|
255 | - /** |
|
256 | - * Return random background |
|
257 | - * |
|
258 | - * @return array |
|
259 | - */ |
|
260 | - public function loadBackground() |
|
261 | - { |
|
262 | - $RandBackground = null; |
|
263 | - if ($backgrounds = $this->_getList('backgrounds', '(gif|jpg|png)')) { |
|
264 | - $RandBackground = $this->config['rootpath'] . '/backgrounds/' . $backgrounds[array_rand($backgrounds)]; |
|
265 | - } |
|
266 | - |
|
267 | - return $RandBackground; |
|
268 | - } |
|
269 | - |
|
270 | - /** |
|
271 | - * Draw Image background |
|
272 | - */ |
|
273 | - public function createFromFile() |
|
274 | - { |
|
275 | - if ($RandImage = $this->loadBackground()) { |
|
276 | - $ImageType = @getimagesize($RandImage); |
|
277 | - switch (@$ImageType[2]) { |
|
278 | - case 1: |
|
279 | - $BackgroundImage = imagecreatefromgif($RandImage); |
|
280 | - break; |
|
281 | - |
|
282 | - case 2: |
|
283 | - $BackgroundImage = imagecreatefromjpeg($RandImage); |
|
284 | - break; |
|
285 | - |
|
286 | - case 3: |
|
287 | - $BackgroundImage = imagecreatefrompng($RandImage); |
|
288 | - break; |
|
289 | - } |
|
290 | - } |
|
291 | - if (!empty($BackgroundImage)) { |
|
292 | - imagecopyresized($this->oImage, $BackgroundImage, 0, 0, 0, 0, imagesx($this->oImage), imagesy($this->oImage), imagesx($BackgroundImage), imagesy($BackgroundImage)); |
|
293 | - imagedestroy($BackgroundImage); |
|
294 | - } else { |
|
295 | - $this->drawBars(); |
|
296 | - } |
|
297 | - } |
|
298 | - |
|
299 | - /** |
|
300 | - * Draw Code |
|
301 | - */ |
|
302 | - public function drawCode() |
|
303 | - { |
|
304 | - for ($i = 0; $i < $this->config['num_chars']; ++$i) { |
|
305 | - // select random greyscale colour |
|
306 | - $text_color = imagecolorallocate($this->oImage, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100)); |
|
307 | - |
|
308 | - // write text to image |
|
309 | - $Angle = mt_rand(10, 30); |
|
310 | - if ($i % 2) { |
|
311 | - $Angle = mt_rand(-10, -30); |
|
312 | - } |
|
313 | - |
|
314 | - // select random font size |
|
315 | - $FontSize = mt_rand($this->config['fontsize_min'], $this->config['fontsize_max']); |
|
316 | - |
|
317 | - $CharDetails = imageftbbox($FontSize, $Angle, $this->font, $this->code[$i], array()); |
|
318 | - $CharHeight = abs($CharDetails[1] + $CharDetails[5]); |
|
319 | - |
|
320 | - // calculate character starting coordinates |
|
321 | - $posX = ($this->spacing / 2) + ($i * $this->spacing); |
|
322 | - $posY = 2 + ($this->height / 2) + ($CharHeight / 4); |
|
323 | - |
|
324 | - imagefttext($this->oImage, $FontSize, $Angle, $posX, $posY, $text_color, $this->font, $this->code[$i], array()); |
|
325 | - } |
|
326 | - } |
|
327 | - |
|
328 | - /** |
|
329 | - * Draw Border |
|
330 | - */ |
|
331 | - public function drawBorder() |
|
332 | - { |
|
333 | - $rgb = mt_rand(50, 150); |
|
334 | - $border_color = imagecolorallocate($this->oImage, $rgb, $rgb, $rgb); |
|
335 | - imagerectangle($this->oImage, 0, 0, $this->width - 1, $this->height - 1, $border_color); |
|
336 | - } |
|
337 | - |
|
338 | - /** |
|
339 | - * Draw Circles background |
|
340 | - */ |
|
341 | - public function drawCircles() |
|
342 | - { |
|
343 | - for ($i = 1; $i <= $this->config['background_num']; ++$i) { |
|
344 | - $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
345 | - imagefilledellipse($this->oImage, mt_rand(0, $this->width - 10), mt_rand(0, $this->height - 3), mt_rand(10, 20), mt_rand(20, 30), $randomcolor); |
|
346 | - } |
|
347 | - } |
|
348 | - |
|
349 | - /** |
|
350 | - * Draw Lines background |
|
351 | - */ |
|
352 | - public function drawLines() |
|
353 | - { |
|
354 | - for ($i = 0; $i < $this->config['background_num']; ++$i) { |
|
355 | - $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
356 | - imageline($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor); |
|
357 | - } |
|
358 | - } |
|
359 | - |
|
360 | - /** |
|
361 | - * Draw Rectangles background |
|
362 | - */ |
|
363 | - public function drawRectangles() |
|
364 | - { |
|
365 | - for ($i = 1; $i <= $this->config['background_num']; ++$i) { |
|
366 | - $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
367 | - imagefilledrectangle($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor); |
|
368 | - } |
|
369 | - } |
|
370 | - |
|
371 | - /** |
|
372 | - * Draw Bars background |
|
373 | - */ |
|
374 | - public function drawBars() |
|
375 | - { |
|
376 | - for ($i = 0; $i <= $this->height;) { |
|
377 | - $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
378 | - imageline($this->oImage, 0, $i, $this->width, $i, $randomcolor); |
|
379 | - $i += 2.5; |
|
380 | - } |
|
381 | - for ($i = 0; $i <= $this->width;) { |
|
382 | - $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
383 | - imageline($this->oImage, $i, 0, $i, $this->height, $randomcolor); |
|
384 | - $i += 2.5; |
|
385 | - } |
|
386 | - } |
|
387 | - |
|
388 | - /** |
|
389 | - * Draw Ellipses background |
|
390 | - */ |
|
391 | - public function drawEllipses() |
|
392 | - { |
|
393 | - for ($i = 1; $i <= $this->config['background_num']; ++$i) { |
|
394 | - $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
395 | - imageellipse($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor); |
|
396 | - } |
|
397 | - } |
|
398 | - |
|
399 | - /** |
|
400 | - * Draw polygons background |
|
401 | - */ |
|
402 | - public function drawPolygons() |
|
403 | - { |
|
404 | - for ($i = 1; $i <= $this->config['background_num']; ++$i) { |
|
405 | - $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
406 | - $coords = array(); |
|
407 | - for ($j = 1; $j <= $this->config['polygon_point']; ++$j) { |
|
408 | - $coords[] = mt_rand(0, $this->width); |
|
409 | - $coords[] = mt_rand(0, $this->height); |
|
410 | - } |
|
411 | - imagefilledpolygon($this->oImage, $coords, $this->config['polygon_point'], $randomcolor); |
|
412 | - } |
|
413 | - } |
|
414 | - |
|
415 | - /** |
|
416 | - * Create CAPTCHA iamge with BMP |
|
417 | - * TODO |
|
418 | - * @param string $file |
|
419 | - * @return string |
|
420 | - */ |
|
421 | - public function createImageBmp($file = '') |
|
422 | - { |
|
423 | - $image = ''; |
|
424 | - |
|
425 | - if (empty($file)) { |
|
426 | - header('Content-type: image/bmp'); |
|
427 | - echo $image; |
|
428 | - } else { |
|
429 | - return $image; |
|
430 | - } |
|
431 | - } |
|
207 | + require_once XOOPS_ROOT_PATH . '/class/xoopslists.php'; |
|
208 | + $file_path = $this->config['rootpath'] . "/{$name}"; |
|
209 | + $files = XoopsLists::getFileListAsArray($file_path); |
|
210 | + foreach ($files as $item) { |
|
211 | + if (empty($extension) || preg_match("/(\.{$extension})$/i", $item)) { |
|
212 | + $items[] = $item; |
|
213 | + } |
|
214 | + } |
|
215 | + if (function_exists('mod_createCacheFile')) { |
|
216 | + mod_createCacheFile($items, "captcha_{$name}", 'captcha'); |
|
217 | + } |
|
218 | + |
|
219 | + return $items; |
|
220 | + } |
|
221 | + |
|
222 | + public function loadFont() |
|
223 | + { |
|
224 | + $fonts = $this->_getList('fonts', 'ttf'); |
|
225 | + $this->font = $this->config['rootpath'] . '/fonts/' . $fonts[array_rand($fonts)]; |
|
226 | + } |
|
227 | + |
|
228 | + public function setImageSize() |
|
229 | + { |
|
230 | + $MaxCharWidth = 0; |
|
231 | + $MaxCharHeight = 0; |
|
232 | + $oImage = imagecreatetruecolor(100, 100); |
|
233 | + $text_color = imagecolorallocate($oImage, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100)); |
|
234 | + $FontSize = $this->config['fontsize_max']; |
|
235 | + for ($Angle = -30; $Angle <= 30; ++$Angle) { |
|
236 | + for ($i = 65; $i <= 90; ++$i) { |
|
237 | + $CharDetails = imageftbbox($FontSize, $Angle, $this->font, chr($i), array()); |
|
238 | + $_MaxCharWidth = abs($CharDetails[0] + $CharDetails[2]); |
|
239 | + if ($_MaxCharWidth > $MaxCharWidth) { |
|
240 | + $MaxCharWidth = $_MaxCharWidth; |
|
241 | + } |
|
242 | + $_MaxCharHeight = abs($CharDetails[1] + $CharDetails[5]); |
|
243 | + if ($_MaxCharHeight > $MaxCharHeight) { |
|
244 | + $MaxCharHeight = $_MaxCharHeight; |
|
245 | + } |
|
246 | + } |
|
247 | + } |
|
248 | + imagedestroy($oImage); |
|
249 | + |
|
250 | + $this->height = $MaxCharHeight + 2; |
|
251 | + $this->spacing = (int)(($this->config['num_chars'] * $MaxCharWidth) / $this->config['num_chars']); |
|
252 | + $this->width = ($this->config['num_chars'] * $MaxCharWidth) + ($this->spacing / 2); |
|
253 | + } |
|
254 | + |
|
255 | + /** |
|
256 | + * Return random background |
|
257 | + * |
|
258 | + * @return array |
|
259 | + */ |
|
260 | + public function loadBackground() |
|
261 | + { |
|
262 | + $RandBackground = null; |
|
263 | + if ($backgrounds = $this->_getList('backgrounds', '(gif|jpg|png)')) { |
|
264 | + $RandBackground = $this->config['rootpath'] . '/backgrounds/' . $backgrounds[array_rand($backgrounds)]; |
|
265 | + } |
|
266 | + |
|
267 | + return $RandBackground; |
|
268 | + } |
|
269 | + |
|
270 | + /** |
|
271 | + * Draw Image background |
|
272 | + */ |
|
273 | + public function createFromFile() |
|
274 | + { |
|
275 | + if ($RandImage = $this->loadBackground()) { |
|
276 | + $ImageType = @getimagesize($RandImage); |
|
277 | + switch (@$ImageType[2]) { |
|
278 | + case 1: |
|
279 | + $BackgroundImage = imagecreatefromgif($RandImage); |
|
280 | + break; |
|
281 | + |
|
282 | + case 2: |
|
283 | + $BackgroundImage = imagecreatefromjpeg($RandImage); |
|
284 | + break; |
|
285 | + |
|
286 | + case 3: |
|
287 | + $BackgroundImage = imagecreatefrompng($RandImage); |
|
288 | + break; |
|
289 | + } |
|
290 | + } |
|
291 | + if (!empty($BackgroundImage)) { |
|
292 | + imagecopyresized($this->oImage, $BackgroundImage, 0, 0, 0, 0, imagesx($this->oImage), imagesy($this->oImage), imagesx($BackgroundImage), imagesy($BackgroundImage)); |
|
293 | + imagedestroy($BackgroundImage); |
|
294 | + } else { |
|
295 | + $this->drawBars(); |
|
296 | + } |
|
297 | + } |
|
298 | + |
|
299 | + /** |
|
300 | + * Draw Code |
|
301 | + */ |
|
302 | + public function drawCode() |
|
303 | + { |
|
304 | + for ($i = 0; $i < $this->config['num_chars']; ++$i) { |
|
305 | + // select random greyscale colour |
|
306 | + $text_color = imagecolorallocate($this->oImage, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100)); |
|
307 | + |
|
308 | + // write text to image |
|
309 | + $Angle = mt_rand(10, 30); |
|
310 | + if ($i % 2) { |
|
311 | + $Angle = mt_rand(-10, -30); |
|
312 | + } |
|
313 | + |
|
314 | + // select random font size |
|
315 | + $FontSize = mt_rand($this->config['fontsize_min'], $this->config['fontsize_max']); |
|
316 | + |
|
317 | + $CharDetails = imageftbbox($FontSize, $Angle, $this->font, $this->code[$i], array()); |
|
318 | + $CharHeight = abs($CharDetails[1] + $CharDetails[5]); |
|
319 | + |
|
320 | + // calculate character starting coordinates |
|
321 | + $posX = ($this->spacing / 2) + ($i * $this->spacing); |
|
322 | + $posY = 2 + ($this->height / 2) + ($CharHeight / 4); |
|
323 | + |
|
324 | + imagefttext($this->oImage, $FontSize, $Angle, $posX, $posY, $text_color, $this->font, $this->code[$i], array()); |
|
325 | + } |
|
326 | + } |
|
327 | + |
|
328 | + /** |
|
329 | + * Draw Border |
|
330 | + */ |
|
331 | + public function drawBorder() |
|
332 | + { |
|
333 | + $rgb = mt_rand(50, 150); |
|
334 | + $border_color = imagecolorallocate($this->oImage, $rgb, $rgb, $rgb); |
|
335 | + imagerectangle($this->oImage, 0, 0, $this->width - 1, $this->height - 1, $border_color); |
|
336 | + } |
|
337 | + |
|
338 | + /** |
|
339 | + * Draw Circles background |
|
340 | + */ |
|
341 | + public function drawCircles() |
|
342 | + { |
|
343 | + for ($i = 1; $i <= $this->config['background_num']; ++$i) { |
|
344 | + $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
345 | + imagefilledellipse($this->oImage, mt_rand(0, $this->width - 10), mt_rand(0, $this->height - 3), mt_rand(10, 20), mt_rand(20, 30), $randomcolor); |
|
346 | + } |
|
347 | + } |
|
348 | + |
|
349 | + /** |
|
350 | + * Draw Lines background |
|
351 | + */ |
|
352 | + public function drawLines() |
|
353 | + { |
|
354 | + for ($i = 0; $i < $this->config['background_num']; ++$i) { |
|
355 | + $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
356 | + imageline($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor); |
|
357 | + } |
|
358 | + } |
|
359 | + |
|
360 | + /** |
|
361 | + * Draw Rectangles background |
|
362 | + */ |
|
363 | + public function drawRectangles() |
|
364 | + { |
|
365 | + for ($i = 1; $i <= $this->config['background_num']; ++$i) { |
|
366 | + $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
367 | + imagefilledrectangle($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor); |
|
368 | + } |
|
369 | + } |
|
370 | + |
|
371 | + /** |
|
372 | + * Draw Bars background |
|
373 | + */ |
|
374 | + public function drawBars() |
|
375 | + { |
|
376 | + for ($i = 0; $i <= $this->height;) { |
|
377 | + $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
378 | + imageline($this->oImage, 0, $i, $this->width, $i, $randomcolor); |
|
379 | + $i += 2.5; |
|
380 | + } |
|
381 | + for ($i = 0; $i <= $this->width;) { |
|
382 | + $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
383 | + imageline($this->oImage, $i, 0, $i, $this->height, $randomcolor); |
|
384 | + $i += 2.5; |
|
385 | + } |
|
386 | + } |
|
387 | + |
|
388 | + /** |
|
389 | + * Draw Ellipses background |
|
390 | + */ |
|
391 | + public function drawEllipses() |
|
392 | + { |
|
393 | + for ($i = 1; $i <= $this->config['background_num']; ++$i) { |
|
394 | + $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
395 | + imageellipse($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor); |
|
396 | + } |
|
397 | + } |
|
398 | + |
|
399 | + /** |
|
400 | + * Draw polygons background |
|
401 | + */ |
|
402 | + public function drawPolygons() |
|
403 | + { |
|
404 | + for ($i = 1; $i <= $this->config['background_num']; ++$i) { |
|
405 | + $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
406 | + $coords = array(); |
|
407 | + for ($j = 1; $j <= $this->config['polygon_point']; ++$j) { |
|
408 | + $coords[] = mt_rand(0, $this->width); |
|
409 | + $coords[] = mt_rand(0, $this->height); |
|
410 | + } |
|
411 | + imagefilledpolygon($this->oImage, $coords, $this->config['polygon_point'], $randomcolor); |
|
412 | + } |
|
413 | + } |
|
414 | + |
|
415 | + /** |
|
416 | + * Create CAPTCHA iamge with BMP |
|
417 | + * TODO |
|
418 | + * @param string $file |
|
419 | + * @return string |
|
420 | + */ |
|
421 | + public function createImageBmp($file = '') |
|
422 | + { |
|
423 | + $image = ''; |
|
424 | + |
|
425 | + if (empty($file)) { |
|
426 | + header('Content-type: image/bmp'); |
|
427 | + echo $image; |
|
428 | + } else { |
|
429 | + return $image; |
|
430 | + } |
|
431 | + } |
|
432 | 432 | } |
433 | 433 | |
434 | 434 | $config = @include dirname(__DIR__) . '/config.php'; |
@@ -5,11 +5,11 @@ discard block |
||
5 | 5 | * D.J. |
6 | 6 | */ |
7 | 7 | |
8 | -include dirname(dirname(dirname(dirname(dirname(__DIR__))))) . '/mainfile.php'; |
|
8 | +include dirname(dirname(dirname(dirname(dirname(__DIR__))))).'/mainfile.php'; |
|
9 | 9 | error_reporting(0); |
10 | 10 | $xoopsLogger->activated = false; |
11 | 11 | |
12 | -if (empty($_SERVER['HTTP_REFERER']) || !preg_match('/^' . preg_quote(XOOPS_URL, '/') . '/', $_SERVER['HTTP_REFERER'])) { |
|
12 | +if (empty($_SERVER['HTTP_REFERER']) || !preg_match('/^'.preg_quote(XOOPS_URL, '/').'/', $_SERVER['HTTP_REFERER'])) { |
|
13 | 13 | exit(); |
14 | 14 | } |
15 | 15 | |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | |
79 | 79 | if ($this->mode === 'bmp') { |
80 | 80 | $this->config['num_chars'] = 4; |
81 | - $this->code = mt_rand(pow(10, $this->config['num_chars'] - 1), (int)str_pad('9', $this->config['num_chars'], '9')); |
|
81 | + $this->code = mt_rand(pow(10, $this->config['num_chars'] - 1), (int) str_pad('9', $this->config['num_chars'], '9')); |
|
82 | 82 | } else { |
83 | 83 | $this->code = substr(md5(uniqid(mt_rand(), 1)), 0, $this->config['num_chars']); |
84 | 84 | if (!$this->config['casesensitive']) { |
@@ -93,13 +93,13 @@ discard block |
||
93 | 93 | return; |
94 | 94 | } |
95 | 95 | |
96 | - $_SESSION['XoopsCaptcha_sessioncode'] = (string)$this->code; |
|
97 | - $maxAttempts = (int)(@$_SESSION['XoopsCaptcha_maxattempts']); |
|
96 | + $_SESSION['XoopsCaptcha_sessioncode'] = (string) $this->code; |
|
97 | + $maxAttempts = (int) (@$_SESSION['XoopsCaptcha_maxattempts']); |
|
98 | 98 | |
99 | 99 | // Increase the attempt records on refresh |
100 | 100 | if (!empty($maxAttempts)) { |
101 | - $_SESSION['XoopsCaptcha_attempt_' . $_SESSION['XoopsCaptcha_name']]++; |
|
102 | - if ($_SESSION['XoopsCaptcha_attempt_' . $_SESSION['XoopsCaptcha_name']] > $maxAttempts) { |
|
101 | + $_SESSION['XoopsCaptcha_attempt_'.$_SESSION['XoopsCaptcha_name']]++; |
|
102 | + if ($_SESSION['XoopsCaptcha_attempt_'.$_SESSION['XoopsCaptcha_name']] > $maxAttempts) { |
|
103 | 103 | $this->invalid = true; |
104 | 104 | } |
105 | 105 | } |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | { |
114 | 114 | if ($this->invalid) { |
115 | 115 | header('Content-type: image/gif'); |
116 | - readfile(XOOPS_ROOT_PATH . '/images/subject/icon2.gif'); |
|
116 | + readfile(XOOPS_ROOT_PATH.'/images/subject/icon2.gif'); |
|
117 | 117 | |
118 | 118 | return; |
119 | 119 | } |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | header('Content-type: image/jpeg'); |
184 | 184 | imagejpeg($this->oImage); |
185 | 185 | } else { |
186 | - imagejpeg($this->oImage, XOOPS_ROOT_PATH . '/' . $this->config['imagepath'] . '/' . $file . '.jpg'); |
|
186 | + imagejpeg($this->oImage, XOOPS_ROOT_PATH.'/'.$this->config['imagepath'].'/'.$file.'.jpg'); |
|
187 | 187 | } |
188 | 188 | imagedestroy($this->oImage); |
189 | 189 | } |
@@ -204,8 +204,8 @@ discard block |
||
204 | 204 | } |
205 | 205 | } |
206 | 206 | */ |
207 | - require_once XOOPS_ROOT_PATH . '/class/xoopslists.php'; |
|
208 | - $file_path = $this->config['rootpath'] . "/{$name}"; |
|
207 | + require_once XOOPS_ROOT_PATH.'/class/xoopslists.php'; |
|
208 | + $file_path = $this->config['rootpath']."/{$name}"; |
|
209 | 209 | $files = XoopsLists::getFileListAsArray($file_path); |
210 | 210 | foreach ($files as $item) { |
211 | 211 | if (empty($extension) || preg_match("/(\.{$extension})$/i", $item)) { |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | public function loadFont() |
223 | 223 | { |
224 | 224 | $fonts = $this->_getList('fonts', 'ttf'); |
225 | - $this->font = $this->config['rootpath'] . '/fonts/' . $fonts[array_rand($fonts)]; |
|
225 | + $this->font = $this->config['rootpath'].'/fonts/'.$fonts[array_rand($fonts)]; |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | public function setImageSize() |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | imagedestroy($oImage); |
249 | 249 | |
250 | 250 | $this->height = $MaxCharHeight + 2; |
251 | - $this->spacing = (int)(($this->config['num_chars'] * $MaxCharWidth) / $this->config['num_chars']); |
|
251 | + $this->spacing = (int) (($this->config['num_chars'] * $MaxCharWidth) / $this->config['num_chars']); |
|
252 | 252 | $this->width = ($this->config['num_chars'] * $MaxCharWidth) + ($this->spacing / 2); |
253 | 253 | } |
254 | 254 | |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | { |
262 | 262 | $RandBackground = null; |
263 | 263 | if ($backgrounds = $this->_getList('backgrounds', '(gif|jpg|png)')) { |
264 | - $RandBackground = $this->config['rootpath'] . '/backgrounds/' . $backgrounds[array_rand($backgrounds)]; |
|
264 | + $RandBackground = $this->config['rootpath'].'/backgrounds/'.$backgrounds[array_rand($backgrounds)]; |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | return $RandBackground; |
@@ -431,7 +431,7 @@ discard block |
||
431 | 431 | } |
432 | 432 | } |
433 | 433 | |
434 | -$config = @include dirname(__DIR__) . '/config.php'; |
|
434 | +$config = @include dirname(__DIR__).'/config.php'; |
|
435 | 435 | $imageHandler = new XoopsCaptchaImageHandler(); |
436 | 436 | $imageHandler->setConfig($config); |
437 | 437 | $imageHandler->loadImage(); |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | |
28 | 28 | /** |
29 | 29 | * @param $javascript |
30 | - * @return mixed|string |
|
30 | + * @return string |
|
31 | 31 | */ |
32 | 32 | public function escape($javascript) |
33 | 33 | { |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | |
49 | 49 | /** |
50 | 50 | * @param $name |
51 | - * @param $function |
|
51 | + * @param string $function |
|
52 | 52 | * @param null $html_options |
53 | 53 | * @return string |
54 | 54 | */ |
@@ -15,90 +15,90 @@ |
||
15 | 15 | */ |
16 | 16 | class JavaScript |
17 | 17 | { |
18 | - /** |
|
19 | - * @param $name |
|
20 | - * @param null $function |
|
21 | - * @return string |
|
22 | - */ |
|
23 | - public function button_to_function($name, $function = null) |
|
24 | - { |
|
25 | - return '<input type="button" value="' . $name . '" onclick="' . $function . '" />'; |
|
26 | - } |
|
18 | + /** |
|
19 | + * @param $name |
|
20 | + * @param null $function |
|
21 | + * @return string |
|
22 | + */ |
|
23 | + public function button_to_function($name, $function = null) |
|
24 | + { |
|
25 | + return '<input type="button" value="' . $name . '" onclick="' . $function . '" />'; |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * @param $javascript |
|
30 | - * @return mixed|string |
|
31 | - */ |
|
32 | - public function escape($javascript) |
|
33 | - { |
|
34 | - $javascript = addslashes($javascript); |
|
35 | - $javascript = str_replace(array("\r\n", "\n", "\r"), array("\n"), $javascript); |
|
28 | + /** |
|
29 | + * @param $javascript |
|
30 | + * @return mixed|string |
|
31 | + */ |
|
32 | + public function escape($javascript) |
|
33 | + { |
|
34 | + $javascript = addslashes($javascript); |
|
35 | + $javascript = str_replace(array("\r\n", "\n", "\r"), array("\n"), $javascript); |
|
36 | 36 | |
37 | - return $javascript; |
|
38 | - } |
|
37 | + return $javascript; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @param $content |
|
42 | - * @return string |
|
43 | - */ |
|
44 | - public function tag($content) |
|
45 | - { |
|
46 | - return '<script type="text/javascript">' . $content . '</script>'; |
|
47 | - } |
|
40 | + /** |
|
41 | + * @param $content |
|
42 | + * @return string |
|
43 | + */ |
|
44 | + public function tag($content) |
|
45 | + { |
|
46 | + return '<script type="text/javascript">' . $content . '</script>'; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @param $name |
|
51 | - * @param $function |
|
52 | - * @param null $html_options |
|
53 | - * @return string |
|
54 | - */ |
|
55 | - public function link_to_function($name, $function, $html_options = null) |
|
56 | - { |
|
57 | - return '<a href="' . (isset($html_options['href']) ? $html_options['href'] : '#') . '" onclick="' . (isset($html_options['onclick']) ? $html_options['onclick'] . ';' : '') . $function . '; return false;" />' . $name . '</a>'; |
|
58 | - } |
|
49 | + /** |
|
50 | + * @param $name |
|
51 | + * @param $function |
|
52 | + * @param null $html_options |
|
53 | + * @return string |
|
54 | + */ |
|
55 | + public function link_to_function($name, $function, $html_options = null) |
|
56 | + { |
|
57 | + return '<a href="' . (isset($html_options['href']) ? $html_options['href'] : '#') . '" onclick="' . (isset($html_options['onclick']) ? $html_options['onclick'] . ';' : '') . $function . '; return false;" />' . $name . '</a>'; |
|
58 | + } |
|
59 | 59 | |
60 | - ///////////////////////////////////////////////////////////////////////////////////// |
|
61 | - // Private functions |
|
62 | - ///////////////////////////////////////////////////////////////////////////////////// |
|
60 | + ///////////////////////////////////////////////////////////////////////////////////// |
|
61 | + // Private functions |
|
62 | + ///////////////////////////////////////////////////////////////////////////////////// |
|
63 | 63 | |
64 | - /** |
|
65 | - * @param $option |
|
66 | - * @return string |
|
67 | - */ |
|
68 | - public function _array_or_string_for_javascript($option) |
|
69 | - { |
|
70 | - $return_val = ''; |
|
71 | - if (is_array($option)) { |
|
72 | - foreach ($option as $value) { |
|
73 | - if (!empty($return_val)) { |
|
74 | - $ret_val .= ', '; |
|
75 | - } |
|
76 | - $return_val .= $value; |
|
77 | - } |
|
64 | + /** |
|
65 | + * @param $option |
|
66 | + * @return string |
|
67 | + */ |
|
68 | + public function _array_or_string_for_javascript($option) |
|
69 | + { |
|
70 | + $return_val = ''; |
|
71 | + if (is_array($option)) { |
|
72 | + foreach ($option as $value) { |
|
73 | + if (!empty($return_val)) { |
|
74 | + $ret_val .= ', '; |
|
75 | + } |
|
76 | + $return_val .= $value; |
|
77 | + } |
|
78 | 78 | |
79 | - return '[' . $return_val . ']'; |
|
80 | - } |
|
79 | + return '[' . $return_val . ']'; |
|
80 | + } |
|
81 | 81 | |
82 | - return "'$option'"; |
|
83 | - } |
|
82 | + return "'$option'"; |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * @param $options |
|
87 | - * @return string |
|
88 | - */ |
|
89 | - public function _options_for_javascript($options) |
|
90 | - { |
|
91 | - $return_val = ''; |
|
85 | + /** |
|
86 | + * @param $options |
|
87 | + * @return string |
|
88 | + */ |
|
89 | + public function _options_for_javascript($options) |
|
90 | + { |
|
91 | + $return_val = ''; |
|
92 | 92 | |
93 | - if (is_array($options)) { |
|
94 | - foreach ($options as $var => $val) { |
|
95 | - if (!empty($return_val)) { |
|
96 | - $return_val .= ', '; |
|
97 | - } |
|
98 | - $return_val .= "$var:$val"; |
|
99 | - } |
|
100 | - } |
|
93 | + if (is_array($options)) { |
|
94 | + foreach ($options as $var => $val) { |
|
95 | + if (!empty($return_val)) { |
|
96 | + $return_val .= ', '; |
|
97 | + } |
|
98 | + $return_val .= "$var:$val"; |
|
99 | + } |
|
100 | + } |
|
101 | 101 | |
102 | - return '{' . $return_val . '}'; |
|
103 | - } |
|
102 | + return '{' . $return_val . '}'; |
|
103 | + } |
|
104 | 104 | } |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | */ |
23 | 23 | public function button_to_function($name, $function = null) |
24 | 24 | { |
25 | - return '<input type="button" value="' . $name . '" onclick="' . $function . '" />'; |
|
25 | + return '<input type="button" value="'.$name.'" onclick="'.$function.'" />'; |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | /** |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public function tag($content) |
45 | 45 | { |
46 | - return '<script type="text/javascript">' . $content . '</script>'; |
|
46 | + return '<script type="text/javascript">'.$content.'</script>'; |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | */ |
55 | 55 | public function link_to_function($name, $function, $html_options = null) |
56 | 56 | { |
57 | - return '<a href="' . (isset($html_options['href']) ? $html_options['href'] : '#') . '" onclick="' . (isset($html_options['onclick']) ? $html_options['onclick'] . ';' : '') . $function . '; return false;" />' . $name . '</a>'; |
|
57 | + return '<a href="'.(isset($html_options['href']) ? $html_options['href'] : '#').'" onclick="'.(isset($html_options['onclick']) ? $html_options['onclick'].';' : '').$function.'; return false;" />'.$name.'</a>'; |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | ///////////////////////////////////////////////////////////////////////////////////// |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | $return_val .= $value; |
77 | 77 | } |
78 | 78 | |
79 | - return '[' . $return_val . ']'; |
|
79 | + return '['.$return_val.']'; |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | return "'$option'"; |
@@ -99,6 +99,6 @@ discard block |
||
99 | 99 | } |
100 | 100 | } |
101 | 101 | |
102 | - return '{' . $return_val . '}'; |
|
102 | + return '{'.$return_val.'}'; |
|
103 | 103 | } |
104 | 104 | } |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
215 | - * @param $klass |
|
215 | + * @param string $klass |
|
216 | 216 | * @param $name |
217 | 217 | * @param null $options |
218 | 218 | * @return string |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | } |
312 | 312 | |
313 | 313 | /** |
314 | - * @param $variable |
|
314 | + * @param string $variable |
|
315 | 315 | * @param $value |
316 | 316 | * @return string |
317 | 317 | */ |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | } |
322 | 322 | |
323 | 323 | /** |
324 | - * @param $function |
|
324 | + * @param string $function |
|
325 | 325 | * @param null $args |
326 | 326 | * @return string |
327 | 327 | */ |
@@ -15,452 +15,452 @@ |
||
15 | 15 | */ |
16 | 16 | class Prototype extends JavaScript |
17 | 17 | { |
18 | - public $CALLBACKS = array( |
|
19 | - 'uninitialized', |
|
20 | - 'loading', |
|
21 | - 'loaded', |
|
22 | - 'interactive', |
|
23 | - 'complete', |
|
24 | - 'failure', |
|
25 | - 'success' |
|
26 | - ); |
|
27 | - |
|
28 | - public $AJAX_OPTIONS = array( |
|
29 | - 'before', |
|
30 | - 'after', |
|
31 | - 'condition', |
|
32 | - 'url', |
|
33 | - 'asynchronous', |
|
34 | - 'method', |
|
35 | - 'insertion', |
|
36 | - 'position', |
|
37 | - 'form', |
|
38 | - 'with', |
|
39 | - 'update', |
|
40 | - 'script', |
|
41 | - 'uninitialized', |
|
42 | - 'loading', |
|
43 | - 'loaded', |
|
44 | - 'interactive', |
|
45 | - 'complete', |
|
46 | - 'failure', |
|
47 | - 'success' |
|
48 | - ); |
|
49 | - |
|
50 | - /** |
|
51 | - * @return string |
|
52 | - */ |
|
53 | - public function evaluate_remote_response() |
|
54 | - { |
|
55 | - return 'eval(request.responseText)'; |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * @param $options |
|
60 | - * @return string |
|
61 | - */ |
|
62 | - public function form_remote_tag($options) |
|
63 | - { |
|
64 | - $options['form'] = true; |
|
65 | - |
|
66 | - return '<form action="' . $options['url'] . '" onsubmit="' . $this->remote_function($options) . '; return false;" method="' . (isset($options['method']) ? $options['method'] : 'post') . '" >'; |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * @param $name |
|
71 | - * @param null $options |
|
72 | - * @param null $html_options |
|
73 | - * @return string |
|
74 | - */ |
|
75 | - public function link_to_remote($name, $options = null, $html_options = null) |
|
76 | - { |
|
77 | - return $this->link_to_function($name, $this->remote_function($options), $html_options); |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * @param $field_id |
|
82 | - * @param null $options |
|
83 | - * @return string |
|
84 | - */ |
|
85 | - public function observe_field($field_id, $options = null) |
|
86 | - { |
|
87 | - if (isset($options['frequency']) && $options['frequency'] > 0) { |
|
88 | - return $this->_build_observer('Form.Element.Observer', $field_id, $options); |
|
89 | - } else { |
|
90 | - return $this->_build_observer('Form.Element.EventObserver', $field_id, $options); |
|
91 | - } |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * @param $form_id |
|
96 | - * @param null $options |
|
97 | - * @return string |
|
98 | - */ |
|
99 | - public function observe_form($form_id, $options = null) |
|
100 | - { |
|
101 | - if (isset($options['frequency'])) { |
|
102 | - return $this->_build_observer('Form.Observer', $form_id, $options); |
|
103 | - } else { |
|
104 | - return $this->_build_observer('Form.EventObserver', $form_id, $options); |
|
105 | - } |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * @param null $options |
|
110 | - * @return string |
|
111 | - */ |
|
112 | - public function periodically_call_remote($options = null) |
|
113 | - { |
|
114 | - $frequency = isset($options['frequency']) ? $options['frequency'] : 10; |
|
115 | - $code = 'new PeriodicalExecuter(function() {' . $this->remote_function($options) . '},' . $frequency . ')'; |
|
116 | - |
|
117 | - return $code; |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * @param $options |
|
122 | - * @return string |
|
123 | - */ |
|
124 | - public function remote_function($options) |
|
125 | - { |
|
126 | - $javascript_options = $this->_options_for_ajax($options); |
|
127 | - |
|
128 | - $update = ''; |
|
129 | - |
|
130 | - if (isset($options['update']) && is_array($options['update'])) { |
|
131 | - $update = isset($options['update']['success']) ? 'success: ' . $options['update']['success'] : ''; |
|
132 | - $update .= empty($update) ? '' : ','; |
|
133 | - $update .= isset($options['update']['failure']) ? 'failure: ' . $options['update']['failure'] : ''; |
|
134 | - } else { |
|
135 | - $update .= isset($options['update']) ? $options['update'] : ''; |
|
136 | - } |
|
137 | - |
|
138 | - $ajax_function = empty($update) ? 'new Ajax.Request(' : 'new Ajax.Updater(\'' . $update . '\','; |
|
139 | - |
|
140 | - $ajax_function .= "'" . $options['url'] . "'"; |
|
141 | - $ajax_function .= ',' . $javascript_options . ')'; |
|
142 | - |
|
143 | - $ajax_function = isset($options['before']) ? $options['before'] . ';' . $ajax_function : $ajax_function; |
|
144 | - $ajax_function = isset($options['after']) ? $ajax_function . ';' . $options['after'] : $ajax_function; |
|
145 | - $ajax_function = isset($options['condition']) ? 'if (' . $options['condition'] . ') {' . $ajax_function . '}' : $ajax_function; |
|
146 | - $ajax_function = isset($options['confirm']) ? 'if ( confirm(\'' . $options['confirm'] . '\' ) ) { ' . $ajax_function . ' } ' : $ajax_function; |
|
147 | - |
|
148 | - return $ajax_function; |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * @param $name |
|
153 | - * @param $value |
|
154 | - * @param $options |
|
155 | - * @return string |
|
156 | - */ |
|
157 | - public function submit_to_remote($name, $value, $options) |
|
158 | - { |
|
159 | - if (isset($options['with'])) { |
|
160 | - $options['with'] = 'Form.serialize(this.form)'; |
|
161 | - } |
|
162 | - |
|
163 | - return '<input type="button" onclick="' . $this->remote_function($options) . '" name="' . $name . '" value ="' . $value . '" />'; |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * @param $element_id |
|
168 | - * @param null $options |
|
169 | - * @param $block |
|
170 | - */ |
|
171 | - public function update_element_function($element_id, $options = null, $block) |
|
172 | - { |
|
173 | - $content = isset($options['content']) ? $options['content'] : ''; |
|
174 | - $content = $this->escape($content); |
|
175 | - } |
|
176 | - |
|
177 | - /** |
|
178 | - * @param $block |
|
179 | - */ |
|
180 | - public function update_page($block) |
|
181 | - { |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * @param $block |
|
186 | - * @return string |
|
187 | - */ |
|
188 | - public function update_page_tag(& $block) |
|
189 | - { |
|
190 | - return $this->tag($block); |
|
191 | - } |
|
192 | - |
|
193 | - ///////////////////////////////////////////////////////////////////////////////////// |
|
194 | - // Private functions |
|
195 | - ///////////////////////////////////////////////////////////////////////////////////// |
|
196 | - |
|
197 | - /** |
|
198 | - * @param $options |
|
199 | - * @return array |
|
200 | - */ |
|
201 | - public function _build_callbacks($options) |
|
202 | - { |
|
203 | - $callbacks = array(); |
|
204 | - foreach ($options as $callback => $code) { |
|
205 | - if (in_array($callback, $this->CALLBACKS)) { |
|
206 | - $name = 'on' . ucfirst($callback); |
|
207 | - $callbacks[$name] = 'function(request){' . $code . '}'; |
|
208 | - } |
|
209 | - } |
|
210 | - |
|
211 | - return $callbacks; |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * @param $klass |
|
216 | - * @param $name |
|
217 | - * @param null $options |
|
218 | - * @return string |
|
219 | - */ |
|
220 | - public function _build_observer($klass, $name, $options = null) |
|
221 | - { |
|
222 | - if (isset($options['with']) && false === strpos($options['with'], '=')) { |
|
223 | - $options['with'] = '\'' . $options['with'] . '=\' + value'; |
|
224 | - } elseif (isset($options['with']) && isset($options['update'])) { |
|
225 | - $options['with'] = 'value'; |
|
226 | - } |
|
227 | - |
|
228 | - $callback = $options['function'] ?: $this->remote_function($options); |
|
229 | - |
|
230 | - $javascript = "new $klass('$name', "; |
|
231 | - $javascript .= isset($options['frequency']) ? $options['frequency'] . ', ' : ''; |
|
232 | - $javascript .= 'function (element,value) { '; |
|
233 | - $javascript .= $callback; |
|
234 | - $javascript .= isset($options['on']) ? ', ' . $options['on'] : ''; |
|
235 | - $javascript .= '})'; |
|
236 | - |
|
237 | - return $javascript; |
|
238 | - } |
|
239 | - |
|
240 | - /** |
|
241 | - * @param $method |
|
242 | - * @return string |
|
243 | - */ |
|
244 | - public function _method_option_to_s($method) |
|
245 | - { |
|
246 | - return strstr($method, "'") ? $method : "'$method'"; |
|
247 | - } |
|
248 | - |
|
249 | - /** |
|
250 | - * @param $options |
|
251 | - * @return string |
|
252 | - */ |
|
253 | - public function _options_for_ajax($options) |
|
254 | - { |
|
255 | - $js_options = is_array($options) ? $this->_build_callbacks($options) : array(); |
|
256 | - |
|
257 | - if (isset($options['type']) && $option['type'] === 'synchronous') { |
|
258 | - $js_options['asynchronous'] = 'false'; |
|
259 | - } |
|
260 | - |
|
261 | - if (isset($options['method'])) { |
|
262 | - $js_options['method'] = $this->_method_option_to_s($options['method']); |
|
263 | - } |
|
264 | - |
|
265 | - if (isset($options['position'])) { |
|
266 | - $js_options['insertion'] = 'Insertion.' . ucfirst($options['position']); |
|
267 | - } |
|
268 | - |
|
269 | - $js_options['evalScripts'] = isset($options['script']) ? $options['script'] : 'true'; |
|
270 | - |
|
271 | - if (isset($options['form'])) { |
|
272 | - $js_options['parameters'] = 'Form.serialize(this)'; |
|
273 | - } elseif (isset($options['parameters'])) { |
|
274 | - $js_options['parameters'] = 'Form.serialize(\'' . $options['submit'] . '\')'; |
|
275 | - } elseif (isset($options['with'])) { |
|
276 | - $js_options['parameters'] = $options['with']; |
|
277 | - } |
|
278 | - |
|
279 | - return $this->_options_for_javascript($js_options); |
|
280 | - } |
|
281 | - |
|
282 | - ///////////////////////////////////////////////////////////////////////////////////// |
|
283 | - // Mergerd Javascript Generator helpers |
|
284 | - ///////////////////////////////////////////////////////////////////////////////////// |
|
285 | - |
|
286 | - /** |
|
287 | - * @param $javascript |
|
288 | - */ |
|
289 | - public function dump($javascript) |
|
290 | - { |
|
291 | - echo $javascript; |
|
292 | - } |
|
293 | - |
|
294 | - /** |
|
295 | - * @param $id |
|
296 | - * @param null $extend |
|
297 | - * @return string |
|
298 | - */ |
|
299 | - public function ID($id, $extend = null) |
|
300 | - { |
|
301 | - return "$('$id')" . (!empty($extend)) ? '.' . $extend . '()' : ''; |
|
302 | - } |
|
303 | - |
|
304 | - /** |
|
305 | - * @param $message |
|
306 | - * @return string |
|
307 | - */ |
|
308 | - public function alert($message) |
|
309 | - { |
|
310 | - return $this->call('alert', $message); |
|
311 | - } |
|
312 | - |
|
313 | - /** |
|
314 | - * @param $variable |
|
315 | - * @param $value |
|
316 | - * @return string |
|
317 | - */ |
|
318 | - public function assign($variable, $value) |
|
319 | - { |
|
320 | - return "$variable = $value;"; |
|
321 | - } |
|
322 | - |
|
323 | - /** |
|
324 | - * @param $function |
|
325 | - * @param null $args |
|
326 | - * @return string |
|
327 | - */ |
|
328 | - public function call($function, $args = null) |
|
329 | - { |
|
330 | - $arg_str = ''; |
|
331 | - if (is_array($args)) { |
|
332 | - foreach ($args as $arg) { |
|
333 | - if (!empty($arg_str)) { |
|
334 | - $arg_str .= ', '; |
|
335 | - } |
|
336 | - if (is_string($arg)) { |
|
337 | - $arg_str .= "'$arg'"; |
|
338 | - } else { |
|
339 | - $arg_str .= $arg; |
|
340 | - } |
|
341 | - } |
|
342 | - } else { |
|
343 | - if (is_string($args)) { |
|
344 | - $arg_str .= "'$args'"; |
|
345 | - } else { |
|
346 | - $arg_str .= $args; |
|
347 | - } |
|
348 | - } |
|
349 | - |
|
350 | - return "$function($arg_str)"; |
|
351 | - } |
|
352 | - |
|
353 | - /** |
|
354 | - * @param int $seconds |
|
355 | - * @param string $script |
|
356 | - * @return string |
|
357 | - */ |
|
358 | - public function delay($seconds = 1, $script = '') |
|
359 | - { |
|
360 | - return "setTimeout( function() { $script } , " . ($seconds * 1000) . ' )'; |
|
361 | - } |
|
362 | - |
|
363 | - /** |
|
364 | - * @param $id |
|
365 | - * @return string |
|
366 | - */ |
|
367 | - public function hide($id) |
|
368 | - { |
|
369 | - return $this->call('Element.hide', $id); |
|
370 | - } |
|
371 | - |
|
372 | - /** |
|
373 | - * @param $position |
|
374 | - * @param $id |
|
375 | - * @param null $options_for_render |
|
376 | - * @return string |
|
377 | - */ |
|
378 | - public function insert_html($position, $id, $options_for_render = null) |
|
379 | - { |
|
380 | - $args = array_merge(array($id), (is_array($options_for_render) ? $options_for_render : array($options_for_render))); |
|
381 | - |
|
382 | - return $this->call('new Insertion.' . ucfirst($position), $args); |
|
383 | - } |
|
384 | - |
|
385 | - /** |
|
386 | - * @param $location |
|
387 | - * @return string |
|
388 | - */ |
|
389 | - public function redirect_to($location) |
|
390 | - { |
|
391 | - return $this->assign('window.location.href', $location); |
|
392 | - } |
|
393 | - |
|
394 | - /** |
|
395 | - * @param $id |
|
396 | - * @return string |
|
397 | - */ |
|
398 | - public function remove($id) |
|
399 | - { |
|
400 | - if (is_array($id)) { |
|
401 | - $arr_str = ''; |
|
402 | - foreach ($id as $obj) { |
|
403 | - if (!empty($arg_str)) { |
|
404 | - $arg_str .= ', '; |
|
405 | - } |
|
406 | - $arg_str .= "'$arg'"; |
|
407 | - } |
|
408 | - |
|
409 | - return "$A[$arg_str].each(Element.remove)"; |
|
410 | - } else { |
|
411 | - return "Element.remove('$id')"; |
|
412 | - } |
|
413 | - } |
|
414 | - |
|
415 | - /** |
|
416 | - * @param $id |
|
417 | - * @param $options_for_render |
|
418 | - * @return string |
|
419 | - */ |
|
420 | - public function replace($id, $options_for_render) |
|
421 | - { |
|
422 | - $args = array_merge(array($id), (is_array($options_for_render) ? $options_for_render : array($options_for_render))); |
|
423 | - |
|
424 | - return $this->call('Element.replace', $args); |
|
425 | - } |
|
426 | - |
|
427 | - /** |
|
428 | - * @param $id |
|
429 | - * @param $options_for_render |
|
430 | - * @return string |
|
431 | - */ |
|
432 | - public function replace_html($id, $options_for_render) |
|
433 | - { |
|
434 | - $args = array_merge(array($id), (is_array($options_for_render) ? $options_for_render : array($options_for_render))); |
|
435 | - |
|
436 | - return $this->call('Element.update', $args); |
|
437 | - } |
|
438 | - |
|
439 | - /** |
|
440 | - * @param $pattern |
|
441 | - * @param null $extend |
|
442 | - * @return string |
|
443 | - */ |
|
444 | - public function select($pattern, $extend = null) |
|
445 | - { |
|
446 | - return "$$('$pattern')" . (!empty($extend)) ? '.' . $extend : ''; |
|
447 | - } |
|
448 | - |
|
449 | - /** |
|
450 | - * @param $id |
|
451 | - * @return string |
|
452 | - */ |
|
453 | - public function show($id) |
|
454 | - { |
|
455 | - return $this->call('Element.show', $id); |
|
456 | - } |
|
457 | - |
|
458 | - /** |
|
459 | - * @param $id |
|
460 | - * @return string |
|
461 | - */ |
|
462 | - public function toggle($id) |
|
463 | - { |
|
464 | - return $this->call('Element.toggle', $id); |
|
465 | - } |
|
18 | + public $CALLBACKS = array( |
|
19 | + 'uninitialized', |
|
20 | + 'loading', |
|
21 | + 'loaded', |
|
22 | + 'interactive', |
|
23 | + 'complete', |
|
24 | + 'failure', |
|
25 | + 'success' |
|
26 | + ); |
|
27 | + |
|
28 | + public $AJAX_OPTIONS = array( |
|
29 | + 'before', |
|
30 | + 'after', |
|
31 | + 'condition', |
|
32 | + 'url', |
|
33 | + 'asynchronous', |
|
34 | + 'method', |
|
35 | + 'insertion', |
|
36 | + 'position', |
|
37 | + 'form', |
|
38 | + 'with', |
|
39 | + 'update', |
|
40 | + 'script', |
|
41 | + 'uninitialized', |
|
42 | + 'loading', |
|
43 | + 'loaded', |
|
44 | + 'interactive', |
|
45 | + 'complete', |
|
46 | + 'failure', |
|
47 | + 'success' |
|
48 | + ); |
|
49 | + |
|
50 | + /** |
|
51 | + * @return string |
|
52 | + */ |
|
53 | + public function evaluate_remote_response() |
|
54 | + { |
|
55 | + return 'eval(request.responseText)'; |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * @param $options |
|
60 | + * @return string |
|
61 | + */ |
|
62 | + public function form_remote_tag($options) |
|
63 | + { |
|
64 | + $options['form'] = true; |
|
65 | + |
|
66 | + return '<form action="' . $options['url'] . '" onsubmit="' . $this->remote_function($options) . '; return false;" method="' . (isset($options['method']) ? $options['method'] : 'post') . '" >'; |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * @param $name |
|
71 | + * @param null $options |
|
72 | + * @param null $html_options |
|
73 | + * @return string |
|
74 | + */ |
|
75 | + public function link_to_remote($name, $options = null, $html_options = null) |
|
76 | + { |
|
77 | + return $this->link_to_function($name, $this->remote_function($options), $html_options); |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * @param $field_id |
|
82 | + * @param null $options |
|
83 | + * @return string |
|
84 | + */ |
|
85 | + public function observe_field($field_id, $options = null) |
|
86 | + { |
|
87 | + if (isset($options['frequency']) && $options['frequency'] > 0) { |
|
88 | + return $this->_build_observer('Form.Element.Observer', $field_id, $options); |
|
89 | + } else { |
|
90 | + return $this->_build_observer('Form.Element.EventObserver', $field_id, $options); |
|
91 | + } |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * @param $form_id |
|
96 | + * @param null $options |
|
97 | + * @return string |
|
98 | + */ |
|
99 | + public function observe_form($form_id, $options = null) |
|
100 | + { |
|
101 | + if (isset($options['frequency'])) { |
|
102 | + return $this->_build_observer('Form.Observer', $form_id, $options); |
|
103 | + } else { |
|
104 | + return $this->_build_observer('Form.EventObserver', $form_id, $options); |
|
105 | + } |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * @param null $options |
|
110 | + * @return string |
|
111 | + */ |
|
112 | + public function periodically_call_remote($options = null) |
|
113 | + { |
|
114 | + $frequency = isset($options['frequency']) ? $options['frequency'] : 10; |
|
115 | + $code = 'new PeriodicalExecuter(function() {' . $this->remote_function($options) . '},' . $frequency . ')'; |
|
116 | + |
|
117 | + return $code; |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * @param $options |
|
122 | + * @return string |
|
123 | + */ |
|
124 | + public function remote_function($options) |
|
125 | + { |
|
126 | + $javascript_options = $this->_options_for_ajax($options); |
|
127 | + |
|
128 | + $update = ''; |
|
129 | + |
|
130 | + if (isset($options['update']) && is_array($options['update'])) { |
|
131 | + $update = isset($options['update']['success']) ? 'success: ' . $options['update']['success'] : ''; |
|
132 | + $update .= empty($update) ? '' : ','; |
|
133 | + $update .= isset($options['update']['failure']) ? 'failure: ' . $options['update']['failure'] : ''; |
|
134 | + } else { |
|
135 | + $update .= isset($options['update']) ? $options['update'] : ''; |
|
136 | + } |
|
137 | + |
|
138 | + $ajax_function = empty($update) ? 'new Ajax.Request(' : 'new Ajax.Updater(\'' . $update . '\','; |
|
139 | + |
|
140 | + $ajax_function .= "'" . $options['url'] . "'"; |
|
141 | + $ajax_function .= ',' . $javascript_options . ')'; |
|
142 | + |
|
143 | + $ajax_function = isset($options['before']) ? $options['before'] . ';' . $ajax_function : $ajax_function; |
|
144 | + $ajax_function = isset($options['after']) ? $ajax_function . ';' . $options['after'] : $ajax_function; |
|
145 | + $ajax_function = isset($options['condition']) ? 'if (' . $options['condition'] . ') {' . $ajax_function . '}' : $ajax_function; |
|
146 | + $ajax_function = isset($options['confirm']) ? 'if ( confirm(\'' . $options['confirm'] . '\' ) ) { ' . $ajax_function . ' } ' : $ajax_function; |
|
147 | + |
|
148 | + return $ajax_function; |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * @param $name |
|
153 | + * @param $value |
|
154 | + * @param $options |
|
155 | + * @return string |
|
156 | + */ |
|
157 | + public function submit_to_remote($name, $value, $options) |
|
158 | + { |
|
159 | + if (isset($options['with'])) { |
|
160 | + $options['with'] = 'Form.serialize(this.form)'; |
|
161 | + } |
|
162 | + |
|
163 | + return '<input type="button" onclick="' . $this->remote_function($options) . '" name="' . $name . '" value ="' . $value . '" />'; |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * @param $element_id |
|
168 | + * @param null $options |
|
169 | + * @param $block |
|
170 | + */ |
|
171 | + public function update_element_function($element_id, $options = null, $block) |
|
172 | + { |
|
173 | + $content = isset($options['content']) ? $options['content'] : ''; |
|
174 | + $content = $this->escape($content); |
|
175 | + } |
|
176 | + |
|
177 | + /** |
|
178 | + * @param $block |
|
179 | + */ |
|
180 | + public function update_page($block) |
|
181 | + { |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * @param $block |
|
186 | + * @return string |
|
187 | + */ |
|
188 | + public function update_page_tag(& $block) |
|
189 | + { |
|
190 | + return $this->tag($block); |
|
191 | + } |
|
192 | + |
|
193 | + ///////////////////////////////////////////////////////////////////////////////////// |
|
194 | + // Private functions |
|
195 | + ///////////////////////////////////////////////////////////////////////////////////// |
|
196 | + |
|
197 | + /** |
|
198 | + * @param $options |
|
199 | + * @return array |
|
200 | + */ |
|
201 | + public function _build_callbacks($options) |
|
202 | + { |
|
203 | + $callbacks = array(); |
|
204 | + foreach ($options as $callback => $code) { |
|
205 | + if (in_array($callback, $this->CALLBACKS)) { |
|
206 | + $name = 'on' . ucfirst($callback); |
|
207 | + $callbacks[$name] = 'function(request){' . $code . '}'; |
|
208 | + } |
|
209 | + } |
|
210 | + |
|
211 | + return $callbacks; |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * @param $klass |
|
216 | + * @param $name |
|
217 | + * @param null $options |
|
218 | + * @return string |
|
219 | + */ |
|
220 | + public function _build_observer($klass, $name, $options = null) |
|
221 | + { |
|
222 | + if (isset($options['with']) && false === strpos($options['with'], '=')) { |
|
223 | + $options['with'] = '\'' . $options['with'] . '=\' + value'; |
|
224 | + } elseif (isset($options['with']) && isset($options['update'])) { |
|
225 | + $options['with'] = 'value'; |
|
226 | + } |
|
227 | + |
|
228 | + $callback = $options['function'] ?: $this->remote_function($options); |
|
229 | + |
|
230 | + $javascript = "new $klass('$name', "; |
|
231 | + $javascript .= isset($options['frequency']) ? $options['frequency'] . ', ' : ''; |
|
232 | + $javascript .= 'function (element,value) { '; |
|
233 | + $javascript .= $callback; |
|
234 | + $javascript .= isset($options['on']) ? ', ' . $options['on'] : ''; |
|
235 | + $javascript .= '})'; |
|
236 | + |
|
237 | + return $javascript; |
|
238 | + } |
|
239 | + |
|
240 | + /** |
|
241 | + * @param $method |
|
242 | + * @return string |
|
243 | + */ |
|
244 | + public function _method_option_to_s($method) |
|
245 | + { |
|
246 | + return strstr($method, "'") ? $method : "'$method'"; |
|
247 | + } |
|
248 | + |
|
249 | + /** |
|
250 | + * @param $options |
|
251 | + * @return string |
|
252 | + */ |
|
253 | + public function _options_for_ajax($options) |
|
254 | + { |
|
255 | + $js_options = is_array($options) ? $this->_build_callbacks($options) : array(); |
|
256 | + |
|
257 | + if (isset($options['type']) && $option['type'] === 'synchronous') { |
|
258 | + $js_options['asynchronous'] = 'false'; |
|
259 | + } |
|
260 | + |
|
261 | + if (isset($options['method'])) { |
|
262 | + $js_options['method'] = $this->_method_option_to_s($options['method']); |
|
263 | + } |
|
264 | + |
|
265 | + if (isset($options['position'])) { |
|
266 | + $js_options['insertion'] = 'Insertion.' . ucfirst($options['position']); |
|
267 | + } |
|
268 | + |
|
269 | + $js_options['evalScripts'] = isset($options['script']) ? $options['script'] : 'true'; |
|
270 | + |
|
271 | + if (isset($options['form'])) { |
|
272 | + $js_options['parameters'] = 'Form.serialize(this)'; |
|
273 | + } elseif (isset($options['parameters'])) { |
|
274 | + $js_options['parameters'] = 'Form.serialize(\'' . $options['submit'] . '\')'; |
|
275 | + } elseif (isset($options['with'])) { |
|
276 | + $js_options['parameters'] = $options['with']; |
|
277 | + } |
|
278 | + |
|
279 | + return $this->_options_for_javascript($js_options); |
|
280 | + } |
|
281 | + |
|
282 | + ///////////////////////////////////////////////////////////////////////////////////// |
|
283 | + // Mergerd Javascript Generator helpers |
|
284 | + ///////////////////////////////////////////////////////////////////////////////////// |
|
285 | + |
|
286 | + /** |
|
287 | + * @param $javascript |
|
288 | + */ |
|
289 | + public function dump($javascript) |
|
290 | + { |
|
291 | + echo $javascript; |
|
292 | + } |
|
293 | + |
|
294 | + /** |
|
295 | + * @param $id |
|
296 | + * @param null $extend |
|
297 | + * @return string |
|
298 | + */ |
|
299 | + public function ID($id, $extend = null) |
|
300 | + { |
|
301 | + return "$('$id')" . (!empty($extend)) ? '.' . $extend . '()' : ''; |
|
302 | + } |
|
303 | + |
|
304 | + /** |
|
305 | + * @param $message |
|
306 | + * @return string |
|
307 | + */ |
|
308 | + public function alert($message) |
|
309 | + { |
|
310 | + return $this->call('alert', $message); |
|
311 | + } |
|
312 | + |
|
313 | + /** |
|
314 | + * @param $variable |
|
315 | + * @param $value |
|
316 | + * @return string |
|
317 | + */ |
|
318 | + public function assign($variable, $value) |
|
319 | + { |
|
320 | + return "$variable = $value;"; |
|
321 | + } |
|
322 | + |
|
323 | + /** |
|
324 | + * @param $function |
|
325 | + * @param null $args |
|
326 | + * @return string |
|
327 | + */ |
|
328 | + public function call($function, $args = null) |
|
329 | + { |
|
330 | + $arg_str = ''; |
|
331 | + if (is_array($args)) { |
|
332 | + foreach ($args as $arg) { |
|
333 | + if (!empty($arg_str)) { |
|
334 | + $arg_str .= ', '; |
|
335 | + } |
|
336 | + if (is_string($arg)) { |
|
337 | + $arg_str .= "'$arg'"; |
|
338 | + } else { |
|
339 | + $arg_str .= $arg; |
|
340 | + } |
|
341 | + } |
|
342 | + } else { |
|
343 | + if (is_string($args)) { |
|
344 | + $arg_str .= "'$args'"; |
|
345 | + } else { |
|
346 | + $arg_str .= $args; |
|
347 | + } |
|
348 | + } |
|
349 | + |
|
350 | + return "$function($arg_str)"; |
|
351 | + } |
|
352 | + |
|
353 | + /** |
|
354 | + * @param int $seconds |
|
355 | + * @param string $script |
|
356 | + * @return string |
|
357 | + */ |
|
358 | + public function delay($seconds = 1, $script = '') |
|
359 | + { |
|
360 | + return "setTimeout( function() { $script } , " . ($seconds * 1000) . ' )'; |
|
361 | + } |
|
362 | + |
|
363 | + /** |
|
364 | + * @param $id |
|
365 | + * @return string |
|
366 | + */ |
|
367 | + public function hide($id) |
|
368 | + { |
|
369 | + return $this->call('Element.hide', $id); |
|
370 | + } |
|
371 | + |
|
372 | + /** |
|
373 | + * @param $position |
|
374 | + * @param $id |
|
375 | + * @param null $options_for_render |
|
376 | + * @return string |
|
377 | + */ |
|
378 | + public function insert_html($position, $id, $options_for_render = null) |
|
379 | + { |
|
380 | + $args = array_merge(array($id), (is_array($options_for_render) ? $options_for_render : array($options_for_render))); |
|
381 | + |
|
382 | + return $this->call('new Insertion.' . ucfirst($position), $args); |
|
383 | + } |
|
384 | + |
|
385 | + /** |
|
386 | + * @param $location |
|
387 | + * @return string |
|
388 | + */ |
|
389 | + public function redirect_to($location) |
|
390 | + { |
|
391 | + return $this->assign('window.location.href', $location); |
|
392 | + } |
|
393 | + |
|
394 | + /** |
|
395 | + * @param $id |
|
396 | + * @return string |
|
397 | + */ |
|
398 | + public function remove($id) |
|
399 | + { |
|
400 | + if (is_array($id)) { |
|
401 | + $arr_str = ''; |
|
402 | + foreach ($id as $obj) { |
|
403 | + if (!empty($arg_str)) { |
|
404 | + $arg_str .= ', '; |
|
405 | + } |
|
406 | + $arg_str .= "'$arg'"; |
|
407 | + } |
|
408 | + |
|
409 | + return "$A[$arg_str].each(Element.remove)"; |
|
410 | + } else { |
|
411 | + return "Element.remove('$id')"; |
|
412 | + } |
|
413 | + } |
|
414 | + |
|
415 | + /** |
|
416 | + * @param $id |
|
417 | + * @param $options_for_render |
|
418 | + * @return string |
|
419 | + */ |
|
420 | + public function replace($id, $options_for_render) |
|
421 | + { |
|
422 | + $args = array_merge(array($id), (is_array($options_for_render) ? $options_for_render : array($options_for_render))); |
|
423 | + |
|
424 | + return $this->call('Element.replace', $args); |
|
425 | + } |
|
426 | + |
|
427 | + /** |
|
428 | + * @param $id |
|
429 | + * @param $options_for_render |
|
430 | + * @return string |
|
431 | + */ |
|
432 | + public function replace_html($id, $options_for_render) |
|
433 | + { |
|
434 | + $args = array_merge(array($id), (is_array($options_for_render) ? $options_for_render : array($options_for_render))); |
|
435 | + |
|
436 | + return $this->call('Element.update', $args); |
|
437 | + } |
|
438 | + |
|
439 | + /** |
|
440 | + * @param $pattern |
|
441 | + * @param null $extend |
|
442 | + * @return string |
|
443 | + */ |
|
444 | + public function select($pattern, $extend = null) |
|
445 | + { |
|
446 | + return "$$('$pattern')" . (!empty($extend)) ? '.' . $extend : ''; |
|
447 | + } |
|
448 | + |
|
449 | + /** |
|
450 | + * @param $id |
|
451 | + * @return string |
|
452 | + */ |
|
453 | + public function show($id) |
|
454 | + { |
|
455 | + return $this->call('Element.show', $id); |
|
456 | + } |
|
457 | + |
|
458 | + /** |
|
459 | + * @param $id |
|
460 | + * @return string |
|
461 | + */ |
|
462 | + public function toggle($id) |
|
463 | + { |
|
464 | + return $this->call('Element.toggle', $id); |
|
465 | + } |
|
466 | 466 | } |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | { |
64 | 64 | $options['form'] = true; |
65 | 65 | |
66 | - return '<form action="' . $options['url'] . '" onsubmit="' . $this->remote_function($options) . '; return false;" method="' . (isset($options['method']) ? $options['method'] : 'post') . '" >'; |
|
66 | + return '<form action="'.$options['url'].'" onsubmit="'.$this->remote_function($options).'; return false;" method="'.(isset($options['method']) ? $options['method'] : 'post').'" >'; |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | public function periodically_call_remote($options = null) |
113 | 113 | { |
114 | 114 | $frequency = isset($options['frequency']) ? $options['frequency'] : 10; |
115 | - $code = 'new PeriodicalExecuter(function() {' . $this->remote_function($options) . '},' . $frequency . ')'; |
|
115 | + $code = 'new PeriodicalExecuter(function() {'.$this->remote_function($options).'},'.$frequency.')'; |
|
116 | 116 | |
117 | 117 | return $code; |
118 | 118 | } |
@@ -128,22 +128,22 @@ discard block |
||
128 | 128 | $update = ''; |
129 | 129 | |
130 | 130 | if (isset($options['update']) && is_array($options['update'])) { |
131 | - $update = isset($options['update']['success']) ? 'success: ' . $options['update']['success'] : ''; |
|
131 | + $update = isset($options['update']['success']) ? 'success: '.$options['update']['success'] : ''; |
|
132 | 132 | $update .= empty($update) ? '' : ','; |
133 | - $update .= isset($options['update']['failure']) ? 'failure: ' . $options['update']['failure'] : ''; |
|
133 | + $update .= isset($options['update']['failure']) ? 'failure: '.$options['update']['failure'] : ''; |
|
134 | 134 | } else { |
135 | 135 | $update .= isset($options['update']) ? $options['update'] : ''; |
136 | 136 | } |
137 | 137 | |
138 | - $ajax_function = empty($update) ? 'new Ajax.Request(' : 'new Ajax.Updater(\'' . $update . '\','; |
|
138 | + $ajax_function = empty($update) ? 'new Ajax.Request(' : 'new Ajax.Updater(\''.$update.'\','; |
|
139 | 139 | |
140 | - $ajax_function .= "'" . $options['url'] . "'"; |
|
141 | - $ajax_function .= ',' . $javascript_options . ')'; |
|
140 | + $ajax_function .= "'".$options['url']."'"; |
|
141 | + $ajax_function .= ','.$javascript_options.')'; |
|
142 | 142 | |
143 | - $ajax_function = isset($options['before']) ? $options['before'] . ';' . $ajax_function : $ajax_function; |
|
144 | - $ajax_function = isset($options['after']) ? $ajax_function . ';' . $options['after'] : $ajax_function; |
|
145 | - $ajax_function = isset($options['condition']) ? 'if (' . $options['condition'] . ') {' . $ajax_function . '}' : $ajax_function; |
|
146 | - $ajax_function = isset($options['confirm']) ? 'if ( confirm(\'' . $options['confirm'] . '\' ) ) { ' . $ajax_function . ' } ' : $ajax_function; |
|
143 | + $ajax_function = isset($options['before']) ? $options['before'].';'.$ajax_function : $ajax_function; |
|
144 | + $ajax_function = isset($options['after']) ? $ajax_function.';'.$options['after'] : $ajax_function; |
|
145 | + $ajax_function = isset($options['condition']) ? 'if ('.$options['condition'].') {'.$ajax_function.'}' : $ajax_function; |
|
146 | + $ajax_function = isset($options['confirm']) ? 'if ( confirm(\''.$options['confirm'].'\' ) ) { '.$ajax_function.' } ' : $ajax_function; |
|
147 | 147 | |
148 | 148 | return $ajax_function; |
149 | 149 | } |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | $options['with'] = 'Form.serialize(this.form)'; |
161 | 161 | } |
162 | 162 | |
163 | - return '<input type="button" onclick="' . $this->remote_function($options) . '" name="' . $name . '" value ="' . $value . '" />'; |
|
163 | + return '<input type="button" onclick="'.$this->remote_function($options).'" name="'.$name.'" value ="'.$value.'" />'; |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | /** |
@@ -203,8 +203,8 @@ discard block |
||
203 | 203 | $callbacks = array(); |
204 | 204 | foreach ($options as $callback => $code) { |
205 | 205 | if (in_array($callback, $this->CALLBACKS)) { |
206 | - $name = 'on' . ucfirst($callback); |
|
207 | - $callbacks[$name] = 'function(request){' . $code . '}'; |
|
206 | + $name = 'on'.ucfirst($callback); |
|
207 | + $callbacks[$name] = 'function(request){'.$code.'}'; |
|
208 | 208 | } |
209 | 209 | } |
210 | 210 | |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | public function _build_observer($klass, $name, $options = null) |
221 | 221 | { |
222 | 222 | if (isset($options['with']) && false === strpos($options['with'], '=')) { |
223 | - $options['with'] = '\'' . $options['with'] . '=\' + value'; |
|
223 | + $options['with'] = '\''.$options['with'].'=\' + value'; |
|
224 | 224 | } elseif (isset($options['with']) && isset($options['update'])) { |
225 | 225 | $options['with'] = 'value'; |
226 | 226 | } |
@@ -228,10 +228,10 @@ discard block |
||
228 | 228 | $callback = $options['function'] ?: $this->remote_function($options); |
229 | 229 | |
230 | 230 | $javascript = "new $klass('$name', "; |
231 | - $javascript .= isset($options['frequency']) ? $options['frequency'] . ', ' : ''; |
|
231 | + $javascript .= isset($options['frequency']) ? $options['frequency'].', ' : ''; |
|
232 | 232 | $javascript .= 'function (element,value) { '; |
233 | 233 | $javascript .= $callback; |
234 | - $javascript .= isset($options['on']) ? ', ' . $options['on'] : ''; |
|
234 | + $javascript .= isset($options['on']) ? ', '.$options['on'] : ''; |
|
235 | 235 | $javascript .= '})'; |
236 | 236 | |
237 | 237 | return $javascript; |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | } |
264 | 264 | |
265 | 265 | if (isset($options['position'])) { |
266 | - $js_options['insertion'] = 'Insertion.' . ucfirst($options['position']); |
|
266 | + $js_options['insertion'] = 'Insertion.'.ucfirst($options['position']); |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | $js_options['evalScripts'] = isset($options['script']) ? $options['script'] : 'true'; |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | if (isset($options['form'])) { |
272 | 272 | $js_options['parameters'] = 'Form.serialize(this)'; |
273 | 273 | } elseif (isset($options['parameters'])) { |
274 | - $js_options['parameters'] = 'Form.serialize(\'' . $options['submit'] . '\')'; |
|
274 | + $js_options['parameters'] = 'Form.serialize(\''.$options['submit'].'\')'; |
|
275 | 275 | } elseif (isset($options['with'])) { |
276 | 276 | $js_options['parameters'] = $options['with']; |
277 | 277 | } |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | */ |
299 | 299 | public function ID($id, $extend = null) |
300 | 300 | { |
301 | - return "$('$id')" . (!empty($extend)) ? '.' . $extend . '()' : ''; |
|
301 | + return "$('$id')".(!empty($extend)) ? '.'.$extend.'()' : ''; |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | /** |
@@ -357,7 +357,7 @@ discard block |
||
357 | 357 | */ |
358 | 358 | public function delay($seconds = 1, $script = '') |
359 | 359 | { |
360 | - return "setTimeout( function() { $script } , " . ($seconds * 1000) . ' )'; |
|
360 | + return "setTimeout( function() { $script } , ".($seconds * 1000).' )'; |
|
361 | 361 | } |
362 | 362 | |
363 | 363 | /** |
@@ -379,7 +379,7 @@ discard block |
||
379 | 379 | { |
380 | 380 | $args = array_merge(array($id), (is_array($options_for_render) ? $options_for_render : array($options_for_render))); |
381 | 381 | |
382 | - return $this->call('new Insertion.' . ucfirst($position), $args); |
|
382 | + return $this->call('new Insertion.'.ucfirst($position), $args); |
|
383 | 383 | } |
384 | 384 | |
385 | 385 | /** |
@@ -443,7 +443,7 @@ discard block |
||
443 | 443 | */ |
444 | 444 | public function select($pattern, $extend = null) |
445 | 445 | { |
446 | - return "$$('$pattern')" . (!empty($extend)) ? '.' . $extend : ''; |
|
446 | + return "$$('$pattern')".(!empty($extend)) ? '.'.$extend : ''; |
|
447 | 447 | } |
448 | 448 | |
449 | 449 | /** |
@@ -245,7 +245,7 @@ |
||
245 | 245 | /** |
246 | 246 | * @param $field_id |
247 | 247 | * @param $options |
248 | - * @return mixed |
|
248 | + * @return string |
|
249 | 249 | */ |
250 | 250 | public function auto_complete_field($field_id, $options) |
251 | 251 | { |
@@ -15,307 +15,307 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class Scriptaculous extends Prototype |
17 | 17 | { |
18 | - public $TOGGLE_EFFECTS = array('toggle_appear', 'toggle_slide', 'toggle_blind'); |
|
19 | - |
|
20 | - /** |
|
21 | - * Scriptaculous constructor. |
|
22 | - */ |
|
23 | - public function __construct() |
|
24 | - { |
|
25 | - } |
|
26 | - |
|
27 | - /** |
|
28 | - * @param $element_id |
|
29 | - * @param null $options |
|
30 | - * @return string |
|
31 | - */ |
|
32 | - public function dragable_element($element_id, $options = null) |
|
33 | - { |
|
34 | - return $this->tag($this->_dragable_element_js($element_id, $options)); |
|
35 | - } |
|
36 | - |
|
37 | - /** |
|
38 | - * @param $element_id |
|
39 | - * @param null $options |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - public function drop_receiving_element($element_id, $options = null) |
|
43 | - { |
|
44 | - return $this->tag($this->_drop_receiving_element($element_id, $options)); |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * @param $name |
|
49 | - * @param bool $element_id |
|
50 | - * @param null $js_options |
|
51 | - * @return string |
|
52 | - */ |
|
53 | - public function visual_effect($name, $element_id = false, $js_options = null) |
|
54 | - { |
|
55 | - $element = $element_id ? "'$element_id'" : 'element'; |
|
56 | - |
|
57 | - $js_queue = ''; |
|
58 | - if (isset($js_options) && is_array($js_options['queue'])) { |
|
59 | - } elseif (isset($js_options)) { |
|
60 | - $js_queue = "'$js_options'"; |
|
61 | - } |
|
62 | - |
|
63 | - if (in_array($name, $this->TOGGLE_EFFECTS)) { |
|
64 | - return "Effect.toggle($element,'" . str_replace('toggle_', '', $name) . "'," . $this->_options_for_javascript($js_options) . ')'; |
|
65 | - } else { |
|
66 | - return 'new Effect.' . ucwords($name) . "($element," . $this->_options_for_javascript($js_options) . ')'; |
|
67 | - } |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * @param $element_id |
|
72 | - * @param null $options |
|
73 | - * @return string |
|
74 | - */ |
|
75 | - public function sortabe_element($element_id, $options = null) |
|
76 | - { |
|
77 | - return $this->tag($this->_sortabe_element($element_id, $options)); |
|
78 | - } |
|
79 | - |
|
80 | - ///////////////////////////////////////////////////////////////////////////////////// |
|
81 | - // Private functions |
|
82 | - ///////////////////////////////////////////////////////////////////////////////////// |
|
83 | - |
|
84 | - /** |
|
85 | - * @param $element_id |
|
86 | - * @param $options |
|
87 | - * @return string |
|
88 | - */ |
|
89 | - public function _sortabe_element($element_id, $options) |
|
90 | - { |
|
91 | - //if (isset($options['with'])) { |
|
92 | - $options['with'] = "Sortable.serialize('$element_id')"; |
|
93 | - // } |
|
94 | - |
|
95 | - //if (isset($option['onUpdate'])) { |
|
96 | - $options['onUpdate'] = 'function(){' . $this->remote_function($options) . '}'; |
|
97 | - //} |
|
98 | - |
|
99 | - foreach ($options as $var => $val) { |
|
100 | - if (in_array($var, $this->AJAX_OPTIONS)) { |
|
101 | - unset($options[$var]); |
|
102 | - } |
|
103 | - } |
|
104 | - |
|
105 | - $arr = array('tag', 'overlap', 'contraint', 'handle'); |
|
106 | - |
|
107 | - foreach ($arr as $var) { |
|
108 | - if (isset($options[$var])) { |
|
109 | - $options[$var] = "'" . $options[$var] . "'"; |
|
110 | - } |
|
111 | - } |
|
112 | - |
|
113 | - if (isset($options['containment'])) { |
|
114 | - $options['containment'] = $this->_array_or_string_for_javascript($options['containment']); |
|
115 | - } |
|
116 | - |
|
117 | - if (isset($options['only'])) { |
|
118 | - $options['only'] = $this->_array_or_string_for_javascript($options['only']); |
|
119 | - } |
|
120 | - |
|
121 | - return "Sortable.create('$element_id'," . $this->_options_for_javascript($options) . ')'; |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * @param $element_id |
|
126 | - * @param $options |
|
127 | - * @return string |
|
128 | - */ |
|
129 | - public function _dragable_element_js($element_id, $options) |
|
130 | - { |
|
131 | - return 'new Draggable(\'' . $element_id . '\',' . $this->_options_for_javascript($options) . ')'; |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * @param $element_id |
|
136 | - * @param $options |
|
137 | - * @return string |
|
138 | - */ |
|
139 | - public function _drop_receiving_element($element_id, $options) |
|
140 | - { |
|
141 | - |
|
142 | - //if (isset($options['with'])) { |
|
143 | - $options['with'] = '\'id=\' + encodeURIComponent(element.id)'; |
|
144 | - // } |
|
145 | - |
|
146 | - //if (isset($option['onDrop'])) |
|
147 | - |
|
148 | - { |
|
149 | - $options['onDrop'] = 'function(element){' . $this->remote_function($options) . '}'; |
|
150 | - } |
|
151 | - |
|
152 | - if (is_array($options)) { |
|
153 | - foreach ($options as $var => $val) { |
|
154 | - if (in_array($var, $this->AJAX_OPTIONS)) { |
|
155 | - unset($options[$var]); |
|
156 | - } |
|
157 | - } |
|
158 | - } |
|
159 | - |
|
160 | - if (isset($options['accept'])) { |
|
161 | - $options['accept'] = $this->_array_or_string_for_javascript($options['accept']); |
|
162 | - } |
|
163 | - |
|
164 | - if (isset($options['hoverclass'])) { |
|
165 | - $options['hoverclass'] = "'" . $options['hoverclass'] . "'"; |
|
166 | - } |
|
167 | - |
|
168 | - return 'Droppables.add(\'' . $element_id . '\',' . $this->_options_for_javascript($options) . ')'; |
|
169 | - } |
|
170 | - |
|
171 | - ///////////////////////////////////////////////////////////////////////////////////// |
|
172 | - // Merged Javascript macro |
|
173 | - ///////////////////////////////////////////////////////////////////////////////////// |
|
174 | - |
|
175 | - /** |
|
176 | - * @param $field_id |
|
177 | - * @param $options |
|
178 | - * @param bool $tag |
|
179 | - * @return string |
|
180 | - */ |
|
181 | - public function in_place_editor($field_id, $options, $tag = true) |
|
182 | - { |
|
183 | - $function = 'new Ajax.InPlaceEditor('; |
|
184 | - $function .= "'$field_id', "; |
|
185 | - $function .= "'" . $options['url'] . "'"; |
|
186 | - |
|
187 | - $js_options = array(); |
|
188 | - if (isset($options['cancel_text'])) { |
|
189 | - $js_options['cancelText'] = $options['cancel_text']; |
|
190 | - } |
|
191 | - if (isset($options['save_text'])) { |
|
192 | - $js_options['okText'] = $options['save_text']; |
|
193 | - } |
|
194 | - if (isset($options['loading_text'])) { |
|
195 | - $js_options['loadingText'] = $options['loading_text']; |
|
196 | - } |
|
197 | - if (isset($options['rows'])) { |
|
198 | - $js_options['rows'] = $options['rows']; |
|
199 | - } |
|
200 | - if (isset($options['cols'])) { |
|
201 | - $js_options['cols'] = $options['cols']; |
|
202 | - } |
|
203 | - if (isset($options['size'])) { |
|
204 | - $js_options['size'] = $options['size']; |
|
205 | - } |
|
206 | - if (isset($options['external_control'])) { |
|
207 | - $js_options['externalControl'] = "'" . $options['external_control'] . "'"; |
|
208 | - } |
|
209 | - if (isset($options['load_text_url'])) { |
|
210 | - $js_options['loadTextURL'] = "'" . $options['load_text_url'] . "'"; |
|
211 | - } |
|
212 | - if (isset($options['options'])) { |
|
213 | - $js_options['ajaxOptions'] = $options['options']; |
|
214 | - } |
|
215 | - if (isset($options['script'])) { |
|
216 | - $js_options['evalScripts'] = $options['script']; |
|
217 | - } |
|
218 | - if (isset($options['with'])) { |
|
219 | - $js_options['callback'] = 'function(form) { return ' . $options['with'] . ' }'; |
|
220 | - } |
|
221 | - |
|
222 | - $function .= ', ' . $this->_options_for_javascript($js_options) . ' )'; |
|
223 | - if ($tag) { |
|
224 | - return $this->tag($function); |
|
225 | - } else { |
|
226 | - return $function; |
|
227 | - } |
|
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * @param $object |
|
232 | - * @param null $tag_options |
|
233 | - * @param null $in_place_editor_options |
|
234 | - * @return string |
|
235 | - */ |
|
236 | - public function in_place_editor_field($object, $tag_options = null, $in_place_editor_options = null) |
|
237 | - { |
|
238 | - $ret_val = ''; |
|
239 | - $ret_val .= '<span id="' . $object . '" class="in_place_editor_field">' . (isset($tag_options['value']) ? $tag_options['value'] : '') . '</span>'; |
|
240 | - $ret_val .= $this->in_place_editor($object, $in_place_editor_options); |
|
241 | - |
|
242 | - return $ret_val; |
|
243 | - } |
|
244 | - |
|
245 | - /** |
|
246 | - * @param $field_id |
|
247 | - * @param $options |
|
248 | - * @return mixed |
|
249 | - */ |
|
250 | - public function auto_complete_field($field_id, $options) |
|
251 | - { |
|
252 | - $function = "var $field_id" . '_auto_completer = new Ajax.Autocompleter('; |
|
253 | - $function .= "'$field_id', "; |
|
254 | - $function .= "'" . (isset($options['update']) ? $options['update'] : $field_id . '_auto_complete') . "', "; |
|
255 | - $function .= "'" . $options['url'] . "'"; |
|
256 | - |
|
257 | - $js_options = array(); |
|
258 | - if (isset($options['tokens'])) { |
|
259 | - $js_options['tokens'] = $this->javascript->_array_or_string_for_javascript($options['tokens']); |
|
260 | - } |
|
261 | - if (isset($options['with'])) { |
|
262 | - $js_options['callback'] = 'function(element, value) { return ' . $options['with'] . ' }'; |
|
263 | - } |
|
264 | - if (isset($options['indicator'])) { |
|
265 | - $js_options['indicator'] = "'" . $options['indicator'] . "'"; |
|
266 | - } |
|
267 | - if (isset($options['select'])) { |
|
268 | - $js_options['select'] = "'" . $options['select'] . "'"; |
|
269 | - } |
|
270 | - |
|
271 | - foreach (array('on_show' => 'onShow', 'on_hide' => 'onHide', 'min_chars' => 'min_chars') as $var => $val) { |
|
272 | - if (isset($options[$var])) { |
|
273 | - $js_options['$val'] = $options['var']; |
|
274 | - } |
|
275 | - } |
|
276 | - |
|
277 | - $function .= ', ' . $this->_options_for_javascript($js_options) . ' )'; |
|
278 | - |
|
279 | - return $this->tag($function); |
|
280 | - } |
|
281 | - |
|
282 | - /** |
|
283 | - * @param $entries |
|
284 | - * @param $field |
|
285 | - * @param null $phrase |
|
286 | - */ |
|
287 | - public function auto_complete_results($entries, $field, $phrase = null) |
|
288 | - { |
|
289 | - if (!is_array($entries)) { |
|
290 | - return; |
|
291 | - } |
|
292 | - $ret_val = '<ul>'; |
|
293 | - // Complete this function |
|
294 | - } |
|
295 | - |
|
296 | - /** |
|
297 | - * @param $object |
|
298 | - * @param null $tag_options |
|
299 | - * @param null $completion_options |
|
300 | - * @return string |
|
301 | - */ |
|
302 | - public function text_field_with_auto_complete($object, $tag_options = null, $completion_options = null) |
|
303 | - { |
|
304 | - $ret_val = isset($completion_options['skip_style']) ? '' : $this->_auto_complete_stylesheet(); |
|
305 | - $ret_val .= '<input autocomplete="off" id="' . $object . '" name="' . $object . '" size="' . (isset($tag_options['size']) ? $tag_options['size'] : 30) . '" type="text" value="' . (isset($tag_options['size']) ? $tag_options['value'] : '') . '" ' . (isset($tag_options['class']) ? 'class = "' . $tag_options['class'] . '" ' : '') . '/>'; |
|
306 | - |
|
307 | - $ret_val .= '<div id="' . $object . '_auto_complete" class="auto_complete"></div>'; |
|
308 | - $ret_val .= $this->auto_complete_field($object, $completion_options); |
|
309 | - |
|
310 | - return $ret_val; |
|
311 | - } |
|
312 | - |
|
313 | - /** |
|
314 | - * @return string |
|
315 | - */ |
|
316 | - public function _auto_complete_stylesheet() |
|
317 | - { |
|
318 | - return '<style> div.auto_complete { |
|
18 | + public $TOGGLE_EFFECTS = array('toggle_appear', 'toggle_slide', 'toggle_blind'); |
|
19 | + |
|
20 | + /** |
|
21 | + * Scriptaculous constructor. |
|
22 | + */ |
|
23 | + public function __construct() |
|
24 | + { |
|
25 | + } |
|
26 | + |
|
27 | + /** |
|
28 | + * @param $element_id |
|
29 | + * @param null $options |
|
30 | + * @return string |
|
31 | + */ |
|
32 | + public function dragable_element($element_id, $options = null) |
|
33 | + { |
|
34 | + return $this->tag($this->_dragable_element_js($element_id, $options)); |
|
35 | + } |
|
36 | + |
|
37 | + /** |
|
38 | + * @param $element_id |
|
39 | + * @param null $options |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + public function drop_receiving_element($element_id, $options = null) |
|
43 | + { |
|
44 | + return $this->tag($this->_drop_receiving_element($element_id, $options)); |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * @param $name |
|
49 | + * @param bool $element_id |
|
50 | + * @param null $js_options |
|
51 | + * @return string |
|
52 | + */ |
|
53 | + public function visual_effect($name, $element_id = false, $js_options = null) |
|
54 | + { |
|
55 | + $element = $element_id ? "'$element_id'" : 'element'; |
|
56 | + |
|
57 | + $js_queue = ''; |
|
58 | + if (isset($js_options) && is_array($js_options['queue'])) { |
|
59 | + } elseif (isset($js_options)) { |
|
60 | + $js_queue = "'$js_options'"; |
|
61 | + } |
|
62 | + |
|
63 | + if (in_array($name, $this->TOGGLE_EFFECTS)) { |
|
64 | + return "Effect.toggle($element,'" . str_replace('toggle_', '', $name) . "'," . $this->_options_for_javascript($js_options) . ')'; |
|
65 | + } else { |
|
66 | + return 'new Effect.' . ucwords($name) . "($element," . $this->_options_for_javascript($js_options) . ')'; |
|
67 | + } |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * @param $element_id |
|
72 | + * @param null $options |
|
73 | + * @return string |
|
74 | + */ |
|
75 | + public function sortabe_element($element_id, $options = null) |
|
76 | + { |
|
77 | + return $this->tag($this->_sortabe_element($element_id, $options)); |
|
78 | + } |
|
79 | + |
|
80 | + ///////////////////////////////////////////////////////////////////////////////////// |
|
81 | + // Private functions |
|
82 | + ///////////////////////////////////////////////////////////////////////////////////// |
|
83 | + |
|
84 | + /** |
|
85 | + * @param $element_id |
|
86 | + * @param $options |
|
87 | + * @return string |
|
88 | + */ |
|
89 | + public function _sortabe_element($element_id, $options) |
|
90 | + { |
|
91 | + //if (isset($options['with'])) { |
|
92 | + $options['with'] = "Sortable.serialize('$element_id')"; |
|
93 | + // } |
|
94 | + |
|
95 | + //if (isset($option['onUpdate'])) { |
|
96 | + $options['onUpdate'] = 'function(){' . $this->remote_function($options) . '}'; |
|
97 | + //} |
|
98 | + |
|
99 | + foreach ($options as $var => $val) { |
|
100 | + if (in_array($var, $this->AJAX_OPTIONS)) { |
|
101 | + unset($options[$var]); |
|
102 | + } |
|
103 | + } |
|
104 | + |
|
105 | + $arr = array('tag', 'overlap', 'contraint', 'handle'); |
|
106 | + |
|
107 | + foreach ($arr as $var) { |
|
108 | + if (isset($options[$var])) { |
|
109 | + $options[$var] = "'" . $options[$var] . "'"; |
|
110 | + } |
|
111 | + } |
|
112 | + |
|
113 | + if (isset($options['containment'])) { |
|
114 | + $options['containment'] = $this->_array_or_string_for_javascript($options['containment']); |
|
115 | + } |
|
116 | + |
|
117 | + if (isset($options['only'])) { |
|
118 | + $options['only'] = $this->_array_or_string_for_javascript($options['only']); |
|
119 | + } |
|
120 | + |
|
121 | + return "Sortable.create('$element_id'," . $this->_options_for_javascript($options) . ')'; |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * @param $element_id |
|
126 | + * @param $options |
|
127 | + * @return string |
|
128 | + */ |
|
129 | + public function _dragable_element_js($element_id, $options) |
|
130 | + { |
|
131 | + return 'new Draggable(\'' . $element_id . '\',' . $this->_options_for_javascript($options) . ')'; |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * @param $element_id |
|
136 | + * @param $options |
|
137 | + * @return string |
|
138 | + */ |
|
139 | + public function _drop_receiving_element($element_id, $options) |
|
140 | + { |
|
141 | + |
|
142 | + //if (isset($options['with'])) { |
|
143 | + $options['with'] = '\'id=\' + encodeURIComponent(element.id)'; |
|
144 | + // } |
|
145 | + |
|
146 | + //if (isset($option['onDrop'])) |
|
147 | + |
|
148 | + { |
|
149 | + $options['onDrop'] = 'function(element){' . $this->remote_function($options) . '}'; |
|
150 | + } |
|
151 | + |
|
152 | + if (is_array($options)) { |
|
153 | + foreach ($options as $var => $val) { |
|
154 | + if (in_array($var, $this->AJAX_OPTIONS)) { |
|
155 | + unset($options[$var]); |
|
156 | + } |
|
157 | + } |
|
158 | + } |
|
159 | + |
|
160 | + if (isset($options['accept'])) { |
|
161 | + $options['accept'] = $this->_array_or_string_for_javascript($options['accept']); |
|
162 | + } |
|
163 | + |
|
164 | + if (isset($options['hoverclass'])) { |
|
165 | + $options['hoverclass'] = "'" . $options['hoverclass'] . "'"; |
|
166 | + } |
|
167 | + |
|
168 | + return 'Droppables.add(\'' . $element_id . '\',' . $this->_options_for_javascript($options) . ')'; |
|
169 | + } |
|
170 | + |
|
171 | + ///////////////////////////////////////////////////////////////////////////////////// |
|
172 | + // Merged Javascript macro |
|
173 | + ///////////////////////////////////////////////////////////////////////////////////// |
|
174 | + |
|
175 | + /** |
|
176 | + * @param $field_id |
|
177 | + * @param $options |
|
178 | + * @param bool $tag |
|
179 | + * @return string |
|
180 | + */ |
|
181 | + public function in_place_editor($field_id, $options, $tag = true) |
|
182 | + { |
|
183 | + $function = 'new Ajax.InPlaceEditor('; |
|
184 | + $function .= "'$field_id', "; |
|
185 | + $function .= "'" . $options['url'] . "'"; |
|
186 | + |
|
187 | + $js_options = array(); |
|
188 | + if (isset($options['cancel_text'])) { |
|
189 | + $js_options['cancelText'] = $options['cancel_text']; |
|
190 | + } |
|
191 | + if (isset($options['save_text'])) { |
|
192 | + $js_options['okText'] = $options['save_text']; |
|
193 | + } |
|
194 | + if (isset($options['loading_text'])) { |
|
195 | + $js_options['loadingText'] = $options['loading_text']; |
|
196 | + } |
|
197 | + if (isset($options['rows'])) { |
|
198 | + $js_options['rows'] = $options['rows']; |
|
199 | + } |
|
200 | + if (isset($options['cols'])) { |
|
201 | + $js_options['cols'] = $options['cols']; |
|
202 | + } |
|
203 | + if (isset($options['size'])) { |
|
204 | + $js_options['size'] = $options['size']; |
|
205 | + } |
|
206 | + if (isset($options['external_control'])) { |
|
207 | + $js_options['externalControl'] = "'" . $options['external_control'] . "'"; |
|
208 | + } |
|
209 | + if (isset($options['load_text_url'])) { |
|
210 | + $js_options['loadTextURL'] = "'" . $options['load_text_url'] . "'"; |
|
211 | + } |
|
212 | + if (isset($options['options'])) { |
|
213 | + $js_options['ajaxOptions'] = $options['options']; |
|
214 | + } |
|
215 | + if (isset($options['script'])) { |
|
216 | + $js_options['evalScripts'] = $options['script']; |
|
217 | + } |
|
218 | + if (isset($options['with'])) { |
|
219 | + $js_options['callback'] = 'function(form) { return ' . $options['with'] . ' }'; |
|
220 | + } |
|
221 | + |
|
222 | + $function .= ', ' . $this->_options_for_javascript($js_options) . ' )'; |
|
223 | + if ($tag) { |
|
224 | + return $this->tag($function); |
|
225 | + } else { |
|
226 | + return $function; |
|
227 | + } |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * @param $object |
|
232 | + * @param null $tag_options |
|
233 | + * @param null $in_place_editor_options |
|
234 | + * @return string |
|
235 | + */ |
|
236 | + public function in_place_editor_field($object, $tag_options = null, $in_place_editor_options = null) |
|
237 | + { |
|
238 | + $ret_val = ''; |
|
239 | + $ret_val .= '<span id="' . $object . '" class="in_place_editor_field">' . (isset($tag_options['value']) ? $tag_options['value'] : '') . '</span>'; |
|
240 | + $ret_val .= $this->in_place_editor($object, $in_place_editor_options); |
|
241 | + |
|
242 | + return $ret_val; |
|
243 | + } |
|
244 | + |
|
245 | + /** |
|
246 | + * @param $field_id |
|
247 | + * @param $options |
|
248 | + * @return mixed |
|
249 | + */ |
|
250 | + public function auto_complete_field($field_id, $options) |
|
251 | + { |
|
252 | + $function = "var $field_id" . '_auto_completer = new Ajax.Autocompleter('; |
|
253 | + $function .= "'$field_id', "; |
|
254 | + $function .= "'" . (isset($options['update']) ? $options['update'] : $field_id . '_auto_complete') . "', "; |
|
255 | + $function .= "'" . $options['url'] . "'"; |
|
256 | + |
|
257 | + $js_options = array(); |
|
258 | + if (isset($options['tokens'])) { |
|
259 | + $js_options['tokens'] = $this->javascript->_array_or_string_for_javascript($options['tokens']); |
|
260 | + } |
|
261 | + if (isset($options['with'])) { |
|
262 | + $js_options['callback'] = 'function(element, value) { return ' . $options['with'] . ' }'; |
|
263 | + } |
|
264 | + if (isset($options['indicator'])) { |
|
265 | + $js_options['indicator'] = "'" . $options['indicator'] . "'"; |
|
266 | + } |
|
267 | + if (isset($options['select'])) { |
|
268 | + $js_options['select'] = "'" . $options['select'] . "'"; |
|
269 | + } |
|
270 | + |
|
271 | + foreach (array('on_show' => 'onShow', 'on_hide' => 'onHide', 'min_chars' => 'min_chars') as $var => $val) { |
|
272 | + if (isset($options[$var])) { |
|
273 | + $js_options['$val'] = $options['var']; |
|
274 | + } |
|
275 | + } |
|
276 | + |
|
277 | + $function .= ', ' . $this->_options_for_javascript($js_options) . ' )'; |
|
278 | + |
|
279 | + return $this->tag($function); |
|
280 | + } |
|
281 | + |
|
282 | + /** |
|
283 | + * @param $entries |
|
284 | + * @param $field |
|
285 | + * @param null $phrase |
|
286 | + */ |
|
287 | + public function auto_complete_results($entries, $field, $phrase = null) |
|
288 | + { |
|
289 | + if (!is_array($entries)) { |
|
290 | + return; |
|
291 | + } |
|
292 | + $ret_val = '<ul>'; |
|
293 | + // Complete this function |
|
294 | + } |
|
295 | + |
|
296 | + /** |
|
297 | + * @param $object |
|
298 | + * @param null $tag_options |
|
299 | + * @param null $completion_options |
|
300 | + * @return string |
|
301 | + */ |
|
302 | + public function text_field_with_auto_complete($object, $tag_options = null, $completion_options = null) |
|
303 | + { |
|
304 | + $ret_val = isset($completion_options['skip_style']) ? '' : $this->_auto_complete_stylesheet(); |
|
305 | + $ret_val .= '<input autocomplete="off" id="' . $object . '" name="' . $object . '" size="' . (isset($tag_options['size']) ? $tag_options['size'] : 30) . '" type="text" value="' . (isset($tag_options['size']) ? $tag_options['value'] : '') . '" ' . (isset($tag_options['class']) ? 'class = "' . $tag_options['class'] . '" ' : '') . '/>'; |
|
306 | + |
|
307 | + $ret_val .= '<div id="' . $object . '_auto_complete" class="auto_complete"></div>'; |
|
308 | + $ret_val .= $this->auto_complete_field($object, $completion_options); |
|
309 | + |
|
310 | + return $ret_val; |
|
311 | + } |
|
312 | + |
|
313 | + /** |
|
314 | + * @return string |
|
315 | + */ |
|
316 | + public function _auto_complete_stylesheet() |
|
317 | + { |
|
318 | + return '<style> div.auto_complete { |
|
319 | 319 | width: 350px; |
320 | 320 | background: #fff; |
321 | 321 | } |
@@ -339,5 +339,5 @@ discard block |
||
339 | 339 | padding:0; |
340 | 340 | } |
341 | 341 | </style>'; |
342 | - } |
|
342 | + } |
|
343 | 343 | } |
@@ -61,9 +61,9 @@ discard block |
||
61 | 61 | } |
62 | 62 | |
63 | 63 | if (in_array($name, $this->TOGGLE_EFFECTS)) { |
64 | - return "Effect.toggle($element,'" . str_replace('toggle_', '', $name) . "'," . $this->_options_for_javascript($js_options) . ')'; |
|
64 | + return "Effect.toggle($element,'".str_replace('toggle_', '', $name)."',".$this->_options_for_javascript($js_options).')'; |
|
65 | 65 | } else { |
66 | - return 'new Effect.' . ucwords($name) . "($element," . $this->_options_for_javascript($js_options) . ')'; |
|
66 | + return 'new Effect.'.ucwords($name)."($element,".$this->_options_for_javascript($js_options).')'; |
|
67 | 67 | } |
68 | 68 | } |
69 | 69 | |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | // } |
94 | 94 | |
95 | 95 | //if (isset($option['onUpdate'])) { |
96 | - $options['onUpdate'] = 'function(){' . $this->remote_function($options) . '}'; |
|
96 | + $options['onUpdate'] = 'function(){'.$this->remote_function($options).'}'; |
|
97 | 97 | //} |
98 | 98 | |
99 | 99 | foreach ($options as $var => $val) { |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | |
107 | 107 | foreach ($arr as $var) { |
108 | 108 | if (isset($options[$var])) { |
109 | - $options[$var] = "'" . $options[$var] . "'"; |
|
109 | + $options[$var] = "'".$options[$var]."'"; |
|
110 | 110 | } |
111 | 111 | } |
112 | 112 | |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | $options['only'] = $this->_array_or_string_for_javascript($options['only']); |
119 | 119 | } |
120 | 120 | |
121 | - return "Sortable.create('$element_id'," . $this->_options_for_javascript($options) . ')'; |
|
121 | + return "Sortable.create('$element_id',".$this->_options_for_javascript($options).')'; |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | */ |
129 | 129 | public function _dragable_element_js($element_id, $options) |
130 | 130 | { |
131 | - return 'new Draggable(\'' . $element_id . '\',' . $this->_options_for_javascript($options) . ')'; |
|
131 | + return 'new Draggable(\''.$element_id.'\','.$this->_options_for_javascript($options).')'; |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | //if (isset($option['onDrop'])) |
147 | 147 | |
148 | 148 | { |
149 | - $options['onDrop'] = 'function(element){' . $this->remote_function($options) . '}'; |
|
149 | + $options['onDrop'] = 'function(element){'.$this->remote_function($options).'}'; |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | if (is_array($options)) { |
@@ -162,10 +162,10 @@ discard block |
||
162 | 162 | } |
163 | 163 | |
164 | 164 | if (isset($options['hoverclass'])) { |
165 | - $options['hoverclass'] = "'" . $options['hoverclass'] . "'"; |
|
165 | + $options['hoverclass'] = "'".$options['hoverclass']."'"; |
|
166 | 166 | } |
167 | 167 | |
168 | - return 'Droppables.add(\'' . $element_id . '\',' . $this->_options_for_javascript($options) . ')'; |
|
168 | + return 'Droppables.add(\''.$element_id.'\','.$this->_options_for_javascript($options).')'; |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | ///////////////////////////////////////////////////////////////////////////////////// |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | { |
183 | 183 | $function = 'new Ajax.InPlaceEditor('; |
184 | 184 | $function .= "'$field_id', "; |
185 | - $function .= "'" . $options['url'] . "'"; |
|
185 | + $function .= "'".$options['url']."'"; |
|
186 | 186 | |
187 | 187 | $js_options = array(); |
188 | 188 | if (isset($options['cancel_text'])) { |
@@ -204,10 +204,10 @@ discard block |
||
204 | 204 | $js_options['size'] = $options['size']; |
205 | 205 | } |
206 | 206 | if (isset($options['external_control'])) { |
207 | - $js_options['externalControl'] = "'" . $options['external_control'] . "'"; |
|
207 | + $js_options['externalControl'] = "'".$options['external_control']."'"; |
|
208 | 208 | } |
209 | 209 | if (isset($options['load_text_url'])) { |
210 | - $js_options['loadTextURL'] = "'" . $options['load_text_url'] . "'"; |
|
210 | + $js_options['loadTextURL'] = "'".$options['load_text_url']."'"; |
|
211 | 211 | } |
212 | 212 | if (isset($options['options'])) { |
213 | 213 | $js_options['ajaxOptions'] = $options['options']; |
@@ -216,10 +216,10 @@ discard block |
||
216 | 216 | $js_options['evalScripts'] = $options['script']; |
217 | 217 | } |
218 | 218 | if (isset($options['with'])) { |
219 | - $js_options['callback'] = 'function(form) { return ' . $options['with'] . ' }'; |
|
219 | + $js_options['callback'] = 'function(form) { return '.$options['with'].' }'; |
|
220 | 220 | } |
221 | 221 | |
222 | - $function .= ', ' . $this->_options_for_javascript($js_options) . ' )'; |
|
222 | + $function .= ', '.$this->_options_for_javascript($js_options).' )'; |
|
223 | 223 | if ($tag) { |
224 | 224 | return $this->tag($function); |
225 | 225 | } else { |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | public function in_place_editor_field($object, $tag_options = null, $in_place_editor_options = null) |
237 | 237 | { |
238 | 238 | $ret_val = ''; |
239 | - $ret_val .= '<span id="' . $object . '" class="in_place_editor_field">' . (isset($tag_options['value']) ? $tag_options['value'] : '') . '</span>'; |
|
239 | + $ret_val .= '<span id="'.$object.'" class="in_place_editor_field">'.(isset($tag_options['value']) ? $tag_options['value'] : '').'</span>'; |
|
240 | 240 | $ret_val .= $this->in_place_editor($object, $in_place_editor_options); |
241 | 241 | |
242 | 242 | return $ret_val; |
@@ -249,23 +249,23 @@ discard block |
||
249 | 249 | */ |
250 | 250 | public function auto_complete_field($field_id, $options) |
251 | 251 | { |
252 | - $function = "var $field_id" . '_auto_completer = new Ajax.Autocompleter('; |
|
252 | + $function = "var $field_id".'_auto_completer = new Ajax.Autocompleter('; |
|
253 | 253 | $function .= "'$field_id', "; |
254 | - $function .= "'" . (isset($options['update']) ? $options['update'] : $field_id . '_auto_complete') . "', "; |
|
255 | - $function .= "'" . $options['url'] . "'"; |
|
254 | + $function .= "'".(isset($options['update']) ? $options['update'] : $field_id.'_auto_complete')."', "; |
|
255 | + $function .= "'".$options['url']."'"; |
|
256 | 256 | |
257 | 257 | $js_options = array(); |
258 | 258 | if (isset($options['tokens'])) { |
259 | 259 | $js_options['tokens'] = $this->javascript->_array_or_string_for_javascript($options['tokens']); |
260 | 260 | } |
261 | 261 | if (isset($options['with'])) { |
262 | - $js_options['callback'] = 'function(element, value) { return ' . $options['with'] . ' }'; |
|
262 | + $js_options['callback'] = 'function(element, value) { return '.$options['with'].' }'; |
|
263 | 263 | } |
264 | 264 | if (isset($options['indicator'])) { |
265 | - $js_options['indicator'] = "'" . $options['indicator'] . "'"; |
|
265 | + $js_options['indicator'] = "'".$options['indicator']."'"; |
|
266 | 266 | } |
267 | 267 | if (isset($options['select'])) { |
268 | - $js_options['select'] = "'" . $options['select'] . "'"; |
|
268 | + $js_options['select'] = "'".$options['select']."'"; |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | foreach (array('on_show' => 'onShow', 'on_hide' => 'onHide', 'min_chars' => 'min_chars') as $var => $val) { |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | } |
275 | 275 | } |
276 | 276 | |
277 | - $function .= ', ' . $this->_options_for_javascript($js_options) . ' )'; |
|
277 | + $function .= ', '.$this->_options_for_javascript($js_options).' )'; |
|
278 | 278 | |
279 | 279 | return $this->tag($function); |
280 | 280 | } |
@@ -302,9 +302,9 @@ discard block |
||
302 | 302 | public function text_field_with_auto_complete($object, $tag_options = null, $completion_options = null) |
303 | 303 | { |
304 | 304 | $ret_val = isset($completion_options['skip_style']) ? '' : $this->_auto_complete_stylesheet(); |
305 | - $ret_val .= '<input autocomplete="off" id="' . $object . '" name="' . $object . '" size="' . (isset($tag_options['size']) ? $tag_options['size'] : 30) . '" type="text" value="' . (isset($tag_options['size']) ? $tag_options['value'] : '') . '" ' . (isset($tag_options['class']) ? 'class = "' . $tag_options['class'] . '" ' : '') . '/>'; |
|
305 | + $ret_val .= '<input autocomplete="off" id="'.$object.'" name="'.$object.'" size="'.(isset($tag_options['size']) ? $tag_options['size'] : 30).'" type="text" value="'.(isset($tag_options['size']) ? $tag_options['value'] : '').'" '.(isset($tag_options['class']) ? 'class = "'.$tag_options['class'].'" ' : '').'/>'; |
|
306 | 306 | |
307 | - $ret_val .= '<div id="' . $object . '_auto_complete" class="auto_complete"></div>'; |
|
307 | + $ret_val .= '<div id="'.$object.'_auto_complete" class="auto_complete"></div>'; |
|
308 | 308 | $ret_val .= $this->auto_complete_field($object, $completion_options); |
309 | 309 | |
310 | 310 | return $ret_val; |
@@ -9,15 +9,15 @@ |
||
9 | 9 | |
10 | 10 | function smartobject_plugin_smartpartner() |
11 | 11 | { |
12 | - $pluginInfo = array(); |
|
12 | + $pluginInfo = array(); |
|
13 | 13 | |
14 | - $pluginInfo['items']['partner']['caption'] = 'Partner'; |
|
15 | - $pluginInfo['items']['partner']['url'] = 'partner.php?partnerid=%u'; |
|
16 | - $pluginInfo['items']['partner']['request'] = 'partnerid'; |
|
14 | + $pluginInfo['items']['partner']['caption'] = 'Partner'; |
|
15 | + $pluginInfo['items']['partner']['url'] = 'partner.php?partnerid=%u'; |
|
16 | + $pluginInfo['items']['partner']['request'] = 'partnerid'; |
|
17 | 17 | |
18 | - $pluginInfo['items']['category']['caption'] = 'Category'; |
|
19 | - $pluginInfo['items']['category']['url'] = 'index.php?view_category_id=%u'; |
|
20 | - $pluginInfo['items']['category']['request'] = 'view_category_id'; |
|
18 | + $pluginInfo['items']['category']['caption'] = 'Category'; |
|
19 | + $pluginInfo['items']['category']['url'] = 'index.php?view_category_id=%u'; |
|
20 | + $pluginInfo['items']['category']['request'] = 'view_category_id'; |
|
21 | 21 | |
22 | - return $pluginInfo; |
|
22 | + return $pluginInfo; |
|
23 | 23 | } |
@@ -9,15 +9,15 @@ |
||
9 | 9 | |
10 | 10 | function smartobject_plugin_smartsection() |
11 | 11 | { |
12 | - $pluginInfo = array(); |
|
12 | + $pluginInfo = array(); |
|
13 | 13 | |
14 | - $pluginInfo['items']['item']['caption'] = 'Article'; |
|
15 | - $pluginInfo['items']['item']['url'] = 'item.php?itemid=%u'; |
|
16 | - $pluginInfo['items']['item']['request'] = 'itemid'; |
|
14 | + $pluginInfo['items']['item']['caption'] = 'Article'; |
|
15 | + $pluginInfo['items']['item']['url'] = 'item.php?itemid=%u'; |
|
16 | + $pluginInfo['items']['item']['request'] = 'itemid'; |
|
17 | 17 | |
18 | - $pluginInfo['items']['category']['caption'] = 'Category'; |
|
19 | - $pluginInfo['items']['category']['url'] = 'category.php?categoryid=%u'; |
|
20 | - $pluginInfo['items']['category']['request'] = 'categoryid'; |
|
18 | + $pluginInfo['items']['category']['caption'] = 'Category'; |
|
19 | + $pluginInfo['items']['category']['url'] = 'category.php?categoryid=%u'; |
|
20 | + $pluginInfo['items']['category']['request'] = 'categoryid'; |
|
21 | 21 | |
22 | - return $pluginInfo; |
|
22 | + return $pluginInfo; |
|
23 | 23 | } |
@@ -9,12 +9,12 @@ |
||
9 | 9 | |
10 | 10 | function smartobject_plugin_xcgal() |
11 | 11 | { |
12 | - global $xoopsConfig; |
|
12 | + global $xoopsConfig; |
|
13 | 13 | |
14 | - $pluginInfo = array(); |
|
15 | - $pluginInfo['items']['album']['caption'] = 'Album'; |
|
16 | - $pluginInfo['items']['item']['url'] = 'thumbnails.php?album=%u'; |
|
17 | - $pluginInfo['items']['item']['request'] = 'album'; |
|
14 | + $pluginInfo = array(); |
|
15 | + $pluginInfo['items']['album']['caption'] = 'Album'; |
|
16 | + $pluginInfo['items']['item']['url'] = 'thumbnails.php?album=%u'; |
|
17 | + $pluginInfo['items']['item']['request'] = 'album'; |
|
18 | 18 | |
19 | - return $pluginInfo; |
|
19 | + return $pluginInfo; |
|
20 | 20 | } |
@@ -9,15 +9,15 @@ |
||
9 | 9 | |
10 | 10 | function smartobject_plugin_smartshop() |
11 | 11 | { |
12 | - $pluginInfo = array(); |
|
12 | + $pluginInfo = array(); |
|
13 | 13 | |
14 | - $pluginInfo['items']['item']['caption'] = 'Item'; |
|
15 | - $pluginInfo['items']['item']['url'] = 'item.php?itemid=%u'; |
|
16 | - $pluginInfo['items']['item']['request'] = 'itemid'; |
|
14 | + $pluginInfo['items']['item']['caption'] = 'Item'; |
|
15 | + $pluginInfo['items']['item']['url'] = 'item.php?itemid=%u'; |
|
16 | + $pluginInfo['items']['item']['request'] = 'itemid'; |
|
17 | 17 | |
18 | - $pluginInfo['items']['category']['caption'] = 'Category'; |
|
19 | - $pluginInfo['items']['category']['url'] = 'category.php?categoryid=%u'; |
|
20 | - $pluginInfo['items']['category']['request'] = 'categoryid'; |
|
18 | + $pluginInfo['items']['category']['caption'] = 'Category'; |
|
19 | + $pluginInfo['items']['category']['url'] = 'category.php?categoryid=%u'; |
|
20 | + $pluginInfo['items']['category']['request'] = 'categoryid'; |
|
21 | 21 | |
22 | - return $pluginInfo; |
|
22 | + return $pluginInfo; |
|
23 | 23 | } |