Webslices in WordPress

Posted by beakersoft | Posted in Programming | Posted on 24-03-2008

15

Wordpress and Webslices header

One of the new features in the beta of Internet Explorer 8 is something called Webslices. These work in a similar way to RSS feeds, but allow you to subscribe to a section of a web page, as opposed to just a feed. The section of the page you subscribe to is a div with a class name of hsclice.

If a page contains webslice’s that can be subscribed to, a little purple icon shows in the IE tool bar, along with any rss feed options for the page. If you click on the webslice option a new link appears in the favorites bar, when you click on this you get the contents of the div. If the content of the div is updated, the item in the favorites bar shimmers and goes bold to inform you of the update.

Webslice

So, I have written a small php script that can be used on a WordPress blog to subscribe to the 7 last posts as a webslice. At the moment all I have is a script, but if people are interested I can turn it into a WordPress plugin. You can download all the parts as a .zip file at the end of the post, but here is what it contains

  • readme.txt – This file contains the bit of HTML code you need to insert in your index.php file (or where ever you want the webslice subscription option to show) and more detailed install information.
  • webslice.php – The actual file that contains a div with the last 7 posts
  • webslice.css – Style sheet for the php file

When you have downloaded the files, change the css to suite you, insert the div code into your page, upload to the server and away you go.

More Info on the script

When I first looked at adding a webslice to my WordPress blog, I thought i would just place the hslice div around the existing previous posts section in my side bar. I went away from that idea though as I wanted the ability to format it differently, maybe add a graphic to the bottom etc so i went with an external file.

To make the page flag as having a webslice, but re-direct it to another page for the actual div, I used the class=”feedurl” option in the div. This just tells IE to look in a different place for the actual content. You can tell it to look at a page or an rss feed. The div containing all this info is hidden so it doesn’t interfere with any of the existing front page content.

The script it’s self is very straight forward. It just looks in your WordPress DB for the last 7 (you can easily change this) posts , and puts them into n unordered list on the page, the formating is controlled by an external style sheet.

Please note this might not be 100% reliable. IE 8 is still in beta so its possible (but unlikely) the way it handles Webslices could change. I have also only tested this on one machine running the new IE, so it might not always work right. If you have problems get in contact and ill try and iron them out.

As I mentioned before if there is enough interest I might turn it into a plug-in

Edit: Since upgrading to the release version of Internet Explorer 8, any web slices I had suddenly stopped working. All I kept getting was ‘page cannot be displayed’ error in the space where the slice was. After much searching and head scratching I finally found the solution at http://support.microsoft.com/kb/969213

It turns out that Google Gears was stopping them from working, just disable the add on in IE and they start to work fine again

Download The Zip Archive

Download the script: wordpress_webslice.zip

Flickr, Google Maps and Classic ASP

Posted by beakersoft | Posted in Programming | Posted on 03-01-2008

0

Header

I went on Holiday to the German Beer festival, Oktoberfest and wanted to be able to upload photos from my camera phone onto Flickr, so I can put them onto a website I run. I also wanted to put the pictures onto a Google map. There were quite a few things that would allow me to do this, but none met my criteria:

  • Most of the scrips i found were PHP or .net, I needed an classic asp one
  • I needed to be able to tag the GPS co-ords into a tag on the photo. My camera phone did not have GPS built in, so I wanted to add two tags to them containing the info, called geo:lat=[xxx] and geo:lon=[xxx]

So, I came up with this script, you can see it in action at http://www.oldmanales.co.uk/feat_OktoberFest07.asp

In order to use the script, you will need a couple of things:

Once you have these, change the API key values to yours in the script, then upload it to your server. Now, call the script something like this:

FlickrTags2Google.asp?lat=11.511955&long=48.129893&tags=Oktoberfest_07&flickrID=7389734@N03

The lat and long parts of the string are where in the world the map will be placed when the pages loads, the tags are a comma separate list of tags to show on the map, in this case everything I have tagged as Oktoberfest_07. The last parameter is your flickrID.

Hopefully, when your call the page now you should get something like the screen shots below, the photos are indicated by the little camera icon, when you click on them you should get a popup preview of the image along with some info on the photo:

Preview1

Download The ASP Script

Download the file :FlickrTags2Google.asp
(and dont forget to rename it to a .asp extension otherwise it wont run.)

Hopefully when I get time I will document the code a bit better. If you find problems with it, or have any good ideas for enhancements let me know.

