Book Image

PHP 5 Social Networking

By :
Book Image

PHP 5 Social Networking

By:

Overview of this book

<p>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.</p> <p>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.</p> <p>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.</p> <p>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.</p>
Table of Contents (21 chapters)
PHP 5 Social Networking
Credits
About the Author
Acknowledgement
About the Reviewers
Preface
Index

Preface

Social networking has quickly become a very popular activity on the Internet, particularly with sites such as Facebook and MySpace. When it comes to creating social networks there are many options to chose from, including off-the-shelf systems, making use of existing social networks (for example, building a Facebook application or creating a Facebook page), or building something yourself. While it may be easy to find existing solutions, the only way to have one looking and behaving exactly as you want is to build it yourself.

By initially developing a light-weight Model-View-Controller-style framework with PHP, which can easily be extended to give us a stable and solid platform to work with making common tasks easier and giving us a structure for our social networking code, we can rapidly develop a custom, powerful social networking website.

Within the first few chapters, you will have a suite of files that deal with template management, database management, user authentication management, and e-mail sending. Once this is in place, social networking-centric features can be rapidly developed and plugged into the framework, including user registration and dealing with forgotten details, user profiles, building connections with users, sending messages, sharing information, forming groups, a Developer API, and events and birthday calendars.

At the end of this book, you will have a powerful social networking platform that can take the user all the way from the signup process to forming relationships and creating groups of users. The platform is developed in a very flexible way, so the needs of any social networking site can be met, with new features easily and quickly added in as the needs of the site change.

This book doesn't just stop with how to develop a social networking platform; there are many other topics, which any developer should consider such as marketing, search engine optimization, backing up and restoring the site, and how to deal with scaling problems when the site gets popular. All of these topics are discussed too, leaving you not only with a solid social network, but with hints, tips, and advice on how to maintain it in the long term and deal with any challenges on the way.

What this book covers

Chapter 1, PHP Social Networking, looks into the growing popularity of social networking, including popular social networks, different ways to create or utilize social networks, and discusses what we will be creating throughout the course of the book.

Chapter 2, Planning and Developing the Core Framework, discusses several architectural and design patterns, including Model-View-Controller, Registry and Factory, the planning and subsequent development of our skeleton MVC-style framework with template, database, and e-mail management.

Chapter 3, Users, Registration, and Authentication, extends our development framework with user authentication classes, and then walks through development of registration and login features for users, as well as reminders for forgotten details.

Chapter 4, Friends and Relationships, looks at allowing users to connect with one another, either by adding them as friends or establishing custom relationships with one another such as a co-worker or family member.

Chapter 5, Profiles and Statuses, walks through the development of profiles for our users as well as a flexible status system so users can update their friends and contacts with what they are doing.

Chapter 6, Status Stream, discusses how to collate user statuses and activities to show a useful stream of status updates for a user's particular network, as well as for administrators to see how the network is growing.

Chapter 7, Public and Private Messages, enables users to communicate with one another by implementing a simple message system.

Chapter 8, Statuses—Other Media, allows users to share media such as images and videos with other users in their network as status updates and profile posts.

Chapter 9, Events and Birthdays, integrates a calendar to manage and display events created by our users and birthday notifications.

Chapter 10, Groups, allows users to create and maintain groups related to specific topics with their own lists of members, who opt in to be part of the group.

Chapter 11, Developing an API, discusses the development of an API to allow third-party websites and developers to interact with the social network, so that it can gain popularity through other applications too.

Chapter 12, Deployment, Security, and Maintenance, looks at steps to make the framework more secure and protect it from spam, as well as looking at how to back up the site and restoring it from a backup.

Chapter 13, Marketing, SEO, User Retention, and Monetization Strategies, advises on how to market and promote the social network, and gives useful tips to help develop search engine-friendly websites.

Chapter 14, Planning for Growth, goes through a number of potential issues that will occur when the social network becomes more popular, and advises on scalability, deployment and hosting options, caching, and content delivery networks.

What you need for this book

During the course of this book, you will need the following software to try out the various code examples:

  • Apache 1.3 or above (2 recommended)

  • mod_rewrite module for Apache

  • MySQL 5.0 or above

  • PHP 5.0 or above (5.2 or above recommended)

When working locally on your own computer, a package such as WampServer 2 for Windows is recommended, as this will install PHP, Apache, and MySQL in one, and make enabling extensions easy.

A text editor is all that is required for editing the code. However, one with syntax highlighting would be beneficial (such as Crimson Editor or Notepad++).

For deployment, an FTP application such as FileZilla will be required, and an SSH client such as PuTTY for some of the backup and restoration options would be useful.

Who this book is for

This book is primarily aimed at PHP developers, but is suitable for any web developer looking to expand their knowledge and understanding of social networking concepts. Intermediate knowledge of PHP and object-oriented programming is assumed, along with a basic knowledge of MySQL.

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 their meaning.

Code words in text are shown as follows: "The delegateControl method checks that the delegate controller is within the allowed delegates."

A block of code is set as follows:

/**
 * Is the profile valid
 * @return bool
 */
 public function isValid()
 {
   return $this->valid;
 }

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

<form action="relationship/create/{ID}" method="post">
<select name="relationship_type">
<!-- START relationship_types -->
<option value="{type_id}">{type_name}</option>
<!-- END relationship_types -->
</select>
<input type="submit" name="create" value="Connect with {name}" />
</form>

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: "Now if we click on the Connect with button on the relationship form, our relationship is created and we are shown a confirmation message".

Note

Warnings or important notes appear in a box like this.

Tip

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 , and mention the book title via the subject of your message.

If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or e-mail .

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.

Tip

Downloading the example code for this book

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/support, 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 on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

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 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 if you are having a problem with any aspect of the book, and we will do our best to address it.