php hook run functions - php

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.

Related

SuiteCRM Database Modified Externally

I'm new to SuiteCRM and I've seen many documentation links given for defining custom modules but none could not clarify my doubt.
I have a simple question: Can we modify the SuiteCRM's database externally from a different application (such as inserting records) and see the changes in the CRM?
There should be a way to do this. I have tried doing it but I get the error: "error retrieving this record: this record may be deleted or you do not have permissions to view it".
Can anyone provide a solution?
Yes. Changes made to the dB will be reflected in the app. It sounds like perhaps something wasn't quite right with the changes you made however.
One safer way would be to use the built in REST or SOAP APIs as this will ensure changes are made and also allows things like logic hooks to still be triggered.

Movabletype: Make the Recommended Contents function

I didn't have much experiences about the CMS (like wordpess, joomla or movabletype) so I don't know my task is possible or NOT.
My customer, they buy and use the CMS (MovableTypes) to make their website. So now they want me to find or write (Code) the new function for website. That function will be get and show the related blogs (entries) like for example:
"if you go to ebay and click to view a cellphone, the website will give you recommend cellphone which have same properties of the current."
In PHP, I can know how to do this, but in MovableTypes I don't know, have anyone had some experience about the MovableType.
They have documentation for extension development here:
https://movabletype.org/documentation/developer/
Whilst following their framework is usually sensible and worth taking the time to do, most CMSs will also usually allow you to find a place to just write in raw PHP via a very basic extension.
Just make sure you never edit core files.

PHP Plugin System: where to create plugin hooks in my 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.

tips on writing my first html embeddable widget?

I have been asked by a client to develop a javascript(mootools)/html/css/php based game as a widget which can be deployed anywhere.
I have not written a widget before, so would love to get some tips and experiences so that I know some of the pitfalls before i start!
Encapsulate your variables. Don't put anything in the global namespace, because you don't want to conflict with anything else operating there.
Ideally, let your widget write itself into the page; that reduces the number of separate things that have to be dropped into the page by the user, thus making it easier to install.
Make it clear what requirements your widget has - if it needs external libraries like MooTools to function, the person installing the widget will need to know that.
First of it depends of what you mean with anywhere? How much code are you allowed to publish to "anywhere".
Any how, the simplest way to publish anywhere is to just send "anywhere" a that implements the game. If you need different variables from each "anywhere" (for example for tracking) you can specify a .php file in the src attr that generates a javascript base on the parameters.
In the script you can use AJAX to talk to your sever and document.write to write at "anywhere" page.
One thing to keep in mind is that using a JS library could be hard since the "anywhere" page might no implement the specific JS library.
good related thread.. Widget -what to do and what not
thanks for answers so far - the more the better!

Is a custom module the best way to access an external API in Drupal?

I'm new to extending Drupal, though I've done similar kinds of things for other CMSes. Anyone care to share opinions on the best way to access an external API from within Drupal?
I need to show things like search results, listings, and listing summaries. In my reading up on Drupal, I think this implies I need to create both "nodes" and "blocks". Is this right? It wasn't clear to me from the module tutorial if this is possible from within the same module.
Thanks for any help / suggestions!
UPDATE: I found the Stock API module which does a simple case of what I'm trying to do. I'll model my module after that one.
Yes, they are all possible from within the same module; consult the various hook functions on how to declare nodes and blocks in a function.
There's also the PHP filter, which lets you embed pure PHP code on content pages, and doesn't require any module development, but for anything non-trivial I cannot recommend it.
Andrew - generally, you will want to put any kind of non-trivial code in an external module. With the exception of display code, which should be put into the template.php file associated with your theme.
If you care to describe your project in greater depth, I may be able to make more useful suggestions.

Categories