Textpattern Forum

You are not logged in. Register | Login | Help

#11 2012-04-02 22:51:12

Tomsec
Plugin Author
Registered: 2012-03-31
Posts: 7
Website

Re: tps_spoiler - Spoiler plugin to quickly hide and unhide text

Updated to V 1.0 and hopefully final.

By the way is there a plugin, that can parse ALL kind of links and sets the rel-Attribute to “nofollow”? (Since I wanna mess around with google and try how it behaves on that move).

I know for your rah-urltolink plugin there is an option, but only for the links it creates itself.
My current approach is to take the PHP DOMDocument, pars the posts HTML and check all links in it. This has the bad side effect, that you have to do some nasty stuff to deal with UTF-8 (at least following the comments at php.net) and some other nasty stuff to get rid of the auto added html- and body-tag.

The result is currently working, but not really efficient and to nasty to be ever released. Thats why I asked for a plugin. I could not get a hold of zem_prblock, since the source code seems to be gone. :(

Offline

#12 2012-04-02 23:27:38

uli
Moderator
From: Cologne/Köln
Registered: 2006-08-15
Posts: 3,043

Re: tps_spoiler - Spoiler plugin to quickly hide and unhide text

Tomsec wrote:

I could not get a hold of zem_prblock, since the source code seems to be gone. :(

My HD is a treasury :)

function zem_prblock_replace($attr, $type='nofollow') {
    global $siteurl, $zem_prblock_atts;

    $atts = @splat($attr);

    $link = @$atts['href'];
    if ($link) {
        $url = parse_url($link);
        $mydomain = preg_replace('/^www\./', '', $siteurl);
        $linkdomain = preg_replace('/^www\./', '', @$url['host']);

        if ($linkdomain and @$url['scheme'] == 'http' and $linkdomain != $mydomain) {
            if ($type == 'nofollow') {
                $atts['rel'] = 'nofollow';
            }
            else {
                $atts['href'] = 'javascript:;';
                $atts['onClick'] = "window.location.href='$link'; return false;";
            }

        if (is_array($zem_prblock_atts))
            $atts = array_merge($atts, $zem_prblock_atts);
        }
    }

    $out = '';
    foreach ($atts as $k=>$v) {
        $out .= ' ' . $k . '="'.$v.'"';
    }

    return '<a'.$out.'>';
}

function zem_prblock($atts, $thing) {
    global $zem_prblock_atts;

    $type = isset($atts['type']) ? $atts['type'] : 'nofollow';
    $zem_prblock_atts = $atts;
    unset($zem_prblock_atts['type']);

    $out = parse($thing);

    return preg_replace('@<a\s+([^>]+)>@ei', "zem_prblock_replace(\"\\1\", \"$type\")", $out);
}

In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#13 2012-04-02 23:55:51

Tomsec
Plugin Author
Registered: 2012-03-31
Posts: 7
Website

Re: tps_spoiler - Spoiler plugin to quickly hide and unhide text

Hey cool, thanks a lot.

That approach does look better than mine. Hopefully Google will get this code, so other can find it too :)

Offline

Board footer

Powered by FluxBB