1 (edited by Helid 2012-06-03 13:02)

Topic: [Extension] Punbb SEO

Today I written my first extension named Punbb SEO. It is simple modification, which add some more seo options.
Functions:
- auto nofollow to all links
- anty duplicate content like redirect from viewtopic.php?pid=4 to topic4-topic-name.html
- title in the form: "topic name - category - forum name"
- h2 in bredcrumbs

That's all, but I will try to add more options over time

1.0.1 - http://pastebin.com/GvJGJysL

I am waiting for comments smile.

2

Re: [Extension] Punbb SEO

Brilliant I was going to make the same myself!

I don't seem to be able to get the redirects to work properly. It works fine for forum redirects but: viewtopic.php?id=37443 doesn't work.

One question, what are you doing in the fn_generate_crumbs_end hook? (I haven't looked at the core code).

It would be even better if you can put it into Github.

Re: [Extension] Punbb SEO

really usefull thanks, i suggest install it on new forums and not in old forum with radicated serp results

4

Re: [Extension] Punbb SEO

SiCo wrote:

Brilliant I was going to make the same myself!

I don't seem to be able to get the redirects to work properly. It works fine for forum redirects but: viewtopic.php?id=37443 doesn't work.

One question, what are you doing in the fn_generate_crumbs_end hook? (I haven't looked at the core code).

It would be even better if you can put it into Github.

On my punbb the redirects work properly, what type of rewriting do you use?

In fn_generate_crumbs_end I am changing title from something like "Topic Name (Pages 1)"  to "topic name - category - forum name". In the future I would like to create configuration for title in admin panel (field with variables: %topic_name%, %category_name%, %forum_name%, %page% - like in wordpress).

5 (edited by Quadric 2011-12-14 22:04)

Re: [Extension] Punbb SEO

Hi Helid. Your extension is very useful but i've got the same problem as SiCo.

The problem is that You've made a redirect for viewforum.php?id= and viewtopic.php?pid= but not for viewtopic.php?id=

In Hook: vt_modify_topic_info you check if there is $pid != 0. It works for viewtopic.php?pid= which is for "view post" But there is another version for viewing topic = viewtopic.php?id= This is when You click topic on viewforum list. then $pid param will always be 0 that's why it doesn't work.

So your extension should handle viewtopic with $id and $pid params. Could you please update your extension to make it work for post and topic?

And a suggestion: I'm not an expert but i think you should die/exit script after making header with location to prevent code execution

Re: [Extension] Punbb SEO

@Helid: Are you going to be able to make the changes suggested by Quadric? Would be good!
If not maybe someone else would like to make the changes and re-release?

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE extension SYSTEM "ext-1.0.dtd">

<!--
/**
 * Add more seo options
 *
 * @copyright Copyright (C) 2011 Helid
 * @license http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
 * @package pun_seo
 */
-->

<extension engine="1.0">
    <id>pun_seo</id>
    <title>Punbb SEO</title>
    <version>1.0.0</version>
    <description>Add more seo options.</description>
    <author>Helid</author>

    <minversion>1.4</minversion>
    <maxtestedon>1.4</maxtestedon>

    <hooks>
        <hook id="vf_modify_forum_info"><![CDATA[
            $seo_url = forum_sublink($forum_url['forum'], $forum_url['page'], (isset($_GET['p']) ? $_GET['p'] : 1), array($id, sef_friendly($cur_forum['forum_name'])));
            if ($seo_url !== get_current_url())
            {
                header("Location: $seo_url", true, 301);
            }
        ]]>
        </hook>
        <hook id="vt_modify_topic_info"><![CDATA[
            $seo_url = forum_sublink($forum_url['topic'], $forum_url['page'], (isset($_GET['p']) ? $_GET['p'] : 1), array($id, sef_friendly($cur_topic['subject'])));
            if ($seo_url !== get_current_url() && $pid != 0)
            {
                header("Location: $seo_url", true, 301);
            }
        ]]>
        </hook>
        <hook id="ps_handle_url_tag_start"><![CDATA[
        if (!$bbcode)
        {
            $full_url = str_replace(array(' ', '\'', '`', '"'), array('%20', '', '', ''), $url);
            if (strpos($url, 'www.') === 0)            // If it starts with www, we add http://
                $full_url = 'http://'.$full_url;
            else if (strpos($url, 'ftp.') === 0)    // Else if it starts with ftp, we add ftp://
                $full_url = 'ftp://'.$full_url;
            else if (!preg_match('#^([a-z0-9]{3,6})://#', $url))     // Else if it doesn't start with abcdef://, we add http://
                $full_url = 'http://'.$full_url;
        
            if (defined('FORUM_SUPPORT_PCRE_UNICODE') && defined('FORUM_ENABLE_IDNA'))
            {
                $link_name = ($link == '' || $link == $url) ? $url : $link;
                if (preg_match('!^(https?|ftp|news){1}'.preg_quote('://xn--', '!').'!', $link_name))
                {
                    $link = $idn->decode($link_name);
                }
            }

            $link = ($link == '' || $link == $url) ? ((utf8_strlen($url) > 55) ? utf8_substr($url, 0 , 39).' … '.utf8_substr($url, -10) : $url) : stripslashes($link);
            return '<a href="'.$full_url.'" rel="nofollow">'.$link.'</a>';
        }
        ]]>
        </hook>
        <hook id="fn_generate_crumbs_end"><![CDATA[
        if ($reverse)
        {
            $items = count($forum_page['crumbs']);
            $last_item = $items-1;
            $before_last_item = $items-2;
            if($items > 1)
            {
                if($forum_page['crumbs'][$last_item][0] != $forum_page['crumbs'][$before_last_item][0])
                {
                    $crumbs = $forum_page['crumbs'][$last_item][0].' - '.$forum_page['crumbs'][$before_last_item][0].' - '.$forum_page['crumbs'][0][0];
                } else {
                    $crumbs = $forum_page['crumbs'][$before_last_item][0].' - '.$forum_page['crumbs'][0][0];
                }
            } else {
                $crumbs = $forum_page['crumbs'][0];
            }
        }
        ]]>
        </hook>
    </hooks>
</extension>

Re: [Extension] Punbb SEO

I've fixed it and add some more features:

http://punbb.informer.com/forums/topic/ … optimizer/

8

Re: [Extension] Punbb SEO

¿Has do you got a Demo?

9 (edited by Helid 2012-06-03 13:02)

Re: [Extension] Punbb SEO

I released a new version, in which I added "<h2>" to topic breadcrumbs.
http://pastebin.com/GvJGJysL

Re: [Extension] Punbb SEO

I am trying to understand it.

11

Re: [Extension] Punbb SEO

@up What do you mean?

Re: [Extension] Punbb SEO

Hi!
Can anyone say, where edit (what file) to add nofollow to links on users profile?