/** * Loads javascript and styles for ajax pagination * */ public function loadJsCss() { $assetsUrl = !empty($this->pdoTools->config['assetsUrl']) ? $this->pdoTools->config['assetsUrl'] : MODX_ASSETS_URL . 'components/pdotools/'; if ($css = trim($this->pdoTools->config['frontend_css'])) { $this->modx->regClientCSS(str_replace('[[+assetsUrl]]', $assetsUrl, $css)); } if ($js = trim($this->pdoTools->config['frontend_js'])) { $this->modx->regClientScript(str_replace('[[+assetsUrl]]', $assetsUrl, $js)); } $limit = $this->pdoTools->config['limit'] > $this->pdoTools->config['maxLimit'] ? $this->pdoTools->config['maxLimit'] : $this->pdoTools->config['limit']; $moreChunk = $this->modx->getOption('ajaxTplMore', $this->pdoTools->config, '@INLINE <button class="btn btn-default btn-more">[[%pdopage_more]]</button>'); $moreTpl = str_replace('"', '\\"', $this->pdoTools->getChunk($moreChunk, array('limit' => $limit))); $config = '{ wrapper: "' . $this->modx->getOption('ajaxElemWrapper', $this->pdoTools->config, '#pdopage') . '", rows: "' . $this->modx->getOption('ajaxElemRows', $this->pdoTools->config, '#pdopage .rows') . '", pagination: "' . $this->modx->getOption('ajaxElemPagination', $this->pdoTools->config, '#pdopage .pagination') . '", link: "' . $this->modx->getOption('ajaxElemLink', $this->pdoTools->config, '#pdopage .pagination a') . '", more: "' . $this->modx->getOption('ajaxElemMore', $this->pdoTools->config, '#pdopage .btn-more') . '", moreTpl: "' . $moreTpl . '", mode: "' . $this->pdoTools->config['ajaxMode'] . '", pageVarKey: "' . $this->pdoTools->config['pageVarKey'] . '", pageLimit: ' . $limit . ', assetsUrl: "' . $assetsUrl . '" }'; $this->modx->regClientStartupScript('<script type="text/javascript">pdoPage = {callbacks: {}, keys: {}};</script>', true); $this->modx->regClientScript('<script type="text/javascript">pdoPage.initialize(' . $config . ');</script>', true); }
/** * Init scripts and add/delete only once */ public function init() { if (!$this->getOption('init', null, false)) { if ($this->getOption('includeScripts')) { if ($this->getOption('jQueryPath') != '') { $this->modx->regClientScript($this->getOption('jQueryPath')); } $this->modx->regClientScript($this->getOption('assetsUrl') . 'js/rememberthis.min.js?v=' . $this->getOption('version')); $script = $this->modx->getChunk($this->getOption('scriptTpl'), array('options' => json_encode($this->getOption('scriptOptions')))); $this->modx->regClientScript($script); } if ($this->getOption('includeCss')) { $this->modx->regClientCSS($this->getOption('assetsUrl') . 'css/rememberthis.css?v=' . $this->getOption('version')); } if ($this->getOption('useCookie')) { $this->getCookie(); } // Add/remove items to/from the list if (isset($_GET[$this->getOption('queryAdd')])) { $this->add($_GET[$this->getOption('queryAdd')]); } if (isset($_GET[$this->getOption('queryDelete')])) { $this->delete(intval($_GET[$this->getOption('queryDelete')])); } $this->setOption('init', true); } }
/** * Initializes component into different contexts. * * @param string $ctx The context to load. Defaults to web. * @param array $scriptProperties * * @return boolean */ public function initialize($ctx = 'web', $scriptProperties = array()) { $this->config = array_merge($this->config, $scriptProperties); $this->config['ctx'] = $ctx; if (empty($this->initialized[$ctx])) { $properties = $this->ms2Gallery->getSourceProperties(); $config_js = array('ctx' => $ctx, 'jsUrl' => $this->config['jsUrl'] . 'web/', 'cssUrl' => $this->config['cssUrl'] . 'web/', 'actionUrl' => $this->config['actionUrl'], 'source' => array('size' => !empty($properties['maxUploadSize']) ? $properties['maxUploadSize'] : 3145728, 'height' => !empty($properties['maxUploadHeight']) ? $properties['maxUploadHeight'] : 1080, 'width' => !empty($properties['maxUploadWidth']) ? $properties['maxUploadWidth'] : 1920, 'extensions' => !empty($properties['allowedFileTypes']) ? $properties['allowedFileTypes'] : 'jpg,jpeg,png,gif')); $this->modx->regClientStartupScript('<script type="text/javascript">ms2GalleryFormConfig=' . $this->modx->toJSON($config_js) . '</script>', true); $css = !empty($this->config['frontend_css']) ? $this->config['frontend_css'] : $this->config['cssUrl'] . 'web/default.css'; if (!empty($css) && preg_match('/\\.css/i', $css)) { $this->modx->regClientCSS($css); } $js = !empty($this->config['frontend_js']) ? $this->config['frontend_js'] : $this->config['jsUrl'] . 'web/default.js'; if (!empty($js) && preg_match('/\\.js/i', $js)) { $this->modx->regClientScript($js); } $this->modx->regClientScript($this->config['jsUrl'] . 'web/lib/plupload/plupload.full.min.js'); $this->modx->regClientScript($this->config['jsUrl'] . 'web/files.js'); $lang = $this->modx->getOption('cultureKey'); if ($lang != 'en' && file_exists($this->config['jsUrl'] . 'web/lib/plupload/i18n/' . $lang . '.js')) { $this->modx->regClientScript($this->config['jsUrl'] . 'web/lib/plupload/i18n/' . $lang . '.js'); } $this->initialized[$ctx] = true; } return true; }
/** * Independent registration of css and js * * @param string $objectName Name of object to initialize in javascript */ public function loadJsCss($objectName = 'AjaxForm') { if ($css = trim($this->config['frontend_css'])) { if (preg_match('/\\.css/i', $css)) { $this->modx->regClientCSS(str_replace('[[+assetsUrl]]', $this->config['assetsUrl'], $css)); } } if ($js = trim($this->config['frontend_js'])) { if (preg_match('/\\.js$/i', $js)) { $this->modx->regClientScript(str_replace('[[+assetsUrl]]', $this->config['assetsUrl'], $js)); } } $config = $this->modx->toJSON(array('assetsUrl' => $this->config['assetsUrl'], 'actionUrl' => str_replace('[[+assetsUrl]]', $this->config['assetsUrl'], $this->config['actionUrl']), 'closeMessage' => $this->config['closeMessage'], 'formSelector' => "form.{$this->config['formSelector']}", 'pageId' => !empty($this->modx->resource) ? $this->modx->resource->get('id') : 0)); $this->modx->regClientScript('<script type="text/javascript">' . trim($objectName) . '.initialize(' . $config . ');</script>', true); }
/** * Initializes AjaxForm into different contexts. * * @param string $ctx The context to load. Defaults to web. * @param array $scriptProperties array with additional parameters * * @return boolean */ public function initialize($ctx = 'web', $scriptProperties = array()) { $this->config = array_merge($this->config, $scriptProperties); $this->config['ctx'] = $ctx; if (!empty($this->initialized[$ctx])) { return true; } switch ($ctx) { case 'mgr': break; default: if (!defined('MODX_API_MODE') || !MODX_API_MODE) { if ($css = trim($this->config['frontend_css'])) { if (preg_match('/\\.css/i', $css)) { $this->modx->regClientCSS(str_replace('[[+assetsUrl]]', $this->config['assetsUrl'], $css)); } } $config_js = preg_replace(array('/^\\n/', '/\\t{6}/'), '', ' afConfig = { assetsUrl: "' . $this->config['assetsUrl'] . '" ,actionUrl: "' . str_replace('[[+assetsUrl]]', $this->config['assetsUrl'], $this->config['actionUrl']) . '" ,closeMessage: "' . $this->config['closeMessage'] . '" ,formSelector: "form.' . $this->config['formSelector'] . '" }; '); if (file_put_contents($this->config['assetsPath'] . 'js/config.js', $config_js)) { $this->modx->regClientStartupScript($this->config['assetsUrl'] . 'js/config.js'); } else { $this->modx->regClientStartupScript("<script type=\"text/javascript\">\n" . $config_js . "\n</script>", true); } if ($js = trim($this->config['frontend_js'])) { if (preg_match('/\\.js/i', $js)) { $this->modx->regClientScript(preg_replace(array('/^\\n/', '/\\t{7}/'), '', ' <script type="text/javascript"> if(typeof jQuery == "undefined") { document.write("<script src=\\"' . $this->config['assetsUrl'] . 'js/lib/jquery.min.js\\" type=\\"text/javascript\\"><\\/script>"); } </script> '), true); $this->modx->regClientScript(str_replace('[[+assetsUrl]]', $this->config['assetsUrl'], $js)); } } } $this->initialized[$ctx] = true; break; } return true; }
/** * Initializes mSearch2 into different contexts. * * @param string $ctx The context to load. Defaults to web. * @param array $scriptProperties * * @return boolean */ public function initialize($ctx = 'web', $scriptProperties = array()) { switch ($ctx) { case 'mgr': if (!$this->modx->loadClass('msearch2.request.mSearch2ControllerRequest', $this->config['modelPath'], true, true)) { return 'Could not load controller request handler.'; } $this->request = new mSearch2ControllerRequest($this); return $this->request->handleRequest(); break; default: $this->config = array_merge($this->config, $scriptProperties); $this->config['ctx'] = $ctx; if (!defined('MODX_API_MODE') || !MODX_API_MODE) { $config = $this->makePlaceholders($this->config); if ($css = trim($this->modx->getOption('mse2_frontend_css'))) { $this->modx->regClientCSS(str_replace($config['pl'], $config['vl'], $css)); } if ($js = trim($this->modx->getOption('mse2_frontend_js'))) { $this->modx->regClientScript(str_replace($config['pl'], $config['vl'], $js)); } } } return true; }
/** * Output the form inputs. * * @access public * @return string The output */ public function output() { if ($this->config['addJquery']) { $this->modx->regClientScript('http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js'); } if ($this->config['addCss']) { $this->modx->regClientCSS($this->config['cssUrl'] . 'ajaxupload.css'); } if ($this->config['addJscript']) { $this->modx->regClientScript($this->config['jsUrl'] . 'fileuploader.js'); $this->modx->regClientScript($this->config['jsUrl'] . 'ajaxupload.js'); } $this->modx->smarty->assign('_lang', $this->modx->lexicon->fetch('ajaxupload.', true)); $this->modx->smarty->assign('params', $this->config); if (empty($this->config['filecopierPath'])) { $this->modx->regClientScript($this->modx->smarty->fetch($this->config['templatesPath'] . 'web/script.tpl'), true); } else { $this->modx->regClientStartupScript($this->modx->smarty->fetch($this->config['templatesPath'] . 'web/elfinder.tpl'), true); } // preload files from $_SESSION $itemList = ''; if (is_array($_SESSION['ajaxupload'][$this->config['uid']])) { $itemList = $this->loadFiles($_SESSION['ajaxupload'][$this->config['uid']]); } $this->modx->smarty->assign('items', $itemList); return $this->modx->smarty->fetch($this->config['templatesPath'] . 'web/uploadSection.tpl'); }
/** * Loads javascript and styles for ajax pagination * */ public function loadJsCss() { $assetsUrl = !empty($this->pdoTools->config['assetsUrl']) ? $this->pdoTools->config['assetsUrl'] : MODX_ASSETS_URL . 'components/pdotools/'; if ($css = trim($this->pdoTools->config['frontend_css'])) { $this->modx->regClientCSS(str_replace('[[+assetsUrl]]', $assetsUrl, $css)); } if ($js = trim($this->pdoTools->config['frontend_js'])) { $this->modx->regClientScript(str_replace('[[+assetsUrl]]', $assetsUrl, $js)); } $ajaxHistory = $this->pdoTools->config['ajaxHistory'] === '' ? !in_array($this->pdoTools->config['ajaxMode'], array('scroll', 'button')) : !empty($this->pdoTools->config['ajaxHistory']); $limit = $this->pdoTools->config['limit'] > $this->pdoTools->config['maxLimit'] ? $this->pdoTools->config['maxLimit'] : $this->pdoTools->config['limit']; $moreChunk = $this->modx->getOption('ajaxTplMore', $this->pdoTools->config, '@INLINE <button class="btn btn-default btn-more">[[%pdopage_more]]</button>'); $moreTpl = $this->pdoTools->getChunk($moreChunk, array('limit' => $limit)); $hash = sha1($this->modx->toJSON($this->pdoTools->config)); $_SESSION['pdoPage'][$hash] = $this->pdoTools->config; $config = $this->modx->toJSON(array('wrapper' => $this->modx->getOption('ajaxElemWrapper', $this->pdoTools->config, '#pdopage'), 'rows' => $this->modx->getOption('ajaxElemRows', $this->pdoTools->config, '#pdopage .rows'), 'pagination' => $this->modx->getOption('ajaxElemPagination', $this->pdoTools->config, '#pdopage .pagination'), 'link' => $this->modx->getOption('ajaxElemLink', $this->pdoTools->config, '#pdopage .pagination a'), 'more' => $this->modx->getOption('ajaxElemMore', $this->pdoTools->config, '#pdopage .btn-more'), 'moreTpl' => $moreTpl, 'mode' => $this->pdoTools->config['ajaxMode'], 'history' => (int) $ajaxHistory, 'pageVarKey' => $this->pdoTools->config['pageVarKey'], 'pageLimit' => $limit, 'assetsUrl' => $assetsUrl, 'connectorUrl' => rtrim($assetsUrl, '/') . '/connector.php', 'pageId' => $this->modx->resource->id, 'hash' => $hash)); $this->modx->regClientStartupScript('<script type="text/javascript">pdoPage = {callbacks: {}, keys: {}, configs: {}};</script>', true); $this->modx->regClientScript('<script type="text/javascript">pdoPage.initialize(' . $config . ');</script>', true); }
/** * @param $src * @param bool|false $plaintext */ public function regClientScript($src, $plaintext = false) { if (empty($this->modx->config['fenom_jscripts'])) { $this->modx->config['fenom_jscripts'] = array(); } $registered = count($this->modx->jscripts); $this->modx->regClientScript($src, $plaintext); $this->modx->config['fenom_jscripts'] = array_replace($this->modx->config['fenom_jscripts'], array_slice($this->modx->jscripts, $registered, null, true)); if (empty($this->modx->config['fenom_loadedscripts'])) { $this->modx->config['fenom_loadedscripts'] = array(); } $this->modx->config['fenom_loadedscripts'][$src] = true; }
/** * Initializes mSearch2 into different contexts. * * @access public * @param string $ctx The context to load. Defaults to web. * * @return boolean */ public function initialize($ctx = 'web', $scriptProperties = array()) { switch ($ctx) { case 'mgr': if (!$this->modx->loadClass('msearch2.request.mSearch2ControllerRequest', $this->config['modelPath'], true, true)) { return 'Could not load controller request handler.'; } $this->request = new mSearch2ControllerRequest($this); return $this->request->handleRequest(); break; default: $this->config = array_merge($this->config, $scriptProperties); $this->config['ctx'] = $ctx; if (!empty($this->initialized[$ctx])) { return true; } if (!defined('MODX_API_MODE') || !MODX_API_MODE) { $config = $this->makePlaceholders($this->config); if ($css = $this->modx->getOption('mse2_frontend_css')) { $this->modx->regClientCSS(str_replace($config['pl'], $config['vl'], $css)); } if ($js = trim($this->modx->getOption('mse2_frontend_js'))) { $this->modx->regClientStartupScript(str_replace(' ', '', ' <script type="text/javascript"> mSearch2Config = { cssUrl: "' . $this->config['cssUrl'] . 'web/" ,jsUrl: "' . $this->config['jsUrl'] . 'web/" ,actionUrl: "' . $this->config['actionUrl'] . '" ,pageId: ' . $this->modx->resource->id . ' ,filter_delimeter: "' . $this->config['filter_delimeter'] . '" ,method_delimeter: "' . $this->config['method_delimeter'] . '" ,values_delimeter: "' . $this->config['values_delimeter'] . '" }; </script> '), true); if (!empty($js) && preg_match('/\\.js$/i', $js)) { $this->modx->regClientScript(str_replace(' ', '', ' <script type="text/javascript"> if(typeof jQuery == "undefined") { document.write("<script src=\\"' . $this->config['jsUrl'] . 'web/lib/jquery.min.js\\" type=\\"text/javascript\\"><\\/script>"); } </script> '), true); $this->modx->regClientScript(str_replace($config['pl'], $config['vl'], $js)); } } } $this->initialized[$ctx] = true; } return true; }
/** * Initializes component into different contexts. * * @param string $ctx The context to load. Defaults to web. * @param array $scriptProperties Properties for initialization. * * @return bool */ public function initialize($ctx = 'web', $scriptProperties = array()) { $this->config = array_merge($this->config, $scriptProperties); $this->config['ctx'] = $ctx; if (!empty($this->initialized[$ctx])) { return true; } switch ($ctx) { case 'mgr': break; default: if (!MODX_API_MODE) { $config = $this->makePlaceholders($this->config); if ($css = $this->modx->getOption('uf_frontend_css')) { $this->modx->regClientCSS(str_replace($config['pl'], $config['vl'], $css)); } if ($js = $this->modx->getOption('uf_frontend_js')) { $time = time(); $this->modx->regClientStartupScript(str_replace(' ', '', ' <script type="text/javascript"> UploadifyConfig = { jsUrl: "' . $this->config['jsUrl'] . 'web/", actionUrl: "' . $this->config['actionUrl'] . '", cssUrl: "' . $this->config['cssUrl'] . 'web/", uploadiFive: ' . $this->config['uploadiFive'] . ' }; if(typeof jQuery == "undefined") { document.write("<script src=\\""+UploadifyConfig.jsUrl+"lib/jquery-1.9.1.min.js\\" type=\\"text/javascript\\"><\\/script>"); } </script> '), true); $this->modx->regClientScript(str_replace($config['pl'], $config['vl'], $js)); } } $this->initialized[$ctx] = true; break; } return true; }
/** * @param $src * @param bool|false $plaintext */ public function regClientScript($src, $plaintext = false) { $this->modx->regClientScript($src, $plaintext); }
/** * Initializes component into different contexts. * * @param string $ctx The context to load. Defaults to web. * @param array $scriptProperties Properties for initialization. * * @return bool */ public function initialize($ctx = 'web', $scriptProperties = array()) { $this->config = array_merge($this->config, $scriptProperties); $this->config['ctx'] = $ctx; if (!empty($this->initialized[$ctx])) { return true; } switch ($ctx) { case 'mgr': break; default: if (!defined('MODX_API_MODE') || !MODX_API_MODE) { $config = $this->makePlaceholders($this->config); if ($css = $this->modx->getOption('ms2_frontend_css')) { $this->modx->regClientCSS(str_replace($config['pl'], $config['vl'], $css)); } $config_js = preg_replace(array('/^\\n/', '/\\t{5}/'), '', ' miniShop2 = {}; miniShop2Config = { cssUrl: "' . $this->config['cssUrl'] . 'web/" ,jsUrl: "' . $this->config['jsUrl'] . 'web/" ,imagesUrl: "' . $this->config['imagesUrl'] . 'web/" ,actionUrl: "' . $this->config['actionUrl'] . '" ,ctx: "' . $this->modx->context->get('key') . '" ,close_all_message: "' . $this->modx->lexicon('ms2_message_close_all') . '" ,price_format: ' . $this->modx->getOption('ms2_price_format', null, '[2, ".", " "]') . ' ,price_format_no_zeros: ' . $this->modx->getOption('ms2_price_format_no_zeros', null, true) . ' ,weight_format: ' . $this->modx->getOption('ms2_weight_format', null, '[3, ".", " "]') . ' ,weight_format_no_zeros: ' . $this->modx->getOption('ms2_weight_format_no_zeros', null, true) . ' ,callbacksObjectTemplate: function() { return { before: function() {/*return false to prevent send data*/} ,response: {success: function(response) {},error: function(response) {}} ,ajax: {done: function(xhr) {},fail: function(xhr) {},always: function(xhr) {}} }; } }; miniShop2.Callbacks = miniShop2Config.Callbacks = { Cart: { add: miniShop2Config.callbacksObjectTemplate() ,remove: miniShop2Config.callbacksObjectTemplate() ,change: miniShop2Config.callbacksObjectTemplate() ,clean: miniShop2Config.callbacksObjectTemplate() } ,Order: { add: miniShop2Config.callbacksObjectTemplate() ,getcost: miniShop2Config.callbacksObjectTemplate() ,clean: miniShop2Config.callbacksObjectTemplate() ,submit: miniShop2Config.callbacksObjectTemplate() ,getRequired: miniShop2Config.callbacksObjectTemplate() } };'); if (file_put_contents($this->config['jsPath'] . 'web/config.js', $config_js)) { $this->modx->regClientStartupScript($this->config['jsUrl'] . 'web/config.js'); } else { $this->modx->regClientStartupScript("<script type=\"text/javascript\">\n" . $config_js . "\n</script>", true); } if ($js = trim($this->modx->getOption('ms2_frontend_js'))) { if (!empty($js) && preg_match('/\\.js/i', $js)) { $this->modx->regClientScript(preg_replace(array('/^\\n/', '/\\t{7}/'), '', ' <script type="text/javascript"> if(typeof jQuery == "undefined") { document.write("<script src=\\"' . $this->config['jsUrl'] . 'web/lib/jquery.min.js\\" type=\\"text/javascript\\"><\\/script>"); } </script> '), true); $this->modx->regClientScript(str_replace($config['pl'], $config['vl'], $js)); } } } require_once dirname(__FILE__) . '/mscarthandler.class.php'; $cart_class = $this->modx->getOption('ms2_cart_handler_class', null, 'msCartHandler'); if ($cart_class != 'msCartHandler') { $this->loadCustomClasses('cart'); } if (!class_exists($cart_class)) { $cart_class = 'msCartHandler'; } $this->cart = new $cart_class($this, $this->config); if (!$this->cart instanceof msCartInterface || $this->cart->initialize($ctx) !== true) { $this->modx->log(modX::LOG_LEVEL_ERROR, 'Could not initialize miniShop2 cart handler class: "' . $cart_class . '"'); return false; } require_once dirname(__FILE__) . '/msorderhandler.class.php'; $order_class = $this->modx->getOption('ms2_order_handler_class', null, 'msOrderHandler'); if ($order_class != 'msOrderHandler') { $this->loadCustomClasses('order'); } if (!class_exists($order_class)) { $order_class = 'msOrderHandler'; } $this->order = new $order_class($this, $this->config); if (!$this->order instanceof msOrderInterface || $this->order->initialize($ctx) !== true) { $this->modx->log(modX::LOG_LEVEL_ERROR, 'Could not initialize miniShop2 order handler class: "' . $order_class . '"'); return false; } $this->initialized[$ctx] = true; break; } return true; }
/** @inheritdoc} */ public function regBottomScript($script = '') { $this->modx->regClientScript(preg_replace('#(\\n|\\t)#', '', "\n\t\t\t\t<script type=\"text/javascript\">\n\t\t\t\t{$script}\n\t\t\t\t</script>\n\t\t"), true); }