Jump to content

Create a URL with a comment id?


eskaiter

Recommended Posts

Posted

How can I create a URL with a comment id?
I found the explaination about generating urls in the dev docs https://invisioncommunity.com/developers/docs/fundamentals/urls-r167/
But I might need some more help to get it.

Here is what I got and not work:

<?php
$_SERVER['SCRIPT_FILENAME'] = __FILE__;
require_once 'init.php';
$commentid = '26951';
$url = \IPS\Http\Url::internal( 'app=forums&module=forums&controller=topic&id='.$commentid, 'front', 'forums_topic', array( 'topic-friendly-slug' ) );
echo (string) $url;
?>


Background

I want to move my forum from vb3 (with vbseo) to ips4 and don't want to loose all links.
Since the converter doesn't support creating rewrite rules I am trying to write my one rewrite rule generator script.
Luckily the converter creates few tables with the old and new ids in the database.
The table convert_link contains mappings for the forum ids for expample but others too.
Thread-IDs you can find in the convert_link_topics table.
Post-ID mappings in convert_link_posts table.
...

Generating the rewrtie rules for the forums is straight forward

<?php
$sql = "SELECT 'foreign_id','ipb_id' FROM 'convert_link' WHERE 'type' LIKE 'forums_forums'";
foreach ($db->query($sql) as $row) {
  if ($row['foreign_id'] != $row['ipb_id']) {
    $redirect_from = "/forum/.*-".$row['foreign_id']."/?";
    $redirect_to   = "/forum/".$row['ipb_id']."-redirect/";
    echo "RewriteRule ^".$redirect_from."$ ".$redirect_to." [R=301,L]\n";
  }
}
?>

Plus one more rewrite rule with regex to match all url with same forum ids.

While it was still enough to add a random placeholder text like -redirect to the forum target url,
the first real problem a ran into was to generate the target url for the posts.
Because here you still need the right thread ID. So my first idea was to generate the url with an ips function.
 

Posted

The easiest way would be just to load the content item and then call the url() method.

<?php
$_SERVER['SCRIPT_FILENAME'] = __FILE__;
require_once 'init.php';

$commentId = 26951;

try
{
	$url = \IPS\forums\Topic::load( $commentId )->url();
}
catch( \OutOfRangeException $e )
{
	// Topic doesn't exist
}

If you only want to return the URL if the user has permission, use loadAndCheckPerms() instead of load()

 

P.S. the converter does support redirecting vB URLs and does work with some VBSEO configurations. Please submit a ticket if you're having an issue with them working.

Posted

Thanks Stuart,

you helped me to find the solution and to get the switch to ips4 a bit closer.
For comments you just need to use: 

$url = (string) \IPS\forums\Topic\Post::load( $commentId )->url();

 

40 minutes ago, Stuart Silvester said:

P.S. the converter does support redirecting vB URLs and does work with some VBSEO configurations.

Oh maybe I have overseen that? Where can I read about it? 

Posted
11 hours ago, eskaiter said:

Oh maybe I have overseen that? Where can I read about it? 

It's built in to the Converter application, there's nothing to read about and nothing to enable (providing the Converter application is left enabled and you have 'rewrite urls' enabled) it should just work. If you're having issues with it redirecting your URLs, submit a ticket and we'll take a look at it to see if there's anything wrong.

The VBSEO Urls we support are the ones that contain '.html. If yours do not (i.e. they were customised) an alternative would be to rewrite your custom URL structure to the standard vBulletin URLs (i.e. showthread.php?t=0000) as these will also be detected by Invision Community

Posted

Oh yes, that sounds good, I didn't expect that. Great job!!
I found checkRedirects() function in /applications/convert/sources/Software/Forums/Vbulletin.php
It seems only to take care about forums, threads, post urls, not gallery pictures, tags...?
But I have slightly customized vbseo rewrites anyway so the checkRedirects function doesn't work with every url.
It would be perfect if the converter would grep /vbseo/resources/xml/config.xml
And wouldn't it better performing having the rewrite rules in the vhost.conf file rather than doing it with php?

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...