MyBB Community Forums

Full Version: Need help with my first plugin
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
Well I'm working on my first plugin and I'm still new to PHP so could you give me some help with this?

The plugin is supposed to change links to adf.ly links.

[Removed Source]

I'm getting this error:

Warning [2] Missing argument 2 for adfly_changelinks() - Line: 24 - File: C:\wamp\www\mybb1412\inc\plugins\adfly.php
I suggest actually learning PHP, and not just copying code hoping that it'll work.
In other words, the function doesn't really make sense.
Well what doesn't really make sense about it? I don't see anything wrong with using other plugins to learn what to do.
(2010-04-14, 10:57 PM)RPicard Wrote: [ -> ]Well what doesn't really make sense about it?
The code. It's totally WTF.

(2010-04-14, 10:57 PM)RPicard Wrote: [ -> ]I don't see anything wrong with using other plugins to learn what to do.
That's fine, but only if you actually understand what this other plugin is actually doing.
Do you learn how to be a car racer just by watching racing cars drive around a track?
Well I thought I knew what it was doing. It's searching for the line '$link = "<a href=\"$fullurl\" target=\"_blank\">$name</a>";' and replacing it with '$link = "<a href=\"http://adf.ly/46497/".$fullurl."\" target=\"_blank\">$name</a>";' using str_replace. I used TimB.'s nofollow plugin as a reference as it edits the same line.

I'd also been reading a few php tutorials to go along with it.
One can only guess what you are trying to achieve there. Maybe str_replace('<a href="', '<a href="http://adf.ly/46497/', $message) would do what you want, while bending standards a little. For a proper solution, preg_replace with a subroutine that provides the correct replacement string, seems to be in order, unless there is a hook that lets you modify URLs directly (or you edit the core code to do so directly).

Why would there be such a line in $message, though?
(2010-04-14, 11:13 PM)frostschutz Wrote: [ -> ]Why would there be such a line in $message, though?

Like I said, I used the nofollow plugin as a reference.



With this code:

[Removed Source]

I'm getting a parse error on the return line.
add the missing ;?
(2010-04-14, 11:52 PM)frostschutz Wrote: [ -> ]add the missing ;?

Ha ha, thanks. Works like a charm now.
(2010-04-14, 11:57 PM)RPicard Wrote: [ -> ]
(2010-04-14, 11:52 PM)frostschutz Wrote: [ -> ]add the missing ;?

Ha ha, thanks. Works like a charm now.

Do you have a demo of this up? looks interesting.
Pages: 1 2 3