config["plugins"]; foreach ($this->components as $c) { if ($c instanceof IComponent) { self::ensure_preparec($c, true); self::ensure_setupc($c, true); } if ($c instanceof IPlugin) $plugins[] = $c; } # Si la page courante est un plugin, l'ajouter aussi if ($page instanceof IPlugin) $plugins[] = $page; foreach ($plugins as &$plugin) { if (is_string($plugin)) $plugin = new $plugin(); elseif (is_array($plugin)) $plugin = func::cons(...$plugin); }; unset($plugin); } protected function overridePrint(IPage $page): void { if ($page->haveContent()) { $this->doResolveConfig(); $this->haveOutput = true; $this->printStartHtml(); $this->printStartHead(); $this->printCssLinks(); $this->printCss(); $this->printJsLinks(); $this->printJs(); $this->printScript(); $this->printHeadTitle(); $this->printEndHead(); $this->printStartBody(); $this->printContent(); $this->printEndBody(); $this->printEndHtml(); } } const JQUERY_MIN_JS = "nur-base/jquery/jquery.min.js"; const JQUERY_JS = "nur-base/jquery/jquery.js"; protected $haveCss = []; protected function setHaveCss(string $name, bool $haveCss=true): void { $this->haveCss[$name] = $haveCss; } protected function haveCss(string $name): bool { return boolval(A::get($this->haveCss, $name)); } protected $haveJs = []; protected function setHaveJs(string $name, bool $haveJs=true): void { $this->haveJs[$name] = $haveJs; } protected function haveJs(string $name): bool { return boolval(A::get($this->haveJs, $name)); } /** @var string[] */ protected $cssUrls; /** @var string[] */ protected $jsUrls; /** @var bool */ protected $needsJquery; function doResolveConfig(): void { $cssUrls = $this->getCssUrls(); $jsUrls = $this->getJsUrls(); $this->needsJquery = config::is_fact(config::FACT_NEEDS_JQUERY); $plugins = $this->getPlugins(); foreach ($plugins as $plugin) { if ($plugin instanceof IPlugin) { $this->needsJquery |= $plugin->haveJquery(); $urls = A::with($plugin->getCss()); if ($plugin->isDynamicCss()) { A::merge($cssUrls, $urls); } else { $index = 0; foreach ($urls as $key => $url) { if (!$url) continue; if ($key === $index) { if (in_array($url, $cssUrls)) continue; $cssUrls[] = $url; } else { if ($this->haveCss($key)) continue; if (in_array($url, $cssUrls)) continue; $cssUrls[$key] = $url; $this->setHaveCss($key); } $index++; } } $urls = A::with($plugin->getJs()); if ($plugin->isDynamicJs()) { A::merge($jsUrls, $urls); } else { $index = 0; foreach ($urls as $key => $url) { if (!$url) continue; if (array_key_exists($key, $jsUrls)) continue; if ($key === $index) { if (in_array($url, $jsUrls)) continue; $jsUrls[] = $url; } else { if ($this->haveJs($key)) continue; if (in_array($url, $jsUrls)) continue; $jsUrls[$key] = $url; $this->setHaveJs($key); } $index++; } } } else { throw ValueException::unexpected_type(IPlugin::class, $plugin); } } if ($this->needsJquery && !$this->haveJs("jquery")) { # toujours mettre jquery en premier $prevJsUrls = $jsUrls; $jsUrls = ["jquery" => self::JQUERY_MIN_JS]; A::merge($jsUrls, $prevJsUrls); } $this->cssUrls = $cssUrls; $this->jsUrls = $jsUrls; } function printStartHtml(): void { ?> getSelfRelativePrefix(); ?>
getSelfRelativePrefix(); foreach ($this->cssUrls as $url) { $url = prefix::add($url, $prefix); ?> getPlugins() as $plugin) { $plugin->printCss(); } } function printJsLinks(): void { $prefix = $this->getSelfRelativePrefix(); foreach ($this->jsUrls as $url) { $url = prefix::add($url, $prefix); ?> getPlugins() as $plugin) { $plugin->printJs(); } } protected function beforeCapture(): void { ob_start(null, 0, PHP_OUTPUT_HANDLER_STDFLAGS ^ PHP_OUTPUT_HANDLER_FLUSHABLE); } private static function strip_lines(array &$lines): void { while (count($lines) > 0 && !$lines[0]) { # enlever les lignes vides au début array_shift($lines); } while (($count = count($lines)) > 0 && !$lines[$count - 1]) { # enlever les lignes vides à la fin array_pop($lines); } } const RE_START_SCRIPT = '/^\s* resolvePluginsScripts(); $this->printMergedScripts(); } function printHeadTitle(): void { co::_print(v::tag("title", $this->getTitle())); } function printEndHead(): void { ?> page]); ly::end(); } function printEndBody(): void { ?>