Simple Machines Community Forum

Customizing SMF => Modifications and Packages => Topic started by: SleePy on June 24, 2008, 10:56:10 PM

Title: [Outdated] Redirect Moved Topics
Post by: SleePy on June 24, 2008, 10:56:10 PM
Link to the mod (https://custom.simplemachines.org/index.php?mod=1273)

This customization will make all future moved topic notices redirect automatically to the topics new location.
The message is still posted for the redirect topic incase you ever want to remove this customization or in process of an upgrade.

There are some minimal changes to the MessageIndex.template.php that are not needed but do make it look a bit nicer for your moved topic links by removing the useless junk such as replies, views, etc.

SMF 2.1 does this by default and this is no longer required
Title: Re: Redirect Moved Topics
Post by: Nathaniel on June 24, 2008, 11:03:39 PM
Thanks for the nice modification SleePy.

Installed perfectly (on a forum with 15+ mods) and works very well! :D
Title: Re: Redirect Moved Topics
Post by: ディン1031 on June 25, 2008, 01:25:16 AM
Is it possible to make a Version for SMF 1.1.x?

Bye
DIN1031
Title: Re: Redirect Moved Topics
Post by: SleePy on June 25, 2008, 01:54:16 PM
Not really.
This version taps into the approved and id_previous_topic columns that only exist in 2.0. Which is the reason it is able to be done so easily :)

To make a 1.1 version we would have copy the approved and id_previous_topic from 2.0 smf_topics table and use the same thing in 1.1 so upgrading to 2.0 in the future would work.

Title: Re: Redirect Moved Topics
Post by: aldo on June 26, 2008, 12:12:33 AM
Awesome! I always saw little point in the move topic posts themselves when they should have been redirected to the new ones in the first place :P Thanks!
Title: Re: Redirect Moved Topics
Post by: Rocks-HD on July 19, 2008, 05:21:42 AM
how

it's the gretest mod and work very well in smf 2.0 beta 3.1 public

thanks
Title: Re: Redirect Moved Topics
Post by: Rocks-HD on July 31, 2008, 01:13:48 PM
I have a problem

when I move a topic I can't delete the topic of the redirect.

I don't know what to do!
Title: Re: Redirect Moved Topics
Post by: Nathaniel on August 07, 2008, 02:08:03 AM
Okay, this mod has an error, this edit from the 'Redirect_Moved_Topics-20b3p.xml' file returns some errors.
      <operation>
         <search position="replace"><![CDATA[               'href' => $scripturl . '?topic=' . $row['id_topic'] . ($row['num_replies'] == 0 ? '.0' : '.msg' . $row['id_last_msg']) . '#new',
               'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . ($row['num_replies'] == 0 ? '.0' : '.msg' . $row['id_last_msg']) . '#new" ' . ($row['num_replies'] == 0 ? '' : 'rel="nofollow"') . '>' . $row['last_subject'] . '</a>'
]]></search>
         <add><![CDATA[               'href' => $scripturl . '?topic=' . ($row['approved'] == 2 && !empty($row['id_previous_topic']) ? $row['id_previous_topic'] : $row['id_topic']) . ($user_info['is_guest'] ? ('.' . (!empty($options['view_newest_first']) ? 0 : ((int) (($row['num_replies']) / $context['pageindex_multiplier'])) * $context['pageindex_multiplier']) . '#msg' . $row['id_last_msg']) : (($row['num_replies'] == 0 ? '.0' : '.msg' . $row['id_last_msg']) . '#new')),
               'link' => '<a href="' . $scripturl . '?topic=' . ($row['approved'] == 2 && !empty($row['id_previous_topic']) ? $row['id_previous_topic'] : $row['id_topic']) . ($user_info['is_guest'] ? ('.' . (!empty($options['view_newest_first']) ? 0 : ((int) (($row['num_replies']) / $context['pageindex_multiplier'])) * $context['pageindex_multiplier']) . '#msg' . $row['id_last_msg']) : (($row['num_replies'] == 0 ? '.0' : '.msg' . $row['id_last_msg']) . '#new')) . '" ' . ($row['num_replies'] == 0 ? '' : 'rel="nofollow"') . '>' . $row['last_subject'] . '</a>'
]]></add>
      </operation>


