Not signed in ( Sign In)


Welcome, Guest

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.

    • CommentTimeAug 25th 2009 edited
    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.

    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.

    To make it work the .htaccess which is used by the pretty URLs plugin, has to be active, of course.

    Plugin Name: shorturls
    Version: 0.1
    Plugin URI:
    Author: Paul Wellner Bou
    Author URI:

    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))

    $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
    $url = _permalink($id, $contents['subject']);
    $url = BLOG_BASEURL . "?x=entry:$id";
    header("Location: $url");

    # copied and adjusted from plugin.prettyurls.php
    function _permalink($id, $title) {
    $title = sanitize_title($title);
    $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;


    You can test it here:

    Of course, if you want to output the hyperlink within the blog entry, the template has to be modified, putting


    Where the <a href...> should appear.