Get all javascript assets of section (header or footer).

@param bool $footer FALSE for head, TRUE for footer

@return string Asset HTML
544469
public function renderScripts($footer = false)
    {
        $this->loadPackageJs();

        if (empty($this->scripts)) {
            return PHP_EOL;
        }

        /** @var JavaScript[] $assets */
        $assets = [];

        foreach ($this->scripts as $javaScript) {
            if ($javaScript->isFooter() === $footer) {
                $assets[$javaScript->getHandle()] = $javaScript;
            }
        }

        if (empty($assets)) {
            return false;
        }

        foreach ($this->sort($assets) as $javaScript) {
            $sorted[] = $this->getJs($javaScript->getHandle());
        }

        return implode(PHP_EOL, $sorted);
    }
1094738
public function loadFile (Asset $asset, ?bool $mode) : string
    {
        $filePath = $this->getFilePath($asset);

        if (!\is_file($filePath))
        {
            throw new FileNotFoundException(sprintf(
                "Asset '%s' not found at '%s'.",
                $asset->getAssetPath(),
                $filePath
            ));
        }

        $fileContent = \file_get_contents($filePath);

        if (false === $fileContent)
        {
            throw new FileNotFoundException(sprintf(
                "Can't read asset file '%s' at '%s'.",
                $asset->getAssetPath(),
                $filePath
            ));
        }

        $fileType = $this->fileTypeRegistry->getFileType($asset);

        if (self::MODE_UNTOUCHED !== $mode)
        {
            // prepend file header in dev and process in prod
            $fileContent = (self::MODE_PROD === $mode)
                ? $fileType->processForProd($asset, $fileContent)
                : $fileType->processForDev($asset, $filePath, $fileContent);
        }

        return $fileContent;
    }
907014
public function render($renderer, $sub = false)
    {
        if (!empty($this->attrs['style'])) {
            $renderer->setCurrentStyle($this->attrs['style']);
        }
        if (!empty($this->attrs['width'])) {
            $this->attrs['width'] *= 3.9;
        }

        $this->text = $this->getStart() . $this->text;
        foreach ($this->elements as $element) {
            if ($element === 'footnotetexts') {
                $renderer->Footnotes();
            } elseif ($element === 'addpage') {
                $renderer->newPage();
            } elseif ($element instanceof ReportBaseHtml) {
                $element->render($renderer, true);
            } else {
                $element->render($renderer);
            }
        }
        $this->text .= $this->getEnd();
        if ($sub) {
            return $this->text;
        }
        $renderer->writeHTML($this->text); //prints 2 empty cells in the Expanded Relatives report
    }
933391
public function show(Footer $footer)
    {
        $footer->load(['seo']);

        $this->setTitle($footer->seo->title);
        $this->addBreadcrumb($footer->seo->title);

        return $this->view('seo::public.footer-page', compact('footer'));
    }
905838
protected function getJavaScriptFiles()
    {
        $formObject = $this->assetHandlerFactory->getFormObject();

        $javaScriptFiles = $this->getFieldsValidationJavaScriptAssetHandler()
            ->getJavaScriptValidationFiles();

        $conditionProcessor = $this->getConditionProcessor($formObject);

        $javaScriptFiles = array_merge($javaScriptFiles, $conditionProcessor->getJavaScriptFiles());

        return $javaScriptFiles;
    }
69234
public static function process($assets)
    {
        if ($directory = self::getOutputDirectory()) {
            $relativeDirectory = self::getRelativeOutputDirectory();
            $filename = '';
            $sourceFiles = array();
            for ($i = 0; $i < count($assets); ++$i) {
                $asset = $assets[$i];
                $filename .= $asset->getAssetHashKey();
                $sourceFiles[] = $asset->getAssetURL();
            }
            $filename = sha1($filename);
            $cacheFile = $directory.'/'.$filename.'.js';
            if (!file_exists($cacheFile)) {
                $js = '';
                foreach ($assets as $asset) {
                    $contents = $asset->getAssetContents();
                    if (isset($contents)) {
                        if ($asset->assetSupportsMinification()) {
                            $contents = \JShrink\Minifier::minify($contents);
                        }
                        $js .= $contents.";\n\n";
                    }
                }
                @file_put_contents($cacheFile, $js);
            }

            $asset = new self();
            $asset->setAssetURL($relativeDirectory.'/'.$filename.'.js');
            $asset->setAssetPath($directory.'/'.$filename.'.js');
            $asset->setCombinedAssetSourceFiles($sourceFiles);

            return array($asset);
        }

        return $assets;
    }
