| |
| |
|
|
|
|
| |
|
| |
|
| :: |
| Author |
Message |
hoaxx
Joined: 07 Dec 2007 Posts: 6
|
Posted: Sun Dec 09, 2007 9:08 pm Post subject: [Patch] Translate topic URL's Mod |
|
|
Hello,
I was wandering if anyone would have an idea how to make this Mod: Translate topic URL's work with Advanced mod Rewrite...
The mod automatically changes intern urls so that they are displayed with their Topic Titles.
Code (.txt) is here (it's merely one function).
// I used the search function, but found no referrence to this mod,
// hope this is the right category to go... |
|
|
| Back to top |
|
 |
|
 |
SeO Administrateur - Site Admin

Joined: 15 Mar 2006 Posts: 3103
|
Posted: Mon Dec 10, 2007 11:54 am Post subject: Re: [Patch] Translate topic URL's Mod |
|
|
Really interesting mod actually.
Could be used to mod all the posted links in post when migrating urls as well, using this code as an add on to the rebuilt search table mod for example.
Anyway, here is how you'll have rewritten urls in the modified links :
| Code: | #
#-----[ OPEN ]------------------------------------------
#
posting.php
#
#-----[ FIND ]------------------------------------------
# partial line
prepare_post($mode,
#
#-----[ BEFORE, ADD ]------------------------------------------
#
//MOD Translate_topic_urls for saving message
$message = xlat_topic_links($message);
#
#-----[ FIND ]------------------------------------------
#
if( $preview )
#
#-----[ BEFORE, ADD ]------------------------------------------
#
//MOD Translate_topic_urls for saving message
$message = xlat_topic_links($message);
#
#-----[ OPEN ]------------------------------------------
#
includes/functions_post.php
#
#-----[ FIND ]------------------------------------------
#
?>
#
#-----[ BEFORE ADD ]------------------------------------------
#
//MOD Translate_topic_urls
//Translate http://www.domain.com/forum/viewtopic.php?..... into url BBCode and topic title
//Works with t=1234.... and p=1234.....
function xlat_topic_links ($message) {
global $phpEx, $db, $board_config;
// www.phpBB-SEO.com SEO TOOLKIT BEGIN
global $phpbb_seo;
// www.phpBB-SEO.com SEO TOOLKIT END
$valid_url = "\w\#$%&~/.\-;:=,?@+"; //from bbcode.php, but no square brackets
// www.phpBB-SEO.com SEO TOOLKIT BEGIN
$pattern = "(?<!\[url=)" . $phpbb_seo->seo_path['phpbb_url'] . "viewtopic\.$phpEx\?[$valid_url]+";
// www.phpBB-SEO.com SEO TOOLKIT END
$pattern = str_replace("/", "\/", $pattern);
$message = preg_replace_callback ("`$pattern`si", 'xlat_topic_links_callback', $message);
return $message;
}
//MOD Translate_topic_urls
//Do the actual translation of one URL into BBCode plus topic title
function xlat_topic_links_callback ($link)
{
global $db;
// www.phpBB-SEO.com SEO TOOLKIT BEGIN
global $phpbb_seo, $phpEx;
// www.phpBB-SEO.com SEO TOOLKIT END
$url = $link[0];
$pos = strpos($url, "=");
if ($pos > 0) {
$type = substr($url, $pos - 1, 1); //POST_TOPIC_URL or POST_POST_URL
for ($i = $pos+1;$i<strlen($url);$i++) { //Lift the post or topic_id
if (! is_numeric(substr($url, $i, 1))) break;
}
$id = intval(substr($url, $pos + 1, $i - $pos - 1));
switch ($type) { //Create the query to get the topic title
// www.phpBB-SEO.com SEO TOOLKIT BEGIN
case POST_TOPIC_URL:
$sql = "SELECT t.topic_title, t.topic_id
FROM " . TOPICS_TABLE . " t
WHERE t.topic_id = $id";
if ( ! ($result = $db->sql_query($sql)) ) {
message_die(GENERAL_ERROR, "Cannot fetch topic title", '', __LINE__, __FILE__, $sql);
}
$row = $db->sql_fetchrow($result);
if ( empty($phpbb_seo->seo_url['topic'][$row['topic_id']]) ) {
$phpbb_seo->seo_url['topic'][$row['topic_id']] = $phpbb_seo->format_url($row['topic_title']);
}
$url = $phpbb_seo->seo_path['phpbb_url'] . append_sid( "viewtopic.$phpEx?" . POST_TOPIC_URL . '=' . $row['topic_id']);
$url = "[url=" . $url . "]" . $row['topic_title'] . "[/url]";
break;
case POST_POST_URL:
$sql = "SELECT t.topic_title, p.post_id
FROM " . TOPICS_TABLE . " t, " . POSTS_TABLE . " p
WHERE t.topic_id = p.topic_id
AND p.post_id = $id";
if ( ! ($result = $db->sql_query($sql)) ) {
message_die(GENERAL_ERROR, "Cannot fetch topic title", '', __LINE__, __FILE__, $sql);
}
$row = $db->sql_fetchrow($result);
$url = $phpbb_seo->seo_path['phpbb_url'] . append_sid( "viewtopic.$phpEx?" . POST_POST_URL . '=' . $row['post_id']) . '#' . $row['post_id'];
$url = "[url=" . $url . "]" . $row['topic_title'] . "[/url]";
break;
}
// www.phpBB-SEO.com SEO TOOLKIT END
}
return($url);
}
//END MOD Translate_topic_urls
#
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------
#
# EoM |
As is, it's still not satisfying all cases, like the original mod in fact, urls such as
or
can end up like :
| Code: | | [url][url=url]topic title[/url][/url] |
and
| Code: | | [url=url][url=url]topic title[/url][/url] |
but it's working nicely on other cases.
Since I'm interested into this mod, I'll work on these issue later on  |
_________________
|
|
| Back to top |
|
 |
hoaxx
Joined: 07 Dec 2007 Posts: 6
|
Posted: Mon Dec 10, 2007 6:18 pm Post subject: Re: [Patch] Translate topic URL's Mod |
|
|
Does it in this form accept seo'ed titles as well or unmodified
viewtopic.php?t=1337 ones only? |
|
|
| Back to top |
|
 |
|
| Navigation |
Similar Topics |
|
|
|
|
|
|
|
| |
|
|
|
|
| |
|
|
|
|
| |