The errors only seem to occur for guests, and they concern the lack of a $context['pageindex_multiplier'] value:
Quote
http://www.verbtest.com/index.php?board=3.0;sort=last_post
2: Division by zero
File: /******/Sources/MessageIndex.php
Line: 552
Quote
http://www.verbtest.com/index.php?board=3.0;sort=last_post
8: Undefined index: pageindex_multiplier
File: /*****/Sources/MessageIndex.php
Line: 552

Line 552 is this:
'href' => $scripturl . '?topic=' . ($row['approved'] == 2 && !empty($row['id_previous_topic']) ? $row['id_previous_topic'] : $row['id_topic']) . ($user_info['is_guest'] ? ('.' . (!empty($options['view_newest_first']) ? 0 : ((int) (($row['num_replies']) / $context['pageindex_multiplier'])) * $context['pageindex_multiplier']) . '#msg' . $row['id_last_msg']) : (($row['num_replies'] == 0 ? '.0' : '.msg' . $row['id_last_msg']) . '#new')),

Have a look at this thread for reference:
http://www.simplemachines.org/community/index.php?topic=253916.new#new (http://www.simplemachines.org/community/index.php?topic=253916.new#new)
Title: Re: Redirect Moved Topics
Post by: Rocks-HD on August 12, 2008, 12:02:53 AM
thanks man

it's work very well
Title: Re: Redirect Moved Topics
Post by: dannbass on November 18, 2009, 02:46:16 PM
@Sleepy, that package manager says that the file is corrupted, could you re-upload it again?
Title: Re: Redirect Moved Topics
Post by: SleePy on November 18, 2009, 11:29:11 PM
I repackaged the file and reuploaded it.  Try again :)
Title: Re: Redirect Moved Topics
Post by: dannbass on November 18, 2009, 11:39:15 PM
Awesome! thank you!! installed perfectly, and looks very nice!
Title: Re: Redirect Moved Topics
Post by: aw06 on March 30, 2010, 11:21:06 AM
Quote from: Rocks-HD on July 31, 2008, 01:13:48 PM
I have a problem

when I move a topic I can't delete the topic of the redirect.

I don't know what to do!

Go to Forum Maintenance>Remove Old Posts>Moved topic notices.
Title: Re: Redirect Moved Topics
Post by: frozenas on July 30, 2010, 02:10:53 PM
Hi. How can i replace that:

  'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0', 'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['first_subject'] . '</a>' 

to that code:

  'href' => $scripturl . '?topic=' . ($row['approved'] == 2 && !empty($row['id_previous_topic']) ? $row['id_previous_topic'] : $row['id_topic']) . '.0', 'link' => '<a href="' . $scripturl . '?topic=' . ($row['approved'] == 2 && !empty($row['id_previous_topic']) ? $row['id_previous_topic'] : $row['id_topic']) . '.0">' . $row['first_subject'] . '</a>' 

when my template have this code:

'href' => $scripturl . '?topic=' . ($row['approved'] == 2 && !empty($row['id_previous_topic']) ? $row['id_previous_topic'] : $row['id_topic']) . '.0',
'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0"'  . $row['nice_tooltip_first_msg'] . ' >' . $row['first_subject'] . '</a>'
?
Title: Re: Redirect Moved Topics
Post by: Joker™ on July 30, 2010, 02:53:03 PM
great mod SleePy ;D , specially for a guy like me who's mods are very lazy , they always leave tails of posts on boards .
Title: Re: Redirect Moved Topics
Post by: SleePy on August 06, 2010, 08:59:43 PM
frozenas,