1131749
function footerHTML( footer ) {
  var content = [];
  content.push( '<div class="footer-cnt"></div>' );
  if ( footer != null ) {
    // footer links
    if ( footer.linkList != null ) {
      content.push( '<div class="footer-links">' );
      for ( var i = 0; i < footer.linkList.length; i++ ) {
        if ( footer.linkList[i] ) {
        var lnk = footer.linkList[i];
        if ( lnk.target != null ) {
          content.push( '<a href="'+ $.i18n( lnk.url )+'" target="'+lnk.target+'">'+ $.i18n( lnk.text )+'</a>   ' );
        } else {
          content.push( '<a href="'+ $.i18n( lnk.url )+'">'+ $.i18n( lnk.text )+'</a>   ' );          
        }
        }
      }
      content.push( "</div>" );
    }
    if ( footer.copyrightText != null ) {
      content.push( '<div class="copyright-div">'+ $.i18n( footer.copyrightText ) +'</div>' );
    } else {
      content.push( '<div class="copyright-div">&copy; MH 2018</div>' );
    }
    
    // header hooks
    if ( footer.modules != null ) {
      for ( var i = 0; i < footer.modules.length; i++ ) {
        if ( footer.modules[i] ) {
        var fMod =  footer.modules[i];
        log( 'footerHTML', "addFooterHtml "+ fMod.type );
        var hook = getHookMethod( "addFooterHtml", fMod.type );
        if ( hook != "" ) {
          log( 'footerHTML', hook+"( ... )");
          content.push( '<div id="'+fMod.id+'" class="'+fMod.type+'"></div>' );
          
          if ( fMod.moduleConfig != null) {
            moduleConfig[ fMod.id ] = fMod.moduleConfig;
          }
          
          if ( fMod.param == null ) {
            fMod.param = {};
          }
          fMod.param.get = getUrlGETparams();
          
          hookCalls.push( hook+'( "'+fMod.id+'", "'+fMod.type+'", '+JSON.stringify(fMod.param)+' )'  );
        }
        }
      }
    }
  }
  $( '#footer' ).html( content.join("\n") );
}
1164305
public static function script($jquery = false)
    {
        $output = '';
        if ($jquery == true) {    // If $jquery is set to true, it will include a copy of that, too, using CDN
            $output .= '<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>';
        }
        $output .= '<script>'.file_get_contents(jstore::fsdir().'/jsoneditor.min.js').'</script>';
        return $output;
    }
45757
public static function js($pro = false)
    {
        if($pro)
        {
            $url = 'pro.fontawesome.com';
            $integrity = 'sha384-GBwm0s/0wYcqnK/JmrCoRqWYIWzFiGEucsfFqkB76Ouii5+d4R31vWHPQtfhv55b';
        }
        else
        {
            $url = 'use.fontawesome.com';
            $integrity = 'sha384-g5uSoOSBd7KkhAMlnQILrecXvzst9TdC09/VM+pjDTCM+1il8RHz5fKANTFFb+gQ';
        }

        return '<script defer src="https://' . $url . '/releases/v' .
        self::FA_VERSION . '/js/all.js" integrity="' . $integrity . '" crossorigin="anonymous"></script>';
    }
307820
public function assetFiles(array $assets, array $options = []): string
    {
        $assets = $this->prepareAssets($assets);
        $options = array_replace_recursive($this->options, $options);

        $cacheKey = $this->getCacheKey($assets, $options);
        $cacheItem = $this->cache->getItem($cacheKey);
        if ($cacheItem->isHit()) {
            return $cacheItem->get();
        }

        $jsFiles = [];
        $cssFiles = [];
        foreach ($assets as $file) {
            $fileType = strtolower(pathinfo($file, PATHINFO_EXTENSION));
            if ($fileType === 'js') {
                $jsFiles[] = $file;
            }
            if ($fileType === 'css') {
                $cssFiles[] = $file;
            }
        }
        $cssContent = $this->css($cssFiles, $options);
        $jsContent = $this->js($jsFiles, $options);
        $result = $cssContent . $jsContent;

        $cacheItem->set($result);
        $this->cache->save($cacheItem);

        return $result;
    }
85535
public function prepend($asset)
	{
		// More than one asset
		if(is_array($asset))
		{
			foreach(array_reverse($asset) as $a)
				$this->prepend($a);
		}

		// Collection
		elseif(isset($this->collections[$asset]))
			$this->prepend($this->collections[$asset]);

		// JavaScript asset
		elseif(preg_match($this->js_regex, $asset))
			$this->prependJs($asset);

		// CSS asset
		elseif(preg_match($this->css_regex, $asset))
			$this->prependCss($asset);

		return $this;
	}
