SEO premod and SocialNet 0.5.2

phpBB SEO Premod for phpBB3 support forum.
This premodded version of phpBB3 includes the three different type of URL rewriting for phpBB3 by phpBB SEO. It comes with several other Search Engine Optimization mods installed.

Moderator: Moderators

SEO premod and SocialNet 0.5.2

Postby scworldnetter » Thu Apr 14, 2011 2:54 pm

I am using SocialNet 0.5.2 with my now premodded board ( 3.0.8 ), I have the "SID Removing" function turned on.

The important links that require SID like logout and other things are still getting the SID, which is good and as expected. However, I installed SocialNet 0.5.2, it's still early in its lifecycle, so I am making code modifications to it to get it to work the way I need to to.

The original 0.5.2 code isn't compatible with mod SEO, that much I've figured out, so I've started to make the required modifications to the mod. The biggest issue is that the newsfeed, a.k.a. "Wall" in that weird things are happening to URLs passed through via the append_sid function.

1) Any URL that is PhPBB native, i.e. has ucp or other original PhPBB scripts in it gets a full absolute path, i.e. the full board URL is appended in front of it. But anything not of PhPBB origin, like external page scripts or in this case, the mainpage.php script of the mod, append_sid returns a relative path, i.e. ./phpbbdir. So when I use a mod_rewrite to make the /phpbbdir/mainpage.php the home page via
Code: Select all
RewriteRule ^/?$ /cafe/mainpage.php [QSA,L,NC]

all the relative links of course break. For now, I have the work around to have hard wired my board URLs where ever there is a problem. This is a very unsatisfactory answer, and requires too much maintenance. Any clue why this is happening?

2) Several critical URLs aren't getting an SID when they really need one. For example,
Code: Select all
'U_LOGIN_LOGOUT'       => append_sid("{$phpbb_root_path}ucp.{$phpEx}?mode=logout&redirect={$phpbb_root_path}mainpage.{$phpEx}"), 'S_SN_MP_' . strtoupper($mode)                   => true,

does not return any SID, the SID is stripped.

So what is the code I need to add so that the mod SEO doesn't strip the SID from this URL?

3) The other issue is that the newsfeed spews out the old style URLs rather than the SEO rewritten URLs. I've started to make changes and inserting the proper code there, but this is less critical because I hide the newsfeed from bots since there is nothing of value for the bots to index there. But I still would like coding advice there too so I can learn.

I figured out what to add for the topics retrieval code, but not for the latest posts.

Here's what the function looks like (it is a function, so I need to add the seo global variables.

