Archive for the ‘Random’ Category

Add URL link to Wordpress default header

Friday, February 15th, 2008

Here is a quick post on how to add a URL link to your Wordpress header. This has only been tested on the default theme. You will need to know the dimensions of the header; the default header is 760px by 200px. Note, you will need to disable Toggle Text Display, in Wordpress Admin→Presentation→Header Image and Color→Advanced→Toggle Text Display.

Simply add the following code into header.php after <div id="header">


<a href="<?php echo get_option('home'); ?>/" style="display:block;height: 200px;width: 760px"></a>

With it inserted should look like the following:


<div id="header"><a href="<?php echo get_option('home'); ?>/" style="display:block;height: 200px;width: 760px"></a>
<div id="headerimg">
<h1><a href="<?php echo get_option('home'); ?>/"><?php bloginfo('name'); ?></a></h1>
<div class="description"><?php bloginfo('description'); ?></div>
</div>
</div>

An example blog with a linking header.

RSS feed aggregator/combiner in PHP

Tuesday, January 29th, 2008

Having also a second blog, I needed a way to combine the RSS feeds into one, hence, the following code was written (well, modified from this code).

The code uses MagpieRSS to read and FeedCreator to write. Thanks to Scott Hurring for code to grab the RSS feed title.

The code has been tested with my 2 Wordpress blogs (view example combined RSS feed). To install, extract and upload the feed directory and modify the settings in index.php.

Download all files and folders

<?php
$TMP_ROOT = "tmp/"; //need to screate a tmp directory with write access
$DOMAIN_NAME = "http://domainname.com/";
$SITE_TITLE = "my RSS combined feed";
$SITE_DESRIPTION = "my RSS combined feeds from domain1.com and domain2.com";
$SITE_AUTHOR = "your name";
$RSS_DIR = "../";

$array = array(
"http://domain1.com/feed/",
"http://domain2.com/feed/"
);
$num = 10;
$showfullfeed = FALSE;

define('MAGPIE_DIR', $RSS_DIR.'feed/');
define('MAGPIE_CACHE_DIR','/'.$TMP_ROOT.'rsscache');

/* include required files */
@require_once(MAGPIE_DIR.'rss_fetch.inc');
@include(MAGPIE_DIR.'feedcreator.class.php');

/* Set RSS properties */
$rss = new UniversalFeedCreator();
$rss->useCached();
$rss->title = $SITE_TITLE;
$rss->description = $SITE_DESRIPTION;
$rss->link = $DOMAIN_NAME;
$rss->syndicationURL = $DOMAIN_NAME."feed/index.php";

$i_temp = 0; //temp i variable
$j_temp = 0; //temp j variable
$total_temp = 0; //temp total number of posts in all rss feeds

$array_count = count($array); //number of rss feeds

