From 3731c45d9c401f5bd8f26368023631e4cd475f6a Mon Sep 17 00:00:00 2001 From: Sonny Le Date: Wed, 31 Jul 2024 14:27:08 +0700 Subject: [PATCH] Add Masonry library --- framework/library/astroid/Document.php | 101 +++++++++++++++---------- 1 file changed, 63 insertions(+), 38 deletions(-) diff --git a/framework/library/astroid/Document.php b/framework/library/astroid/Document.php index aa5f513b..4f41d9c0 100644 --- a/framework/library/astroid/Document.php +++ b/framework/library/astroid/Document.php @@ -34,6 +34,8 @@ class Document protected $minify_html = false; protected static $_fontawesome = false; protected static $_fancybox = false; + protected static $_masonry = false; + protected static $_slick = false; protected static $_layout_paths = []; protected $type = null; protected $modules = null; @@ -60,7 +62,7 @@ public function getType() return $this->type; } - public function addLayoutPath($path) + public function addLayoutPath($path): void { self::$_layout_paths[] = $path; } @@ -116,7 +118,7 @@ public function include($section, $data = [], $return = false) echo trim($content); } - public function compress() + public function compress(): void { $app = Factory::getApplication(); $body = $app->getBody(); @@ -133,7 +135,7 @@ public function compress() $app->setBody($body); } - public function isFrontendEditing() + public function isFrontendEditing(): bool { if (!Framework::isSite()) { return false; @@ -219,7 +221,7 @@ function addProtocol($url) } - public function minifyCSS($html) + public function minifyCSS($html): array|string { Framework::getDebugger()->log('Minifying CSS'); $stylesheets = []; @@ -381,7 +383,7 @@ public function minifyJS($html) return $html; } - public function minifyHTML($html) + public function minifyHTML($html): array|string|null { Framework::getDebugger()->log('Minifying HTML'); $level = Framework::getTemplate()->getParams()->get('minify_html_level', 'basic'); @@ -476,7 +478,7 @@ public function minifyHTML($html) return trim($html); } - public function _replace($rx, $replacement, $code, $callback = null) + public function _replace($rx, $replacement, $code, $callback = null): array|string|null { if ($callback === null) { return preg_replace($rx, $replacement, $code); @@ -515,7 +517,7 @@ public function _minifyAssets($m) return $m[0]; } - private function _assetsHash() + private function _assetsHash(): string { $assets = []; $assets[] = \json_encode($this->_styles); @@ -529,7 +531,7 @@ private function _assetsHash() return md5(serialize($assets)); } - public function position($position, $style = 'none') + public function position($position, $style = 'none'): string { if (empty($position)) { return ''; @@ -547,7 +549,7 @@ public function position($position, $style = 'none') return $return; } - public function hasModule($position, $module) + public function hasModule($position, $module): bool { return in_array($module, array_column(ModuleHelper::getModules($position), 'module')); } @@ -582,7 +584,7 @@ public function loadModule($content) return $content; } - private function _modulePosition($position) + private function _modulePosition($position): false|string { $this->modules[$position] = ''; $document = Factory::getDocument(); @@ -599,7 +601,7 @@ private function _modulePosition($position) return $this->modules[$position]; } - private function _moduleId($id) + private function _moduleId($id): false|string { $this->modules[$id] = ''; $document = Factory::getDocument(); @@ -664,7 +666,7 @@ private function _positionLayouts() return $return; } - protected function checkDev() + protected function checkDev(): void { $params = Framework::getTemplate()->getParams(); if ($params->exists('developemnt_mode')) { @@ -675,7 +677,7 @@ protected function checkDev() $this->_dev = ($dev ? true : false); } - public function isDev() + public function isDev(): bool { if ($this->_dev === null) { $this->checkDev(); @@ -683,7 +685,7 @@ public function isDev() return $this->_dev; } - public function addMeta($name, $content, $attribs = []) + public function addMeta($name, $content, $attribs = []): void { $this->_metas[$name] = [ 'name' => $name, @@ -692,7 +694,7 @@ public function addMeta($name, $content, $attribs = []) ]; } - public function addLink($href = '', $rel = 'stylesheet', $attribs = ['type' => 'text/css']) + public function addLink($href = '', $rel = 'stylesheet', $attribs = ['type' => 'text/css']): void { $this->_links[md5($href)] = [ 'href' => $href, @@ -701,7 +703,7 @@ public function addLink($href = '', $rel = 'stylesheet', $attribs = ['type' => ' ]; } - public function renderMeta() + public function renderMeta(): string { $html = ''; foreach ($this->_metas as $meta) { @@ -720,7 +722,7 @@ public function renderMeta() return $html; } - public function renderLinks() + public function renderLinks(): string { $html = ''; foreach ($this->_links as $link) { @@ -739,7 +741,7 @@ public function renderLinks() return $html; } - public function beutifyURL($url) + public function beutifyURL($url): array|string { $url = str_replace('?' . Helper::joomlaMediaVersion(), '', $url); $url = str_replace(Uri::root(), '', $url); @@ -754,7 +756,7 @@ public function beutifyURL($url) return $url; } - public function addScript($url, $position = 'head', $options = [], $attribs = [], $type = '') + public function addScript($url, $position = 'head', $options = [], $attribs = [], $type = ''): void { if (!is_array($url)) { $url = [$url]; @@ -771,7 +773,7 @@ public function addScript($url, $position = 'head', $options = [], $attribs = [] } } - public function getScripts($position = 'head') + public function getScripts($position = 'head'): string { $html = ''; foreach ($this->_javascripts[$position] as $javascript) { @@ -783,7 +785,7 @@ public function getScripts($position = 'head') return $html; } - public function getCustomTags($position = 'head') + public function getCustomTags($position = 'head'): string { $content = ''; foreach ($this->_customtags[$position] as $tag) { @@ -792,7 +794,7 @@ public function getCustomTags($position = 'head') return $content; } - public function addScriptOptions($key, $options, $merge = true) + public function addScriptOptions($key, $options, $merge = true): static { if (empty($this->scriptOptions[$key])) { $this->scriptOptions[$key] = []; @@ -816,7 +818,7 @@ public function getScriptOptions($key = null) return $this->scriptOptions; } - protected function _systemUrl($url, $version = true) + protected function _systemUrl($url, $version = true): string { $config = Factory::getApplication()->getConfig(); $params = Helper::getPluginParams(); @@ -848,7 +850,7 @@ protected function _systemUrl($url, $version = true) return $url.$postfix ; } - public function addScriptDeclaration($content, $position = 'head', $type = 'text/javascript') + public function addScriptDeclaration($content, $position = 'head', $type = 'text/javascript'): void { if (empty($content)) { return; @@ -859,7 +861,7 @@ public function addScriptDeclaration($content, $position = 'head', $type = 'text $this->_scripts[$position][] = $script; } - public function addStyleDeclaration($content, $device = 'desktop') + public function addStyleDeclaration($content, $device = 'desktop'): void { if (empty($content)) { return; @@ -867,7 +869,7 @@ public function addStyleDeclaration($content, $device = 'desktop') $this->_styles[$device][] = trim($content); } - public function addStyleSheet($url, $attribs = ['rel' => 'stylesheet', 'type' => 'text/css'], $shifted = 0) + public function addStyleSheet($url, $attribs = ['rel' => 'stylesheet', 'type' => 'text/css'], $shifted = 0): void { if (!is_array($url)) { $url = [$url]; @@ -886,7 +888,7 @@ public function addStyleSheet($url, $attribs = ['rel' => 'stylesheet', 'type' => } } - public function addCustomTag($content, $position = 'head') + public function addCustomTag($content, $position = 'head'): void { if (empty($content)) { return; @@ -897,7 +899,7 @@ public function addCustomTag($content, $position = 'head') } } - public function loadFontAwesome() + public function loadFontAwesome(): void { if (self::$_fontawesome) { return; @@ -905,7 +907,7 @@ public function loadFontAwesome() Helper\Font::loadFontAwesome(); } - public function loadFancyBox() + public function loadFancyBox(): void { if (self::$_fancybox) { return; @@ -916,13 +918,35 @@ public function loadFancyBox() self::$_fancybox = true; } - public function moveFile(&$array, $a, $b) + public function loadMasonry(): void + { + if (!self::$_masonry) { + $wa = Factory::getApplication()->getDocument()->getWebAssetManager(); + $wa->registerAndUseScript('masonry', 'astroid/masonry.pkgd.min.js', ['relative' => true, 'version' => 'auto'], [], ['jquery']); + self::$_masonry = true; + } + } + + public function loadSlick($obj = '', $config = ''): void + { + $wa = Factory::getApplication()->getDocument()->getWebAssetManager(); + if (!self::$_slick) { + $wa->registerAndUseStyle('slick.css', 'astroid/slick.min.css'); + $wa->registerAndUseScript('slick.js', 'astroid/slick.min.js', ['relative' => true, 'version' => 'auto'], [], ['jquery']); + self::$_slick = true; + } + if (!empty($obj) && !empty($config)) { + $wa->addInlineScript('jQuery(document).ready(function(){jQuery(\''.$obj.'\').slick({'.$config.'})});'); + } + } + + public function moveFile(&$array, $a, $b): void { $out = array_splice($array, $a, 1); array_splice($array, $b, 0, $out); } - public function getStylesheets() + public function getStylesheets(): string { $keys = array_keys($this->_stylesheets); foreach ($keys as $index => $key) { @@ -943,7 +967,7 @@ public function getStylesheets() return $content; } - public function renderScss($path) + public function renderScss($path): void { ini_set('memory_limit', '1024M'); Framework::getDebugger()->log('Rendering Scss'); @@ -1071,7 +1095,7 @@ public function renderScss($path) Helper::putContents($path, $css->getCss()); } - public function renderCss() + public function renderCss(): string { /* if (Framework::isSite()) { $template = Framework::getTemplate(); @@ -1090,7 +1114,7 @@ public function renderCss() return $cssScript; } - public function getBodyClass($extra_class = '') + public function getBodyClass($extra_class = ''): string { $template = Framework::getTemplate(); @@ -1160,7 +1184,7 @@ public function getBodyClass($extra_class = '') return implode(' ', $class); } - public function isBuilder() + public function isBuilder(): bool { $jinput = Factory::getApplication()->input; $option = $jinput->get('option', ''); @@ -1193,7 +1217,7 @@ public static function getDir($dir, $extension = null, &$results = array()) return $results; } - public static function scssHash() + public static function scssHash(): string { $params = Helper::getPluginParams(); $debug = $params->get('astroid_debug', 0); @@ -1220,7 +1244,7 @@ public static function scssHash() return md5($name); } - public function astroidCSS() + public function astroidCSS(): void { $getPluginParams = Helper::getPluginParams(); $wa = Factory::getApplication()->getDocument()->getWebAssetManager(); @@ -1292,7 +1316,8 @@ public function astroidCustomCSS() { } } - public function astroidInlineCSS() { + public function astroidInlineCSS(): string + { // css on page $getPluginParams = Helper::getPluginParams(); $astroid_inline_css = $getPluginParams->get('astroid_inline_css', 0);