Code: Select all
         global $db, $auth, $template, $user, $config;
         global $phpbb_root_path, $phpEx;
         global $bbcode_bitfield, $phpbb_seo;

         $a_f_auth_read = $auth->acl_getf('f_read');
         $a_f_read = array();
         if (!empty($a_f_auth_read))
         {
            foreach ($a_f_auth_read as $i_f_id => $a_auth)
            {
               if ($a_auth['f_read'] == 1)
               {
                  $a_f_read[] = $i_f_id;
               }
            }
         }

         // First we fill in the list of top posts that need to be on the front page
         $last_posts = 'SELECT p.post_id, p.topic_id, p.post_time, p.forum_id, t.topic_title, f.forum_name
                  FROM ' . POSTS_TABLE . ' p
                     LEFT JOIN ' . TOPICS_TABLE . ' t ON p.topic_id = t.topic_id
                     LEFT JOIN ' . FORUMS_TABLE . ' f ON p.forum_id = f.forum_id
                  WHERE p.post_approved = 1
                     AND ' . $db->sql_in_set('p.forum_id', $a_f_read, false, true) . '
                  ORDER BY p.post_id DESC';
         $last_posts_result = $db->sql_query_limit($last_posts, $config['mp_num_last_posts']);
         $last_posts_rowset = $db->sql_fetchrowset($last_posts_result);
         $db->sql_freeresult($last_posts_result);

         for ($i = 0; isset($last_posts_rowset[$i]); $i++) //while ($last_posts_row = $db->sql_fetchrow($last_posts_result))
         
         {
            $last_posts_row = $last_posts_rowset[$i];
            $template->assign_block_vars('last_posts', array('TOPIC_TITLE'       => $last_posts_row['topic_title'],
               'POST_LINK'          => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "t=" . $last_posts_row['topic_id'] . "&p=" . $last_posts_row['post_id'] . "#p" . $last_posts_row['post_id']),
               'TOPIC_FORUM'       => $last_posts_row['forum_name'],
               'TOPIC_FORUM_LINK'    => append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=" . $last_posts_row['forum_id']),
               'POST_TIME'          => snFunctions::time_ago($last_posts_row['post_time']),
            ));
         }





         // then we fill in the last five topics
         $last_topics = 'SELECT t.*, p.*, f.forum_name
                  FROM ' . TOPICS_TABLE . ' t
                     LEFT JOIN ' . POSTS_TABLE . ' p ON p.post_id = t.topic_first_post_id
                     LEFT JOIN ' . FORUMS_TABLE . ' f ON f.forum_id = t.forum_id
                  WHERE t.topic_approved = 1
                     AND ' . $db->sql_in_set('p.forum_id', $a_f_read, false, true) . '
                  ORDER BY p.post_id DESC';
         $last_topics_result = $db->sql_query_limit($last_topics, 5);
         $last_topics_rowset = $db->sql_fetchrowset($last_topics_result);
         $db->sql_freeresult($last_topics_result);

         for ($i = 0; isset($last_topics_rowset[$i]); $i++) //
         
         {
            $last_topics_row = $last_topics_rowset[$i];
            
            $topic_text = nl2br($last_topics_row['post_text']);
            $bbcode = new bbcode(base64_encode($bbcode_bitfield));
            $bbcode->bbcode_second_pass($topic_text, $last_topics_row['bbcode_uid'], $last_topics_row['bbcode_bitfield']);
            $topic_text = smiley_text($topic_text);
            
            
            // http://www.phpBB-SEO.com SEO TOOLKIT BEGIN
            // need to properly initialize $phpbb_seo
              if (!empty($last_topics_row['topic_url'])) {
                  $phpbb_seo->prepare_iurl($last_topics_row, 'topic', '');
              } else {
                  if ($phpbb_seo->modrtype > 2) {
                      $last_topics_row['topic_title'] = censor_text($last_topics_row['topic_title']);
                  }
                  $cur_forum_id = (int) $last_topics_row['forum_id'];
                  $parent_forum = $last_topics_row['topic_type'] == POST_GLOBAL ? $phpbb_seo->seo_static['global_announce'] : (!empty($phpbb_seo->seo_url['forum'][$cur_forum_id]) ? $phpbb_seo->seo_url['forum'][$cur_forum_id] : false);
                  if ($parent_forum) {
                      $phpbb_seo->prepare_iurl($last_topics_row, 'topic', $parent_forum);
                  }
              }
              // http://www.phpBB-SEO.com SEO TOOLKIT END

                               // need to force URL to have the right URL and not a relative path
            $topic_url = 'http://myboard.com/phpbb/'.$last_topics_row['topic_url'].$last_topics_row['topic_id'].'.html';
            
            
            $template->assign_block_vars('last_topics', array(
               'TOPIC_TITLE'       => $last_topics_row['topic_title'],
                                        // force url once again, how annoying
               'TOPIC_POSTER'       => "<a href=\"http://myboard.com/phpbb/".$last_topics_row['topic_first_poster_name']."/\">".$last_topics_row['topic_first_poster_name']."</a>",
               'TOPIC_URL'           => $topic_url,
               'TOPIC_FORUM'       => $last_topics_row['forum_name'],
               'TOPIC_FORUM_LINK'    => append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=" . $last_topics_row['forum_id']),
               'POST_TIME'          => snFunctions::time_ago($last_topics_row['post_time']),
               'TOPIC_TEXT'        => $topic_text,
               // share icons
               'SHARE_HEADER'      => 'Share this topic:',
               'SHARE_URL'          => urlencode($topic_url),
               'SHARE_TITLE'       => urlencode($last_topics_row['topic_title']),
               'SHARE_SUMMARY'      => urlencode(substr($last_topics_row['post_text'], 0, 150)),
               'SHARE_URL_RAW'       => $topic_url,
               'SHARE_TITLE_RAW'    => $last_topics_row['topic_title'],
            ));
         }   


Again, in this code I am having to force the URLs to be absolute paths, which is very annoying.

Thanks for any insights you can offer.
scworldnetter
 
Posts: 17
Joined: Mon Mar 14, 2011 1:11 am

Advertisement

Re: SEO premod and SocialNet 0.5.2

Postby dcz » Sat Apr 16, 2011 11:54 am

scworldnetter wrote:I am using SocialNet 0.5.2 with my now premodded board ( 3.0.8 ), I have the "SID Removing" function turned on.


I don't encourage you to use the SID removal option. This feature indeed was added after we started to get really bored by user constantly asking to remove (almost) all SIDs despite the fact there is absolutely no reason to do it SEOwise, and that it may break sessions for users not accepting cookies (yes this implies that a guests, not a known bot, refusing cookie will create a session per visited page).
The thing is without the sid removal option, bot will not see any and if by chance a genuine but unknown bot (which also implies that we're not talking about google here) would visit the forum and thus see sid or if a known one would crawl a link with sid found somewhere in a hard coded href link, it would be HTTP 301 redirected to the same url without sid by the zero duplicate as soon as the session id would not match the real one in use (not to loose current session).
Al together this means that there is NO issue with SIDs SEOwise. Simple proof : http://www.google.com/search?q=site:php ... linurl:sid

scworldnetter wrote:1) Any URL that is PhPBB native, i.e. has ucp or other original PhPBB scripts in it gets a full absolute path, i.e. the full board URL is appended in front of it. But anything not of PhPBB origin, like external page scripts or in this case, the mainpage.php script of the mod, append_sid returns a relative path, i.e. ./phpbbdir. So when I use a mod_rewrite to make the /phpbbdir/mainpage.php the home page via