1288434
public function footer() {
        global $CFG, $DB, $PAGE;

        // Give plugins an opportunity to touch the page before JS is finalized.
        $pluginswithfunction = get_plugins_with_function('before_footer', 'lib.php');
        foreach ($pluginswithfunction as $plugins) {
            foreach ($plugins as $function) {
                $function();
            }
        }

        $output = $this->container_end_all(true);

        $footer = $this->opencontainers->pop('header/footer');

        if (debugging() and $DB and $DB->is_transaction_started()) {
            // TODO: MDL-20625 print warning - transaction will be rolled back
        }

        // Provide some performance info if required
        $performanceinfo = '';
        if (defined('MDL_PERF') || (!empty($CFG->perfdebug) and $CFG->perfdebug > 7)) {
            $perf = get_performance_info();
            if (defined('MDL_PERFTOFOOT') || debugging() || $CFG->perfdebug > 7) {
                $performanceinfo = $perf['html'];
            }
        }

        // We always want performance data when running a performance test, even if the user is redirected to another page.
        if (MDL_PERF_TEST && strpos($footer, $this->unique_performance_info_token) === false) {
            $footer = $this->unique_performance_info_token . $footer;
        }
        $footer = str_replace($this->unique_performance_info_token, $performanceinfo, $footer);

        // Only show notifications when we have a $PAGE context id.
        if (!empty($PAGE->context->id)) {
            $this->page->requires->js_call_amd('core/notification', 'init', array(
                $PAGE->context->id,
                \core\notification::fetch_as_array($this)
            ));
        }
        $footer = str_replace($this->unique_end_html_token, $this->page->requires->get_end_code(), $footer);

        $this->page->set_state(moodle_page::STATE_DONE);

        return $output . $footer;
    }
735191
public function renderHead()
    {
        list($cssFiles, $jsFiles, $inlineCss, $inlineJs, $inlineHead) = $this->getAssets(null, self::RELATIVE_URL);
        $html = '';

        foreach ($cssFiles as $file) {
            $html .= sprintf('<link rel="stylesheet" type="text/css" href="%s">' . "\n", $file);
        }

        foreach ($inlineCss as $content) {
            $html .= sprintf('<style type="text/css">%s</style>' . "\n", $content);
        }

        foreach ($jsFiles as $file) {
            $html .= sprintf('<script type="text/javascript" src="%s"></script>' . "\n", $file);
        }

        foreach ($inlineJs as $content) {
            $html .= sprintf('<script type="text/javascript">%s</script>' . "\n", $content);
        }

        foreach ($inlineHead as $content) {
            $html .= $content . "\n";
        }

        if ($this->enableJqueryNoConflict && !$this->useRequireJs) {
            $html .= '<script type="text/javascript">jQuery.noConflict(true);</script>' . "\n";
        }

        return $html;
    }
636239
public function getMergedAssets($useBundle = false)
    {
        $plugin = new MelisHeadPluginHelper($this->getServiceLocator());
        $assets = $plugin->__invoke('/', $useBundle);

        return $assets;
    }
510671
public function renderHead()
    {
        list($cssFiles, $jsFiles) = $this->getAssets(null, self::RELATIVE_URL);
        $html = '';

        foreach ($cssFiles as $file) {
            $html .= sprintf('<link rel="stylesheet" type="text/css" href="%s">' . "\n", $file);
        }

        foreach ($jsFiles as $file) {
            $html .= sprintf('<script type="text/javascript" src="%s"></script>' . "\n", $file);
        }

        if ($this->enableJqueryNoConflict && !$this->useRequireJs) {
            $html .= '<script type="text/javascript">jQuery.noConflict(true);</script>' . "\n";
        }

        return $html;
    }
743378
protected function _getAssetFile($url) {
        //Brood unload hack cause vendor plugin loaded for some reason
        Plugin::unload('Garderobe');
        $parts = explode('/', $url);
        $fileType = array_shift($parts);
        $fileFragment = implode(DS, $parts);
        $allowedExtensions = ComponentInstaller::getSupportedExtensions();
        $registeredComponents = require ROOT . DS . 'vendor' . DS . 'cakephp-components.php';
        foreach($registeredComponents as $component){
            $extensions = implode('|', $allowedExtensions);
            if (preg_match("/($extensions)$/i", $fileFragment)) {
                foreach($component as $type=>$chunk){
                    if($fileType != $type){
                        continue;
                    }
                    $path = ROOT . DS . Configure::read('App.webroot') . DS . $chunk. DS;
                    if((Configure::read('debug') == false)&&!strpos($fileFragment, 'min')){
                        $fileFragment =  preg_replace("/(css|js)$/i", "min.$1", $fileFragment);
                    }
                    if (file_exists($path. $fileFragment)) {
                        return $path.$fileFragment;
                    }
                }
            }
        }
    }
989625
public function loadingJS($scope = false)
    {
        $assets = \Cake\Core\Configure::read('assets');
        
        if (!$scope) {
            $scope = ($this->request->param('prefix')) ? $this->request->param('prefix') : 'front';
        }
        
        $all = $this->fetchSetting();
        $css = Hash::extract($all, '{n}.js.base.{n}');
        $css = array_merge($css, Hash::extract($all, "{n}.js.{$scope}.{n}"));
  
        return $this->Html->script($css,['crossorigin'=> 'anonymous']);
    }