Function Last Topic

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

Moderator: Moderators

Function Last Topic

Postby psaico » Sun May 25, 2008 10:38 am

Hi guys..
Error:
Code: Select all
Fatal error: Call to a member function on a non-object in /home/mhd-01/www.big-bug.net/htdocs/forum/includes/cache.php on line 51


Functions:
Code: Select all
<?php
function ShowLastTopic($id,$limit){
ob_start();
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
ob_end_flush();
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

$sql = "SELECT DISTINCT(t.topic_id), t.forum_id, t.topic_title, t.topic_last_post_id, t.topic_status, t.topic_replies, t.topic_replies_real, t.topic_type, f.forum_name
   FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f
   WHERE t.forum_id = $id
   AND t.topic_status <> 2
   AND t.forum_id = f.forum_id
   ORDER BY t.topic_last_post_id DESC LIMIT $limit";   
$result = $db->sql_query($sql);

$line = array();
while( $row = $db->sql_fetchrow($result)) {
   $line[] = $row;
}
$db->sql_freeresult($result);

for( $i = 0; $i < count($line); $i++ )
{
   $forum_name = $line[$i]['forum_name'];
   $topic_id = $line[$i]['topic_id'];
   $forum_id = $line[$i]['forum_id'];
   $post_id = $line[$i]['topic_last_post_id'];
   $topic_title = censor_text($line[$i]['topic_title']); 
   $replies = ($auth->acl_get('m_approve', $forum_id)) ? $line[$i]['topic_replies_real'] : $line[$i]['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 ($line[$i]['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]);
   }
   if ( empty($phpbb_seo->seo_url['forum'][$forum_id]) ) {
      $phpbb_seo->seo_url['forum'][$forum_id] = $phpbb_seo->set_url($line[$i]['forum_name'], $forum_id, $phpbb_seo->seo_static['forum']);
   }
   // 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 '<a href="' . $post_url . '">recent post</a> to &quot;';     
   echo '<a href="'. $topic_url .'">'. $topic_title .'</a>&quot;<br/>';
}
}
ShowLastTopic(2,10);
?>


Why?
:o
User avatar
psaico
PR0
PR0
 
Posts: 56
Joined: Wed May 14, 2008 2:55 pm

Advertisement

Postby SeO » Sun May 25, 2008 12:21 pm

The phpbb_seo object needs to be globalized into functions, add :

Code: Select all
global $phpbb_seo;


after :

