pcman Posted July 30, 2011 Share Posted July 30, 2011 i want to build to my app plugin system (like what you have in wordpress) how can i do it?(concept level) i will be happy for articles thanks Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted July 30, 2011 Share Posted July 30, 2011 http://codex.wordpress.org/Writing_a_Plugin Quote Link to comment Share on other sites More sharing options...
trq Posted July 31, 2011 Share Posted July 31, 2011 I don't believe the question was 'How do I write a wordpress plugin?' But 'how do I write a plugin system?' Unfortunately there is no simple answer to this question as it really depends on your overall applications design. Some applications (such as wordpress) have hooks that are executed at during certain phases of the applications executing. You can then use these hooks to inject third party code. Others use the filter chain pattern to allow injection into specific locations within the execution process. Others might use an observer pattern and broadcast events during execution. There are lot's of ways of doing it. All of which are likely to depend entirely on how your application is designed int he first place. If your application is simply spaghetti code that is tightly coupled and not really using any clearly defined patterns then a plugin system will be quite difficult to implement. Can you describe your architecture? Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted July 31, 2011 Share Posted July 31, 2011 Misunderstood. However a 2 sentence vague question = me posting a link Quote Link to comment Share on other sites More sharing options...
Elven6 Posted August 14, 2011 Share Posted August 14, 2011 One method that I'm looking into is simply having a system that adds/replaces code on plugin install similar to how SMF, phpBB, etc do it (almost done, just need to get a code find/replace system setup). I don't know if this is the best method but I don't really know of any alternatives of this level. I think the benefit with this system would be you can create plugins that radically alter/add functionality. Another method I looked into was having a plugin activate via a database entry and then have a file with code for that plugin load using a function. This system in theory should work great if you wanted to add modules and such to your site/CMS but if you wanted more advanced functionality, like for example a CAPTCHA system, I don't think it would be very capable. These are pretty simple methods that I've played around with but I don't know how well they would reflect in the community. Quote Link to comment Share on other sites More sharing options...
trq Posted August 14, 2011 Share Posted August 14, 2011 This kind of system is very easy to implement using simple patches, which is IMO what SMF should be using instead of there custom search and replace framework. The only real problem with this method is that once you have installed a plugin that replaces existing code, another plugin that looks for that code won't be able to find it. Quote Link to comment Share on other sites More sharing options...
Elven6 Posted August 14, 2011 Share Posted August 14, 2011 This kind of system is very easy to implement using simple patches, which is IMO what SMF should be using instead of there custom search and replace framework. The only real problem with this method is that once you have installed a plugin that replaces existing code, another plugin that looks for that code won't be able to find it. Patches? Sorry, can you give an example of what you mean. Valid point regarding that type of a system though. Quote Link to comment Share on other sites More sharing options...
trq Posted August 15, 2011 Share Posted August 15, 2011 There is a program called diff that can display the difference between two files or directories or even an entire directory structure. You can use the output of this diff program to create patch files. You can then use a patch file to apply these changes to code. Example. old/foo.php <?php echo "hello world"; new/foo.php <?php echo "Hello World"; Creating a patch: diff -rupN old/ new/ > foo.patch foo.patch diff -rupN old/foo.php new/foo.php --- old/foo.php 2011-08-15 11:10:14.000000000 +1000 +++ new/foo.php 2011-08-15 11:10:43.000000000 +1000 @@ -1,3 +1,3 @@ <?php -echo "hello world"; +echo "Hello World"; The - at the start of aline indicates that that line has been removed, while the + indicates that that line has been added. To apply a patch you use the patch command: cd old/; patch -p1 < ../foo.patch Now, if you look at old/foo.php <?php echo "Hello World"; Patching can be even easier these days of your project uses Git for version control. Git has it's own mechanism for creating and applying patches. Quote Link to comment Share on other sites More sharing options...
Elven6 Posted August 15, 2011 Share Posted August 15, 2011 Thanks for the example, I hadn't heard of it before but it seems worthwhile. I'll definitely have to look into it for my plugin system. Quote Link to comment Share on other sites More sharing options...
trq Posted August 15, 2011 Share Posted August 15, 2011 This is the system that has been used for many many years to patch software. 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.