Welcome to Geeklog, Anonymous Monday, November 25 2024 @ 02:25 am EST

Geeklog Forums

lib-plugins hack for better autotag support


Status: offline

ByteEnable

Forum User
Full Member
Registered: 10/20/03
Posts: 138
The current lib-plugins.php function PLG_replaceTags breaks when you add autotags and the first parameter contains a ":". So here is a hack to fix that so you can have autotags like the following:

[oslink:http://www.somewhere.com Some Where]

Would then be in html:
Text Formatted Code

<a href="http://www.somewhere.com>Some Where</a>

 

Just FYI: oslink = off site link

Changes in lib-plugins.php, function PLG_replaceTags
Text Formatted Code

$parms = explode (':', $parms[0]);

// START NEW CODE
if ( $parms[2] == '' ) {
                                $p_parms1 = $parms[1];
                        }
                        else {
                                $p_parms1 = $parms[1] . ':' . $parms[2];
                        }
// END NEW CODE
                    $newtag = array (
                        'module'    => $module,
                        'tag'       => $moduletag,
                        'tagstr'    => $tag,
                        'startpos'  => $start_pos,
                        'length'    => $taglength,
                        'parm1'     => $p_parms1, // Replace with new variable
                        'parm2'     => $label
                    );

 


So just after the explode you will want to add the new code, and don't forget to update the $newtag arrary with $p_parms1.

Now you need to add your autotag to the core in function PLG_collectTags
Text Formatted Code

$autolinkModules = array ('story' => 'geeklog','oslink' => 'geeklog','event' => 'geeklog');

 


Next the code needs to be added to substitute the tag with html in function PLG_replaceTags

Text Formatted Code

if ($autotag['module'] == 'geeklog') {
                $url = '';
                $linktext = $autotag['parm2'];
// START NEW CODE
                if ($autotag['tag'] == 'oslink') {
                        $autotag['parm1'] = COM_applyFilter ($autotag['parm1']);
                        $content = str_replace($autotag['tagstr'],'<a href="' . $autotag['parm1'] .'">' . $linktext . '</a>',$content);
                }
// END NEW CODE

 


Thats it.
 Quote

Status: offline

drshakagee

Forum User
Full Member
Registered: 10/01/03
Posts: 231
Just curious but wouldn't it be much easier to just use
Text Formatted Code
[oslink:www.somewhere.com Some Where]
 

then have your plugin add the http:// stuff to it?

Yes I am mental.
 Quote

Status: offline

ByteEnable

Forum User
Full Member
Registered: 10/20/03
Posts: 138
What if the link is:

ftp:// or https://

Then you have to have two more autotags.

Also when cut-n-pasting links, usually the http:// is part of the link already.
 Quote

Status: offline

drshakagee

Forum User
Full Member
Registered: 10/01/03
Posts: 231
Oh that makes sense I never even thought of the ftp:// thing. Thanks for clearing that up, did you submit a patch so your hack can be included in the core?
Yes I am mental.
 Quote

Status: offline

Flernk

Forum User
Chatty
Registered: 07/31/03
Posts: 46
I've been trying to implement this to my own plugins but with no success. I've tried it several times and here is the result...

in the story, I type:

[go:http://www.feb28.com Testing]

(I'm using "go" instead of "oslink")

This is what it's returning:

href="http://www.feb28.com">http://www.feb28.com Testing

and the html code looks like this:
Text Formatted Code
<a href="">href="http://www.feb28.com">http://www.feb28.com</a> Testing</a>
 


It looks like everythings in the wrong order and I have a doubled /a tag, but I can't figure out where I went wrong. Any ideas?

Here is my lib-plugin code for that section with your hacks:
Text Formatted Code
                    $parms = explode (':', $parms[0]);
// START NEW CODE
if ( $parms[2] == '' ) {
                                $p_parms1 = $parms[1];
                        }
                        else {
                                $p_parms1 = $parms[1] . ':' . $parms[2];
                        }
// END NEW CODE
                    $newtag = array (
                        'module'    => $module,
                        'tag'       => $moduletag,
                        'tagstr'    => $tag,
                        'startpos'  => $start_pos,
                        'length'    => $taglength,
                        'parm1'     => $p_parms1, // Replace with new variable
                        'parm2'     => $label
                    );
                    $tags[] = $newtag;

                } else {
                    /* Error tags do not match - return with no changes */
                    return $content . $LANG32['32'];
                }
                $prev_offset = $offset;
                $offset = $end_pos;
            } else {
                $prev_offset = $end_pos;
                $end_pos = $strlen;
                $offset = $strlen;
            }
        }
    }

    // If we have found 1 or more AutoLink tag
    if (count ($tags) > 0) {       // Found the [tag] - Now process them all
        foreach ($tags as $autotag) {
            $function = 'plugin_autotags_' . $autotag['module'];
            if ($autotag['module'] == 'geeklog') {
                $url = '';
                $linktext = $autotag['parm2'];
// START NEW CODE
                if ($autotag['tag'] == 'go') {
                        $autotag['parm1'] = COM_applyFilter ($autotag['parm1']);
                        $content = str_replace($autotag['tagstr'],'<a href="' . $autotag['parm1'] .'">' . $linktext . '</a>',$content);
                }
// END NEW CODE

 


Any ideas?
 Quote

Status: offline

Flernk

Forum User
Chatty
Registered: 07/31/03
Posts: 46
After playing with it for a while, it seems to only allow a single character after http://

so I can have http://w or http://f and it will work fine, but as soon as it becomes http://ww or http://fe it fails and creates what I just posted.

Does that make any sense to anybody?
 Quote

All times are EST. The time is now 02:25 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content