As you’ve probably noticed, the blogmarks are visible on the right menu (throughout the site - should be only on the index page, but I haven’t figured out how to do that in a MT global template). If you’ve not got Javascript enabled you won’t see them - the only way I could get dynamic content into a static MT-generated site. Archives will follow.
_[Apologies to Simon for nicking the format - well, they do say imitation is the sincerest form of flattery!]_
h2. Some notes on the implementation
The bookmarklet comes from “Clagnut”:http://clagnut.com/blog/264/ and was used without modification (other than to enter my site’s URI).
h3. Extracting the referrers’ title
I also pinched the logic of his PHP code to grab the title from the referring site, but rewrote it to make it a bit more compact (and hopefully more efficient):
bc. if ($open=@fopen($_GET['via_url'],”r”)) {
while(!feof($open)) {
$line=@fgets($open, 1024);
if (preg_match(’!
break;
}
}
fclose($open);
$via_title = $matches[1];
It still needs tuning, so the connection dies quicker if the page cannot be found.
h3. Storing the blogmarks
A simple table, based on the one “Simon uses”:http://simon.incutio.com/archive/2003/11/24/blogmarks but of course with the column names altered slightly :-).
bc. CREATE TABLE “blogmarks” (
“blogmark_id” int4 DEFAULT nextval(’”blogmarks_blogmark_id_seq”‘::text) NOT NULL,
“link_url” varchar,
“link_title” varchar,
“comments” varchar,
“via_url” varchar,
“via_title” varchar,
“date_added” timestamp
);
CREATE UNIQUE INDEX “blogmarks_blogmark_id_key” ON “blogmarks” (”blogmark_id”);
(This is using PostgreSQL - yes I’m pretty sure the ID should be bigger than int4, but when I said ‘Integer’ that’s what it gave me…)
h3. PHP code
Very simple in concept, but mine is currently very complicated in execution. I decided to use writing this application as a learning exercise in “DB_DatabOject”:http://pear.php.net/manual/en/package.database.db-dataobject.php - which was way overkill, and I can’t see the use for either. I mean, treating your database as objects just doesn’t seem to make sense. Still, at least I’ve made up my mind now ![]()
I am hoping to release the code once I’ve got it cleaned up and finished writing everything - not sure though whether it’ll be using the native PHP PostgreSQL functions (if so the first time I’ve coded specifically for a database for over a year) or some DBA(Database Abstraction) layer. Part of the script currently uses “MDB”:http://pear.php.net/manual/en/package.database.mdb.php but again it feels like way too much load for such a tiny script. Oh, and there’s no templating at present either - not because I didn’t think it would be a good idea, but because I wanted to write something quickly that worked.
3 comments ↓
how do u add blogmarks please?
Thanks for the insight on how to do this. I will definitely take a look at Clagnut’s Bookmarklet and since I have been using FeedDemon recently, I think it is time to programmatically extract the links stored in its News Bin as it is stored in rss format. I still need more ideas but this was a good start. Thanks.
thank you for updating post
Leave a Comment