phpBB SEO
Boards
Directory  
SEO  
Downloads
  phpBB SEO : Search Engine Optimization, Directory, Forums  
Index
Forums
Annuaire
Référencement
Télécharger
 
  Search Rechercher
    Register
Username :  Password :  Log me on automatically each visit  
S'enregistrer  
 
   
Issue with rewriting links in external file

 
Post new topic   Reply to topic    phpBB SEO » SEO Forum  » phpBB3 SEO TooLKit  » phpBB3 SEO MODS
::  
Author Message
tbxn



Joined: 03 Aug 2008
Posts: 9

Issue with rewriting links in external filePosted: Tue Sep 02, 2008 2:46 pm    Post subject: Issue with rewriting links in external file

Hello, first of all I would like to thank you for the mods that you have created. I've found them very useful.

I have a small problem, hopefully you can give me some insight on this matter. I am integrating my website with the phpbb forum. I have the latest advanced seo mod installed on my forum, as well as the other seo toolkit mods. On my news page I fetch posts from the database and display them. A few of the URLs are rewritten but some of them are not and I am hoping you can help me with this. Below is a portion of my news script which fetches posts from the forum for display. Perhaps I am just missing an included file? My post-author/member links are rewritten, as well as the forum url but the viewtopic.php?t=1 etc. links are not rewritten, and I would like them to be rewritten to the topic url such as mysite.com/this-topic/. Thank you for your help.
Code:

<?php

define('IN_PHPBB', true);
$phpEx = substr(strrchr(__FILE__, '.'), 1);

include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
   
// Start session management
$user->session_begin();
$auth->acl($user->data);

//news script variables
$charlimit = '0';
$timestamp = 'D M j, Y g:i a';
$forum_id = array('2');
$showavatars = 'false';
$newsdisplay = '10';

