Get a JavaScript parser

@param  array  $config Config array returned by the configurator
@return string         JavaScript parser
334052
public function getParser(array $config = null)
	{
		$this->configOptimizer->reset();

		// Get the stylesheet used for rendering
		$xslt      = new XSLT;
		$xslt->optimizer->normalizer->remove('RemoveLivePreviewAttributes');
		$this->xsl = $xslt->getXSL($this->configurator->rendering);

		// Prepare the parser's config
		$this->config = (isset($config)) ? $config : $this->configurator->asConfig();
		$this->config = ConfigHelper::filterConfig($this->config, 'JS');
		$this->config = $this->callbackGenerator->replaceCallbacks($this->config);

		// Get the parser's source and inject its config
		$src = $this->getHints() . $this->injectConfig($this->getSource());

		// Export the public API
		$src .= "if (!window['s9e']) window['s9e'] = {};\n" . $this->getExports();

		// Minify the source
		$src = $this->getMinifier()->get($src);

		// Wrap the source in a function to protect the global scope
		$src = '(function(){' . $src . '})()';

		return $src;
	}
413757
public function setConfig(array $config) {
        if (!$config) {
            return $this;
        }

        foreach ($config as $key => $value) {
            switch ($key) {
                case 'open':
                case 'close':
                    $this->setBrackets($config['open'], $config['close']);
                break;
                case 'locale':
                    $this->setLocale($value);
                break;
                case 'disable':
                case 'disabled':
                    $this->disable($value);
                break;
                case 'shorthand':
                case 'shorthandLinks':
                    $this->setShorthand($value);
                break;
                case 'xhtml':
                case 'xhtmlOutput':
                    $this->setXhtml($value);
                break;
                case 'escape':
                case 'escapeHtml':
                    $this->setEscaping($value);
                break;
                case 'strict':
                case 'strictMode':
                    $this->setStrict($value);
                break;
                case 'newlines':
                case 'maxNewlines':
                    $this->setMaxNewlines($value);
                break;
                case 'standaloneTags':
                    $this->setStandaloneTags($value);
                break;
                case 'lineBreaks':
                    $this->setLineBreaks($value);
                break;
                case 'removeEmpty':
                    $this->setRemoveEmptyTags($value);
                break;
                case 'cacheExpires':
                    $this->setCacheExpiration($value);
                break;

                // Doesn't need a setter as it's only used in the constructor
                case 'configPath':
                    $this->_config['configPath'] = $value;
                break;
            }
        }

        return $this;
    }
1200860
public function parseString($config)
    {
        // Handle PHP start tag
        $config = trim($config);
        if (substr($config, 0, 2) === '<?') {
            $config = '?>' . $config;
        }

        // Eval the string, if it throws an exception, rethrow it
        try {
            $data = $this->isolate($config);
        } catch (Exception $exception) {
            throw new ParseException(
                [
                    'message'   => 'PHP string threw an exception',
                    'exception' => $exception,
                ]
            );
        }

        // Complete parsing
        return (array)$this->parse($data);
    }
1035135
protected function getDsn(array $config)
    {
        return $this->hasDsnString($config) ? $this->getDsnString($config) : $this->getHostDsn($config);
    }
166839
static public function config($config = array())
    {
        !empty($config) && self::$config = array_merge(self::$config, $config);
        if (!empty(self::$config['cachepath'])) {
            Cache::$cachepath = self::$config['cachepath'];
        }
        if (empty(self::$config['component_verify_ticket'])) {
            self::$config['component_verify_ticket'] = Cache::get('component_verify_ticket');
        }
        if (empty(self::$config['token']) && !empty(self::$config['component_token'])) {
            self::$config['token'] = self::$config['component_token'];
        }
        if (empty(self::$config['appsecret']) && !empty(self::$config['component_appsecret'])) {
            self::$config['appsecret'] = self::$config['component_appsecret'];
        }
        if (empty(self::$config['encodingaeskey']) && !empty(self::$config['component_encodingaeskey'])) {
            self::$config['encodingaeskey'] = self::$config['component_encodingaeskey'];
        }
        return self::$config;
    }
574996
protected function convertScrapeConfig(array $config)
	{
		$config['extract'] = $this->convertRegexps($config['extract']);
		$config['match']   = $this->convertRegexps($config['match']);

		return $config;
	}
967094
public function parseString($config)
    {
        libxml_use_internal_errors(true);
        $data = simplexml_load_string($config, null, LIBXML_NOERROR);
        return (array)$this->parse($data);
    }
384393
public function modal($config = array())
    {
        $config = new ObjectConfigJson($config);
        $config->append(array(
            'debug'    => \Kodekit::getInstance()->isDebug(),
            'selector' => '[data-k-modal]',
            'data'     => 'k-modal',
            'options_callback' => null,
            'options'  => array('type' => 'image')
        ));

        $html = '';

        if(!static::isLoaded('modal'))
        {
            $html .= $this->jquery();
            $html .= '<ktml:script src="assets://js/'.($config->debug ? 'build/' : 'min/').'jquery.magnific-popup.js" />';

            static::setLoaded('modal');
        }

        if(!static::isLoaded('modal-select2-fix'))
        {
            $html .= "<script>

                // WORKAROUND FOR ISSUE: #873

                kQuery(function($)
                {
                    $.magnificPopup.instance._onFocusIn = function(e)
                    {
                        // Do nothing if target element is select2 input
                        if( $(e.target).hasClass('select2-search__field') ) {
                            return true;
                        }
            
                        // Else call parent method
                        $.magnificPopup.proto._onFocusIn.call(this,e);
                    };
                });
            </script>";

            static::setLoaded('modal-select2-fix');
        }

        $options   = (string)$config->options;
        $signature = md5('modal-'.$config->selector.$config->options_callback.$options);

        if (!static::isLoaded($signature))
        {
            if ($config->options_callback) {
                $options = $config->options_callback.'('.$options.')';
            }

            $html .= "<script>
            kQuery(function($){
                $('$config->selector').each(function(idx, el) {
                    var el = $(el);
                    var data = el.data('$config->data');
                    var options = ".$options.";
                    if (data) {
                        $.extend(true, options, data);
                    }
                    el.magnificPopup(options);
                });
            });
            </script>";

            static::setLoaded($signature);
        }

        return $html;
    }
