Recent Topics

1 Feb 24, 2005 18:48    

I know how you feel! You get tired of clicking the little linky button every time you want to link to the same old site you always link to. You *wish* there was an automatic way to tell this thing "just link BillyBob to the URL I always link BillyBob to", and now there is! Presenting
* Link-A-Word *
The worlds FIRST plugin designed to link key words to specified URLs... for b2evolution... by EdB.
WooHoo! Yea! Hurrah!

<?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 $replacements = array(
											'b2evolution' => 'http://b2evolution.net/',
											'b2evo' => 'http://b2evolution.net/',
											'EdB' => 'http://wonderwinds.com/',
											'google' => 'http://www.google.com/',
											'W3C' => 'http://www.w3.org/',
											);
	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 = false;

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

?>

You will of course want to edit the LinkWord array to suit your tastes. Since I'm one of those obnoxious people who launch new windows from links inside posts this here thingie has the option to do that, but it defaults to "don't be rude". That'd be the $new_window = false bit.

I tested it on a pretty much plain-jane v11 installation and verified that new_window=true works, the key words are case sensitive, the key words have to be flanked by non-alphanumeric characters, key words already enclosed in another tag don't get renderated, and something else really special but I forget what.

As I say in the plugin, this is based entirely on Isaac's [url=http://forums.b2evolution.net/viewtopic.php?t=1655]AutoAcro plugin[/url].

EDIT: I just now changed the "apply to xml" param to true, though I haven't tested what happens. Seems to me a no-brainer though since one would want the link to be part of the sidnikashun feed.

2 Feb 25, 2005 20:26

Something bugs me about this. It makes the URL be the title for the link, which is okay I guess, but I wish I knew how to make it have user-defined text for the title. In other words I type BillyBob so it links to http://fakedomain.com and give a title of "BillyBob's lame web". Any takers?

3 Feb 26, 2005 01:17

Very cool. I'm messing around with it on my site. Ha! And it seems to handle two or three grouped words just fine too, as long as neither of the grouped words are already defined (in which case, it reverts to the single-word) :D

4 Feb 26, 2005 05:35

I'm guessing, but would that be order-dependent in your LinkAWord list? Like if your linkaword array has 'cream' then 'ice cream' ice cream never gets linked because cream comes first? So maybe moving 'ice cream' above 'cream' would do it?

Hmmm. I like ice cream AND I like Cream. SWLABR still kicks it hard.

