Showing posts with label START. Show all posts
Showing posts with label START. Show all posts

Friday, 3 July 2009

Some START progress

Well it seems I've finished the majority of the back end work for this project, successfully integrating Twitter, Picassa and Blogger into one page using, PHP & XML... Which I'm quite happy with seeing as prior to this project I've not coded anything in php! As part of me trying to maintain the whole creative commons thing and trying to share and share alike thingy here's the code I've used:

Blogness.php - Grabs the xml from the rss feed and displays all posts:
Adapted from: http://www.hiash.com/blogger.php

<?php
define('MAGPIE_DIR', '../../magpierss/');
require_once(MAGPIE_DIR.'rss_fetch.inc');

//RSS feed has to be of ATOM format
$rss = fetch_rss( 'http://www.blogger.com/feeds/8911594570691911602/posts/default' );

//display latest blog content:
foreach ($rss->items as $item) {
$title = $item['title'];
$content = $item['atom_content'];
echo "<h1>$title</h1><p>$content</p>";
}
?>


Twitterness.php - grabs the rss from your public twitter feed and displays the last 5 posts...
Adapted from http://workbench.cadenhead.org/twitter-rss-to-html/


<?php

define('MAGPIE_DIR', '../../magpierss/');
require_once(MAGPIE_DIR.'rss_fetch.inc');

$tweets_to_display = 5;
// the page where the tweet(s) will be displayed
$page = "";
// the user's Twitter username
$username = "StartPlymouth";


$rss = fetch_rss( 'http://twitter.com/statuses/user_timeline/49595711.rss' );

// start buffering output
ob_start();

$count = 1;
$now = time();


foreach ($rss->items as $item) {
// limit the number of tweets displayed
if ($tweets_to_display > 0) {
if ($count > $tweets_to_display) {
continue;
}
}
$tweet = $item['description'];
// ignore tweets linking back to page (if it is defined)
if ($page != "") {
if (!strpos($tweet, $page) === false) {
continue;
}
}
// figure out how recently the tweet was posted
$when = ($now - strtotime($item['pubdate']));
$posted = "";
if ($when < 60) {
$posted = $when . " seconds ago";
}
if (($posted == "") & ($when < 3600)) {
$posted = "about " . (floor($when / 60)) . " minutes ago";
}
if (($posted == "") & ($when < 7200)) {
$posted = "about 1 hour ago";
}
if (($posted == "") & ($when < 86400)) {
$posted = "about " . (floor($when / 3600)) . " hours ago";
}
if (($posted == "") & ($when < 172800)) {
$posted = "about 1 day ago";
}
if ($posted == "") {
$posted = (floor($when / 86400)) . " days ago";
}
// filter the user's username out of tweets
$tweet = str_replace($username . ": ", "", $tweet);
// turn URLs into hyperlinks
$tweet = preg_replace("/(http:\/\/)(.*?)\/([\w\.\/\&\=\?\-\,\:\;\#\_\~\%\+]*)/", "<a href=\"\\0\">Link</a>", $tweet);
// link to users in replies
$tweet = preg_replace("(@([a-zA-Z0-9\_]+))", "<a href=\"http://www.twitter.com/\\1\">\\0</a>", $tweet);
echo '<p class="Tweets"> <strong>'.$username.':</strong> '.$tweet.'</p><p class="TweetInfo">'.$posted.'</p>';
$count++;

}

// display output
ob_end_flush();
?>