$allow_bbcode = true;
$allow_smilies = false;
$allow_urls = true;

   // Auth
   $can_read_forum = $auth->acl_getf('f_read');                   //Get the forums the user can read from
   $forums_auth_ary = array_keys($can_read_forum);                   //Re-work the array some
   $authed_news_ary = array_intersect($forum_id, $forums_auth_ary);   //Of the desired forums, pull out the authed ones
   unset($can_read_forum);
   unset($forums_auth_ary);

   $sql = 'SELECT t.forum_id, t.topic_id, t.topic_title, t.topic_replies, p.post_id, p.post_subject, p.post_text, p.post_time, p.bbcode_bitfield, p.bbcode_uid, u.username, u.user_id, u.user_avatar, u.user_avatar_type, u.user_avatar_width, u.user_avatar_height, u.user_colour
         FROM ' . TOPICS_TABLE . ' t
            INNER JOIN ' . POSTS_TABLE . ' p ON (t.topic_id = p.topic_id)
               INNER JOIN ' . USERS_TABLE . ' u ON (p.poster_id = u.user_id)
                  WHERE t.topic_approved = 1
                     AND p.post_approved = 1
                     AND ' . $db->sql_in_set('p.forum_id', $authed_news_ary) . '
                     AND p.post_id = t.topic_first_post_id
                  ORDER BY p.post_time DESC';

   $result = $db->sql_query_limit($sql, $newsdisplay);
   $row = $db->sql_fetchrowset($result);
   $db->sql_freeresult($result);
   
   $flags = (($allow_bbcode) ? OPTION_FLAG_BBCODE : 0) + (($allow_smilies) ? OPTION_FLAG_SMILIES : 0) + (($allow_urls) ? OPTION_FLAG_LINKS : 0);

   // Check that we have enough entries to display
   if(sizeof($row) < $newsdisplay)
   {
      $newsdisplay = sizeof($row);
   }

   //
   // Organize the posts into an array
   // Trim and work some display magic if necessary
   //
   $posts = array();
   for($i = 0; $i < $newsdisplay; $i++)
   {
      $posts[$i]['topic_id'] = $row[$i]['topic_id'];
      $posts[$i]['forum_id'] = $row[$i]['forum_id'];
      $posts[$i]['topic_replies'] = $row[$i]['topic_replies'];
      $posts[$i]['post_time'] = date($timestamp, $row[$i]['post_time']);
      $posts[$i]['topic_title'] = $row[$i]['topic_title'];
      $posts[$i]['post_subject'] = $row[$i]['post_subject'];
      $posts[$i]['user_id'] = $row[$i]['user_id'];
      $posts[$i]['user_link'] = get_username_string('full', $row[$i]['user_id'], $row[$i]['username'], $row[$i]['user_colour']);
      $posts[$i]['user_avatar'] = get_user_avatar($row[$i]['user_avatar'], $row[$i]['user_avatar_type'], $row[$i]['user_avatar_width'], $row[$i]['user_avatar_height']);
      $posts[$i]['topic_link'] = append_sid("{$forum_root_path}viewtopic.$phpEx", 'f=' . $posts[$i]['forum_id'] . '&amp;t=' . $posts[$i]['topic_id']);
      $posts[$i]['reply_link'] = append_sid("{$forum_root_path}posting.$phpEx", 'mode=reply&amp;f=' . $posts[$i]['forum_id'] . '&amp;t=' . $posts[$i]['topic_id']);

      censor_text($posts[$i]['topic_title']);
      censor_text($posts[$i]['post_subject']);
   
      $post_text = '';
      //If the text is short enough, don't trim it, and fully display it with BBCdoes, Smilies, and URLs
      if(($charlimit == 0) || (strlen($row[$i]['post_text'] <= $charlimit)))
      {
         $posts[$i]['message'] = generate_text_for_display($row[$i]['post_text'], $row[$i]['bbcode_uid'], $row[$i]['bbcode_bitfield'], $flags);
      }
      else
      {
         strip_bbcode($row[$i]['post_text']);
         censor_text($row[$i]['post_text']);
         $posts[$i]['message'] = substr($row[$i]['post_text'], 0, $charlimit) . '...' . '<br /><br /><a href="' . $posts[$i]['topic_link'] . '">[Read More]</a>';
      }
     
      $sql = 'SELECT forum_name
            FROM ' . FORUMS_TABLE . '
               WHERE forum_id = ' . intval($posts[$i]['forum_id']);
      $result = $db->sql_query($sql);
      $posts[$i]['forum_name'] = $db->sql_fetchfield('forum_name');
      $db->sql_freeresult($result);

      if($posts[$i]['topic_title'] == '')
      {
         continue;
      }

      $template->assign_block_vars('fetchpost_row', array(
         'AVATAR'      => $posts[$i]['user_avatar'],
         'FORUM_NAME'   => $posts[$i]['forum_name'],
         'POSTER'      => $posts[$i]['user_link'],
         'POST_SUBJECT'   => $posts[$i]['post_subject'],
         'POST_TIME'      => $posts[$i]['post_time'],
         'REPLIES'      => $posts[$i]['topic_replies'],
         'TEXT'         => $posts[$i]['message'],
         'TOPIC_TITLE'   => $posts[$i]['topic_title'],
         'U_FORUMLINK'   => append_sid("{$forum_root_path}viewforum.$phpEx", 'f=' . $posts[$i]['forum_id']),
         'U_REPLYLINK'   => $posts[$i]['reply_link'],
         'U_VIEWLINK'   => $posts[$i]['topic_link'],
         ));
   }

    $template->set_filenames(array(
        'body' => 'home.html',
    ));

    page_footer();

?>
Back to top
dcz
Administrateur - Site Admin
Administrateur - Site Admin


Joined: 28 Apr 2006
Posts: 15242

Issue with rewriting links in external filePosted: Sat Sep 06, 2008 8:38 am    Post subject: Re: Issue with rewriting links in external file

You'd probably should do better to get forum names :

Code:
      $sql = 'SELECT forum_name
            FROM ' . FORUMS_TABLE . '
               WHERE forum_id = ' . intval($posts[$i]['forum_id']);
      $result = $db->sql_query($sql);
      $posts[$i]['forum_name'] = $db->sql_fetchfield('forum_name');
      $db->sql_freeresult($result);


Means one SQL per topic listed where you could do it all at once if you'd first collect all forum IDs from the topic data, and then use WHERE forum_id IN (id1,id2 ...).
This would mean to loop twice, once to parse topic data and collect forum ids and then once to assemble the forum data to the topic data and send it to the template, but it should be more efficient this way.