Going Green – Creating a PC Shutdown Script

Posted by beakersoft | Posted in Programming | Posted on 15-11-2007

0

There’s been a lot of talk throughout the IT industry recently about being more ‘Green’. Well, being all for that and also sick of users who leave there pc’s turned on all night for no good reason I have come up with a script to turn of pc’s.

The script looks into Active Directory for computer objects in a specific OU, loops through all of the computers and creates a batch file that calls the windows script Shutdown.vbs. This is a script that comes bundled with XP, and allows an administrator to shutdown a remote machine from the command line.

You can download the script from http://www.beakersoft.oldmanales.co.uk/ShutDownPCs.txt

Rename the file to a .vbs file, change the 3 variables at the top of the script to match your environment and it should create your file. A couple of things to note before using this script:

BE CAREFUL! You could end up shutting down servers or client machines that are being used. I would make sure first the pc’s are ok to shutdown, and only run the script after you know the users aren’t likely to be using them.

This script will not forcefully close open applications, so not to lose any users work. If you really want to force the machine down (even if the user has un-saved open work) you can add a ‘-f’ switch to the script on the line where it writes the computer name out to the file.

You will need to be a Domain admin or similar to shutdown the remote machines, or you’ll just get an access denied errors.

As I mentioned before this could be dangerous so make sure the pc’s are ok to shut down before running the script.

API Wrapper Classes

Posted by beakersoft | Posted in Programming | Posted on 08-11-2007

0

The past couple of days I have been on a short course run by one of our vendors about using the API from one of there products.

Now I have to firstly applaud them for making there product open enough for us to call it using its api, there are some bits of business logic missing, but for the most part it is very good and very well documented.

The only problem with it is the amount of parameters you can pass to some of the methods, and the amount of information you get back. In some case’s there are over 30 inputs to a method, but only 2 are mandatory. So Calling the API could look something like this:

result = AppInteraction.API(“APICustSearch”, pi_pointer, pi_source, type.missing, type.missing, type.missing) etc etc

This kind of code while functional can get very messy and hard to read. What we could do with is a class to wrap the functionality of the API calls in.

First thing to do is create a couple of classes for the input and outputs of the method. This example is using the method called APICustSearch, it will have 5 possible inputs and 3 outputs.

Public Class CustSearch _input
Public Spointer As String

Public Source As String

Public date As String

Public Active As String
Public MinSpend As String

End Class

Public Class CustSearch _results
Public Result As Integer

Public Resulttext As String

Public Custname As String

End Class

The above classes just deal with the inputs/outputs of the api, next we need to code the actual api call into a class:

Public Class AppWrapper
‘ Defintion for API APICustSearch
Public Function CustSearch(ByVal oInput As CustSearch_input) As CustSearch_results

Dim oApp As New AppAPI.Interaction
Dim oResults As New AppAPI.colGeneric
Dim oReturn As New Suborderrestart_results

oResults = oApp.API(“APICustSearch”, oInput.Spointer , oInput.Source, oInput.date, oInput.Active, oInput.MinSpend )

While System.Runtime.InteropServices.Marshal.ReleaseComObject(oApp) > 0
End While
While System.Runtime.InteropServices.Marshal.ReleaseComObject(oResults) > 0
End While

oResults = Nothing
oApp = Nothing

Return oReturn
End Function

End Class

So now we have our class to call the functionality of the API method we are interested in, we can easily call it from our application like so:

Dim App As New AppWrapper
Dim CustSearchParam As New CustSearch_input
Dim search_result As CustSearch_results

With CustSearchParam
.Spointer = “12345″
.Source = “API”
.date = “08/11/2007″
.Active = “Y”
.MinSpend = “0″
End With

search_result = App.CustSearch(CustSearchParam)

‘this is some checking specific to the API i was working with. If the search_result.Result was not 0
‘an error had happened and the details were in search_result.Resulttext
If (search_result.Result <> 0) Then
MessageBox.Show(search_result.Resulttext, “Search error”)
End If

If (search_result.Result = 0) Then
MessageBox.Show(search_result.Resulttext, “SubOrderRestart Suceeded” & vbnewline & search_result.Custname )
End If

You will obviously have to tailor the classes based on the api you are using, but you can just add all the methods you use the the AppWrapper class, and create new input and output classes based on the spec.

Apologies for any errors in the example code, I have re-written sections of mine to make it more generic, but hopefully you should get the idea