Want to take part in these discussions? Sign in if you have an account, or apply for one below
Vanilla 1.1.10 is a product of Lussumo. More Information: Documentation, Community Support.
<?php
/*
Plugin Name: shorturls
Version: 0.1
Plugin URI: http://blog.wbou.de
Author: Paul Wellner Bou
Author URI: http://blog.wbou.de
*/
define('PAULWB_PLUGIN_SHORTURL', true);
add_action('init', 'plugin_shorturls_head', 0);
add_action('entry_block', 'plugin_shorturls_calc');
function plugin_shorturls_calc() {
global $fpdb, $smarty;
$q = $fpdb->getQuery();
$id = $q->currentid;
$htmlLinkStr = "<div class=\"shortlink\">[<a href=\"/".getShortId($id)."\">Short Link</a>]</div>";
$smarty->assign('shortlink', $htmlLinkStr);
}
function plugin_shorturls_head() {
$url = $_SERVER['REQUEST_URI'];
if(!preg_match("/^\/[a-z0-9]{1,5}$/", $url))
return;
$shortUrlStr = str_replace("/", "", $url);
$o = new FPDB_Query(array('start'=>0,'count'=>-1,'fullparse'=>false), null);
while ($o->hasMore()) {
list($id, $contents) = $o->getEntry();
if($shortUrlStr == getShortId($id)){
// use pretty urls, if plugin available
if(defined('PRETTYURLS_TITLES')){
$url = _permalink($id, $contents['subject']);
}else{
$url = BLOG_BASEURL . "?x=entry:$id";
}
header("Location: $url");
die();
}
}
}
# copied and adjusted from plugin.prettyurls.php
function _permalink($id, $title) {
if (PRETTYURLS_TITLES)
$title = sanitize_title($title);
else
$title = $id;
$date = date_from_id($id);
return BLOG_BASEURL . "20{$date['y']}/{$date['m']}/{$date['d']}/$title/";
}
function getShortId($fullid) {
return base_convert(getNumericId($fullid), 10, 36);
}
function getNumericId($fullid) {
$numid = substr($fullid, strpos($fullid, "-")+1);
$numid = intval($numid);
return $numid;
}
?>
...
{$shortlink}
...<a href...> should appear.
1 to 1 of 1