diff --git a/framework/library/astroid/Helper/Client.php b/framework/library/astroid/Helper/Client.php index d9214c85..abf6b62e 100644 --- a/framework/library/astroid/Helper/Client.php +++ b/framework/library/astroid/Helper/Client.php @@ -12,6 +12,9 @@ use Astroid\Framework; use Astroid\Helper; use Joomla\CMS\Uri\Uri; +use Joomla\Filesystem\Folder; +use Joomla\Filesystem\File; +use Joomla\Filesystem\Path; use Joomla\Registry\Registry; use Joomla\CMS\Factory; use Joomla\CMS\Form\Form; @@ -281,6 +284,19 @@ public function onInstallerAfterInstaller($package) return true; } + public function onContentAfterDelete($context, $article): void + { + if ($context === 'com_content.article' && isset($article->id)) { + $templates = Folder::folders(JPATH_SITE . '/media/templates/site'); + foreach ($templates as $template) { + if (file_exists(Path::clean(JPATH_SITE . '/media/templates/site/' . $template . '/astroid/article_widget_data'))) { + $files = Folder::files(JPATH_SITE . '/media/templates/site/' . $template . '/astroid/article_widget_data', '^'. $article->id . '_', false, true); + File::delete($files); + } + } + } + } + public function saveArticleElement() { try { // Check for request forgeries. diff --git a/plugins/astroid/src/Extension/AstroidPlugin.php b/plugins/astroid/src/Extension/AstroidPlugin.php index 71a306f4..d6820576 100644 --- a/plugins/astroid/src/Extension/AstroidPlugin.php +++ b/plugins/astroid/src/Extension/AstroidPlugin.php @@ -42,58 +42,52 @@ public function onAfterRoute() public function onContentPrepareForm($form, $data) { - if (!file_exists(JPATH_LIBRARIES . '/astroid/framework/library/astroid')) { - return false; + if (defined('_ASTROID')) { + Framework::getClient()->onContentPrepareForm($form, $data); } - Framework::getClient()->onContentPrepareForm($form, $data); } public function onContentBeforeSave($context, $table, $isNew, $data = null) { - if (!file_exists(JPATH_LIBRARIES . '/astroid/framework/library/astroid')) { - return false; + if (defined('_ASTROID')) { + return Framework::getClient()->onContentBeforeSave($context, $table, $isNew, $data); } - - return Framework::getClient()->onContentBeforeSave($context, $table, $isNew, $data); } public function onBeforeRender() { - if (!file_exists(JPATH_LIBRARIES . '/astroid/framework/library/astroid')) { - return false; + if (defined('_ASTROID')) { + Framework::getClient()->onBeforeRender(); } - Framework::getClient()->onBeforeRender(); } public function onAfterRender() { - if (!file_exists(JPATH_LIBRARIES . '/astroid/framework/library/astroid')) { - return false; + if (defined('_ASTROID')) { + Framework::getClient()->onAfterRender(); } - Framework::getClient()->onAfterRender(); } public function onAfterRespond() { - if (!file_exists(JPATH_LIBRARIES . '/astroid/framework/library/astroid')) { - return false; - } - if (!(Helper::getPluginParams()->get('astroid_debug', 0)) || Framework::isAdmin()) { - return false; - } + if (defined('_ASTROID')) { + if (!(Helper::getPluginParams()->get('astroid_debug', 0)) || Framework::isAdmin()) { + return; + } - $cache = PluginHelper::getPlugin('system', 'cache'); - if (Framework::isSite() && !empty($cache)) { - return false; - } + $cache = PluginHelper::getPlugin('system', 'cache'); + if (Framework::isSite() && !empty($cache)) { + return; + } - // Capture output. - $contents = ob_get_contents(); + // Capture output. + $contents = ob_get_contents(); - if ($contents) { - ob_end_clean(); + if ($contents) { + ob_end_clean(); + } + echo Helper::str_lreplace('', Helper::debug() . '', $contents); } - echo Helper::str_lreplace('', Helper::debug() . '', $contents); } public function onContentPrepareData($context, $user) @@ -131,21 +125,22 @@ public function onUserAfterSave($user, $isnew, $success, $msg): void public function onInstallerAfterInstaller($installmodel, $package, $installer, $result) { - if (!$result || Framework::isSite()) { - return false; + if (defined('_ASTROID')) { + if (!$result || Framework::isSite()) { + return false; + } + Framework::getClient()->onInstallerAfterInstaller($package); } - Framework::getClient()->onInstallerAfterInstaller($package); } public function onExtensionAfterSave($context, $table, $isNew) { - if (!file_exists(JPATH_LIBRARIES . '/astroid/framework/library/astroid')) { - return false; - } - if (Framework::isAdmin() && $context == "com_templates.style" && $isNew && Template::isAstroidTemplate(JPATH_SITE . "/templates/{$table->template}/templateDetails.xml")) { - $params = \json_decode($table->params, TRUE); - $parent_id = $params['astroid']; - Template::setTemplateDefaults($table->template, $table->id, $parent_id); + if (defined('_ASTROID')) { + if (Framework::isAdmin() && $context == "com_templates.style" && $isNew && Template::isAstroidTemplate(JPATH_SITE . "/templates/{$table->template}/templateDetails.xml")) { + $params = \json_decode($table->params, TRUE); + $parent_id = $params['astroid']; + Template::setTemplateDefaults($table->template, $table->id, $parent_id); + } } } @@ -156,4 +151,11 @@ public function onAfterAstroidFormLoad($template, $form) $form->removeField('presets', 'params'); } } + + public function onContentAfterDelete($context, $article): void + { + if (defined('_ASTROID')) { + Framework::getClient()->onContentAfterDelete($context, $article); + } + } }