Anyway, for the rewriting, you just need to fill the seo_url arrays, as is, you'd need to add :
Code:
 t.topic_type,

after :
Code:
t.topic_replies,


and :

Code:
// www.phpBB-SEO.com SEO TOOLKIT BEGIN
if ( empty($phpbb_seo->seo_url['topic'][$posts[$i]['topic_id']]) ) {
   if ($posts[$i]['topic_type'] == POST_GLOBAL) {
      $phpbb_seo->seo_opt['topic_type'][$posts[$i]['topic_id']] = POST_GLOBAL;
   }
   $phpbb_seo->seo_url['topic'][$posts[$i]['topic_id']] = $phpbb_seo->format_url(censor_text($posts[$i]['topic_title']));
}
if ( empty($phpbb_seo->seo_url['forum'][$posts[$i]['forum_id']]) ) {
   $phpbb_seo->seo_url['forum'][$posts[$i]['forum_id']] = $phpbb_seo->set_url($posts[$i]['forum_name'], $posts[$i]['forum_id'], $phpbb_seo->seo_static['forum']);
}
// www.phpBB-SEO.com SEO TOOLKIT END


after :

Code:
      if($posts[$i]['topic_title'] == '')
      {
         continue;
      }


Should do it Wink

++

_________________
Useful links :
SEO Forum || SEO Directory || SEO phpBB || SEO phpBB3 || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Référencement phpBB3 || Recherche
Back to top
Visit poster's website
tbxn



Joined: 03 Aug 2008
Posts: 9

Issue with rewriting links in external filePosted: Sat Sep 06, 2008 1:48 pm    Post subject: Re: Issue with rewriting links in external file

I made the adjustments but the viewtopic urls are still not rewritten. Also I was wondering if you could elaborate on what you were saying about forum names... how would I implement that change? Thanks again for your help.

Anyway, here is what my file looks like now with the SEO mod additions:

Code:
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('mods/site');

//news script variables
$charlimit = '0';
$timestamp = 'D M j, Y g:i a';
$forum_id = array('2', '16', '27', '28', '29', '30', '31', '32', '33', '34', '36', '38', '39');
$newsdisplay = '10';

