MyBB Community Forums

Full Version: Where do I place eval statement
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
This is driving me nuts... Toungue

I created a template misc_code_expander

Contents:

<script type="text/javascript" src="templates/bbc_box/divexpand.js"></script>
<div align="left">
	<script type="text/javascript">
	var code_header = 'Code';
	var expand = 'Expand';
	var expand_more = 'Expand more';
	var contract = 'Contract';
	var select_all = 'Select all';
	codeDivStart()
	</script>

Eval Statement:

eval("\$code_expander = \"".$templates->get("misc_code_expander")."\";");

In class_parser.php I changed the code handler to:

return "</p>$code_expander<div class=\"code_body\"><div dir=\"ltr\"><code>".$code."</code></div></div>\n<p>\n";

The <div class="code_header" is handled by the javascript. Wink

This hook works fine everywhere I've tried it, besides where I want it to go. And that's to replace the <div class="header etc. in class_parser.php Sad

In what .php file do I place the eval string, and where to place it would be a great help. As I'm burned out trying to find it. Toungue
Put it right above the return "</p>$code_expander" line in class_parser.php.

You may need to put "global $templates;" above the eval line too.
Thanks for the prompt reply Chris,

You make it sound so easy.. Wink

Tomorrow would be a good time to finish it.

I'll PM you a link for a preview of what I'm trying to achieve. Smile

I think it will be a nice addition to MyBB.. Toungue
Hi,

Can you attach the copy of class_parser.php so I can see where you went wrong with the code replacement?
This was the only change Chris,

		$code = str_replace('&amp;', '&', $code);
		$code = preg_replace('#\$([0-9])#', '\\\$\\1', $code);
		$code = str_replace('\\', '\', $code);
		$code = str_replace("\t", '&nbsp;&nbsp;&nbsp;&nbsp;', $code);
		$code = str_replace("  ", '&nbsp;&nbsp;', $code);
		return "</p>(\"$code_expander\");<div class=\"code_body\"><div dir=\"ltr\"><code>".$code."</code></div></div>\n<p>\n";

The added brackets and quotes you've seen were just an attempt at guessing on how the variables are actually parsed in that section of MyBB. And I left them there while I looked for an answer. I knew they didn't work, but it did give me an indication of being in the right place.

I also did add the eval statement in class_parser.php, (and used only the clean var $code_expander in the above string - - No brackets, backslashes or quotes etc), but not at the location you recommended.

After your recommendations, I'll add one thing at a time to see what solves the problem.

Tomorrow... Toungue

PS: There is also possibly a better way to add the request to the string in class_parser.php, but it would take a re-write of some of the code.

I'll do a deal with you:

It will no doubt work with your recommendations - - I'll set the path for the javascript to the default MyBB .js path, get the whole thing working... You clean it up and add it as an integral part and a feature of MyBB.
Just upload your class parser and I'll do it for ya. It's only take me 2 secs
Tikitiki Wrote:Just upload your class parser and I'll do it for ya. It's only take me 2 secs

Do you have the time to get involved with it, if you want to ??

Learning all of the other aspects of the code is taking some time for me, and I'd like to move it on. If I can get it to parse that $var at the code header, I should be able to work out the quote and php headers too.

Chris's suggestion doesn't quite work, but it's also difficult for him to see the whole picture too. Wink

I'll send you the .php file of where I'm at..

In the meantime, there's a pm for you with the link.. (at the top of the thread) this is what it's supposed to do.

Wink
I merely would add 2 lines of code that would make it work. Can't you just upload the class_parser.php file?
I sent it zipped.

I suppose it would have been better to post it here, then anyone who wants to try something similar; will have half the answers. Smile
return "</p>(\"$code_expander\");<div class=\"code_body\"><div dir=\"ltr\"><code>".$code."</code></div></div>\n<p>\n";

Should have been:
global $templates;
eval("\$code_expander = \"".$templates->get("misc_code_expander")."\";");
return "</p>$code_expander<div class=\"code_body\"><div dir=\"ltr\"><code>".$code."</code></div></div>\n<p>\n";
Pages: 1 2