You are previewing PHP 5 Social Networking.
O'Reilly logo
PHP 5 Social Networking

Book Description

Create a powerful and dynamic Social Networking website in PHP by building a flexible framework

  • Build a flexible Social Networking framework using PHP which can be extended to fit the needs of any Social Networking site

  • Develop a suitable structure for our framework, with MVC to structure the architecture and a Registry to store core Objects

  • Allow users to connect and communicate with each other using communication with friends list, flexible user profiles, messages, discussions, and much more

  • Plan marketing and scaling strategies, to entice more users and ensure the site can cope with the demand

  • Packed with real-world code and clear explanation, this book uses an ongoing case study for creating a Social Networking framework

  • In Detail

    Social Networking has quickly become a very popular activity on the Internet, particularly with the emergence of sites like Facebook and MySpace. PHP is a flexible web development language used on a wide variety of sites, including Facebook and Yahoo! But building a social networking site from scratch using PHP involves some complex logic, and also some serious coding.

    This book will demonstrate how to create, maintain, and extend a powerful social network site. It shows how to create your own flexible social networking framework, allowing users to sign up, customize their profile, befriend other users, share information, communicate, interact with one another, and much more.

    Taking best practices, such as object-oriented programming, and the Model-View-Controller architecture, this book will begin by walking through the development of a simple development framework, which is then used to rapidly build a Social Networking platform, building upon the social features chapter by chapter. At the end of this book, you will have a powerful Social Networking platform loaded with many features which can take the user from signing up and connecting with other users to posting and sharing information. With an API in place, the platform can be extended and used by other Social Networks. This book doesn’t just stop with the code and the logic behind it; useful supplementary information is also covered, such as marketing the Social Network, keeping Search Engine Optimization in mind when developing, backing up and maintaining the site, and how to deal with large amounts of traffic through scaling.

    By the end of this book, you will be left fully prepared to build, manage, maintain, and extend a powerful Social Network for your business, hobby, organization, family, and clients.

    A fast-paced guide to creating a flexible Social Networking website using PHP with a custom, light weight MVC framework.

    Table of Contents

    1. PHP 5 Social Networking
      1. PHP 5 Social Networking
      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. PHP Social Networking
        1. Introduction to social networks
          1. Business logic to social networks
            1. Examples: Businesses making use of existing social networks and their own social networks
              1. NameCheap: Twitter
              2. Dell: Twitter
              3. BT: Twitter
              4. Netgear: custom
        2. Existing social networks
          1. Facebook
          2. LinkedIn
          3. MySpace
          4. Twitter
        3. Existing social networking software
          1. Drupal
          2. Elgg
          3. Joomla!
          4. Hybrid approaches
        4. Rolling your own
          1. Why roll your own?
            1. Easier to update and maintain
            2. Licensing
            3. Enhance knowledge
            4. Provide a service
            5. Improve business
            6. Improve communication
          2. Why use PHP?
          3. When to use something else
        5. Our site: DinoSpace
        6. Feature list
          1. Limitations
        7. Summary
      8. 2. Planning and Developing the Core Framework
        1. Designing the framework
          1. Patterns—making life easier
            1. MVC: Model-View-Controller
              1. Model
              2. View
              3. Controller
            2. The Front Controller pattern
            3. Registry
              1. Factory within our registry
              2. A note on the Singleton pattern
              3. Registry + MVC
            4. Folder structure
        2. Building the framework
          1. Registry
            1. The registry object
            2. Registry objects
              1. Database
                1. Connecting to the database and managing connections
                2. Executing queries
                3. Simplifying common queries
                4. Sanitizing data
                5. Wrapping other MySQLi functions
                6. Disconnecting
              2. Template management
                1. Page
              3. Authentication
              4. URL processing
              5. Extending the registry: potential new objects
          2. Front Controller: single point of access
            1. index.php
            2. .htaccess
        3. Summary
      9. 3. Users, Registration, and Authentication
        1. Privacy policies
        2. Users
          1. Our user object
          2. Our authentication registry object
            1. POST authentication
            2. SESSION authentication
          3. Structuring the database
        3. Registration
          1. Standard details
          2. Hooking additional fields on
          3. Processing the registration
            1. Creating the profile
            2. Putting it all together: registration constructor
          4. CAPTCHA
            1. General CAPTCHA
            2. reCAPTCHA
          5. Where do I sign up?
          6. E-mail verification
            1. Sending e-mails
              1. Room for improvement
            2. Sending the e-mail verification e-mail
        4. Authentication with our authentication object
          1. Logging in
          2. Are we logged in?
          3. Logging out
          4. Remember me
        5. Help! I've forgotten!
          1. Username
          2. Password
            1. Let them reset the password
        6. Summary
      10. 4. Friends and Relationships
        1. Inviting friends
          1. Manually inviting friends
            1. Invitation controller
          2. Automatically inviting friends
            1. Google Friend Connect
            2. Windows Live contacts
            3. Yahoo!
            4. Gmail contacts
          3. Automatically connecting with friends
        2. Members
          1. Listing users
            1. Pagination
            2. Paginated members
            3. Paginated users by letter
          2. Searching for users
        3. Custom relationships
          1. Relationship types
          2. Relationships
        4. Adding friends
          1. Forming a relationship
            1. Relationship model
            2. Relationship controller
          2. Mutual relationships—accepting or rejecting a request
            1. Pending requests
              1. New model method
              2. New controller method
              3. The result
            2. Accepting a pending request
            3. Rejecting a pending request
        5. Listing friends
          1. Our friends
          2. Their friends
            1. Mutual friends
        6. Friends in your profile
        7. Summary
      11. 5. Profiles and Statuses
        1. User profiles
          1. Extendable profile
          2. Profile controller
            1. Core shared information
              1. Name, ID, and photograph
                1. Profile model
              2. Sample of friends
              3. Pulling the core shared information together
          3. Static profile
            1. Viewing the profile
              1. Profile link
              2. Controller
              3. Template
              4. In action
            2. Relationships—some improvements
              1. All contacts
                1. Template
                2. In action
            3. Editing the profile
              1. Controller additions
                1. Uploading a photograph—an image handler
                2. Back to the controller
              2. Template
                1. The template file
                2. Datepicker
              3. In action
        2. Statuses
          1. Statuses database table
            1. Statuses types database table
            2. Different types of status
          2. Template improvements
          3. Listing statuses
            1. Templates
            2. In action
          4. Likes, dislikes, and comments
            1. Comments
              1. Template
              2. Code
              3. In action
              4. Try it yourself
        3. Summary
      12. 6. Status Stream
        1. What is a status stream?
        2. Stream model
          1. Building the stream
          2. Relationships—get the IDs!
          3. Friendly times
          4. The rest…
        3. Stream controller
          1. Generating the stream
          2. Comments, likes, and dislikes
            1. Comments
            2. Likes and dislikes
        4. Views
          1. Main template
          2. Status type templates
        5. In action
        6. Room for improvement
        7. A system stream for administrators
        8. Summary
      13. 7. Public and Private Messages
        1. Public messages
          1. Controller
            1. Displaying profile messages
            2. Displaying the post message box
              1. Process a new message
                1. Status model
              2. Controller additions
          2. Displaying a confirmation message
          3. View
          4. In action
        2. Private messages
          1. Database
          2. Message model
          3. Messages model
          4. Controllers and views
            1. Listing messages
              1. Inbox
            2. Reading a message
              1. View message template
              2. Mark as read
            3. Deleting a message
            4. Composing a new message
            5. Creating a message template
          5. In action
          6. Room for improvement?
            1. Sent items
            2. Replies
            3. Group messages
        3. Summary
      14. 8. Statuses—Other Media
        1. Why support other media types?
        2. Changes to the view
          1. Template
            1. jQuery to enhance the user experience
          2. View in action
        3. Images
          1. Database table
          2. Model
            1. Class, variable, and constructor
            2. Processing the image upload
              1. Using the image manager library to process the file upload
            3. Saving the status
        4. Video (via YouTube)
          1. Database
          2. Model
        5. Links
          1. Database
          2. Model
        6. Extending the profiles
          1. Processing the new status posts
          2. Altering our profile status' query
          3. Status views
            1. Images
            2. Video
            3. Links
          4. In action
            1. Images
            2. Videos
            3. Links
          5. Repeat!
        7. Summary
      15. 9. Events and Birthdays
        1. Let's plan
          1. Calendars: what do we need to be able to do?
        2. Calendar library
          1. Generating the month
          2. Days in the month
          3. Ordered days
          4. Previous month
          5. Next month
        3. Displaying a calendar
          1. Generate and output
          2. Multiple calendars
          3. With events
        4. Birthdays
          1. Getting relationship IDs
          2. Setting up the calendar
          3. Getting the birthdays
          4. Passing them to the calendar
          5. The results
        5. Events
          1. Event model
          2. Events model
          3. Attendees, invitations, and RSVPs
            1. RSVPs
          4. Controller
            1. Creating an event
              1. Template for a new event
            2. Calendar of events
            3. Viewing an event
              1. Event template
              2. Viewing an event in action
            4. Upcoming events
        6. Reminders
          1. On-site notifications
          2. E-mail notifications
          3. SMS notifications
        7. Summary
      16. 10. Groups
        1. Some planning
          1. Group information
          2. Types of groups
          3. Ownership
          4. Membership
          5. Features
        2. A group
          1. Discussion
            1. Database
              1. Topics
              2. Posts
            2. Post
              1. Model
            3. Topic
              1. Model
          2. The group itself
            1. Group table
            2. Model
          3. Creating a group
            1. Controller
            2. View
            3. Creating a group—in action
          4. Viewing a group
            1. Membership
              1. Membership model
            2. Controller
            3. View
            4. In action
          5. Discussing within a group
            1. Group controller additions
              1. Creating a topic
              2. Viewing a topic
              3. Replying to a topic
            2. View
              1. Creating a topic
              2. Viewing a topic
            3. Discussion in action—viewing a topic
          6. Joining a group
            1. Joining (public) groups
        3. Groups
          1. Listing groups
            1. Group controller addition
            2. Template
            3. In action
          2. My groups
            1. Addition to the group's controller
            2. Template file
            3. In action
        4. Summary
      17. 11. Developing an API
        1. What is an API and why should we create one?
        2. APIs in social networks
          1. Facebook
          2. MySpace
          3. OpenSocial
        3. Some planning
          1. What should it do, and who should be able to do what?
          2. How should it work?
            1. How could it work?
              1. REST
              2. RPC / RMI
              3. SOAP
            2. Let's go with REST
              1. Requests
                1. HTTP verbs
                2. Resources
                3. Resources and verbs—the requests
              2. Responses
            3. Further reading
              1. RESTful PHP Web Services
              2. Conference talks
        4. Implementation
          1. Data format
          2. API controller
            1. Wait—no models?
            2. Authentication
              1. Sessions lead to unREST!
                1. Amending the authenticate registry object
                2. Amending index.php
          3. Delegating control: API controllers for our features
            1. Profile's delegate
              1. Tweaking the profiles model: validity and data
                1. Revised controller
                2. New getter: isValid()
                3. New getter: toArray()
        5. An Application Framework API
          1. One solution: use OpenSocial
        6. Consuming
          1. POSTing data to our API with cURL
        7. Summary
      18. 12. Deployment, Security, and Maintenance
        1. Deploying the site
          1. Choosing a domain name
          2. Registering a domain name
            1. Popular domain name registrars
          3. Signing up with a hosting provider
            1. Choosing a web hosting provider
            2. Considerations for hosts of social networking websites
            3. Popular web hosting providers
          4. Setting the nameservers for the domain
          5. Creating a database on the hosting account
            1. With cPanel hosting control panel
            2. With appropriate privileges on phpMyAdmin
          6. Exporting our local database
          7. Importing our local database to the hosting account
          8. Changing some of our database records
          9. Changing our database configuration options
          10. Uploading the files
          11. Testing
        2. Automating deployment
        3. Security
          1. Server Security
            1. Software
            2. Securing the site with a firewall
            3. Shared hosting precautions
          2. Passwords
          3. Error reporting
          4. Directory listings
          5. SPAM
        4. Maintenance
          1. Backing up and restoring your social network
            1. With cPanel
              1. Restoring the site and database
            2. Using the command line
              1. Command Line Access and PuTTY
              2. Backing up the site and database
              3. Restoring the site and the database
            3. Do they work?
          2. Access logs and statistics
        5. Summary
      19. 13. Marketing, SEO, User Retention, and Monetization Strategies
        1. Marketing
          1. Online advertising
            1. Pay-Per-Click
              1. Search engine PPC networks
              2. Pay Per Action—a look to the future
            2. Advertising space
              1. Warning: keep the search engines happy!
                1. Getting penalized by the search engines
                2. Keeping them happy
            3. Newsletter advertising
          2. Newsletters
          3. Social marketing
            1. Viral marketing campaigns
            2. Twitter
            3. RSS feeds
        2. Search engine optimization
          1. On-site SEO
            1. Headings
            2. Links
            3. Up to date, relevant content
            4. Page metadata
            5. Site speed
            6. Search engine goodies—sitemaps and tools
          2. Off-site SEO
          3. What to look for in an SEO company
        3. User retention
          1. E-mails for the user's action
          2. User feedback
          3. Hello there!
        4. Monetization options
        5. Final tips: web stats
        6. Summary
      20. 14. Planning for Growth
        1. Code performance
          1. Code profiling
          2. Slow queries
          3. Compression
          4. Useful tools and resources
        2. Server performance
          1. Apache
          2. MySQL
          3. Alternative web servers
        3. Scaling
          1. VPS Cloud Hosting
          2. Additional servers
        4. Caching systems
          1. Memcached
          2. Available caching systems
        5. Redundancy
        6. Content Delivery Networks
        7. Message queues
          1. Message queue versus database table
          2. What can we queue?
          3. Processing queued tasks
        8. No SQL
        9. Learn from the experts
        10. Farm it out
        11. Summary