Designer to design her own CMS - Oh, the horror of it all!

Do you think that’s a stupid idea? I’d not even disagree. Of course there are gazillion CMSes out there, some of them even with adequate code. But I’ve always wanted to know what it’s like to build a CMS. Not a complex one, mind you. Just a barebones CMS with super clean and smart code, a database, easily extendible, and super lightweight.

This is an amateur project, so please no “don’t reinvent the wheel” comments as I’m doing this strictly to learn and eventually use it just for me and to get a better understanding on what’s involved in the process of building an application. :slight_smile:

I have all the time in the world to do this and it’s meant to be a pure fun experience in which I hopefully learn some practical, hands-down PHP and am perfectly content with the occasional head-scratching and hair-pulling.

So, got any tips? Anything you’d recommend I avoid or pay special attention to? :smiley:

That sounds sweet! I wish you good luck with it and would love to see the result when it’s done.

Thanks for the tip. This is roughly going to be my approach as well. Not that I’ll create a guestbook, but I’ll start with the CMS after this weekend and one of my priorities will be to add as few features as possible to the system. Only when something’s truly neccessary (like you have described), I’ll add another feature or two.

I like it a lot. There are some minor mistakes in the code, but the book has a forum where those issues are solved. Building a Comic Book CMS is fun :slight_smile: so it’s a fun way to learn. I’m only half-way through, but the thing I noticed most is how many SQL queries there are and how critical that is to the entire process.

It is cool to have a project in mind to practice all this stuff. My own little personal project involves designing and coding a recipe database - my own little online cookbook :cool:. I wish you the best of luck on your project!

I am a newbie with PHP and I’m building a simple CMS through the book “beginning PHP6, Apache, MySQL Web Development” from Wrox publishing. It takes you through building a Comic Book Appreciation site. One thing I am learning is this: PHP is only half of it. You also need to know how to write MySQL queries to query the database. So brush up on how to SELECT, UPDATE, DELETE and INSERT, cuz you’ll be doing it a LOT.

@Jake, I am not a novice PHP programmer. I’m an absolute amateur PHP programmer. Big difference. I do sometimes understand things though, so that’s where I’m taking my encouragement from to learn PHP and hopefully learning some fundamentals of programming along the way.

@ahundiak, fantastic advice! I have two CMSes that I like a lot. One’s considered to be horribly coded (WordPress), the other’s said to have a devastatingly poor handle on MVC (ExpressionEngine). I’m sure there are CMSes out there that are cleaner and/or of higher quality in terms of logic and code, so if there’s one you feel is a good example of proper programming, out with it. :slight_smile:

Just give up and use WP jk :lol:

I would figure out what you want it to do first so when you are part way through, you don’t have to do major edits to add on.

:x @ Ryan! :smiley:

Thanks for the input. Yes, I do plan to write down everything first before touching code. :slight_smile:

@Jake. That’s great advice. I’ve heard of MVC, the emphasis is on “heard”. I’ll do my homework.

Great advice so far, thanks!

[ot]Nice to see you about Jake! Are you per chance heading to PHPNW10 tonight/tomorrow?

There seems to be a large SP contingent! Myself, Cups, SpikeZ, Salathe…[/ot]

Stupid idea? Never. You are out to learn things. That is never, ever stupid.

Before you start writing your own CMS, you should see what else is out there just to get a general feel of what is available. As someone who has authored a complete CMS from the ground up, I’d like to think I am somewhat of an authority on the topic :wink: - see my signature. For a taste of how “difficult” it can be, it took me one year of my spare time to go from the concept to version 1.0 of my CMS. But, as you already know, there are thousands of CMS products out there. It depends on how complex you want to make it but it can take anywhere from a couple months to a year or two (depending on skill).

