Skip to content

Commit

Permalink
Update to Nameless version 2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
samerton committed May 1, 2023
1 parent de6dd41 commit 4f05523
Show file tree
Hide file tree
Showing 14 changed files with 141 additions and 156 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
The Nameless-Resources module allows users to share zip files, GitHub projects and external links to your website, either freely or requiring a PayPal purchase.

## Requirements
- NamelessMC version 2 pre-release 13
- NamelessMC version 2.1.0

## Installation
- Upload the contents of the **upload** directory straight into your NamelessMC installation's directory
Expand Down
4 changes: 2 additions & 2 deletions upload/modules/Resources/classes/Resources_Sitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static function generateSitemap(Sitemap $sitemap = null){
$authors = [];

foreach($resources as $resource){
$sitemap->addItem(URL::build('/resources/resource/' . Output::getClean($resource->id . '-' . Util::stringToURL($resource->name))), 0.5, 'weekly', date('Y-m-d', $resource->updated));
$sitemap->addItem(URL::build('/resources/resource/' . Output::getClean($resource->id . '-' . URL::urlSafe($resource->name))), 0.5, 'weekly', date('Y-m-d', $resource->updated));
if(!in_array($resource->creator_id, $authors))
$authors[] = $resource->creator_id;
}
Expand All @@ -47,7 +47,7 @@ public static function generateSitemap(Sitemap $sitemap = null){
$categories = $db->query('SELECT id, `name` FROM nl2_resources_categories WHERE id IN (SELECT category_id FROM nl2_resources_categories_permissions WHERE group_id = 0 AND `view` = 1)')->results();

foreach($categories as $category){
$sitemap->addItem(URL::build('/resources/category/' . Output::getClean($category->id . '-' . Util::stringToURL($category->name))), 0.5, 'daily');
$sitemap->addItem(URL::build('/resources/category/' . Output::getClean($category->id . '-' . URL::urlSafe($category->name))), 0.5, 'daily');
}
}
}
57 changes: 21 additions & 36 deletions upload/modules/Resources/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
* Made by Samerton
* https://github.com/NamelessMC/Nameless/
* NamelessMC version 2.0.2
* NamelessMC version 2.1.0
*
* License: MIT
*
Expand All @@ -18,8 +18,8 @@ public function __construct($pages, $language, $resource_language){

$name = 'Resources';
$author = '<a href="https://samerton.me" target="_blank">Samerton</a>';
$module_version = '1.7.2';
$nameless_version = '2.0.2';
$module_version = '1.8.0';
$nameless_version = '2.1.0';

parent::__construct($this, $name, $author, $module_version, $nameless_version);

Expand Down Expand Up @@ -49,28 +49,13 @@ public function __construct($pages, $language, $resource_language){

public function onInstall(){
try {
$engine = Config::get('mysql/engine');
$charset = Config::get('mysql/charset');
} catch(Exception $e){
$engine = 'InnoDB';
$charset = 'utf8mb4';
}

if(!$engine || is_array($engine))
$engine = 'InnoDB';

if(!$charset || is_array($charset))
$charset = 'latin1';

$queries = new Queries();
try {
$data = $queries->createTable("resources_categories", " `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(32) NOT NULL, `description` text, `display_order` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`id`)", "ENGINE=$engine DEFAULT CHARSET=$charset");
$data = $queries->createTable("resources", " `id` int(11) NOT NULL AUTO_INCREMENT, `category_id` int(11) NOT NULL, `creator_id` int(11) NOT NULL, `name` varchar(64) NOT NULL, `short_description` varchar(64) NULL DEFAULT NULL, `has_icon` tinyint(1) NOT NULL DEFAULT '0', `icon` varchar(512) NULL DEFAULT NULL, `icon_updated` int(11) NOT NULL DEFAULT '0', `description` mediumtext NOT NULL, `contributors` text, `views` int(11) NOT NULL DEFAULT '0', `downloads` int(11) NOT NULL DEFAULT '0', `created` int(11) NOT NULL, `updated` int(11) NOT NULL, `github_url` varchar(128) DEFAULT NULL, `github_username` varchar(64) DEFAULT NULL, `github_repo_name` varchar(64) DEFAULT NULL, `rating` int(11) NOT NULL DEFAULT '0', `latest_version` varchar(32) DEFAULT NULL, `type` tinyint(1) NOT NULL DEFAULT '0', `price` varchar(16) DEFAULT NULL, `payment_email` varchar(256) DEFAULT NULL, PRIMARY KEY (`id`)", "ENGINE=$engine DEFAULT CHARSET=$charset");
$data = $queries->createTable("resources_releases", " `id` int(11) NOT NULL AUTO_INCREMENT, `resource_id` int(11) NOT NULL, `category_id` int(11) NOT NULL, `release_title` varchar(128) NOT NULL, `release_description` mediumtext NOT NULL, `release_tag` varchar(16) NOT NULL, `created` int(11) NOT NULL, `downloads` int(11) NOT NULL DEFAULT '0', `rating` int(11) NOT NULL DEFAULT '0', `download_link` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`)", "ENGINE=$engine DEFAULT CHARSET=$charset");
$data = $queries->createTable("resources_comments", " `id` int(11) NOT NULL AUTO_INCREMENT, `resource_id` int(11) NOT NULL, `author_id` int(11) NOT NULL, `content` mediumtext NOT NULL, `release_tag` varchar(16) NOT NULL, `created` int(11) NOT NULL, `reply_id` int(11) DEFAULT NULL, `rating` int(11) NOT NULL DEFAULT '0', `hidden` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`id`)", "ENGINE=$engine DEFAULT CHARSET=$charset");
$data = $queries->createTable("resources_categories_permissions", " `id` int(11) NOT NULL AUTO_INCREMENT, `category_id` int(11) NOT NULL, `group_id` int(11) NOT NULL, `view` tinyint(1) NOT NULL DEFAULT '1', `post` tinyint(1) NOT NULL DEFAULT '1', `move_resource` tinyint(1) NOT NULL DEFAULT '1', `edit_resource` tinyint(1) NOT NULL DEFAULT '1', `delete_resource` tinyint(1) NOT NULL DEFAULT '1', `edit_review` tinyint(1) NOT NULL DEFAULT '1', `delete_review` tinyint(1) NOT NULL DEFAULT '1', `download` tinyint(1) NOT NULL DEFAULT '0', `premium` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`id`)", "ENGINE=$engine DEFAULT CHARSET=$charset");
$data = $queries->createTable("resources_payments", " `id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL, `resource_id` int(11) NOT NULL, `transaction_id` varchar(32) NOT NULL, `created` int(11) NOT NULL, `status` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`id`)", "ENGINE=$engine DEFAULT CHARSET=$charset");
$data = $queries->createTable("resources_users_premium_details", " `id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL, `paypal_email` varchar(256) DEFAULT NULL, PRIMARY KEY (`id`)", "ENGINE=$engine DEFAULT CHARSET=$charset");
DB::getInstance()->createTable("resources_categories", " `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(32) NOT NULL, `description` text, `display_order` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`id`)");
DB::getInstance()->createTable("resources", " `id` int(11) NOT NULL AUTO_INCREMENT, `category_id` int(11) NOT NULL, `creator_id` int(11) NOT NULL, `name` varchar(64) NOT NULL, `short_description` varchar(64) NULL DEFAULT NULL, `has_icon` tinyint(1) NOT NULL DEFAULT '0', `icon` varchar(512) NULL DEFAULT NULL, `icon_updated` int(11) NOT NULL DEFAULT '0', `description` mediumtext NOT NULL, `contributors` text, `views` int(11) NOT NULL DEFAULT '0', `downloads` int(11) NOT NULL DEFAULT '0', `created` int(11) NOT NULL, `updated` int(11) NOT NULL, `github_url` varchar(128) DEFAULT NULL, `github_username` varchar(64) DEFAULT NULL, `github_repo_name` varchar(64) DEFAULT NULL, `rating` int(11) NOT NULL DEFAULT '0', `latest_version` varchar(32) DEFAULT NULL, `type` tinyint(1) NOT NULL DEFAULT '0', `price` varchar(16) DEFAULT NULL, `payment_email` varchar(256) DEFAULT NULL, PRIMARY KEY (`id`)");
DB::getInstance()->createTable("resources_releases", " `id` int(11) NOT NULL AUTO_INCREMENT, `resource_id` int(11) NOT NULL, `category_id` int(11) NOT NULL, `release_title` varchar(128) NOT NULL, `release_description` mediumtext NOT NULL, `release_tag` varchar(16) NOT NULL, `created` int(11) NOT NULL, `downloads` int(11) NOT NULL DEFAULT '0', `rating` int(11) NOT NULL DEFAULT '0', `download_link` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`)");
DB::getInstance()->createTable("resources_comments", " `id` int(11) NOT NULL AUTO_INCREMENT, `resource_id` int(11) NOT NULL, `author_id` int(11) NOT NULL, `content` mediumtext NOT NULL, `release_tag` varchar(16) NOT NULL, `created` int(11) NOT NULL, `reply_id` int(11) DEFAULT NULL, `rating` int(11) NOT NULL DEFAULT '0', `hidden` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`id`)");
DB::getInstance()->createTable("resources_categories_permissions", " `id` int(11) NOT NULL AUTO_INCREMENT, `category_id` int(11) NOT NULL, `group_id` int(11) NOT NULL, `view` tinyint(1) NOT NULL DEFAULT '1', `post` tinyint(1) NOT NULL DEFAULT '1', `move_resource` tinyint(1) NOT NULL DEFAULT '1', `edit_resource` tinyint(1) NOT NULL DEFAULT '1', `delete_resource` tinyint(1) NOT NULL DEFAULT '1', `edit_review` tinyint(1) NOT NULL DEFAULT '1', `delete_review` tinyint(1) NOT NULL DEFAULT '1', `download` tinyint(1) NOT NULL DEFAULT '0', `premium` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`id`)");
DB::getInstance()->createTable("resources_payments", " `id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL, `resource_id` int(11) NOT NULL, `transaction_id` varchar(32) NOT NULL, `created` int(11) NOT NULL, `status` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`id`)");
DB::getInstance()->createTable("resources_users_premium_details", " `id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL, `paypal_email` varchar(256) DEFAULT NULL, PRIMARY KEY (`id`)");
} catch(Exception $e){
// Error
}
Expand All @@ -80,13 +65,13 @@ public function onInstall(){
}

public function onUninstall(){
DB::getInstance()->createQuery('DROP TABLE resources_categories');
DB::getInstance()->createQuery('DROP TABLE resources');
DB::getInstance()->createQuery('DROP TABLE resources_releases');
DB::getInstance()->createQuery('DROP TABLE resources_comments');
DB::getInstance()->createQuery('DROP TABLE resources_categories_permissions');
DB::getInstance()->createQuery('DROP TABLE resources_payments');
DB::getInstance()->createQuery('DROP TABLE resources_users_premium_details');
DB::getInstance()->query('DROP TABLE resources_categories');
DB::getInstance()->query('DROP TABLE resources');
DB::getInstance()->query('DROP TABLE resources_releases');
DB::getInstance()->query('DROP TABLE resources_comments');
DB::getInstance()->query('DROP TABLE resources_categories_permissions');
DB::getInstance()->query('DROP TABLE resources_payments');
DB::getInstance()->query('DROP TABLE resources_users_premium_details');
}

public function onEnable(){
Expand Down Expand Up @@ -196,10 +181,10 @@ public function onPageLoad($user, $pages, $cache, $smarty, $navs, $widgets, $tem
// Update to 1.6.0
private static function updateTo160($cache) {
try {
DB::getInstance()->createQuery('ALTER TABLE `nl2_resources` ADD `short_description` varchar(64) NULL DEFAULT NULL');
DB::getInstance()->createQuery('ALTER TABLE `nl2_resources` ADD `has_icon` tinyint(1) NOT NULL DEFAULT \'0\'');
DB::getInstance()->createQuery('ALTER TABLE `nl2_resources` ADD `icon` varchar(512) NULL DEFAULT NULL');
DB::getInstance()->createQuery('ALTER TABLE `nl2_resources` ADD `icon_updated` int(11) NOT NULL DEFAULT \'0\'');
DB::getInstance()->query('ALTER TABLE `nl2_resources` ADD `short_description` varchar(64) NULL DEFAULT NULL');
DB::getInstance()->query('ALTER TABLE `nl2_resources` ADD `has_icon` tinyint(1) NOT NULL DEFAULT \'0\'');
DB::getInstance()->query('ALTER TABLE `nl2_resources` ADD `icon` varchar(512) NULL DEFAULT NULL');
DB::getInstance()->query('ALTER TABLE `nl2_resources` ADD `icon_updated` int(11) NOT NULL DEFAULT \'0\'');

$cache->store('160', true);

Expand Down
8 changes: 4 additions & 4 deletions upload/modules/Resources/pages/resources/author.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
$category_count = $category_count->count();
$to_array = [
'name' => Output::getClean($category->name),
'link' => URL::build('/resources/category/' . $category->id . '-' . Util::stringToURL($category->name)),
'link' => URL::build('/resources/category/' . $category->id . '-' . URL::urlSafe($category->name)),
'count' => Output::getClean($category_count)
];
$category_array[] = $to_array;
Expand All @@ -87,7 +87,7 @@
// Pagination
$paginator = new Paginator((isset($template_pagination) ? $template_pagination : []));
$results = $paginator->getLimited($latest_releases, 10, $p, count($latest_releases));
$pagination = $paginator->generate(7, URL::build('/resources/author/' . $author->data()->id . '-' . Util::stringToURL($author->getDisplayname(true)) . '/', true));
$pagination = $paginator->generate(7, URL::build('/resources/author/' . $author->data()->id . '-' . URL::urlSafe($author->getDisplayname(true)) . '/', true));

$smarty->assign('PAGINATION', $pagination);

Expand All @@ -112,7 +112,7 @@

if (!isset($releases_array[$results->data[$n]->id])) {
$releases_array[$results->data[$n]->id] = [
'link' => URL::build('/resources/resource/' . $results->data[$n]->id . '-' . Util::stringToURL($results->data[$n]->name)),
'link' => URL::build('/resources/resource/' . $results->data[$n]->id . '-' . URL::urlSafe($results->data[$n]->name)),
'name' => Output::getClean($results->data[$n]->name),
'short_description' => Output::getClean($results->data[$n]->short_description),
'description' => mb_substr(strip_tags(Output::getDecoded($results->data[$n]->description)), 0, 50) . '...',
Expand All @@ -137,7 +137,7 @@
if($results->data[$n]->has_icon == 1 ) {
$releases_array[$results->data[$n]->id]['icon'] = $results->data[$n]->icon;
} else {
$releases_array[$results->data[$n]->id]['icon'] = rtrim(Util::getSelfURL(), '/') . (defined('CONFIG_PATH') ? CONFIG_PATH . '/' : '/') . 'uploads/resources_icons/default.png';
$releases_array[$results->data[$n]->id]['icon'] = rtrim(URL::getSelfURL(), '/') . (defined('CONFIG_PATH') ? CONFIG_PATH . '/' : '/') . 'uploads/resources_icons/default.png';
}

}
Expand Down
14 changes: 7 additions & 7 deletions upload/modules/Resources/pages/resources/category.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@
$current_category = $current_category->first();

$sort_types = [];
$sort_types['updated'] = ['type' => 'updated', 'sort' => $resource_language->get('resources', 'last_updated'), 'link' => URL::build('/resources/category/' . $current_category->id . '-' . Util::stringToURL($current_category->name), 'sort=updated')];
$sort_types['newest'] = ['type' => 'created', 'sort' => $resource_language->get('resources', 'newest'), 'link' => URL::build('/resources/category/' . $current_category->id . '-' . Util::stringToURL($current_category->name), 'sort=newest')];
$sort_types['downloads'] = ['type' => 'downloads', 'sort' => $resource_language->get('resources', 'downloads'), 'link' => URL::build('/resources/category/' . $current_category->id . '-' . Util::stringToURL($current_category->name), 'sort=downloads')];
$sort_types['updated'] = ['type' => 'updated', 'sort' => $resource_language->get('resources', 'last_updated'), 'link' => URL::build('/resources/category/' . $current_category->id . '-' . URL::urlSafe($current_category->name), 'sort=updated')];
$sort_types['newest'] = ['type' => 'created', 'sort' => $resource_language->get('resources', 'newest'), 'link' => URL::build('/resources/category/' . $current_category->id . '-' . URL::urlSafe($current_category->name), 'sort=newest')];
$sort_types['downloads'] = ['type' => 'downloads', 'sort' => $resource_language->get('resources', 'downloads'), 'link' => URL::build('/resources/category/' . $current_category->id . '-' . URL::urlSafe($current_category->name), 'sort=downloads')];

if(isset($_GET['sort']) && array_key_exists($_GET['sort'], $sort_types)){
$sort_type = $_GET['sort'];
Expand All @@ -61,7 +61,7 @@
} else {
$sort_by = 'updated';
$sort_by_text = $resource_language->get('resources', 'last_updated');
$url = URL::build('/resources/category/' . $current_category->id . '-' . Util::stringToURL($current_category->name), '');
$url = URL::build('/resources/category/' . $current_category->id . '-' . URL::urlSafe($current_category->name), '');
}

if ($user->isLoggedIn()) {
Expand Down Expand Up @@ -91,7 +91,7 @@
$category_count = $category_count->count();
$to_array = [
'name' => Output::getClean($category->name),
'link' => URL::build('/resources/category/' . $category->id . '-' . Util::stringToURL($category->name)),
'link' => URL::build('/resources/category/' . $category->id . '-' . URL::urlSafe($category->name)),
'count' => Output::getClean($category_count)
];
if($current_category->id == $category->id){
Expand Down Expand Up @@ -132,7 +132,7 @@
if (!isset($releases_array[$resource->id])) {
$resource_author = new User($resource->creator_id);
$releases_array[$resource->id] = [
'link' => URL::build('/resources/resource/' . $resource->id . '-' . Util::stringToURL($resource->name)),
'link' => URL::build('/resources/resource/' . $resource->id . '-' . URL::urlSafe($resource->name)),
'name' => Output::getClean($resource->name),
'short_description' => Output::getClean($resource->short_description),
'description' => mb_substr(strip_tags(Output::getPurified(Output::getDecoded($resource->description))), 0, 50) . '...',
Expand All @@ -157,7 +157,7 @@
if($resource->has_icon == 1 ) {
$releases_array[$resource->id]['icon'] = $resource->icon;
} else {
$releases_array[$resource->id]['icon'] = rtrim(Util::getSelfURL(), '/') . (defined('CONFIG_PATH') ? CONFIG_PATH . '/' : '/') . 'uploads/resources_icons/default.png';
$releases_array[$resource->id]['icon'] = rtrim(URL::getSelfURL(), '/') . (defined('CONFIG_PATH') ? CONFIG_PATH . '/' : '/') . 'uploads/resources_icons/default.png';
}
}

Expand Down
4 changes: 2 additions & 2 deletions upload/modules/Resources/pages/resources/icon_upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@
}

DB::getInstance()->update('resources', $resource->id, [
'icon' => rtrim(Util::getSelfURL(), '/') . (defined('CONFIG_PATH') ? CONFIG_PATH . '/' : '/') . 'uploads/resources_icons/'. $resource->id . '.' . $upload->getMime(),
'icon' => rtrim(URL::getSelfURL(), '/') . (defined('CONFIG_PATH') ? CONFIG_PATH . '/' : '/') . 'uploads/resources_icons/'. $resource->id . '.' . $upload->getMime(),
'has_icon' => 1,
'icon_updated' => date('U')
]);

Redirect::to(URL::build('/resources/resource/' . $resource->id . '-' . Util::stringToURL($resource->name)));
Redirect::to(URL::build('/resources/resource/' . $resource->id . '-' . URL::urlSafe($resource->name)));

} else {
http_response_code(400);
Expand Down
Loading

0 comments on commit 4f05523

Please sign in to comment.