Hey everyone,

I'm currently working on a redesign of a project I am planning to get at least mostly finished (I'm not making anything super-ambitious, don't worry) by the end of this summer. The project is a simple, custom (that's the reason why I'm even making something like this when there are many other options,) CMS project. The project actually started two summer's ago, but it was more like a more simple clone of the old PHPNuke mixed with blogging ideas.

Anyway, I am wanting to get away from the way PHPNuke handled modules (extra functionality for the future.) The way that it worked (in the version I used to use, I'm not sure how it or PostNuke work now though,) was one would have two folders: "case" and "modules". Then, there was a variable called "op". When there was a need to do something, like list users on a page, or show an article, etc. you would use the op variable to go grab the function you wanted to call (in a module usually.)

That method works okay, but I want to make the "module" idea a bit different. And after seeing how Drupal manages modules, I had an idea to use a MySQL table (in addition to the other tables I have for the CMS database,) to store what modules are found or located in a specified folder--and if the module is enabled or not. The table part is easy to do, that's not the question I'm asking here.

The question I am asking is more like a request. I made a simple flow chart of ideas of how my idea for modules would work. I want to know how unefficient it is, and if there is a better way to enable modules to be used in a CMS type PHP program. By the way, for clarification, a module is basically a set of functions specific to the purpose of a module.

Flow Chart:

Check a directory for Modules → (modules not found, so break)
↓
(modules found)
↓
Put all module filenames into an array
↓
LOOP: compare modules in folder (via the filenames array with modules that are listed in the module table in MySQL database → (if module listed.. do something..)
↓
(if module isn't already listed)
↓
Insert module name into database table (and set it's enabled value to 0 (off) as a default)

And then, I was thinking, I will have to check the module table in the database, to check to see what modules are enabled (when browsing the CMS) and then, if a module is enabled, then make that a require() file ... but isn't this method going to be a bit slow? Is there a more efficient way to handle modules for a simple CMS?

Thank you for any advice, pointers, comments or criticisms.

Andy

    Huh...lots of text there.

    To comment on your remark about it possibly being slow, I'd like to remind all of us that though we may be sticklers for efficiency all the time, we do sometimes take a BIT too far. The only time what you're describing would become quite slow was if there were a large amount of people browsing your site on a minute to minute basis, and your list of modules was quite large.

    Now of course, you could easily use a caching system input there somewhere, maybe involving crontabs or something of the likes, but in my mind you might as well just parse the data when you need it.

    In other words, there is no real need for you to check the directory everytime that you're loading the page, unless the page you're loading is one that deals with the modules in the directory. With that in mind, it might be more efficient for you to only include files that are enabled.

    Not sure how much of a help this has been, bit late for me at the moment, so I apologize if it's just rubbish. However, I do think that there has to be SOMETHING in all the babble that can at least point you in the right direction.

      Thanks for the thoughts and pointers, and maybe to help clarify the situation, I'll give an example of a module I am making.

      It is a "story" module, basically a module that takes an article (ofdata is stored in a database) and then displays the article on a given page. Not much different than any PHP/MySQL type thing. Well, I want to make my core system able to function without that specific module (why would I want to do this? It's because in the future, there most likely will be a need to want to do a different type of story module.)

      So, I guess I need to be able to have a check somewhere in my script, to check to see if the story module is enabled (and by default, it will be enabled.) I think you are right about the efficiency--the script is for a few sites all on one server, one MySQL database. But I don't see the potential for lots and lots of people to be browsing the site all at once. However, I don't need to keep checking for modules at that point. I had another idea, that maybe I could have a place in the admin section/control panel, where an administrator can scan for new modules (after the admin physcially moves a new module file to the module folder) so that the table listing the modules available can be updated. That way, the module folder only has to be scanned from time to time. Any thoughts anyone? Thanks again for the help.

        That was basically what I was getting at, in regards to the admin ability to scan for new modules. Goes with the early morning for me...or...late night. Whatever. Point is...you got the point I wanted to make.

          Write a Reply...