Recent Topics

1 Feb 17, 2006 23:36    

Hereunder you can find the plugin that EdB and Isaac pulled together for 0.9.x.
I loved that plugin, but I'm in no condition to turn that to the new plugin system.
For the coders among us, it will be a peace of cake, I'm shure.

For those up to a chalenge, it would be awsome, if we could edit this file (= add more links) through the backoffice.

<?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/}
 *
 * Scroll down to 'var $replacements' to add your own keywords and associated
 * URLs.  Keywords can be single words or phrases, but in order to be linked 
 * the text you type must match exactly what you have in here (case-sensitive).  
 * Keywords that are part of other tags will not be linked.  Keywords in your 
 * text must be preceeded and followed by non-alphanumeric characters.
 *
 * I suggest giving this a low priority number so that rendering happens early.
 *
 * Save this file as '_linkword.renderer.php' in your toolbars/renderers folder.
 *
 * 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 = 14;
	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 $replacements = array(
'b2evolution' => 'http://www.b2evolution.net/',
'b2evo' => 'http://www.b2evolution.net/', 
'b2e' => 'http://www.w3.org/',
'google' => 'http://www.google.com/',
'Hospitality Club' => 'http://www.hospitalityclub.org',
'Flickr' => 'http://www.flickr.com',
);
	var $search = array();
	var $replace = array();

	/**
	 * Constructor
	 * {@internal linkword_Rendererplugin::linkword_Rendererplugin(-)}}
	 */
	function linkword_Rendererplugin()
	{
		/**
		 * do you want links to open in new windows?  Some folk consider it rude, but
		 * some folk consider it okay.  Since I have links in posts open new windows
		 * I figured I better add the option to the plugin so's it would be what I
		 * want it to be.  Default is to NOT launch new windows.  Change to 'true' if
		 * you want to be rude and obnoxious to your visitors... like me.
		 */
		$new_window = true;

		foreach( $this->replacements as $k => $v ) {
			$this->link_search[] = '#(^|[^0-9A-Za-z>./:?!$_])(' . $k . ')([^0-9A-Za-z<:_])#';
			$this->link_replace[] = '$1<a href="' . $v . '">$2</a>$3';
			$this->linktitle_search[] = '#(<a href="[^"]*")(>)(' . $k . ')(</a>)#';
			if( $new_window ) {
				$this->linktitle_replace[] = '$1 title="' . $v . '" target="_blank"$2$3$4';
				} else {
				$this->linktitle_replace[] = '$1 title="' . $v . '"$2$3$4';
				}
			}
		$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. Key words are case sensitive!  Key words must be preceeded and followed by a non-alphanumeric [0-9A-Za-z] character. Key words are checked to see if they are already enclosed by some other tag. Open up $blogurl/plugins/renderers/_linkword.renderer.php to edit the list of key words and their URLs.');
		}

	/**
	 * 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 );
		$content = preg_replace( $this->linktitle_search, $this->linktitle_replace, $content );
		// strip out tags within tags
		$content = preg_replace( '#(<[^<>]*)(<[A-Za-z]+[^>]*>)(.*)(</[A-Za-z]+>)([^<>]*>)#', '$1$3$5', $content);
		return true;
		}
	}

// Register the plugin:
$this->register( new linkword_Rendererplugin() );

?>

2 Feb 18, 2006 04:42

Hi Topanga. I was figuring on doing this plugin again but not until we have a reasonably stable target. If I make it be 1.6 compliant it'll be no good as soon as 1.7 (or whatever it'll be called) is available.

From the beginning the idea of having to hack files for a plugin didn't make sense, but it was all I knew how to do. Hopefully when we start seeing some other groovy plugins, or a list of hooks and what they do, I'll be able to make this one work the way you describe.

Unless someone smart beats me to it 8|

3 Feb 18, 2006 11:03

Then I'll have the patience to wait till plugins-definitions in 1.7 are stable.

Looking forward to it.


Form is loading...