From aa2b6dfba6d2b82d9dfe834da8f73fa3c1366c33 Mon Sep 17 00:00:00 2001 From: effone Date: Fri, 9 Apr 2021 14:22:07 +0530 Subject: [PATCH] Create settings --- README.md | 12 +++-- .../languages/english/admin/markpost.lang.php | 6 +++ upload/inc/plugins/markpost.php | 53 +++++++++++++------ 3 files changed, 52 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 7ba5496..7ef5fdf 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,15 @@ # Bookmark-Post A plugin for MyBB to Bookmark posts those are important to get quick access on a later stage -## TODO: -- Some Settings +## Implemented Features +- Users can bookmark any visible post the feel useful for future reference +- The list of bookmarked posts appears in user's UCP for quick access + ## Planned Features - Add personalized notes against each bookmarked post - AJAX bookmark removal -- Remove bookmarks directly from UCP \ No newline at end of file +- Remove bookmarks directly from UCP +- Show number of posts bookmarked by the user in user profile +- Show number of posts made by the user that others bookmarked in user profile +- Limit bookmarking per usergroup (might be useful for those paid group promotion sites) +- Export bookmarked posts (?) \ No newline at end of file diff --git a/upload/inc/languages/english/admin/markpost.lang.php b/upload/inc/languages/english/admin/markpost.lang.php index ab6a785..f231fb8 100644 --- a/upload/inc/languages/english/admin/markpost.lang.php +++ b/upload/inc/languages/english/admin/markpost.lang.php @@ -1,4 +1,10 @@ If you choose 'No' the accumulated data will remain in the database for future reference / usage.
Choosing 'Yes' will drop the table wiping all data and this can not be undone."; \ No newline at end of file diff --git a/upload/inc/plugins/markpost.php b/upload/inc/plugins/markpost.php index 21ecdb1..9ed023c 100644 --- a/upload/inc/plugins/markpost.php +++ b/upload/inc/plugins/markpost.php @@ -7,9 +7,11 @@ if (defined('IN_ADMINCP')) { function markpost_info() { + global $lang; + $lang->load('markpost'); return array( - 'name' => 'Bookmark Post', - 'description' => 'Bookmark posts those are important to get quick access on a later stage.', + 'name' => $lang->markpost_title, + 'description' => $lang->markpost_desc, 'website' => 'https://mybb.group/Thread-Bookmark-Post', 'author' => 'effone, Laird & Omar G.', 'authorsite' => 'https://eff.one', @@ -33,7 +35,8 @@ function markpost_deactivate() function markpost_install() { - global $db; + global $db, $lang; + $lang->load('markpost'); // Install templates $templates = array(); @@ -51,7 +54,7 @@ function markpost_install() } $db->query( - "CREATE TABLE IF NOT EXISTS " . TABLE_PREFIX . "markpost ( + "CREATE TABLE IF NOT EXISTS {$db->table_prefix}markpost ( mid int(10) UNSIGNED NOT NULL AUTO_INCREMENT, uid int(10) UNSIGNED NOT NULL, pid int(10) UNSIGNED NOT NULL, @@ -66,14 +69,31 @@ function markpost_install() // Build Plugin Settings $markpost_group = array( "name" => "markpost", - "title" => "markpost", - "description" => 'Mark a post as important to get quick access on a later stage.', + "title" => $lang->markpost_title, + "description" => $lang->markpost_desc, "disporder" => "9", "isdefault" => "0", ); $db->insert_query("settinggroups", $markpost_group); $gid = $db->insert_id(); + $markpost_opts = array( + ['per_page', 'numeric', '8'], + ['force_redirect', 'onoff', '1'] + ); $disporder = 0; + $markpost_settings = array(); + + foreach ($markpost_opts as $markpost_opt) { + $markpost_opt[0] = 'markpost_' . $markpost_opt[0]; + $markpost_opt = array_combine(['name', 'optionscode', 'value'], $markpost_opt); + $markpost_opt['title'] = $lang->{$markpost_opt['name'] . "_title"}; + $markpost_opt['description'] = $lang->{$markpost_opt['name'] . "_desc"}; + $markpost_opt['disporder'] = $disporder++; + $markpost_opt['gid'] = intval($gid); + $markpost_settings[] = $markpost_opt; + } + $db->insert_query_multiple('settings', $markpost_settings); + rebuild_settings(); } function markpost_is_installed() @@ -97,10 +117,10 @@ function markpost_uninstall() } else { // Only remove the database tables if the admin has selected NOT to keep data. if (!isset($mybb->input['no'])) { - $db->query("drop TABLE " . TABLE_PREFIX . "markpost"); + $db->query("drop TABLE {$db->table_prefix}markpost"); } - //$db->delete_query("settings", "name LIKE '%ipatrol%'"); + $db->delete_query("settings", "name LIKE '%markpost%'"); $db->delete_query("settinggroups", "name='markpost'"); // Delete Templates @@ -139,9 +159,9 @@ function markpost_stamp(&$post) if (!empty($dupes)) { foreach ($dupes as $dupe) { $db->query( - "DELETE FROM " . TABLE_PREFIX . "markpost WHERE uid=" . $mybb->user['uid'] . " AND pid={$dupe} and mid not in + "DELETE FROM {$db->table_prefix}markpost WHERE uid=" . $mybb->user['uid'] . " AND pid={$dupe} and mid not in ( SELECT * FROM - (SELECT MIN(mid) FROM " . TABLE_PREFIX . "markpost WHERE uid={$mybb->user['uid']} AND pid={$dupe}) AS temp + (SELECT MIN(mid) FROM {$db->table_prefix}markpost WHERE uid={$mybb->user['uid']} AND pid={$dupe}) AS temp )" ); } @@ -184,7 +204,7 @@ function markpost_commit() } else { $state = 'failure'; } - $mybb->settings['markpost_force_redirect'] = false; + $lang->load('markpost'); redirect("showthread.php?tid={$tid}&pid={$pid}#pid{$pid}", $lang->{'markpost_' . $mybb->input['action'] . $state . '_message'}, '', (bool)$mybb->settings['markpost_force_redirect']); } @@ -281,7 +301,8 @@ function markpost_listdown() $postmarks = ""; $alt_row = alt_trow(true); - $perpage = 8; // Settings??? + $perpage = (int)$mybb->settings['markpost_per_page']; + if (empty($perpage) || $perpage < 1) $perpage = 8; $pagenum = $mybb->get_input('page', MyBB::INPUT_INT); if ($pagenum > 0) $offset = ($pagenum - 1) * $perpage; if ($pagenum <= 0 || $pagenum > ceil($marked / $perpage)) // Reset range out @@ -296,10 +317,10 @@ function markpost_listdown() SELECT p.uid as poster, p.subject, p.message as post, p.dateline as postdate, t.uid as originator, t.dateline as threaddate, t.subject as tsubject, t.fid, f.name as forum, m.pid, m.tid, m.dateline as markdate - FROM " . TABLE_PREFIX . "markpost m - LEFT JOIN " . TABLE_PREFIX . "posts p on (m.pid = p.pid) - LEFT JOIN " . TABLE_PREFIX . "threads t on (m.tid = t.tid) - LEFT JOIN " . TABLE_PREFIX . "forums f on (t.fid = f.fid) + FROM {$db->table_prefix}markpost m + LEFT JOIN {$db->table_prefix}posts p on (m.pid = p.pid) + LEFT JOIN {$db->table_prefix}threads t on (m.tid = t.tid) + LEFT JOIN {$db->table_prefix}forums f on (t.fid = f.fid) WHERE {$where} ORDER BY m.dateline DESC LIMIT {$perpage} OFFSET {$offset}