Rewriting URLs in script

phpBB3 SEO Advanced mod Rewrite support forum.
This mods performs URL rewriting for phpBB, injecting forums and topic titles in their URLs.

Moderator: Moderators

Rewriting URLs in script

Postby seqwence » Fri May 09, 2008 10:01 pm

Hi guys,

I've found this script, which allows me to get several last posts in the custom pages:

Code: Select all

    <?php
    /**
    * newest_posts - raw dump of newest posts from forum
    *
    * @copyright (c) 2008 ameeck / Vojtech Vondra - phpBB.cz
    * @license http://opensource.org/licenses/gpl-license.php GNU Public License
    */
    define('IN_PHPBB', true);
    $phpbb_root_path = './';
    $phpEx = substr(strrchr(__FILE__, '.'), 1);
    include($phpbb_root_path . 'common.' . $phpEx);

    // Start session management
    $user->session_begin();
    $auth->acl($user->data);
    $user->setup();

    // Number of posts and grabbing permissions
    // Počet příspěvků pro zobrazení a oprávnění
    $topic_limit = request_var('topic_limit', 5);
    $forums = array_unique(array_keys($auth->acl_getf('f_read', true)));

    // Select the last topics to which we have permissions
    // Vybrat poslední témata ke kterým máme oprávnění
    $sql = 'SELECT p.post_id, p.topic_id, p.forum_id, p.post_subject, p.post_time, u.username
                    FROM ' . POSTS_TABLE . ' p , ' . USERS_TABLE . ' u
                    WHERE post_approved = 1
                        AND ' . $db->sql_in_set('forum_id', $forums) . '
                        AND u.user_id = p.poster_id
                    ORDER BY post_time DESC
                    LIMIT 0,' . $topic_limit;
    $result = $db->sql_query($sql);

    // Proper header since output not buffered
    // Poslat hlavičky pro správné kódování, protože výpis obsahu je postupný
    header('Content-Type: text/html; charset=utf-8');

    // Now let's output the content
    // A teď vypsat obsah
    echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Poslední příspěvky z fóra</title></head><body><div id="post_content"><strong>Novinky z fora:</strong><br/><ul>';
    while ($row = $db->sql_fetchrow($result))
    {
        $url = generate_board_url() . "/viewtopic.{$phpEx}?f={$row['forum_id']}&amp;t={$row['topic_id']}&amp;p={$row['post_id']}#p{$row['post_id']}";
        echo '<li><a target="_top" href="' . $url . '">' . $row['post_subject'] . '</a> od ' . $row['username'] . ' v ' . $user->format_date($row['post_time']) . '</li>';
    }
    echo '</ul></div></body></html>';
    ?>



But there's a rub. It doesn't rewrite the URLs ...

Is there any way to do that?

Beside I'm using phpBB 3.0.1. - Advanced phpBB3 SEO mod Rewrite.

Thanks in advance :-)
seqwence
 
Posts: 5
Joined: Mon May 14, 2007 2:07 pm

Advertisement

Postby seqwence » Sun May 11, 2008 12:26 pm

Hi guys,

please, can anybody take a look on that script and find out how to add SEF URLs to it? It's very important. I'll be very grateful. :-)
seqwence
 
Posts: 5
Joined: Mon May 14, 2007 2:07 pm

Postby HB » Sun May 11, 2008 1:59 pm

FYI, I lifted the phpBB-seo related code directly from viewtopic.php with minor modifications.

Code: Select all
<?php
    define('IN_PHPBB', true);
    $phpbb_root_path = './';
    $phpEx = substr(strrchr(__FILE__, '.'), 1);
    include($phpbb_root_path . 'common.' . $phpEx);

    // Start session management
    $user->session_begin();
    $auth->acl($user->data);
    $user->setup();

    // Number of posts and grabbing permissions
    $topic_limit = request_var('topic_limit', 5);
    $forums = array_unique(array_keys($auth->acl_getf('f_read', true)));

    // Select the last topics to which we have permissions
    $sql = 'SELECT p.post_id, p.topic_id, p.forum_id, p.post_subject, p.post_time, u.username,  t.topic_title, t.topic_last_post_id, t.topic_replies, t.topic_replies_real, t.topic_type, t.topic_title
                    FROM ' . POSTS_TABLE . ' p , ' . USERS_TABLE . ' u, ' . TOPICS_TABLE . ' t
                    WHERE post_approved = 1
                        AND ' . $db->sql_in_set('p.forum_id', $forums) . '
                        AND u.user_id = p.poster_id
                        AND p.topic_id = t.topic_id
                    ORDER BY post_time DESC
                    LIMIT 0,' . $topic_limit;
    $result = $db->sql_query($sql);

    // Proper header since output not buffered
    header('Content-Type: text/html; charset=utf-8');

    // Now let's output the content
    echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Test</title></head><body><div id="post_content"><strong>Novinky z fora:</strong><br/><ul>';
    while ($row = $db->sql_fetchrow($result))
    {
      $topic_id = $row['topic_id'];
      $forum_id = $row['forum_id'];
      $post_id = $row['topic_last_post_id'];
      $topic_title = censor_text($row['topic_title']);

      $replies = ($auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies'];   
      $start = floor(($replies) / $config['posts_per_page']) * $config['posts_per_page'];
         
      // www.phpBB-SEO.com SEO TOOLKIT BEGIN
      if ( empty($phpbb_seo->seo_url['topic'][$topic_id]) ) {
         if ($row['topic_type'] == POST_GLOBAL) {
            $phpbb_seo->seo_opt['topic_type'][$topic_id] = POST_GLOBAL;
         }
         $phpbb_seo->seo_censored[$topic_id] = $topic_title;
         $phpbb_seo->seo_url['topic'][$topic_id] = $phpbb_seo->format_url($phpbb_seo->seo_censored[$topic_id]);
      }
      // www.phpBB-SEO.com SEO TOOLKIT END   
   
      $post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $topic_id . '&amp;f=' . $forum_id . '&amp;start=' . $start ) . '#p' . $post_id;
      $topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;start=$start");        
      
        echo '<li><a target="_top" href="' . $post_url . '">' . $topic_title . '</a> od ' . $row['username'] . ' v ' . $user->format_date($row['post_time']) . '</li>';
    }
    echo '</ul></div></body></html>';
?>
Dan Kehn
HB
phpBB SEO Team
phpBB SEO Team
 
Posts: 1504
Joined: Mon Oct 16, 2006 2:25 am

Postby seqwence » Sun May 11, 2008 2:52 pm

Thank you. :-)
seqwence
 
Posts: 5
Joined: Mon May 14, 2007 2:07 pm


Return to Advanced SEO URL

 


  • Related topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: No registered users and 3 guests