PHPUK 2011 Talk: Beyond Frameworks

Posted by Stuart Herbert on February 25th, 2011 in Conferences.

I’ve just finished giving my talk at this year’s excellent PHP UK 2011 conference, on how to use code frameworks like Zend Framework and Symfony without them holding your code hostage. Here are my slides from the talk:

This talk is a follow up to my successful PHPUK 2009 about what it can be like to live with frameworks when you do product development. Looking back on that talk now, it’s interesting to see how some of the themes from two years ago have changed as the business enjoyed two straight years of record growth.

If you were at the conference, and attended the talk, I’d love to read comments about how I did on joind.in.

Be the first to leave a comment »

I post photos to Flickr from time to time, and then write blog articles about the photos. The blog articles get written days, weeks, sometimes months in advance of when they’re scheduled to appear on my blog … which makes it a tad difficult to add a link from a photo to all of the blog articles that mention it.

So a couple of weekends ago I knocked up a very crude script that uses the Flickr API (via phpFlickr) to work through all of the published blog posts and make sure each of my Flickr photos has links back to each blog post that mention it. I’m posting it here in the public domain. Hopefully someone will find it a useful starting point to do something similar for their own blog.

[code lang=”php”]

<?php

require_once('phpflickr-3.0/phpFlickr.php');

$flickrApiKey = '’;
$flickrSecret = ”;
$flickrToken = ”;

$f = new phpFlickr($flickrApiKey, $flickrSecret);
$f->setToken($flickrToken);
$f->enableCache(‘fs’, ‘/tmp’, 3600);

// first step – find the first published blog post
$url = ‘http://blog.stuartherbert.com/photography/’;
$rawHtml = file_get_contents($url);
preg_match(‘/

/’, $rawHtml, $matches);

$blogPosts = array();
$flickrPhotos = array();

$latestPost = $matches[1];
$nextPost = $url . ‘?p=’ . $latestPost;

function updatePhotos($photoIndex, $flickrPhotos, $blogPosts, $f)
{
foreach ($photoIndex as $photoId => $flickrPhoto)
{
// we must rewrite the description
preg_match(‘|(.*)Copyright |s’, $flickrPhoto[‘description’], $matches);
if (isset($matches[1]))
{
$description = $matches[1];
}
else
{
$description = ”;
}
$description .= ‘Copyright (c) Stuart Herbert. Blog | Twitter | Facebook‘ . “n”
. ‘Photography: Merthyr Road | Daily Desktop Wallpaper | 25×9 | Twitter.’ . “nn”;

if (count($flickrPhoto[‘blogPosts’]) == 1)
{
$description .= ‘Want to know more about this photo? See this blog entry:’ . “nn”;
}
else
{
$description .= “Want to know more about this photo? See these blog entries:nn”;
}

foreach ($flickrPhoto[‘blogPosts’] as $postUrl => $blogPost)
{
$description .= ‘* ‘ . $blogPost[‘title’] . “n”;
}

// description is made … now to upload it
echo “Photo: ” . $photoId . ‘ :: ‘ . $flickrPhoto[‘title’] . “n”;
echo “URL : ” . $flickrPhoto[‘url’] . “n”;
echo “Old : ” . $flickrPhoto[‘description’] . “n”;
echo “New : ” . $description . “n”;

echo “nPushing changes to Flickr …”;
$f->photos_setMeta($photoId, $flickrPhoto[‘title’], $description);
echo ” donen”;
}
}

while ($nextPost !== null)
{
$photoIndex = array();

echo “Downloading $nextPost …”;
$rawHtml = file_get_contents($nextPost);
echo ” donen”;
if (!$rawHtml)
{
die(“Unable to download HTML for URL: ” . $nextPost . “n”);
}

preg_match(‘|

.*(.*)|Us’, $rawHtml, $matches);
$postUrl = $matches[2];
$title = $matches[3];
echo “Blog post title is: $titlen”;
echo “Blog post url is: $postUrln”;

preg_match(‘||’, $rawHtml, $matches);
if (isset($matches[1]))
{
$nextPost = $matches[1];
}
else
{
$nextPost = null;
}

preg_match(‘|

(.*)

|Us’, $rawHtml, $matches);
if (!isset($matches[1]))
die(“regex failed againn”);
$entryHtml = $matches[1];

preg_match_all(‘|(http://www.flickr.com/photos/stuartherbert/[0-9]+/)”|’, $entryHtml, $matches);
$blogPosts[$postUrl][‘url’] = $postUrl;
$blogPosts[$postUrl][‘title’] = $title;
$blogPosts[$postUrl][‘matches’] = $matches;

foreach ($matches[1] as $flickrPhoto)
{
$parts = explode(‘/’, $flickrPhoto);
$photoId = $parts[count($parts)-2];
$photoInfo = $f->photos_getInfo($photoId);

$flickrPhotos[$photoId][‘url’] = $flickrPhoto;
$flickrPhotos[$photoId][‘title’] = $photoInfo[‘title’];
$flickrPhotos[$photoId][‘description’] = $photoInfo[‘description’];
$flickrPhotos[$photoId][‘blogPosts’][$postUrl] = $blogPosts[$postUrl];

// note the photos we need to update because we have
// seen this post
$photoIndex[$photoId] = $flickrPhotos[$photoId];

echo “- Photo: ” . $photoInfo[“title”] . “n”;
}

updatePhotos($photoIndex, $flickrPhotos, $blogPosts, $f);
}

echo “nn”;
echo “Photo scraping complete!!nn”;

// when we get to here, we have photos to go and update on flickr
?>
[/code]

1 comment »

February’s meeting of the PHP SouthWest User Group will be at The Golden Guinea in Redcliffe, Bristol, from 7pm on Wednesday 9th February.

What Is Planned

I’m speaking at the PHP UK conference later in February, and will be practising my talk. No guarantees, but I think Rob Allen might be practicing his talk too.

How To Get There

We’ll be at The Golden Guinea, 19 Guinea Street, Bristol BS1 6SX. It’s a short walk from Bristol Temple Meads Railway Station if you’re coming by train.

How To Get Involved

Please join the PHPSW Google Group and say hello!

Be the first to leave a comment »