1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-01-18 06:38:43 +01:00

- magic urls should have class="postlink", added class="postlink-local" for relative magic urls [Bug #9867]

run develop/adjust_magic_urls.php to modify your post/sig/pm contents to use class="postlink"
- corrected a few bugs in fulltext_mysql stats [Bug #10165]


git-svn-id: file:///svn/phpbb/trunk@7424 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Nils Adermann 2007-04-28 21:16:32 +00:00
parent aaa93a8fc7
commit 87956e71a4
4 changed files with 140 additions and 15 deletions

View File

@ -0,0 +1,126 @@
<?php
/**
* Adds class="postlink" to magic urls
*
* You should make a backup from your users, posts and privmsgs table in case something goes wrong
* Forum descriptions and rules need to be re-submitted manually.
*/
die("Please read the first lines of this script for instructions on how to enable it");
set_time_limit(0);
define('IN_PHPBB', true);
$phpbb_root_path = './../';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.'.$phpEx);
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
$echos = 0;
$replace = array(
'<!-- l --><a href="',
'<!-- m --><a href="',
'<!-- w --><a href="',
);
$with = array(
'<!-- l --><a class="postlink-local" href="',
'<!-- m --><a class="postlink" href="',
'<!-- w --><a class="postlink" href="',
);
// Adjust user signatures
$sql = 'SELECT user_id, user_sig
FROM ' . USERS_TABLE;
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$new_content = str_replace($replace, $with, $row['user_sig']);
if ($new_content != $row['user_sig'])
{
$sql = 'UPDATE ' . USERS_TABLE . " SET user_sig = '" . $db->sql_escape($new_content) . "'
WHERE user_id = " . $row['user_id'];
$db->sql_query($sql);
if ($echos > 200)
{
echo '<br />' . "\n";
$echos = 0;
}
echo '.';
$echos++;
flush();
}
}
$db->sql_freeresult($result);
// Now adjust posts
$sql = 'SELECT post_id, post_text
FROM ' . POSTS_TABLE;
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$new_content = str_replace($replace, $with, $row['post_text']);
if ($row['post_text'] != $new_content)
{
$sql = 'UPDATE ' . POSTS_TABLE . " SET post_text = '" . $db->sql_escape($new_content) . "'
WHERE post_id = " . $row['post_id'];
$db->sql_query($sql);
if ($echos > 200)
{
echo '<br />' . "\n";
$echos = 0;
}
echo '.';
$echos++;
flush();
}
}
$db->sql_freeresult($result);
// Now to the private messages
$sql = 'SELECT msg_id, message_text
FROM ' . PRIVMSGS_TABLE;
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$new_content = str_replace($replace, $with, $row['message_text']);
if ($row['message_text'] != $new_content)
{
$sql = 'UPDATE ' . PRIVMSGS_TABLE . " SET bbcode_bitfield = '" . $db->sql_escape($new_content) . "'
WHERE msg_id = " . $row['msg_id'];
$db->sql_query($sql);
if ($echos > 200)
{
echo '<br />' . "\n";
$echos = 0;
}
echo '.';
$echos++;
flush();
}
}
$db->sql_freeresult($result);
// Done
$db->sql_close();
?>

View File