It looks like the code was already applied to that section of code.
Title: Re: Redirect Moved Topics
Post by: Rain Forest on March 12, 2011, 07:38:18 AM
Please update to RC5 :)
Title: Re: Redirect Moved Topics
Post by: [Crash_Override] on July 28, 2011, 06:34:09 PM
Is this mod still in development?

If it is I would like to brink to attention that although it says it is compatible with version 2.0 I get at least 5 errors when trying to install it on a regular SMF board
Title: Re: Redirect Moved Topics
Post by: Spoogs on July 28, 2011, 06:43:06 PM
What are the errors you get?
Title: Re: Redirect Moved Topics
Post by: [Crash_Override] on July 28, 2011, 07:02:17 PM
In ./Sources/Subs-Post.php

Find
'id_poll' => 'int', 'unapproved_posts' => 'int', 'approved' => 'int',


Replace


'id_poll' => 'int', 'unapproved_posts' => 'int', 'approved' => 'int',
                // Add this in for Moved Redirction Topics.
'id_previous_topic' => 'int',





Find

$topicOptions['poll'] === null ? 0 : $topicOptions['poll'], $msgOptions['approved'] ? 0 : 1, $msgOptions['approved'],


Replace

$topicOptions['poll'] === null ? 0 : $topicOptions['poll'], $msgOptions['approved'] ? 0 : 1, $msgOptions['approved'],
                // Tell it where to send the Moved Redirect Topic, maybe.
!empty($topicOptions['id_previous_topic']) ? $topicOptions['id_previous_topic'] : 0,


Then in ./Themes/default/MessageIndex.template.php

Find

<img src="', $settings['images_url'], '/topic/', $topic['class'], '.gif" alt="" />


Replace

', !$topic['is_moved_redirect'] ? '<img src="' . $settings['images_url'] . '/topic/' . $topic['class'] . '.gif" alt="" />' : '' ,'





Find

<img src="', $topic['first_post']['icon_url'], '" alt="" />


Replace

', !$topic['is_moved_redirect'] ? '<img src="' . $topic['first_post']['icon_url'] . '" alt="" />' : '', '





Find

// Is this topic new? (assuming they are logged in!)
if ($topic['new'] && $context['user']['is_logged'])


Replace

// Is this topic new? (assuming they are logged in!)
if ($topic['new'] && $context['user']['is_logged'] && !$topic['is_moved_redirect'])





Find

', $topic['replies'], ' ', $txt['replies'], '


Replace

', $topic['is_moved_redirect'] ? '--' : $topic['replies'] . ' ' . $txt['replies'], '





Find

', $topic['views'], ' ', $txt['views'], '


Replace

', $topic['is_moved_redirect'] ? '--' : $topic['views'] . ' ' . $txt['views'], '





Find

<a href="', $topic['last_post']['href'], '"><img src="', $settings['images_url'], '/icons/last_post.gif" alt="', $txt['last_post'], '" title="', $txt['last_post'], '" /></a>
', $topic['last_post']['time'], '<br />
', $txt['by'], ' ', $topic['last_post']['member']['link'], '


Replace

', $topic['is_moved_redirect'] ? '--' : '<a href="' . $topic['last_post']['href'] . '"><img src="' . $settings['images_url'] . '/icons/last_post.gif" alt="' . $txt['last_post'] . '" title="' . $txt['last_post'] . '" /></a>
' . $topic['last_post']['time'] . '<br />
' . $txt['by'] . ' ' . $topic['last_post']['member']['link'], '


Now the weird thing is I can find all of those code segments in the corresponding files but the package won't install no matter what.  Does this mean I have to do it manually?
Title: Re: Redirect Moved Topics
Post by: Spoogs on July 28, 2011, 07:07:13 PM
What other mods do you have installed, more than likely the target code has been edited by another mod, you can try to manually edit the files if you'd like