Picassaness.php - This one is the most complex but doesn't require Magpierss which is cool, does the same grabs public xml, I've got it to store all the images in an array and select a random 5 and display them. (to change on each refresh):
(I adapted from - http://code.lawpower.net/2008/01/21/picasa-gallery-googles-cruel-rss-feed/)

<?php
$DisplayNumberofPhotos = 5;

function AddXMLtoItems($xmlurl){
//get the xml from the feed provided in $xmlurl
$session = curl_init($xmlurl);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($session);
curl_close($session);
$xml = simplexml_load_string($response);
$items = $xml->channel;

//now we have each item from the XML file into $items we now need to split them up so their more useful to us
foreach($items->item as $item){
$title = $item->title;
$content = $item->description;

//pull the images from the *descripotion* section
$quotes = array('"', "'", "\n");
$imgContents = str_replace($quotes, '', $content); #Strip " and ' as well as \n from input string
$imgContents = stristr($imgContents, 'src='); #Drop everything before the 'src'
$endTagPosition = stripos($imgContents, 'alt'); #Position of the end tag '>'
$img = substr($imgContents, 4, $endTagPosition - 4); #Get everything from src to end tag --> 'src="path" something>'

//Change the dimentions of the images, Picasa sets images sizes at specific sizes within the url
$ImageURL = str_replace('/s288', '/s220', $img);
$ImageURLs[] = $ImageURL;
}
return $ImageURLs;
}

//Grab the images from the array and merge them all into one big array...
$ImageURLs = AddXMLtoItems("http://picasaweb.google.com/data/feed/base/user/StartPlymouth/albumid/5354140273775432289?alt=rss&kind=photo&authkey=Gv1sRgCOGggY2Y8baMLw&hl=en_US");
//$ImageURLs2 = AddXMLtoItems("");
//$ImageURLs3 = AddXMLtoItems("");
//$ImageURLs4 = AddXMLtoItems("");
//$ImageURLs = array_merge((array)$ImageURLs1, (array)$ImageURLs2, (array)$ImageURLs3, (array)$ImageURLs4);

//Now we need to grab random images from this array to be displayed on the home page
for ( $counter = 0; $counter <= ($DisplayNumberofPhotos - 1); $counter += 1) {
//get ImageToDisplay to be a exact image number
$ImageToDisplay = sizeof($ImageURLs);
$ImageToDisplay = rand(0, $ImageToDisplay);
$ImageToDisplay = round($ImageToDisplay);
$ArrayofImagesBeenDisplayed[] = $ImageToDisplay;
}
//add image displayed to an array to ensure we don't get duplications
$ArrayofImagesBeenDisplayed = array_unique($ArrayofImagesBeenDisplayed);

//Display these random images and link them to a larger image
for ($counter2 = 0; $counter2 < sizeof($ArrayofImagesBeenDisplayed); $counter2 += 1) {
$ImageDisplayURL = $ImageURLs[$ArrayofImagesBeenDisplayed[$counter2]];
$ImageLinkURL = str_replace('/s220', '/s1024', $ImageURLs[$ArrayofImagesBeenDisplayed[$counter2]]);
echo "<a href='" . $ImageLinkURL . "'><img src='" . $ImageDisplayURL . "' /></a>";
}
?>


Obviously I'm no coder and I'm sure this will make some of you spit your coffee out at your computer screen, but I'm sure some of you will find it useful! Any feedback would be good. I've made these seporate files to be called into the main page by using Include('file.php'); so should hopefully work with you, for the picassa one you have to declare how many images you want displayed: $DisplayNumberofPhotos = 5; include('Picassaness.php') In the picassa one I would quite like it to find all rss feeds related to that piccassa user rather than having to list each individual album manually so if anyone knows how to do that, that would be great. Otherwise shall try and work it out myself and post it here.

Friday, 26 June 2009

START - Progress and Windows 7!

As you can hopefully see I've progressed with the sites design, some what and am rather happy with how it looks:

My next major task is to arrogate all the random feeds I've suggested Start to sign up to, i.e. Twitter, Blogspot and Picasssa. I initially aimed to use Twitter and Googles API to do this but was just running into constant problems. Which was a shame but being a slight novise to PHP I couldn't afford to waste to much time.

What I did manage to do was use MagpieRSS which with some coding grabs Twitters and Blogspots RSS feeds and displaying them in your PHP. Magic! Some of the usefull links I've been using:

http://workbench.cadenhead.org/twitter-rss-to-html/
http://www.hiash.com/blogger.php
http://magpierss.sourceforge.net/

Due to the none pleasant working conditions of Center Court when its warm weather, lack of air flow and bad sewage smells, and thanks to the lame guttering I've chosen to work from home for a couple days. Which has been far more productive than in the office this is down to a few key points:

  • Windows 7 - Microsoft really have got it going on here kicking dust in OSX's eyes due to a number of reasons, mostly their Task bar (admittedly they've just copied Linux and OSx here but if it works why complain!), I also like their snap windows to edges system which I've been using heavily on this project.
  • 1000watt sound system, keeps me going
  • 27inch screen also helps!

Wednesday, 27 May 2009

START - Website

I've been given this delightful project via Avril Butler, START stands for Students and Refugees Together, their a charity started by Avril which works with many Social Work students (hence my involvement) .

After my first meeting with them it's become apparent that this is going to be a fun project. Particularly that I'm not to restrained with technologies i.e. not tied down to SharePoint (not that there's anything wrong with SharePoint). But it does mean I get to do some coding etc. The Aim's of this project are to freshen up their current website:



And make it more Web2.0 well intially they indicated they wanted it to look nice and have areas to update. I felt that having some structured formal areas i.e. about us, history etc which arn't going to change to keep them straight html i.e. I'll make them and they'll stay that way but have image galleries, and blogs which are driven by themselves.

Which this is where the exciting bits come in, the photo galleries, shall be driven by flikr, and the blogs by blogger and obviously have a twitter feed etc. It should be a true mash up!

Annoyingly they currently have some lame hosting with Mr Site, which is shocking and very restricting so I'm hopeing we can change this or use their own servers. So whilst I wait for this to be finalised I've been researching how to import all these 2.0 technologies into one page:

Twitter was quite easy.
Blogger is a little bit more complicated and requires me to use something called MagpieRss, which essentially embeds the RSS feeds from your blog into a html page.
Picassa (googles version of Flickr), requires you to install Googles API to access full functionality, however it does enable it to be hugely flexible and will hopefully result in seamless transitions between site and Picassa.

The majority of the software and technologies I'm going to be using on this project will be based around OpenSource or Free Software, and I'm hoping to maintain Creative Commons throughout this project which fits with my own views and hopefully suits the fact that I'm working with a Charity.