I'm working on a custom CMS for my own use and was thinking about implementing a plugin system so I could extend the code a little easier. I'm having trouble conceptualizing the architecture and layout though.
I know I could go through a few open source programs that implement similar features but this is really just academic at this point so I really don't want to spend too much time digging through foreign code.
Does anyone have any good ideas of how to proceed? If someone could outline how some of the more popular programs do it that'd be perfect.
Define the functionality you want the plugins to plug into (ie, what will they do and over what)
Define a class hierarchy on which plugins fit, like, all article mangling plugins should inherit from ArticleMangler
Define a physical location for plugins, like /plugins
Import all plugins present in the location
Use either Decorator or Observer patterns to inject the plugin's behavior or to notify the plugins of events occurence. Strategy might be applicable in some cases as well.
PHP makes this fairly easy at a potential cost of making a mess if you're not careful. I like the Observer method where plugins register themselves to a plugin manager which notify them of what happened and wait for their action to happen.
If you don't trust plugins then you'd have to put add controls over which events you are going to allow any plugin to register for.
Related
I have recently look into observable pattern and I understand how things work and the concept. I also played with it in my application but I want to find out how to use it when you want to make a plugin in a php application, because that was my main purpose.
I haven't found any decent example until now. I want to understand the concept of making plugin with observable and also a good and easy example would be nice.
By making a plugin I mean to have a standard application and want to do some particular stuff for every client, because not all the clients ask the same things I can't give them all the same application, so the ideas so to make a standard application and configure it for every client and I understand that something like that is called to make a plugin and It can be done with observer.
Observer/Observable pattern would be a good fit if you want to implement some kind of custom triggers/actions based on user or application/service actions.
For example, an identity/authentication service might implement a pluggable architecture using some kind of observer to let third-party plug-ins do something when some user authenticates, or some user is registered...
Also it should work in the UI, because you might be able to show a menu or add some visual component based on user interaction.
If you want to make a very free plugin based application, you might want to do a slightly different version of this.
Implement a centralized event control.
Each Plugin (serving as your controllers) registers there to be notified for certain events.
Now if you want to access some functionality, just dispatch a specific event through that central event control. You no longer need to know what plugin will respond to your event, you only need to know the interface of said event and the form of response you will get.
Now multiple plugins can register on a event, overriding or extending the results of other plugins. Or just allow completely new events.
This application structure takes a bit of patience to properly create all needed classes, but the end product is extremely decoupled -> flexible. Think of it as a form of MVC where the controller(s) dont need to know each other, they just know where to ask in a very generic form.
(I heard Zend2 tries a similar approach?)
I am developing modules in socialengine4. Now I need to change the core functionality of the application. I need to make some changes in user signup process by adding some core features like proving auto complete fields.
I know this is a core feature of User module of SocialEngine. But This is not a good practice because any update of socialengine will override my changes.
I have searched the solution but couldn't be able to find any thing. I know if you want to change any thing in core modules of magento, it directs us specific way to do that. Similarly I want to know the process, how can I change in socialengine?
Regards
It depends on what you want to change on SocialEngine core.
To change the signup process (for example add a new step), you have to add a new row in this table engine4_user_signup and implement your new step.
If you just want to add some actions after a user signup successfully, you can add a Hook in your custom module.
To implement a hook in Socialengine, following these steps:
Define hook in manifest file, will be something like below
'hooks' => array(
array(
'event' => 'onUserCreateAfter',
'resource' => 'YourPluginName_Plugin_Signup',
),
),
In the plugin class YourPluginName_Plugin_Signup, add this method onUserCreateAfter
public function onUserCreateAfter($payload)
{
$user = $payload->getPayload();
//Do whatever you want
}
Hope this can help you.
I'm not the slightest bit familiar with Social Engine, but seeing that it offers plugins:
http://www.socialengine.com/customize/se4/plugins
… I feel rather safe to suggest that there's some kind of API that allows you to hook into, and probably override, whatever core functionality you're not entirely happy with.
If it's anything like Symfony, Drupal or WordPress, there more often than not is some kind of event, hook, action, filter, whatever, at a key step in the process. It should allow you to catch whatever core has come up with to that point, trash it, and entirely override and "redo" it. The key here is to have a thorough understanding of the APIs involved — no amount of asking SO questions will spare you from reading the docs.
What occasionally happens, that being said, is that the only plausible candidate event is uncooperative, in the sense that it comes too late and only allows you to "add" something extra to what has been done already. In this case, you can take the higher ground and fight back by finding an earlier event. Start an output buffer on it, and trash this buffer in the uncooperative event. Now, you redo things as the way you want them, without losing your changes during upgrades.
Note that doing the latter is not risk-free, though. If anything, it adds a huge burden on you: if core changes anything in this area that you've redone from the ground up, you need to make sure that your overriding it doesn't break when you upgrade the application.
I want to add a plugin system to my PHP application.
I'd like to create a hook system where my plugins register themselves to these hooks. So for so good. The problem is knowing from start what kind of hooks to create.
Are there any guidelines on how to do this? Should I have a hook for every point in the app where I might want to update data? Hooks for outputing data?
Would I need to have a hook for something like "before_script_ends", "before_avatar_output"?
This seems pretty opinion based...
I'd start with requirements of what your developers are asking for in this plugin system. Try just kicking it off thinking about minimum viable product. What things would be most beneficial. I'd vote with routing type features so probably create hooks for that. That may actually be all you need.
Also decide if a plugin system is what you want. You might prefer more separated apps. In which case a rest based/oauth like approach might be more appropriate.
It is hard to say with out some specific use case.
I'm taking on a relatively small freelance project and my client would like to update several portions of their site; photo gallery, calendar list, about page, and some event links.
My gut tells me to use something like WordPress and use "Pages" for these sections, but I'm worried about my client maintaining the formatting. Especially something like calendar dates and links.
They won't be doing any blogging - this is just so they can update those sections when needed (obviously).
But then I thought, what if I just roll my own CRUD for these portions, but I'm not sure if that would be necessary for a project like this.
So what would people out there use in a situation like this? How much control does one have over the formatting of content in WordPress? I'd like not to have to teach my client on when to call certain CSS classes.
Any help is more than appreciated.
EDIT:
Any idea how the top carousel of BungoBox was made in WordPress? Or don't you think it's possible and that is done manually?
I would stick to wordpress or similar CMS system. It will be a pain-in-the-arse, to take care of formatting (WYSIWYG for client), take care of security, make the administation pages nice and functional, and so on.
You will find a LOT of information on wordpress as a cms on the web, for example see here
Have you considered any other cms system?
From the description this is a site that would consist of just a few pages that the client would want to update? if so, I'd stick with wordpress myself. There's a ton of pre-written modules and themes already out there, and there's no sense "re-inventing the wheel". Also I've found in my travels that Wordpress leads the pack in being able to manipulate content to your will of all the CMS's and the available WYSIWIG plugins they have. Remember, if they cant' get their document to look just right, guess whose getting the call, and who will be expected to fix it on your dime if you didn't specify that in your contract (you are offering maintenance as an additional feature right?)
Now if the client is looking for a more robust system, a larger site then I interpreted in your writeup, then I'd look into more of a CMS system such as Drupal or Joomla. Avoid the trap that seems to nail PHP coders that it'd be faster to do it yourself; it'd have to be a lot of custom functioanlity to start looking at building it yourself from the ground up (and even then, there's enough frameworks to help)
What about something like Drupal? Never used it personally, but I think it's built for this sort of thing, whereas WordPress is kind of tailored towards blogs.
Definatly go with wordpress, drupal is just too heavy for the job and will take you much longer to configure.
If you are worried about your client ruining design with a WYSIWYG editor, just don't give them access.. keep them on a need to know basis for their own good.
Working with wordpress will free you from maintaining security issues and many other unpredictable-at-this-point cases of reinventing the wheel.
This can probably apply to other extensible content management systems, but I've been working with Drupal. Specifically I created an image sharing web application whose functionality relied on more original code than Drupal core code. I used the WebForm module and point its forms at Custom Pages with hard coded php to have nodes created programmatically and other strange voodoo.
Just before I was done I realized I perhaps should have just made my own module, or should I have?
Even in retrospect it's difficult to tell.
What do you use to decide when a new module needs to be written and when the functionality you're seeking can just be kludged together from what's available?
I have a strong opinion on this, which is that all custom coding should be done within custom modules, with only one possible exception (see below):
I discern three cases:
Completely new functionality - this obviously calls for a custom module that encapsulates the new functionality. It makes it reusable and can even turn into an 'official' contributed Drupal module, if the functionality meets popular demand.
Tweaking existing functionality - for every site, I immediately setup a blank, custom module (named after the site). All custom code used for tweaking existing functionality (be it from core or contributed modules) happens within this module. That way, all my customizations are cleanly separated, which makes it much easier to update the core or other modules without constantly having to reapply my customizations to the updated code (of course one has to check if the customizations still work after the update and adjust or remove them as needed).
Fixing bugs/adding missing features - this is the possible exception mentioned above. If my changes are just a bug fix or an addition of an obvious, but missing feature, I might just do that within the original code, submitting my changes as a patch to the original module, hoping that they will get incorporated in a future release, thus making my changes obsolete.
In my experience, the 'overhead' of separating the customizations from the original code isn't really an 'overhead', as the 'one-off' tweaks & fixes usually stick around much longer than anticipated, and have a tendency to grow over the lifetime of a site. Having them separated from the start saves a lot off troubles down the road in maintenance, as applying updates & security fixes, as well as extending the tweaks will be much easier.
Make a new module when you want to share or reuse the functionality easily. There is overhead in doing so, so if it's a one-off it's not worth it.
What i prefer doing is a full-on search on drupal.org for any/all modules that have the functionality that I require. I search drupal.org & groups.drupal.org (& maybe even the forums) with that module(s) name to see what other folks are saying about it. Lastly, I always check drupalmodules.com to see what others in the community are saying about it.
If I can't find exactly what I need, I roll out my own module. Plynx is right also, if you plan to reuse the functionality, create a new module IF it's unique enough to not exist yet.