Skip to content

Commit

Permalink
Create settings
Browse files Browse the repository at this point in the history
  • Loading branch information
effone committed Apr 9, 2021
1 parent 3f51a94 commit aa2b6df
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 19 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
- 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 (?)
6 changes: 6 additions & 0 deletions upload/inc/languages/english/admin/markpost.lang.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
<?php

$l['markpost_title'] = "Bookmark Post";
$l['markpost_desc'] = "Bookmark posts those are important to get quick access on a later stage.";
$l['markpost_per_page_title'] = "Bookmarks Per Page";
$l['markpost_per_page_desc'] = "Define the number of bookmarked posts that will be listed in a single page in UCP";
$l['markpost_force_redirect_title'] = "Force Redirect Page";
$l['markpost_force_redirect_desc'] = "Force user to see redirect page after adding / removing bookmarks for status message";
$l['markpost_uninstall'] = "Uninstall Markpost";
$l['markpost_uninstall_message'] = "Are you sure you want to delete all the existing data of Mark Post?<br>If you choose 'No' the accumulated data will remain in the database for future reference / usage.<br>Choosing 'Yes' will drop the table wiping all data and this can not be undone.";
53 changes: 37 additions & 16 deletions upload/inc/plugins/markpost.php
Original file line number Diff line number Diff line change
Expand Up @@ -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</a>, <a href="https://creativeandcritical.net">Laird</a> & <a href="https://ougc.network">Omar G.',
'authorsite' => 'https://eff.one',
Expand All @@ -33,7 +35,8 @@ function markpost_deactivate()

function markpost_install()
{
global $db;
global $db, $lang;
$lang->load('markpost');

// Install templates
$templates = array();
Expand All @@ -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,
Expand All @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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
)"
);
}
Expand Down Expand Up @@ -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']);
}
Expand Down Expand Up @@ -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
Expand All @@ -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}
Expand Down

0 comments on commit aa2b6df

Please sign in to comment.