Not Solved Hide Politics
#1
Not Solved
I'm intending to setup a PG board and I find this Hide Politics plugin a very helpful way to mark threads as 18+ content warning to youngsters. Only problem is it's not working properly.

Hide Politics plugin:
https://community.mybb.com/mods.php?action=view&pid=837

I have Threaded Mode plugin installed and alter table permissions for my database user.

When I turn on threaded mode I get this error:

Quote:Fatal error: Uncaught Error: Call to private method ThreadedMode::buildtree() from context 'HidePolitics' in C:\xampp\htdocs\mybb\inc\plugins\hide_politics.php:296 Stack trace: #0 C:\xampp\htdocs\mybb\inc\plugins\hide_politics.php(34): HidePolitics::showthread_threaded() #1 C:\xampp\htdocs\mybb\inc\class_plugins.php(139): hide_politics_showthread_threaded('') #2 C:\xampp\htdocs\mybb\showthread.php(882): pluginSystem->run_hooks(Array) #3 {main} thrown in C:\xampp\htdocs\mybb\inc\plugins\hide_politics.php on line 296

It's only 1 php file.

Quote:<?php

if(!defined("IN_MYBB")) {
   die("You cannot access this file directly. Please make sure IN_MYBB is defined.");
}

$plugins->add_hook('forumdisplay_get_threads', 'hide_politics_forumdisplay_get_threads');
$plugins->add_hook('showthread_linear', 'hide_politics_showthread_linear');
$plugins->add_hook('showthread_threaded', 'hide_politics_showthread_threaded', 1);
$plugins->add_hook('usercp_options_end', 'hide_politics_usercp_options_end');
$plugins->add_hook('usercp_do_options_end', 'hide_politics_usercp_do_options_end');

function hide_politics_info() {
return HidePolitics::info();
}

function hide_politics_activate() {
HidePolitics::activate();
}

function hide_politics_deactivate() {
HidePolitics::deactivate();
}

function hide_politics_forumdisplay_get_threads() {
HidePolitics::forumdisplay_get_threads();
}

function hide_politics_showthread_linear() {
HidePolitics::showthread_linear();
}

function hide_politics_showthread_threaded() {
HidePolitics::showthread_threaded();
}

function hide_politics_usercp_options_end() {
HidePolitics::usercp_options_end();
}

function hide_politics_usercp_do_options_end() {
HidePolitics::usercp_do_options_end();
}

class HidePolitics {

private static $description = "Allows posters and moderators to marks posts and threads as political using the Politics icon and thread prefix, and allows users to opt out of seeing posts and threads marked with such icons or thread prefixes.  This plugin requires that the Threaded Mode plugin be installed.";

public static function info() {
return array(
"name"   => "Hide Politics",
"description" => self::$description,
"website"       => "http://forums.woodnet.net",
"author"        => "kloddant",
"authorsite"    => "http://forums.woodnet.net",
"version"       => "1.0",
"guid"          => "",
"compatibility" => "18*"
);
}

public static function activate() {
global $db;

if (!class_exists('ThreadedMode')) {
error("Cannot activate Hide Politics.  Threaded Mode plugin must be installed.");
}

$group = array(
       'name'    => 'hide_politics',
       'title'       => 'Hide Politics',
       'description' => self::$description,
       'disporder'   => "1",
       'isdefault'   => "0",
   );

   $db->insert_query('settinggroups', $group);
$gid = $db->insert_id();

$enable = array(
       'name'        => 'hide_politics_enable',
       'title'            => 'Do you want to enable hide politics?',
       'description'    => 'If you set this option to yes, this plugin will allow posters and moderators to mark posts and threads as political and users to opt out of seeing political posts and threads.',
       'optionscode'    => 'yesno',
       'value'        => '1',
       'disporder'        => 1,
       'gid'            => intval($gid),
   );

   $db->insert_query('settings', $enable);
rebuild_settings();

$prefix = array(
"prefix" => "Politics",
"displaystyle" => $db->escape_string("<img class=\"thread-prefix politics\" src=\"/images/icons/politics.gif\" />"),
);
$db->insert_query("threadprefixes", $prefix);

$icon = array(
"name" => "Politics",
"path" => "images/icons/politics.gif"
);
$db->insert_query("icons", $icon);

$db->add_column("users", "showpolitics", "BOOLEAN DEFAULT 1");

self::write_image();
}

public static function deactivate() {
global $db;

$db->query("
DELETE FROM ".TABLE_PREFIX."settings
WHERE name LIKE 'hide_politics%'
");
   $db->query("
    DELETE FROM ".TABLE_PREFIX."settinggroups
    WHERE name = 'hide_politics'
   ");

   $db->query("
    DELETE FROM ".TABLE_PREFIX."threadprefixes
    WHERE prefix = 'Politics'
   ");

   $db->query("
    DELETE FROM ".TABLE_PREFIX."icons
    WHERE name = 'Politics'
   ");

rebuild_settings();

$db->drop_column("users", "showpolitics");

unlink(MYBB_ROOT."images/icons/politics.gif");
}

public static function forumdisplay_get_threads() {
global $mybb, $db, $ratingadd, $fid, $tuseronly, $tvisibleonly, $datecutsql2, $prefixsql2, $t, $sortfield, $sortordernow, $sortfield2, $start, $perpage;
if (!$mybb->settings['hide_politics_enable']) {
return;
}
$ratingadd = $ratingadd."
t.username AS threadusername, u.username
FROM ".TABLE_PREFIX."threads t
LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid = t.uid)
LEFT OUTER JOIN ".TABLE_PREFIX."threadprefixes p ON (t.prefix = p.pid)
LEFT OUTER JOIN ".TABLE_PREFIX."icons i ON (t.icon = i.iid)
WHERE t.fid='$fid' $tuseronly $tvisibleonly $datecutsql2 $prefixsql2 AND (".(isset($mybb->user['showpolitics'])?$mybb->user['showpolitics']:'1')." = 1 OR ((p.prefix <> 'Politics' OR p.prefix IS NULL) AND (i.name <> 'Politics' OR i.name IS NULL)))
ORDER BY t.sticky DESC, {$t}{$sortfield} $sortordernow $sortfield2
LIMIT $start, $perpage
/*
";
$perpage = "*/";
}

public static function showthread_linear() {
global $mybb, $db, $post, $thread, $pids, $posts;
if (!$mybb->settings['hide_politics_enable']) {
return;
}
$query = $db->query("
SELECT u.*, u.username AS userusername, p.*, f.*, eu.username AS editusername, CONCAT('Re: ', parent.subject) AS parentsubject, CONCAT('by ', parent.username) AS parentusername, CONCAT('(', SUBSTRING(parent.message, 1, 20), '...)') AS parentmessage
FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid)
LEFT JOIN ".TABLE_PREFIX."userfields f ON (f.ufid=u.uid)
LEFT JOIN ".TABLE_PREFIX."users eu ON (eu.uid=p.edituid)
LEFT OUTER JOIN ".TABLE_PREFIX."icons i ON (p.icon = i.iid)
LEFT OUTER JOIN ".TABLE_PREFIX."posts parent ON (p.replyto = parent.pid)
WHERE p.$pids AND (".(isset($mybb->user['showpolitics'])?$mybb->user['showpolitics']:'1')." = 1 OR i.name <> 'Politics' OR i.name IS NULL)
ORDER BY p.dateline
");
$posts = "";
while($post = $db->fetch_array($query))
{
$post['parentusername'] = htmlspecialchars(strip_tags($post['parentusername']));
$post['parentsubject'] = htmlspecialchars(strip_tags($post['parentsubject']));
$post['parentmessage'] = htmlspecialchars(strip_tags($post['parentmessage']));
if($thread['firstpost'] == $post['pid'] && $thread['visible'] == 0)
{
$post['visible'] = 0;
}
$posts .= build_postbit($post);
$post = '';
}
}

public static function showthread_threaded() {
global $mybb, $db, $threadexbox, $templates, $tid, $visible, $start, $perpage, $tree, $postsdone, $pids, $threadedbits, $posts;
if (!$mybb->settings['hide_politics_enable'] or !class_exists('ThreadedMode')) {
return;
}

$tree = array();
$postsdone = array();
$pids = array();
$threadedbits = "";
$posts = "";
$threadexbox = "";

$isfirst = 1;

// Pagination
if(!$mybb->settings['postsperpage'] || (int)$mybb->settings['postsperpage'] < 1) {
$mybb->settings['postsperpage'] = 20;
}
$perpage = $mybb->settings['postsperpage'];

$page = 1;
if($mybb->get_input('page', MyBB::INPUT_INT) && $mybb->get_input('page') != "last")
{
$page = $mybb->get_input('page', MyBB::INPUT_INT);
}

$query = $db->query("
       SELECT count(*) AS count
FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid)
LEFT JOIN ".TABLE_PREFIX."userfields f ON (f.ufid=u.uid)
LEFT OUTER JOIN ".TABLE_PREFIX."icons i ON (p.icon = i.iid)
       WHERE p.tid='$tid'
       $visible
   ");
   $postcount = $db->fetch_field($query, "count");

   $pages = ceil($postcount / $perpage);

if($mybb->get_input('page') == "last") {
$page = $pages;
}

if($page > $pages || $page <= 0) {
$page = 1;
}

if($page) {
$start = ($page-1) * $perpage;
}
else {
$start = 0;
$page = 1;
}
$upper = $start + $perpage;
$multipage = multipage($postcount, $perpage, $page, str_replace("{tid}", $tid, THREAD_URL_PAGED."&amp;mode=threaded"));

$query = $db->query("
           SELECT u.*, u.username AS userusername, p.*, f.*, eu.username AS editusername, parent.subject AS parentsubject, parent.username AS parentusername, CONCAT(SUBSTRING(parent.message, 1, 20), '...') AS parentmessage
FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid)
LEFT JOIN ".TABLE_PREFIX."userfields f ON (f.ufid=u.uid)
LEFT JOIN ".TABLE_PREFIX."users eu ON (eu.uid=p.edituid)
LEFT OUTER JOIN ".TABLE_PREFIX."icons i ON (p.icon = i.iid)
LEFT OUTER JOIN ".TABLE_PREFIX."posts parent ON (p.replyto = parent.pid)
           WHERE p.tid='$tid'
           AND (".(isset($mybb->user['showpolitics'])?$mybb->user['showpolitics']:'1')." = 1 OR i.name <> 'Politics' OR i.name IS NULL)
           $visible
           ORDER BY p.dateline, p.replyto
           LIMIT $start, $perpage
       ");
       $pids = array();

       while($post = $db->fetch_array($query))
       {

           if(!$postsdone[$post['pid']])
           {
               if($post['pid'] == $mybb->input['pid'] || ($isfirst && !$mybb->input['pid']))
               {
$postcounter = count($postsdone);
                   $isfirst = 0;
               }
               if ($post['replyto'] == "") {
                $post['replyto'] = 0;
               }
               if (is_null($tree) or !in_array($post['replyto'], $pids)) {
                $post['replyto'] = 0;
               }
               $tree[$post['replyto']][$post['pid']] = $post;
               $postsdone[$post['pid']] = 1;
               $pids[] = $post['pid'];
           }
       }

       $attachcache = array();
if($mybb->settings['enableattachments'] == 1 && $thread['attachmentcount'] > 0 || is_moderator($fid, 'caneditposts'))
{
// Get the attachments for this post.
$query = $db->simple_select("attachments", "*", "pid IN (".implode(',', $pids).")");
while($attachment = $db->fetch_array($query))
{
$attachcache[$attachment['pid']][$attachment['aid']] = $attachment;
}
}

$threadedbits = ThreadedMode::buildtree();
eval("\$threadexbox = \"".$templates->get("showthread_threadedbox")."\";");
}

private static function write_image() {
$image_contents = "R0lGODlhDwAPAKIAAP///66urtPT04yMjBIA/wAAAP8AAAAAACH5BAAAAAAALAAAAAAPAA8AAAM6CLpQ9iyqQqqM5crB9RpCOHhDYJrjBQYCm25t/EarrJ74rNSsu4TAXgzYwhmNgEAyqTQtlU+mtAlIAAA7";
$handle = fopen(MYBB_ROOT."images/icons/politics.gif", "w");
fwrite($handle, base64_decode($image_contents));
fclose($handle);
}

public static function usercp_options_end() {
global $user, $board_style, $mybb;
if (!$mybb->settings['hide_politics_enable']) {
return;
}
if(isset($user['showpolitics']) && $user['showpolitics'] == 1) {
$showpoliticscheck = "checked=\"checked\"";
}
else {
$showpoliticscheck = "";
}
$option = '
<tr>
<td valign="top" width="1"><input type="checkbox" class="checkbox" name="showpolitics" id="showpolitics" value="1" '.$showpoliticscheck.' /></td>
<td><span class="smalltext"><label for="showpolitics">Show political content</label></span></td>
</tr>
';
$board_style = $option.$board_style;
}

public static function usercp_do_options_end() {
global $user, $mybb, $errors, $userhandler;
if (!$mybb->settings['hide_politics_enable']) {
return;
}

$user['options']['showpolitics'] = $mybb->get_input('showpolitics', MyBB::INPUT_INT);
$userhandler->set_data($user);
if(!$userhandler->validate_user()) {
$errors = $userhandler->get_friendly_errors();
$errors = inline_error($errors);
$mybb->input['action'] = "options";
}
else {
$userhandler->update_user();
}
}

}

?>
Any help with this would be great. Especially if there is a way to use this plugin without using threaded mode?
Reply
#2
Not Solved
Strange, seeing this code you may have an alert when trying to activate: Cannot activate Hide Politics. Threaded Mode plugin must be installed. (this is writen in the plugin page, as requirement).
Download https://community.mybb.com/mods.php?action=view&pid=829 and install it before installing this one.
Tchat en français
Do not ask me help through PM or Discord

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)