You are previewing PHP 5 CMS Framework Development.
O'Reilly logo
PHP 5 CMS Framework Development

Book Description

For professional PHP developers, this is the perfect guide to web-oriented frameworks and content management systems. Covers all the critical design issues and programming techniques in an easy-to-follow style and structure.

  • Learn about the design choices involved in the creation of advanced web oriented PHP systems

  • Build an infrastructure for web applications that provides high functionality while avoiding pre-empting styling choices

  • Implement solid mechanisms for common features such as menus, presentation services, user management, and more

  • Written by a seasoned developer of CMS applications and other modern software

  • In Detail

    If you want an insight into the critical design issues and programming techniques required for a web oriented framework in PHP5, this book will be invaluable. Whether you want to build your own CMS style framework, want to understand how such frameworks are created, or simply want to review advanced PHP5 software development techniques, this book is for you.

    As a former development team leader on the renowned Mambo open-source content management system, author Martin Brampton offers unique insight and practical guidance into the problem of building an architecture for a web oriented framework or content management system, using the latest versions of popular web scripting language PHP.

    The scene-setting first chapter describes the evolution of PHP frameworks designed to support web sites by acting as content management systems. It reviews the critical and desirable features of such systems, followed by an overview of the technology and a review of the technical environment. Following chapters look at particular topics, with: • A concise statement of the problem • Discussion of the important design issues and problems faced • Creation of the framework solution

    At every point, there is an emphasis on effectiveness, efficiency and security – all vital attributes for sound web systems. By and large these are achieved through thoughtful design and careful implementation.

    Early chapters look at the best ways to handle some fundamental issues such as the automatic loading of code modules and interfaces to database systems. Digging deeper into the problems that are driven by web requirements, following chapters go deeply into session handling, caches, and access control.

    New for this edition is a chapter discussing the transformation of URLs to turn ugly query strings into readable strings that are believed to be more “search engine friendly” and are certainly more user friendly. This topic is then extended into a review of ways to handle “friendly” URLs without going through query strings, and how to build RESTful interfaces.

    The final chapter discusses the key issues that affect a wide range of specific content handlers and explores a practical example in detail.

    This book takes you through the creation of a working architecture for a PHP 5-based framework for web applications, stepping you through the design and major implementation issues, right through to explanations of working code examples

    "

    Table of Contents

    1. PHP 5 CMS Framework Development
      1. PHP 5 CMS Framework Development
      2. Credits
      3. About the Author
      4. Acknowledgement
      5. About the Reviewers
      6. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Errata
          2. Piracy
          3. Questions
      7. 1. CMS Architecture
        1. The idea of a CMS
          1. Critical CMS features
          2. Desirable CMS features
          3. System management
        2. Technology for CMS building
          1. Leveraging PHP5
          2. Some PHP policies
          3. Globalness in PHP
          4. Classes and objects
          5. Objects, patterns, and refactoring
          6. The object-relational compromise
          7. Basics of combining PHP and XHTML
          8. Model, view, and controller
        3. The CMS environment
          1. Hosting the CMS
          2. Basic browser matters
          3. Security of a CMS
          4. Some CMS terminology
        4. Summary
      8. 2. Organizing Code
        1. The problem
        2. Discussion and considerations
          1. Security
          2. Methods of code inclusion
          3. Practicality in coding
        3. Exploring PHP and object design
          1. Autoloading
          2. Namespaces and class visibility
          3. Singletons
            1. Objections to use of singletons
        4. Framework solution
          1. Autoloading
            1. The smart class mapper
          2. Finding a path to the class
          3. Populating the dynamic class map
          4. Saving map elements
            1. Obtaining class information
        5. Summary
      9. 3. Database and Data Objects
        1. The problem
        2. Discussion and considerations
          1. Database dependency
          2. The role of the database
          3. Level of database abstraction
          4. Ease of development
          5. Keeping up with change
          6. Database security
          7. Pragmatic error handling
        3. Exploring PHP—indirect references
        4. Framework solution
          1. Class structure
            1. Connecting to a database
          2. Handling databases easily
            1. Prefixing table names in SQL
            2. Making the database work
            3. Getting hold of data
            4. Higher level data access
            5. Assisted update and insert
            6. What happened?
          3. Database extended services
            1. Getting data about data
            2. Easier data about data
            3. Aiding maintenance
          4. Data objects
            1. Rudimentary data object methods
            2. Data object input and output
            3. Setting data in data objects
            4. Sequencing database rows
          5. Database maintenance utility
        5. Summary
      10. 4. Administrators, Users, and Guests
        1. The problem
        2. Discussion and considerations
          1. Who needs users?
          2. Secure authentication
          3. Secure storage of passwords
          4. Blocking SQL injection
          5. Login
          6. Managing user data
          7. User self service
          8. Customizing for users
          9. Extended user information
        3. Exploring PHP—arrays and SQL
        4. Framework solution
          1. The user database table
          2. Indexes on users
          3. Keeping user tables in step
          4. Achieving login
          5. Administering users
          6. Generating passwords
        5. Summary
      11. 5. Sessions and Users
        1. The problem
        2. Discussion and considerations
          1. Why sessions?
          2. How sessions work
          3. Avoiding session vulnerabilities
          4. Search engine bots
        3. Session data and scalability
        4. Exploring PHP—frameworks of classes
        5. Framework solution
          1. Building a session handler
        6. Creating a session
          1. Finding the IP address
          2. Validating a session
          3. Remembering users
          4. Completing session handling
          5. Session data
          6. Session data and bots
          7. Retrieving session data
        7. Keeping session data tidy
        8. Summary
      12. 6. Caches and Handlers
        1. The problem
        2. Discussion and considerations
          1. Why build information handlers?
          2. The singleton cache
            1. The disk cache
            2. Scalability and database cache
          3. The XHTML cache
          4. Other caches
        3. Exploring PHP—static elements and helpers
        4. Framework solution
          1. Abstract cache class
          2. Singleton object cache manager
          3. Creating the base class cached singleton
          4. Generalized cache
        5. Summary
      13. 7. Access Control
        1. The problem
        2. Discussion and considerations
          1. Adding hierarchy
          2. Adding constraints
          3. Avoiding unnecessary restrictions
          4. Some special roles
          5. Implementation efficiency
          6. Where are the real difficulties?
        3. Exploring SQL—MySQL and PHP
        4. Framework solution
          1. Database for RBAC
          2. Administering RBAC
          3. The general RBAC cache
          4. Asking RBAC questions
        5. Summary
      14. 8. Handling Extensions
        1. The problem
        2. Discussion and considerations
          1. An extension ecosystem
            1. Templates in the ecosystem
            2. Modules in the ecosystem
            3. Components in the ecosystem
            4. Component templates
            5. Modules everywhere
          2. More on extensions
            1. Templates
            2. Modules
            3. Components
              1. Component for the administrator
              2. Component for the user
              3. Component standard structure
            4. Plugins
          3. Extension parameters
        3. Exploring PHP—XML handling
        4. Framework solution
          1. Packaging extensions
          2. Module interface and structure
          3. The logic of module activation
          4. Component interface and structure
            1. A standardized component structure
          5. Plugin interface and structure
          6. Invoking plugins
          7. Applications
          8. Installing and managing extensions
            1. Structuring installer tasks
            2. Putting extension files in place
            3. Extensions and the database
            4. Knowing about extension classes
        5. Summary
      15. 9. Menus
        1. The problem
        2. Discussion and considerations
          1. Page management by URI
          2. Menu database requirements
          3. Menu management
          4. Menu construction
          5. Menu presentation
        3. Exploring PHP—array functions
        4. Framework solution
          1. Building the menu handler
          2. Interfacing to components
          3. The menu creator
          4. An example of a menu module
        5. Summary
      16. 10. Languages
        1. The problem
        2. Discussion and considerations
          1. Character sets
          2. UTF-8 and XHTML
          3. Specifying languages
          4. Handling multiple languages in code
          5. Languages in CMS extensions
          6. Handling languages in data
        3. Exploring PHP—character sets
        4. Framework solution
          1. The gettext implementation
            1. File formats for gettext
            2. Functions for gettext
            3. The PHPgettext classes
            4. The language class
            5. Administrator language application
              1. Language details
              2. Translation
          2. Handling extensions
            1. Managing extension translations
            2. Installing translations with CMS extensions
            3. Handling multilingual data
        5. Summary
      17. 11. Presentation Services
        1. The problem
        2. Discussion and considerations
          1. Differing points of view
          2. Model View Controller
          3. XHTML, CSS, and themes
          4. PHP for XHTML creation
          5. GUI widgets and XHTML
          6. Page control and navigation
          7. WYSIWYG editors
          8. XHTML cleaning
          9. The administrator interface
        3. Exploring PHP—clarity and succinctness
        4. Framework solution
          1. Using "heredoc" to define XHTML
          2. Using templating engines
          3. Some widgets
          4. Building page control
          5. Supporting editors
          6. Cleaning up XHTML
          7. Administrator database management
          8. Customization through subclassing
        5. Summary
      18. 12. Other Services
        1. The problem
        2. Discussion and considerations
          1. Parsing XML
          2. Configuration handling
          3. WYSIWYG editing
          4. File and directory handling
          5. Sending mail
          6. Parameter objects
          7. Administrator ready-made functionality
          8. Exploring PHP—file issues in web hosting
            1. Basic file and directory permissions
            2. Hosting and ownership
            3. Living with split ownership
            4. Avoiding split ownership
        3. Framework solution
          1. Reading XML files easily
          2. Storing configuration data
          3. Incorporating a WYSIWYG editor
          4. Dealing with files and directories
          5. Compound parameter objects
          6. Administrator ready-made table handlers
        4. Summary
      19. 13. SEF and RESTful Services
        1. The problem
        2. Discussion
          1. Transforming query strings
          2. Direct URI handling and REST
          3. Mechanics of URI handling
          4. Essential HTTP result codes
          5. The importance of metadata
          6. Exploring PHP—PHP and HTTP
        3. Framework solution
          1. Efficient lookup of very long keys
          2. Cache and database transformation
          3. Looking at SEF transformation code
            1. Decoding an incoming URI
            2. Encoding an outgoing URI
          4. Direct URI handling
            1. The future of direct URIs
        4. Summary
      20. 14. Error Handling
        1. The problem
        2. Discussion
          1. PHP error handling
          2. Database errors
          3. Application errors
          4. Exploring PHP—error handling
        3. Framework solution
          1. Handling database errors
          2. 404 and 403 errors
        4. Summary
      21. 15. Real Content
        1. The problem
        2. Discussion and considerations
          1. Articles, blogs, magazines, and FAQ
          2. Comments and reviews
          3. Forums
          4. Galleries, repositories, and streaming
          5. E-commerce and payments
          6. Forms
          7. Calendars
          8. Integrators
          9. RSS readers
          10. Other categories
          11. Exploring technology—accessibility
            1. General good practice
            2. Use of JavaScript
            3. Validation
        3. Framework solution
          1. A simple blog application
            1. The database table for blog
            2. A blog data object
            3. Administering blog items—controller
            4. Administering blog items—viewer
            5. Showing blogs to visitors
            6. Menu building
        4. Summary
      22. A. Packaging Extensions
        1. The XML setup file
        2. Parameters
          1. Parameter types
      23. B. Packaging XML Example