If you want something that will get you started on the right foot or just want to look at some basic code that is easy to follow, you could take a look at Admin Pack - a related product to my CMS. It provides a framework in which to operate that deals with critical issues like CSRF attacks and standardizing user input and creating a common form display so visual elements are 100% consistent. I use Admin Pack extensively for creating cheesy, secure admin tools in a fraction of the time it used to take me. It isn’t well-suited though for a full-fledged CMS but should give you a few ideas.

One thing I’ve found over the years is that databases are painfully slow. Yet most CMS products use a database. Databases are useful for pure dynamic content - but, for static content that can be cached, they are not necessary and can even get in the way. Very few CMSes are purely file-based. When I learned of the PHP serialize() function a few years ago, I knew I had found my new best friend. (Then I married that friend to base64_encode() and they formed the basis of how I store information in my CMS). I now serialize() pretty much everything. I even stuff PHP serialized data into databases. Using a serialized PHP array is SOOO much easier than altering database tables every time I need a new field. The downside is I can’t easily use the data in other scripting languages. Which is what json_encode() is for. A good friend but not nearly as amazing as serialize().

One other tip: Don’t use TinyMCE. The output it creates is a nightmare to process and clean up. I much prefer WYMEditor. Of course, I’m assuming you want some visually appealing WYSWYG-ish editor - if you want to enter raw HTML, then just use a textarea and be done with it. Also, use htmlspecialchars() extensively when displaying content.

Download three or four of the more popular cms systems. Make a spreadsheet and start listing the sort of things they support and how they do it using a column for each different system. Having such a side by side comparison might give you some ideas for your own system.

Consider using php name spaces. I don’t think any of the major existing systems use name spaces so it might be breaking new ground. Be interesting to see if name space functionality can really add anything useful to the project.

MVC is rather complex if you haven’t done much with application design before. Basically it involves creating classes with different jobs in the application - how you go about it varies, but a typical approach is:

[User sends request to any page in the website] -> [This request, if the file in question doesn’t exist, is passed to a controller file] -> [This controller file takes the request as a string and parses it to create a command, e.g. Article/Edit/3] -> [This then collects the output of an include() to the Edit.php file under /Modules/Article, passing 3 as an identifier] -> [The output is sent to a main template file].

[ot]

Ahhh the last few weeks have been very busy! Should be back on track any time soon :slight_smile:

I’m not going to the conference, no - I would have loved to, but there’s so much on with uni that I foresaw the time and transport difficulties![/ot]

My start was to build a guestbook. It was cool, whatever I typed and submitted was actually on the page. I started thinking of adding a wysiwyg to the html area. Cool, now I can add hyperlinks and images, but wait, I don’t have any images on the server. Using GDlib, made a script that would upload and resize my images. I’m getting somewhere now but don’t want just anybody uploading things so I set about moving those functions into a session based login section.

Now wouldn’t it be great to create another editable page. That wasn’t too hard and added an inc_menu.php to all the new pages so that all of the pages had links to the other pages. (Un)fortunatly I am a fan of suckerfish dropdowns. This meant frustration trying to build the nested menu and keep the links straight. At this point I could create read update delete (CRUD) everything. Next step was to add multimedia and stuff like PDF’s. I wanted to be able to put these where I wanted them and came up with a copy and paste solution. [flv|videofile.flv] gets pasted where you want the media and the script finds the correct player for it.

Just saying that it can be done. In action,
http://wifigator.com/wiki/
and
http://tazwire.com/
It’s very satisfying to build something yourself.
Start with the guest book concept and put it on steroids.

If you have the time to do this, DO IT! You will learn SO MUCH by creating your own projects like this. You can’t trade experience for just studying it! I look back at projects I made for fun years ago and I can see improvements like night and day and feel really good!

Give yourself tiny realistic goals, and challenge yourself to keep improving on it, like this!

Start:
---------------------_
Make a textfield form, and submit it.
Make it save to a database.
Make that display on a page.

Next
---------------------_
Now make that page editable, so the text that you typed in fills in the textarea.

Next
---------------------_
Now make the backend require a password to get into. (You’ll have to come back to this time to time to make it secure!)