For this you could try to move :
Code: Select all
         // add full url
         $url = $this->path == $phpbb_root_path ? $this->seo_path['phpbb_url'] . preg_replace('`^' . $phpbb_root_path . '`', '', $url) : $url;

From where it is in phpbb_seo_class.php to right before :
Code: Select all
      if ( isset($this->seo_stop_files[$this->filename]) ) {

This should solve the matter for all scripts within $phpbb_root_path, though not for scripts in a sub, upper or same level dir (that is not for $phpbb_root_path . 'dir/' or $phpbb_root_path . '../dir/' or $phpbb_root_path . '../' ).
I'm currently investigating to find out if this particular change could cause trouble before I commit it into the mod (sine it could be helpful to go further into fixing relative path and virtual directories issues), and so far did not find any, and also do not think I will, but please tell me if you find any side effect to this change.

scworldnetter wrote:2) Several critical URLs aren't getting an SID when they really need one. For example,

This should go away if you turn off sid removal.

scworldnetter wrote:3) The other issue is that the newsfeed spews out the old style URLs rather than the SEO rewritten URLs. I've started to make changes and inserting the proper code there, but this is less critical because I hide the newsfeed from bots since there is nothing of value for the bots to index there. But I still would like coding advice there too so I can learn.


The field required to handle url rewriting in all cases are topic_id, topic_type, topic_title, topic_url, forum_id, forum_name. If you use sql rewriting, only the topic_id and topic_url are required for topic with topic_url set (which should always be the case with sql rewriting activated and after the first sync).
If you are not using sql rewriting and you are not using virtual folders, only the topic_id and topic_title are required, if you are using virtual folders, you'll need the forum_id also if your forum urls are cached or the forum_id and forum_name if they aren't.
In simple and mixed mode, the topic_id could be enough, but we'll still prefer to also get the topic_url with sql rewriting option since in that case you always have the possibility to use custom urls on a per case basis (like on phpBB SEO, for all release threads for example).

Global announcements is a special case, topic_type is the field we'll use to properly handle them, but it only really matter with virtual folders since other wise we'll just do as with any other topic. Also, if you query for forum_ids !=0, you will (well should) never fell on these.

Since your code is already querying for topic_id, topic_title, forum_id, forum_name, I'll do the tweak for the general case which works under all circumstances even though the global announcement case will not apply here (since you specify existing forum ids, but it's not this much work to add it and will make the code more reusable).
First the select, replace :
Code: Select all
         $last_posts = 'SELECT p.post_id, p.topic_id, p.post_time, p.forum_id, t.topic_title, f.forum_name

with :
Code: Select all
         $last_posts = 'SELECT p.post_id, p.topic_id, p.post_time, p.forum_id, t.topic_type, t.topic_title,' . (!empty($phpbb_seo->seo_opt['sql_rewrite']) ? ' t.topic_url, ' : ' ') . 'f.forum_name

I conditionally add the topic_url field because it may not be present in the table if sql rewriting is not activated which would raise an error. Strictly speaking, this implies an edge case, if sql rewriting was once turned on and topic_url sync'ed, but is later turned of (which does not drop the topic_url field), viewtopic.php will still use it because it's selecting * in the topic_table and the logic in the mod is to prevent unnecessary redirecting (that is, do not massively redirect just because you turned sql rewriting off by accident, but still do it if you intentionally dropped the topic_url field or emptied it with the sync script). In this particular (but unlikely) case, this code would not necessarily build the same url as in viewtopic.php. You could use t.* here to really handle all cases, but that would cost a bit more sql load and it is not really important with the zero dupe watching our back (yes, it appears that I am today set in verbose mod :roll: ).

Then, we have everything we need to do the job. The url rewriting principle is to first store all the required info in the phpbb_seo class, and then let the magic happen in append_sid.

For the first loop, since you'llbe building post url and there is not easy way to translate them to topic url except when we deal with last post in thread, we'll just take care of the forum urls
Code: Select all
            // www.phpBB-SEO.com SEO TOOLKIT BEGIN
            $phpbb_seo->set_url($last_posts_row['forum_name'], $last_posts_row['forum_id'], 'forum'); // this makes the forum url bit available, either generated or retrieved from the forum url cache
            // www.phpBB-SEO.com SEO TOOLKIT END

