[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: www/sites/forum/mybb-plugins/seo/inc/plugins
From: Ben Cooksley <sourtooth () gmail ! com>
Date: 2009-04-09 11:29:24
Message-ID: 1239276564.184371.703.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 951444 by bcooksley:
Centralise generation of redirection urls to avoid code dupication
M +44 -57 seo.php
--- trunk/www/sites/forum/mybb-plugins/seo/inc/plugins/seo.php #951443:951444
@@ -279,6 +279,47 @@
{ return; }
}
+ $redir_url = seo_get_redirect_url();
+
+ // Some pages should not be viewed by spiders....
+ if( $session->is_spider == true )
+ {
+ if ( $mybb->input['tid'] != '' && ( $scriptname == 'ratethread.php' || \
$scriptname == 'sendthread.php' || $scriptname == 'printthread.php' || $scriptname == \
'usercp2.php' || $scriptname == 'polls.php' || $scriptname == 'newreply.php' ) ) { + \
$redir_url = seo_topic_url($mybb->input['tid'], 1, $original_url); + } else if ( \
$scriptname == 'misc.php' && $mybb->input['action'] == 'markread' && \
$mybb->input['fid'] != '' ) { + $redir_url = seo_forum_url($mybb->input['fid'], \
1, $original_url); + } else if ( $scriptname == 'editpost.php' && \
$mybb->input['pid'] != '' ) { + $fetch_data = seo_fetch_topic_title(0, \
$mybb->input['pid']); + $redir_url = \
"{$fetch_data['subject']}-t-{$fetch_data['topic_id']}".(($fetch_data['page'] != "" && \
$fetch_data['page'] != 1) ? "-{$fetch_data['page']}" : "") . \
".html#pid{$mybb->input['pid']}"; + } else if ( $mybb->input['uid'] != '' && \
$scriptname == 'member.php' && $mybb->input['action'] == 'emailuser' ) { + \
$redir_url = seo_profile_url($mybb->input['uid'], $original_url, ''); + } else if \
( $mybb->input['uid'] != '' && $scriptname == 'private.php' && $mybb->input['action'] \
== 'send' ) { + $redir_url = seo_profile_url($mybb->input['uid'], \
$original_url, ''); + } else if ( $mybb->input['fid'] != '' && ( $scriptname == \
'usercp2.php' || $scriptname == 'newthread.php' ) ) { + $redir_url = \
seo_forum_url($mybb->input['fid'], 1, $original_url); + } else if ( $scriptname \
== 'misc.php' || $scriptname == 'usercp.php' || $scriptname == 'modcp.php' || \
$scriptname == 'private.php' || $scriptname == 'ratethread.php' || $scriptname == \
'sendthread.php' || $scriptname == 'printthread.php' || $scriptname == 'usercp2.php' \
|| $scriptname == 'polls.php' ) { + $redir_url = 'index.php';
+ }
+ }
+
+ if( $redir_url != '' ) {
+ $redir_url = "{$mybb->settings['bburl']}/{$redir_url}";
+ header("HTTP/1.1 301 Moved Permanently");
+ header("Location: {$redir_url}");
+ }
+}
+
+/**
+ * Function that generates the appropriate url to use in rel=canonical, or for 301 \
redirects + * Could probably be used elsewhere also
+ *
+ * @access private
+ */
+function seo_get_redirect_url()
+{
+ $basename = basename(REQUEST_URI);
+ $scriptname = basename($_SERVER['SCRIPT_NAME']);
+ $original_url = "{$scriptname}?{$_SERVER['QUERY_STRING']}";
if (($scriptname == 'forumdisplay.php' OR $scriptname == 'showthread.php' OR \
$scriptname == 'member.php' OR $scriptname == 'announcements.php' ) && \
FORCE_LOWERCASE == 1 && CASE_COMPATABILITY == 1 && substr($basename, 0, \
strpos($basename, '?')) == $scriptname) {
$seo_type = 2;
@@ -311,33 +352,7 @@
break;
}
}
-
- // Some pages should not be viewed by spiders....
- if( $session->is_spider == true )
- {
- if ( $mybb->input['tid'] != '' && ( $scriptname == 'ratethread.php' || \
$scriptname == 'sendthread.php' || $scriptname == 'printthread.php' || $scriptname == \
'usercp2.php' || $scriptname == 'polls.php' || $scriptname == \
'newreply.php' ) ) {
- $redir_url = seo_topic_url($mybb->input['tid'], 1, $original_url);
- } else if ( $scriptname == 'misc.php' && $mybb->input['action'] == 'markread' \
&& $mybb->input['fid'] != '' ) {
- $redir_url = seo_forum_url($mybb->input['fid'], 1, $original_url);
- } else if ( $scriptname == 'editpost.php' && $mybb->input['pid'] != '' ) {
- $fetch_data = seo_fetch_topic_title(0, $mybb->input['pid']);
- $redir_url = \
"{$fetch_data['subject']}-t-{$fetch_data['topic_id']}".(($fetch_data['page'] != "" && \
$fetch_data['page'] != 1) ? "-{$fetch_data['page']}" : "") . \
".html#pid{$mybb->input['pid']}";
- } else if ( $mybb->input['uid'] != '' && $scriptname == 'member.php' && \
$mybb->input['action'] == 'emailuser' ) {
- $redir_url = seo_profile_url($mybb->input['uid'], $original_url, '');
- } else if ( $mybb->input['uid'] != '' && $scriptname == 'private.php' && \
$mybb->input['action'] == 'send' ) {
- $redir_url = seo_profile_url($mybb->input['uid'], $original_url, '');
- } else if ( $mybb->input['fid'] != '' && ( $scriptname == 'usercp2.php' || \
$scriptname == 'newthread.php' ) ) {
- $redir_url = seo_forum_url($mybb->input['fid'], 1, $original_url);
- } else if ( $scriptname == 'misc.php' || $scriptname == 'usercp.php' || \
$scriptname == 'modcp.php' || $scriptname == 'private.php' || $scriptname == \
'ratethread.php' || $scriptname == 'sendthread.php' || $scriptname == \
'printthread.php' || $scriptname == 'usercp2.php' || $scriptname == \
'polls.php' ) {
- $redir_url = 'index.php';
- }
- }
-
- if( $redir_url != '' ) {
- $redir_url = "{$mybb->settings['bburl']}/{$redir_url}";
- header("HTTP/1.1 301 Moved Permanently");
- header("Location: {$redir_url}");
- }
+ return $redir_url;
}
/**
@@ -572,38 +587,10 @@
$scriptname = basename($_SERVER['SCRIPT_NAME']);
if( $scriptname == "showthread.php" || $scriptname == "forumdisplay.php" || \
$scriptname == "announcements.php" || $scriptname == "member.php" ) {
- $original_url = "{$scriptname}?{$_SERVER['QUERY_STRING']}";
- $seo_type = 2;
- if( $mybb->input['page'] == 1 OR $mybb->input['page'] == '' ) {
- $seo_type = 1;
- }
- switch( $scriptname )
- {
- case "showthread.php":
- if( $mybb->input['pid'] != '' ) {
- $fetch_data = seo_fetch_topic_title(0, $mybb->input['pid']);
- $canon_url = \
"{$fetch_data['subject']}-t-{$fetch_data['topic_id']}".(($fetch_data['page'] != "" && \
$fetch_data['page'] != 1) ? "-{$fetch_data['page']}" : "") . ".html";
- } else {
- $canon_url = seo_topic_url($mybb->input['tid'], $seo_type, $original_url, "" \
, $mybb->input['page']);
- }
- break;
- case "forumdisplay.php":
- $canon_url = seo_forum_url($mybb->input['fid'], $seo_type, $original_url);
- break;
- case "announcements.php":
- $queryannounce = $query = $db->query(" SELECT a.* FROM \
".TABLE_PREFIX."announcements a WHERE a.aid = \
{$mybb->input['aid']}");
- $announcement = $db->fetch_array($queryannounce);
- $canon_url = seo_clean_title($announcement['subject'], 'a') . \
"-a-{$mybb->input['aid']}.html";
- break;
- case "member.php":
- $canon_url = seo_profile_url($mybb->input['uid'], $original_url, '');
- break;
- default:
- break;
- }
+ $canon_url = seo_get_redirect_url();
$meta_tag_relcanon = "link rel=\"canonical\" \
href=\"{$mybb->settings['bburl']}/{$canon_url}\" /"; $page = \
preg_replace("</title>", "/title>\n<{$meta_tag_relcanon}", $page );
- }
+ }
// replace showthread links one last time
$page = preg_replace("#(\"|')showthread.php\?tid=([0-9]+)(\"|')#e", \
"seo_topic_url(\\2, 1, '\\0', '\\3')", $page);
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic