MyBB Community Forums

Full Version: Information in the warned post.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I was on MyBB 1.6.x plugin information in the post, which has been issued a warning.


However, in the MyBB 1.8.x does not work to me, you can look at what I'm doing wrong?


function postwarnings_collect(&$post)

{
global $postID;
if(!count($postID))
{
$postID = array();
}
array_push($postID, $post['pid']);
}

function postwarnings_main(&$page)
{
global $db, $postID, $page;
if(count($postID))
{
$query = $db->query("SELECT A.`pid`, A.`tid`, A.`title`, B.`title` AS `title2`, A.`points` FROM `". TABLE_PREFIX ."warnings` AS A JOIN `". TABLE_PREFIX ."warningtypes` AS B WHERE A.`pid` IN (". implode(", ", $postID) .") AND A.`tid` = B.`tid`;");
while($row = $db->fetch_array($query))
{
if(!empty($row['title2']))
{
$reason = $row['title2'];
}
else
{
$reason = $row['title'];
}
$page = str_replace("<div class=\"post_body scaleimages\" id=\"pid_" . $row['pid']. "\">", "<div class=\"post_body scaleimages\" id=\"pid_" . $row['pid']. "\"><div class=\"post_warned\" style=\"border: 2px dotted red; background: #330000; font-weight: bold; color: red; padding: 2px;\"><br />* Autor postu otrzymał ostrzeżenie. Powód: " . $reason . " (+" . $row['points'] . " " .(($row['points'] == 1)?("punkt"):((($row['points'] % 10 > 1)&&($row['points'] % 10 < 5)&&!(($row['points'] % 100 >= 10)&&($row['points'] % 100 <= 21)))?("punkty"):("punktów"))) . ").<br /><br /></div><br />", $page);
}
}
}

Regards.

Sorry, translate.
Sorry, does anyone have any suggestions? I really care about.
1. Not a fan of doing it like this, why don't you just globalise the $pids in the postbit hook function and use that in a query? Then save the query results in a static variable and get the required info below. 1 hook, 1 query.
2. Then you can also use find_replace_templatesets() and move the code to a template instead of the long str_replace.
2. You should format your code in a better way, it's terribly hard to read. Tabbed indendation, interpolation instead of concantenation in long "" strings, etc.
Sorry I'm late, but I put it on second place.
So I applied in part to the advice @Destroy666, now displays information about warn, but there is one small problem:
Everywhere shows the same "warn reason" and the same number of points, you can advise something?
$query = $db->query("SELECT A.`uid`, A.`pid`, A.`tid`, A.`title`, B.`title` AS `title2`, B.`tid`, A.`points` FROM `". TABLE_PREFIX ."warnings` AS A JOIN `". TABLE_PREFIX ."warningtypes` AS B WHERE A.`pid` = '{$post['pid']}'  AND  A.`uid`='{$post['uid']}' ;"); 

		while($row = $db->fetch_array($query))
		{
			if(!empty($row['title2']))
			{
				$reason = $row['title2'];
			} 
			else
			{
				$reason = $row['title'];
			}
}
Now that ...
I noticed that in the query downloading only the post (WHERE A.pid = '{$post['pid']}') from the database.

This is corrected by changing to: WHERE A.pid IN (" . implode(", ", $pids) . ").
Only that still displays only one reason everywhere, as if the variable is assigned only to the last warn (?). I have a problem writing to each post that you warn a reason.


--- Sorry if this is something incomprehensible.

Any suggestions?
(2014-12-23, 10:37 PM)Snake_ Wrote: [ -> ]as if the variable is assigned only to the last warn (?)

Because that's the case. You assign every result to the single variable, so it gets overwritten in the while loop until the last result gets assigned to it.

You should assign the results to an array like this:
$reason[$row['pid']] = $row['title'];

Globalise $reason and then get the specific value in a postbit hook:
$post['something'] = isset($reason[$post['pid']]) ? $reason[$post['pid']] : 'brak';
and display $post['something'] in postbit template(s).
Okay. Now displays reason, but only where they typed. It remains only to warn reason of the warning system. When you choose from a list of warn reason, it does not display it at all. Thank you very much for your interest.
(2014-12-24, 12:32 AM)Snake_ Wrote: [ -> ]It remains only to warn reason of the warning system. When you choose from a list of warn reason, it does not display it at all.

https://github.com/mybb/mybb/issues/1660