Never actually tested it with multiple term linkables. Since I copied the auto-acro thing it just never crossed my feeble mind. Personally I'm still trying to figure out what I would want to link to frequently. Now that I know I can link multiple words I think I'll link "I landed" to my local hospital. (that's a hang gliding joke, sort of.)

5 Feb 26, 2005 11:57

First off, I don't have the latest .11 version and this works fine in 0.9.0.9 except for one thing.
The linkword cannot be the starting or ending word within <p>tags or <div>'s. They just wont render for some reason!!!

Any ideas?

6 Feb 26, 2005 12:09

Leaving a single space fixes this issue BTW

8 May 31, 2005 21:02

I just installed this and made my first post using it, very nice. It was my first plug-in install for B2evo so there was a little confusion there but it still only took about fifteen minutes to go from copy/pasting to test posting with some of my own keywords added. This is a great tool for those of us who regularly refer to other pages on our own sites or other people's sites. To maximize google results I like to link whenever it's reasonable and this lets me set up all my common links and not waste time entering them every time. I haven't exhaustively tested it yet but it handled "EdB's" just fine and your brief explanation of how the array order would influence things let me avoid potential hitches with that as well.

Here's a [url=http://www.rwphoto.easyhost4all.info/b2/]link[/url] to the first post using Link-A-Word. It's a live link to the main blog so it won't always be the first post, but I see no reason why it won't always show an example of this helpful plug-in's handiwork.

Now to see if I can find something similar for phpBB :D That would make this a productive day even if I got nothing else done.

9 Jun 10, 2005 22:16

EdB,

I thought about editing it to use a table.
But i am untill now not familiar with how plugins work.

I tried to slightly change your code to use a table for it.
Mysql table : evo_linkword
[ 2 fields of 150 varstring ] [as word, link ]

code is used :

$result = $DB->get_results("SELECT * FROM evo_linkword"):
$replacements = $results[0];

But it didnt work for some reason.

any idea ?

Regards,
Raptor

10 Sep 08, 2005 19:38

Sounds great! But it seems not work with version 0.9.0.12 b2evo now. Can u make it suit please. Thanks.

11 Sep 08, 2005 20:18

I'm using it on v12, so I'm sort of thinking it does work. Can you show us where it's not working? Do you get an error, or it just doesn't make linkage for you? How about showing us a post with something that should've been turned into a link but wasn't?

No promises, but if I can make it work for you I will.

12 Sep 08, 2005 20:57

Thanks for your time!

I only change for key word links, here is the code i changed:

	var $replacements = array(
											
											'b2evolution' => 'http://b2evolution.net/',
											'b2evo' => 'http://b2evolution.net/',
											'EdB' => 'http://wonderwinds.com/',
											'StarForum' => 'http://bbs.toustar.com/',
											'starforum' => 'http://bbs.toustar.com/',
                                            'StarBlog'=> 'http://blog.toustar.com/',
                                            'starblog'=> 'http://blog.toustar.com/',
											'toustar' => 'http://www.toustar.com/',
											
											);
	var $search = array();
	var $replace = array();

And as u said, I put it in fold: *mysite*/plugins/renderers/ as a name: _linkword.renderer.php

A screenshot from my blog after installing Link a Word as bellow:

http://www.toustar.com/photonline/starblog_screenshot.gif

I do added key words like StarBlog/starforum but it seems not make any change.

Forther, if it will be ok. Can it be no case sensitive?

EDIT by EdB: turned off Smilies to get them out of the pasted code

13 Sep 08, 2005 21:22

The screenshot helps. Link-a-word only links words in posts - not comments. I never even thought about making it do comments, but it's probably possible. Same with case-insensitive matching: I never thought about it but it's probably possible. I'm not too sure about case-insensitive matching. I have this feeling it could lead to linking letter strings in the middle of a word. I'll have to think about that a bit, but in the meantime your method of adding both upper and lower case versions works.

BTW I won't do *anything* about this plugin until after phoenix is released. Right now I'm trying to (a) build a wicked-cool open blog app and (b) work on the antispam list and (c) trying to document how to make your skin work in phoenix and (d) trying to make a bunch of existing skins work in phoenix and (e) trying to find myself a job that actually pays me. I'm just not up to tweaking or creating hacks for a version of b2evolution that will be obsolete soon.

Hey I hope you don't mind me editing your post to remove the smilies. It bugs me when code has bunches of => inside is why I did it.

14 Sep 08, 2005 21:48

Yes, u r right! Its not works in comments, but in posts. You got a lot of no pay job to do(what a nice man!) n u do needs to find a paid job. Wish u got one soon! I'll be waiting for the next version of your works. Im now your fans now!

BTW its alright my post got edited, I even dont know how to get them off my post-code before that.

Thanks anyway!

15 Apr 26, 2006 05:13

EdB, this is a gem, and hugely useful for cross-linking posts on my site (I made the link URL search results on my site for that term). Thought I'd share that particular use in case anyone else finds it useful. Thanks!!

16 May 19, 2006 17:40

Hello EdB,
I've read the whole thread and hope I haven't missed out on anything when I ask if'n'wether the database'd version of your fine plugin ever actually was published.

btw, (do) you know the very nifty [url=http://www.bloggingpro.com/index.php?s=Ubernyms]Ubernyms[/url] for Wordpress? I thought you might find this one inspiring.

Looking forward to your reply a lot. Best Regards; Lex

17 May 19, 2006 17:45

Nope - haven't gone near it yet. Kinda mostly waiting for the release of 1.8 so I can do it as a real plugin plugin instead of the kind where you have to hack something.

18 May 19, 2006 17:59

EdB wrote:

Nope - haven't gone near it yet. Kinda mostly waiting for the release of 1.8 so I can do it as a real plugin plugin instead of the kind where you have to hack something.

aw, shucks. :-)
Any reasonable estimate as to when 1.8 be out? (On the site the newest version I saw was 1.6 Phoenix Alpha, I am mostly toying with 0.9.1 Dawn)

more regards, and thx for your swift reply,
Lex (I'll be off now for today)

19 May 23, 2006 19:22

EdB, this works great with 'Sparkle', thanks.

20 Jun 03, 2006 21:53

Hello EdB,
would it also be possible to store the link references in external files? I have things I'd like to auto-link globally (in 2 evos residing site by site on one server), some in Evo A only, others in Evo B only.

I tried replacing


   var $replacements = array(
                                 'b2evolution' => 'http://b2evolution.net/',
                                 'b2evo' => 'http://b2evolution.net/',
                                 'EdB' => 'http://wonderwinds.com/',
                                 'google' => 'http://www.google.com/',
                                 'W3C' => 'http://www.w3.org/',
                                 );


with


   var $replacements = array(
{include file="links-global.txt"}
{include file="links-pri.txt"}
);


which didn't work due to the brackets (duh), giving me this error

Parse error: parse error, unexpected '{', expecting ')' in [...]/lexnet/pri/plugins/renderers/_link-a-word.renderer.php on line 36

is there an other way to notate includes inside of the array brackets? Please bear with me since I am none to experienced with PHP so far .. (sometimes I get things to work the way I want them to and other times, well, not. ;) ) Live and learn, I say! So, is there a way I can accomplish calling the links from external files?

TIA! Best regards,
lex

21 Jun 03, 2006 22:20

Using an external file, or a table in the database, are pretty straightforward ideas that I never thought of and never got around to even trying. Bummer, but all I do is tweak what I see without really *thinking* about it. In general I haven't really paid much attention to older hacks, but perhaps I should come back to this one now that sparkle is out. Apparently it works in sparkle, so I should put some effort into bumping it up a notch or two. If you beat me to it please share your improvements with the world!

22 Jun 03, 2006 22:28

LOL, unlikely I'll manage. I don't even know how to make brackets inside brackets work - or how to write it differently.
But I'll still try. Heck, I'll walk by #php right bloody now and see if I can turn up any takers :D
I'll let you know should I get anywhere. Best regards,
lex

23 Jun 03, 2006 22:38

Totally off the top of my head :-

$replacements = file('links-global.txt');
$replacements += file( 'links-pri.txt');

I've got a 1.6 db driven plugin thing if you want to play with it EdB ?

¥

24 Jun 03, 2006 22:50

Hello Yabba, and thanks for stepping in;
tried your suggestions right away (like

   var $replacements = array(
	$replacements = file('links-global.txt');
	$replacements += file( 'links-pri.txt'); 
);


) but got

Parse error: parse error, unexpected T_VARIABLE, expecting ')' in [...]lexnet/pri/plugins/renderers/_link-a-word.renderer.php on line 36

maybe something with the semicola? *guessing wildly*

btw, #php crowd on freenode.net prefers to give me lecutrings instead of hints

[...][22:41] <php-bot> Guideline #10) We don't support script(s). We help you *write* PHP, not recommend or download and install/hack/modify/adapt/use pre-written scripts. Contact the authors of the script for support options they provide.
[...]
[22:43] <RiPLeX> actually i was asking for the proper PHP method to include includes inside a array [...] Please?

Oh well, I'll keep scratching.

25 Jun 03, 2006 23:20

[22:57] <RiPLeX> rephrased question: how can I properly include references to external file/s inside a var $name = array( ); ?
[22:58] <Wolfpaws> you can't?
[22:58] <RiPLeX> ah LOL is that so?
[...][23:00] <RiPLeX> what do you think about using: $replacements = file('name.txt');
[...][23:00] <Wolfpaws> RiPLeX: I think it's sexy
[23:01] <RiPLeX> still gives me an error ;-` and I don't know enough PHP to figure out where I went wrong
[...][23:02] <Wolfpaws> I can't understand what you're doing... Are you trying to included that in the class variable declaration?
[23:02] <RiPLeX> yeah, I guess ...
[23:03] <Wolfpaws> you *can't* do that
[...][23:04] <RiPLeX> aw :-(
[...][23:05] <RiPLeX> so I'll always have to edit the (page).php itself whenever I want to add a new autolink?
[23:05] <Wolfpaws> no need...
[23:06] <Wolfpaws> Where do you have the links stored?
[...][23:06] <RiPLeX> wait a sec ill pastebin it
[...][23:09] <RiPLeX> @Wolfpaws: http://pastebin.com/756394
[...][23:13] <Wolfpaws> RiPLeX: you can put them in the file/db and then do the $this->replacement magic in constructor
[...][23:15] <RiPLeX> @Wolfpaws: constructor? :-0 I don't understand what you are telling me, sorry. Is there an URL wehre I can read up on this that you could tell me?
[...][23:17] <Wolfpaws> RiPLeX: php.net/oop
[...][23:19] <RiPLeX> thx I'll go look it up

26 Jun 03, 2006 23:43

hum, after reviewing http://de3.php.net/oop and http://de3.php.net/manual/de/language.oop.constructor.php
(not really understanding too much) I tried this:


   var $replacements = array(
   function B()
   {
       include file="..\..\..\links-global.txt";
       include file="..\..\..\links-pri.txt";
   }
// calling B() as constructor.
$b = new B;
);


but still: no cake:

Parse error: parse error, unexpected T_FUNCTION, expecting ')' in [...]/lexnet/pri/plugins/renderers/_link-a-word.renderer.php on line 36

I guess I'll call it a day :(

27 Jun 04, 2006 07:51

Instead of :-

 var $replacements = array(
   $replacements = file('links-global.txt');
   $replacements += file( 'links-pri.txt');
);

just use :

 var $replacements = file('links-global.txt');
   $replacements += file( 'links-pri.txt');

¥

28 Jun 04, 2006 14:30

hey, Yabba; thx
putting your suggestion gives me

Parse error: parse error, unexpected '(', expecting ',' or ';' in [...]/lexnet/pri/plugins/renderers/_link-a-word.renderer.php on line 36

and .. if we remove the


 var $replacements = array(
); 


isn't the


   var $search = array();
   var $replace = array();


bound to fail?

thx! l8rs,
lex

29 Jun 04, 2006 15:56

The file() command reads a file in as an array, try this instead :-


   function linkword_Rendererplugin()
   {
      $this->replacements = file('links-global.txt');
      $this->replacements += file( 'links-pri.txt'); 

¥

30 Jun 04, 2006 18:43

Hello Yabba; OK, It took me a while to figure out that your latest suggestion belongs a bit futher down into the file, around line 50, and have put the two lines

      $this->replacements = file('links-global.txt');
      $this->replacements += file( 'links-pri.txt'); 


immediately afte the line

   function linkword_Rendererplugin()
   { 


already there. This acesses the files (giving absolute URLs) just fine, however: the rendering doesn't work anymore now.
The referred files contain just what was in the original array brackets in EdB's code, no leading or trailing whitespace.
Now what? I'll attach the renderer file for review.
Clueless,

'lex

31 Jun 05, 2006 16:10

Hey, Crowd,
by chance I have discovered that the tinkered version indeed does access the files, just output the stored information in an unwanted manner. :-)

Nothing happened as long as I just posted with text only.

However, when I did a test posting employing [url=http://forums.b2evolution.net/viewtopic.php?t=3562&highlight=b2media]Danny's fine Amazon Plugin B2Media[/url], all of a sudden a line from the external test-file for Link-A-Word showed up, in there it says

'b2evolution' => 'http://b2evolution.net/',

like it would have in EdB's original array.
Now, instead of rendering the line to link/s, it seems to deliver the HTML of the line following criteria I have not yet transscended:

=> 'http://b2evolution.net/',
" title="'b2evolution' => 'http://b2evolution.net/',
" target="_blank">0" alt="" />

Potential conflict with the Emoticon renderer turning the arrow (equal-sign-greater-than-sign) into an arrow icon?

I'll attach a screencshot for further illustration.
Best regards, 'lex

32 Jun 06, 2006 10:12

Sorry for the delay, I've been wandering around in a field for the last couple of days :p

There was a smidge of an error in my logic, change these two lines :-

      $this->replacements = file('links-global.txt');
      $this->replacements += file( 'links-pri.txt');

to :-

require_once dirname(__FILE__).'/links-global.txt');
require_once dirname(__FILE__). '/links-pri.txt');

And then change your two text files to :-

$this->replacements += array (
// current file contents
);

¥

33 Jun 06, 2006 12:46

Hello Yabba,

hum; I have done as advised, at first slamming into a wall of errors. I then enclosed the textfiles content including your suggested changes into php brackets, so they look like this now:

<?php
$this->replacements += array ( 
'b2evolution' => 'http://b2evolution.net/',
[i]{etc.}[/i]
);
?>

and

<?php
$this->replacements += array (
'pri' => 'http://www.test.de',
);
?>


respectively.
I now 'only' receive a one line error

Fatal error: Unsupported operand types in [...]/lexnet/links-global.txt on line 9

Line 9 in the file in question is the line having the ");"
If remove the "<?php" .... "?>" in links-global.txt I get

$this->replacements += array ( 'b2evolution' => 'http://b2evolution.net/', 'b2evo' => 'http://b2evolution.net/', 'EdB' => 'http://wonderwinds.com/', 'google' => 'http://www.google.com/', 'W3C' => 'http://www.w3.org/', 'global' => 'http://www.alexandermaiwald.de/', );
Fatal error: Unsupported operand types in [...]/lexnet/links-pri.txt on line 4

Line 4 in links-pri.txt again has the ");". If I remove the PHP brackets here as well I get

$this->replacements += array ( 'b2evolution' => 'http://b2evolution.net/', 'b2evo' => 'http://b2evolution.net/', 'EdB' => 'http://wonderwinds.com/', 'google' => 'http://www.google.com/', 'W3C' => 'http://www.w3.org/', 'global' => 'http://www.alexandermaiwald.de/', );$this->replacements += array ( 'pri' => 'http://www.alexandermaiwald.de/pri', );
Warning: Invalid argument supplied for foreach() in [...]/lexnet/pri/plugins/renderers/_link-a-word.renderer.php on line 60

Warning: Empty regular expression in [...]/lexnet/pri/plugins/renderers/_link-a-word.renderer.php on line 89

Warning: Empty regular expression in [...]/lexnet/pri/plugins/renderers/_link-a-word.renderer.php on line 90

Maybe I did something wrong about the order in which the stuff is in the renderer? I'll attach the file in it's latest tinkered version for review.

Maybe I should just leave it be and enter the links in EdB's originally intended manner? This is getting to time consuming, me thinks. Unless, of course, you are feeling ambitious about getting this to work - then I'll be trying to hobble along :-)
Best regards,
'lex

34 Jun 06, 2006 13:03

Ok, your text files should have the <?php ?> tags.

Try this and see if it cures your errors

¥

35 Jun 06, 2006 13:22

YAY! It works! Incredible!! Teriffic!! Thanks!!!! :D

36 Jun 06, 2006 13:49

I get there eventually :p

¥

37 Jun 06, 2006 14:10

heh :D winning attitude, if I ever saw one! Kudos to you,
sends 'lex

38 Oct 11, 2006 20:32

Sadly, I've not been able to get 1.8.2 to recognize or use this plug in.


Form is loading...

Photo albums software – This forum is powered by b2evolution CMS, a complete engine for your website.