// BBCodes, Smilies, etc... for fully displayed posts.  Trimmed posts will lose effects
$allow_bbcode = true;
$allow_smilies = false;
$allow_urls = true;

   // Auth
   $can_read_forum = $auth->acl_getf('f_read');                   //Get the forums the user can read from
   $forums_auth_ary = array_keys($can_read_forum);                   //Re-work the array some
   $authed_news_ary = array_intersect($forum_id, $forums_auth_ary);   //Of the desired forums, pull out the authed ones
   unset($can_read_forum);
   unset($forums_auth_ary);

   $sql = 'SELECT t.forum_id, t.topic_id, t.topic_title, t.topic_replies, t.topic_type, p.post_id, p.post_subject, p.post_text, p.post_time, p.bbcode_bitfield, p.bbcode_uid, u.username, u.user_id, u.user_colour
         FROM ' . TOPICS_TABLE . ' t
            INNER JOIN ' . POSTS_TABLE . ' p ON (t.topic_id = p.topic_id)
               INNER JOIN ' . USERS_TABLE . ' u ON (p.poster_id = u.user_id)
                  WHERE t.topic_approved = 1
                     AND p.post_approved = 1
                     AND ' . $db->sql_in_set('p.forum_id', $authed_news_ary) . '
                     AND p.post_id = t.topic_first_post_id
                  ORDER BY p.post_time DESC';

   $result = $db->sql_query_limit($sql, $newsdisplay);
   $row = $db->sql_fetchrowset($result);
   $db->sql_freeresult($result);
   
   $flags = (($allow_bbcode) ? OPTION_FLAG_BBCODE : 0) + (($allow_smilies) ? OPTION_FLAG_SMILIES : 0) + (($allow_urls) ? OPTION_FLAG_LINKS : 0);

   // Check that we have enough entries to display
   if(sizeof($row) < $newsdisplay)
   {
      $newsdisplay = sizeof($row);
   }

   //
   // Organize the posts into an array
   // Trim and work some display magic if necessary
   //
   $posts = array();
   for($i = 0; $i < $newsdisplay; $i++)
   {
      $posts[$i]['topic_id'] = $row[$i]['topic_id'];
     $posts[$i]['topic_type'] = $row[$i]['topic_type'];
      $posts[$i]['forum_id'] = $row[$i]['forum_id'];
      $posts[$i]['topic_replies'] = $row[$i]['topic_replies'];
      $posts[$i]['post_time'] = date($timestamp, $row[$i]['post_time']);
      $posts[$i]['topic_title'] = $row[$i]['topic_title'];
      $posts[$i]['post_subject'] = $row[$i]['post_subject'];
      $posts[$i]['user_id'] = $row[$i]['user_id'];
      $posts[$i]['user_link'] = get_username_string('full', $row[$i]['user_id'], $row[$i]['username'], $row[$i]['user_colour']);
      $posts[$i]['topic_link'] = append_sid("{$forum_root_path}viewtopic.$phpEx", 'f=' . $posts[$i]['forum_id'] . '&amp;t=' . $posts[$i]['topic_id']);
      $posts[$i]['reply_link'] = append_sid("{$forum_root_path}posting.$phpEx", 'mode=reply&amp;f=' . $posts[$i]['forum_id'] . '&amp;t=' . $posts[$i]['topic_id']);

      censor_text($posts[$i]['topic_title']);
      censor_text($posts[$i]['post_subject']);
   
      $post_text = '';
      //If the text is short enough, don't trim it, and fully display it with BBCdoes, Smilies, and URLs
      if(($charlimit == 0) || (strlen($row[$i]['post_text'] <= $charlimit)))
      {
         $posts[$i]['message'] = generate_text_for_display($row[$i]['post_text'], $row[$i]['bbcode_uid'], $row[$i]['bbcode_bitfield'], $flags);
      }
      //If the text is too long, trim it.  Do not show BBCodes, Smilies, or URLs, as trimming will wreck havoc on the page if we splice an HTML code
      else
      {
         strip_bbcode($row[$i]['post_text']);
         censor_text($row[$i]['post_text']);
         $posts[$i]['message'] = substr($row[$i]['post_text'], 0, $charlimit) . '...' . '<br /><br /><a href="' . $posts[$i]['topic_link'] . '">[Read More]</a>';
      }
     
      $sql = 'SELECT forum_name
            FROM ' . FORUMS_TABLE . '
               WHERE forum_id = ' . intval($posts[$i]['forum_id']);
      $result = $db->sql_query($sql);
      $posts[$i]['forum_name'] = $db->sql_fetchfield('forum_name');
      $db->sql_freeresult($result);

      if($posts[$i]['topic_title'] == '')
      {
         continue;
      }
    
     // www.phpBB-SEO.com SEO TOOLKIT BEGIN
if ( empty($phpbb_seo->seo_url['topic'][$posts[$i]['topic_id']]) ) {
   if ($posts[$i]['topic_type'] == POST_GLOBAL) {
      $phpbb_seo->seo_opt['topic_type'][$posts[$i]['topic_id']] = POST_GLOBAL;
   }
   $phpbb_seo->seo_url['topic'][$posts[$i]['topic_id']] = $phpbb_seo->format_url(censor_text($posts[$i]['topic_title']));
}
if ( empty($phpbb_seo->seo_url['forum'][$posts[$i]['forum_id']]) ) {
   $phpbb_seo->seo_url['forum'][$posts[$i]['forum_id']] = $phpbb_seo->set_url($posts[$i]['forum_name'], $posts[$i]['forum_id'], $phpbb_seo->seo_static['forum']);
}
// www.phpBB-SEO.com SEO TOOLKIT END

      $template->assign_block_vars('fetchpost_row', array(
         'FORUM_NAME'   => $posts[$i]['forum_name'],
         'POSTER'      => $posts[$i]['user_link'],
         'POST_SUBJECT'   => $posts[$i]['post_subject'],
         'POST_TIME'      => $posts[$i]['post_time'],
         'REPLIES'      => $posts[$i]['topic_replies'],
         'TEXT'         => $posts[$i]['message'],
         'TOPIC_TITLE'   => $posts[$i]['topic_title'],
         'U_FORUMLINK'   => append_sid("{$forum_root_path}viewforum.$phpEx", 'f=' . $posts[$i]['forum_id']),
         'U_REPLYLINK'   => $posts[$i]['reply_link'],
         'U_VIEWLINK'   => $posts[$i]['topic_link'],
         ));
   }

    $template->set_filenames(array(
        'body' => 'home.html',
    ));

    page_footer();

