diff --git a/upload/modules/Resources/hooks/DeleteUserResourcesHook.php b/upload/modules/Resources/hooks/DeleteUserResourcesHook.php new file mode 100644 index 0000000..8f296e7 --- /dev/null +++ b/upload/modules/Resources/hooks/DeleteUserResourcesHook.php @@ -0,0 +1,28 @@ + 1) { + $db = DB::getInstance(); + + // Delete the user's resources + $db->delete('resources', ['creator_id', $params['user_id']]); + + // Delete the user's resource comments + $db->delete('resources_comments', ['author_id', $params['user_id']]); + + // Resource payments + $db->delete('resources_payments', ['user_id', $params['user_id']]); + + // Resource premium details + $db->delete('resources_users_premium_details', ['user_id', $params['user_id']]); + } + } +} diff --git a/upload/modules/Resources/init.php b/upload/modules/Resources/init.php index 238feec..786c186 100644 --- a/upload/modules/Resources/init.php +++ b/upload/modules/Resources/init.php @@ -12,7 +12,8 @@ // Initialise module language $resource_language = new Language(ROOT_PATH . '/modules/Resources/language', LANGUAGE); -require_once(ROOT_PATH . '/modules/Resources/classes/Resources_Sitemap.php'); +require_once ROOT_PATH . '/modules/Resources/classes/Resources_Sitemap.php'; +require_once ROOT_PATH . '/modules/Resources/hooks/DeleteUserResourcesHook.php'; -require_once(ROOT_PATH . '/modules/Resources/module.php'); +require_once ROOT_PATH . '/modules/Resources/module.php'; $module = new Resources_Module($pages, $language, $resource_language); diff --git a/upload/modules/Resources/module.php b/upload/modules/Resources/module.php index 4528fd6..edfbab4 100644 --- a/upload/modules/Resources/module.php +++ b/upload/modules/Resources/module.php @@ -42,6 +42,8 @@ public function __construct($pages, $language, $resource_language){ $pages->add('Resources', '/resources/icon_upload', 'pages/resources/icon_upload.php'); $pages->add('Resources', '/user/resources/licenses', 'pages/user/licenses.php'); + EventHandler::registerListener('deleteUser', 'DeleteUserResourcesHook::execute'); + } public function onInstall(){ diff --git a/upload/modules/Resources/pages/user/resources.php b/upload/modules/Resources/pages/user/resources.php index c8946ce..bc4fb7a 100644 --- a/upload/modules/Resources/pages/user/resources.php +++ b/upload/modules/Resources/pages/user/resources.php @@ -132,6 +132,11 @@ require(ROOT_PATH . '/core/templates/cc_navbar.php'); +// Temporary fix until v2.0.0 +if (NAMELESS_VERSION == '2.0.0-pr13' && !defined('FOMANTIC_RESOURCES_FIX')) { + $template->addJSScript('$(\'.menu .item\').tab();'); +} + $template->onPageLoad(); require(ROOT_PATH . '/core/templates/navbar.php'); diff --git a/upload/modules/Resources/widgets/LatestResources.php b/upload/modules/Resources/widgets/LatestResources.php index ffb3685..c20acb4 100644 --- a/upload/modules/Resources/widgets/LatestResources.php +++ b/upload/modules/Resources/widgets/LatestResources.php @@ -42,7 +42,27 @@ public function initialise(): void { $timeago = new TimeAgo(TIMEZONE); - $latestResources = DB::getInstance()->orderAll('resources', 'updated', 'DESC LIMIT 5'); + $groups = '0'; + if (($user = new User())->isLoggedIn()) { + $groups = implode(',', array_keys($user->getAllGroupIds())); + } + + $latestResources = DB::getInstance()->query( + <<results() as $resource) { @@ -80,4 +100,4 @@ public function initialise(): void { $this->_content = $this->_smarty->fetch('widgets/resources/latest_resources.tpl'); } -} \ No newline at end of file +} diff --git a/upload/modules/Resources/widgets/TopResources.php b/upload/modules/Resources/widgets/TopResources.php index b08f707..1e1d33d 100644 --- a/upload/modules/Resources/widgets/TopResources.php +++ b/upload/modules/Resources/widgets/TopResources.php @@ -42,13 +42,30 @@ public function initialise(): void { $timeago = new TimeAgo(TIMEZONE); - $topResources = DB::getInstance()->orderAll('resources', 'rating', 'DESC LIMIT 5'); + $groups = '0'; + if (($user = new User())->isLoggedIn()) { + $groups = implode(',', array_keys($user->getAllGroupIds())); + } + + $topResources = DB::getInstance()->query( + <<results() as $resource) { - // check if resource rating > 0 - if ($resource->rating == 0) continue; - $author = new User($resource->creator_id); if (!$author->exists()) { @@ -72,7 +89,7 @@ public function initialise(): void { if($resource->has_icon == 1 ) { $topResourcesArr[$resource->id]['icon'] = Output::getClean($resource->icon); } else { - $topResourcesArr[$resource->id]['icon'] = rtrim(Util::getSelfURL(), '/') . (defined('CONFIG_PATH') ? CONFIG_PATH . '/' : '/') . 'uploads/resources_icons/default.png'; + $topResourcesArr[$resource->id]['icon'] = rtrim(URL::getSelfURL(), '/') . (defined('CONFIG_PATH') ? CONFIG_PATH . '/' : '/') . 'uploads/resources_icons/default.png'; } } @@ -84,4 +101,4 @@ public function initialise(): void { $this->_content = $this->_smarty->fetch('widgets/resources/top_resources.tpl'); } -} \ No newline at end of file +}