MyBB Community Forums

Full Version: Allowed memory Exhausted -View Single Post Plugin Question
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello all,

http://mods.mybb.com/view/view-single-post

Was one of the first plugins installed 2 years ago in my board. Worked good until it was deactivated for upgrading reasons. I have been trying to contact the author arash_j13 with no luck so far. So that´s why I´m starting this thread.

The thing is...when I click Activate, a blank page shows up with a message that I was used to see in Wordpress, being the first time that I see it on MyBB. So I got surprised.

The message:

Quote:Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 95789537 bytes) in /home1/XXXXXXX/public_html/bb/inc/adminfunctions_templates.php on line 56

Undecided

Here is the viewpost.php file plugin:

<?php
/*
	 view post  0.8.0
	
	by arash_j13
	
	E-mail : [email protected]
*/
$plugins->add_hook("postbit","viewpost_insert_url");
$plugins->add_hook("showthread_start","viewpost");

function viewpost_info()
{
	return array(
		'name'			=> 'viewe post',
		'description'	=> 'display post',
		'website'		=> 'mailto:[email protected]',
		'author'		=> 'Arash_j13',
		'authorsite'	=> 'mailto:[email protected]',
		'version'		=> '0.8.0',
	);
}

function viewpost_activate()
{
	 require '../inc/adminfunctions_templates.php';
	 find_replace_templatesets("postbit",'#'.preg_quote('{$post[\'posturl\']}').'#',
								'{$post[\'viewpost\']}{$post[\'posturl\']}');
	
	find_replace_templatesets("viewpost",'##','<html>
<head>
<title>{$title}</title>
{$headerinclude}
<script type="text/javascript">
		 var quickdelete_confirm = "{$lang->quickdelete_confirm}";
</script>
<script type="text/javascript" src="jscripts/thread.js?ver=120"></script>
</head>
<body>
{$header}
<table border="0" cellspacing="{\$theme[\'borderwidth\']}" cellpadding="{\$theme[\'tablespace\']}" class="tborder" style="clear: both;">
<tr>
<td class="tcat" width="15%"><span class="smalltext"><strong>{\$lang->author}</strong></span></td>
<td class="tcat" width="85%"><span class="smalltext"><strong>{\$lang->message}</strong></span></td>
</tr>
{\$viewpost}
</table>
<br />
{\$footer}
{\$viewpost_copy}
</body>
</html>',1); 	
}
  
function viewpost_deactivate()
{
	global $db;
	require '../inc/adminfunctions_templates.php';
	find_replace_templatesets("postbit",'#'.preg_quote('{$post[\'viewpost\']}').'#','',0);
	$db->delete_query(TABLE_PREFIX."templates","title='viewpost'");
}
  
function viewpost_insert_url($post)
{
	global $postcounter,$tid;
	$url="./showthread.php?action=viewpost&tid=$tid&pid={$post['pid']}";
	$post['viewpost']="<a href=\"$url\">#{$postcounter}</a>"	;
}

function viewpost()
{
	global $mybb,$db,$lang,$templates;
	if (isset($mybb->input['action']) && $mybb->input['action']=='viewpost')
	{
		$lang->load('viewpost');
		$pids="p.pid={$mybb->input['pid']}";
		$query = $db->query("
			SELECT u.*, u.username AS userusername, p.*, f.*, eu.username AS editusername
			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)
			WHERE $pids
			LIMIT 0,1
		");
		if($post = $db->fetch_array($query))
		{
			$viewpost=build_postbit($post);
		}
		else
		    error($lang->invalidpost);
			
		$title=$lang->vp_viewpost." : ".$post['subject'];
		$viewpost_copy='<div class="smalltext" align="center">
	View post Copyright &copy; <a href="mailto:arash_j13$yahoo.com"><strong>Arash_j13</strong></a></div>'; 
		global $headerinclude,$header,$footer;
		eval("\$view_post = \"".$templates->get("viewpost")."\";");
		output_page($view_post);
	}
}
?>

The plugin is obviously deactivated but I would like to know if it´s something wrong with it now that I´m running the latest MyBB version or, if it´s not a plugin problem then...is it that my memory size is not enough?....how to increase it?

Thanks.

PD: Apologies if this is in the wrong forum section.
How big are you forums?

		$query = $db->query("
			SELECT u.*, u.username AS userusername, p.*, f.*, eu.username AS editusername
			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)
			WHERE $pids
			LIMIT 0,1
		");

That's a big query the thread runs.

But just try to add manually the template and remove the code from activation.
Hi Labrocca,

To your question:

Database size = 29.45 MB
Memory Usage = 8 M
Cache size = 149 M
Max Upload / POST Size = 10M/10M
Post per day = 21.21

Not a big forum I think.

Relating on you advice I would like to add that at ACP/Templates/Ungroupped Templates

There si one called "View Post" and its content is a huge content.

<html>
<head>
<title>{$title}</title>
{$headerinclude}
<script type="text/javascript">
         var quickdelete_confirm = "{$lang->quickdelete_confirm}";
</script>
<script type="text/javascript" src="jscripts/thread.js?ver=120"></script>
</head>
<body>
{$header}
<table border="0" cellspacing="{\$theme[\'borderwidth\']}" cellpadding="{\$theme[\'tablespace\']}" class="tborder" style="clear: both;">
<tr>
<td class="tcat" width="15%"><span class="smalltext"><strong>{\$lang->author}</strong></span></td>
<td class="tcat" width="85%"><span class="smalltext"><strong>{\$lang->message}</strong></span></td>
</tr>
{\$viewpost}
</table>
<br />
{\$footer}
{\$viewpost_copy}
</body>
</html><<html>
<head>
<title>{$title}</title>
{$headerinclude}
<script type="text/javascript">
         var quickdelete_confirm = "{$lang->quickdelete_confirm}";
</script>
<script type="text/javascript" src="jscripts/thread.js?ver=120"></script>
</head>
<body>
{$header}
<table border="0" cellspacing="{\$theme[\'borderwidth\']}" cellpadding="{\$theme[\'tablespace\']}" class="tborder" style="clear: both;">
<tr>
<td class="tcat" width="15%"><span class="smalltext"><strong>{\$lang->author}</strong></span></td>
<td class="tcat" width="85%"><span class="smalltext"><strong>{\$lang->message}</strong></span></td>
</tr>
{\$viewpost}
</table>
<br />
{\$footer}
{\$viewpost_copy}
</body>
</html>m<html>
<head>
<title>{$title}</title>
{$headerinclude}
<script type="text/javascript">
         var quickdelete_confirm = "{$lang->quickdelete_confirm}";
</script>
<script type="text/javascript" src="jscripts/thread.js?ver=120"></script>
</head>
<body>
{$header}
<table border="0" cellspacing="{\$theme[\'borderwidth\']}" cellpadding="{\$theme[\'tablespace\']}" class="tborder" style="clear: both;">
<tr>
<td class="tcat" width="15%"><span class="smalltext"><strong>{\$lang->author}</strong></span></td>
<td class="tcat" width="85%"><span class="smalltext"><strong>{\$lang->message}</strong></span></td>
</tr>
{\$viewpost}
</table>
<br />
{\$footer}
{\$viewpost_copy}
</body>
</html>y<html>
<head>
<title>{$title}</title>
{$headerinclude}
<script type="text/javascript">
         var quickdelete_confirm = "{$lang->quickdelete_confirm}";
</script>
<script type="text/javascript" src="jscripts/thread.js?ver=120"></script>
</head>
<body>
{$header}
<table border="0" cellspacing="{\$theme[\'borderwidth\']}" cellpadding="{\$theme[\'tablespace\']}" class="tborder" style="clear: both;">
<tr>
<td class="tcat" width="15%"><span class="smalltext"><strong>{\$lang->author}</strong></span></td>
<td class="tcat" width="85%"><span class="smalltext"><strong>{\$lang->message}</strong></span></td>
</tr>
{\$viewpost}
</table>
<br />
{\$footer}
{\$viewpost_copy}
</body>
</html>s<html>
<head>
<title>{$title}</title>
{$headerinclude}
<script type="text/javascript">
         var quickdelete_confirm = "{$lang->quickdelete_confirm}";
</script>
<script type="text/javascript" src="jscripts/thread.js?ver=120"></script>
</head>
<body>
{$header}
<table border="0" cellspacing="{\$theme[\'borderwidth\']}" cellpadding="{\$theme[\'tablespace\']}" class="tborder" style="clear: both;">
<tr>
<td class="tcat" width="15%"><span class="smalltext"><strong>{\$lang->author}</strong></span></td>
<td class="tcat" width="85%"><span class="smalltext"><strong>{\$lang->message}</strong></span></td>
</tr>
{\$viewpost}
</table>
<br />
{\$footer}
{\$viewpost_copy}
</body>
</html>t<html>
<head>
<title>{$title}</title>
{$headerinclude}
<script type="text/javascript">
         var quickdelete_confirm = "{$lang->quickdelete_confirm}";
</script>
<script type="text/javascript" src="jscripts/thread.js?ver=120"></script>
</head>
<body>
{$header}
<table border="0" cellspacing="{\$theme[\'borderwidth\']}" cellpadding="{\$theme[\'tablespace\']}" class="tborder" style="clear: both;">
<tr>
<td class="tcat" width="15%"><span class="smalltext"><strong>{\$lang->author}</strong></span></td>
<td class="tcat" width="85%"><span class="smalltext"><strong>{\$lang->message}</strong></span></td>
</tr>
{\$viewpost}
</table>
<br />
{\$footer}
{\$viewpost_copy}
</body>
</html>g<html>
<head>
<title>{$title}</title>
{$headerinclude}
<script type="text/javascript">......

And goes on, and on and on

This file has at least 100 repetitions of the same thing. Now I´m even more confused Huh

(2010-09-17, 09:47 PM)labrocca Wrote: [ -> ]How big are you forums?

		$query = $db->query("
			SELECT u.*, u.username AS userusername, p.*, f.*, eu.username AS editusername
			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)
			WHERE $pids
			LIMIT 0,1
		");

That's a big query the thread runs.
[Image: jesus-facepalm-facepalm-jesus-epic-demot...1248715819]


But as you suspected, it's the viewpost template most likely. Delete all instances of it, and replace the following code
find_replace_templatesets("viewpost",'##','<html>
with
find_replace_templatesets("viewpost",'#^.*$#s','<html>

You may wish to check your postbit template too.
Hey Yumi,

After the edit the plugin was activated.

I went directly to ungrouped templates in order to check the viewpost template and I found this.

image below
[attachment=19922]

And when I try to edit the new "blank" template is shows up a MyBB message:

Quote:Please make sure you have all the input required to edit this template (tid and sid)

The template viewtopic just dissapeared.

On the other hand, I went to check on my postbit template and goes like this:

{$post['postdate']}, {$post['posttime']} <span id="edited_by_{$post['pid']}">{$post['editedmsg']}</span>
				</div>
				{$post['viewpost']}{$post['viewpost']}{$post['viewpost']}{$post['viewpost']}{$post['viewpost']}{$post['viewpost']}{$post['viewpost']}{$post['viewpost']}{$post['viewpost']}{$post['viewpost']}{$post['viewpost']}{$post['viewpost']}{$post['viewpost']}{$post['viewpost']}{$post['viewpost']}{$post['viewpost']}{$post['viewpost']}{$post['viewpost']}{$post['viewpost']}{$post['posturl']}
			</td>
19 times {$post['viewpost']} is repeating.

In the forum (thread page) every post has 19 times #number. And when I click in one of those...a blank page shows up.

Now I´m not sure if I´m gonna be able to deactivate it back LOL

Edited: I clicked "Deactivate" and a page shows up with this:

Quote:MyBB SQL Error

MyBB has experienced an internal SQL error and cannot continue.

SQL Error:
1146 - Table 'xxxxx_myBB2671.mybb_mybb_templates' doesn't exist
Query:
DELETE FROM mybb_mybb_templates WHERE title='viewpost'

....I need a beer.
(2010-09-17, 09:47 PM)labrocca Wrote: [ -> ]But just try to add manually the template and remove the code from activation.

After 4 beers I managed to deactivate this plugin with no error. Then activated again by trying your suggestion (manually template added and removing the code from the activate function).

All good except for new message I´m getting everytime I click on the view single post link.

Quote:Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in home1/XXXXXXX/public_html/bb/inc/plugins/viewpost.php(47)Sad)'d eval on line 13

After this, it´s deactivated and uninstalled. Hopefully someone is able to produce a better plugin because i´m done with this one.