@@ -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 | } |
@@ -28,26 +28,26 @@ discard block |
||
| 28 | 28 | */ |
| 29 | 29 | function xoops_module_update_smartobject(XoopsModule $module) |
| 30 | 30 | { |
| 31 | - ob_start(); |
|
| 31 | + ob_start(); |
|
| 32 | 32 | |
| 33 | - $dbVersion = smart_GetMeta('version', 'smartobject'); |
|
| 34 | - if (!$dbVersion) { |
|
| 35 | - $dbVersion = 0; |
|
| 36 | - } |
|
| 33 | + $dbVersion = smart_GetMeta('version', 'smartobject'); |
|
| 34 | + if (!$dbVersion) { |
|
| 35 | + $dbVersion = 0; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - $dbupdater = new SmartobjectDbupdater(); |
|
| 38 | + $dbupdater = new SmartobjectDbupdater(); |
|
| 39 | 39 | |
| 40 | - echo '<code>' . _SDU_UPDATE_UPDATING_DATABASE . '<br>'; |
|
| 40 | + echo '<code>' . _SDU_UPDATE_UPDATING_DATABASE . '<br>'; |
|
| 41 | 41 | |
| 42 | - // db migrate version = 1 |
|
| 43 | - $newDbVersion = 1; |
|
| 44 | - if ($dbVersion < $newDbVersion) { |
|
| 45 | - echo 'Database migrate to version ' . $newDbVersion . '<br>'; |
|
| 42 | + // db migrate version = 1 |
|
| 43 | + $newDbVersion = 1; |
|
| 44 | + if ($dbVersion < $newDbVersion) { |
|
| 45 | + echo 'Database migrate to version ' . $newDbVersion . '<br>'; |
|
| 46 | 46 | |
| 47 | - // Create table smartobject_link |
|
| 48 | - $table = new SmartDbTable('smartobject_link'); |
|
| 49 | - if (!$table->exists()) { |
|
| 50 | - $table->setStructure("CREATE TABLE %s ( |
|
| 47 | + // Create table smartobject_link |
|
| 48 | + $table = new SmartDbTable('smartobject_link'); |
|
| 49 | + if (!$table->exists()) { |
|
| 50 | + $table->setStructure("CREATE TABLE %s ( |
|
| 51 | 51 | `linkid` int(11) NOT NULL auto_increment, |
| 52 | 52 | `from_uid` int(11) NOT NULL default '0', |
| 53 | 53 | `from_email` varchar(255) NOT NULL default '', |
@@ -64,63 +64,63 @@ discard block |
||
| 64 | 64 | PRIMARY KEY (`linkid`) |
| 65 | 65 | ) ENGINE=MyISAM COMMENT='SmartObject by The SmartFactory <www.smartfactory.ca>' AUTO_INCREMENT=1 ;"); |
| 66 | 66 | |
| 67 | - if (!$dbupdater->updateTable($table)) { |
|
| 68 | - /** |
|
| 69 | - * @todo trap the errors |
|
| 70 | - */ |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - unset($table); |
|
| 74 | - // Create table smartobject_link |
|
| 75 | - $table = new SmartDbTable('smartobject_link'); |
|
| 76 | - if (!$table->fieldExists('date')) { |
|
| 77 | - $table->addNewField('date', "int(11) NOT NULL default '0'"); |
|
| 78 | - if (!$dbupdater->updateTable($table)) { |
|
| 79 | - /** |
|
| 80 | - * @todo trap the errors |
|
| 81 | - */ |
|
| 82 | - } |
|
| 83 | - } |
|
| 84 | - unset($table); |
|
| 85 | - |
|
| 86 | - // Create table smartobject_tag |
|
| 87 | - $table = new SmartDbTable('smartobject_tag'); |
|
| 88 | - if (!$table->exists()) { |
|
| 89 | - $table->setStructure("CREATE TABLE %s ( |
|
| 67 | + if (!$dbupdater->updateTable($table)) { |
|
| 68 | + /** |
|
| 69 | + * @todo trap the errors |
|
| 70 | + */ |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + unset($table); |
|
| 74 | + // Create table smartobject_link |
|
| 75 | + $table = new SmartDbTable('smartobject_link'); |
|
| 76 | + if (!$table->fieldExists('date')) { |
|
| 77 | + $table->addNewField('date', "int(11) NOT NULL default '0'"); |
|
| 78 | + if (!$dbupdater->updateTable($table)) { |
|
| 79 | + /** |
|
| 80 | + * @todo trap the errors |
|
| 81 | + */ |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + unset($table); |
|
| 85 | + |
|
| 86 | + // Create table smartobject_tag |
|
| 87 | + $table = new SmartDbTable('smartobject_tag'); |
|
| 88 | + if (!$table->exists()) { |
|
| 89 | + $table->setStructure("CREATE TABLE %s ( |
|
| 90 | 90 | `tagid` int(11) NOT NULL auto_increment, |
| 91 | 91 | `name` varchar(255) NOT NULL default '', |
| 92 | 92 | `description` TEXT NOT NULL, |
| 93 | 93 | PRIMARY KEY (`id`) |
| 94 | 94 | ) ENGINE=MyISAM COMMENT='SmartObject by The SmartFactory <www.smartfactory.ca>' AUTO_INCREMENT=1 ;"); |
| 95 | 95 | |
| 96 | - if (!$dbupdater->updateTable($table)) { |
|
| 97 | - /** |
|
| 98 | - * @todo trap the errors |
|
| 99 | - */ |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - // Create table smartobject_tag_text |
|
| 104 | - $table = new SmartDbTable('smartobject_tag_text'); |
|
| 105 | - if (!$table->exists()) { |
|
| 106 | - $table->setStructure("CREATE TABLE %s ( |
|
| 96 | + if (!$dbupdater->updateTable($table)) { |
|
| 97 | + /** |
|
| 98 | + * @todo trap the errors |
|
| 99 | + */ |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + // Create table smartobject_tag_text |
|
| 104 | + $table = new SmartDbTable('smartobject_tag_text'); |
|
| 105 | + if (!$table->exists()) { |
|
| 106 | + $table->setStructure("CREATE TABLE %s ( |
|
| 107 | 107 | `tagid` int(11) NOT NULL default 0, |
| 108 | 108 | `language` varchar(255) NOT NULL default '', |
| 109 | 109 | `value` TEXT NOT NULL, |
| 110 | 110 | PRIMARY KEY (`id`, `language`) |
| 111 | 111 | ) ENGINE=MyISAM COMMENT='SmartObject by The SmartFactory <www.smartfactory.ca>' AUTO_INCREMENT=1 ;"); |
| 112 | 112 | |
| 113 | - if (!$dbupdater->updateTable($table)) { |
|
| 114 | - /** |
|
| 115 | - * @todo trap the errors |
|
| 116 | - */ |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - // Create table smartobject_adsense |
|
| 121 | - $table = new SmartDbTable('smartobject_adsense'); |
|
| 122 | - if (!$table->exists()) { |
|
| 123 | - $table->setStructure(" |
|
| 113 | + if (!$dbupdater->updateTable($table)) { |
|
| 114 | + /** |
|
| 115 | + * @todo trap the errors |
|
| 116 | + */ |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + // Create table smartobject_adsense |
|
| 121 | + $table = new SmartDbTable('smartobject_adsense'); |
|
| 122 | + if (!$table->exists()) { |
|
| 123 | + $table->setStructure(" |
|
| 124 | 124 | `adsenseid` int(11) NOT NULL auto_increment, |
| 125 | 125 | `format` VARCHAR(100) NOT NULL, |
| 126 | 126 | `description` TEXT NOT NULL, |
@@ -134,23 +134,23 @@ discard block |
||
| 134 | 134 | `tag` varchar(50) NOT NULL default '', |
| 135 | 135 | PRIMARY KEY (`adsenseid`) |
| 136 | 136 | "); |
| 137 | - } |
|
| 138 | - |
|
| 139 | - if (!$dbupdater->updateTable($table)) { |
|
| 140 | - /** |
|
| 141 | - * @todo trap the errors |
|
| 142 | - */ |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - // db migrate version = 2 |
|
| 146 | - $newDbVersion = 2; |
|
| 147 | - if ($dbVersion < $newDbVersion) { |
|
| 148 | - echo 'Database migrate to version ' . $newDbVersion . '<br>'; |
|
| 149 | - |
|
| 150 | - // Create table smartobject_rating |
|
| 151 | - $table = new SmartDbTable('smartobject_rating'); |
|
| 152 | - if (!$table->exists()) { |
|
| 153 | - $table->setStructure(' |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + if (!$dbupdater->updateTable($table)) { |
|
| 140 | + /** |
|
| 141 | + * @todo trap the errors |
|
| 142 | + */ |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + // db migrate version = 2 |
|
| 146 | + $newDbVersion = 2; |
|
| 147 | + if ($dbVersion < $newDbVersion) { |
|
| 148 | + echo 'Database migrate to version ' . $newDbVersion . '<br>'; |
|
| 149 | + |
|
| 150 | + // Create table smartobject_rating |
|
| 151 | + $table = new SmartDbTable('smartobject_rating'); |
|
| 152 | + if (!$table->exists()) { |
|
| 153 | + $table->setStructure(' |
|
| 154 | 154 | `ratingid` int(11) NOT NULL auto_increment, |
| 155 | 155 | `dirname` VARCHAR(255) NOT NULL, |
| 156 | 156 | `item` VARCHAR(255) NOT NULL, |
@@ -161,36 +161,36 @@ discard block |
||
| 161 | 161 | PRIMARY KEY (`ratingid`), |
| 162 | 162 | UNIQUE (`dirname`, `item`, `itemid`, `uid`) |
| 163 | 163 | '); |
| 164 | - } |
|
| 165 | - |
|
| 166 | - if (!$dbupdater->updateTable($table)) { |
|
| 167 | - /** |
|
| 168 | - * @todo trap the errors |
|
| 169 | - */ |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - // Create table smartobject_currency |
|
| 173 | - $table = new SmartDbTable('smartobject_currency'); |
|
| 174 | - $table->setData("2, 'EUR', 'Euro', '�', 0.65, 0"); |
|
| 175 | - $table->setData("3, 'USD', 'American dollar', '$', 0.9, 0"); |
|
| 176 | - $table->setData("1, 'CAD', 'Canadian dollar', '$', 1, 1"); |
|
| 177 | - |
|
| 178 | - if (!$dbupdater->updateTable($table)) { |
|
| 179 | - /** |
|
| 180 | - * @todo trap the errors |
|
| 181 | - */ |
|
| 182 | - } |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - // db migrate version = 3 |
|
| 186 | - $newDbVersion = 3; |
|
| 187 | - if ($dbVersion < $newDbVersion) { |
|
| 188 | - echo 'Database migrate to version ' . $newDbVersion . '<br>'; |
|
| 189 | - |
|
| 190 | - // Create table smartobject_customtag |
|
| 191 | - $table = new SmartDbTable('smartobject_customtag'); |
|
| 192 | - if (!$table->exists()) { |
|
| 193 | - $table->setStructure(' |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + if (!$dbupdater->updateTable($table)) { |
|
| 167 | + /** |
|
| 168 | + * @todo trap the errors |
|
| 169 | + */ |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + // Create table smartobject_currency |
|
| 173 | + $table = new SmartDbTable('smartobject_currency'); |
|
| 174 | + $table->setData("2, 'EUR', 'Euro', '�', 0.65, 0"); |
|
| 175 | + $table->setData("3, 'USD', 'American dollar', '$', 0.9, 0"); |
|
| 176 | + $table->setData("1, 'CAD', 'Canadian dollar', '$', 1, 1"); |
|
| 177 | + |
|
| 178 | + if (!$dbupdater->updateTable($table)) { |
|
| 179 | + /** |
|
| 180 | + * @todo trap the errors |
|
| 181 | + */ |
|
| 182 | + } |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + // db migrate version = 3 |
|
| 186 | + $newDbVersion = 3; |
|
| 187 | + if ($dbVersion < $newDbVersion) { |
|
| 188 | + echo 'Database migrate to version ' . $newDbVersion . '<br>'; |
|
| 189 | + |
|
| 190 | + // Create table smartobject_customtag |
|
| 191 | + $table = new SmartDbTable('smartobject_customtag'); |
|
| 192 | + if (!$table->exists()) { |
|
| 193 | + $table->setStructure(' |
|
| 194 | 194 | `customtagid` int(11) NOT NULL auto_increment, |
| 195 | 195 | `name` VARCHAR(255) NOT NULL, |
| 196 | 196 | `description` TEXT NOT NULL, |
@@ -198,24 +198,24 @@ discard block |
||
| 198 | 198 | `language` TEXT NOT NULL, |
| 199 | 199 | PRIMARY KEY (`customtagid`) |
| 200 | 200 | '); |
| 201 | - } |
|
| 202 | - |
|
| 203 | - if (!$dbupdater->updateTable($table)) { |
|
| 204 | - /** |
|
| 205 | - * @todo trap the errors |
|
| 206 | - */ |
|
| 207 | - } |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - // db migrate version = 4 |
|
| 211 | - $newDbVersion = 4; |
|
| 212 | - if ($dbVersion < $newDbVersion) { |
|
| 213 | - echo 'Database migrate to version ' . $newDbVersion . '<br>'; |
|
| 214 | - |
|
| 215 | - // Create table smartobject_currency |
|
| 216 | - $table = new SmartDbTable('smartobject_currency'); |
|
| 217 | - if (!$table->exists()) { |
|
| 218 | - $table->setStructure(' |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + if (!$dbupdater->updateTable($table)) { |
|
| 204 | + /** |
|
| 205 | + * @todo trap the errors |
|
| 206 | + */ |
|
| 207 | + } |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + // db migrate version = 4 |
|
| 211 | + $newDbVersion = 4; |
|
| 212 | + if ($dbVersion < $newDbVersion) { |
|
| 213 | + echo 'Database migrate to version ' . $newDbVersion . '<br>'; |
|
| 214 | + |
|
| 215 | + // Create table smartobject_currency |
|
| 216 | + $table = new SmartDbTable('smartobject_currency'); |
|
| 217 | + if (!$table->exists()) { |
|
| 218 | + $table->setStructure(' |
|
| 219 | 219 | `currencyid` int(11) NOT NULL auto_increment, |
| 220 | 220 | `iso4217` VARCHAR(5) NOT NULL, |
| 221 | 221 | `name` VARCHAR(255) NOT NULL, |
@@ -224,46 +224,46 @@ discard block |
||
| 224 | 224 | `default_currency` int(1) NOT NULL, |
| 225 | 225 | PRIMARY KEY (`currencyid`) |
| 226 | 226 | '); |
| 227 | - } |
|
| 228 | - |
|
| 229 | - if (!$dbupdater->updateTable($table)) { |
|
| 230 | - /** |
|
| 231 | - * @todo trap the errors |
|
| 232 | - */ |
|
| 233 | - } |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - // db migrate version = 6 |
|
| 237 | - $newDbVersion = 6; |
|
| 238 | - if ($dbVersion < $newDbVersion) { |
|
| 239 | - echo 'Database migrate to version ' . $newDbVersion . '<br>'; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - $newDbVersion = 7; |
|
| 243 | - if ($dbVersion < $newDbVersion) { |
|
| 244 | - echo 'Database migrate to version ' . $newDbVersion . '<br>'; |
|
| 245 | - |
|
| 246 | - // Create table smartobject_file |
|
| 247 | - $table = new SmartDbTable('smartobject_file'); |
|
| 248 | - if (!$table->exists()) { |
|
| 249 | - $table->setStructure(' |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + if (!$dbupdater->updateTable($table)) { |
|
| 230 | + /** |
|
| 231 | + * @todo trap the errors |
|
| 232 | + */ |
|
| 233 | + } |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + // db migrate version = 6 |
|
| 237 | + $newDbVersion = 6; |
|
| 238 | + if ($dbVersion < $newDbVersion) { |
|
| 239 | + echo 'Database migrate to version ' . $newDbVersion . '<br>'; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + $newDbVersion = 7; |
|
| 243 | + if ($dbVersion < $newDbVersion) { |
|
| 244 | + echo 'Database migrate to version ' . $newDbVersion . '<br>'; |
|
| 245 | + |
|
| 246 | + // Create table smartobject_file |
|
| 247 | + $table = new SmartDbTable('smartobject_file'); |
|
| 248 | + if (!$table->exists()) { |
|
| 249 | + $table->setStructure(' |
|
| 250 | 250 | `fileid` int(11) NOT NULL auto_increment, |
| 251 | 251 | `caption` varchar(255) collate latin1_general_ci NOT NULL, |
| 252 | 252 | `url` varchar(255) collate latin1_general_ci NOT NULL, |
| 253 | 253 | `description` text collate latin1_general_ci NOT NULL, |
| 254 | 254 | PRIMARY KEY (`fileid`) |
| 255 | 255 | '); |
| 256 | - if (!$dbupdater->updateTable($table)) { |
|
| 257 | - /** |
|
| 258 | - * @todo trap the errors |
|
| 259 | - */ |
|
| 260 | - } |
|
| 261 | - } |
|
| 262 | - unset($table); |
|
| 263 | - // Create table smartobject_urllink |
|
| 264 | - $table = new SmartDbTable('smartobject_urllink'); |
|
| 265 | - if (!$table->exists()) { |
|
| 266 | - $table->setStructure(' |
|
| 256 | + if (!$dbupdater->updateTable($table)) { |
|
| 257 | + /** |
|
| 258 | + * @todo trap the errors |
|
| 259 | + */ |
|
| 260 | + } |
|
| 261 | + } |
|
| 262 | + unset($table); |
|
| 263 | + // Create table smartobject_urllink |
|
| 264 | + $table = new SmartDbTable('smartobject_urllink'); |
|
| 265 | + if (!$table->exists()) { |
|
| 266 | + $table->setStructure(' |
|
| 267 | 267 | `urllinkid` int(11) NOT NULL auto_increment, |
| 268 | 268 | `caption` varchar(255) collate latin1_general_ci NOT NULL, |
| 269 | 269 | `url` varchar(255) collate latin1_general_ci NOT NULL, |
@@ -271,25 +271,25 @@ discard block |
||
| 271 | 271 | `target` varchar(10) collate latin1_general_ci NOT NULL, |
| 272 | 272 | PRIMARY KEY (`urllinkid`) |
| 273 | 273 | '); |
| 274 | - if (!$dbupdater->updateTable($table)) { |
|
| 275 | - /** |
|
| 276 | - * @todo trap the errors |
|
| 277 | - */ |
|
| 278 | - } |
|
| 279 | - } |
|
| 280 | - unset($table); |
|
| 281 | - } |
|
| 282 | - echo '</code>'; |
|
| 283 | - |
|
| 284 | - $feedback = ob_get_clean(); |
|
| 285 | - if (method_exists($module, 'setMessage')) { |
|
| 286 | - $module->setMessage($feedback); |
|
| 287 | - } else { |
|
| 288 | - echo $feedback; |
|
| 289 | - } |
|
| 290 | - smart_SetMeta('version', $newDbVersion, 'smartobject'); //Set meta version to current |
|
| 291 | - |
|
| 292 | - return true; |
|
| 274 | + if (!$dbupdater->updateTable($table)) { |
|
| 275 | + /** |
|
| 276 | + * @todo trap the errors |
|
| 277 | + */ |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | + unset($table); |
|
| 281 | + } |
|
| 282 | + echo '</code>'; |
|
| 283 | + |
|
| 284 | + $feedback = ob_get_clean(); |
|
| 285 | + if (method_exists($module, 'setMessage')) { |
|
| 286 | + $module->setMessage($feedback); |
|
| 287 | + } else { |
|
| 288 | + echo $feedback; |
|
| 289 | + } |
|
| 290 | + smart_SetMeta('version', $newDbVersion, 'smartobject'); //Set meta version to current |
|
| 291 | + |
|
| 292 | + return true; |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | /** |
@@ -298,10 +298,10 @@ discard block |
||
| 298 | 298 | */ |
| 299 | 299 | function xoops_module_install_smartobject(XoopsModule $module) |
| 300 | 300 | { |
| 301 | - ob_start(); |
|
| 301 | + ob_start(); |
|
| 302 | 302 | |
| 303 | - echo 'Using the ImpressCMS onInstall event'; |
|
| 304 | - $feedback = ob_get_clean(); |
|
| 303 | + echo 'Using the ImpressCMS onInstall event'; |
|
| 304 | + $feedback = ob_get_clean(); |
|
| 305 | 305 | |
| 306 | - return $feedback; |
|
| 306 | + return $feedback; |
|
| 307 | 307 | } |
@@ -9,17 +9,17 @@ |
||
| 9 | 9 | |
| 10 | 10 | function smartobject_plugin_smartband() |
| 11 | 11 | { |
| 12 | - global $xoopsConfig; |
|
| 13 | - require_once XOOPS_ROOT_PATH . '/modules/smartband/language/' . $xoopsConfig['language'] . '/main.php'; |
|
| 12 | + global $xoopsConfig; |
|
| 13 | + require_once XOOPS_ROOT_PATH . '/modules/smartband/language/' . $xoopsConfig['language'] . '/main.php'; |
|
| 14 | 14 | |
| 15 | - $pluginInfo = array(); |
|
| 16 | - $pluginInfo['items']['item']['caption'] = _MD_ARTALBUM_ITEM_CAP; |
|
| 17 | - $pluginInfo['items']['item']['url'] = 'item.php?itemid=%u'; |
|
| 18 | - $pluginInfo['items']['item']['request'] = 'itemid'; |
|
| 15 | + $pluginInfo = array(); |
|
| 16 | + $pluginInfo['items']['item']['caption'] = _MD_ARTALBUM_ITEM_CAP; |
|
| 17 | + $pluginInfo['items']['item']['url'] = 'item.php?itemid=%u'; |
|
| 18 | + $pluginInfo['items']['item']['request'] = 'itemid'; |
|
| 19 | 19 | |
| 20 | - $pluginInfo['items']['category']['caption'] = _MD_ARTALBUM_CATEGORY; |
|
| 21 | - $pluginInfo['items']['category']['url'] = 'category.php?categoryid=%u'; |
|
| 22 | - $pluginInfo['items']['category']['request'] = 'categoryid'; |
|
| 20 | + $pluginInfo['items']['category']['caption'] = _MD_ARTALBUM_CATEGORY; |
|
| 21 | + $pluginInfo['items']['category']['url'] = 'category.php?categoryid=%u'; |
|
| 22 | + $pluginInfo['items']['category']['request'] = 'categoryid'; |
|
| 23 | 23 | |
| 24 | - return $pluginInfo; |
|
| 24 | + return $pluginInfo; |
|
| 25 | 25 | } |
@@ -66,10 +66,10 @@ |
||
| 66 | 66 | global $xoopsConfig; |
| 67 | 67 | $common_file = XOOPS_ROOT_PATH . '/modules/smartobject/language/' . $xoopsConfig['language'] . '/common.php'; |
| 68 | 68 | if (file_exists($common_file)) { |
| 69 | - $flag_common = true; |
|
| 70 | - require_once $common_file; |
|
| 69 | + $flag_common = true; |
|
| 70 | + require_once $common_file; |
|
| 71 | 71 | } else { |
| 72 | - require_once XOOPS_ROOT_PATH . '/modules/smartobject/language/english/common.php'; |
|
| 72 | + require_once XOOPS_ROOT_PATH . '/modules/smartobject/language/english/common.php'; |
|
| 73 | 73 | } |
| 74 | 74 | // ----- |
| 75 | 75 | |