From 5aca217839f4e2de7f6d18a77f57f299e765e5d9 Mon Sep 17 00:00:00 2001 From: Sonny Le Date: Thu, 20 Jun 2024 11:19:17 +0700 Subject: [PATCH] Fix issue create custom Widget #707 --- framework/library/astroid/Admin.php | 12 +++++++++--- framework/library/astroid/Element.php | 2 +- framework/library/astroid/Element/Layout.php | 18 +++++++++--------- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/framework/library/astroid/Admin.php b/framework/library/astroid/Admin.php index 9beda951..5782256d 100644 --- a/framework/library/astroid/Admin.php +++ b/framework/library/astroid/Admin.php @@ -75,7 +75,7 @@ protected function getLayouts() { $app = Factory::getApplication(); $template_name = $app->input->get('template', NULL, 'RAW'); - $this->response(Layout::getSublayouts($template_name)); + $this->response(Layout::getDatalayouts($template_name, 'layouts')); } protected function getLayout() @@ -87,7 +87,7 @@ protected function getLayout() $template_name = $app->input->get('template', NULL, 'RAW'); $filename = $app->input->get('name', NULL, 'RAW'); - $this->response(Layout::getSubLayout($filename, $template_name)); + $this->response(Layout::getDataLayout($filename, $template_name, 'layouts')); } catch (\Exception $e) { $this->errorResponse($e); } @@ -154,13 +154,19 @@ protected function deleteLayouts() $template_name = $app->input->get('template', NULL, 'RAW'); $layouts = $app->input->get('layouts', array(), 'RAW'); - $this->response(Layout::deleteSublayouts($layouts, $template_name)); + $this->response(Layout::deleteDatalayouts($layouts, $template_name, 'layouts')); } catch (\Exception $e) { $this->errorResponse($e); } return true; } + protected function getArticleLayouts() { + $app = Factory::getApplication(); + $template_name = $app->input->get('template', NULL, 'RAW'); + $this->response(Layout::getDatalayouts($template_name, 'article_layouts')); + } + protected function getcategories() { $this->response(Utility::getCategories()); diff --git a/framework/library/astroid/Element.php b/framework/library/astroid/Element.php index 90086132..63388f4b 100644 --- a/framework/library/astroid/Element.php +++ b/framework/library/astroid/Element.php @@ -60,7 +60,7 @@ public function __construct($type = '', $data = [], $template = null) $this->template->setLog("Initiated Element : " . $type, "success"); if ($type !== 'subform') { $library_elements_directory = JPATH_LIBRARIES . '/' . 'astroid' . '/' . 'framework' . '/' . 'elements' . '/'; - $template_elements_directory = JPATH_SITE . '/' . 'templates' . '/' . $this->template->template . '/' . 'astroid' . '/' . 'elements' . '/'; + $template_elements_directory = JPATH_SITE . '/media/templates/site/' . $this->template->template . '/' . 'astroid' . '/' . 'elements' . '/'; switch ($this->type) { case 'section': diff --git a/framework/library/astroid/Element/Layout.php b/framework/library/astroid/Element/Layout.php index a96e45d6..4648a309 100644 --- a/framework/library/astroid/Element/Layout.php +++ b/framework/library/astroid/Element/Layout.php @@ -42,7 +42,7 @@ public static function render() public static function renderSublayout($source, $template = '') { Framework::getDebugger()->log('Render '.$source.' Layout'); - $sublayout = self::getSubLayout($source, $template); + $sublayout = self::getDataLayout($source, $template, 'layouts'); if (!isset($sublayout['data']) || !$sublayout['data']) { return ''; } @@ -63,13 +63,13 @@ public static function renderSublayout($source, $template = '') return $content; } - public static function getSublayouts($template = '') + public static function getDatalayouts($template = '', $type = '') { if (!$template) { $template = Framework::getTemplate()->template; } - $layouts_path = JPATH_SITE . "/media/templates/site/{$template}/astroid/layouts/"; + $layouts_path = JPATH_SITE . "/media/templates/site/{$template}/astroid/{$type}/"; if (!file_exists($layouts_path)) { return []; } @@ -86,14 +86,14 @@ public static function getSublayouts($template = '') $layout['desc'] = Text::_($data['desc']); } if (isset($data['thumbnail']) && !empty($data['thumbnail'])) { - $layout['thumbnail'] = Uri::root() . 'media/templates/site/' . $template . '/images/layouts/' . $data['thumbnail']; + $layout['thumbnail'] = Uri::root() . 'media/templates/site/' . $template . '/images/' . $type . '/' . $data['thumbnail']; } $layouts[] = $layout; } return $layouts; } - public static function getSubLayout($filename = '', $template = '') + public static function getDataLayout($filename = '', $template = '', $type = '') { if (!$filename) { return []; @@ -102,7 +102,7 @@ public static function getSubLayout($filename = '', $template = '') $template = Framework::getTemplate()->template; } - $layout_path = JPATH_SITE . "/media/templates/site/{$template}/astroid/layouts/" . $filename . '.json'; + $layout_path = JPATH_SITE . "/media/templates/site/{$template}/astroid/{$type}/" . $filename . '.json'; if (!file_exists($layout_path)) { return []; } @@ -112,7 +112,7 @@ public static function getSubLayout($filename = '', $template = '') return $data; } - public static function deleteSublayouts($layouts = [], $template = '') + public static function deleteDatalayouts($layouts = [], $template = '', $type = '') { if (!count($layouts)) { return false; @@ -121,8 +121,8 @@ public static function deleteSublayouts($layouts = [], $template = '') $template = Framework::getTemplate()->template; } - $layouts_path = JPATH_SITE . "/media/templates/site/{$template}/astroid/layouts/"; - $images_path = JPATH_SITE . "/media/templates/site/{$template}/images/layouts/"; + $layouts_path = JPATH_SITE . "/media/templates/site/{$template}/astroid/{$type}/"; + $images_path = JPATH_SITE . "/media/templates/site/{$template}/images/{$type}/"; foreach ($layouts as $layout) { if (file_exists($layouts_path . $layout . '.json')) { $json = file_get_contents($layouts_path . $layout . '.json');