Code: Select all
function ShowLastTopic($id,$limit){


And you'll be able to manipulate the class in your function ;)
SeO
Admin
Admin
 
Posts: 6334
Joined: Wed Mar 15, 2006 9:41 pm

Postby psaico » Sun May 25, 2008 12:32 pm

UHm, thanks..
but don't work.. i receive the same error.

I have try with
Code: Select all
function ShowLastTopic($id,$limit){
global $phpbb_seo;
var_dump($phpbb_seo);
return;
code ..
code ..

and $phpbb_seo is NULL

:(
User avatar
psaico
PR0
PR0
 
Posts: 56
Joined: Wed May 14, 2008 2:55 pm

Postby SeO » Sun May 25, 2008 12:36 pm

Of course, this assumes that the phbb_seo class was started before, which should here be the case since common.php is included. The phpbb_seo class should thus be accessible.

try :

Code: Select all
var_dump($phpbb_seo);


after :
Code: Select all
ob_end_flush();


To see if you get something.
SeO
Admin
Admin
 
Posts: 6334
Joined: Wed Mar 15, 2006 9:41 pm

Postby psaico » Sun May 25, 2008 12:44 pm

Code: Select all
function ShowLastTopic($id,$limit){
global $phpbb_seo;
ob_start();
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
ob_end_flush();
var_dump($phpbb_seo);
return;
some code..

mmm nothing ..
Code: Select all
Fatal error: Call to a member function on a non-object in /home/mhd-01/www.big-bug.net/htdocs/forum/includes/cache.php on line 51
User avatar
psaico
PR0
PR0
 
Posts: 56
Joined: Wed May 14, 2008 2:55 pm

Postby SeO » Sun May 25, 2008 1:24 pm

mm, what about your common.php file, does it actually start the phpbb_seo class, is the mod installed on the forum you're connecting this script to ?
SeO
Admin
Admin
 
Posts: 6334
Joined: Wed Mar 15, 2006 9:41 pm

Postby psaico » Sun May 25, 2008 1:41 pm

I have installed phpbb-seo
and in my common.php there is this part of code
Code: Select all
#
if (empty($phpbb_seo) ) {
#
require_once($phpbb_root_path . 'phpbb_seo/phpbb_seo_class.'.$phpEx);
#
$phpbb_seo = new phpbb_seo();
#
}


:roll:
User avatar
psaico
PR0
PR0
 
Posts: 56
Joined: Wed May 14, 2008 2:55 pm

Postby SeO » Sun May 25, 2008 2:09 pm

Anything shows up if you add :

var_dump($phpbb_seo);

after this code in common.php for a sec ?
SeO
Admin
Admin
 
Posts: 6334
Joined: Wed Mar 15, 2006 9:41 pm

Postby psaico » Sun May 25, 2008 2:16 pm

Look the output on source code in this page:
http://www.big-bug.net/forum/index.php

the output is in <!-- -->

Thx .
User avatar
psaico
PR0
PR0
 
Posts: 56
Joined: Wed May 14, 2008 2:55 pm

Postby SeO » Sun May 25, 2008 2:19 pm

Are you using this script on phpbb's index ?

Looks like meant to be used on pages that do not share phpbb's code.

Various solutions already exist to display last posts on phpBB's index as well as on other pages, have you given search a try ?
SeO
Admin
Admin
 
Posts: 6334
Joined: Wed Mar 15, 2006 9:41 pm

Postby psaico » Sun May 25, 2008 2:24 pm

No, i used on homepage.. but not in homepage forum :(
User avatar
psaico
PR0
PR0
 
Posts: 56
Joined: Wed May 14, 2008 2:55 pm

Postby psaico » Thu May 29, 2008 8:17 am

up :(
User avatar
psaico
PR0
PR0
 
Posts: 56
Joined: Wed May 14, 2008 2:55 pm

Postby psaico » Fri May 30, 2008 6:48 am

Ok, now it work:
Code: Select all
<?php

   function GetTopic($forum_id,$limit,$order_by){
      global $db,$auth,$phpbb_seo,$config,$phpEx,$user,$cache,$template;      
      define('IN_PHPBB', true);
      $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './forum/';
      $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);
      $user->setup();   
      $sql =
      "SELECT DISTINCT(t.topic_id), t.forum_id, t.topic_title, t.topic_last_post_id, t.topic_status, t.topic_replies,    t.topic_replies_real, t.topic_type, f.forum_name FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f
        WHERE t.forum_id = $forum_id
        AND t.topic_status <> 2
        AND t.forum_id = f.forum_id
           ORDER BY $order_by DESC LIMIT $limit";   
        $result = $db->sql_query($sql);
        $line = array();
        while( $row = $db->sql_fetchrow($result)) {
          $line[] = $row;
        }         
        $db->sql_freeresult($result);
        for( $i = 0; $i < count($line); $i++ ){
            $forum_name = $line[$i]['forum_name'];
             $topic_id = $line[$i]['topic_id'];
                $forum_id = $line[$i]['forum_id'];
                $post_id = $line[$i]['topic_last_post_id'];
              $topic_title = censor_text($line[$i]['topic_title']); 
             $replies = ($auth->acl_get('m_approve', $forum_id)) ? $line[$i]['topic_replies_real'] : $line[$i] ['topic_replies'];   
             $start = floor(($replies) / $config['posts_per_page']) * $config['posts_per_page'];
            if (empty($phpbb_seo->seo_url['topic'][$topic_id]) ) {
              if ($line[$i]['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]);
           }
           if ( empty($phpbb_seo->seo_url['forum'][$forum_id]) ) {
             $phpbb_seo->seo_url['forum'][$forum_id] = $phpbb_seo->set_url($line[$i]['forum_name'],
             $forum_id, $phpbb_seo->seo_static['forum']);
            }
             $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 '<a href="' . $post_url . '">recent post</a> to &quot;';     
      echo '<a href="'. $topic_url .'">'. $topic_title .'</a>&quot;<br/>';
   }
}
GetTopic(2,55,"topic_time");
?>

But i call the functions in the directory / and not in /forum/ i receive this error:
Code: Select all
[phpBB Debug] PHP Notice: in file /Users/duccio/Sites/bigbug3/forum/includes/utf/utf_tools.php on line 1776: include(/forum/includes/utf/utf_normalizer.php) [function.include]: failed to open stream: No such file or directory
[phpBB Debug] PHP Notice: in file /Users/duccio/Sites/bigbug3/forum/includes/utf/utf_tools.php on line 1776: include() [function.include]: Failed opening '/forum/includes/utf/utf_normalizer.php' for inclusion (include_path='.:/Applications/xampp/xamppfiles/lib/php')

Fatal error: Class 'utf_normalizer' not found in /Users/duccio/Sites/bigbug3/forum/includes/utf/utf_tools.php on line 1781


Ideas? :?
User avatar
psaico
PR0
PR0
 
Posts: 56
Joined: Wed May 14, 2008 2:55 pm

Postby SeO » Fri May 30, 2008 8:08 am

Try to globalise $phpbb_root_path in your function and eventually to set it outside of it.
SeO
Admin
Admin
 
Posts: 6334
Joined: Wed Mar 15, 2006 9:41 pm

Postby psaico » Fri May 30, 2008 8:19 am

Oh yeahhhhhh!
it work :) :)


edit:
if i call two times the function i receive this error:
Code: Select all

Fatal error: Cannot redeclare deregister_globals() (previously declared in /Users/duccio/Sites/bigbug3/forum/common.php:32) in /Users/duccio/Sites/bigbug3/forum/common.php on line 94


ideas? :wink:
User avatar
psaico
PR0
PR0
 
Posts: 56
Joined: Wed May 14, 2008 2:55 pm

Next

Return to Advanced SEO URL

 


  • Related topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: No registered users and 4 guests


 
cron