Archive for the ‘Code’ tag
Delicious Snapcasa – my first wordpress plugin
Whiiiiiiiiiiiiiii! If this works there should be about 4 thumbnails on this page, showing links bookmarked using Delicious, and tagged with “art”.
Download:
Download wp_delicious_snapcasa.zip here, version 0.5 of my very first wordpress plugin.
Usage:

(ps, right now you have to hack it if you want to see your own bookmarks, mskogly is hardcoded :) Working on that :)
What’s next:
I’m considering a few other thumbnailing services:
Working with the QXL.no api to show the latest bid on an auction

My sexy colleagues in NRK Mp3 are selling themselves on the auctionsite qxl.no for a good cause (Blå Kors), and I wanted to cook up a fast way to display the latest bid on the NRK Mp3 website.
Here is the result so far:
Not very fancy to say the least! But it does what it needs to: Fetch the latest bid on a particular auction.
Because I have to display it on bort nrk.no/mp3 and nrkp3.no (an externally hosted site), I decided to go for Flash, and using the new and lovely XML functionality of AS3.
It is in use on http://nrkp3.no/programledere-til-salgs/ and the frontpage of http://nrk.no/mp3 until the 19th of october at least.
Todo:
Make the code more reusable, everything is basically hardcoded.
Update: The php is now dynamic, send AuctionNr as a parameter to retrieve the auction you want like this: http://pappmaskin.no/opensource/qxl/qxlproxy.php?AuctionNr=549364732 . Next: Send in AuctionNr using the embed code.
Downloads:
QXL.zip.
The zip contains:
- qxl.fla (as3, made with flash cs3, very easy to understand what to change).
- qxlproxy.php (used to get around crossdomain-issues in flash)
Old QXL webservice documentation:
http://hjelp.qxl.no/avansert:xml_api
QXL Old api:
http://www.qxl.no/accdb/viewItemXML.asp?IDI=549689208
QXL New api, received by mail after contacting QXL:
http://www.qxl.no/accdb/viewitemxml.asp?AuctionNr=549689208&Catg=11395&ListingType=0&ListingSort=1&LanguageNr=0&PageNum=1
Resources:
Good as3 xml tutorial on Gotoandlearn.com
More about this years charity event
http://nrk.no/tvaksjonen/
Podcastplayer in flash! Php script to convert RSS to XSPF
Create your own free flash based podcast / mp3 player
I like the flashbased XSPF mp3 player. I had planned to rewrite the actionscript so that it could read rss with enclosures instead, but I liked the possibility to have unique pictures on each track, and I wanted to check out the XSPF format.
So I wrote a PHP script that uses DOMXML and xpath to convert an existing rss to xspf, it even have a search function of sorts.
I’m going to use it on a project I’m working on after a little more tweaking but I wanted to share it with other people who has a podcast and want a quick open source way to present their podcasts on their website.
<?php
$path = “http://podkast.nrk.no/program/radioresepsjonen.rss”;
$showfile = file_get_contents($path);
if(!$doc = domxml_open_mem($showfile)) {
echo “Error while parsing the document…”;
exit;
}
$xpath = xpath_new_context($doc);
$root = $doc->document_element();
//debugging
//echo domxml_version();
//var_dump(xpath_eval_expression($xpath, ‘/rss/channel/item’)); //http://no.php.net/manual/sv/function.xpath-eval-expression.php
//debugging – memory dump
//echo $doc->dump_mem( true, ‘UTF-8′ ) ; //http://no.php.net/manual/sv/function.domdocument-dump-mem.php
//print ” Path: <a href=\”$path\”>$path</a><br>\n”;
//print ” Showfile: <a href=\”$showfile\”>$showfile</a><br>\n”;
//print ” domDoc: <a href=\”$domDoc\”>$domDoc</a><br>\n”;
//print ” root: <a href=\”$root\”>$root</a><br>\n”;
// playlist plus search function
$playlist = $xpath->xpath_eval(“/rss/channel/item[contains(translate(title,'abcdefghijklmnopqrstuvwxyzæøåö', 'ABCDEFGHIJKLMNOPQRSTUVWXYZÆØÅÖ'), '".strtoupper($_REQUEST["search"]).”‘)]”);
//debug
//print “playlist found: “.count($playlist->nodeset).”\n”;
print “<?xml version=\”1.0\” encoding=\”UTF-8\” ?>\n”;
print “<playlist version=\”0\” xmlns=\”http://xspf.org/ns/0/\”>\n”;
print ” <title>Put clever title here, or get it from the rss</title>\n”;
print ” <annotation>Description of some sort</annotation>\n”;
print ” <creator>Who made this</creator>\n”;
print ” <info>http://link to more info</info>\n”;
print ” <location>http://yourdomain.com/doesnreallymatter/rss2xspf.php</location>\n”;
print ” <license></license>\n”;
print “<trackList>\n”;
foreach ($playlist->nodeset as $tracklist) {
$description = “”;
$title = “”;
$enclosureurl = “”;
//$enclosureurl = $tracklist->get_attribute(“length”);
//$spor = $tracklist->get_attribute(“spor”);
//$sangid = “$arkivnr-$spor”;
foreach ($tracklist->child_nodes() as $child) {
if ($child->node_name() == “title”) $title = $child->get_content();
if ($child->node_name() == “description”) $description = $child->get_content();
if ($child->node_name() == “enclosure”) $enclosureurl = $child->get_attribute(“url”);
}
print “<track>\n”;
print ” <location>$enclosureurl</location>\n”;
print ” <image>hassan/bilder/else150.jpg</image>\n”;
print ” <annotation>$title</annotation>\n”;
print ” <info></info>\n”;
print ” <info_text>$description</info_text>\n”;
print ” </track>\n”;
}
print “</trackList>\n”;
print “</playlist>\n”;
?>
Copypaste the above code into a new file and save it as rss2xspf.php and upload it to your server to test if you have domxml support. (If you don’t it will say something like Call to undefined function: domxml_open_mem. In that case, tough luck, find a new host.)
Download the exellent XSPF flash based mp3 player here: XSPF Web Music Player (Flash) – Plays MP3 on your website
Read more about XSPF over at http://www.xspf.org/
And please drop a comment if you use it and like or have problems.
You can also send me an email at morten.skogly _at_ gmail dot com.
There’s a lot of room for improvement, like using the rss image in place of a staticly defined image, or inserting a random image, or doing som web2.0 stuff like snarfing the images from amazon or whatever, please let me know if you make something superclever with it :)
Idea for your site: You can use del.icio.us to make your own mp3 podcast, visit bands you like bookmark the mp3s you like with del.icio.us, go there to get the rss, and your set to go, you have the same music on your site as on your ipod :) (You might have to use feedburner.com as a gobetween to create the enclosures and make it itunes-compatible.)
Updated: 06.04.2008: Unless you really really digg the XSPF player linked up above, I suggest you use the superb Jeroen Media Player instead. It is open source and supports both XSPF and RSS directly. It takes up more space, but it has video support and a very cool javascript api.
Del.icio.us system error
It’s always interesting to se other peoples error output :) But I’m a little surprised that del.icio.us is showing its soft white underbelly like this.
System error
error: Can’t call method “prepare” on an undefined value at /www/del.icio.us/comp/user/get line 13.
context:
…
9: my $usedb = ‘master’;
10: my $ret;
11:
12: if (!$auth_user) { $usedb = ‘user’ }
13: if (!exists ($db->{$usedb})) { $usedb = ‘master’ }
14: $user_name_q->{$usedb} = $db->{$usedb}->prepare(’select * from users where user_name = ?’);
15: my $query = $user_name_q->{$usedb};
16: $query->execute(lc($user_name));
17:
…
code stack: /www/del.icio.us/comp/user/get:13
/www/del.icio.us/site/search/index:59
/www/del.icio.us/site/autohandler:110
RAW ERROR
System error
error: Can’t call method “prepare” on an undefined value at /www/del.icio.us/comp/user/get line 13.
context:
…
9: my $usedb = ‘master’;
10: my $ret;
11:
12: if (!$auth_user) { $usedb = ‘user’ }
13: if (!exists ($db->{$usedb})) { $usedb = ‘master’ }
14: $user_name_q->{$usedb} = $db->{$usedb}->prepare(’select * from users where user_name = ?’);
15: my $query = $user_name_q->{$usedb};
16: $query->execute(lc($user_name));
17:
…
code stack: /www/del.icio.us/comp/user/get:13
/www/del.icio.us/site/search/index:59
/www/del.icio.us/site/autohandler:110
raw error
Can’t call method “prepare” on an undefined value at /www/del.icio.us/comp/user/get line 13.
Trace begun at /usr/share/perl5/HTML/Mason/Exceptions.pm line 131
HTML::Mason::Exceptions::rethrow_exception(‘Can\’t call method “prepare” on an undefined value at /www/del.icio.us/comp/user/get line 13.^J’) called at /www/del.icio.us/comp/user/get line 13
HTML::Mason::Commands::__ANON__(‘dbh’, ‘DBI::db=HASH(0×1b3f9d0)’, ‘user_name’, ‘mskogly’) called at /usr/share/perl5/HTML/Mason/Component.pm line 134
HTML::Mason::Component::run(‘HTML::Mason::Component::FileBased=HASH(0×1d0bd40)’, ‘dbh’, ‘DBI::db=HASH(0×1b3f9d0)’, ‘user_name’, ‘mskogly’) called at /usr/share/perl5/HTML/Mason/Request.pm line 1069
eval {…} at /usr/share/perl5/HTML/Mason/Request.pm line 1068
HTML::Mason::Request::comp(undef, undef, ‘dbh’, ‘DBI::db=HASH(0×1b3f9d0)’, ‘user_name’, ‘mskogly’) called at /www/del.icio.us/site/search/index line 59
HTML::Mason::Commands::__ANON__(‘all’, ‘xbox’, ‘dbh’, ‘DBI::db=HASH(0×1b3f9d0)’, ‘auth_user’, ‘mskogly’, ‘items’, 10, ‘tagview’, ‘list’, ‘tagsort’, ‘alpha’, ‘bundleview’, ’show’, ‘cookies’, ‘HASH(0×1fd6dc0)’, ‘browser’, ‘ff’) called at /usr/share/perl5/HTML/Mason/Component.pm line 134
HTML::Mason::Component::run(‘HTML::Mason::Component::FileBased=HASH(0×2028030)’, ‘all’, ‘xbox’, ‘dbh’, ‘DBI::db=HASH(0×1b3f9d0)’, ‘auth_user’, ‘mskogly’, ‘items’, 10, ‘tagview’, ‘list’, ‘tagsort’, ‘alpha’, ‘bundleview’, ’show’, ‘cookies’, ‘HASH(0×1fd6dc0)’, ‘browser’, ‘ff’) called at /usr/share/perl5/HTML/Mason/Request.pm line 1074
eval {…} at /usr/share/perl5/HTML/Mason/Request.pm line 1068
HTML::Mason::Request::comp(undef, undef, ‘all’, ‘xbox’, ‘dbh’, ‘DBI::db=HASH(0×1b3f9d0)’, ‘auth_user’, ‘mskogly’, ‘items’, 10, ‘tagview’, ‘list’, ‘tagsort’, ‘alpha’, ‘bundleview’, ’show’, ‘cookies’, ‘HASH(0×1fd6dc0)’, ‘browser’, ‘ff’) called at /usr/share/perl5/HTML/Mason/Request.pm line 760
HTML::Mason::Request::call_next(‘HTML::Mason::Request::ApacheHandler=HASH(0×1fdfe40)’, ‘dbh’, ‘DBI::db=HASH(0×1b3f9d0)’, ‘auth_user’, ‘mskogly’, ‘items’, 10, ‘tagview’, ‘list’, ‘tagsort’, ‘alpha’, ‘bundleview’, ’show’, ‘cookies’, ‘HASH(0×1fd6dc0)’, ‘browser’, ‘ff’) called at /www/del.icio.us/site/autohandler line 110
HTML::Mason::Commands::__ANON__(‘all’, ‘xbox’) called at /usr/share/perl5/HTML/Mason/Component.pm line 134
HTML::Mason::Component::run(‘HTML::Mason::Component::FileBased=HASH(0×1b23360)’, ‘all’, ‘xbox’) called at /usr/share/perl5/HTML/Mason/Request.pm line 1069
eval {…} at /usr/share/perl5/HTML/Mason/Request.pm line 1068
HTML::Mason::Request::comp(undef, undef, undef, ‘all’, ‘xbox’) called at /usr/share/perl5/HTML/Mason/Request.pm line 338
eval {…} at /usr/share/perl5/HTML/Mason/Request.pm line 338
eval {…} at /usr/share/perl5/HTML/Mason/Request.pm line 297
HTML::Mason::Request::exec(‘HTML::Mason::Request::ApacheHandler=HASH(0×1fdfe40)’) called at /usr/share/perl5/HTML/Mason/ApacheHandler.pm line 134
eval {…} at /usr/share/perl5/HTML/Mason/ApacheHandler.pm line 134
HTML::Mason::Request::ApacheHandler::exec(‘HTML::Mason::Request::ApacheHandler=HASH(0×1fdfe40)’) called at /usr/share/perl5/HTML/Mason/ApacheHandler.pm line 793
HTML::Mason::ApacheHandler::handle_request(‘HTML::Mason::ApacheHandler=HASH(0×1ad1730)’, ‘Apache=SCALAR(0×1fdd840)’) called at (eval 43) line 8
HTML::Mason::ApacheHandler::handler(‘HTML::Mason::ApacheHandler’, ‘Apache=SCALAR(0×1fdd840)’) called at /dev/null line 0
eval {…} at /dev/null line 0
Filed in: del.icio.us
Userscripts.org: Amazon Sambok and BIBSYS ISBN Search
Hey, my first Greasemonkey userscript!
Userscripts.org: Amazon Sambok ISBN Search:
This is just a fast remake of the Hight Library Linky script. Its my first script, just wanted to check out how hard it would be to rework. Luckily for me it was super easy. It inserts links to two norwegian bibliographical databases.
Bibsys, containing material from universities and colleges.
And Sambok, containing material from most Public Libraries in Norway.
Pretty useful, at least in theory, since ISBN search is quite limiting. But it will have to do for now.





