Posts: 15,129
Threads: 240
Joined: Jun 2009
Reputation:
703
2012-04-12, 02:17 PM
Ah, I missed the curly bracket. try this instead:
/**
* Redirect the user to a given URL with a given message
*
* @param string The URL to redirect the user to
* @param string The redirection message to be shown
*/
function redirect($url, $message="", $title="")
{
global $header, $footer, $mybb, $theme, $headerinclude, $templates, $lang, $plugins;
$redirect_args = array('url' => &$url, 'message' => &$message, 'title' => &$title);
$plugins->run_hooks("redirect", $redirect_args);
if($mybb->input['ajax'])
{
// Send our headers.
@header("Content-type: text/html; charset={$lang->settings['charset']}");
echo "<script type=\"text/javascript\">\n";
if($message != "")
{
echo 'alert("'.addslashes($message).'");';
}
$url = str_replace("#", "&#", $url);
$url = htmlspecialchars_decode($url);
$url = str_replace(array("\n","\r",";"), "", $url);
echo 'window.location = "'.addslashes($url).'";'."\n";
echo "</script>\n";
exit;
}
if(!$message)
{
$message = $lang->redirect;
}
$time = TIME_NOW;
$timenow = my_date($mybb->settings['dateformat'], $time) . " " . my_date($mybb->settings['timeformat'], $time);
if(!$title)
{
$title = $mybb->settings['bbname'];
}
// Show redirects only if both ACP and UCP settings are enabled, or ACP is enabled, and user is a guest.
if($mybb->settings['redirects'] == 1 && ($mybb->user['showredirect'] != 0 || !$mybb->user['uid']) && (THIS_SCRIPT != 'search.php'))
{
$url = htmlspecialchars($url);
eval("\$redirectpage = \"".$templates->get("redirect")."\";");
output_page($redirectpage);
}
else
{
$url = htmlspecialchars_decode($url);
$url = str_replace(array("\n","\r",";"), "", $url);
run_shutdown();
if(my_substr($url, 0, 7) !== 'http://' && my_substr($url, 0, 8) !== 'https://')
{
header("Location: {$mybb->settings['bburl']}/{$url}");
}
else
{
header("Location: {$url}");
}
}
exit;
}
Posts: 42
Threads: 7
Joined: Mar 2012
Reputation:
0
2012-04-12, 02:57 PM
(This post was last modified: 2012-04-12, 03:48 PM by Come On Thru.)
(2012-04-12, 02:17 PM)euantor Wrote: Ah, I missed the curly bracket. try this instead:
/**
* Redirect the user to a given URL with a given message
*
* @param string The URL to redirect the user to
* @param string The redirection message to be shown
*/
function redirect($url, $message="", $title="")
{
global $header, $footer, $mybb, $theme, $headerinclude, $templates, $lang, $plugins;
$redirect_args = array('url' => &$url, 'message' => &$message, 'title' => &$title);
$plugins->run_hooks("redirect", $redirect_args);
if($mybb->input['ajax'])
{
// Send our headers.
@header("Content-type: text/html; charset={$lang->settings['charset']}");
echo "<script type=\"text/javascript\">\n";
if($message != "")
{
echo 'alert("'.addslashes($message).'");';
}
$url = str_replace("#", "&#", $url);
$url = htmlspecialchars_decode($url);
$url = str_replace(array("\n","\r",";"), "", $url);
echo 'window.location = "'.addslashes($url).'";'."\n";
echo "</script>\n";
exit;
}
if(!$message)
{
$message = $lang->redirect;
}
$time = TIME_NOW;
$timenow = my_date($mybb->settings['dateformat'], $time) . " " . my_date($mybb->settings['timeformat'], $time);
if(!$title)
{
$title = $mybb->settings['bbname'];
}
// Show redirects only if both ACP and UCP settings are enabled, or ACP is enabled, and user is a guest.
if($mybb->settings['redirects'] == 1 && ($mybb->user['showredirect'] != 0 || !$mybb->user['uid']) && (THIS_SCRIPT != 'search.php'))
{
$url = htmlspecialchars($url);
eval("\$redirectpage = \"".$templates->get("redirect")."\";");
output_page($redirectpage);
}
else
{
$url = htmlspecialchars_decode($url);
$url = str_replace(array("\n","\r",";"), "", $url);
run_shutdown();
if(my_substr($url, 0, 7) !== 'http://' && my_substr($url, 0, 8) !== 'https://')
{
header("Location: {$mybb->settings['bburl']}/{$url}");
}
else
{
header("Location: {$url}");
}
}
exit;
}
Works like a charm. I owe you one.
MyBB should do something about this thing. Especially on Lost Password Recovery when Friendly Redirect Pages are disabled, cause users are redirected straight to the index page and has no feedback about whether their password recovery procedure worked (or how it's supposed to work).
Posts: 15,129
Threads: 240
Joined: Jun 2009
Reputation:
703
2012-04-12, 05:52 PM
Yeah, it would be nice to have some kind of feedback where feedback really is necessary (such as the password recovery as you mentioned).
Posts: 1,869
Threads: 71
Joined: Feb 2012
Reputation:
243
2013-02-12, 12:38 PM
Sorry if I bump such an old thread, but I'd like to inform you I've just begun a plugin development which will feature inline success messages. This is as far as I've tried pretty simple to do and it won't require too much development.
Posts: 152
Threads: 17
Joined: Dec 2013
Reputation:
1
2014-01-29, 01:04 PM
(2012-04-12, 02:17 PM)Euan T Wrote: Ah, I missed the curly bracket. try this instead:
/**
* Redirect the user to a given URL with a given message
*
* @param string The URL to redirect the user to
* @param string The redirection message to be shown
*/
function redirect($url, $message="", $title="")
{
global $header, $footer, $mybb, $theme, $headerinclude, $templates, $lang, $plugins;
$redirect_args = array('url' => &$url, 'message' => &$message, 'title' => &$title);
$plugins->run_hooks("redirect", $redirect_args);
if($mybb->input['ajax'])
{
// Send our headers.
@header("Content-type: text/html; charset={$lang->settings['charset']}");
echo "<script type=\"text/javascript\">\n";
if($message != "")
{
echo 'alert("'.addslashes($message).'");';
}
$url = str_replace("#", "&#", $url);
$url = htmlspecialchars_decode($url);
$url = str_replace(array("\n","\r",";"), "", $url);
echo 'window.location = "'.addslashes($url).'";'."\n";
echo "</script>\n";
exit;
}
if(!$message)
{
$message = $lang->redirect;
}
$time = TIME_NOW;
$timenow = my_date($mybb->settings['dateformat'], $time) . " " . my_date($mybb->settings['timeformat'], $time);
if(!$title)
{
$title = $mybb->settings['bbname'];
}
// Show redirects only if both ACP and UCP settings are enabled, or ACP is enabled, and user is a guest.
if($mybb->settings['redirects'] == 1 && ($mybb->user['showredirect'] != 0 || !$mybb->user['uid']) && (THIS_SCRIPT != 'search.php'))
{
$url = htmlspecialchars($url);
eval("\$redirectpage = \"".$templates->get("redirect")."\";");
output_page($redirectpage);
}
else
{
$url = htmlspecialchars_decode($url);
$url = str_replace(array("\n","\r",";"), "", $url);
run_shutdown();
if(my_substr($url, 0, 7) !== 'http://' && my_substr($url, 0, 8) !== 'https://')
{
header("Location: {$mybb->settings['bburl']}/{$url}");
}
else
{
header("Location: {$url}");
}
}
exit;
}
What code would I have to use if I only want friendly redirects for new threads? And can I edit the time duration of the friendly redirect, longer messages are impossible to read within 5seconds?
Posts: 15,129
Threads: 240
Joined: Jun 2009
Reputation:
703
2014-01-29, 04:46 PM
Try this Gobee:
/**
* Redirect the user to a given URL with a given message
*
* @param string The URL to redirect the user to
* @param string The redirection message to be shown
*/
function redirect($url, $message="", $title="")
{
global $header, $footer, $mybb, $theme, $headerinclude, $templates, $lang, $plugins;
$redirect_args = array('url' => &$url, 'message' => &$message, 'title' => &$title);
$plugins->run_hooks("redirect", $redirect_args);
if($mybb->input['ajax'])
{
// Send our headers.
@header("Content-type: text/html; charset={$lang->settings['charset']}");
echo "<script type=\"text/javascript\">\n";
if($message != "")
{
echo 'alert("'.addslashes($message).'");';
}
$url = str_replace("#", "&#", $url);
$url = htmlspecialchars_decode($url);
$url = str_replace(array("\n","\r",";"), "", $url);
echo 'window.location = "'.addslashes($url).'";'."\n";
echo "</script>\n";
exit;
}
if(!$message)
{
$message = $lang->redirect;
}
$time = TIME_NOW;
$timenow = my_date($mybb->settings['dateformat'], $time) . " " . my_date($mybb->settings['timeformat'], $time);
if(!$title)
{
$title = $mybb->settings['bbname'];
}
// Show redirects only if both ACP and UCP settings are enabled, or ACP is enabled, and user is a guest.
if($mybb->settings['redirects'] == 1 && ($mybb->user['showredirect'] != 0 || !$mybb->user['uid']) && (THIS_SCRIPT == 'new thread.php'))
{
$url = htmlspecialchars($url);
eval("\$redirectpage = \"".$templates->get("redirect")."\";");
output_page($redirectpage);
}
else
{
$url = htmlspecialchars_decode($url);
$url = str_replace(array("\n","\r",";"), "", $url);
run_shutdown();
if(my_substr($url, 0, 7) !== 'http://' && my_substr($url, 0, 8) !== 'https://')
{
header("Location: {$mybb->settings['bburl']}/{$url}");
}
else
{
header("Location: {$url}");
}
}
exit;
}
I'm not entirely sure where the duration is specified actually. It may be within the "redirect" template itself.
|