[Home]WikiPatches/LiveJournalLinkPattern

UseModWiki | WikiPatches | RecentChanges | Preferences

I use Livejournal a lot and had needed to reference a lot of post on the livejournal sites (also on the deadjournal and ujournal as well), so I decided to take care of myself and my readers/editors to remove unnecessary link stuff. That's what we have for example:

 http://www.livejournal.com/talkread.bml?journal=lj_dev&itemid=486670&usescheme=lynx

Long to copy, long to proofread, and looking not really appealing to my minimalistic tastes. So I wrote a little patch to accept the following form:

 [sericeId|userId|itemId(#optionalAnchor)]

It consists of two parts.

Part zero is adding new vars (in the header after the part where it says "Other global variables"):

 use vars qw($urlMajor $showid)

Otherwise strict mode is going to prevent script from starting up, giving out an error. That's really not what we want. Then goes actually the next, first part.

It is a regexp added to the different bracketed links patterns. I placed it next to the sub StoreBracketLink?.

 if ($BracketText) {  # Links like [URL text of link]              -- OLD LINE
   s/\[$UrlPattern?\s+([^\]]+?)\]/&StoreBracketUrl?($1, $2)/geos;  -- OLD LINE
   s/\[(lj|uj|dj)\|([0-9a-z_]+)\|([0-9]+)([\#0-9a-z_]*)\]/&StoreJournalUrl?($1, $2, $3, $4)/geos;

I left two lines to make it easy to find the necessary place in the body of the script.

Second part goes into subroutines list and actually does the dirty stuff constructing the link and returning it to the user:

 # [JLINK02] START

 sub StoreJournalUrl? {

 # we got the regexp result with four vars.
 # joid = id of journalling service
 # uid = id of the user (username)
 # itemid = id of the record we want referenced
   my ($joid, $uid, $itemid, $anchor) = @_;

   if ($joid eq "lj") {
     $urlMajor = "http://www.livejournal.com/";
   }
   if ($joid eq "uj") {
     $urlMajor = "http://www.ujornal.org/";
   }
   if ($joid eq "dj") {
     $urlMajor = "http://www.deadjournal.com/";
   }
   return &StoreRaw("<a href=\"".$urlMajor."talkread.bml?journal=$uid&itemid=$itemid$anchor\">[$uid:$itemid]</a>");
 }

 # [JLINK02] END

Can be done to enhance it a little:

-- AlexanderMisch


UseModWiki | WikiPatches | RecentChanges | Preferences
Edit text of this page | View other revisions | Search MetaWiki
Last edited January 25, 2003 11:22 pm by AlexanderMisch (diff)
Search: