Hello,
I have a custom script inside a phpBB page, if i know a topic ID, how can i go about using the phpBB SEO functions to generate the URL?
If there a function like generate_url($topic_id) for example?
Thanks!
Moderator: Moderators
/**
* generate_topic_url($topic_data = array(), $forum_name = false, $start = 0)
* Example call :
* $topic_data = array('topic_id' => 25, 'topic_type' => POST_NORMAL, 'topic_title' => 'this is a title', 'forum_id' => 5);
* if ($test = generate_topic_url($topic_data)) {
* $url = $test;
* }
* */
function generate_topic_url($topic_data = array(), $forum_name = false, $start = 0) {
global $phpbb_root_path, $phpEx, $phpbb_seo, $db;
$topic_id = !empty($topic_data['topic_id']) ? (int) $topic_data['topic_id'] : false;
$topic_title = !empty($topic_data['topic_title']) ? censor_text($topic_data['topic_title']) : false;
$topic_type = isset($topic_data['topic_title']) ? (int) $topic_data['topic_title'] : false;
$forum_id = !empty($topic_data['forum_id']) ? (int) $topic_data['forum_id'] : false;
$start = max(0, (int) $start);
if ($topic_id === false) {
return false;
}
if (empty($phpbb_seo->seo_url['topic'][$topic_id]) || $forum_id === false) {
if ($topic_title === false || $topic_type === false || $forum_name === false || $forum_id === false) {
$sql = "SELECT t.topic_title, t.topic_id, t.forum_id, topic_type, f.forum_name
FROM " . TOPICS_TABLE . " AS t, " . FORUMS_TABLE . " AS f
WHERE t.topic_id = $topic_id
AND f.forum_id = t.forum_id";
$result = $db->sql_query($sql);
if ($row = $db->sql_fetchrow($result)) {
$topic_title = censor_text($row['topic_title']);
$topic_type = $row['topic_type'];
$forum_name = $row['forum_name'];
$forum_id = (int) $row['forum_id'];
} else {
return false;
}
}
if ($topic_type == POST_GLOBAL) {
$phpbb_seo->seo_opt['topic_type'][$topic_id] = POST_GLOBAL;
}
$phpbb_seo->seo_url['topic'][$topic_id] = $phpbb_seo->format_url($topic_title);
if ( empty($phpbb_seo->seo_url['forum'][$forum_id]) ) {
$phpbb_seo->seo_url['forum'][$forum_id] = $phpbb_seo->set_url($forum_name, $forum_id, $phpbb_seo->seo_static['forum']);
}
}
return append_sid($phpbb_root_path . "viewtopic.$phpEx?f=$forum_id&t=$topic_id" . ( $start ? "&start=$start" : ''));
}$topic_data = array('topic_id' => xx); $topic_data = array('topic_id' => 25, 'topic_type' => POST_NORMAL, 'topic_title' => 'this is a title', 'forum_id' => 5);
if ($test = generate_topic_url($topic_data), 'forum title') {
$url = $test;
}


return append_sid($phpbb_root_path . "viewtopic.$phpEx?f=$forum_id&t=$topic_id" . ( $start ? "&start=$start" : ''));return append_sid($phpbb_seo->seo_url['forum'][$forum_id] . "/" . $phpbb_seo->seo_url['topic'][$topic_id] . "-t" . $topic_id . ( $start ? "/page$start.html" : '.html'));
Users browsing this forum: No registered users and 2 guests