473,796 Members | 2,505 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 2606
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
3778
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
1812
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
2179
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
1738
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
2529
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
2954
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
1798
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
8377
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
9680
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10456
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...
0
10230
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10174
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
10012
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7548
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5442
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
4118
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
3731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.