Backend\Core\Engine\Header::parseJS PHP Method

parseJS() public method

Parse the JS-files
public parseJS ( )
    public function parseJS()
    {
        $jsFiles = array();
        $existingJSFiles = $this->getJSFiles();
        // if there aren't any JS-files added we don't need to do something
        if (!empty($existingJSFiles)) {
            // some files should be cached, even if we don't want cached (mostly libraries)
            $ignoreCache = array('/bower_components/jquery/dist/jquery.min.js', '/bower_components/jquery-migrate/jquery-migrate.min.js', '/bower_components/jquery-ui/jquery-ui.min.js', '/bower_components/bootstrap-sass/assets/javascripts/bootstrap.min.js', '/bower_components/bootstrap-tagsinput/dist/bootstrap-tagsinput.min.js', '/src/Backend/Core/Js/jquery/jquery.ui.dialog.patch.js', '/src/Backend/Core/Js/jquery/jquery.backend.js', '/src/Backend/Core/Js/ckeditor/ckeditor.js', '/src/Backend/Core/Js/ckeditor/adapters/jquery.js', '/src/Backend/Core/Js/ckfinder/ckfinder.js');
            foreach ($existingJSFiles as $file) {
                // some files shouldn't be uncachable
                if (in_array($file['file'], $ignoreCache) || $file['add_timestamp'] === false) {
                    $file = array('file' => $file['file']);
                } else {
                    if (mb_substr($file['file'], 0, 11) == '/frontend/js') {
                        $file = array('file' => $file['file'] . '&m=' . time());
                    } else {
                        $modifiedTime = mb_strpos($file['file'], '?') !== false ? '&m=' . LAST_MODIFIED_TIME : '?m=' . LAST_MODIFIED_TIME;
                        $file = array('file' => $file['file'] . $modifiedTime);
                    }
                }
                // add
                $jsFiles[] = $file;
            }
        }
        // assign JS-files
        $this->tpl->assign('jsFiles', $jsFiles);
        // fetch preferred interface language
        if (Authentication::getUser()->isAuthenticated()) {
            $interfaceLanguage = (string) Authentication::getUser()->getSetting('interface_language');
        } else {
            $interfaceLanguage = BL::getInterfaceLanguage();
        }
        // some default stuff
        $this->jsData['debug'] = $this->getContainer()->getParameter('kernel.debug');
        $this->jsData['site']['domain'] = SITE_DOMAIN;
        $this->jsData['editor']['language'] = $interfaceLanguage;
        $this->jsData['interface_language'] = $interfaceLanguage;
        // is the user object filled?
        if (Authentication::getUser()->isAuthenticated()) {
            $this->jsData['editor']['language'] = (string) Authentication::getUser()->getSetting('interface_language');
        }
        // CKeditor has support for simplified Chinese, but the language is called zh-cn instead of zn
        if ($this->jsData['editor']['language'] == 'zh') {
            $this->jsData['editor']['language'] = 'zh-cn';
        }
        // theme
        if ($this->get('fork.settings')->get('Core', 'theme') !== null) {
            $this->jsData['theme']['theme'] = $this->get('fork.settings')->get('Core', 'theme');
            $this->jsData['theme']['path'] = FRONTEND_PATH . '/Themes/' . $this->get('fork.settings')->get('Core', 'theme');
            $this->jsData['theme']['has_css'] = is_file(FRONTEND_PATH . '/Themes/' . $this->get('fork.settings')->get('Core', 'theme') . '/Core/Layout/Css/screen.css');
            $this->jsData['theme']['has_editor_css'] = is_file(FRONTEND_PATH . '/Themes/' . $this->get('fork.settings')->get('Core', 'theme') . '/Core/Layout/Css/editor_content.css');
        }
        // encode and add
        $jsData = json_encode($this->jsData);
        $this->tpl->assign('jsData', 'var jsData = ' . $jsData . ';' . "\n");
    }