diff --git a/src/customCategory.js b/src/customCategory.js index 99d2c226..b47d6623 100644 --- a/src/customCategory.js +++ b/src/customCategory.js @@ -115,7 +115,7 @@ class CustomCategory { applyContent (content) { this.content = content - ajax('customCategory', { content: this.content }, () => {}) + ajax('customCategory', { action: 'save' }, this.content, () => {}) if (this.textarea) { this.textarea.value = content @@ -207,7 +207,7 @@ hooks.register('browser-more-categories', (browser, parameters) => { function customCategoriesList (browser, options) { browser.dom.innerHTML = ' ' + lang('loading') - ajax('customCategory', { 'list': true }, (result) => { + ajax('customCategory', { action: 'list' }, (result) => { browser.dom.innerHTML = '' const ul = document.createElement('ul') diff --git a/src/customCategory.php b/src/customCategory.php index 388d78f0..eb7e331c 100644 --- a/src/customCategory.php +++ b/src/customCategory.php @@ -1,12 +1,12 @@ prepare("select customCategory.id, customCategory.created, customCategory.content, t.accessCount, t.popularity, t.lastAccess from customCategory left join (select id, count(id) accessCount, sum(1/((julianday('2023-08-06 00:00:00') - julianday(ts))/365.25 + 1)) popularity, max(ts) lastAccess from customCategoryAccess group by id) t on customCategory.id=t.id order by popularity desc, created desc limit 25"); @@ -32,7 +32,7 @@ function ajax_customCategory ($param) { return $data; } - if ($param['id']) { + if (isset($param['id'])) { $stmt = $db->prepare("select content from customCategory where id=:id"); $stmt->bindValue(':id', $param['id'], PDO::PARAM_STR); if ($stmt->execute()) { @@ -48,12 +48,12 @@ function ajax_customCategory ($param) { return false; } - if ($param['content']) { - $id = md5($param['content']); + if (isset($param['action']) && $param['action'] === 'save') { + $id = md5($content); $stmt = $db->prepare("insert or ignore into customCategory (id, content) values (:id, :content)"); $stmt->bindValue(':id', $id, PDO::PARAM_STR); - $stmt->bindValue(':content', $param['content'], PDO::PARAM_STR); + $stmt->bindValue(':content', $content, PDO::PARAM_STR); $result = $stmt->execute(); customCategoryUpdateAccess($id);