tas2580 / seourls

phpBB Extension: URL rewriting for phpBB forums
https://tas2580.net/downloads/phpbb-seo-url/
GNU General Public License v2.0
44 stars 25 forks source link

Error with stacked forum in last post #10

Closed soft4tec closed 9 years ago

soft4tec commented 9 years ago

If you have subforums in your forum there is an in the link for the last post. For Example

I found an quick&dirty solution in the listener.php for the function:

public function display_forums_modify_template_vars($event)

Replace the line:

$url = $this->generate_topic_link($event['row']['forum_id'], $event['row']['forum_name'], $event['row']['topic_id'], $event['row']['topic_title']);

with:

                $sql = 'SELECT p.post_id, p.topic_id, p.forum_id, f.forum_name
                        FROM ' . POSTS_TABLE . ' AS p
                        LEFT JOIN ' . FORUMS_TABLE . ' AS f
                        ON f.forum_id = p.forum_id
                        WHERE ' . $db->sql_build_array('SELECT', array('post_id'    => $event['row']['forum_last_post_id']));
                $result = $db->sql_query($sql);
                $LastPostRow = $db->sql_fetchrow($result);
                $db->sql_freeresult($result);
                $url = $this->generate_topic_link($LastPostRow['forum_id'], $LastPostRow['forum_name'], $LastPostRow['topic_id'], $event['row']['forum_last_post_subject']);

Maybe there is a better way to get the title and ids, but this works for the first.

Sarr commented 9 years ago

@soft4tec sorry but it doesn't work for me. I get: "Fatal error: Call to a member function sql_build_array() on a non-object in /home/sarr/public_html/forum.swordcoast.pl/ext/tas2580/seourls/event/listener.php on line 184"

There are 2 occurance of '$url = $this->generate_topic_link($event['row']['forum_id'], $event['row']['forum_name'], $event['row']['topic_id'], $event['row']['topic_title']);'

First is in "public function search_modify_tpl_ary($event)" I changed only the second one, as you wrote. (under display_forums_modify_template_vars)

soft4tec commented 9 years ago

Oh sorry, I forget the

global $db;

to access the Database-Object in the function. Then it should be work.

tas2580 commented 9 years ago

Thanks for reporting, but your solution has the problem that it will make a lot of SQL queries. I have found a better way without additional SQL queries. I hope it will work.