473,854 Members | 1,851 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Building a "modular" PHP site

Hi everyone

Not really a specific PHP problem this, but...

I have been pondering over building a "modular" site which accepts
add-ons built by other people. I was wondering if anyone has any links
to any reading material on how you build this kind of facility into
your site?

Obviously I could take something like Mambo's source and try to fathom
out how their com_ type modules work, but I once looked at
Mambo/Joomla's source and the code was a lot to take in in one go.

Does anyone have any good short examples or links to articles that
explain how you make a site that accepts 'add-ons'/'modules', ie. a
quickly and easily extendable site?

Thanks

Tyno Gendo.
Apr 4 '07 #1
2 2609
Tyno Gendo wrote:
I have been pondering over building a "modular" site which accepts
add-ons built by other people. I was wondering if anyone has any links
to any reading material on how you build this kind of facility into
your site?
The basic technique is this:

1. Provide a plugin registration function, which we'll call, say,
"plugin_registe r". When a plugin is loaded, it will call your
plugin_register function and tell your site at least the following
information:

1. How to use the plugin -- i.e. provide a function name
or a class name that the site can use to access the
functionality of the plugin;

2. When to use the plugin -- this is normally done via
a named hook.

So a particular plugin might be defined like this:

<?php
function tobys_plugin ()
{
echo "<!-- Hello World -->\n";
}
plugin_register ('tobys_plugin' , 'onpagefinished ');
?>

Your plugin_register function would then add "tobys_plug in" to a list of
functions that need to be run when the page has finished outputting.

Then in the rest of your code, add you hooks. For example, at the end of
each page, you'd have:

<?php
run_plugins('on pagefinished');
?>

where run_plugins looks at the list of registered plugins and runs the ones
that have registered using that hook.

That's the simplified version. In real life, to allow the plugins to be
more useful, you'll often want to pass them particular parameters, such as
the current URL, the login name of the currently logged in user, etc. I'll
leave you to figure that out on your own.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!
Apr 4 '07 #2
Toby A Inkster wrote:
Tyno Gendo wrote:
>I have been pondering over building a "modular" site which accepts
add-ons built by other people. I was wondering if anyone has any links
to any reading material on how you build this kind of facility into
your site?

The basic technique is this:

1. Provide a plugin registration function, which we'll call, say,
"plugin_registe r". When a plugin is loaded, it will call your
plugin_register function and tell your site at least the following
information:

1. How to use the plugin -- i.e. provide a function name
or a class name that the site can use to access the
functionality of the plugin;

2. When to use the plugin -- this is normally done via
a named hook.

So a particular plugin might be defined like this:

<?php
function tobys_plugin ()
{
echo "<!-- Hello World -->\n";
}
plugin_register ('tobys_plugin' , 'onpagefinished ');
?>

Your plugin_register function would then add "tobys_plug in" to a list of
functions that need to be run when the page has finished outputting.

Then in the rest of your code, add you hooks. For example, at the end of
each page, you'd have:

<?php
run_plugins('on pagefinished');
?>

where run_plugins looks at the list of registered plugins and runs the ones
that have registered using that hook.

That's the simplified version. In real life, to allow the plugins to be
more useful, you'll often want to pass them particular parameters, such as
the current URL, the login name of the currently logged in user, etc. I'll
leave you to figure that out on your own.
Excellent, thanks for that reply. I will have a toy around with
something and of course follow up my post with an example when I get
around to it.
Apr 4 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
3789
by: Hayden Kirk | last post by:
Hey guys I am about to write some back end software for my business. I want a system that I can create invoices, clients etc... I can do this no problem. However I want to write it in modules so its extendable in the future. Like someone else can write a module for it and it can plug stright into my system. I can't figure out a good way to do this in php. I was thinking of hooks or something, but PHP does not support this.
2
1814
by: Ira Baxter | last post by:
My understanding is that Zend are the folks behind the one and only PHP implementation. Now that PHP5 is released, I'm quite interested in using it. However, the documentation avialable at PHP.NET suggests that it isn't by Zend. What reason is there to believe it is complete and accurate in any sense? (There's lot of user clarifications which show that it isn't complete). In particular, the section of PHP5 has parts that are...
6
2185
by: Rick | last post by:
Hello all. I have an index.php file that has a lot of functions that I wrote. Let's say for the sake of argument that there are 1000 functions of 100 lines each. The index.php file is invoked with a "state" a la "index.php?state=L1-2L3C4-47". Different functions are called according to what the state is, and then user actions can cause index.php to be invoked again with a different state. For instance, you can click an "erase this...
5
1739
by: Peter Clark | last post by:
Think of something like MyYahoo: a personalized portal with news aggregator, weather forecast, comics, etc. Now instead of visiting a web site, think of all of it being sent daily as an email. It does have a web interface, but mostly for selecting your content: this is my location for weather, these are the news feeds I'm interested in, these are the comics I like, save my preferences, and the server takes care of the rest. Does such a...
1
362
by: janek | last post by:
Reply to athresh: If your opinion is such that, see into Stroustrup's "The C++ Programming Language" (AT&T 1997) . There in Introduction is declared very similar "namespace" to mine. Janek
26
2536
by: Chris Potter | last post by:
Hello everyone. I am taking my first course in C and in one of my assignments i need to print out an array that could have anywhere from 0 to 100 positive integers in it (a negative integer is used to stop input), and i have to print 8 integers per line. The code that i have works, and does exactly that, but i feel a little uneasy because i am using two breaks. I would like to hear any comments about this approach, and what i might do to...
6
2957
by: Gary James | last post by:
This may not be a direct C# question, but since I'll be using using C# for development, I thought I'd pose the question here. I'll soon be involved in the design of a new software product that will employ a software "Plug-In" architecture. Taking the plug-in route will give us a design that can adapt to, as yet, undefined future requirements (within the scope of the plug-in interface spec of course). In the past I've done this with...
2
1804
by: Tyno Gendo | last post by:
I'm writing a test "modular site". So far I have created an App class, a Module Manager class and a couple of test modules. The Manager looks in a directory called 'modules' and then for every ..php file is try to create a class of type <filenameminus the .php, so eg. for testmodule.php it tries to create a class "testmodule" and puts it into an array within the module manager called $_modules Module Manager has a dispatch_message...
206
8426
by: WaterWalk | last post by:
I've just read an article "Building Robust System" by Gerald Jay Sussman. The article is here: http://swiss.csail.mit.edu/classes/symbolic/spring07/readings/robust-systems.pdf In it there is a footprint which says: "Indeed, one often hears arguments against building exibility into an engineered sys- tem. For example, in the philosophy of the computer language Python it is claimed: \There should be one|and preferably only one|obvious...
0
9750
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11024
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10744
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9510
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7077
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5738
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4550
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4150
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3182
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.