/* code to determine which post to display */
for ($i = 0; $i < $array_count; $i++) {
$rss1 = fetch_rss($array[$i]);
if ($rss1) {
while ($array_temp[$i]['page_title'] == null){  //url_grab_title doesn't always work first pass
$array_temp[$i]['page_title'] = url_grab_title($array[$i]);
}
$items = array_slice($rss1->items, 0);
$array_temp[$i]['rss_data'] = $items;
$total_temp += count($items);
$array_temp[$i]['rss_pointer'] = 0;
preg_match('@^(?:http://)?([^/]+)@i', $array[$i], $matches);
$array_temp[$i]['site_url'] = $matches[0];
}
}
while ($total_temp <> 0 && $num > 0){// loop while there are remaining posts to process
$date_timestamp_temp = 0; //initialise to 0
for ($i = 0; $i < $array_count; $i++) {
$date_timestamp_temp = max($date_timestamp_temp, $array_temp[$i]['rss_data'][$array_temp[$i]['rss_pointer']]['date_timestamp']); //determine latest post from rss feeds
if ($date_timestamp_temp == $array_temp[$i]['rss_data'][$array_temp[$i]['rss_pointer']]['date_timestamp']) { //latest post is found so save where it came from
$i_temp = $i;
$j_temp = $array_temp[$i]['rss_pointer'];
}
}
$total_temp --; //decrement total remaining posts to process
$num --; //decrement number of posts to display
$array_temp[$i_temp]['rss_pointer'] ++; //increment post index of used post rss

/* code to display post */
$item = $array_temp[$i_temp]['rss_data'][$j_temp];
$href = $item['link'];
$title = $item['title'];
if (!$showfullfeed) {
$desc = $item['description'];
}else{
$desc =  $item['content']['encoded'];
}
$desc .=  '<p>Copyright &copy; <a href="'.$array_temp[$i_temp]['site_url'].'">'.$array_temp[$i_temp]['page_title'].'</a>.  All Rights Reserved.</p>';
$pdate = $item['pubdate'];
$item = new FeedItem();
$item->title = $title;
$item->link = $href;
$item->description = $desc;
$item->date = $pdate;
$item->source = $DOMAIN_NAME;
$item->author = $SITE_AUTHOR;
$rss->addItem($item);
}

// below function from http://hurring.com/scott/code/php/url_title/
// fetch a "chunk" of data and look for <title> in it
function url_grab_title($rss_url) {
$fp = fopen($rss_url, 'r');
$chunk = fread($fp, 512);
$chunk = preg_replace("/(\n|\r)/", '', $chunk);

// Look for <title>(.*?)</title> in the text
if (preg_match('/<title>(.*?)<\/title>/i', $chunk, $matches)) {
return $matches[1];
}
return null;
}

// get your news items from other feed and display back
$rss->saveFeed("RSS2.0", '/'.$TMP_ROOT."rsscache/feed.xml");

?>

How to disassemble a Seagate FreeAgent Pro

Monday, December 3rd, 2007

I purchased a 750gb Seagate FreeAgent Pro (from America) with the sole intention of using just the drive as it was actually the same price as the standalone drive (in Australia). To remove the drive is quite a tricky procedure if you don’t have the knowhow.

Seagate FreeAgent Pro

I didn’t complete mangle my FreeAgent Pro, it is still usable (I think), but it isn’t pretty anymore.

There is already information out there but it seems this is an older model (which also looks like it was a lot easier to dismantle).

To start, remove the base. This is the easy part, just keep on removing screws till the base can be removed. You will have to remove the circuit board and also the SATA and SATA power cables from the board. Once the base is removed, you will have something that looks like this.

Seagate FreeAgent Pro with base removed

This is an already gutted FreeAgent Pro. Note the Seagate logo, this is the side that comes apart.

Now, onto the hard part. Also, as a note, I haven’t actually tried this method, but once I had it opened it was easier to assume how it should have been open (got to love hindsight). You will need a stiff, straight piece of wire, a wire coat hanger works perfectly, with the hook bent straight.

Seagate FreeAgent Pro location of main clips.

The locations of the two problematic clips are at the base. Once these are unclipped the ones at the top unclip very easily.

Seagate FreeAgent Pro positioning of wire.

Seagate FreeAgent Pro positioning of wire.

Insert the wire into the gaps at the bottom, the idea is to push the clip that secures the cover. When the wire is inserted and pushing on the clip, gently try to remove the cover. Do not apply too much force because as soon as the clip is deformed it will be impossible to remove (this is from experience). The cover should declip on one side nicely. Repeat this process for the clip on the other side.

Seagate FreeAgent Pro location of four clips.

It can be noted that the two clips, located at the bottom have been broken off, this was the extremely measures that I took to remove cover. Hopefully this post will prevent you from doing the same.

Welcome to my blog

Saturday, November 3rd, 2007

I have decided to join the blogging bandwagon. I have lots of information I think would be useful to others and I believe a blog would make it easier to write and organise this information. It should also help to correlate all my previous projects and increase my net presence.