?>
Back to top
dcz
Administrateur - Site Admin
Administrateur - Site Admin


Joined: 28 Apr 2006
Posts: 15242

Issue with rewriting links in external filePosted: Sat Sep 06, 2008 2:57 pm    Post subject: Re: Issue with rewriting links in external file

oh yes, add :
Code:
     // www.phpBB-SEO.com SEO TOOLKIT BEGIN
if ( empty($phpbb_seo->seo_url['topic'][$posts[$i]['topic_id']]) ) {
   if ($posts[$i]['topic_type'] == POST_GLOBAL) {
      $phpbb_seo->seo_opt['topic_type'][$posts[$i]['topic_id']] = POST_GLOBAL;
   }
   $phpbb_seo->seo_url['topic'][$posts[$i]['topic_id']] = $phpbb_seo->format_url(censor_text($posts[$i]['topic_title']));
}
     // www.phpBB-SEO.com SEO TOOLKIT END

after :

Code:
   for($i = 0; $i < $newsdisplay; $i++)
   {



and then :
Code:
// www.phpBB-SEO.com SEO TOOLKIT BEGIN
if ( empty($phpbb_seo->seo_url['forum'][$posts[$i]['forum_id']]) ) {
   $phpbb_seo->seo_url['forum'][$posts[$i]['forum_id']] = $phpbb_seo->set_url($posts[$i]['forum_name'], $posts[$i]['forum_id'], $phpbb_seo->seo_static['forum']);
}
// www.phpBB-SEO.com SEO TOOLKIT END


after :
Code:
      if($posts[$i]['topic_title'] == '')
      {
         continue;
      }


should do it, the topic link was built before Wink

++

_________________
Useful links :
SEO Forum || SEO Directory || SEO phpBB || SEO phpBB3 || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Référencement phpBB3 || Recherche
Back to top
Visit poster's website
tbxn



Joined: 03 Aug 2008
Posts: 9

Issue with rewriting links in external filePosted: Sat Sep 06, 2008 3:51 pm    Post subject: Re: Issue with rewriting links in external file

At first it came up with undefined offset errors. I realized that the problem was the first bit of code:

Code:

// www.phpBB-SEO.com SEO TOOLKIT BEGIN
if ( empty($phpbb_seo->seo_url['topic'][$posts[$i]['topic_id']]) ) {
   if ($posts[$i]['topic_type'] == POST_GLOBAL) {
      $phpbb_seo->seo_opt['topic_type'][$posts[$i]['topic_id']] = POST_GLOBAL;
   }
   $phpbb_seo->seo_url['topic'][$posts[$i]['topic_id']] = $phpbb_seo->format_url(censor_text($posts[$i]['topic_title']));
}
     // www.phpBB-SEO.com SEO TOOLKIT END


This used the $posts[$i]['topic_id'] variables which had not yet been defined so I just changed that bit of code to:

Code:
// www.phpBB-SEO.com SEO TOOLKIT BEGIN
   if ( empty($phpbb_seo->seo_url['topic'][$row[$i]['topic_id']]) ) {
    if ($row[$i]['topic_type'] == POST_GLOBAL) {
         $phpbb_seo->seo_opt['topic_type'][$row[$i]['topic_id']] = POST_GLOBAL;
      }
         $phpbb_seo->seo_url['topic'][$row[$i]['topic_id']] = $phpbb_seo->format_url(censor_text($row[$i]['topic_title']));
      }
     // www.phpBB-SEO.com SEO TOOLKIT END


and now it works great. Thanks a lot for all your help. By the way, I'm curious about what you were saying about optimizing that sql query.

Quote:
Means one SQL per topic listed where you could do it all at once if you'd first collect all forum IDs from the topic data, and then use WHERE forum_id IN (id1,id2 ...).
This would mean to loop twice, once to parse topic data and collect forum ids and then once to assemble the forum data to the topic data and send it to the template, but it should be more efficient this way.


Could you please explain a bit more about how I might go about implementing this? I'm already using that bit of code that you posted towards the bottom of my script.

Thanks again.
Back to top
dcz
Administrateur - Site Admin
Administrateur - Site Admin


Joined: 28 Apr 2006
Posts: 15242

Issue with rewriting links in external filePosted: Sat Sep 13, 2008 7:58 am    Post subject: Re: Issue with rewriting links in external file

You could do something like :

Code:
// ...
   $sql = 'SELECT t.forum_id, t.topic_id, t.topic_title, t.topic_replies, t.topic_type, p.post_id, p.post_subject, p.post_text, p.post_time, p.bbcode_bitfield, p.bbcode_uid, u.username, u.user_id, u.user_colour
         FROM ' . TOPICS_TABLE . ' t
            INNER JOIN ' . POSTS_TABLE . ' p ON (t.topic_id = p.topic_id)
               INNER JOIN ' . USERS_TABLE . ' u ON (p.poster_id = u.user_id)
                  WHERE t.topic_approved = 1
                     AND p.post_approved = 1
                     AND ' . $db->sql_in_set('p.forum_id', $authed_news_ary) . '
                     AND p.post_id = t.topic_first_post_id
                  ORDER BY p.post_time DESC';

   $result = $db->sql_query_limit($sql, $newsdisplay);
   $posts = array();
   $topic_forum_ids = array();
   while ( $row = $db->sql_fetchrow($result)) {
      $posts[] = $row;
      $topic_forum_ids[] = (int) $row['forum_id'];
   }
   $db->sql_freeresult($result);
   $sql = 'SELECT forum_id, forum_name
            FROM ' . FORUMS_TABLE . '
            WHERE ' . $db->sql_in_set('forum_id', $topic_forum_ids, false);
   $result = $db->sql_query($sql);
   $forums = array();
   while ( $row = $db->sql_fetchrow($result)) {
      $forums[$row['forum_id']] = $row['forum_name'];
   }
   $db->sql_freeresult($result);
   $flags = (($allow_bbcode) ? OPTION_FLAG_BBCODE : 0) + (($allow_smilies) ? OPTION_FLAG_SMILIES : 0) + (($allow_urls) ? OPTION_FLAG_LINKS : 0);
   if (!empty($posts)) {
      foreach ($posts as $thistopic) {
         // format the var prior to output
         $topic_id = (int) $thistopic['topic_id'];
         $forum_id= (int) $thistopic['forum_id'];
         // Var needing some formatting
         $thistopic['post_time'] = date($timestamp, thistopic['post_time']);
         // Retrieve the forum name from the previously filled forums array
         $thistopic['forum_name'] = $forums[$forum_id];
// Etc .... using $thistopic where $posts[$i] was used, and without the need for lines such as
// $posts[$i]['topic_title'] = $row[$i]['topic_title'];
// Since $row[$i] is pretty much the same as $thistopic too here (except for forum names)
// the template vars should be parsed in this loop too
      }
   }


This way, you'd only use 2 SQL queries in all cases, not up to one + one per forum (eg up to on + number of topics).
Lines starting with // are comments to help a bit to understand the general principle.

++

_________________
Useful links :
SEO Forum || SEO Directory || SEO phpBB || SEO phpBB3 || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Référencement phpBB3 || Recherche
Back to top
Visit poster's website
tbxn



Joined: 03 Aug 2008
Posts: 9

Issue with rewriting links in external filePosted: Fri Oct 03, 2008 6:28 pm    Post subject: Re: Issue with rewriting links in external file

Thanks a lot for taking the time to show me that bit of code. I'm having problems implementing it however. When I try to follow your suggestions I just end up with a blank white screen, which I'm assuming is because my syntax or structure is wrong. Do you think you could show me a more precise example using the script I posted above? Thank you for your time.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    phpBB SEO » SEO Forum  » phpBB3 SEO TooLKit  » phpBB3 SEO MODS
Page 1 of 1

Navigation Similar Topics

Jump to: