コード例 #1
0
    /**
     * 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;
    }
コード例 #2
0
 /**
  * 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;
 }