right after :
Code: Select all
            $last_posts_row = $last_posts_rowset[$i];


For the second loop, what you did is right, but can be simplified to :
Code: Select all
            // www.phpBB-SEO.com SEO TOOLKIT BEGIN
            $last_topics_row['topic_title'] = censor_text($last_topics_row['topic_title']); // let's do thing properly also for the mod itself
            $phpbb_seo->set_url($last_topics_row['forum_name'], $last_topics_row['forum_id'], 'forum'); // this makes the forum url bit available, either generated or retrieved from the forum url cache
            $phpbb_seo->prepare_iurl($last_topics_row, 'topic', $last_topics_row['topic_type'] == POST_GLOBAL ? $phpbb_seo->seo_static['global_announce'] : $phpbb_seo->seo_url['forum'][$last_topics_row['forum_id']]); // this makes the topic bit available, either retrieved from the topic_url field or generated (which is why we could need the forum bit)
            // www.phpBB-SEO.com SEO TOOLKIT END

again, add it right after :
Code: Select all
            $last_topics_row = $last_topics_rowset[$i];


Since the code you took from viewforum.php is complicated by the fact that the same code is used to display topics from forums we do not necessarily have all required informations about, that is if we display active sub forum topics and forum cache is not filled (in such case, the query did not make their name available, only the forum_id from the topic table).
It's no big deal to call phpbb_seo::set_url again for already prepared forums since the result forum bits are cached in phpbb_seo::seo_url['forum'] (the same apply for all type of urls).
So here, we have everything we want.
You then seem to need url without sid, but, we need to go through append_sid to handle url rewriting in all cases (and also to add the full url with domain). Fortunately, the phpbb_seo::drop_sid method is here to do the job.
Then remove :
Code: Select all
            // http://www.phpBB-SEO.com SEO TOOLKIT BEGIN
            // need to properly initialize $phpbb_seo
              if (!empty($last_topics_row['topic_url'])) {
                  $phpbb_seo->prepare_iurl($last_topics_row, 'topic', '');
              } else {
                  if ($phpbb_seo->modrtype > 2) {
                      $last_topics_row['topic_title'] = censor_text($last_topics_row['topic_title']);
                  }
                  $cur_forum_id = (int) $last_topics_row['forum_id'];
                  $parent_forum = $last_topics_row['topic_type'] == POST_GLOBAL ? $phpbb_seo->seo_static['global_announce'] : (!empty($phpbb_seo->seo_url['forum'][$cur_forum_id]) ? $phpbb_seo->seo_url['forum'][$cur_forum_id] : false);
                  if ($parent_forum) {
                      $phpbb_seo->prepare_iurl($last_topics_row, 'topic', $parent_forum);
                  }
              }
              // http://www.phpBB-SEO.com SEO TOOLKIT END

                               // need to force URL to have the right URL and not a relative path
            $topic_url = 'http://myboard.com/phpbb/'.$last_topics_row['topic_url'].$last_topics_row['topic_id'].'.html';


And replace :
Code: Select all
               'TOPIC_URL'           => $topic_url,

with :
Code: Select all
               'TOPIC_URL'           => $phpbb_seo->drop_sid(append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=" . $last_topics_row['forum_id'] . "&t=" . $last_topics_row['topic_id'], false)),

We also use the $is_amp param to properly tell append_sid (and thus phpbb_seo::url_rewrite that we are using & and not &amp;, even if it does not matter here since we won't be adding any more parameter to our rewritten url (we could under some desired circumstances end up with url.html?var1=value1&var2=value2).
For the topic poster url, we'll do something similar, just replace :
Code: Select all
               'TOPIC_POSTER'       => "<a href=\"http://myboard.com/phpbb/".$last_topics_row['topic_first_poster_name']."/\">".$last_topics_row['topic_first_poster_name']."</a>",

With :
Code: Select all
               'TOPIC_POSTER'       => "<a href=\"".$phpbb_seo->drop_sid(get_username_string('profile', $last_topics_row['topic_poster'], $last_topics_row['topic_first_poster_name']))."\">".$last_topics_row['topic_first_poster_name']."</a>",

get_username_string does all the job to properly rewrite profiles in all cases, as long as you provide with the proper parameters.

And you should be all good (there could be some obvious typo error in this though, since I'm writing this without testing, but they should be obvious to find in any).
Also, you may want to phpbb_seo::drop_sid on other urls build with append_sid (forums and posts), but you should have everything to do it now ;)

++
Useful links :
SEO Forum || SEO Directory || SEO phpBB || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Recherche
dcz
Admin
Admin
 
Posts: 21291
Joined: Fri Apr 28, 2006 9:03 pm


Return to phpBB SEO Premod

 


  • Related topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: Google Adsense [Bot] and 4 guests