Manual Installation of Mods (http://wiki.simplemachines.org/smf/Manual_installation_of_mods)


Actually the errors are there on a fresh install as well.
Title: Re: Redirect Moved Topics
Post by: [Crash_Override] on July 28, 2011, 07:16:55 PM
I considered that as an option so I did a vanilla install on my private server and got the same thing.

PM me if you want to access the test forum and see what I am talking about

seems we both figured that one out
Title: Re: Redirect Moved Topics
Post by: Spoogs on July 28, 2011, 07:19:52 PM
I checked the mod itself it's the number of indentations that are incorrect... for example

Code (find) Select
<a href="', $topic['last_post']['href'], '"><img src="', $settings['images_url'], '/icons/last_post.gif" alt="', $txt['last_post'], '" title="', $txt['last_post'], '" /></a>
', $topic['last_post']['time'], '<br />
', $txt['by'], ' ', $topic['last_post']['member']['link'], '


should be
Code (find) Select
<a href="', $topic['last_post']['href'], '"><img src="', $settings['images_url'], '/icons/last_post.gif" alt="', $txt['last_post'], '" title="', $txt['last_post'], '" /></a>
', $topic['last_post']['time'], '<br />
', $txt['by'], ' ', $topic['last_post']['member']['link'], '
Title: Re: Redirect Moved Topics
Post by: [Crash_Override] on July 28, 2011, 07:21:24 PM
really its that sensitive!?

this makes sense I guess since I use the search option in Dreamweaver to ignore white-space

well I can modify the xml so it works with the default but have had no luck with the core theme

I've attached my modified package that works for now but will leave it up to the developer if they want to continue with it
Title: Re: Redirect Moved Topics
Post by: Cereus on January 14, 2012, 09:42:57 PM
Hello guys! Do you have any update to this MOD?

Hugs!
Title: Re: Redirect Moved Topics
Post by: NekoJonez on June 28, 2013, 06:04:11 PM
I can't delete the moved topic thingies.
Title: Re: Redirect Moved Topics
Post by: Kolya on February 09, 2015, 03:03:12 PM
There is another problem with this mod (apart from the fact that you can only delete moved topic notices through the backend (http://www.simplemachines.org/community/index.php?topic=246230.msg2561544#msg2561544)):
The moved topic notice (the redirector) is marked unread for anyone but the topic mover. And it is rather difficult to change that state. You cannot go into the topic and marking it as read via checkbox on the topic table doesn't work either for some reason. The only way is to mark ALL read (this can be within a subforum scope).

Which makes me think that a little Javascript redirect inside the topic notice would solve redirection more gracefully.
Title: Re: Redirect Moved Topics
Post by: Kolya on February 09, 2015, 04:31:34 PM
Quote from: Kolya on February 09, 2015, 03:03:12 PM
Which makes me think that a little Javascript redirect inside the topic notice would solve redirection more gracefully.

In Source/MoveTopic.php:
FIND
$txt['movetopic_auto_topic'] => '[iurl]' . $scripturl . '?topic=' . $topic . '.0[/iurl]'

REPLACE WITH
$txt['movetopic_auto_topic'] => '[iurl]' . $scripturl . '?topic=' . $topic . '.0[/iurl]
     
Redirecting....<script>var mtu = document.getElementsByClassName("bbc_link");setInterval(function(){window.location = mtu[mtu.length-1].innerHTML;},2000);</script>'
Title: Re: Redirect Moved Topics
Post by: Kolya on October 10, 2015, 06:50:14 PM
I have removed my own script (above) from my boards today. It was causing a problem in lists of posts where the redirecting thread appears including its post text and redirection script. The whole listing page was unintentionally redirected in this case. An example of such a list is Posts made by a user and possibly search results.

I have therefore replaced this script with this mod by Arantor (http://custom.simplemachines.org/mods/index.php?mod=2257) which allows to redirect the user as well as setting an expiry date on the redirection topic.