joomla/plg_hotlink/hotlink.php

<?php
defined( '_JEXEC' ) or die( 'Restricted Access');
jimport('joomla.plugin.plugin');

class PlgContentHotlink extends JPlugin {
    function __construct(&$subject, $config) {
        wktrace("hotlink construct config:", $config);
        parent::__construct( $subject, $config );
    }

    public function onContentPrepare($context, &$article, &$params, $page = 0)
    {
        $cat = JCategories::getInstance('Content')->get()->getChildren()[0]->id; # any non root category will do
        wktrace("hotlink $context firstCat=$cat params:", $this->params);
                $u = JUri::getInstance();
        wktrace(null, "hotlink JUri base()=" . $u->base() . ' root()=' . $u->root(), $u);

        $regex = "/{hotlink=([^\s]*)\s*name=([^}]*)}/";
        $href = 'index.php?option=com_content&view=article&id=$1&catid=' . $cat . '&Itemid=101';
        $repl = '<a href="' . $href .'">$2 href='. $href .'</a>';
        $article->text = preg_replace($regex, $repl, $article->text);

        $image = $this->params->get('image', 'globe3.png');
#        $imH = " <img src='media/system/images/$image' border='0'> ";
#                   get correct uri prefix!
        $imH = " <img src='" . JUri::getInstance()->base() . "media/system/images/$image' border='0'> ";
        wktrace(null, "hotlink image $image");
        
        $regex= "#(<a\shref=[^>]*>([^<]*))</a>#";
        $repl = '$1' . $imH . '</a>';
        $article->text = preg_replace($regex, $repl, $article->text);

    }
}
?>