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: March 2011 Second Edition: April 2013
Production Reference: 1160413
Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78216-931-4 www.packtpub.com
Cover Image by Jarek Blaminsky (firstname.lastname@example.org)
Credits Author Remo Laubacher Reviewers
Project Coordinator Abhishek Kori Proofreaders
John Steele Indexer Acquisition Editor
Mary Nadar Graphics Lead Technical Editor
Savio Jose Production Coordinator Technical Editors
Sharvari Baet Ankita Meshram Kirti Pujari
Cover Work Conidon Miranda
About the Author Remo Laubacher grew up in Central Switzerland in a small village surrounded by mountains and natural beauty. He started working with computers a long time ago and then, after various computer-related projects, focused on ERP and Oracle development. After completing his BSc in Business Administration, Remo became a partner at Ortic, his ERP and Oracle business, as well as a partner at Mesch web consulting and design GmbH. At Mesch—where he's responsible for all development-related topics—he discovered concrete5 as the perfect tool for their web-related projects and has since become a key member of the concrete5 community. You can find his latest publications on http://www.codeblog.ch/. He has also authored concrete5 Beginner's Guide and Creating concrete5 Themes.
About the Reviewers Ryan Hewitt has been a web developer for over 10 years and has worked extensively with concrete5, with it being his content management system of choice. Ryan's background includes working for both large and small development companies, wading through oceans of code and fighting SQL beasts, PHP devils, and CSS nasties. He has written numerous custom online systems and scripts—finding solace in the advantages that well written frameworks and libraries such as CakePHP, jQuery, Boostrap Twitter, and concrete5 bring forth. Ryan started his own web development business in 2011, with his partner Lelita Baldock, called Mesuva Web Development. From the beautiful coastal town of Goolwa, in South Australia, Ryan and Lelita build a wide range of websites and online shops using concrete5, often heavily customizing them with custom-built blocks and packages. One of concrete5's greatest strengths as a CMS is its active online community, and Ryan takes pride in contributing answers and insights to the online forum, as well as providing free concrete5 packages and support. The Mesuva website can be found at https://www.mesuva.com.au and Ryan can be contacted through it.
Werner Nindl is an Oracle Hyperion consultant by day and a concrete5 web developer by night. As a consultant, he has lived and worked in Europe, China, and the US. During his day job, Werner manages consulting programs for Financial Consolidation and Reporting.
Intrigued by the capabilities of concrete5, he has started to convert his clients' web sites to concrete5. Participating in the review of this book has helped him to plan for future enhancements. He believes that he can implement those enhancements now at a much lower resource cost then previously planned. I want to thank the publishers for the opportunity to participate. First and foremost I want to compliment Remo on his tremendous insight into, and knowledge about, concrete5.
John Steele began teaching himself BASIC on a borrowed Atari. He purchased his first computer, the Timex Sinclair 1000, later trading it in on a Commodore 64. He then taught himself 6502 Assembly followed by the C language, creating a 3D wireframe program to design a hang-glider. He was a Mathematics major, switching to Computer Science as soon as the degree program was available. He worked as a Systems Programmer at the IBM Almaden Research Center using C, Fortran, Pascal, and 8086 Assembly. Next, he worked as Systems Analyst and Lead Programmer for the largest selling POS software for video stores. He was a beta tester for every version of the Microsoft C compiler. Fascinated by the Internet, he taught himself PHP3 and MySQL programming and started his business Steelesoft Consulting. He's used just about every Unix-based operating system since the DEC PDP-11 and owns the first version of Linux on CD. He's also been a technical editor for two PHP4 books by Osborne-McGraw Hill. I'd like to thank Remo and all the fine folks at concrete5.org and the wonderful people who help others on the Forums everyday.
www.PacktPub.com Support files, eBooks, discount offers and more You might want to visit www.PacktPub.com for support files and downloads related to your book. Did you know that Packt offers eBook versions of every book published, with PDF and ePub files 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 email@example.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. TM
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.
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.
Table of Contents Preface1 Chapter 1: Installing concrete5 7 Preparing for installation Web browser Text editor Archive utility FTP client Installing Bitnami Time for action – installing Bitnami WAMP stack Downloading concrete5 Time for action – downloading the latest version Creating an empty MySQL database Time for action – creating a MySQL database Installing concrete5 Time for action – installing concrete5 The configuration file Disabling caching
7 8 8 8 8 9 9 15 16 17 17 19 20 23 24
Time for action – disabling caching Enabling pretty URLs
Time for action – enabling pretty URLs File and directory structure of concrete5 Dispatcher process
25 26 27
Chapter 2: Working with concrete5 Getting familiar with concrete5 Time for action – logging in to concrete5 Adding new blocks Time for action – adding new blocks
29 29 30 32 32
Table of Contents
Time for action – editing existing blocks Time for action – exiting edit mode Working with the dashboard Time for action – changing the site's name Adding more pages Time for action – adding pages to create a news section Time for action – adding blocks to a new page Managing page defaults Time for action – adding default blocks to a page type Adding blocks to existing pages Time for action – adding blocks to existing pages Moving and sorting pages Time for action – moving and sorting your pages Splitting content into columns Time for action – creating a multi-column layout Copying blocks using the clipboard Time for action – copying the block using the clipboard Working with stacks Time for action – working with stacks Styling with design and CSS Time for action – styling your blocks Summary
Managing basic permissions Adding users and groups Time for action – adding groups
61 62 62
Group expiration options
Time for action – adding users
Working with user attributes
Granting sitemap and file manager permissions Time for action – assigning sitemap permissions Time for action – granting file manager permissions Granting page editing permissions Time for action – granting edit access Managing edit access on a page by page basis
Creating a protected website section Time for action – creating a protected website Granting partial dashboard access Time for action – granting partial dashboard access Restricting block access [ ii ]
66 66 68 70 70 71
72 72 74 74 75
Table of Contents
Time for action – restricting access to blocks Working with the advanced permission mode Time for action – activating the advanced permission mode Managing advanced page permissions
75 76 76 77
Time for action – removing permissions to change permissions Managing area permissions Managing block permissions Managing subpage permissions Time for action – setting subpage permissions Summary
Chapter 4: Managing Add-ons
78 79 80 81 81 83
Introduction to add-ons Installing add-ons from the marketplace Time for action – installing an add-on Time for action – uninstalling an add-on Manually installing an add-on Time for action – installing an add-on manually Working with theme add-ons Parts of a theme Theme file structure Working with block add-ons Block structure Packages Summary
Chapter 5: Creating Your Own Theme
85 86 86 88 88 89 90 91 92 94 94 96 97
Starting with a new layout The HTML code CSS rules Converting HTML and CSS to a concrete5 theme Time for action – creating the concrete5 theme header Time for action – creating the concrete5 theme footer Time for action – creating a page template Time for action – creating more page templates Installing your theme Time for action – installing theme PHP constants and functions Time for action – getting a list of available constants Time for action – listing all available functions Time for action – checking for edit mode
Time for action – hiding content from anonymous visitors Time for action – restricting numbers of blocks per area Time for action – inserting a block wrapper in an area Working with page attributes Time for action – using attributes to set background picture Time for action – accessing attribute data from a template Inserting blocks in templates Time for action – replacing the header area with a template block Time for action – finding autonav block properties Time for action – specifying block templates in an area Applying a theme to a single page Time for action – creating a single page layout Time for action – adding variables to handle login errors Creating customizable themes Time for action – creating a customizable theme Summary
Custom templates to modify a block layout Thumbnails in a page list Time for action – adding thumbnails to a page list Time for action – restricting thumbnails to a custom dimension Block template folder Time for action – creating a template folder Picture pop-ups in a content block Time for action – building a lightbox gallery Adding a Gravatar picture in the guestbook Time for action – adding a Gravatar picture to the guestbook Avoiding duplicate code in a custom template Time for action – including an existing template Transforming a slideshow into a gallery Time for action – creating a gallery template for a slideshow Time for action – adding a slideshow gallery Slideshow using file attributes Time for action – adding file attributes to our slideshow Time for action – using file attributes in the gallery Using advanced tooltips in the content block Time for action – creating advanced tooltips Summary
Introducing the autonav block Preparation Time for action – undoing autonav block integration Autonav options Autonav page structure Page order Example 1 – showing all pages Example 2 – showing relevant subpages Example 3 – showing relevant subpages starting from the top
Autonav output Adding navigation images Time for action – creating page attributes for navigation pictures Time for action – creating a block picture navigation template Adding a CSS3 hover effect Time for action – creating a CSS3 transition autonav template Building a drop-down navigation Time for action – creating a SooperFish template Sliding mobile navigation Time for action – building a mobile navigation Summary
Chapter 8: Creating your Own Add-on Block Building a product information block Steps for creating a block
159 160 160 161 161 161 162 164 164
165 168 168 168 170 171 173 174 177 177 180
181 182 182
Adding the database schema
Time for action – creating the database structure Time for action – creating the block controller Time for action – creating the editing interface Time for action – printing block output Time for action – installing a block Checking for mandatory fields Time for action – adding a check for mandatory fields Adding product categories Time for action – adding product categories Building a product list Handling multiple block versions Time for action – handling multiple block versions Creating a product list block Time for action – creating the product list block Creating a picture magnifier
Time for action – creating the picture magnifier block Creating a PDF-generating block Time for action – creating the PDF generation block Using generate_pdf.php Creating a simple gallery Time for action – creating the simple gallery block Summary
Chapter 9: Everything in a Package
201 204 205 208 208 209 213
Working with the MVC pattern Adding the broken link interface Time for action – creating the broken links dashboard extension Moving database access into a model Time for action – creating a package model Working with multiple controller methods Time for action – adding a second controller method [ vi ]
245 247 248 252 252 255 256
Table of Contents
Embedding a file editor in the dashboard Time for action – creating the file editor add-on Controllers without logic Summary
Chapter 11: Deployment and Configuration Deploying a concrete5 site Preparations for deployment Time for action – disabling pretty URLs and the cache Transferring MySQL databases Time for action – transferring MySQL databases Transferring files to the server Time for action – transferring files to the server Time for action – updating the configuration file Setting file permissions Time for action – setting file permissions Updating production configuration Updating the configuration file Base URL redirection Changing the concrete5 language Time for action – installing a translation file Improving performance with a cache Time for action – getting PHP information Caching with APC Measuring site performance
Time for action – measuring site performance Where to go next Summary
Pop Quiz Answers Index
288 290 291
[ vii ]
Preface concrete5 Beginner's Guide covers everything you need to build your own website with a number of customizations and add-ons built from scratch, for those who need a pretty site that also offers some slick functionality. concrete5 is one of many CMS' out there, but it manags to shine with a number of ideas and impressive solutions. For example, there's a very intuitive in-site editing concept where you can manage the content of your site in the actual layout of it and don't have to understand a complicated backend. The book gives you a quick introduction about this concept, but is focused on developers with the intention to build websites and-applications. You'll therefore need some experience as a web developer, if possible with the technologies used by concrete5: PHP, MySQL, and jQuery. Experience with concrete5 isn't necessary though. The book guides you step-by-step from installation to the customization, and even to the creation of add-ons. As you'll see towards the end, the packaging system of concrete5 you use to build your add-ons is very powerful and, thanks to the marketplace, you can easily popularize your own work and, if you want, also get some money by selling your add-ons.
What this book covers Chapter 1, Installing concrete5, helps you to get a test-site running on your local computer, from where we'll continue to work with concrete5. Chapter 2, Working with concrete5, discusses the basics of concrete5 you need to know to manage the content of a site, basically a compression of an end-user manual. Chapter 3, Managing Permissions, looks at the powerful permissions of concrete5. You'll learn how to restrict access to a part of your site as well as allowing editors to see parts of the managing interface of concrete5.
Chapter 4, Managing Add-ons, explains what an add-on is and how you can install them from the marketplace. Chapter 5, Creating Your Own Theme, shows how to convert an existing HTML layout into a concrete5 theme. Chapter 6, Customizing Block Layouts, looks at ways to customize block layouts—blocks are layout elements in concrete5—making them look well in your own theme. Chapter 7, Adding Site Navigation, teaches you how to add a dynamic navigation to your website. Chapter 8, Creating Your Own Add-on Block, teaches you to create your own block, and the content elements of concrete5 from scratch. Chapter 9, Everything in a Package, discusses how packages make it easier to work with add-ons that contains different things. We'll wrap a few things we've created in the previous chapters into a package. Chapter 10, Dashboard Extensions, teaches you how to extend the dashboard, which is the place in concrete5 where you manage users, settings, and a lot more. Chapter 11, Deployment and Configuration, explains how to copy the site from the local computer to a live server and also explains a few configurations.
What you need for this book You're almost free to use any kind of tool you want. The screenshots in this book were taken on a Windows computer but Mac OSX as well as Linux works fine as well. A text editor such as Notepad++, a web server such as Apache with PHP and MySQL, and an FTP client such as FileZilla are all you need.
Conventions In this book, you will find several headings appearing frequently. To give clear instructions of how to complete a procedure or task, we use:
Time for action – heading 1. 2. 3.
Action 1 Action 2 Action 3
Instructions often need some extra explanation so that they make sense, so they are followed with:
What just happened? This heading explains the working of tasks or instructions that you have just completed. You will also find some other learning aids in the book, including:
Pop quiz – heading These are short multiple-choice questions intended to help you test your own understanding.
Have a go hero – heading These are practical challenges and give you ideas for experimenting with what you have learned. You will also 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 their meaning. Code words in text are shown as follows: "You may notice that we used the Unix command rm to remove the Drush directory rather than the DOS del command." A block of code is set as follows: # * Fine Tuning # key_buffer = 16M key_buffer_size = 32M max_allowed_packet = 16M thread_stack = 512K thread_cache_size = 8 max_connections = 300
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold: # * Fine Tuning # key_buffer = 16M key_buffer_size = 32M max_allowed_packet = 16M thread_stack = 512K thread_cache_size = 8 max_connections = 300
Any command-line input or output is written as follows: cd /ProgramData/Propeople rm -r Drush git clone --branch master http://git.drupal.org/project/drush.git
New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "On the Select Destination Location screen, click on Next to accept the default destination.". Warnings or important notes appear in a box like this.
Tips and tricks appear like this.
Reader feedback Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of. To send us general feedback, simply send an e-mail to firstname.lastname@example.org, and mention the book title through the subject of your message. If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.
Customer support Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
Downloading the example code You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
Errata Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website, or added to any list of existing errata, under the Errata section of that title.
Piracy Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy. Please contact us at email@example.com with a link to the suspected pirated material. We appreciate your help in protecting our authors, and our ability to bring you valuable content.
Questions You can contact us at firstname.lastname@example.org if you are having a problem with any aspect of the book, and we will do our best to address it.
Installing concrete5 In this chapter, you'll learn what you need to get your own concrete5 site up and running on your local computer. You don't need to have a lot of experience with Apache, PHP, and MySQL configuration as we're going to use Bitnami, which will install all necessary components in almost no time. Before you can start working with concrete5, you have to set up an environment, where you can test and play around with concrete5 to get used to it. If you have a web hosting account, you can install concrete5 there, but since that isn't always the case, we'll install everything concrete5 needs to work smoothly on your local Windows computer. We're assuming that you're working with Windows but instructions are available for those running Mac OS or Linux; most instructions work the same for all operating systems. Bitnami installs a local web server, which we'll use to build and test the add-ons we're going to create. In the last chapter of this book, we're going to move the site from your local computer to a live web server.
Preparing for installation There are a few tools you need, before you can start with the installation process. You probably already work with similar tools, but let's still make sure you've got everything before continuing.
Text editor Since we're going to edit PHP files you'll need a text editor. The requirements are quite small; you can pick almost any text editor you want. Just make sure it does support PHP syntax highlighting. Here are some possible editors:
PSPad (Windows only, free), http://www.pspad.com. A simple text editor with in-built FTP support. This can make a quick fix on your website even quicker.
TextWrangler (Mac OS only, free), http://www.barebones.com/products/ textwrangler/. A very slick and clean text editor with extensive FTP support.
Notepad++ (Windows only, free), http://notepad-plus-plus.org/. A small and fast replacement for Windows notepad.
There are a lot more text editors, as mentioned previously; you can use almost any editor you want. If you're familiar with another product, just go with it. You won't find anything in this book where you need a special text editor feature.
Archive utility The same with the file archive utility, there are plenty of tools out there and if you want, you can use the in-built extraction utility of Windows or Mac OS. If you're looking for something more advanced, you can go with 7-Zip at http://www.7-zip.org/ or IZArc at http://www.izarc.org/; both are free and do a good job.
FTP client Once more, there are lots of choices. You'll have to change file permissions later, so make sure your FTP client includes this option. A powerful and well known client is FileZilla, http://filezilla-project.org/. It's free as well and has a lot more features than we need.