Archive for January, 2009

More ‘Your Brand’ Products Released/Updated

January 26th, 2009

I generally like to write how-tos and tutorials on this site but I feel the need to mention some of the WordPress work i have been doing with Tim Nash.

We have been working very hard over the last couple of months putting together a number of new plugins and updating some older ones.

Finally we got the major bugs ironed out and the products released last week. They are as follows:

The following additions to Your Members were released:

  • Your Members Firesale

The following products are currently in closed Beta and will be shortly be released for all (in Beta):

  • Your Responder – Autoresponder Plugin
  • Your Classifieds – Classified Advertising Plugin

All of the products have had their interfaces ‘tweaked’ to allow for the reshuffle (complete change) in the recent release of WordPress 2.7 and we are always optimising the code to be both more maintainable and more efficient.

If you have not heard of ‘Your Brand’ or want to find out more then please visit www.newmedias.co.uk or drop by the forums where myself and Tim can usually be found answering questions and helping people out.

We have also written a few Free WordPress Plugins that are available! Click here to visit the Freebies page on Newmedias.

XLS Download from PHP Class!

January 21st, 2009

Following on from my last post on creating a proper XLS spreadsheet from PHP I have just written a small class which will do all the hard work for you if necessary.

It will handle rows and columns automatically aswell as being able to be passed an array and then generating a spreadsheet download for you.

Download: XLS from PHP Example Class (783 bytes)

Sample usage is as follows:

	//Require the file
	require_once (SHARED_CLASSES_DIR . 'xls.class.php');

	//Instantiate the class.
	$xls = new xls(); 

	//Just build an example array out of test data
	$array = array(
		array(1,2,3,4,'five')
		, array('five','test' ,4,3, 0)
	);

	//Triggers the download using the passed array
	$xls->download_from_array($array);

Note that when instantiating the class you can pass a string as an argument and it will set the name of the XLS download. No need to add .xls to the end because it will do that for you.

Download: XLS from PHP Example Class (783 bytes)

Creating a Downloadable Spreadsheet from PHP

January 16th, 2009

I have written several systems that show data on a page but also provide a CSV download file either through a textarea with formatted data inside to copy and paste or via a download link and creates a file on the fly.

I recently decided that this wasn’t the best way to do it seeing as the people will want to be using Microsoft Excel to view the data. It is possible to write a spreadsheet using PHP and using an example from AppServ I started to do it this way.

The original link is included above but here is my simplified version with smaller more understandable function naming:

Download the example script here: XLS from PHP Example (723 bytes)

<?php

function xls_BOF() {
	echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
}

function xls_EOF() {
	echo pack("ss", 0x0A, 0x00);
}

function xls_write_cell($row, $col, $value='') {
	if (is_numeric($value)) {
		echo pack("sssss", 0x203, 14, $row, $col, 0x0);
		$value = pack("d", $value);
	} else {
		$l = strlen($value);
		echo pack("ssssss", 0x204, 8 + $l, $row, $col, 0x0, $l);
	}

	echo $value;
}

// Send Headers to set the Filename and force a download of the contents of the script
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");

 // Put the filename in \"'s if you want it to include spaces
header("Content-Disposition: attachment;filename=" . $filename . ".xls");
header("Content-Transfer-Encoding: binary ");

xlsBOF(); //Start the Spreadsheet

xls_write_cell(0, 1, 'Column 1');
xls_write_cell(0, 2, 'Column 2');
xls_write_cell(0, 3, 'Column 3');

$row = 1;
for ($i=0; $i<2; $i++) {
	xls_write_cell($row, 0, 'Row ' . $row . ' Column ' . $i);
	xls_write_cell($row, 1, 'Row ' . $row . ' Column ' . $i);
	xls_write_cell($row, 2, 'Row ' . $row . ' Column ' . $i);

	$row++;
}

xlsEOF(); //End the Spreadsheet

exit(); //Exit the script after download

?>

My Forum

January 11th, 2009

I have been getting the odd comment about various posts of mine and each one has lead to an off site conversation about the comment. I decided to install a forum on this site so if ever anyone decides to ask me anything then they can do without any problems.

I have used Simplepress Forum as it installs like a plugin unlike BBPress which is separate and is a pain to integrate.

Feel free to ask me anything, I get a few emails about Google Map API and Geocoding. If you prefer not to speak on a public forum then my email address is barton.sean@gmail.com

Update: Binned it because I decided SimplePress was rubbish :)

SB Child List Plugin

January 11th, 2009

I have been working on my boat site for a short while now and want to show some sort of heirarchy in the pages. I have decided to call one of my pages ‘articles’ and have my articles use it as their parent.

Logically you would expect to see a list of the child pages on the articles page along with a pretty picture and some intro text. This doesn’t seem possible natively with wordpress so I decided to make it happen.

Adding the hook to any page will by default show an unordered list showing the children and links to them. If you prefer to style it yourself then don’t worry because you can do that too using the templating system on the settings page.

There is also add another tag, , that allows you to provide a back to parent link from any child. This enables you (in the articles example) to add a “click here to read more on this subject” link. It is also template based so it can say anything or look however you see fit.

Download it here: Download Page

Windows XP Update Popup

January 5th, 2009

The windows update popup has lost me hours of work for the last time!

Please Restart... Please Restart... Please...

Please Restart... Please Restart... Please...

Ok.. so that may be a little over the top, maybe minutes of work but it’s still irritating losing all of the windows I have spend days opening and lovingly arranging. After the umpteenth popup of the day I thought I would Google the answer to turn off this unwanted menace.

I found a site that told me exactly the answer I was hoping for and I was popup free in under 5 minutes. The depressing thing is that it was written in 2006 and it took me nearly three years to build up the inclination to do something about it.

So here’s how to do it:

  • Click on the Start button and choose ‘Run.’
  • Type: gpedit.msc.
  • Expand Local Computer Policy, Computer Configuration, Administrative Templates, Windows Components, Windows Update.
  • Select “Re-prompt for restart with scheduled installations.”
  • Choose “Enable” and then type in how many minutes you want to wait.

I do feel it necessary to put a little disclaimer in here, gpedit is not something that you should really go playing with and I imagine you need to be an administrator on the machine (most home computers are set up so you are the admin) to make the change

I got this handy hint from Tech Target however you are bombarded with advertising as you enter the site. you have been warned.