PHP Plugin System: where to create plugin hooks in my application? - php

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.

Related

How to change core module files in socialengine4

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.

Which CMS for having a mixture of CMS-enabled pages and my PHP programs?

I'm creating a website which has a public-facing side, which I want selected users to be able to edit like in a CMS, but I also want to create a private intranet side which is made up of pages written in PHP by me to perform certain functions, but are not part of the CMS as such.
So basically I want:
- Some CMS-ified pages which are user-editable
- Some custom pages which use the CMS templating engine, authentication etc..
Which would be the best CMS for this?
Drupal is really good when you need this kind of flexibility. You can easily configure it to link to other pages via the menu system and TBH, it's so flexible, you'll find that anything you would want to hand code for the intranet can be done by installing and configuring existing third party modules, with the option of writing a custom module if you really have to.
We do developments like this and bring all of the intranet stuff into Drupal by putting code into a custom module and having the functions called by simple forms made in Drupal. To see data from internal DBs, tell Drupal the DB details in the config, then use the views module to make lists etc.
Not sure if it's the best, but Drupal is a very good candidate based on your description.
Your custom pages can be implemented in a module (PHP code). Specific URLs can be declared as being handled by your module and the rest of the CMS will not get in the way if you don't want to. From the point of view of your code, Drupal can be seen as a kind of framework.
I might use drupal. From what I've done with it, it seems very customizable. It's more flexible and seems more clean and secure than something like joomla. There are plenty of addon's. I haven't done enough with it to get to the point where I was interfacing my own PHP pages with it, but if I had to try anyone that's what I would go with.
I, however, personally just make my own CMS. It might be more work, but then everything is the way that I want it to be. It depends on how much you want them to be able to edit. For example, I was making a website for a shop, and so I created a place where they could add and remove items, which wasn't that difficult, especially since it was database based. To be able to do things like change menus and appearance and such might be harder...probably look towards something like a CMS.

php hook run functions

I am thinking of building some kind of "hook" function system. Basically a couple of functions that is run before the whole application start doing what it is suppose to do. I guess some kind of authentication would be proper to have as a hook. Check if the user is still logged in etc. There should also be some kind of priority order.
But how do I structure this kind of hook system? How do I initialize it?
I guess I would need some class to handle this for me. An add_hook and run_hooks method or something.
phpBB, the open source bulletin board software, has a hook system you might benefit from looking into. Of course much of the code will be specific to phpBB's framework, but the basic idea would be the same, I think.
I achieve this by using the auto_prepend_file directive of the php.ini file. In my case, it's functions/init.php, which does such things as connect to the database, get user data from SESSION, authenticate, update user's info if needed, etc. etc.. Sounds like just what you need.

Cms to plugin to a multiple controller php site

I have a php site setup with multiple controllers for the different sections of the site.
e.g index.php, gallery.php, faq.php etc.
Currently I have a base template which I call from each controller, which in turn includes the relevant content for the page. I also use tinymce to edit this content file.
So it's really a very simple cms.
Edit: To clarify, I have several new features I would like for my cms. e.g Specific section editing, menu editing and a few others.
But I thought instead of continuing development on this and reinventing the wheel, I'd try to find a cms which can plug in to my multi-controller system, instead of forcing me to develop my app in it's framework. I guess I want it to manage just the content, not any other backend stuff of my site.
Hope this is understandable.
I'm not sure if I'm understanding your question correctly. You have a site with a basic CMS using a template system and multiple controllers. You don't want a framework to port your site to, but you instead want a CMS that will "plug in" to your current site? What exactly do you want plugged in to your site? (i.e. What features/functionality are you looking for?)
Edit:
I still think you should consider an MVC framework like CakePHP if your goal is to build a more robust CMS without re-inventing the wheel. Building on a well-designed framework would also make extending your site's functionality in the future much easier (as well as make it easier to maintain a complex web application).
The only other option I can think of is to simply replace your existing CMS with a more robust one, like Drupal/Joomla/Wordpress, which you could then extend with modules. But that would probably give you less flexibility, not more.
Le me see if I have this right. You want a CMS. But it has to be one that will conform to your arbitrary way of doing things that you can drop in and have work. You want a CMS that isn't frameworkish at all. A CMS that will only do the frontend, and not the backend.
You don't want a CMS at all. A CMS, by its very nature, does backend work. That's the point of a CMS. What you want is Dreamweaver-esque magic template handling.
Or maybe you should adopt a real CMS or framework, and work from there. It's not really reasonable to expect this sort of magic psychic power from a CMS.
i also recommend Drupal. its very well organized and is easily adjusted to almost any style of website. you can use it as a pure cms or add plugins w additional features as needed .. the core package is fairly small, very easy to set up and play with, and very well supported .. worth looking at
If you wrote a very basic CMS for your own use it seems to me that you should have no problem adopting an existing out of the box solution like Drupal, Joomla, etc. These are full featured CMSs that are ready to go and with some graphics work and a little hacking on your end can look like anything you want.
Your other option is using an existing framework like others have suggested such as CakePHP, CodeIgniter, etc. These are all frameworks which basically give you all the tools you need in order to build a more robust custom CMS than what you have now.
It seems to me that you know at least a little bit about what you're doing. I would suggest you check out the different frameworks that are available and run with that.
CodeIgniter
CakePHP

build a plugin system with php

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.

Categories