MyBB Community Forums
How to change value of $ratingvotesav in showthread ? - Printable Version

+- MyBB Community Forums (https://community.mybb.com)
+-- Forum: Extensions (https://community.mybb.com/forum-201.html)
+--- Forum: Plugins (https://community.mybb.com/forum-73.html)
+---- Forum: Plugin Development (https://community.mybb.com/forum-68.html)
+---- Thread: How to change value of $ratingvotesav in showthread ? (/thread-171560.html)



How to change value of $ratingvotesav in showthread ? - Goose - 2015-06-06

Hello,

I'm coding my own plugin.

I want to create a rating rich snippet in specific post/forum.

Here is the code of my plugin:

	function rating_snippet(&$thread)
{
	if($thread['numratings'] > 0)
	{
		$offer_name = $thread['subject'];
		$offer_rating = $thread['averagerating'];
		$offer_count = $thread['numratings'];
		$ratingvotesav = "<div itemprop=\"aggregateRating\" itemscope itemtype=\"http://schema.org/AggregateRating\">
			<div>Rating : 
			  <span itemprop=\"ratingValue\">" . $offer_rating . "</span>/
			  <span itemprop=\"bestRating\">5</span>
			  (<span itemprop=\"ratingCount\">" . $offer_count . "</span> vote(s))
			</div>
		  </div>";
	}
}

Since it's currently local, of course value $ratingvotesav is not update in showthread.

I tried to put $ratingvotesav in method call (function rating_snippet(&$thread, &$ratingvotesav) ) but it's not working.

Any idea ?

Another solution to my problem could be to dynamically change template from "showthread_ratethread" to "showthread_ratethread_with_snippet" in my plugin, but I don't know if it is possible, and how to do this...


RE: How to change value of $ratingvotesav in showthread ? - dragonexpert - 2015-06-06

You need to globalize the variable $ratingvotesave.


RE: How to change value of $ratingvotesav in showthread ? - Goose - 2015-06-06

Thank

How can I do this ?

function rating_snippet(&$thread)
{
	global $ratingvotesav;
	
	$ratingvotesav .= "test"; 
...

change nothing...


RE: How to change value of $ratingvotesav in showthread ? - Destroy666 - 2015-06-07

Because your code is just wrong - you mentioned in the 1st post that you want to change something in showthread, yet none of the showthread hooks accepts/expects a parameter.. http://docs.mybb.com/1.8/development/plugins/hooks/ So $thread including $thread['numratings'] is always empty and the conditional fails with a PHP notice. This means you need to globalize $thread too and remove it from the parameter.

Also, not sure what you want to achieve, but editing a global variable to add HTML is never the best solution. You should rather edit the template with the find_replace_templatesets() function (+ possibly create a new template for the added HTML, eval() it into a variable and add that variable to the core template).

But from the looks of code from the 1st post, you don't even need a plugin and you can paste that HTML directly to the template, using the core variable which you're duplicating for some reason ($thread['averagerating'] and $thread['numratings'])..


RE: How to change value of $ratingvotesav in showthread ? - Goose - 2015-06-07

Thank, I succeed coding my plugin with your help.