Social Network, Part 4

For this addition to my social network, I wanted to take the opportunity to really learn something more that just how to write the network itself in PHP. One big thing in web programing is making things dynamic and loading stuff via JavaScript. I also was interested in XML. Since this addition was the inclusion of a new stream feature, I figured it was the perfect time to learn how to generate and use XML.

It turns out that PHP includes a way make XML, called SimpleXML. It’s actually quite simple to generate trees. For example, this would generate an xml file, with a node friend that has a child node userid with the value ‘123456.’

$xml = new SimpleXMLElement(‘<xml/>’);
$friend = $xml->addChild(‘friend’);
$friend->addChild(‘userid’, “123456”);

So I took this tool and used it to generate XML files of a user’s stream, a user’s info, and a user’s friend list. Then to make my profile simpler, I rewrote the thing using CSS and JavaScript to use a tabbed interface. Using display properties and ids, I selectively showed divs by pressing buttons that were made of table cells. It was really awesome to learn that you can turn table cells into buttons using javascript. I even made them change color on a mouse over. For each of the tabs, the content is loaded, parsed, and formatted into HTML via JavaScript then inserted into the page via innerHTML.

The big user facing feature is the dispatches feature. Dispatches are what I am calling statuses and wall posts. I built this feature from the ground up using XML. Beyond learning about XML, this feature helped me really understand MySQL subqueries, joins, and sorting keywords. The query is actually kind of interesting:

SELECT * from (SELECT * FROM messages where (userid = ‘$userid’ AND recipientid IS NULL) OR recipientid = ‘$userid’) as feed NATURAL JOIN userinfo as feedwithinfo ORDER BY timestamp DESC;

Changelog and Screenshots Below:

What’s new in version theBrotherhood 0.4 (Apr-23-2012):
*Dispatches. Now you can post dispatches for you and your friends to see. Your feed of dispatches is now on the homepage.
*Redesigned Profiles. Due to the addition of more features, User Profiles have been redesigned with a tab interface.
*JavaScript is now required for using the website
*Lots of the backend is now built on XML and is dynamically loaded in the background