193632
public function dialog($config = array())
    {
        $html  = $this->createHelper('behavior')->modal();
        $html .= $this->command($config);

        return $html;
    }
480661
public static function getCSPHeader(array $config): array
    {
        $directives = [
            'default-src',
            'base-uri',
            'connect-src',
            'font-src',
            'form-action',
            'frame-ancestors',
            'frame-src',
            'img-src',
            'manifest-src',
            'media-src',
            'object-src',
            'plugin-types',
            'require-sri-for',
            'sandbox',
            'script-src',
            'style-src',
            'worker-src',
        ];

        $headers = [];

        foreach ($directives as $directive) {
            if (isset($config[$directive])) {
                $headers[] = self::compileDirective($directive, $config[$directive]);
            }
        }

        if (! empty($config['block-all-mixed-content'])) {
            $headers[] = 'block-all-mixed-content';
        }

        if (! empty($config['upgrade-insecure-requests'])) {
            $headers[] = 'upgrade-insecure-requests';
        }

        if (! empty($config['report-uri'])) {
            $headers[] = sprintf('report-uri %s', $config['report-uri']);
        }

        $key = ! empty($config['report-only'])
            ? 'Content-Security-Policy-Report-Only'
            : 'Content-Security-Policy';

        return [$key => implode('; ', array_filter($headers, 'strlen'))];
    }
559890
public function transform(string $config = ''): array
    {
        $parsed = [];
        if (!empty($config)) {
            $config = \parse_ini_string($config, true, INI_SCANNER_RAW);
            if (\is_array($config)) {
                $parsed = $this->processNode($config);
            }
        }
        return $parsed;
    }
1042466
protected function getDsn(array $config)
    {
        if (! empty($config['tns'])) {
            return $config['tns'];
        }

        // parse configuration
        $config = $this->parseConfig($config);

        // check multiple connections/host, comma delimiter
        $config = $this->checkMultipleHostDsn($config);

        // return generated tns
        return $config['tns'];
    }
1157305
public static function getMessage(array $config = []): Message
    {
        $message = Message::class;
        $msgConf = $config['message'] ?? [];
        if (!empty($config['message']['instance'])) {
            $message = $config['message']['instance'];
            unset($config['message']['instance']);
        }
        $message = new $message($msgConf);

        return $message;
    }
910606
public function bootstrap($config = array())
    {
        $config = new KObjectConfigJson($config);
        $config->append(array(
            'debug' => false,
            'css'   => true,
            'javascript' => false
        ));

        $html = '';

        if ($config->javascript && !static::isLoaded('bootstrap-javascript'))
        {
            $html .= $this->jquery($config);
            $html .= '<ktml:script src="assets://js/'.($config->debug ? 'build/' : 'min/').'bootstrap.js" />';

            static::setLoaded('bootstrap-javascript');
        }

        if ($config->css && !static::isLoaded('bootstrap-css'))
        {
            $html .= '<ktml:style src="assets://css/bootstrap.css" />';

            static::setLoaded('bootstrap-css');
        }

        return $html;
    }
1255526
public function render($config = array())
    {
        // Load the language strings for toolbar button labels
        JFactory::getLanguage()->load('joomla', JPATH_ADMINISTRATOR);

        $html = parent::render($config);

        return $html;
    }
203971
protected function load($config = array())
	{
		// Check whether editor is already loaded
		if (!is_null($this->editor))
		{
			return;
		}

		// Build the path to the needed editor plugin
		$name = (string) preg_replace('/[^A-Z0-9_\.-]/i', '', $this->name);
		$name = ltrim($name, '.');

		$path = PATH_APP . '/plugins/editors/' . $name . '/' . $name . '.php';
		if (!is_file($path))
		{
			$path = PATH_CORE . '/plugins/editors/' . $name . '/' . $name . '.php';
			if (!is_file($path))
			{
				\Notify::error(Lang::txt('JLIB_HTML_EDITOR_CANNOT_LOAD'));
				return false;
			}
		}

		// Require plugin file
		require_once $path;

		// Get the plugin
		$plugin = Plugin::byType('editors', $this->name);

		$params = new Registry($plugin->params);
		$params->merge($config);

		$plugin->params = $params;

		// Build editor plugin classname
		$name = 'plgEditor' . $this->name;

		if ($this->editor = new $name($this, (array) $plugin))
		{
			// Load plugin parameters
			$this->initialise();

			Plugin::import('editors-xtd');
		}
	}
812164
protected function getDebugOption(array $config)
    {
        if (isset($config['debug'])) {
            return ($config['debug'] === true) ? fopen('php://stderr', 'ab') : $config['debug'];
        }

        if ($this->debugOverride && $this->debug) {
            return ($this->debug === true) ? fopen('php://stderr', 'ab') : $this->debug;
        } elseif (!$this->debugOverride && static::$staticDebug) {
            return (static::$staticDebug === true) ? fopen('php://stderr', 'ab') : static::$staticDebug;
        }

        return false;
    }