... Newcastle.
He has been involved with a number of books, having written ve books: PHP 5
Social Networking, PHP 5 E-Commerce Development, Drupal 6 Social Networking,
Selling online with Drupal ...
www.twitter.com/michaelpeacock.
Download from Wow! eBook <www.wowebook.com>
PHP 5 Social Networking
Create a powerful and dynamic social networking
website in PHP by building a exible framework
Michael Peacock
BIRMINGHAM ... 14
Enhance knowledge 14
Provide a service 14
Improve business 15
Improve communication 15
Why use PHP? 16
When to use something else 16
Our site: DinoSpace 16
Feature list 18
Limitations 19
Summary...
... 28
The registry object 28
Registry objects 31
Front Controller: single point of access 56
index .php 56
.htaccess 58
Summary 59
Chapter 3: Users, Registration, and Authentication 61
Privacy policies ... on the hosting account 378
With cPanel hosting control panel 378
With appropriate privileges on phpMyAdmin 380
Exporting our local database 381
Importing our local database to the hosting account...
... PHP Social Networking
Welcome to PHP social networking! During the course of this book, we are going
to build a exible social networking site and framework using PHP, which we ... 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, ... 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...
... social
networking website.
Download from Wow! eBook <www.wowebook.com>
PHP Social Networking
[ 16 ]
Why use PHP?
PHP is a popular, open source programming language. Also, unlike some other ... of the original PHP engine.
This book assumes we have a reasonable understanding of PHP and some
knowledge of object-oriented programming, so another good reason for using
PHP is skill level.
When ...
external communication details are shown to you.
Download from Wow! eBook <www.wowebook.com>
PHP Social Networking
[ 12 ]
Existing social networking software
Just like there a number of fantastic...
... registry, and one
to store the core objects that we wish to access via the registry.
< ?php
/**
* PHP Social Networking
Download from Wow! eBook <www.wowebook.com>
Chapter 2
[ 29 ]
... this because with PHP 5
by default objects are passed by reference. This means if we pass an object to another
object, instead of getting a new copy of the object (as with PHP 4), a reference ... Chapter 2
[ 23 ]
Model
Within our framework, the models will be PHP classes that store, manage, and
process data and business logic. Access to the underlying database...
... $insert;
$this->executeQuery( $insert );
return true;
}
Sanitizing data
Depending on the exact PHP setup, data needs to be sanitized slightly differently,
to prevent characters being escaped ... get_magic_quotes_gpc() )
{
$value = stripslashes ( $value );
}
// Quote value
if ( version_compare( phpversion(), "4.3.0" ) == "-1" )
{
$value = $this->connections[$this->activeConnection]- ... $registry )
{
$this->registry = $registry;
include( FRAMEWORK_PATH . '/registry/page.class .php& apos;);
$this->page = new Page( $this->registry );
}
Since the views are made up of a...
... though there are methods
that can make taking data stored in an array and pushing it into the PHP variables
dened within the template.
Personally, I prefer to have the views not do any processing ... stored in
our page object, so let us see what we need in our page class (registry/page.
class .php
).
Firstly, we need some variables to store the replacement data, such as tags,
post-parse...
... template
$registry->getObject('template')->buildFromTemplates('header.tpl .php& apos;,
'main.tpl .php& apos;, 'footer.tpl .php& apos;);
$registry->getObject('template')->parseOutput();
print ... /index .php
DirectoryIndex index .php
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index .php? page=$1 ... us with a single point of access to the framework powering Dino Space.
index .php
Our front controller is our index .php le. The rst thing we should do is call
session_start, as this needs to...
... exposes the password in plain text more than required,
as it would be processed and accessed by both PHP and the MySQL server
(which may be stored on a remote machine):
$hash = md5( $password );
... from that.
This will make up part of our authentication object (
registry/authentication.
class .php
), which will reside in our registry and interact with the user object.
The
checkForAuthentication ... function sessionAuthenticate( $uid )
{
require_once(FRAMEWORK_PATH.'registry/user.class .php& apos;);
$this->user = new User( $this->registry, intval( $_SESSION['sn_
auth_session_uid']...
... 'userbar-guest.tpl .php& apos;);
$this->registry->getObject('template')-
>buildFromTemplates('header.tpl .php& apos;, 'login.tpl .php& apos;,
'footer.tpl .php& apos;);
... $this->subject, $this->message,
$this->headers) )
{
$this->error .= ' problems sending via PHP\ 's mail
function';
return false;
}
else
{
return true;
}
}
}
Download from ... template
for our view! Below is code for our views/default/templates/authenticate/
register/main.tpl .php file
. This code contains HTML elds for all of the elds
we have set in the registration controller...
... $this->registry->getObject('authenticate')->isLoggedIn() ==
true )
{
require_once( FRAMEWORK_PATH . 'models/relationships .php& apos;);
$relationships = new Relationships( $this->registry );
$types = $relationships->getTypes( ... $this->registry->getObject('template')->addTemplateBit(
'form_relationship', 'members/form_relationship.tpl .php& apos;);
$this->registry->getObject('template')->getPage()->addPPTag( ... template variable when the user
is logged in (views/default/templates/members/form_relationship.tpl .php) .
This has a template loop within it, into which the relationship types are inserted.
<form...
... $this->registry->getObject('template')->buildFromTemplates(
'header.tpl .php& apos;, 'friends/pending.tpl .php& apos;,
'footer.tpl .php& apos;);
$this->registry->getObject('template')->getPage() ... $this->registry->getObject('template')->buildFromTemplates(
'header.tpl .php& apos;, 'friends/mine.tpl .php& apos;, 'footer.tpl .php& apos;);
$this->registry->getObject('template')->getPage()->addTag( ... is through the prole
controller. The controller should act in a way similar to our main index .php le,
passing control to additional controllers such as a prole information controller,
or...