@ -2601,7 +2601,7 @@ function generate_text_for_edit($text, $uid, $flags)
* Cuts down displayed size of link if over 50 chars, turns absolute links
* into relative versions when the server/script path matches the link
*/
function make_clickable($text, $server_url = false)
function make_clickable($text, $server_url = false, $class = 'postlink')
{
if ($server_url === false)
{
@ -2610,23 +2610,28 @@ function make_clickable($text, $server_url = false)
static $magic_url_match;
static $magic_url_replace;
static $static_class;
if (!is_array($magic_url_match))
if (!is_array($magic_url_match) || $static_class != $class)
{
$static_class = $class;
$class = ($static_class) ? ' class="' . $static_class . '"' : '';
$local_class = ($static_class) ? ' class="' . $static_class . '-local"' : '';
$magic_url_match = $magic_url_replace = array();
// Be sure to not let the matches cross over. ;)
// relative urls for this board
$magic_url_match[] = '#(^|[\n\t (])(' . preg_quote($server_url, '#') . ')/(' . get_preg_expression('relative_url_inline') . ')#ie';
$magic_url_replace[] = "'\$1<!-- l --><a href=\"' . append_sid('\$2/' . preg_replace('/(&amp;|\?)sid=[0-9a-f]{32}$/', '', preg_replace('/(&amp;|\?)sid=[0-9a-f]{32}&amp;/', '\\\\1', '\$3'))) . '\">' . ((strlen('\$3')) ? preg_replace('/(&amp;|\?)sid=[0-9a-f]{32}$/', '', preg_replace('/(&amp;|\?)sid=[0-9a-f]{32}&amp;/', '\\\\1', '\$3')) : '\$2/') . '</a><!-- l -->'";
$magic_url_replace[] = "'\$1<!-- l --><a$local_class href=\"' . append_sid('\$2/' . preg_replace('/(&amp;|\?)sid=[0-9a-f]{32}$/', '', preg_replace('/(&amp;|\?)sid=[0-9a-f]{32}&amp;/', '\\\\1', '\$3'))) . '\">' . ((strlen('\$3')) ? preg_replace('/(&amp;|\?)sid=[0-9a-f]{32}$/', '', preg_replace('/(&amp;|\?)sid=[0-9a-f]{32}&amp;/', '\\\\1', '\$3')) : '\$2/') . '</a><!-- l -->'";
// matches a xxxx://aaaaa.bbb.cccc. ...
$magic_url_match[] = '#(^|[\n\t (])(' . get_preg_expression('url_inline') . ')#ie';
$magic_url_replace[] = "'\$1<!-- m --><a href=\"\$2\">' . ((strlen('\$2') > 55) ? str_replace('&', '&amp;', substr(str_replace('&amp;', '&', '\$2'), 0, 39)) . ' ... ' . str_replace('&', '&amp;', substr(str_replace('&amp;', '&', '\$2'), -10)) : '\$2') . '</a><!-- m -->'";
$magic_url_replace[] = "'\$1<!-- m --><a$class href=\"\$2\">' . ((strlen('\$2') > 55) ? str_replace('&', '&amp;', substr(str_replace('&amp;', '&', '\$2'), 0, 39)) . ' ... ' . str_replace('&', '&amp;', substr(str_replace('&amp;', '&', '\$2'), -10)) : '\$2') . '</a><!-- m -->'";
// matches a "www.xxxx.yyyy[/zzzz]" kinda lazy URL thing
$magic_url_match[] = '#(^|[\n\t (])(' . get_preg_expression('www_url_inline') . ')#ie';
$magic_url_replace[] = "'\$1<!-- w --><a href=\"http://\$2\">' . ((strlen('\$2') > 55) ? str_replace('&', '&amp;', substr(str_replace('&amp;', '&', '\$2'), 0, 39)) . ' ... ' . str_replace('&', '&amp;', substr(str_replace('&amp;', '&', '\$2'), -10)) : '\$2') . '</a><!-- w -->'";
$magic_url_replace[] = "'\$1<!-- w --><a$class href=\"http://\$2\">' . ((strlen('\$2') > 55) ? str_replace('&', '&amp;', substr(str_replace('&amp;', '&', '\$2'), 0, 39)) . ' ... ' . str_replace('&', '&amp;', substr(str_replace('&amp;', '&', '\$2'), -10)) : '\$2') . '</a><!-- w -->'";
// matches an email@domain type address at the start of a line, or after a space or after what might be a BBCode.
$magic_url_match[] = '/(^|[\n\t )])(' . get_preg_expression('email') . ')/ie';
@ -3260,7 +3265,7 @@ function get_preg_expression($mode)
case 'bbcode_htm':
return array(
'#<!\-\- e \-\-><a href="mailto:(.*?)">.*?</a><!\-\- e \-\->#',
'#<!\-\- l \-\-><a href="(.*?)(?:(&amp;|\?)sid=[0-9a-f]{32})?">.*?</a><!\-\- l \-\->#',
'#<!\-\- l \-\-><a (?:class="[\w-]+" )?href="(.*?)(?:(&amp;|\?)sid=[0-9a-f]{32})?">.*?</a><!\-\- l \-\->#',
'#<!\-\- ([mw]) \-\-><a href="(.*?)">.*?</a><!\-\- \1 \-\->#',
'#<!\-\- s(.*?) \-\-><img src="\{SMILIES_PATH\}\/.*? \/><!\-\- s\1 \-\->#',
'#<!\-\- .*? \-\->#s',

View File

@ -807,9 +807,6 @@ class fulltext_mysql extends search_backend
return array(
$user->lang['FULLTEXT_MYSQL_TOTAL_POSTS'] => ($this->index_created()) ? $this->stats['total_posts'] : 0,
$user->lang['FULLTEXT_MYSQL_TEXT_CARDINALITY'] => isset($this->stats['post_text']['Cardinality']) ? $this->stats['post_text']['Cardinality'] : 0,
$user->lang['FULLTEXT_MYSQL_SUBJECT_CARDINALITY'] => isset($this->stats['post_subject']['Cardinality']) ? $this->stats['post_subject']['Cardinality'] : 0,
$user->lang['FULLTEXT_MYSQL_COMBINED_CARDINALITY'] => isset($this->stats['post_content']['Cardinality']) ? $this->stats['post_content']['Cardinality'] : 0,
);
}
@ -834,15 +831,15 @@ class fulltext_mysql extends search_backend
if ($index_type == 'FULLTEXT')
{
if ($row['Column_name'] == 'post_text')
if ($row['Key_name'] == 'post_text')
{
$this->stats['post_text'] = $row;
}
else if ($row['Column_name'] == 'post_subject')
else if ($row['Key_name'] == 'post_subject')
{
$this->stats['post_subject'] = $row;
}
else if ($row['Column_name'] == 'post_content')
else if ($row['Key_name'] == 'post_content')
{
$this->stats['post_content'] = $row;
}

View File

@ -49,9 +49,6 @@ $lang = array_merge($lang, array(
'FULLTEXT_MYSQL_INCOMPATIBLE_VERSION' => 'The MySQL fulltext backend can only be used with MySQL4 and above.',
'FULLTEXT_MYSQL_NOT_MYISAM' => 'MySQL fulltext indexes can only be used with MyISAM tables.',
'FULLTEXT_MYSQL_SUBJECT_CARDINALITY' => 'Cardinality of the post_subject fulltext index (estimate of unique values)',
'FULLTEXT_MYSQL_TEXT_CARDINALITY' => 'Cardinality of the post_text fulltext index (estimate of unique values)',
'FULLTEXT_MYSQL_COMBINED_CARDINALITY' => 'Cardinality of the post_content fulltext index (estimate of unique values)',
'FULLTEXT_MYSQL_TOTAL_POSTS' => 'Total number of indexed posts',
'FULLTEXT_MYSQL_MBSTRING' => 'Support for non-latin UTF-8 characters using mbstring:',
'FULLTEXT_MYSQL_PCRE' => 'Support for non-latin UTF-8 characters using PCRE:',