<rss version="2.0">
		<channel>
			<title>FlatPress forums - Short Links Plugin (for Twitter, for example)</title>
			<lastBuildDate>Wed, 08 Sep 2010 15:35:04 +0200</lastBuildDate>
			<link>http://www.flatpress.org/forums/</link>
			<description></description>
			<generator>Lussumo Vanilla 1.1.10</generator>
			<item>
		<title>Short Links Plugin (for Twitter, for example)</title>
		<link>http://www.flatpress.org/forums/comments.php?DiscussionID=807&amp;Focus=4747#Comment_4747</link>
		<guid isPermaLink="false">http://www.flatpress.org/forums/comments.php?DiscussionID=807&amp;Focus=4747#Comment_4747</guid>
		<pubDate>Tue, 25 Aug 2009 08:14:04 +0200</pubDate>
		<author>paul</author>
		<description>
			<![CDATA[I created a little plugin (workaround) to enable short links on a flatpress blog to use for example on Twitter. Not sure if anyone is interested, but I announce it here anyway.<br /><br />The design is not really nice as this plugin builds the URLs to redirect for itself instead of calling a core function of flatpress doing this (is there a function like this?). But it works well, does not matter if you use pretty URLs or not. The short link will redirect you per header redirect to the right URL.<br /><br />To make it work the .htaccess which is used by the pretty URLs plugin, has to be active, of course.<br /><br /><code >&lt;?php<br />/*<br />Plugin Name: shorturls<br />Version: 0.1<br />Plugin URI: http://blog.wbou.de<br />Author: Paul Wellner Bou<br />Author URI: http://blog.wbou.de<br />*/<br /><br />define('PAULWB_PLUGIN_SHORTURL', true);<br /><br />add_action('init', 'plugin_shorturls_head', 0);<br />add_action('entry_block', 'plugin_shorturls_calc');<br /><br />function plugin_shorturls_calc() {<br />	global $fpdb, $smarty;<br />	<br />	$q = $fpdb-&gt;getQuery();<br />	$id = $q-&gt;currentid;<br />	$htmlLinkStr = &quot;&lt;div class=\&quot;shortlink\&quot;&gt;[&lt;a href=\&quot;/&quot;.getShortId($id).&quot;\&quot;&gt;Short Link&lt;/a&gt;]&lt;/div&gt;&quot;;<br />	$smarty-&gt;assign('shortlink', $htmlLinkStr);<br />}<br /><br />function plugin_shorturls_head() {<br />	<br />	$url = $_SERVER['REQUEST_URI'];<br />	if(!preg_match(&quot;/^\/[a-z0-9]{1,5}$/&quot;, $url))<br />		return;<br /><br />	$shortUrlStr = str_replace(&quot;/&quot;, &quot;&quot;, $url);	<br />	$o = new FPDB_Query(array('start'=&gt;0,'count'=&gt;-1,'fullparse'=&gt;false), null);<br />	<br />	while ($o-&gt;hasMore()) {<br />		list($id, $contents) = $o-&gt;getEntry();<br />		if($shortUrlStr == getShortId($id)){<br />			// use pretty urls, if plugin available<br />			if(defined('PRETTYURLS_TITLES')){<br />				$url =  _permalink($id, $contents['subject']);<br />			}else{<br />				$url = BLOG_BASEURL . &quot;?x=entry:$id&quot;;<br />			}<br />			header(&quot;Location: $url&quot;);<br />			die();<br />		}<br />	}<br />}<br /><br /># copied and adjusted from plugin.prettyurls.php<br />function _permalink($id, $title) {<br />	if (PRETTYURLS_TITLES)<br />		$title = sanitize_title($title);<br />	else <br />		$title = $id;<br />	$date = date_from_id($id);<br />	return BLOG_BASEURL  . &quot;20{$date['y']}/{$date['m']}/{$date['d']}/$title/&quot;;<br />}<br /><br />function getShortId($fullid) {<br />	return base_convert(getNumericId($fullid), 10, 36);<br />}<br /><br />function getNumericId($fullid) {<br />	$numid = substr($fullid, strpos($fullid, &quot;-&quot;)+1);<br />	$numid = intval($numid);<br />	return $numid;<br />}<br /><br />?&gt;<br /></code><br /><br />You can test it here: http://blog.wbou.de<br /><br />Of course, if you want to output the hyperlink within the blog entry, the template has to be modified, putting<br /><br /><code >...<br />{$shortlink}<br />...</code><br /><br />Where the <code >&lt;a href...&gt;</code> should appear.]]>
		</description>
	</item>
	
		</channel>
	</rss>