forked from bakoontz/WikkaWiki
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconvertHTMLEntities.php
executable file
·108 lines (85 loc) · 3.59 KB
/
convertHTMLEntities.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
/*
Script: convertHTMLEntities.php
This script will convert HTML entities (values stored in the format
"〹") in your Wikka database to UTF-8 multibyte characters. This
conversion is necessary if you are upgrading from version 1.2-p1 or
earlier to version 1.3 or later and you have been using UTF-8
character encodings. If you have not been using HTML entities for
language characters, it is not necessary to run this script.
Before running this script:
***BACKUP YOUR DATABASE!***BACKUP YOUR DATABASE!***BACKUP YOUR DATABASE!***
We recommended this script be executed from the command line. If you
attempt to execute this script from within Wikka, the script may time
out for large databases.
Please note that your PHP version must be enabled with the mbstring
extension for this script to work. Details about this process can be
found here: http://www.php.net/manual/en/mbstring.installation.php
===> To run this script from the command line <===
Run this script from within your scripts directory/folder:
php.exe -f convertHTMLEntities.php (Windows)
php -f convertHTMLEntities.php (Unix/OSX)
Note that you might need to specify the directory from which to run
your php executable.
===> To run this script from within Wikka <===
Create an .htaccess file in your scripts directory with the following
line:
RewriteEngine Off
Point your browser to this script, specifying the scripts directory:
http://your.wikka.url/scripts/convertHTMLEntities.php
BE SURE TO DELETE THE .htaccess FILE AFTER RUNNING THE SCRIPT! If
you are not using mod_rewrite, you might also want to delete the
script as well, as it will not be needed for future upgrades.
*/
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<?php
// This script is deprecated for PHP versions 7 and greater!
if (!defined('PHP_VERSION_ID')) {
$version = explode('.', PHP_VERSION);
define('PHP_VERSION_ID', ($version[0] * 10000 + $version[1] * 100 + $version[2]));
}
if(PHP_VERSION_ID >= 70000) {
die("This script is deprecated for PHP versions 7 and greater!");
}
include_once('../wikka.config.php');
function replace_callback($matches)
{
$new = mb_convert_encoding($matches[1], 'UTF-8', 'HTML-ENTITIES');
return $new;
}
echo '<pre>', PHP_EOL;
$db = @mysql_connect($wakkaConfig['mysql_host'], $wakkaConfig['mysql_user'], $wakkaConfig['mysql_password'], true);
if(!@mysql_select_db($wakkaConfig['mysql_database'], $db))
die("select db");
mysql_query("SET NAMES 'utf8'", $db);
$sql = "SELECT id FROM ".$wakkaConfig['table_prefix']."pages where latest='Y'";
$result = @mysql_query($sql, $db);
while($row = @mysql_fetch_assoc($result))
{
$count = 0;
$sql = "SELECT tag, time, body, owner, user, latest, note FROM ".$wakkaConfig['table_prefix']."pages WHERE id=".$row['id'];
$result2 = mysql_fetch_assoc(@mysql_query($sql, $db));
$body = $result2['body'];
$body = preg_replace_callback('/(\&\#[0-9]+\;)/', 'replace_callback', $body, -1, $count);
if($count > 0)
{
echo "Converting ".$result2['tag']." to UTF-8...";
$note = "HTML entities converted to UTF-8";
$sql = "INSERT INTO ".$wakkaConfig['table_prefix']."pages (tag, time, body, owner, user, latest, note) VALUES ('".$result2['tag']."', now(), '".mysql_escape_string($body)."', '".$result2['owner']."', '".$result2['user']."', 'Y', '".$note."')";
mysql_query($sql, $db);
$sql = "UPDATE ".$wakkaConfig['table_prefix']."pages SET latest = 'N' WHERE id = ".$row['id'];
mysql_query($sql, $db);
echo "done!", PHP_EOL;
}
}
@mysql_close($db);
echo "Conversion complete.", PHP_EOL;
echo '</pre>', PHP_EOL;
?>
</body>
</html>