2 caschy Jul 17, 2005 19:04

Here's a new and improved version of Link-a-word:
<?php
/**
* This file implements the LinkWord plugin for b2evolution
*
* Automatic Linking of key words
*
* This hack is based ENTIRELY on Isaac's {@link http://isaacschlueter.com/} groovy
* AutoAcro plugin, and was converted to LinkWord by EdB {@link http://wonderwinds.com/}
*
* b2evolution - {@link http://b2evolution.net/}
* Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
* @copyright b2evolution (c)2003-2004 by Francois PLANQUE - (@link http://fplanque.net/)
*
* @package plugins
* @subpackage renderers
*/
if( !defined('DB_USER') ) die( 'Please, do not access this page directly.' );require_once dirname(__FILE__).'/../renderer.class.php';
class linkword_Rendererplugin extends RendererPlugin
{
var $code = 'LinkWord';
var $name = 'Link-A-Word';
var $priority = 40;
var $apply_when = 'opt-out';
var $apply_to_html = true;
var $apply_to_xml = true;
var $short_desc;
var $long_desc;/**
* LinkWord array - this is where you set up your keywords and associated URLs
*/
var $search = array();
var $replace = array();/**
* Constructor
* {@internal linkword_Rendererplugin::linkword_Rendererplugin(-)}}
*/
function linkword_Rendererplugin()
{
$filename = dirname(__FILE__).'/../../skins/custom/wordlinks.txt';
$linkwords = fopen($filename,"r");while(!feof($linkwords))
{
$values = preg_split("/:/",rtrim(fgets($linkwords)),3,PREG_SPLIT_NO_EMPTY);
$this->link_search[] = '/\b('.$values[0].')\b/i';
$this->link_replace[] = '<a title="'.$values[1].'" href="http://'.$values[2].'">$1</a>';
}fclose($linkwords);
$this->short_desc = T_('Automagically link to sites you like');
$this->long_desc = T_('Words added to the plugin array will automatically be linked to the designated URL./**
* Perform rendering
* {@internal linkword_Rendererplugin::render(-)}}
*
* @param string content to render (by reference) / rendered content
* @param string Output format, see {@link format_to_output()}
* @return boolean true if we can render something for the required output format
*/
function render( & $content, $format )
{
if( ! parent::render( $content, $format ) )
{ // We cannot render the required format
return false;
}$content = preg_replace( $this->link_search, $this->link_replace, $content,1 );
$content = preg_replace( '#(<[^<>]*)(<[A-Za-z]+[^>]*>)(.*)(</[A-Za-z]+>)([^<>]*>)#', '$1$3$5', $content);
return true;
}
}// Register the plugin:
$this->register( new linkword_Rendererplugin() );?>
Each line of the wordlinks file should have this format:
keyword:tooltip:link
A quick example:
b2evo|blog:Everyone's favourite:www.b2evolution.net
slashdot:Geek news:slashdot.org
The first token allows to use OR expressions and you should bear in mind that you may not include the separator : in any of the strings, unless you change the separator to something else.
Also, you should change the file path to whatever suits your needs.
Can anyone check this code?the php syntax is bugy and give back an error.
greetz
kuschti
How to install?