www.it-ebooks.info CMS Design Using PHP and jQuery Build and improve your in-house PHP CMS by enhancing it with jQuery Kae Verens BIRMINGHAM - MUMBAI Downloa d f r o m W o w ! e B o o k < w w w.woweb o o k . c o m > www.it-ebooks.info CMS Design Using PHP and jQuery Copyright © 2010 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: December 2010 Production Reference: 1031210 Published by Packt Publishing Ltd. 32 Lincoln Road Olton Birmingham, B27 6PA, UK. ISBN 978-1-849512-52-7 www.packtpub.com Cover Image by Asher Wishkerman (a.wishkerman@mpic.de) www.it-ebooks.info Credits Author Kae Verens Reviewers Tim Nolte Paul Zabin Acquisition Editor Chaitanya Apte Development Editor Chaitanya Apte Technical Editors Pooja Pande Aaron Rosario Indexer Hemangini Bari Editorial Team Leader Aanchal Kumar Project Team Leader Ashwin Shetty Project Coordinators Zainab Bagasrawala Poorvi Nair Proofreader Lynda Sliwoski Production Coordinator Kruthika Bangera Cover Work Kruthika Bangera www.it-ebooks.info About the Author Kae Verens lives in Monaghan, Ireland with his wife Bronwyn and their two kids Jareth and Boann. He has been programming professionally for more than half his life. Kae started writing in JavaScript in the nineties and started working on server-side languages a few years later. After writing CGI in C and Perl, Kae switched to PHP in 2000, and has worked with it since. Kae worked for almost ten years with Irish web development company Webworks before branching out to form his own company KV Sites ( http://kvsites.ie/) a small company which provides CMS and custom software solutions, as well as design, e-mail, and customer support. Kae wrote the Packt book jQuery 1.3 with PHP, which has since become a part of his company's in-house training. Outside of programming, Kae is currently planning a book on budget clavichord design and building, and is the author of the online instructional book Kae's Guide to Contact Juggling, available here: http://tinyurl. com/kae-cj-book . Kae is currently the secretary of the Irish PHP Users' Group, http://php.ie/, is the owner of the Irish web development company kvsites.ie, http://kvsites.ie/, and is the author of popular web-based le manager KFM, http://kfm.verens.com/. This is Kae's second book for Packt, having written jQuery 1.3 with PHP in 2009. In his spare time, Kae plays the guitar and piano, likes to occasionally dust the skateboard off and mess around on it, and is studying Genbukan Ninjutsu. www.it-ebooks.info Acknowledgement I'd like to thank Packt again, for the great job the reviewers did reining in my ramblings, for their patience when real life intruded and I wasn't always communicative, and for their advice when the book threatened to go on for a few more hundred pages and we had to cut out a few of the planned chapters. Overall, I think we did a good job, and I look forward to seeing what other programmers think of it. Everything in this book was inspired by having to do it for paying customers. When I started building the CMS this book is based on, it was years ago and the other available OS solutions were simply not what our customers wanted; this allowed me the rare chance to build a CMS all the way up from the beginning, and to overcome each of the hurdles that this presents. I've learned a lot on the way, and I hope you, as readers, can benet from what I've learned. My family has had to suffer me being absent for hours every week as I ignored them to concentrate on writing this, so I must thank Bronwyn and my kids Jareth and Boann for their patience! And I'd like to thank all the reviewers of the previous book—hopefully this one will get as good a reception! www.it-ebooks.info About the Reviewers Tim Nolte has been involved in web development since 1996. His rst website was for Davisco Foods International as a high school student at the Minnesota New Country School in Le Sueur, MN. He has many other interests including music, science ction, and the outdoors. Tim now lives in the Grand Rapid, Michigan area with his wife and daughter. Tim began his early web development using a simple text editor. He later moved on to using Dreamweaver and expanding his web development using PHP. Over the years he has had the opportunity to be the developer of many non-prot and business websites. He went on to do web application development in the wireless telecommunications industry at iPCS Wireless, Inc. Today Tim has taken a similar role at Ericsson Services, Inc. where he has expanded his skills and serves customers around the globe. Recently, Tim has had the opportunity to work with a marketing rm to redesign their website using ExpressionEngine and jQuery, as well as give a hand with the rebuilding of Haiti through the development of the Starsh Haiti website. In addition to Tim's professional career, he has been able to use his time and talents at Daybreak ( www.daybreak.tv). He has volunteered for the role of Online Manager at Daybreak for the past three years, where he continues to help Daybreak with their online presence. I thank my wife for her support during the time of reviewing this book. www.it-ebooks.info Paul Zabin wrote his rst BASIC program back in 1977 and has been hooked ever since. Paul's favorite development platform is a combination jQuery, PHP, and MySQL, which he uses to build Google Gadgets, show off his wife's ne art photography, and to learn the true meaning of a JavaScript closure. Paul contributes back to the development community by publishing Google Spreadsheet templates that track stock portfolios, and occasionally posts articles on LinkedIn on how to get XML stock market data from "the cloud". Paul lives in Berkeley, California, with his very patient wife Jenna, where they tend to a rare cactus garden. When not programming or watering the plants, he can be found at the local farmers market or newly discovered coffee shop. Paul can be contacted through his public prole at http://www.linkedin.com/in/ajaxdeveloper/. www.it-ebooks.info www.PacktPub.com Support les, eBooks, discount offers and more You might want to visit www.PacktPub.com for support les and downloads related to your book. Did you know that Packt offers eBook versions of every book published, with PDF and ePub les available? You can upgrade to the eBook version at www.PacktPub. com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at service@packtpub.com for more details. At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks. http://PacktLib.PacktPub.com Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can access, read, and search across Packt's entire library of books. www.it-ebooks.info Why Subscribe? • Fully searchable across every book published by Packt • Copy and paste, print, and bookmark content • On demand and accessible via web browser Free Access for Packt account holders If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access. Downloa d f r o m W o w ! e B o o k < w w w.woweb o o k . c o m > www.it-ebooks.info [...]... distinctly different websites and web projects using one codebase, web design templates, and custom-written plugins for any site-specific differences Example code and explanation is provided for the entire project This book describes how to use PHP, MySQL, and jQuery to build an entire CMS from the ground up, complete with plugin architecture, user management, templatedriven site design, and an installer Each... their results to the CMS, which then renders the results using an HTML template, and sends the result of that back to the browser And a real-life example: The CMS is asked for /news?page=2 The CMS realizes /news uses the "news" plugin and starts that up, passing it the "page=2" parameter The plugin grabs the information it needs from the database and sends its result back to the CMS The CMS then creates... /ww .php_ classes /ww.plugins /ww.skins # # # # # # # # # # # web root configuration directory admin area CMS caches admin-uploaded file resources CMS images CMS function libraries CMS JavaScript files CMS PHP class files CMS plugins templates There are only two files kept in the web root All others are kept in whichever directory makes the most sense for them [ 13 ] www.it-ebooks.info CMS Core Design. .. problems and solutions to various aspects of CMS design, with example code and explanation provided for the chosen solutions A plugin architecture is explained and built, which allows you to enhance your own CMS by adding site-specific code that doesn't involve "hacking" the core CMS By the end of this book, you will have developed a full CMS which can be used to create a large variety of different site designs... use the name "cmsdb" for the database, with the username "cmsuser" and the password "cmspass" You can use phpMyAdmin or some other similar tool to create the database I prefer to do it using the MySQL console itself mysql> create database cmsdb; Query OK, 1 row affected (0.00 sec) mysql> grant all on cmsdb.* to cmsuser@localhost identified by 'cmspass'; Query OK, 0 rows affected (0.00 sec) mysql> flush... simplify future scripts and sites The book is aimed at people who understand the basics of PHP and jQuery, and want to know how they can be used effectively to create a large project that is user-friendly and flexible Conventions In this book, you will find a number of styles of text that distinguish between different kinds of information Here are some examples of these styles, and an explanation of... and the administration area of any site using such a CMS would be daunting—you would have extremely complex editing areas for even the most simple sites, to cater for all possible use cases Instead, the way we handle differences between sites is by using a very simple core, and extending this with plugins The plugins handle anything that the core doesn't handle, and add their own administration forms... all of this manually In your web root, create a directory and call it private This directory will hold the config file Create the file private/config .php and add a basic config (tailored to your own settings): < ?php $DBVARS=array( 'username'=>'cmsuser', 'password '=>'cmspass', 'hostname'=>'localhost', 'db_name' =>'cmsdb' ); This will be expanded throughout the book as we add new capabilities to the... a templates engine for providing cdesign to the front-end, and a simple navigation menu Chapter 6, Design Templates – Part Two, improves on the navigation menu we started in the previous chapter by adding some jQuery to it, and will finish up the templating engine Chapter 7, Plugins, discusses how plugins work, and we will demonstrate this by building a plugin to handle page comments Chapter 8, Forms... done, I recommend using Linux In this book, I used Fedora 13 for the creation of the CMS, and CentOS 5.2 for testing in Chapter 12, Building an Installer Who this book is for If you want to see jQuery in action with PHP and MySQL code, in the context of a real application, this is the book for you This book is written for developers who have written multiple scripts or websites, and want to know how . www.it-ebooks.info CMS Design Using PHP and jQuery Build and improve your in-house PHP CMS by enhancing it with jQuery Kae Verens BIRMINGHAM - MUMBAI Downloa d. websites, and want to know how to combine them all into one package that can be used to simplify future scripts and sites. The book is aimed at people who understand the basics of PHP and jQuery, and. a small company which provides CMS and custom software solutions, as well as design, e-mail, and customer support. Kae wrote the Packt book jQuery 1.3 with PHP, which has since become a part