mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-30 21:40:43 +02:00
Move trunk/phpBB to old_trunk/phpBB
git-svn-id: file:///svn/phpbb/trunk@10210 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
DIR=$(dirname "$0")/../cache;
|
||||
cat "$DIR/sql_*.php" | grep '/* SELECT' | sed 's,/\* ,,;s, \*/,,' | sort
|
@@ -1,33 +0,0 @@
|
||||
File structure grouped by filesystem:
|
||||
|
||||
/includes/core/ Core
|
||||
/includes/api/ API
|
||||
/includes/acm/ Cache
|
||||
/includes/auth/ Authentication
|
||||
/includes/bbcode/ BBCode
|
||||
/includes/captcha/ Captcha
|
||||
/includes/db/ DBAL
|
||||
/includes/search/ Search
|
||||
/includes/utf/ UTF8-specific files/classes
|
||||
|
||||
/includes/classes/ Collection of single classes which we do not want to put into a separate directory. Although later it would be nice to have all of them in one "location".
|
||||
acl.php: ACL/permission class.
|
||||
cache.php: Static class for obtaining cached items/arrays
|
||||
session.php: The session class used for managing sessions.
|
||||
template.php, template_compile.php: The template engine
|
||||
user.php: The user object, handling user-based session and user-specific setups. It defines the users workspace.
|
||||
|
||||
/includes/libraries/ Collection of external and "adjusted" libraries we use and do not constitute one "system" in phpBB.
|
||||
/includes/libraries/diff/ Diff System (Text_Diff-1.1.0 - http://pear.php.net/package/Text_Diff/) - Used By: Updater,
|
||||
/includes/libraries/sftp/ SFTP (http://phpseclib.sourceforge.net/) - Used By: Transfer Class,
|
||||
|
||||
|
||||
/modules/ Directory holding directories/files for the defined module sections (ucp, mcp, acp, etc.)
|
||||
/plugins/ Plugins for phpBB (Hooks are now plugins btw... includes/hooks no longer exists)
|
||||
|
||||
/develop/ Internal helper files for development. Only present in SVN
|
||||
/docs/ Documentation, Documents, License file, Coding Guidelines
|
||||
|
||||
/cache/ Cache directory for storing files. Needs to be writeable
|
||||
/store/ Store directory for storing backup files and temporary files. Needs to be writeable
|
||||
/files/ Files directory for storing attachments and uploaded files. Needs to be writeable
|
@@ -1,29 +0,0 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Remove all those annoying ^M characters that Winblows editor's like to add
|
||||
# from all files in the current directory and all subdirectories.
|
||||
#
|
||||
# Written by: Jonathan Haase.
|
||||
#
|
||||
# UPDATE: 7/31/2001: fix so that it doesn't touch things in the images directory
|
||||
#
|
||||
# UPDATE: 12/15/2003: Fix so that it doesn't touch any "non-text" files
|
||||
#
|
||||
|
||||
find . > FILELIST.$$
|
||||
grep -sv FILELIST FILELIST.$$ > FILELIST2.$$
|
||||
grep -sv $(basename $0) FILELIST2.$$ > FILELIST.$$
|
||||
grep -sv "^\.$" FILELIST.$$ > FILELIST2.$$
|
||||
file -f FILELIST2.$$ |grep text | sed -e 's/^\([^\:]*\)\:.*$/\1/' > FILELIST
|
||||
file -f FILELIST2.$$ |grep -sv text | sed -e 's/^\([^\:]*\)\:.*$/Not Modifying file: \1/'
|
||||
rm FILELIST2.$$
|
||||
rm FILELIST.$$
|
||||
|
||||
for i in $(cat FILELIST); do
|
||||
if [ -f $i ]; then
|
||||
sed -e s/
|
||||
//g $i > $i.tmp
|
||||
mv $i.tmp $i
|
||||
fi
|
||||
done
|
||||
rm FILELIST
|
@@ -1,154 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package phpBB3
|
||||
* @version $Id$
|
||||
* @copyright (c) 2005 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||
*
|
||||
*/
|
||||
|
||||
if (php_sapi_name() != 'cli')
|
||||
{
|
||||
die("This program must be run from the command line.\n");
|
||||
}
|
||||
|
||||
//
|
||||
// Security message:
|
||||
//
|
||||
// This script is potentially dangerous.
|
||||
// Remove or comment the next line (die(".... ) to enable this script.
|
||||
// Do NOT FORGET to either remove this script or disable it after you have used it.
|
||||
//
|
||||
die("Please read the first lines of this script for instructions on how to enable it");
|
||||
|
||||
set_time_limit(0);
|
||||
|
||||
define('IN_PHPBB', true);
|
||||
define('PHPBB_ROOT_PATH', './../');
|
||||
define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
|
||||
|
||||
echo "Checking for required files\n";
|
||||
download('http://unicode.org/Public/UNIDATA/CaseFolding.txt');
|
||||
echo "\n";
|
||||
|
||||
|
||||
/**
|
||||
* Load the CaseFolding table
|
||||
*/
|
||||
echo "Loading CaseFolding\n";
|
||||
$unidata = file_get_contents('CaseFolding.txt');
|
||||
|
||||
|
||||
function utf8_chr($cp)
|
||||
{
|
||||
if ($cp > 0xFFFF)
|
||||
{
|
||||
return chr(0xF0 | ($cp >> 18)) . chr(0x80 | (($cp >> 12) & 0x3F)) . chr(0x80 | (($cp >> 6) & 0x3F)) . chr(0x80 | ($cp & 0x3F));
|
||||
}
|
||||
else if ($cp > 0x7FF)
|
||||
{
|
||||
return chr(0xE0 | ($cp >> 12)) . chr(0x80 | (($cp >> 6) & 0x3F)) . chr(0x80 | ($cp & 0x3F));
|
||||
}
|
||||
else if ($cp > 0x7F)
|
||||
{
|
||||
return chr(0xC0 | ($cp >> 6)) . chr(0x80 | ($cp & 0x3F));
|
||||
}
|
||||
else
|
||||
{
|
||||
return chr($cp);
|
||||
}
|
||||
}
|
||||
|
||||
preg_match_all('/^([0-9A-F]+); ([CFS]); ([0-9A-F]+(?: [0-9A-F]+)*);/im', $unidata, $array, PREG_SET_ORDER);
|
||||
|
||||
$uniarray = array();
|
||||
|
||||
foreach ($array as $value)
|
||||
{
|
||||
$uniarray[$value[2]][utf8_chr(hexdec((string)$value[1]))] = implode(array_map('utf8_chr', array_map('hexdec', explode(' ', $value[3]))));
|
||||
}
|
||||
|
||||
foreach ($uniarray as $idx => $contents)
|
||||
{
|
||||
echo "Writing to case_fold_$idx." . PHP_EXT . "\n";
|
||||
$fp = fopen(PHPBB_ROOT_PATH . 'includes/utf/data/case_fold_' . strtolower($idx) . '.' . PHP_EXT, 'wb');
|
||||
fwrite($fp, '<?php return ' . my_var_export($contents) . ';');
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a parsable string representation of a variable
|
||||
*
|
||||
* This is function is limited to array/strings/integers
|
||||
*
|
||||
* @param mixed $var Variable
|
||||
* @return string PHP code representing the variable
|
||||
*/
|
||||
function my_var_export($var)
|
||||
{
|
||||
if (is_array($var))
|
||||
{
|
||||
$lines = array();
|
||||
|
||||
foreach ($var as $k => $v)
|
||||
{
|
||||
$lines[] = my_var_export($k) . '=>' . my_var_export($v);
|
||||
}
|
||||
|
||||
return 'array(' . implode(',', $lines) . ')';
|
||||
}
|
||||
else if (is_string($var))
|
||||
{
|
||||
return "'" . str_replace(array('\\', "'"), array('\\\\', "\\'"), $var) . "'";
|
||||
}
|
||||
else
|
||||
{
|
||||
return $var;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Download a file to the develop/ dir
|
||||
*
|
||||
* @param string $url URL of the file to download
|
||||
* @return void
|
||||
*/
|
||||
function download($url)
|
||||
{
|
||||
if (file_exists(PHPBB_ROOT_PATH . 'develop/' . basename($url)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
echo 'Downloading from ', $url, ' ';
|
||||
|
||||
if (!$fpr = fopen($url, 'rb'))
|
||||
{
|
||||
die("Can't download from $url\nPlease download it yourself and put it in the develop/ dir, kthxbai");
|
||||
}
|
||||
|
||||
if (!$fpw = fopen(PHPBB_ROOT_PATH . 'develop/' . basename($url), 'wb'))
|
||||
{
|
||||
die("Can't open develop/" . basename($url) . " for output... please check your permissions or something");
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
$chunk = 32768;
|
||||
$done = '';
|
||||
|
||||
while (!feof($fpr))
|
||||
{
|
||||
$i += fwrite($fpw, fread($fpr, $chunk));
|
||||
echo str_repeat("\x08", strlen($done));
|
||||
|
||||
$done = ($i >> 10) . ' KiB';
|
||||
echo $done;
|
||||
}
|
||||
fclose($fpr);
|
||||
fclose($fpw);
|
||||
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
?>
|
@@ -1,238 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package phpBB3
|
||||
* @version $Id$
|
||||
* @copyright (c) 2005 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||
*
|
||||
*/
|
||||
|
||||
if (php_sapi_name() != 'cli')
|
||||
{
|
||||
die("This program must be run from the command line.\n");
|
||||
}
|
||||
|
||||
//
|
||||
// Security message:
|
||||
//
|
||||
// This script is potentially dangerous.
|
||||
// Remove or comment the next line (die(".... ) to enable this script.
|
||||
// Do NOT FORGET to either remove this script or disable it after you have used it.
|
||||
//
|
||||
die("Please read the first lines of this script for instructions on how to enable it");
|
||||
|
||||
set_time_limit(0);
|
||||
|
||||
define('IN_PHPBB', true);
|
||||
define('PHPBB_ROOT_PATH', './../');
|
||||
define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
|
||||
|
||||
echo "Checking for required files\n";
|
||||
download('http://unicode.org/reports/tr39/data/confusables.txt');
|
||||
download('http://unicode.org/Public/UNIDATA/CaseFolding.txt');
|
||||
echo "\n";
|
||||
|
||||
|
||||
/**
|
||||
* Load the confusables table
|
||||
*/
|
||||
echo "Loading confusables\n";
|
||||
$unidata = file_get_contents('confusables.txt');
|
||||
|
||||
/**
|
||||
* Load the CaseFolding table
|
||||
*/
|
||||
echo "Loading CaseFolding\n";
|
||||
$casefolds = file_get_contents('CaseFolding.txt');
|
||||
|
||||
|
||||
function utf8_chr($cp)
|
||||
{
|
||||
if ($cp > 0xFFFF)
|
||||
{
|
||||
return chr(0xF0 | ($cp >> 18)) . chr(0x80 | (($cp >> 12) & 0x3F)) . chr(0x80 | (($cp >> 6) & 0x3F)) . chr(0x80 | ($cp & 0x3F));
|
||||
}
|
||||
else if ($cp > 0x7FF)
|
||||
{
|
||||
return chr(0xE0 | ($cp >> 12)) . chr(0x80 | (($cp >> 6) & 0x3F)) . chr(0x80 | ($cp & 0x3F));
|
||||
}
|
||||
else if ($cp > 0x7F)
|
||||
{
|
||||
return chr(0xC0 | ($cp >> 6)) . chr(0x80 | ($cp & 0x3F));
|
||||
}
|
||||
else
|
||||
{
|
||||
return chr($cp);
|
||||
}
|
||||
}
|
||||
|
||||
preg_match_all('/^([0-9A-F]+) ;\s((?:[0-9A-F]+ )*);.*?$/im', $unidata, $array, PREG_SET_ORDER);
|
||||
preg_match_all('/^([0-9A-F]+); ([CFS]); ([0-9A-F]+(?: [0-9A-F]+)*);/im', $casefolds, $casefold_array);
|
||||
|
||||
// some that we defined ourselves
|
||||
$uniarray = array(
|
||||
"\xC2\xA1" => "\x69", // EXCLAMATION MARK, INVERTED => LATIN SMALL LETTER I
|
||||
"\xC7\x83" => "\x21", // LATIN LETTER RETROFLEX CLICK => EXCLAMATION MARK
|
||||
"\xCE\xB1" => "\x61", // GREEK SMALL LETTER ALPHA => LATIN SMALL LETTER A
|
||||
"\xE1\x9A\x80" => "\x20", // OGHAM SPACE MARK
|
||||
|
||||
"\xC2\xAD" => '', // HYPHEN, SOFT => empty string
|
||||
"\xDB\x9D" => '', // ARABIC END OF AYAH
|
||||
"\xDC\x8F" => '', // SYRIAC ABBREVIATION MARK
|
||||
"\xE1\xA0\x86" => '', // MONGOLIAN TODO SOFT HYPHEN
|
||||
"\xE1\xA0\x8E" => '', // MONGOLIAN VOWEL SEPARATOR
|
||||
"\xE2\x80\x8B" => '', // ZERO WIDTH SPACE
|
||||
"\xE2\x80\x8C" => '', // ZERO WIDTH NON-JOINER
|
||||
"\xE2\x80\x8D" => '', // ZERO WIDTH JOINER
|
||||
"\xE2\x80\xA8" => '', // LINE SEPARATOR
|
||||
"\xE2\x80\xA9" => '', // PARAGRAPH SEPARATOR
|
||||
"\xE2\x81\xA0" => '', // WORD JOINER
|
||||
"\xE2\x81\xA1" => '', // FUNCTION APPLICATION
|
||||
"\xE2\x81\xA2" => '', // INVISIBLE TIMES
|
||||
"\xE2\x81\xA3" => '', // INVISIBLE SEPARATOR
|
||||
"\xE2\x81\xAA" => '', // [CONTROL CHARACTERS]
|
||||
"\xE2\x81\xAB" => '', // [CONTROL CHARACTERS]
|
||||
"\xE2\x81\xAC" => '', // [CONTROL CHARACTERS]
|
||||
"\xE2\x81\xAD" => '', // [CONTROL CHARACTERS]
|
||||
"\xE2\x81\xAE" => '', // [CONTROL CHARACTERS]
|
||||
"\xE2\x81\xAF" => '', // [CONTROL CHARACTERS]
|
||||
"\xEF\xBB\xBF" => '', // ZERO WIDTH NO-BREAK SPACE
|
||||
"\xEF\xBF\xB9" => '', // [CONTROL CHARACTERS]
|
||||
"\xEF\xBF\xBA" => '', // [CONTROL CHARACTERS]
|
||||
"\xEF\xBF\xBB" => '', // [CONTROL CHARACTERS]
|
||||
"\xEF\xBF\xBC" => '', // [CONTROL CHARACTERS]
|
||||
"\xF0\x9D\x85\xB3" => '', // [MUSICAL CONTROL CHARACTERS]
|
||||
"\xF0\x9D\x85\xB4" => '', // [MUSICAL CONTROL CHARACTERS]
|
||||
"\xF0\x9D\x85\xB5" => '', // [MUSICAL CONTROL CHARACTERS]
|
||||
"\xF0\x9D\x85\xB6" => '', // [MUSICAL CONTROL CHARACTERS]
|
||||
"\xF0\x9D\x85\xB7" => '', // [MUSICAL CONTROL CHARACTERS]
|
||||
"\xF0\x9D\x85\xB8" => '', // [MUSICAL CONTROL CHARACTERS]
|
||||
"\xF0\x9D\x85\xB9" => '', // [MUSICAL CONTROL CHARACTERS]
|
||||
"\xF0\x9D\x85\xBA" => '', // [MUSICAL CONTROL CHARACTERS]
|
||||
);
|
||||
|
||||
$copy = $uniarray;
|
||||
|
||||
foreach ($array as $value)
|
||||
{
|
||||
$temp_hold = implode(array_map('utf8_chr', array_map('hexdec', explode(' ', trim($value[2])))));
|
||||
|
||||
if (isset($copy[utf8_chr(hexdec((string)$value[1]))]))
|
||||
{
|
||||
$num = '';
|
||||
$string = utf8_chr(hexdec((string)$value[1]));
|
||||
for ($i = 0; $i < strlen($string); $i++)
|
||||
{
|
||||
$num .= '\x' . str_pad(base_convert(ord($string[$i]), 10, 16), 2, '0', STR_PAD_LEFT);
|
||||
}
|
||||
echo $num . "\n";
|
||||
if ($uniarray[$string] != $temp_hold)
|
||||
{
|
||||
echo " --> $string\n";
|
||||
echo " --> " . $temp_hold . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
// do some tests for things that transform into something with the number one
|
||||
if (strpos($temp_hold, utf8_chr(0x0031)) !== false)
|
||||
{
|
||||
// any kind of letter L?
|
||||
if (strpos($value[0], 'LETTER L') !== false || strpos($value[0], 'IOTA') !== false || strpos($value[0], 'SMALL L ') !== false || preg_match('/SMALL LIGATURE [^L]*L /', $value[0]))
|
||||
{
|
||||
// replace all of the mappings that transform some sort of letter l to number one instead to some sort of letter l to latin small letter l
|
||||
$temp_hold = str_replace(utf8_chr(0x0031), utf8_chr(0x006C), $temp_hold);
|
||||
}
|
||||
}
|
||||
|
||||
// uppercased chars that were folded do not exist in this universe,
|
||||
// no amount of normalization could ever "trick" this into not working
|
||||
if (in_array($value[1], $casefold_array[1]))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$uniarray[utf8_chr(hexdec((string)$value[1]))] = $temp_hold;
|
||||
}
|
||||
|
||||
echo "Writing to confusables." . PHP_EXT . "\n";
|
||||
|
||||
$fp = fopen(PHPBB_ROOT_PATH . 'includes/utf/data/confusables.' . PHP_EXT, 'wb');
|
||||
fwrite($fp, '<?php return ' . my_var_export($uniarray) . ';');
|
||||
fclose($fp);
|
||||
|
||||
/**
|
||||
* Return a parsable string representation of a variable
|
||||
*
|
||||
* This is function is limited to array/strings/integers
|
||||
*
|
||||
* @param mixed $var Variable
|
||||
* @return string PHP code representing the variable
|
||||
*/
|
||||
function my_var_export($var)
|
||||
{
|
||||
if (is_array($var))
|
||||
{
|
||||
$lines = array();
|
||||
|
||||
foreach ($var as $k => $v)
|
||||
{
|
||||
$lines[] = my_var_export($k) . '=>' . my_var_export($v);
|
||||
}
|
||||
|
||||
return 'array(' . implode(',', $lines) . ')';
|
||||
}
|
||||
else if (is_string($var))
|
||||
{
|
||||
return "'" . str_replace(array('\\', "'"), array('\\\\', "\\'"), $var) . "'";
|
||||
}
|
||||
else
|
||||
{
|
||||
return $var;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Download a file to the develop/ dir
|
||||
*
|
||||
* @param string $url URL of the file to download
|
||||
* @return void
|
||||
*/
|
||||
function download($url)
|
||||
{
|
||||
if (file_exists(PHPBB_ROOT_PATH . 'develop/' . basename($url)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
echo 'Downloading from ', $url, ' ';
|
||||
|
||||
if (!$fpr = fopen($url, 'rb'))
|
||||
{
|
||||
die("Can't download from $url\nPlease download it yourself and put it in the develop/ dir, kthxbai");
|
||||
}
|
||||
|
||||
if (!$fpw = fopen(PHPBB_ROOT_PATH . 'develop/' . basename($url), 'wb'))
|
||||
{
|
||||
die("Can't open develop/" . basename($url) . " for output... please check your permissions or something");
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
$chunk = 32768;
|
||||
$done = '';
|
||||
|
||||
while (!feof($fpr))
|
||||
{
|
||||
$i += fwrite($fpw, fread($fpr, $chunk));
|
||||
echo str_repeat("\x08", strlen($done));
|
||||
|
||||
$done = ($i >> 10) . ' KiB';
|
||||
echo $done;
|
||||
}
|
||||
fclose($fpr);
|
||||
fclose($fpw);
|
||||
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
?>
|
@@ -1,570 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package phpBB3
|
||||
* @version $Id$
|
||||
* @copyright (c) 2005 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||
*
|
||||
*/
|
||||
|
||||
if (php_sapi_name() != 'cli')
|
||||
{
|
||||
die("This program must be run from the command line.\n");
|
||||
}
|
||||
|
||||
//
|
||||
// Security message:
|
||||
//
|
||||
// This script is potentially dangerous.
|
||||
// Remove or comment the next line (die(".... ) to enable this script.
|
||||
// Do NOT FORGET to either remove this script or disable it after you have used it.
|
||||
//
|
||||
die("Please read the first lines of this script for instructions on how to enable it");
|
||||
|
||||
set_time_limit(0);
|
||||
|
||||
define('IN_PHPBB', true);
|
||||
define('PHPBB_ROOT_PATH', './../');
|
||||
define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
|
||||
|
||||
echo "Checking for required files\n";
|
||||
download('http://www.unicode.org/Public/UNIDATA/CompositionExclusions.txt');
|
||||
download('http://www.unicode.org/Public/UNIDATA/DerivedNormalizationProps.txt');
|
||||
download('http://www.unicode.org/Public/UNIDATA/UnicodeData.txt');
|
||||
echo "\n";
|
||||
|
||||
require_once(PHPBB_ROOT_PATH . 'includes/utf/utf_normalizer.' . PHP_EXT);
|
||||
$file_contents = array();
|
||||
|
||||
/**
|
||||
* Generate some Hangul/Jamo stuff
|
||||
*/
|
||||
echo "\nGenerating Hangul and Jamo tables\n";
|
||||
for ($i = 0; $i < UNICODE_HANGUL_LCOUNT; ++$i)
|
||||
{
|
||||
$utf_char = cp_to_utf(UNICODE_HANGUL_LBASE + $i);
|
||||
$file_contents['utf_normalizer_common']['utf_jamo_index'][$utf_char] = $i * UNICODE_HANGUL_VCOUNT * UNICODE_HANGUL_TCOUNT + UNICODE_HANGUL_SBASE;
|
||||
$file_contents['utf_normalizer_common']['utf_jamo_type'][$utf_char] = UNICODE_JAMO_L;
|
||||
}
|
||||
|
||||
for ($i = 0; $i < UNICODE_HANGUL_VCOUNT; ++$i)
|
||||
{
|
||||
$utf_char = cp_to_utf(UNICODE_HANGUL_VBASE + $i);
|
||||
$file_contents['utf_normalizer_common']['utf_jamo_index'][$utf_char] = $i * UNICODE_HANGUL_TCOUNT;
|
||||
$file_contents['utf_normalizer_common']['utf_jamo_type'][$utf_char] = UNICODE_JAMO_V;
|
||||
}
|
||||
|
||||
for ($i = 0; $i < UNICODE_HANGUL_TCOUNT; ++$i)
|
||||
{
|
||||
$utf_char = cp_to_utf(UNICODE_HANGUL_TBASE + $i);
|
||||
$file_contents['utf_normalizer_common']['utf_jamo_index'][$utf_char] = $i;
|
||||
$file_contents['utf_normalizer_common']['utf_jamo_type'][$utf_char] = UNICODE_JAMO_T;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the CompositionExclusions table
|
||||
*/
|
||||
echo "Loading CompositionExclusion\n";
|
||||
$fp = fopen('CompositionExclusions.txt', 'rt');
|
||||
|
||||
$exclude = array();
|
||||
while (!feof($fp))
|
||||
{
|
||||
$line = fgets($fp, 1024);
|
||||
|
||||
if (!strpos(' 0123456789ABCDEFabcdef', $line[0]))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$cp = strtok($line, ' ');
|
||||
|
||||
if ($pos = strpos($cp, '..'))
|
||||
{
|
||||
$start = hexdec(substr($cp, 0, $pos));
|
||||
$end = hexdec(substr($cp, $pos + 2));
|
||||
|
||||
for ($i = $start; $i < $end; ++$i)
|
||||
{
|
||||
$exclude[$i] = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$exclude[hexdec($cp)] = 1;
|
||||
}
|
||||
}
|
||||
fclose($fp);
|
||||
|
||||
/**
|
||||
* Load QuickCheck tables
|
||||
*/
|
||||
echo "Generating QuickCheck tables\n";
|
||||
$fp = fopen('DerivedNormalizationProps.txt', 'rt');
|
||||
|
||||
while (!feof($fp))
|
||||
{
|
||||
$line = fgets($fp, 1024);
|
||||
|
||||
if (!strpos(' 0123456789ABCDEFabcdef', $line[0]))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$p = array_map('trim', explode(';', strtok($line, '#')));
|
||||
|
||||
/**
|
||||
* Capture only NFC_QC, NFKC_QC
|
||||
*/
|
||||
if (!preg_match('#^NFK?C_QC$#', $p[1]))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($pos = strpos($p[0], '..'))
|
||||
{
|
||||
$start = hexdec(substr($p[0], 0, $pos));
|
||||
$end = hexdec(substr($p[0], $pos + 2));
|
||||
}
|
||||
else
|
||||
{
|
||||
$start = $end = hexdec($p[0]);
|
||||
}
|
||||
|
||||
if ($start >= UTF8_HANGUL_FIRST && $end <= UTF8_HANGUL_LAST)
|
||||
{
|
||||
/**
|
||||
* We do not store Hangul syllables in the array
|
||||
*/
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($p[2] == 'M')
|
||||
{
|
||||
$val = UNICODE_QC_MAYBE;
|
||||
}
|
||||
else
|
||||
{
|
||||
$val = UNICODE_QC_NO;
|
||||
}
|
||||
|
||||
if ($p[1] == 'NFKC_QC')
|
||||
{
|
||||
$file = 'utf_nfkc_qc';
|
||||
}
|
||||
else
|
||||
{
|
||||
$file = 'utf_nfc_qc';
|
||||
}
|
||||
|
||||
for ($i = $start; $i <= $end; ++$i)
|
||||
{
|
||||
/**
|
||||
* The vars have the same name as the file: $utf_nfc_qc is in utf_nfc_qc.php
|
||||
*/
|
||||
$file_contents[$file][$file][cp_to_utf($i)] = $val;
|
||||
}
|
||||
}
|
||||
fclose($fp);
|
||||
|
||||
/**
|
||||
* Do mappings
|
||||
*/
|
||||
echo "Loading Unicode decomposition mappings\n";
|
||||
$fp = fopen(PHPBB_ROOT_PATH . 'develop/UnicodeData.txt', 'rt');
|
||||
|
||||
$map = array();
|
||||
while (!feof($fp))
|
||||
{
|
||||
$p = explode(';', fgets($fp, 1024));
|
||||
$cp = hexdec($p[0]);
|
||||
|
||||
if (!empty($p[3]))
|
||||
{
|
||||
/**
|
||||
* Store combining class > 0
|
||||
*/
|
||||
$file_contents['utf_normalizer_common']['utf_combining_class'][cp_to_utf($cp)] = (int) $p[3];
|
||||
}
|
||||
|
||||
if (!isset($p[5]) || !preg_match_all('#[0-9A-F]+#', strip_tags($p[5]), $m))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strpos($p[5], '>'))
|
||||
{
|
||||
$map['NFKD'][$cp] = implode(' ', array_map('hexdec', $m[0]));
|
||||
}
|
||||
else
|
||||
{
|
||||
$map['NFD'][$cp] = $map['NFKD'][$cp] = implode(' ', array_map('hexdec', $m[0]));
|
||||
}
|
||||
}
|
||||
fclose($fp);
|
||||
|
||||
/**
|
||||
* Build the canonical composition table
|
||||
*/
|
||||
echo "Generating the Canonical Composition table\n";
|
||||
foreach ($map['NFD'] as $cp => $decomp_seq)
|
||||
{
|
||||
if (!strpos($decomp_seq, ' ') || isset($exclude[$cp]))
|
||||
{
|
||||
/**
|
||||
* Singletons are excluded from canonical composition
|
||||
*/
|
||||
continue;
|
||||
}
|
||||
|
||||
$utf_seq = implode('', array_map('cp_to_utf', explode(' ', $decomp_seq)));
|
||||
|
||||
if (!isset($file_contents['utf_canonical_comp']['utf_canonical_comp'][$utf_seq]))
|
||||
{
|
||||
$file_contents['utf_canonical_comp']['utf_canonical_comp'][$utf_seq] = cp_to_utf($cp);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decompose the NF[K]D mappings recursively and prepare the file contents
|
||||
*/
|
||||
echo "Generating the Canonical and Compatibility Decomposition tables\n\n";
|
||||
foreach ($map as $type => $decomp_map)
|
||||
{
|
||||
foreach ($decomp_map as $cp => $decomp_seq)
|
||||
{
|
||||
$decomp_map[$cp] = decompose($decomp_map, $decomp_seq);
|
||||
}
|
||||
unset($decomp_seq);
|
||||
|
||||
if ($type == 'NFKD')
|
||||
{
|
||||
$file = 'utf_compatibility_decomp';
|
||||
$var = 'utf_compatibility_decomp';
|
||||
}
|
||||
else
|
||||
{
|
||||
$file = 'utf_canonical_decomp';
|
||||
$var = 'utf_canonical_decomp';
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the corresponding file
|
||||
*/
|
||||
foreach ($decomp_map as $cp => $decomp_seq)
|
||||
{
|
||||
$file_contents[$file][$var][cp_to_utf($cp)] = implode('', array_map('cp_to_utf', explode(' ', $decomp_seq)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate and/or alter the files
|
||||
*/
|
||||
foreach ($file_contents as $file => $contents)
|
||||
{
|
||||
/**
|
||||
* Generate a new file
|
||||
*/
|
||||
echo "Writing to $file." . PHP_EXT . "\n";
|
||||
|
||||
if (!$fp = fopen(PHPBB_ROOT_PATH . 'includes/utf/data/' . $file . '.' . PHP_EXT, 'wb'))
|
||||
{
|
||||
trigger_error('Cannot open ' . $file . ' for write');
|
||||
}
|
||||
|
||||
fwrite($fp, '<?php');
|
||||
foreach ($contents as $var => $val)
|
||||
{
|
||||
fwrite($fp, "\n\$GLOBALS[" . my_var_export($var) . ']=' . my_var_export($val) . ";");
|
||||
}
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
echo "\n*** UTF-8 normalization tables done\n\n";
|
||||
|
||||
/**
|
||||
* Now we'll generate the files needed by the search indexer
|
||||
*/
|
||||
echo "Generating search indexer tables\n";
|
||||
|
||||
$fp = fopen(PHPBB_ROOT_PATH . 'develop/UnicodeData.txt', 'rt');
|
||||
|
||||
$map = array();
|
||||
while ($line = fgets($fp, 1024))
|
||||
{
|
||||
/**
|
||||
* The current line is split, $m[0] hold the codepoint in hexadecimal and
|
||||
* all other fields numbered as in http://www.unicode.org/Public/UNIDATA/UCD.html#UnicodeData.txt
|
||||
*/
|
||||
$m = explode(';', $line);
|
||||
|
||||
/**
|
||||
* @var integer $cp Current char codepoint
|
||||
* @var string $utf_char UTF-8 representation of current char
|
||||
*/
|
||||
$cp = hexdec($m[0]);
|
||||
$utf_char = cp_to_utf($cp);
|
||||
|
||||
/**
|
||||
* $m[2] holds the "General Category" of the character
|
||||
* @link http://www.unicode.org/Public/UNIDATA/UCD.html#General_Category_Values
|
||||
*/
|
||||
switch ($m[2][0])
|
||||
{
|
||||
case 'L':
|
||||
/**
|
||||
* We allow all letters and map them to their lowercased counterpart on the fly
|
||||
*/
|
||||
$map_to_hex = (isset($m[13][0])) ? $m[13] : $m[0];
|
||||
|
||||
if (preg_match('#^LATIN.*(?:LETTER|LIGATURE) ([A-Z]{2}(?![A-Z]))$#', $m[1], $capture))
|
||||
{
|
||||
/**
|
||||
* Special hack for some latin ligatures. Using the name of a character
|
||||
* is bad practice, but for now it works well enough.
|
||||
*
|
||||
* @todo Note that ligatures with combining marks such as U+01E2 are
|
||||
* not supported at this time
|
||||
*/
|
||||
$map[$cp] = strtolower($capture[1]);
|
||||
}
|
||||
else if (isset($m[13][0]))
|
||||
{
|
||||
/**
|
||||
* If the letter has a lowercased form, use it
|
||||
*/
|
||||
$map[$cp] = hex_to_utf($m[13]);
|
||||
}
|
||||
else
|
||||
{
|
||||
/**
|
||||
* In all other cases, map the letter to itself
|
||||
*/
|
||||
$map[$cp] = $utf_char;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'M':
|
||||
/**
|
||||
* We allow all marks, they are mapped to themselves
|
||||
*/
|
||||
$map[$cp] = $utf_char;
|
||||
break;
|
||||
|
||||
case 'N':
|
||||
/**
|
||||
* We allow all numbers, but we map them to their numeric value whenever
|
||||
* possible. The numeric value (field #8) is in ASCII already
|
||||
*
|
||||
* @todo Note that fractions such as U+00BD will be converted to something
|
||||
* like "1/2", with a slash. However, "1/2" entered in ASCII is converted
|
||||
* to "1 2". This will have to be fixed.
|
||||
*/
|
||||
$map[$cp] = (isset($m[8][0])) ? $m[8] : $utf_char;
|
||||
break;
|
||||
|
||||
default:
|
||||
/**
|
||||
* Everything else is ignored, skip to the next line
|
||||
*/
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
fclose($fp);
|
||||
|
||||
/**
|
||||
* Add some cheating
|
||||
*/
|
||||
$cheats = array(
|
||||
'00DF' => 'ss', # German sharp S
|
||||
'00C5' => 'ae', # Capital A with diaeresis
|
||||
'00E4' => 'ae', # Small A with diaeresis
|
||||
'00D6' => 'oe', # Capital O with diaeresis
|
||||
'00F6' => 'oe', # Small O with diaeresis
|
||||
'00DC' => 'ue', # Capital U with diaeresis
|
||||
'00FC' => 'ue', # Small U with diaeresis
|
||||
);
|
||||
|
||||
/**
|
||||
* Add our "cheat replacements" to the map
|
||||
*/
|
||||
foreach ($cheats as $hex => $map_to)
|
||||
{
|
||||
$map[hexdec($hex)] = $map_to;
|
||||
}
|
||||
|
||||
/**
|
||||
* Split the map into smaller blocks
|
||||
*/
|
||||
$file_contents = array();
|
||||
foreach ($map as $cp => $map_to)
|
||||
{
|
||||
$file_contents[$cp >> 11][cp_to_utf($cp)] = $map_to;
|
||||
}
|
||||
unset($map);
|
||||
|
||||
foreach ($file_contents as $idx => $contents)
|
||||
{
|
||||
echo "Writing to search_indexer_$idx." . PHP_EXT . "\n";
|
||||
$fp = fopen(PHPBB_ROOT_PATH . 'includes/utf/data/search_indexer_' . $idx . '.' . PHP_EXT, 'wb');
|
||||
fwrite($fp, '<?php return ' . my_var_export($contents) . ';');
|
||||
fclose($fp);
|
||||
}
|
||||
echo "\n*** Search indexer tables done\n\n";
|
||||
|
||||
|
||||
die("\nAll done!\n");
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Internal functions //
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Decompose a sequence recusively
|
||||
*
|
||||
* @param array $decomp_map Decomposition mapping, passed by reference
|
||||
* @param string $decomp_seq Decomposition sequence as decimal codepoints separated with a space
|
||||
* @return string Decomposition sequence, fully decomposed
|
||||
*/
|
||||
function decompose(&$decomp_map, $decomp_seq)
|
||||
{
|
||||
$ret = array();
|
||||
foreach (explode(' ', $decomp_seq) as $cp)
|
||||
{
|
||||
if (isset($decomp_map[$cp]))
|
||||
{
|
||||
$ret[] = decompose($decomp_map, $decomp_map[$cp]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$ret[] = $cp;
|
||||
}
|
||||
}
|
||||
|
||||
return implode(' ', $ret);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a parsable string representation of a variable
|
||||
*
|
||||
* This is function is limited to array/strings/integers
|
||||
*
|
||||
* @param mixed $var Variable
|
||||
* @return string PHP code representing the variable
|
||||
*/
|
||||
function my_var_export($var)
|
||||
{
|
||||
if (is_array($var))
|
||||
{
|
||||
$lines = array();
|
||||
|
||||
foreach ($var as $k => $v)
|
||||
{
|
||||
$lines[] = my_var_export($k) . '=>' . my_var_export($v);
|
||||
}
|
||||
|
||||
return 'array(' . implode(',', $lines) . ')';
|
||||
}
|
||||
else if (is_string($var))
|
||||
{
|
||||
return "'" . str_replace(array('\\', "'"), array('\\\\', "\\'"), $var) . "'";
|
||||
}
|
||||
else
|
||||
{
|
||||
return $var;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Download a file to the develop/ dir
|
||||
*
|
||||
* @param string $url URL of the file to download
|
||||
* @return void
|
||||
*/
|
||||
function download($url)
|
||||
{
|
||||
if (file_exists(PHPBB_ROOT_PATH . 'develop/' . basename($url)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
echo 'Downloading from ', $url, ' ';
|
||||
|
||||
if (!$fpr = fopen($url, 'rb'))
|
||||
{
|
||||
die("Can't download from $url\nPlease download it yourself and put it in the develop/ dir, kthxbai");
|
||||
}
|
||||
|
||||
if (!$fpw = fopen(PHPBB_ROOT_PATH . 'develop/' . basename($url), 'wb'))
|
||||
{
|
||||
die("Can't open develop/" . basename($url) . " for output... please check your permissions or something");
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
$chunk = 32768;
|
||||
$done = '';
|
||||
|
||||
while (!feof($fpr))
|
||||
{
|
||||
$i += fwrite($fpw, fread($fpr, $chunk));
|
||||
echo str_repeat("\x08", strlen($done));
|
||||
|
||||
$done = ($i >> 10) . ' KiB';
|
||||
echo $done;
|
||||
}
|
||||
fclose($fpr);
|
||||
fclose($fpw);
|
||||
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a codepoint in hexadecimal to a UTF-8 char
|
||||
*
|
||||
* @param string $hex Codepoint, in hexadecimal
|
||||
* @return string UTF-8 char
|
||||
*/
|
||||
function hex_to_utf($hex)
|
||||
{
|
||||
return cp_to_utf(hexdec($hex));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a UTF string formed from a sequence of codepoints in hexadecimal
|
||||
*
|
||||
* @param string $seq Sequence of codepoints, separated with a space
|
||||
* @return string UTF-8 string
|
||||
*/
|
||||
function hexseq_to_utf($seq)
|
||||
{
|
||||
return implode('', array_map('hex_to_utf', explode(' ', $seq)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a codepoint to a UTF-8 char
|
||||
*
|
||||
* @param integer $cp Unicode codepoint
|
||||
* @return string UTF-8 string
|
||||
*/
|
||||
function cp_to_utf($cp)
|
||||
{
|
||||
if ($cp > 0xFFFF)
|
||||
{
|
||||
return chr(0xF0 | ($cp >> 18)) . chr(0x80 | (($cp >> 12) & 0x3F)) . chr(0x80 | (($cp >> 6) & 0x3F)) . chr(0x80 | ($cp & 0x3F));
|
||||
}
|
||||
else if ($cp > 0x7FF)
|
||||
{
|
||||
return chr(0xE0 | ($cp >> 12)) . chr(0x80 | (($cp >> 6) & 0x3F)) . chr(0x80 | ($cp & 0x3F));
|
||||
}
|
||||
else if ($cp > 0x7F)
|
||||
{
|
||||
return chr(0xC0 | ($cp >> 6)) . chr(0x80 | ($cp & 0x3F));
|
||||
}
|
||||
else
|
||||
{
|
||||
return chr($cp);
|
||||
}
|
||||
}
|
@@ -1,58 +0,0 @@
|
||||
<?php
|
||||
|
||||
//
|
||||
// Security message:
|
||||
//
|
||||
// This script is potentially dangerous.
|
||||
// Remove or comment the next line (die(".... ) to enable this script.
|
||||
// Do NOT FORGET to either remove this script or disable it after you have used it.
|
||||
//
|
||||
die("Please read the first lines of this script for instructions on how to enable it");
|
||||
|
||||
//
|
||||
// Do not change anything below this line.
|
||||
//
|
||||
|
||||
|
||||
// Just a handy script to completely wipe out the contents of a
|
||||
// database.. Use with caution :)
|
||||
|
||||
|
||||
if(!isset($submit))
|
||||
{
|
||||
?>
|
||||
<FORM ACTION="<?php echo $PHP_SELF?>" METHOD="post" >
|
||||
<table>
|
||||
<tr>
|
||||
<td>DB host:</td>
|
||||
<td><INPUT TYPE="text" name="dbhost" value="localhost"></td>
|
||||
</tr><tr>
|
||||
<td>DB name:</td>
|
||||
<td><INPUT TYPE="text" name="dbname" value="phpBB"></td>
|
||||
</tr><tr>
|
||||
<td>DB username:</td>
|
||||
<td><INPUT TYPE="text" name="dbuser" value="root"></td>
|
||||
</tr><tr>
|
||||
<td>DB password:</td>
|
||||
<td><INPUT TYPE="password" name="dbpass"></td>
|
||||
</tr></table>
|
||||
<INPUT TYPE="submit" name="submit" value="Submit">
|
||||
</FORM>
|
||||
<?php
|
||||
}
|
||||
else
|
||||
{
|
||||
mysql_connect($dbhost, $dbuser, $dbpass) || die(mysql_error());
|
||||
mysql_select_db($dbname);
|
||||
|
||||
$result = mysql_query("SHOW TABLES");
|
||||
while($row = mysql_fetch_row($result)){
|
||||
$table = $row[0];
|
||||
print "Going to drop $table...";
|
||||
mysql_query("DROP TABLE $table") || die();
|
||||
print "Done.<br>\n";
|
||||
flush();
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -1,854 +0,0 @@
|
||||
<?php
|
||||
define('IN_PHPBB', true);
|
||||
define('PHPBB_ROOT_PATH', './../');
|
||||
define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
|
||||
include(PHPBB_ROOT_PATH . 'common.' . PHP_EXT);
|
||||
|
||||
//$db = new dbal_mysqli();
|
||||
|
||||
class posting_api
|
||||
{
|
||||
/*
|
||||
topic table:
|
||||
topic_id
|
||||
forum_id
|
||||
topic_title
|
||||
topic_status
|
||||
topic_type
|
||||
topic_shadow_id // to implement
|
||||
|
||||
sec:
|
||||
topic_posts
|
||||
topic_shadow_posts
|
||||
topic_deleted_posts
|
||||
topic_unapproved_posts
|
||||
|
||||
all must be approved:
|
||||
topic_poster
|
||||
topic_first_poster_name
|
||||
topic_first_poster_id
|
||||
topic_last_post_id
|
||||
topic_last_poster_name
|
||||
topic_last_poster_id
|
||||
topic_last_post_title
|
||||
topic_last_post_time
|
||||
*/
|
||||
|
||||
/*
|
||||
post table:
|
||||
post_id
|
||||
topic_id
|
||||
post_subject
|
||||
post_body
|
||||
post_status
|
||||
post_type
|
||||
post_username
|
||||
poster_id
|
||||
forum_id
|
||||
post_time
|
||||
|
||||
/*
|
||||
forum table:
|
||||
forum_id
|
||||
forum_posts
|
||||
forum_shadow_posts
|
||||
forum_deleted_posts
|
||||
forum_unapproved_posts
|
||||
|
||||
sec:
|
||||
forum_topics
|
||||
forum_shadow_topics
|
||||
forum_deleted_topics
|
||||
forum_unapproved_topics
|
||||
|
||||
forum_last_poster_name
|
||||
forum_last_user_id
|
||||
forum_last_post_title
|
||||
forum_last_post_time
|
||||
*/
|
||||
|
||||
const NORMAL = 0;
|
||||
|
||||
// status
|
||||
const UNAPPROVED = 1;
|
||||
const DELETED = 2;
|
||||
|
||||
// type
|
||||
const ANNOUNCEMENT = 1;
|
||||
const STICKY = 2;
|
||||
|
||||
// we, for now, only support the insertion of posts that are not already
|
||||
// shadow'd and not deleted (it must first exist for it to be shadow'd or deleted!)
|
||||
static function insert_topic($data)
|
||||
{
|
||||
// one transaction, we can now garuntee that atomicity of insertions
|
||||
phpbb::$db->sql_transaction('begin');
|
||||
|
||||
$user_id = (int) $data['user_id'];
|
||||
$forum_id = (int) $data['forum_id'];
|
||||
$topic_title = $data['title'];
|
||||
$post_contents = $data['post_contents'];
|
||||
$topic_status = (int) $data['status'];
|
||||
$topic_type = (int) $data['type'];
|
||||
$approved = (bool) $data['approved'];
|
||||
|
||||
$shadow_forums = $data['shadow_forums'];
|
||||
|
||||
$time = ($data['time']) ? (int) $data['time'] : time();
|
||||
|
||||
if (isset($data['username']))
|
||||
{
|
||||
$username = $data['username'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql = 'SELECT username
|
||||
FROM ' . USERS_TABLE . '
|
||||
WHERE user_id = ' . $user_id;
|
||||
$result = phpbb::$db->sql_query($sql);
|
||||
$username = (string) phpbb::$db->sql_fetchfield('username');
|
||||
phpbb::$db->sql_freeresult($result);
|
||||
}
|
||||
|
||||
$sql = 'SELECT forum_topics, forum_unapproved_topics, forum_posts, forum_unapproved_posts
|
||||
FROM ' . FORUMS_TABLE . '
|
||||
WHERE forum_id = ' . (int) $forum_id;
|
||||
$result = phpbb::$db->sql_query($sql);
|
||||
$row = phpbb::$db->sql_fetchrow($result);
|
||||
phpbb::$db->sql_freeresult($result);
|
||||
|
||||
// throw our topic to the dogs
|
||||
$topic_data = array(
|
||||
'topic_title' => $topic_title,
|
||||
'topic_status' => $topic_status,
|
||||
'topic_type' => $topic_type,
|
||||
'topic_posts' => 1,
|
||||
'topic_shadow_posts' => 0,
|
||||
'topic_deleted_posts' => 0,
|
||||
'topic_unapproved_posts' => ($approved) ? 0 : 1,
|
||||
'topic_first_poster_name' => $username,
|
||||
'topic_poster' => $user_id,
|
||||
'topic_last_username' => $username,
|
||||
'topic_last_post_title' => $topic_title,
|
||||
'topic_last_post_time' => $time,
|
||||
'topic_last_poster_id' => $user_id,
|
||||
'forum_id' => $forum_id
|
||||
);
|
||||
|
||||
phpbb::$db->sql_handle_data('INSERT', TOPICS_TABLE, $topic_data);
|
||||
$topic_id = phpbb::$db->sql_nextid();
|
||||
|
||||
// I suppose it is time to make us a post, no?
|
||||
$post_data = array(
|
||||
'topic_id' => $topic_id,
|
||||
'post_subject' => $topic_title,
|
||||
'post_body' => $post_contents,
|
||||
'post_username' => $username,
|
||||
'poster_id' => $user_id,
|
||||
'post_status' => $topic_status, // first post inherits its type from the topic
|
||||
'post_type' => self::NORMAL, // for now, there are no shadow, global or sticky posts
|
||||
'forum_id' => $forum_id
|
||||
);
|
||||
|
||||
phpbb::$db->sql_handle_data('INSERT', POSTS_TABLE, $post_data);
|
||||
$post_id = phpbb::$db->sql_nextid();
|
||||
|
||||
// time to fill in the blanks
|
||||
phpbb::$db->sql_handle_data('UPDATE', TOPICS_TABLE, array('topic_first_post_id' => $post_id, 'topic_last_post_id' => $post_id), "topic_id = $topic_id");
|
||||
|
||||
// let's go update the forum table
|
||||
$forum_data = array(
|
||||
'forum_posts' => ++$row['forum_posts'],
|
||||
'forum_topics' => ++$row['forum_topics'],
|
||||
);
|
||||
|
||||
// the last post inserted is always the latest,
|
||||
// we must update the forum records to make sure everybody knows the good news
|
||||
if ($approved)
|
||||
{
|
||||
$forum_data['forum_last_poster_name'] = $username;
|
||||
$forum_data['forum_last_user_id'] = $user_id;
|
||||
$forum_data['forum_last_post_title'] = $topic_title;
|
||||
$forum_data['forum_last_post_time'] = $time;
|
||||
}
|
||||
else
|
||||
{
|
||||
$forum_data['forum_unapproved_posts'] = ++$row['forum_unapproved_posts'];
|
||||
$forum_data['forum_unapproved_topics'] = ++$row['forum_unapproved_topics'];
|
||||
}
|
||||
|
||||
phpbb::$db->sql_handle_data('UPDATE', FORUMS_TABLE, $forum_data, "forum_id = $forum_id");
|
||||
|
||||
foreach ($shadow_forums as $shadow_forum_id)
|
||||
{
|
||||
$data['shadow_topic_id'] = $topic_id;
|
||||
$data['forum_id'] = $shadow_forum_id;
|
||||
self::insert_shadow_topic($data);
|
||||
}
|
||||
|
||||
// we are consistant, victory is ours
|
||||
phpbb::$db->sql_transaction('commit');
|
||||
}
|
||||
|
||||
// inserts a shadow topic into the database
|
||||
static function insert_shadow_topic($data)
|
||||
{
|
||||
// one transaction, we can now garuntee that atomicity of insertions
|
||||
phpbb::$db->sql_transaction('begin');
|
||||
|
||||
$user_id = (int) $data['user_id'];
|
||||
$forum_id = (int) $data['forum_id'];
|
||||
$topic_title = $data['title'];
|
||||
$topic_status = (int) $data['status'];
|
||||
$topic_type = (int) $data['type'];
|
||||
$time = ($data['time']) ? (int) $data['time'] : time();
|
||||
$shadow_topic_id = (int) $data['shadow_topic_id'];
|
||||
$approved = (bool) $data['approved'];
|
||||
|
||||
if (isset($data['username']))
|
||||
{
|
||||
$username = $data['username'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql = 'SELECT username
|
||||
FROM ' . USERS_TABLE . '
|
||||
WHERE user_id = ' . $user_id;
|
||||
$result = phpbb::$db->sql_query($sql);
|
||||
$username = (stromg) phpbb::$db->sql_fetchfield('username');
|
||||
phpbb::$db->sql_freeresult($result);
|
||||
}
|
||||
|
||||
$sql = 'SELECT forum_topics, forum_shadow_topics
|
||||
FROM ' . FORUMS_TABLE . '
|
||||
WHERE forum_id = ' . (int) $forum_id;
|
||||
$result = phpbb::phpbb::$db->sql_query($sql);
|
||||
$row = phpbb::$db->sql_fetchrow($result);
|
||||
phpbb::$db->sql_freeresult($result);
|
||||
|
||||
// throw our topic to the dogs
|
||||
$topic_data = array(
|
||||
'topic_title' => $topic_title,
|
||||
'topic_status' => $topic_status,
|
||||
'topic_type' => $topic_type,
|
||||
'topic_posts' => 0,
|
||||
'topic_shadow_posts' => 0,
|
||||
'topic_deleted_posts' => 0,
|
||||
'topic_unapproved_posts' => ($approved ? 0 : 1),
|
||||
'topic_first_poster_name' => $username,
|
||||
'topic_poster' => $user_id,
|
||||
'topic_last_username' => $username,
|
||||
'topic_last_post_title' => $topic_title,
|
||||
'topic_last_post_time' => $time,
|
||||
'topic_last_poster_id' => $user_id,
|
||||
'forum_id' => $forum_id,
|
||||
'topic_shadow_id' => $shadow_topic_id
|
||||
);
|
||||
|
||||
phpbb::$db->sql_handle_data('INSERT', TOPICS_TABLE, $topic_data);
|
||||
|
||||
// let's go update the forum table
|
||||
$forum_data = array(
|
||||
'forum_topics' => ++$row['forum_topics'],
|
||||
'forum_shadow_topics' => ++$row['forum_shadow_topics']
|
||||
);
|
||||
|
||||
// an unapproved shadow topic? I suppose...
|
||||
if (!$approved)
|
||||
{
|
||||
$forum_data['forum_unapproved_topics'] = ++$row['forum_unapproved_topics'];
|
||||
}
|
||||
|
||||
phpbb::$db->sql_handle_data('UPDATE', FORUMS_TABLE, $forum_data, "forum_id = $forum_id");
|
||||
|
||||
// we are consistant, victory is ours
|
||||
phpbb::$db->transaction('END');
|
||||
}
|
||||
|
||||
static function insert_post($data)
|
||||
{
|
||||
// one transaction, we can now garuntee that atomicity of insertions
|
||||
phpbb::$db->transaction('BEGIN');
|
||||
|
||||
$user_id = (int) $data['user_id'];
|
||||
$topic_id = (int) $data['topic_id'];
|
||||
|
||||
// begin massive amounts of hand holding
|
||||
|
||||
if (isset($data['forum_id']))
|
||||
{
|
||||
$forum_id = (int) $data['forum_id'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql = 'SELECT forum_id
|
||||
FROM ' . TOPICS_TABLE . '
|
||||
WHERE topic_id = ' . $topic_id;
|
||||
$result = phpbb::$db->sql_query($sql);
|
||||
$forum_id = (int) phpbb::$db->sql_fetchfield('forum_id');
|
||||
phpbb::$db->sql_freeresult($result);
|
||||
}
|
||||
|
||||
$post_title = $data['title'];
|
||||
$post_contents = $data['post_contents'];
|
||||
$time = ($data['time']) ? (int) $data['time'] : time();
|
||||
|
||||
if (isset($data['username']))
|
||||
{
|
||||
$username = $data['username'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql = 'SELECT username
|
||||
FROM ' . USERS_TABLE . '
|
||||
WHERE user_id = ' . $user_id;
|
||||
$result = phpbb::$db->sql_query($sql);
|
||||
$username = (string) phpbb::$db->sql_fetchfield('username');
|
||||
phpbb::$db->sql_freeresult($result);
|
||||
}
|
||||
|
||||
// hand holding complete, lets write some posts
|
||||
|
||||
$sql = 'SELECT forum_topics, forum_unapproved_topics, forum_posts, forum_unapproved_posts
|
||||
FROM ' . FORUMS_TABLE . '
|
||||
WHERE forum_id = ' . (int) $forum_id;
|
||||
$result = phpbb::$db->sql_query($sql);
|
||||
$row = phpbb::$db->sql_fetchrow($result);
|
||||
phpbb::$db->sql_freeresult($result);
|
||||
|
||||
$post_status = (int) $data['post_status'];
|
||||
$approved = ($post_status === self::NORMAL);
|
||||
|
||||
// I suppose it is time to make us a post, no?
|
||||
$post_data = array(
|
||||
'topic_id' => $topic_id,
|
||||
'post_subject' => $post_title,
|
||||
'post_body' => $post_contents,
|
||||
'post_username' => $username,
|
||||
'poster_id' => $user_id,
|
||||
'post_status' => $post_status,
|
||||
'forum_id' => $forum_id,
|
||||
);
|
||||
phpbb::$db->sql_handle_data('INSERT', POSTS_TABLE, $post_data);
|
||||
|
||||
// what is the new post_id?
|
||||
$post_id = phpbb::$db->sql_nextid();
|
||||
|
||||
// iceberg ahead! we must only update the topic information if the post is approved ;)
|
||||
if ($approved)
|
||||
{
|
||||
// time to fill in the blanks
|
||||
$topics_data = array(
|
||||
'topic_last_poster_id' => $user_id,
|
||||
'topic_last_post_id' => $post_id,
|
||||
'topic_last_poster_name'=> $username,
|
||||
'topic_last_post_title' => $post_title,
|
||||
'topic_last_post_time' => $time,
|
||||
);
|
||||
phpbb::$db->sql_handle_data('UPDATE', TOPICS_TABLE, $topics_data, "topic_id = $topic_id");
|
||||
}
|
||||
|
||||
// let's go update the forum table
|
||||
$forum_data = array(
|
||||
'forum_posts' => ++$row['forum_posts'],
|
||||
);
|
||||
|
||||
// the last post inserted is always the latest,
|
||||
// we must update the forum records to make sure everybody knows the good news
|
||||
if ($approved)
|
||||
{
|
||||
$forum_data['forum_last_poster_name'] = $username;
|
||||
$forum_data['forum_last_user_id'] = $user_id;
|
||||
$forum_data['forum_last_post_title'] = $post_title;
|
||||
$forum_data['forum_last_post_time'] = $time;
|
||||
}
|
||||
else
|
||||
{
|
||||
$forum_data['forum_unapproved_posts'] = ++$row['forum_unapproved_posts'];
|
||||
}
|
||||
|
||||
phpbb::$db->sql_handle_data('UPDATE', FORUMS_TABLE, $forum_data, "forum_id = $forum_id");
|
||||
|
||||
// we are consistant, victory is ours
|
||||
phpbb::$db->sql_transaction('commit');
|
||||
}
|
||||
|
||||
static function delete_topic($data)
|
||||
{
|
||||
// just call the more powerful variant with just one topic :)
|
||||
self::delete_topics(array('topic_ids' => array($data['topic_id'])));
|
||||
}
|
||||
|
||||
static function delete_topics($data)
|
||||
{
|
||||
// lets get this party started
|
||||
phpbb::$db->sql_transaction('begin');
|
||||
|
||||
$topic_ids = array_map('intval', $data['topic_ids']);
|
||||
|
||||
// what kind of topic is this? lets find out how much we must tamper with the forum table...
|
||||
// TODO: investigate how aggregate functions can speed this up/reduce the number of results returned/misc. other benefits
|
||||
$sql = 'SELECT topic_posts, topic_shadow_posts, topic_deleted_posts, topic_unapproved_posts, topic_shadow_id, forum_id, topic_status
|
||||
FROM ' . TOPICS_TABLE . '
|
||||
WHERE ' . phpbb::$db->sql_in_set('topic_id', $topic_ids);
|
||||
$result = phpbb::$db->sql_query($sql);
|
||||
// the following in an array, key'd by forum id that refers to topic rows
|
||||
$forum_lookup = array();
|
||||
while ($topic_row = phpbb::$db->sql_fetchrow($result))
|
||||
{
|
||||
$forum_id = (int) $topic_row['forum_id'];
|
||||
|
||||
// deal with posts
|
||||
$forum_lookup[$forum_id]['forum_posts'] += $topic_row['topic_posts'];
|
||||
$forum_lookup[$forum_id]['forum_shadow_posts'] += $topic_row['topic_shadow_posts'];
|
||||
$forum_lookup[$forum_id]['forum_deleted_posts'] += $topic_row['topic_deleted_posts'];
|
||||
$forum_lookup[$forum_id]['forum_unapproved_posts'] += $topic_row['topic_unapproved_posts'];
|
||||
|
||||
// deal with topics
|
||||
$topic_status = (int) $topic_row['topic_status'];
|
||||
$forum_lookup[$forum_id]['forum_topics']++; // a topic is a topic
|
||||
$forum_lookup[$forum_id]['forum_shadow_topics'] += ($topic_row['topic_shadow_id'] != 0);
|
||||
$forum_lookup[$forum_id]['forum_deleted_topics'] += ($topic_status & self::DELETED);
|
||||
$forum_lookup[$forum_id]['forum_unapproved_topics'] += ($topic_status & self::UNAPPROVED);
|
||||
}
|
||||
phpbb::$db->sql_freeresult($result);
|
||||
|
||||
// goodnight, topics
|
||||
phpbb::$db->sql_query('DELETE FROM ' . TOPICS_TABLE . ' WHERE ' . phpbb::$db->sql_in_set('topic_id', $topic_ids));
|
||||
|
||||
// goodnight, posts
|
||||
phpbb::$db->sql_query('DELETE FROM ' . POSTS_TABLE . ' WHERE ' . phpbb::$db->sql_in_set('topic_id', $topic_ids));
|
||||
|
||||
$forum_ids = array_keys($forum_lookup);
|
||||
|
||||
// what kind of topic is this? lets find out how much we must tamper with the forum table...
|
||||
$sql = 'SELECT forum_posts, forum_shadow_posts, forum_deleted_posts, forum_unapproved_posts, forum_id
|
||||
FROM ' . FORUMS_TABLE . '
|
||||
WHERE ' . phpbb::$db->sql_in_set('forum_id', $forum_ids);
|
||||
$result = phpbb::$db->sql_query($sql);
|
||||
$forum_rows = array();
|
||||
while ($forum_row = phpbb::$db->sql_fetchrow($result))
|
||||
{
|
||||
$forum_id = (int) $forum_row['forum_id'];
|
||||
$forum_rows[$forum_id] = $forum_row;
|
||||
}
|
||||
phpbb::$db->sql_freeresult($result);
|
||||
|
||||
$shadow_topic_ids = array();
|
||||
foreach ($forum_rows as $forum_id => $forum_row)
|
||||
{
|
||||
$topic_row = $forum_lookup[$forum_id];
|
||||
$forum_array = array(
|
||||
'forum_posts' => max($forum_row['forum_posts'] - $topic_row['forum_posts'], 0),
|
||||
'forum_shadow_posts' => max($forum_row['forum_shadow_posts'] - $topic_row['forum_shadow_posts'], 0),
|
||||
'forum_deleted_posts' => max($forum_row['forum_deleted_posts'] - $topic_row['forum_deleted_posts'], 0),
|
||||
'forum_unapproved_posts' => max($forum_row['forum_unapproved_posts'] - $topic_row['forum_unapproved_posts'], 0),
|
||||
|
||||
'forum_topics' => max($forum_row['forum_topics'] - $topic_row['forum_topics'], 0),
|
||||
'forum_shadow_topics' => max($forum_row['forum_shadow_topics'] - $topic_row['forum_shadow_topics'], 0),
|
||||
'forum_deleted_topics' => max($forum_row['forum_deleted_topics'] - $topic_row['forum_deleted_topics'], 0),
|
||||
'forum_unapproved_topics' => max($forum_row['forum_unapproved_topics'] - $topic_row['forum_unapproved_topics'], 0),
|
||||
);
|
||||
|
||||
// get the last "normal" post in the forum, we _must_ update it
|
||||
$sql = 'SELECT MAX(post_id) as max_post_id
|
||||
FROM ' . POSTS_TABLE . '
|
||||
WHERE post_status = ' . self::NORMAL . '
|
||||
AND forum_id = ' . $forum_id;
|
||||
$result = phpbb::$db->sql_query($sql);
|
||||
$row = phpbb::$db->sql_fetchrow($result);
|
||||
phpbb::$db->sql_freeresult($result);
|
||||
|
||||
// anything left?
|
||||
if ($row)
|
||||
{
|
||||
// OK, lets go do some magick
|
||||
$sql = 'SELECT post_username, poster_id, post_subject, post_time
|
||||
FROM '. POSTS_TABLE . '
|
||||
WHERE post_id = ' . (int) $row['max_post_id'];
|
||||
$result = phpbb::$db->sql_query($sql);
|
||||
$last_post = phpbb::$db->sql_fetchrow($result);
|
||||
phpbb::$db->sql_freeresult($result);
|
||||
|
||||
$forum_array['forum_last_user_id'] = (int) $last_post['poster_id'];
|
||||
$forum_array['forum_last_poster_name'] = $last_post['post_username'];
|
||||
$forum_array['forum_last_post_title'] = $last_post['post_subject'];
|
||||
$forum_array['forum_last_post_time'] = (int) $last_post['post_time'];
|
||||
}
|
||||
else
|
||||
{
|
||||
// reset forum state
|
||||
$forum_array['forum_last_user_id'] = 0;
|
||||
$forum_array['forum_last_poster_name'] = '';
|
||||
$forum_array['forum_last_post_title'] = '';
|
||||
$forum_array['forum_last_post_time'] = 0;
|
||||
}
|
||||
|
||||
phpbb::$db->sql_handle_data('UPDATE', FORUMS_TABLE, $forum_array, "forum_id = $forum_id");
|
||||
}
|
||||
|
||||
// let's not get too hasty, we can kill off the shadows later,
|
||||
// instead we compose a list of all shadows and then efficiently kill them off :)
|
||||
$sql = 'SELECT topic_id
|
||||
FROM ' . TOPICS_TABLE . '
|
||||
WHERE ' . phpbb::$db->sql_in_set('topic_shadow_id', $topic_ids);
|
||||
$result = phpbb::$db->sql_query($sql);
|
||||
|
||||
while ($row = phpbb::$db->sql_fetchrow($result))
|
||||
{
|
||||
$shadow_topic_ids[] = $row['topic_id'];
|
||||
}
|
||||
|
||||
phpbb::$db->sql_freeresult($result);
|
||||
|
||||
// recursion, the other white meat.
|
||||
if (sizeof($shadow_topic_ids))
|
||||
{
|
||||
self::delete_topics(array('topic_ids' => $shadow_topic_ids));
|
||||
}
|
||||
|
||||
// goodnight, moon
|
||||
phpbb::$db->transaction('commit');
|
||||
}
|
||||
|
||||
static function delete_post($data)
|
||||
{
|
||||
// just call the more powerful variant with just one post :)
|
||||
self::delete_posts(array('post_ids' => array($data['post_id'])));
|
||||
}
|
||||
|
||||
static function delete_posts($data)
|
||||
{
|
||||
// lets get this party started
|
||||
phpbb::$db->sql_transaction('begin');
|
||||
|
||||
$post_ids = array_map('intval', $data['post_ids']);
|
||||
|
||||
$sql = 'SELECT topic_id, post_status, post_id, post_shadow_id, forum_id
|
||||
FROM ' . POSTS_TABLE . '
|
||||
WHERE ' . phpbb::$db->sql_in_set('post_id', $post_ids);
|
||||
$result = phpbb::$db->sql_query($sql);
|
||||
|
||||
// the following arrays are designed to allow for much faster updates
|
||||
$topic_lookup = array();
|
||||
$forum_lookup = array();
|
||||
|
||||
while ($post_row = phpbb::$db->sql_fetchrow($result))
|
||||
{
|
||||
$topic_id = (int) $post_row['topic_id'];
|
||||
$forum_id = (int) $post_row['forum_id'];
|
||||
$post_status = (int) $post_row['post_status'];
|
||||
|
||||
$topic_lookup[$topic_id]['topic_posts']++; // we remove a post, go figure
|
||||
$topic_lookup[$topic_id]['topic_shadow_posts'] += ($post_row['post_shadow_id'] != 0); // did we just try to kill a shadow post?!
|
||||
$topic_lookup[$topic_id]['topic_deleted_posts'] += ($post_status & self::DELETED);
|
||||
$topic_lookup[$topic_id]['topic_unapproved_posts'] += ($post_status & self::UNAPPROVED);
|
||||
|
||||
$forum_lookup[$forum_id]['forum_posts']++;
|
||||
$forum_lookup[$topic_id]['forum_shadow_posts'] += ($post_row['post_shadow_id'] != 0); // did we just try to kill a shadow post?!
|
||||
$forum_lookup[$topic_id]['forum_deleted_posts'] += ($post_status & self::DELETED);
|
||||
$forum_lookup[$topic_id]['forum_unapproved_posts'] += ($post_status & self::UNAPPROVED);
|
||||
}
|
||||
phpbb::$db->sql_freeresult($result);
|
||||
|
||||
$topic_ids = array_keys($forum_lookup);
|
||||
|
||||
// goodnight, posts
|
||||
phpbb::$db->sql_query('DELETE FROM ' . POSTS_TABLE . ' WHERE ' . phpbb::$db->sql_in_set('topic_id', $topic_ids));
|
||||
|
||||
// mangle the forums table
|
||||
$sql = 'SELECT forum_posts, forum_shadow_posts, forum_deleted_posts, forum_unapproved_posts, forum_id
|
||||
FROM ' . FORUMS_TABLE . '
|
||||
WHERE forum_id = ' . $forum_id;
|
||||
$result = phpbb::$db->sql_query($sql);
|
||||
$forum_rows = array();
|
||||
while ($forum_row = phpbb::$db->sql_fetchrow($result))
|
||||
{
|
||||
$forum_id = (int) $forum_row['forum_id'];
|
||||
$forum_rows[$forum_id] = $forum_row;
|
||||
}
|
||||
phpbb::$db->sql_freeresult($result);
|
||||
|
||||
$shadow_topic_ids = array();
|
||||
foreach ($forum_rows as $forum_id => $forum_row)
|
||||
{
|
||||
$topic_row = $forum_lookup[$forum_id];
|
||||
$forum_array = array(
|
||||
'forum_posts' => max($forum_row['forum_posts'] - $topic_row['forum_posts'], 0),
|
||||
'forum_shadow_posts' => max($forum_row['forum_shadow_posts'] - $topic_row['forum_shadow_posts'], 0),
|
||||
'forum_deleted_posts' => max($forum_row['forum_deleted_posts'] - $topic_row['forum_deleted_posts'], 0),
|
||||
'forum_unapproved_posts' => max($forum_row['forum_unapproved_posts'] - $topic_row['forum_unapproved_posts'], 0),
|
||||
);
|
||||
|
||||
// get the last "normal" post in the forum, we _must_ update it
|
||||
$sql = 'SELECT MAX(post_id) as max_post_id
|
||||
FROM ' . POSTS_TABLE . '
|
||||
WHERE post_status = ' . self::NORMAL . '
|
||||
AND forum_id = ' . $forum_id;
|
||||
$result = phpbb::$db->sql_query($sql);
|
||||
$row = phpbb::$db->sql_fetchrow($result);
|
||||
phpbb::$db->sql_freeresult($result);
|
||||
|
||||
// anything left?
|
||||
if ($row)
|
||||
{
|
||||
// OK, lets go do some magick
|
||||
$sql = 'SELECT post_username, poster_id, post_subject, post_time
|
||||
FROM '. POSTS_TABLE . '
|
||||
WHERE post_id = ' . (int) $row['max_post_id'];
|
||||
$result = phpbb::$db->sql_query($sql);
|
||||
$last_post = phpbb::$db->sql_fetchrow($result);
|
||||
phpbb::$db->sql_freeresult($result);
|
||||
|
||||
$forum_array['forum_last_user_id'] = (int) $last_post['poster_id'];
|
||||
$forum_array['forum_last_poster_name'] = $last_post['post_username'];
|
||||
$forum_array['forum_last_post_title'] = $last_post['post_subject'];
|
||||
$forum_array['forum_last_post_time'] = (int) $last_post['post_time'];
|
||||
}
|
||||
else
|
||||
{
|
||||
// reset forum state
|
||||
$forum_array['forum_last_user_id'] = 0;
|
||||
$forum_array['forum_last_poster_name'] = '';
|
||||
$forum_array['forum_last_post_title'] = '';
|
||||
$forum_array['forum_last_post_time'] = 0;
|
||||
}
|
||||
|
||||
phpbb::$db->sql_handle_data('UPDATE', FORUMS_TABLE, $forum_array, "forum_id = $forum_id");
|
||||
}
|
||||
|
||||
// mangle the topics table now :)
|
||||
$sql = 'SELECT topic_posts, topic_shadow_posts, topic_deleted_posts, topic_unapproved_posts, topic_id
|
||||
FROM ' . TOPICS_TABLE . '
|
||||
WHERE forum_id = ' . $forum_id;
|
||||
$result = phpbb::$db->sql_query($sql);
|
||||
$topic_rows = array();
|
||||
while ($topic_row = phpbb::$db->sql_fetchrow($result))
|
||||
{
|
||||
$topic_id = (int) $topic_row['topic_id'];
|
||||
$topic_rows[$topic_id] = $topic_row;
|
||||
}
|
||||
phpbb::$db->sql_freeresult($result);
|
||||
|
||||
$empty_topic_ids = array();
|
||||
|
||||
foreach ($topic_rows as $topic_id => $topic_row)
|
||||
{
|
||||
$post_row = $topic_lookup[$topic_id];
|
||||
$topic_array = array(
|
||||
'topic_posts' => max($topic_row['topic_posts'] - $post_row['topic_posts'], 0),
|
||||
'topic_shadow_posts' => max($topic_row['topic_shadow_posts'] - $post_row['topic_shadow_posts'], 0),
|
||||
'topic_deleted_posts' => max($topic_row['topic_deleted_posts'] - $post_row['topic_deleted_posts'], 0),
|
||||
'topic_unapproved_posts' => max($topic_row['topic_unapproved_posts'] - $post_row['topic_unapproved_posts'], 0),
|
||||
);
|
||||
|
||||
// get the last "normal" post in the topic, we _must_ update it
|
||||
$sql = 'SELECT MAX(post_id) as max_post_id
|
||||
FROM ' . POSTS_TABLE . '
|
||||
WHERE post_status = ' . self::NORMAL . '
|
||||
AND topic_id = ' . $topic_id;
|
||||
$result = phpbb::$db->sql_query($sql);
|
||||
$row = phpbb::$db->sql_fetchrow($result);
|
||||
phpbb::$db->sql_freeresult($result);
|
||||
|
||||
// anything left?
|
||||
if ($row)
|
||||
{
|
||||
// OK, lets go do some magick
|
||||
$sql = 'SELECT post_username, poster_id, post_subject, post_time
|
||||
FROM '. POSTS_TABLE . '
|
||||
WHERE post_id = ' . (int) $row['max_post_id'];
|
||||
$result = phpbb::$db->sql_query($sql);
|
||||
$last_post = phpbb::$db->sql_fetchrow($result);
|
||||
phpbb::$db->sql_freeresult($result);
|
||||
|
||||
$topic_array['topic_last_user_id'] = (int) $last_post['poster_id'];
|
||||
$topic_array['topic_last_poster_name'] = $last_post['post_username'];
|
||||
$topic_array['topic_last_post_title'] = $last_post['post_subject'];
|
||||
$topic_array['topic_last_post_time'] = (int) $last_post['post_time'];
|
||||
}
|
||||
else
|
||||
{
|
||||
// mark this post for execution!
|
||||
$empty_topic_ids[] = $topic_id;
|
||||
}
|
||||
|
||||
phpbb::$db->sql_handle_data('UPDATE', TOPICS_TABLE, $topic_array, "topic_id = $topic_id");
|
||||
}
|
||||
|
||||
$shadow_post_ids = array();
|
||||
|
||||
// let's not get too hasty, we can kill off the shadows later,
|
||||
// instead we compose a list of all shadows and then efficiently kill them off :)
|
||||
$sql = 'SELECT post_id
|
||||
FROM ' . POSTS_TABLE . '
|
||||
WHERE ' . phpbb::$db->sql_in_set('post_shadow_id', $topic_ids);
|
||||
$result = phpbb::$db->sql_query($sql);
|
||||
|
||||
while ($row = phpbb::$db->sql_fetchrow($result))
|
||||
{
|
||||
$shadow_post_ids[] = $row['post_id'];
|
||||
}
|
||||
|
||||
phpbb::$db->sql_freeresult($result);
|
||||
|
||||
// recursion, the other white meat.
|
||||
if (sizeof($shadow_topic_ids))
|
||||
{
|
||||
self::delete_posts(array('post_ids' => $shadow_post_ids));
|
||||
}
|
||||
|
||||
// we killed all the posts in a topic, time to kill the topics!
|
||||
if (sizeof($empty_topic_ids))
|
||||
{
|
||||
self::delete_topics(array('topic_ids' => $empty_topic_ids));
|
||||
}
|
||||
|
||||
// goodnight, moon
|
||||
phpbb::$db->transaction('commit');
|
||||
}
|
||||
|
||||
static function move_topic($data)
|
||||
{
|
||||
self::move_topics(array('topic_forum_mapping' => array(array('topic_id' => $data['topic_id'], 'forum_id' => $data['forum_id'], 'make_shadow' => $data['make_shadow']))));
|
||||
}
|
||||
|
||||
static function move_topics($data)
|
||||
{
|
||||
// lets get this party started
|
||||
phpbb::$db->transaction('begin');
|
||||
|
||||
// all of each are indexed by topic id
|
||||
$to_forum_ids = $shadow_topic_ids = array();
|
||||
|
||||
foreach ($data['topic_forum_mapping'] as $mapping)
|
||||
{
|
||||
$topic_id = (int) $mapping['topic_id'];
|
||||
$to_forum_ids[$topic_id] = (int) $mapping['forum_id'];
|
||||
if ($mapping['make_shadow'])
|
||||
{
|
||||
$shadow_topic_ids[] = $topic_id;
|
||||
}
|
||||
}
|
||||
|
||||
$forum_columns = array('forum_posts', 'forum_shadow_posts', 'forum_deleted_posts', 'forum_unapproved_posts', 'forum_topics', 'forum_shadow_topics', 'forum_deleted_topics', 'forum_unapproved_topics');
|
||||
|
||||
$topic_ids = array_keys($to_forum_ids);
|
||||
|
||||
// let us first determine how many items we are removing from the pool
|
||||
$sql = 'SELECT topic_posts, topic_shadow_posts, topic_deleted_posts, topic_unapproved_posts, forum_id, topic_status, topic_type, topic_shadow_id, topic_id
|
||||
FROM ' . TOPICS_TABLE . '
|
||||
WHERE ' . phpbb::$db->sql_in_set('topic_id', $topic_ids);
|
||||
$result = phpbb::$db->sql_query($sql);
|
||||
$forum_lookup = array();
|
||||
while ($topic_row = phpbb::$db->sql_fetchrow($result))
|
||||
{
|
||||
$topic_id = $topic_row['topic_id'];
|
||||
$from_forum_id = (int) $topic_row['forum_id'];
|
||||
$to_forum_id = $to_forum_ids[$topic_id];
|
||||
|
||||
// we are iterating one topic at a time...
|
||||
$forum_lookup[$from_forum_id]['forum_topics'] = $forum_lookup[$to_forum_id]['forum_topics'] = 1;
|
||||
|
||||
foreach ($forum_columns as $column)
|
||||
{
|
||||
$forum_lookup[$from_forum_id][$column] -= $topic_row['topic_posts'];
|
||||
$forum_lookup[$to_forum_id][$column] += $topic_row['topic_posts'];
|
||||
}
|
||||
}
|
||||
phpbb::$db->sql_freeresult($result);
|
||||
|
||||
// determine the totals
|
||||
$sql = 'SELECT forum_posts, forum_shadow_posts, forum_deleted_posts, forum_unapproved_posts, forum_id, forum_topics, forum_deleted_topics, forum_unapproved_topics
|
||||
FROM ' . FORUMS_TABLE . '
|
||||
WHERE ' . phpbb::$db->sql_in_set('forum_id', array_keys($forum_lookup));
|
||||
$result = phpbb::$db->sql_query($sql);
|
||||
|
||||
while ($row = phpbb::$db->sql_fetchrow($result))
|
||||
{
|
||||
$forum_id = (int) $row['forum_id'];
|
||||
|
||||
foreach ($forum_columns as $column)
|
||||
{
|
||||
$forum_lookup[$forum_id][$column] += (int) $row[$column];
|
||||
}
|
||||
}
|
||||
|
||||
// create a listing of which topics are going in which forums
|
||||
$update_list = array();
|
||||
|
||||
foreach ($to_forum_ids as $topic_id => $forum_id)
|
||||
{
|
||||
$update_list[$forum_id][] = $topic_id;
|
||||
}
|
||||
|
||||
// we save as many queries as we can by updating all similar topics at once
|
||||
foreach ($update_list as $forum_id => $topic_ids)
|
||||
{
|
||||
// update the topic itself
|
||||
phpbb::$db->sql_handle_data('UPDATE', TOPICS_TABLE, array('forum_id' => $to_forum_id), phpbb::$db->sql_in_set('topic_id', $topic_ids));
|
||||
|
||||
// update the posts now
|
||||
phpbb::$db->sql_handle_data('UPDATE', POSTS_TABLE, array('forum_id' => $to_forum_id), phpbb::$db->sql_in_set('topic_id', $topic_ids));
|
||||
}
|
||||
|
||||
// start building the needed arrays for updating the forum data
|
||||
foreach ($forum_lookup as $forum_id => $forum_data)
|
||||
{
|
||||
foreach ($forum_columns as $column)
|
||||
{
|
||||
$forum_data[$column] = max($forum_data[$column], 0); // ensure the result is unsigned
|
||||
}
|
||||
|
||||
// get the last "normal" post in the old forum, we _must_ update it
|
||||
$sql = 'SELECT MAX(post_id) as max_post_id
|
||||
FROM ' . POSTS_TABLE . '
|
||||
WHERE post_status = ' . self::NORMAL . '
|
||||
AND forum_id = ' . $forum_id;
|
||||
$result = phpbb::$db->sql_query($sql);
|
||||
$row = phpbb::$db->sql_fetchrow($result);
|
||||
phpbb::$db->sql_freeresult($result);
|
||||
|
||||
// anything left?
|
||||
if ($row)
|
||||
{
|
||||
// OK, lets go do some magick
|
||||
$sql = 'SELECT post_username, poster_id, post_subject, post_time
|
||||
FROM '. POSTS_TABLE . '
|
||||
WHERE post_id = ' . (int) $row['max_post_id'];
|
||||
$result = phpbb::$db->sql_query($sql);
|
||||
$last_post = phpbb::$db->sql_fetchrow($result);
|
||||
phpbb::$db->sql_freeresult($result);
|
||||
|
||||
$forum_data['forum_last_user_id'] = (int) $last_post['poster_id'];
|
||||
$forum_data['forum_last_poster_name'] = $last_post['post_username'];
|
||||
$forum_data['forum_last_post_title'] = $last_post['post_subject'];
|
||||
$forum_data['forum_last_post_time'] = (int) $last_post['post_time'];
|
||||
}
|
||||
else
|
||||
{
|
||||
// reset forum state
|
||||
$forum_data['forum_last_user_id'] = 0;
|
||||
$forum_data['forum_last_poster_name'] = '';
|
||||
$forum_data['forum_last_post_title'] = '';
|
||||
$forum_data['forum_last_post_time'] = 0;
|
||||
}
|
||||
|
||||
// update the old forum
|
||||
phpbb::$db->sql_handle_data('UPDATE', FORUMS_TABLE, $forum_data, "forum_id = $forum_id");
|
||||
}
|
||||
|
||||
// hooray for code reuse!
|
||||
foreach ($shadow_topic_ids as $topic_id)
|
||||
{
|
||||
$data['shadow_topic_id'] = $topic_id;
|
||||
$data['forum_id'] = $from_forum_id;
|
||||
self::insert_shadow_topic($data);
|
||||
}
|
||||
|
||||
phpbb::$db->sql_transaction('commit');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@@ -1,83 +0,0 @@
|
||||
<?php
|
||||
//
|
||||
// Security message:
|
||||
//
|
||||
// This script is potentially dangerous.
|
||||
// Remove or comment the next line (die(".... ) to enable this script.
|
||||
// Do NOT FORGET to either remove this script or disable it after you have used it.
|
||||
//
|
||||
die("Please read the first lines of this script for instructions on how to enable it");
|
||||
|
||||
|
||||
// IP regular expressions
|
||||
|
||||
$dec_octet = '(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])';
|
||||
$h16 = '[\dA-F]{1,4}';
|
||||
$ipv4 = "(?:$dec_octet\.){3}$dec_octet";
|
||||
$ls32 = "(?:$h16:$h16|$ipv4)";
|
||||
|
||||
$ipv6_construct = array(
|
||||
array(false, '', '{6}', $ls32),
|
||||
array(false, '::', '{5}', $ls32),
|
||||
array('', ':', '{4}', $ls32),
|
||||
array('{1,2}', ':', '{3}', $ls32),
|
||||
array('{1,3}', ':', '{2}', $ls32),
|
||||
array('{1,4}', ':', '', $ls32),
|
||||
array('{1,5}', ':', false, $ls32),
|
||||
array('{1,6}', ':', false, $h16),
|
||||
array('{1,7}', ':', false, '')
|
||||
);
|
||||
|
||||
$ipv6 = '(?:';
|
||||
foreach ($ipv6_construct as $ip_type)
|
||||
{
|
||||
$ipv6 .= '(?:';
|
||||
if ($ip_type[0] !== false)
|
||||
{
|
||||
$ipv6 .= "(?:$h16:)" . $ip_type[0];
|
||||
}
|
||||
$ipv6 .= $ip_type[1];
|
||||
if ($ip_type[2] !== false)
|
||||
{
|
||||
$ipv6 .= "(?:$h16:)" . $ip_type[2];
|
||||
}
|
||||
$ipv6 .= $ip_type[3] . ')|';
|
||||
}
|
||||
$ipv6 = substr($ipv6, 0, -1) . ')';
|
||||
|
||||
echo 'IPv4: ' . $ipv4 . "<br />\nIPv6: " . $ipv6 . "<br />\n";
|
||||
|
||||
// URL regular expressions
|
||||
|
||||
$pct_encoded = "%[\dA-F]{2}";
|
||||
$unreserved = 'a-z0-9\-._~';
|
||||
$sub_delims = '!$&\'()*+,;=';
|
||||
$pchar = "(?:[$unreserved$sub_delims:@|]+|$pct_encoded)"; // rfc: no "|"
|
||||
|
||||
$scheme = '[a-z][a-z\d+\-.]*';
|
||||
$reg_name = "(?:[$unreserved$sub_delims:@|]+|$pct_encoded)+"; // rfc: * instead of + and no "|" and no "@" and no ":" (included instead of userinfo)
|
||||
//$userinfo = "(?:(?:[$unreserved$sub_delims:]+|$pct_encoded))*";
|
||||
$ipv4_simple = '[0-9.]+';
|
||||
$ipv6_simple = '\[[a-z0-9.]+:[a-z0-9.]+:[a-z0-9.:]+\]';
|
||||
$host = "(?:$reg_name|$ipv4_simple|$ipv6_simple)";
|
||||
$port = '\d*';
|
||||
//$authority = "(?:$userinfo@)?$host(?::$port)?";
|
||||
$authority = "$host(?::$port)?";
|
||||
$segment = "$pchar*";
|
||||
$path_abempty = "(?:/$segment)*";
|
||||
$hier_part = "/{2}$authority$path_abempty";
|
||||
$query = "(?:[$unreserved$sub_delims:@/?|]+|$pct_encoded)*"; // pchar | "/" | "?", rfc: no "|"
|
||||
$fragment = $query;
|
||||
|
||||
$url = "$scheme:$hier_part(?:\?$query)?(?:\#$fragment)?";
|
||||
echo 'URL: ' . $url . "<br />\n";
|
||||
|
||||
// no scheme, shortened authority, but host has to start with www.
|
||||
$www_url = "www\.$reg_name(?::$port)?$path_abempty(?:\?$query)?(?:\#$fragment)?";
|
||||
echo 'www.URL: ' . $www_url . "<br />\n";
|
||||
|
||||
// no schema and no authority
|
||||
$relative_url = "$segment$path_abempty(?:\?$query)?(?:\#$fragment)?";
|
||||
echo 'relative URL: ' . $relative_url . "<br />\n";
|
||||
|
||||
?>
|
@@ -1,149 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Rebuild BOTS
|
||||
*
|
||||
* You should make a backup from your whole database. Things can and will go wrong.
|
||||
* This will only work if no BOTs were added.
|
||||
*
|
||||
*/
|
||||
die("Please read the first lines of this script for instructions on how to enable it");
|
||||
|
||||
set_time_limit(0);
|
||||
|
||||
define('IN_PHPBB', true);
|
||||
define('PHPBB_ROOT_PATH', './../');
|
||||
define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
|
||||
include(PHPBB_ROOT_PATH . 'common.' . PHP_EXT);
|
||||
include(PHPBB_ROOT_PATH . 'includes/functions_user.' . PHP_EXT);
|
||||
|
||||
|
||||
// Start session management
|
||||
phpbb::$user->session_begin();
|
||||
phpbb::$acl->init(phpbb::$user->data);
|
||||
phpbb::$user->setup();
|
||||
|
||||
$bots = array(
|
||||
'AdsBot [Google]' => array('AdsBot-Google', ''),
|
||||
'Alexa [Bot]' => array('ia_archiver', ''),
|
||||
'Alta Vista [Bot]' => array('Scooter/', ''),
|
||||
'Ask Jeeves [Bot]' => array('Ask Jeeves', ''),
|
||||
'Baidu [Spider]' => array('Baiduspider+(', ''),
|
||||
'Exabot [Bot]' => array('Exabot/', ''),
|
||||
'FAST Enterprise [Crawler]' => array('FAST Enterprise Crawler', ''),
|
||||
'FAST WebCrawler [Crawler]' => array('FAST-WebCrawler/', ''),
|
||||
'Francis [Bot]' => array('http://www.neomo.de/', ''),
|
||||
'Gigabot [Bot]' => array('Gigabot/', ''),
|
||||
'Google Adsense [Bot]' => array('Mediapartners-Google', ''),
|
||||
'Google Desktop' => array('Google Desktop', ''),
|
||||
'Google Feedfetcher' => array('Feedfetcher-Google', ''),
|
||||
'Google [Bot]' => array('Googlebot', ''),
|
||||
'Heise IT-Markt [Crawler]' => array('heise-IT-Markt-Crawler', ''),
|
||||
'Heritrix [Crawler]' => array('heritrix/1.', ''),
|
||||
'IBM Research [Bot]' => array('ibm.com/cs/crawler', ''),
|
||||
'ICCrawler - ICjobs' => array('ICCrawler - ICjobs', ''),
|
||||
'ichiro [Crawler]' => array('ichiro/2', ''),
|
||||
'Majestic-12 [Bot]' => array('MJ12bot/', ''),
|
||||
'Metager [Bot]' => array('MetagerBot/', ''),
|
||||
'MSN NewsBlogs' => array('msnbot-NewsBlogs/', ''),
|
||||
'MSN [Bot]' => array('msnbot/', ''),
|
||||
'MSNbot Media' => array('msnbot-media/', ''),
|
||||
'NG-Search [Bot]' => array('NG-Search/', ''),
|
||||
'Nutch [Bot]' => array('http://lucene.apache.org/nutch/', ''),
|
||||
'Nutch/CVS [Bot]' => array('NutchCVS/', ''),
|
||||
'OmniExplorer [Bot]' => array('OmniExplorer_Bot/', ''),
|
||||
'Online link [Validator]' => array('online link validator', ''),
|
||||
'psbot [Picsearch]' => array('psbot/0', ''),
|
||||
'Seekport [Bot]' => array('Seekbot/', ''),
|
||||
'Sensis [Crawler]' => array('Sensis Web Crawler', ''),
|
||||
'SEO Crawler' => array('SEO search Crawler/', ''),
|
||||
'Seoma [Crawler]' => array('Seoma [SEO Crawler]', ''),
|
||||
'SEOSearch [Crawler]' => array('SEOsearch/', ''),
|
||||
'Snappy [Bot]' => array('Snappy/1.1 ( http://www.urltrends.com/ )', ''),
|
||||
'Steeler [Crawler]' => array('http://www.tkl.iis.u-tokyo.ac.jp/~crawler/', ''),
|
||||
'Synoo [Bot]' => array('SynooBot/', ''),
|
||||
'Telekom [Bot]' => array('crawleradmin.t-info@telekom.de', ''),
|
||||
'TurnitinBot [Bot]' => array('TurnitinBot/', ''),
|
||||
'Voyager [Bot]' => array('voyager/1.0', ''),
|
||||
'W3 [Sitesearch]' => array('W3 SiteSearch Crawler', ''),
|
||||
'W3C [Linkcheck]' => array('W3C-checklink/', ''),
|
||||
'W3C [Validator]' => array('W3C_*Validator', ''),
|
||||
'WiseNut [Bot]' => array('http://www.WISEnutbot.com', ''),
|
||||
'YaCy [Bot]' => array('yacybot', ''),
|
||||
'Yahoo MMCrawler [Bot]' => array('Yahoo-MMCrawler/', ''),
|
||||
'Yahoo Slurp [Bot]' => array('Yahoo! DE Slurp', ''),
|
||||
'Yahoo [Bot]' => array('Yahoo! Slurp', ''),
|
||||
'YahooSeeker [Bot]' => array('YahooSeeker/', ''),
|
||||
);
|
||||
|
||||
$bot_ids = array();
|
||||
user_get_id_name($bot_ids, array_keys($bots), phpbb::USER_IGNORE);
|
||||
foreach($bot_ids as $bot)
|
||||
{
|
||||
user_delete('remove', $bot);
|
||||
}
|
||||
// Done
|
||||
add_bots($bots);
|
||||
echo 'done';
|
||||
|
||||
|
||||
/**
|
||||
* Add the search bots into the database
|
||||
* This code should be used in execute_last if the source database did not have bots
|
||||
* If you are converting bots this function should not be called
|
||||
* @todo We might want to look at sharing the bot list between the install code and this code for consistency
|
||||
*/
|
||||
function add_bots($bots)
|
||||
{
|
||||
$sql = 'SELECT group_id FROM ' . GROUPS_TABLE . " WHERE group_name = 'BOTS'";
|
||||
$result = phpbb::$db->sql_query($sql);
|
||||
$group_id = (int) phpbb::$db->sql_fetchfield('group_id', $result);
|
||||
phpbb::$db->sql_freeresult($result);
|
||||
phpbb::$db->sql_query('TRUNCATE TABLE ' . BOTS_TABLE);
|
||||
|
||||
if (!$group_id)
|
||||
{
|
||||
add_default_groups();
|
||||
|
||||
$sql = 'SELECT group_id FROM ' . GROUPS_TABLE . " WHERE group_name = 'BOTS'";
|
||||
$result = phpbb::$db->sql_query($sql);
|
||||
$group_id = (int) phpbb::$db->sql_fetchfield('group_id', $result);
|
||||
phpbb::$db->sql_freeresult($result);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
foreach ($bots as $bot_name => $bot_ary)
|
||||
{
|
||||
$user_row = array(
|
||||
'user_type' => phpbb::USER_IGNORE,
|
||||
'group_id' => $group_id,
|
||||
'username' => $bot_name,
|
||||
'user_regdate' => time(),
|
||||
'user_password' => '',
|
||||
'user_colour' => '9E8DA7',
|
||||
'user_email' => '',
|
||||
'user_lang' => phpbb::$config['default_lang'],
|
||||
'user_style' => 1,
|
||||
'user_timezone' => 0,
|
||||
'user_allow_massemail' => 0,
|
||||
);
|
||||
|
||||
$user_id = user_add($user_row);
|
||||
|
||||
if ($user_id)
|
||||
{
|
||||
$sql = 'INSERT INTO ' . BOTS_TABLE . ' ' . phpbb::$db->sql_build_array('INSERT', array(
|
||||
'bot_active' => 1,
|
||||
'bot_name' => $bot_name,
|
||||
'user_id' => $user_id,
|
||||
'bot_agent' => $bot_ary[0],
|
||||
'bot_ip' => $bot_ary[1])
|
||||
);
|
||||
phpbb::$db->sql_query($sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@@ -1,129 +0,0 @@
|
||||
<?php
|
||||
|
||||
//
|
||||
// Security message:
|
||||
//
|
||||
// This script is potentially dangerous.
|
||||
// Remove or comment the next line (die(".... ) to enable this script.
|
||||
// Do NOT FORGET to either remove this script or disable it after you have used it.
|
||||
//
|
||||
|
||||
//
|
||||
// Security message:
|
||||
//
|
||||
// This script is potentially dangerous.
|
||||
// Remove or comment the next line (die(".... ) to enable this script.
|
||||
// Do NOT FORGET to either remove this script or disable it after you have used it.
|
||||
//
|
||||
die("Please read the first lines of this script for instructions on how to enable it");
|
||||
|
||||
//
|
||||
// Do not change anything below this line.
|
||||
//
|
||||
set_time_limit(0);
|
||||
|
||||
define('IN_PHPBB', true);
|
||||
define('PHPBB_ROOT_PATH', './../');
|
||||
define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
|
||||
include(PHPBB_ROOT_PATH . 'common.' . PHP_EXT);
|
||||
|
||||
// Start session management
|
||||
phpbb::$user->session_begin();
|
||||
phpbb::$acl->init(phpbb::$user->data);
|
||||
phpbb::$user->setup();
|
||||
|
||||
$search_type = phpbb::$config['search_type'];
|
||||
|
||||
if (!file_exists(PHPBB_ROOT_PATH . 'includes/search/' . $search_type . '.' . PHP_EXT))
|
||||
{
|
||||
trigger_error('NO_SUCH_SEARCH_MODULE');
|
||||
}
|
||||
|
||||
require(PHPBB_ROOT_PATH . 'includes/search/' . $search_type . '.' . PHP_EXT);
|
||||
|
||||
$error = false;
|
||||
$search = new $search_type($error);
|
||||
|
||||
if ($error)
|
||||
{
|
||||
trigger_error($error);
|
||||
}
|
||||
|
||||
print "<html>\n<body>\n";
|
||||
|
||||
//
|
||||
// Fetch a batch of posts_text entries
|
||||
//
|
||||
$sql = "SELECT COUNT(*) as total, MAX(post_id) as max_post_id
|
||||
FROM ". POSTS_TABLE;
|
||||
if ( !($result = phpbb::$db->sql_query($sql)) )
|
||||
{
|
||||
$error = phpbb::$db->sql_error();
|
||||
die("Couldn't get maximum post ID :: " . $sql . " :: " . $error['message']);
|
||||
}
|
||||
|
||||
$max_post_id = phpbb::$db->sql_fetchrow($result);
|
||||
|
||||
$totalposts = $max_post_id['total'];
|
||||
$max_post_id = $max_post_id['max_post_id'];
|
||||
|
||||
$postcounter = (!isset($HTTP_GET_VARS['batchstart'])) ? 0 : $HTTP_GET_VARS['batchstart'];
|
||||
|
||||
$batchsize = 200; // Process this many posts per loop
|
||||
$batchcount = 0;
|
||||
for(;$postcounter <= $max_post_id; $postcounter += $batchsize)
|
||||
{
|
||||
$batchstart = $postcounter + 1;
|
||||
$batchend = $postcounter + $batchsize;
|
||||
$batchcount++;
|
||||
|
||||
$sql = "SELECT *
|
||||
FROM " . POSTS_TABLE . "
|
||||
WHERE post_id
|
||||
BETWEEN $batchstart
|
||||
AND $batchend";
|
||||
if( !($result = phpbb::$db->sql_query($sql)) )
|
||||
{
|
||||
$error = phpbb::$db->sql_error();
|
||||
die("Couldn't get post_text :: " . $sql . " :: " . $error['message']);
|
||||
}
|
||||
|
||||
$rowset = phpbb::$db->sql_fetchrowset($result);
|
||||
phpbb::$db->sql_freeresult($result);
|
||||
|
||||
$post_rows = sizeof($rowset);
|
||||
|
||||
if( $post_rows )
|
||||
{
|
||||
|
||||
// $sql = "LOCK TABLES ".POST_TEXT_TABLE." WRITE";
|
||||
// $result = phpbb::$db->sql_query($sql);
|
||||
print "\n<p>\n<a href='{$_SERVER['PHP_SELF']}?batchstart=$batchstart'>Restart from posting $batchstart</a><br>\n";
|
||||
|
||||
// For every post in the batch:
|
||||
for($post_nr = 0; $post_nr < $post_rows; $post_nr++ )
|
||||
{
|
||||
print ".";
|
||||
flush();
|
||||
|
||||
$post_id = $rowset[$post_nr]['post_id'];
|
||||
|
||||
$search->index('post', $rowset[$post_nr]['post_id'], $rowset[$post_nr]['post_text'], $rowset[$post_nr]['post_subject'], $rowset[$post_nr]['poster_id']);
|
||||
}
|
||||
// $sql = "UNLOCK TABLES";
|
||||
// $result = phpbb::$db->sql_query($sql);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
print "<br>Removing common words (words that appear in more than 50% of the posts)<br>\n";
|
||||
flush();
|
||||
$search->tidy();
|
||||
print "Removed words that where too common.<br>";
|
||||
|
||||
echo "<br>Done";
|
||||
|
||||
?>
|
||||
|
||||
</body>
|
||||
</html>
|
@@ -1,119 +0,0 @@
|
||||
<?php
|
||||
//
|
||||
// This file provides some useful functions for debugging the unicode/UTF-8 library
|
||||
// It requires utf_tools.php to be loaded
|
||||
//
|
||||
die("Please read the first lines of this script for instructions on how to enable it");
|
||||
|
||||
if (!headers_sent())
|
||||
{
|
||||
header('Content-type: text/html; charset=UTF-8');
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts unicode escape sequences (\u0123) into UTF-8 characters
|
||||
*
|
||||
* @param string A unicode sequence
|
||||
* @return string UTF-8 representation of the given unicode sequence
|
||||
*/
|
||||
function unicode_to_utf8($string)
|
||||
{
|
||||
$utf8 = '';
|
||||
$chars = array();
|
||||
for ($i = 0; $i < strlen($string); $i++)
|
||||
{
|
||||
if (isset($string[$i + 5]) && substr($string, $i, 2) == '\\u' && ctype_xdigit(substr($string, $i + 2, 4)))
|
||||
{
|
||||
$utf8 .= utf8_from_unicode(array(base_convert(substr($string, $i + 2, 4), 16, 10)));
|
||||
$i += 5;
|
||||
}
|
||||
else
|
||||
{
|
||||
$utf8 .= $string[$i];
|
||||
}
|
||||
}
|
||||
return $utf8;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes an array of ints representing the Unicode characters and returns
|
||||
* a UTF-8 string.
|
||||
*
|
||||
* @param array $array array of unicode code points representing a string
|
||||
* @return string UTF-8 character string
|
||||
*/
|
||||
function utf8_from_unicode($array)
|
||||
{
|
||||
$str = '';
|
||||
foreach ($array as $value)
|
||||
{
|
||||
$str .= utf8_chr($value);
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a UTF-8 string to unicode code points
|
||||
*
|
||||
* @param string $text UTF-8 string
|
||||
* @return string Unicode code points
|
||||
*/
|
||||
function utf8_to_unicode($text)
|
||||
{
|
||||
return preg_replace_callback(
|
||||
'#[\\xC2-\\xF4][\\x80-\\xBF]?[\\x80-\\xBF]?[\\x80-\\xBF]#',
|
||||
'utf8_to_unicode_callback',
|
||||
preg_replace_callback(
|
||||
'#[\\x00-\\x7f]#',
|
||||
'utf8_to_unicode_callback',
|
||||
$text
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a UTF-8 char and replaces it with its unicode escape sequence. Attention, $m is an array
|
||||
*
|
||||
* @param array $m 0-based numerically indexed array passed by preg_replace_callback()
|
||||
* @return string A unicode escape sequence
|
||||
*/
|
||||
function utf8_to_unicode_callback($m)
|
||||
{
|
||||
return '\u' . str_pad(base_convert(utf8_ord($m[0]), 10, 16), 4, '0', STR_PAD_LEFT) . '';
|
||||
}
|
||||
|
||||
/**
|
||||
* A wrapper function for the normalizer which takes care of including the class if required and modifies the passed strings
|
||||
* to be in NFKC
|
||||
*
|
||||
* @param mixed $strings a string or an array of strings to normalize
|
||||
* @return mixed the normalized content, preserving array keys if array given.
|
||||
*/
|
||||
function utf8_normalize_nfkc($strings)
|
||||
{
|
||||
if (empty($strings))
|
||||
{
|
||||
return $strings;
|
||||
}
|
||||
|
||||
if (!class_exists('utf_normalizer'))
|
||||
{
|
||||
include(PHPBB_ROOT_PATH . 'includes/utf/utf_normalizer.' . PHP_EXT);
|
||||
}
|
||||
|
||||
if (!is_array($strings))
|
||||
{
|
||||
utf_normalizer::nfkc($strings);
|
||||
}
|
||||
else if (is_array($strings))
|
||||
{
|
||||
foreach ($strings as $key => $string)
|
||||
{
|
||||
utf_normalizer::nfkc($strings[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
return $strings;
|
||||
}
|
||||
|
||||
?>
|
@@ -1,389 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package phpBB3
|
||||
* @version $Id$
|
||||
* @copyright (c) 2005 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||
*
|
||||
*/
|
||||
|
||||
if (php_sapi_name() != 'cli')
|
||||
{
|
||||
die("This program must be run from the command line.\n");
|
||||
}
|
||||
|
||||
//
|
||||
// Security message:
|
||||
//
|
||||
// This script is potentially dangerous.
|
||||
// Remove or comment the next line (die(".... ) to enable this script.
|
||||
// Do NOT FORGET to either remove this script or disable it after you have used it.
|
||||
//
|
||||
die("Please read the first lines of this script for instructions on how to enable it");
|
||||
|
||||
set_time_limit(0);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
define('IN_PHPBB', true);
|
||||
define('PHPBB_ROOT_PATH', './../');
|
||||
define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
|
||||
|
||||
|
||||
/**
|
||||
* Let's download some files we need
|
||||
*/
|
||||
download('http://www.unicode.org/Public/UNIDATA/NormalizationTest.txt');
|
||||
download('http://www.unicode.org/Public/UNIDATA/UnicodeData.txt');
|
||||
|
||||
/**
|
||||
* Those are the tests we run
|
||||
*/
|
||||
$test_suite = array(
|
||||
/**
|
||||
* NFC
|
||||
* c2 == NFC(c1) == NFC(c2) == NFC(c3)
|
||||
* c4 == NFC(c4) == NFC(c5)
|
||||
*/
|
||||
'NFC' => array(
|
||||
'c2' => array('c1', 'c2', 'c3'),
|
||||
'c4' => array('c4', 'c5')
|
||||
),
|
||||
|
||||
/**
|
||||
* NFD
|
||||
* c3 == NFD(c1) == NFD(c2) == NFD(c3)
|
||||
* c5 == NFD(c4) == NFD(c5)
|
||||
*/
|
||||
'NFD' => array(
|
||||
'c3' => array('c1', 'c2', 'c3'),
|
||||
'c5' => array('c4', 'c5')
|
||||
),
|
||||
|
||||
/**
|
||||
* NFKC
|
||||
* c4 == NFKC(c1) == NFKC(c2) == NFKC(c3) == NFKC(c4) == NFKC(c5)
|
||||
*/
|
||||
'NFKC' => array(
|
||||
'c4' => array('c1', 'c2', 'c3', 'c4', 'c5')
|
||||
),
|
||||
|
||||
/**
|
||||
* NFKD
|
||||
* c5 == NFKD(c1) == NFKD(c2) == NFKD(c3) == NFKD(c4) == NFKD(c5)
|
||||
*/
|
||||
'NFKD' => array(
|
||||
'c5' => array('c1', 'c2', 'c3', 'c4', 'c5')
|
||||
)
|
||||
);
|
||||
|
||||
require_once(PHPBB_ROOT_PATH . 'includes/utf/utf_normalizer.' . PHP_EXT);
|
||||
|
||||
$i = $n = 0;
|
||||
$failed = false;
|
||||
$tested_chars = array();
|
||||
|
||||
$fp = fopen(PHPBB_ROOT_PATH . 'develop/NormalizationTest.txt', 'rb');
|
||||
while (!feof($fp))
|
||||
{
|
||||
$line = fgets($fp);
|
||||
++$n;
|
||||
|
||||
if ($line[0] == '@')
|
||||
{
|
||||
if ($i)
|
||||
{
|
||||
echo "done\n";
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
echo "\n", substr($line, 1), "\n\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!strpos(' 0123456789ABCDEF', $line[0]))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (++$i % 100 == 0)
|
||||
{
|
||||
echo $i, ' ';
|
||||
}
|
||||
|
||||
list($c1, $c2, $c3, $c4, $c5) = explode(';', $line);
|
||||
|
||||
if (!strpos($c1, ' '))
|
||||
{
|
||||
/**
|
||||
* We are currently testing a single character, we add it to the list of
|
||||
* characters we have processed so that we can exclude it when testing
|
||||
* for invariants
|
||||
*/
|
||||
$tested_chars[$c1] = 1;
|
||||
}
|
||||
|
||||
foreach ($test_suite as $form => $serie)
|
||||
{
|
||||
foreach ($serie as $expected => $tests)
|
||||
{
|
||||
$hex_expected = ${$expected};
|
||||
$utf_expected = hexseq_to_utf($hex_expected);
|
||||
|
||||
foreach ($tests as $test)
|
||||
{
|
||||
$utf_result = $utf_expected;
|
||||
call_user_func(array('utf_normalizer', $form), $utf_result);
|
||||
|
||||
if (strcmp($utf_expected, $utf_result))
|
||||
{
|
||||
$failed = true;
|
||||
$hex_result = utf_to_hexseq($utf_result);
|
||||
|
||||
echo "\nFAILED $expected == $form($test) ($hex_expected != $hex_result)";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($failed)
|
||||
{
|
||||
die("\n\nFailed at line $n\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose($fp);
|
||||
|
||||
/**
|
||||
* Test for invariants
|
||||
*/
|
||||
echo "\n\nTesting for invariants...\n\n";
|
||||
|
||||
$fp = fopen(PHPBB_ROOT_PATH . 'develop/UnicodeData.txt', 'rt');
|
||||
|
||||
$n = 0;
|
||||
while (!feof($fp))
|
||||
{
|
||||
if (++$n % 100 == 0)
|
||||
{
|
||||
echo $n, ' ';
|
||||
}
|
||||
|
||||
$line = fgets($fp, 1024);
|
||||
|
||||
if (!$pos = strpos($line, ';'))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$hex_tested = $hex_expected = substr($line, 0, $pos);
|
||||
|
||||
if (isset($tested_chars[$hex_tested]))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$utf_expected = hex_to_utf($hex_expected);
|
||||
|
||||
if ($utf_expected >= utf_normalizer::UTF8_SURROGATE_FIRST
|
||||
&& $utf_expected <= utf_normalizer::UTF8_SURROGATE_LAST)
|
||||
{
|
||||
/**
|
||||
* Surrogates are illegal on their own, we expect the normalizer
|
||||
* to return a replacement char
|
||||
*/
|
||||
$utf_expected = utf_normalizer::UTF8_REPLACEMENT;
|
||||
$hex_expected = utf_to_hexseq($utf_expected);
|
||||
}
|
||||
|
||||
foreach (array('nfc', 'nfkc', 'nfd', 'nfkd') as $form)
|
||||
{
|
||||
$utf_result = $utf_expected;
|
||||
call_user_func(array('utf_normalizer', $form), $utf_result);
|
||||
$hex_result = utf_to_hexseq($utf_result);
|
||||
// echo "$form($utf_expected) == $utf_result\n";
|
||||
|
||||
if (strcmp($utf_expected, $utf_result))
|
||||
{
|
||||
$failed = 1;
|
||||
|
||||
echo "\nFAILED $hex_expected == $form($hex_tested) ($hex_expected != $hex_result)";
|
||||
}
|
||||
}
|
||||
|
||||
if ($failed)
|
||||
{
|
||||
die("\n\nFailed at line $n\n");
|
||||
}
|
||||
}
|
||||
fclose($fp);
|
||||
|
||||
die("\n\nALL TESTS PASSED SUCCESSFULLY\n");
|
||||
|
||||
/**
|
||||
* Download a file to the develop/ dir
|
||||
*
|
||||
* @param string $url URL of the file to download
|
||||
* @return void
|
||||
*/
|
||||
function download($url)
|
||||
{
|
||||
if (file_exists(PHPBB_ROOT_PATH . 'develop/' . basename($url)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
echo 'Downloading from ', $url, ' ';
|
||||
|
||||
if (!$fpr = fopen($url, 'rb'))
|
||||
{
|
||||
die("Can't download from $url\nPlease download it yourself and put it in the develop/ dir, kthxbai");
|
||||
}
|
||||
|
||||
if (!$fpw = fopen(PHPBB_ROOT_PATH . 'develop/' . basename($url), 'wb'))
|
||||
{
|
||||
die("Can't open develop/" . basename($url) . " for output... please check your permissions or something");
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
$chunk = 32768;
|
||||
$done = '';
|
||||
|
||||
while (!feof($fpr))
|
||||
{
|
||||
$i += fwrite($fpw, fread($fpr, $chunk));
|
||||
echo str_repeat("\x08", strlen($done));
|
||||
|
||||
$done = ($i >> 10) . ' KiB';
|
||||
echo $done;
|
||||
}
|
||||
fclose($fpr);
|
||||
fclose($fpw);
|
||||
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a UTF string to a sequence of codepoints in hexadecimal
|
||||
*
|
||||
* @param string $utf UTF string
|
||||
* @return integer Unicode codepoints in hex
|
||||
*/
|
||||
function utf_to_hexseq($str)
|
||||
{
|
||||
$pos = 0;
|
||||
$len = strlen($str);
|
||||
$ret = array();
|
||||
|
||||
while ($pos < $len)
|
||||
{
|
||||
$c = $str[$pos];
|
||||
switch ($c & "\xF0")
|
||||
{
|
||||
case "\xC0":
|
||||
case "\xD0":
|
||||
$utf_char = substr($str, $pos, 2);
|
||||
$pos += 2;
|
||||
break;
|
||||
|
||||
case "\xE0":
|
||||
$utf_char = substr($str, $pos, 3);
|
||||
$pos += 3;
|
||||
break;
|
||||
|
||||
case "\xF0":
|
||||
$utf_char = substr($str, $pos, 4);
|
||||
$pos += 4;
|
||||
break;
|
||||
|
||||
default:
|
||||
$utf_char = $c;
|
||||
++$pos;
|
||||
}
|
||||
|
||||
$hex = dechex(utf_to_cp($utf_char));
|
||||
|
||||
if (!isset($hex[3]))
|
||||
{
|
||||
$hex = substr('000' . $hex, -4);
|
||||
}
|
||||
|
||||
$ret[] = $hex;
|
||||
}
|
||||
|
||||
return strtr(implode(' ', $ret), 'abcdef', 'ABCDEF');
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a UTF-8 char to its codepoint
|
||||
*
|
||||
* @param string $utf_char UTF-8 char
|
||||
* @return integer Unicode codepoint
|
||||
*/
|
||||
function utf_to_cp($utf_char)
|
||||
{
|
||||
switch (strlen($utf_char))
|
||||
{
|
||||
case 1:
|
||||
return ord($utf_char);
|
||||
|
||||
case 2:
|
||||
return ((ord($utf_char[0]) & 0x1F) << 6) | (ord($utf_char[1]) & 0x3F);
|
||||
|
||||
case 3:
|
||||
return ((ord($utf_char[0]) & 0x0F) << 12) | ((ord($utf_char[1]) & 0x3F) << 6) | (ord($utf_char[2]) & 0x3F);
|
||||
|
||||
case 4:
|
||||
return ((ord($utf_char[0]) & 0x07) << 18) | ((ord($utf_char[1]) & 0x3F) << 12) | ((ord($utf_char[2]) & 0x3F) << 6) | (ord($utf_char[3]) & 0x3F);
|
||||
|
||||
default:
|
||||
die('UTF-8 chars can only be 1-4 bytes long');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a UTF string formed from a sequence of codepoints in hexadecimal
|
||||
*
|
||||
* @param string $seq Sequence of codepoints, separated with a space
|
||||
* @return string UTF-8 string
|
||||
*/
|
||||
function hexseq_to_utf($seq)
|
||||
{
|
||||
return implode('', array_map('hex_to_utf', explode(' ', $seq)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a codepoint in hexadecimal to a UTF-8 char
|
||||
*
|
||||
* @param string $hex Codepoint, in hexadecimal
|
||||
* @return string UTF-8 char
|
||||
*/
|
||||
function hex_to_utf($hex)
|
||||
{
|
||||
return cp_to_utf(hexdec($hex));
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a codepoint to a UTF-8 char
|
||||
*
|
||||
* @param integer $cp Unicode codepoint
|
||||
* @return string UTF-8 string
|
||||
*/
|
||||
function cp_to_utf($cp)
|
||||
{
|
||||
if ($cp > 0xFFFF)
|
||||
{
|
||||
return chr(0xF0 | ($cp >> 18)) . chr(0x80 | (($cp >> 12) & 0x3F)) . chr(0x80 | (($cp >> 6) & 0x3F)) . chr(0x80 | ($cp & 0x3F));
|
||||
}
|
||||
else if ($cp > 0x7FF)
|
||||
{
|
||||
return chr(0xE0 | ($cp >> 12)) . chr(0x80 | (($cp >> 6) & 0x3F)) . chr(0x80 | ($cp & 0x3F));
|
||||
}
|
||||
else if ($cp > 0x7F)
|
||||
{
|
||||
return chr(0xC0 | ($cp >> 6)) . chr(0x80 | ($cp & 0x3F));
|
||||
}
|
||||
else
|
||||
{
|
||||
return chr($cp);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user