thewag Posted January 28, 2007 Report Share Posted January 28, 2007 I've been toying with the idea of making TNG "Plugin" friendly...without changing any TNG files. The idea is built around around the ob_* functions in PHP and Regular Expression. Placing a ob_start in the header.php file and a ob_end_flush at the end which calls a callback. Inside the callback, through RE we search out, say for example, the getperson pages. Then for ever getperson link, we call something like a plugin_person_link(personID, tree, name) to which various mods can then use the information (wiki comes to mind). Something similar could be done for locations.So....question would be to all the MOD writers, would this be of any use? All of this could be placed in something like the customconfig.php or the like.Questions, comments, suggestions...Ben Quote Link to comment Share on other sites More sharing options...
Rush Posted January 28, 2007 Report Share Posted January 28, 2007 Interesting...Just a couple thoughts on this (and none of them might be well founded )1. Conflicting mods:If two different mods were trying regex the same part of the original code to meet the mod requirements.Is there a good way to 'control' this?2. Changes to original code:If the original code for a file is changed or removed due to a regular TNG upgrade, this could create a debugging nightmare for someone working on the mod.I'm not sure if they are valid concerns, but just somethings that came to mind.Rush Quote Link to comment Share on other sites More sharing options...
Gnome Posted January 28, 2007 Report Share Posted January 28, 2007 From a user pespective, making TNG "Plug in" friendly would be very usefull, currenly upgrading takes a fair while with lots of time spend compairng files. The same applies to the templates. My PHP coding is not upto helping with the development but I could assist with testing.Regards Gnome Quote Link to comment Share on other sites More sharing options...
thewag Posted January 28, 2007 Author Report Share Posted January 28, 2007 Hey Rush:1. Conflicting mods:If two different mods were trying regex the same part of the original code to meet the mod requirements.Is there a good way to 'control' this?Ok, I wasn't clear. =) Mod'ers would place a call to their script (either through function or include...thinking about this one)...in either the individual function or place function. Something like:function plugin_person_link(personID, tree, name) { create_some_wiki_page($name); create_some_other_thing($personID); include("some_really_cool_something.php");}Then the person's name could now be followed by:Someone Wiki_link other_thing something_really_coolClear as mud? 2. Changes to original code:If the original code for a file is changed or removed due to a regular TNG upgrade, this could create a debugging nightmare for someone working on the mod.This is why I'd only have the code placed in header, footer, and customconfig. These files are not changed by upgrades.I don't think this could be adapted to all the mods...but I think several would benefit from it.Ben Quote Link to comment Share on other sites More sharing options...
thewag Posted February 5, 2007 Author Report Share Posted February 5, 2007 Ok, this is what I've got so far. I'm using a modified script from my pmWiki site. I'll leave that off for now.1st - In header.php (yes, has to be php) add:<?phpglobal $text;ob_start("callback");?> 2nd - In footer.php add: <?phpglobal $text;ob_end_flush();?> 3rd - In customconfig.php add: <?phprequire_once("mod_pmWiki.php"); //THIS WOULD BE THE MOD FUNCTIONS. BELOW I USE create_wiki_linkfunction person_link($personID, $treeID, $name) { $text = create_wiki_link("person", $name, 0 ); return $text;}function header_link($name) { $text = create_wiki_link("person", $name, 0 ); return $text;}function full_page($buffer) { return $buffer;}function location_link($place) { $text = create_wiki_link("place", $place, 0); return $text;}function callback($buffer) { //DO NOT EDIT THIS FUNCTION!!!! $buffer = preg_replace( "/<span class='header'>(.*)<sup>/ie", "'<span class=\'header\'>$1 '.header_link('\\1').'</a><sup>'", $buffer); $buffer = preg_replace( "/<a href=\"(.?[^javascript]*?)getperson\.php\?personID=(.*)(&|&)tree=(.*?)\">([A-Za-z\s0-9\.]*?)<\/a>/ie", "'<a href=\"'.stripslashes('\\1').'getperson.php?personID='.stripslashes('\\2').'&tree='.stripslashes('\\3').'\">'.stripslashes('\\5').'</a>'.person_link(stripslashes('\\2'),stripslashes('\\4'),stripslashes('\\5'))", $buffer); $buffer = preg_replace( "/<a href=\"(.*?)placesearch\.php\?(.*?)psearch=(.*?)\"(.*?)<\/a>/ie", "'<a href=\"'.stripslashes('\\1').'placesearch.php?'.stripslashes('\\2').'psearch='.stripslashes('\\3').'\"'.stripslashes('\\4').'</a> '.location_link(urldecode('\\3'))", $buffer); $buffer = full_page($buffer); return $buffer;} //your custom PHP code goes here.?>Anyone have comments? Its working on my test site. I'll hopefully attach my "mod_pmWiki.php" also and the graphics I use...Happy coding.Benwiki_tng.zipmod_pmWiki.php Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.