By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,979 Members | 960 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,979 IT Pros & Developers. It's quick & easy.

Porting a themes engine to OO

P: n/a
Hey again!

In my quest to make proper use of OO PHP I would like to ask for a
critique of the current method of doing themes in the Camera Life
(http://fdcl.sf.net) software and see if an OO approach is more
appropriate. This program consists of multiple PHP pages that include a
common.php file. My motivation is to make making themes easier, so we
can get more theme contributors!

Themes consist of image files, a css file and a PHP file that generates
HTML. An example is linked from here:
http://fdcl.sourceforge.net/index.php?content=themes In order to
"install a theme," you untar the package into your "themes" folder and
select the new theme from the administrative page.

* The common.php file gets the preference: $theme =
$preferences['theme']
* The page you are viewing (if it is interactive, and needs themes),
has: include("common.php");
include("themes/$theme/theme.php");
* The first line in HEAD of the page you are viewing is: <link
rel="stylesheet" href="themes/<?= $theme ?>/theme.css">
* The page you are viewing makes some HTML calls to the theme engine
(in the golbal namespace) like this: html_section('Photo Tasks and
Information');
* Any themed images on the page go like this: <img src="themes/<?=
$theme ?>/images/small-photo" ...>, images can be in any format,
because the software explicitly requires content negotiation :-)

I am wondering if I should update this to a OO approach, and if so,
how? My first guess would be to:

* Create themes/theme_base.php with a "theme" class and stubs for all
the html functions.
* All themes/*/theme.php will be classes that extend the "theme" class
* Change common.php to something like:
foreach(glob("themes/*/theme.php" as $themefile) {include $themefile};
* Add to common.php something like "$themeengine = new
$preferences['theme']". Here $preferences['theme'] is the name of a
type that will instantiate $themeengine.
* On each page the user sees, change to calls like:
$themeengine->html_section(...)

Please let me know if this is an abuse of the OO concept of PHP, or if
there are other considerations that I am overlooking. And thanks for
your quick and helpful responses to my last OO question.

Thank in advance,
FD

Jan 3 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.