Next
---------------------_
Make it so you can create brand new pages!

Next
---------------------_
List all the pages that exist by the title.
Make it so you can click edit next to a page and change the content!

By doing it this way you won’t think, well that project has SO much to do that I dont want to bother its going to take all day. What you’ll find is doing little things at once (ATLEAST FOR ME) gets you in the thought cycle and you end up doing it for hours and its fun!

Yes, I figured as much. I’ve got SitePoint’s “Build Your Own Database Driven Website Using PHP and MySQL”. I think I also have Rudy’s SQL book lying around here somewhere, or it’s just my imagination. :smiley: I am not certain whether or not it’s a good idea to use these books as a starting point or whether it’s better to use the PHP manual (php.net) and work my way through that instead, or both. Lots of testing out will probably help. :slight_smile:

How do you like the book you are currently working with, bopjo1?

This is sweet! Thanks for that, Dave. I’ve never liked MODx’ backend, but that’s got nothing to do with how well the application is done. I’ll download it again and will use it to study the code after I’ve read up on MVC, as you suggested.

As for the points I should consider, hmm…admittedly, some points are over my head at this time, but I’ve made a few notes on core features that I want to implement. Security and administration are abstract terms for me and sound mighty complicated. But I’ll try and get my head around those too.

Oh, lots of great information, JREAM! Sounds like you’ve gone a similar route yourself? :slight_smile:

I’ll definitely do it in small steps as you laid out, as I tend to get nervous if that one end goal is so far out of sight.

Well, that’s all a lot to digest. I’m going to make notes of everything you’ve outlined and that should give me a better overview.

A simple CMS is rather aptly named - simple.

As you want more and more features/flexibility, you’ll find yourself in a world of constant application rewriting and headaches. All part of the fun :stuck_out_tongue:

So start of simple. REAL simple. Give each page a unique name and to view the content, go to view.php?page=[pagename], to edit content go to edit.php?page=[pagename] etc. If you don’t want a full user-auth system, you can always use .htaccess authentication for a simple login just to prevent attacks.

Make sure your input is filtered enough - it’s rather easy to make a mess of a page by not closing a tag etc. If you don’t want to use HTML to input content, then use methods which encode the < to < and > to &rt; etc upon output.

That’s pretty much as basic as it gets.

You can use a mod-rewrite later on to reroute urls to something like /content/[pagename].html if you want. More advanced would be to reroute all requests to a central controller file, which loads templates based on the requests given - so MVC would be worth looking into if you want flexibility.

I know this is obvious, but I would suggest doing some basic reading on MVC before you start looking at code bases. There are some examples of “MVC” applications which are built when it’s obvious there’s limited understanding of what the concepts mean - I’ve recently working with one where the only way to gain access to the database on the client side was to make web service calls to the administrative area. Needless to say, it’s slow and frustrating - but I’m not going to say who it came from because I don’t want to provide ANY publicity at all.

That said, I’ve heard really nice things about MODx. Another currently popular one is [URL=“http://drupal.org/”]Drupal - though that may be overkill for what you’re looking to build and may be overwhelming (and I don’t think it’s MVC).

I’ve often thought about writing my own CMS and have started it a couple times (based on language I was working on at the moment). Here are a couple things I would suggest you think about before you get too far in.[LIST=1]
[]Core adminstrators - are they going to be developers who are going to be more willing to get their hands dirty, or is it going to be non-technical people who’ll struggle with anything that doesn’t look like email/word? This will also affect how you handle error messages, upgrades, etc.
[
]Security - are you going group based or role-based? Think long and hard on this one, and once you make a choice, try to stick to it because otherwise you’re going to be kicking yourself when you have to go back and reverse it (or worse yet, have to have a hybird)
[]Templating - are you going to use something like Smarty, something else, or are you going to build your own? Or are you going to use a theme concept.
[
]Media Management - this one can include photos, music files, etc. Whatever you need to manage generically. How are you going to handle the management (and the access from point#2)?
[/LIST]