MyBB Community Forums

Full Version: Avoid Template Edits With Plugin?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello...

I was hoping someone could help me with a plugin I'm working on. Basically the only part that I'm having problems with now is where I want to do a str_replace on some code in the the newreply template so that I can add code to the template without doing any template edits.

Now the problem is, I'm not sure how I should do this one... Because the newreply_start hook has no parameter that I can use. Heck I dont even know if I'm looking at this from the right angle....

<?php
/* ... */
$plugins->add_hook("newreply_start", "spellCheck");
/* ... */
function spellCheck($page)
{
	$page = str_replace('<div style="text-align:center">', '<div style="text-align:center">I want to put some code here...', $page);
	return $page;
}
/* ... */
?>

Anyway, I did a search and I couldn't really find anything that was helpful so i decided to make a post.
What exactly do you want to do? Just add something to a template not find/replace?
(2010-01-01, 06:25 AM)Jammerx2 Wrote: [ -> ]What exactly do you want to do? Just add something to a template not find/replace?
I just want to add something to the template using str_replace (or similar function)... I really dont want to do a find/replace inside the template.
What's wrong with the find replace function?
$plugins->add_hook('newreply_end','happy_new_year_to_you');
function happy_new_year_to_you() {
 global $templates;
 if(!$templates->cache['newreply']) $templates->cache('newreply');
 $templates->cache['newreply'] = str_replace('2009', '2010', $templates->cache['newreply']);
}
Oh, I didn't understand what you wanted, if what Yumi posted is what you wanted.
(2010-01-01, 07:05 AM)Jammerx2 Wrote: [ -> ]What's wrong with the find replace function?
The find-replace function is good for anything you don't plan to change often. Where as, if you were to use the str_replace function you can have extremely advanced code generated on the fly and inserted into anywhere you want without having to do a find-replace every time.


(2010-01-01, 07:40 AM)Yumi Wrote: [ -> ]
$plugins->add_hook('newreply_end','happy_new_year_to_you');
function happy_new_year_to_you() {
 global $templates;
 if(!$templates->cache['newreply']) $templates->cache('newreply');
 $templates->cache['newreply'] = str_replace('2009', '2010', $templates->cache['newreply']);
}
Thats exactly what i was looking for! Thanks Smile