topical media & game development
mashup-delicious-07-delicious-summary2-index.php / php
<?php
//define the delicious account information we need
define('DELICIOUS_USERNAME','username');
define('DELICIOUS_PASSWORD','password');
//mysql database information
define('MYSQL_HOST','localhost');
define('MYSQL_DATABASE','delicious_summary2');
define('MYSQL_USERNAME','delicious_sql');
define('MYSQL_PASSWORD','password');
//bring in Snoopy goodness
include('lib/Snoopy.class.php');
//get rid of error Notices because Snoopy produces some
error_reporting(E_ERROR | E_WARNING | E_PARSE);
//also bring in the del.icio.us Mashups PHP library we made
include('lib/delicious_mashups.inc.php');
//bring in Sajax goodness
require("lib/Sajax.php");
//create the MySQL Database Connection
linkroll_data
linkroll_cache_query = "select count(*) from linkroll where time_retrieved > date_sub(now(), interval 1 hour)";
linkroll_cache_query);
//if a count was returned, we should use cache and NOT make an api call
if (mysql_result(linkroll_data = get_last_cached_data('linkroll');
} else {
//no cache so time to update our cache with a new data fetched from the api
do_api_call('/posts/recent?','count=20');
//if status is 200 then create the cache and use
//otherwise, fetch the cache data instead.
if (api_return['status'] == 200)
{
api_return))
);
mysql_query(linkroll_data = linkroll_data = get_last_cached_data('linkroll');
}
}
//next let’s fill
//using the API
tagroll_data = array();
//start by seeing if the first (and only) row in the tagroll table has a
// time_retrieved that is in the last hour
tagroll_cache_result = mysql_query(tagroll_cache_result,0) >= 1) {
//use the tagroll cache
api_return for our data.
//otherwise, fetch the cache data instead.
if (add_cache_query = sprintf(
"insert into tagroll (time_retrieved,serialized_data_array) values
(now(),'\%s')",
mysql_real_escape_string(serialize(add_cache_query) or die(mysql_error());
api_return;
} else {
//otherwise, force using the cache
tag) {
global tag
tag_linkroll_cache_query = "select * from tag_linkroll where time_retrieved > date_sub(now(), interval 1 hour) and tag='".mysql_real_escape_string(tag_linkroll_cache_result = mysql_query(tag_linkroll_cache_result) >= 1) {
//use the tag linkroll cache
tag);
} else {
//no cache so time to update our cache with a new data fetched from the api
do_api_call('/posts/recent?',"count=20&tag=".api_return for our data.
//otherwise, fetch the cache data instead.
if (add_cache_query = sprintf(
"insert into tag_linkroll
(time_retrieved,serialized_data_array,tag)
values (now(),'\%s','\%s')",
mysql_real_escape_string(serialize(tag)
);
mysql_query(tag_linkroll_data = tag_linkroll_data = get_last_cached_data('tag_linkroll',posts = html = "<em>selected tag: html .= "<ul>";
foreach (post)
{
post['attributes']['HREF']."\">".
post['attributes']['EXTENDED']))
post['attributes']['EXTENDED']."</p>";
}
html;
}
//this shared function fetches the last cached data for a given table
function get_last_cached_data(tag = '')
{
//grab the newest cached item from
if (tag != '') {
table where tag = '".mysql_real_escape_string(query = "select serialized_data_array from result = mysql_query(row = mysql_fetch_row(row[0]);
}
//initalize sajax and export the get_tag_linkroll function
sajax_init();
sajax_export("get_tag_linkroll");
sajax_handle_client_request();
?>
</?xml version="1.0" encoding="UTF-8"/?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title><?php echo DELICIOUS_USERNAME; ?>'s del.icio.us Summary Page</title>
<link href="stylesheet.css" rel="stylesheet" type="text/css" />
<script>
<?php
//this brings in all the javascript SAJAX needs to do its thing
sajax_show_javascript();
?>
//called when you click a tag in the tag-cloud
function get_tag_linkroll(tag) {
document.getElementById("tag_linkroll").innerHTML = "<em>Fetching linkroll. Please wait....</em>";
x_get_tag_linkroll(tag, get_tag_linkroll_cb);
}
//x_get_tag_linkroll callback
function get_tag_linkroll_cb(result) {
document.getElementById("tag_linkroll").innerHTML = result;
}
</head>
<body>
<h1 id="header"><?php echo DELICIOUS_USERNAME; ?>'s del.icio.us Summary Page</h1>
<div id="center_col">
<div class="col_banner">My Tags</div>
<div style="text-align: justify">
<?php
//pull all of the tags and their count out of the data array first
//and put it into a k => v array, where v = an array of all tags w/ that count
tags = tags as tag_counts[tag['attributes']['TAG'];
//sort tags by counts
ksort(tag_counts with a count of 3 or below
for (i <= 3; tag_counts["tag_counts["smallest_count = array_shift(array_keys(largest_count = array_pop(array_keys(count_difference = smallest_count;
count_difference / 3; //3 different sub-sizes
//create a new array of all tag names, sorted, as keys with counts as values
tag_counts as tags_in_count){
foreach (tag_name)
tag_name] = tag_values);
//now go through
foreach (tag_values as tag_count)
{
if (largest_count)
echo "<span class=\"largest_tag\"> ";
elseif (smallest_count)
echo "<span class=\"smallest_tag\"> ";
elseif (smallest_count + (tag_count > count_distribution)
echo "<span class=\"medium_tag\"> ";
else
echo "<span class=\"small_tag\"> ";
echo "<a href=\"#\" onClick=\"get_tag_linkroll('".tag_name."</a>";
echo " </span>";
}
?>
</div>
</div>
<div id="left_col">
<div class="col_banner">My Latest Bookmarks</div>
<?php
//list recent posts (linkroll)
linkroll_data[0]['children'];
echo "<ul>";
foreach (post)
{
echo "<li><a href=\"".post['attributes']['DESCRIPTION']."</a></li>";
if (isset(post['attributes']['EXTENDED']."</p>";
}
echo "</ul>";
?>
</div>
<div id="right_col">
<div class="col_banner">Browse by Tag</div>
<div id="tag_linkroll">
<p>« Click a tag in the column to the left to view my bookmarks for
it here.</p>
</div>
</div>
</body>
</html>
<?php
//close the database connection since we won't need it past this point
mysql_close(
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.