PluginProbe ʕ •ᴥ•ʔ
JetBackup – Backup, Restore & Migrate / 1.6.9
JetBackup – Backup, Restore & Migrate v1.6.9
3.1.22.3 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.8.1 1.4.9 1.5.0 1.5.1 1.5.1.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.10 1.6.11 1.6.12 1.6.13 1.6.15 1.6.5.1 1.6.8.8 1.6.9 1.6.9.1 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7.5 2.0.8.7 2.0.9.11 2.0.9.14 2.0.9.15 2.0.9.6 2.0.9.7 2.0.9.9 3.1.10.7 3.1.11.1 3.1.12.3 3.1.13.4 3.1.14.17 3.1.15.4 3.1.16.1 3.1.17.5 3.1.18.10 3.1.18.8 3.1.18.9 3.1.19.8 3.1.20.3 3.1.21.3 3.1.7.9 3.1.9.2 trunk 1.1.90 1.1.91 1.2.0 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2
backup / com / lib / SGCharsetHandler.php
backup / com / lib Last commit date
BackupGuard 5 years ago Dropbox 3 years ago Request 5 years ago SGArchive.php 4 years ago SGAuthClient.php 4 years ago SGCallback.php 5 years ago SGCdrEntry.php 9 years ago SGCharsetHandler.php 7 years ago SGDBState.php 8 years ago SGEntry.php 9 years ago SGFileEntry.php 5 years ago SGFileState.php 6 years ago SGMigrateState.php 8 years ago SGMysqldump.php 5 years ago SGReloadHandler.php 4 years ago SGReloader.php 5 years ago SGReloaderState.php 9 years ago SGReviewManager.php 6 years ago SGState.php 5 years ago SGStatsRequests.php 5 years ago SGUploadHandler.php 5 years ago SGUploadState.php 5 years ago
SGCharsetHandler.php
94 lines
1 <?php
2
3 class SGCharsetHandler
4 {
5 private $utf8mb4Available = false;
6 private $utf8mb4520Available = false;
7
8 public function __construct()
9 {
10 $this->utf8mb4Available = $this->mysqlHasCapability('utf8mb4');
11 $this->utf8mb4520Available = $this->mysqlHasCapability('utf8mb4_520');
12 }
13
14 public function replaceInvalidCharsets($query)
15 {
16 $search = array();
17 $replace = array();
18
19 //check for utf8mb4_520 support first
20 if (!$this->utf8mb4520Available) {
21 $search[] = 'COLLATE=utf8mb4_unicode_520_ci';
22 $replace[] = $this->utf8mb4Available?'COLLATE=utf8mb4_unicode_ci':'COLLATE=utf8_general_ci';
23
24 $search[] = 'COLLATE utf8mb4_unicode_520_ci';
25 $replace[] = $this->utf8mb4Available?'COLLATE utf8mb4_unicode_ci':'COLLATE utf8_general_ci';
26 }
27
28 //then check for utf8mb4 support
29 if (!$this->utf8mb4Available) {
30 $search[] = 'COLLATE=utf8mb4_unicode_ci';
31 $replace[] = 'COLLATE=utf8_general_ci';
32
33 $search[] = 'COLLATE utf8mb4_unicode_ci';
34 $replace[] = 'COLLATE utf8_general_ci';
35
36 $search[] = 'CHARACTER SET utf8mb4';
37 $replace[] = 'CHARACTER SET utf8';
38
39 $search[] = 'CHARSET=utf8mb4';
40 $replace[] = 'CHARSET=utf8';
41
42 $search[] = 'character_set_client = utf8mb4';
43 $replace[] = 'character_set_client = utf8';
44
45 $search[] = 'SET NAMES utf8mb4';
46 $replace[] = 'SET NAMES utf8';
47 }
48
49 if (count($search) && count($replace)) {
50 $query = str_replace($search, $replace, $query);
51 }
52
53 return $query;
54 }
55
56 public function getMysqlClientInfo()
57 {
58 if (function_exists('mysqli_connect')) {
59 if (version_compare(phpversion(), '5.5', '>=') || !function_exists('mysql_connect')) {
60 return @mysqli_get_client_info();
61 }
62 }
63
64 return SG_MYSQL_VERSION;
65 }
66
67 public function mysqlHasCapability($cap)
68 {
69 if ($cap == 'utf8mb4') {
70 if (version_compare(SG_MYSQL_VERSION, '5.5.3', '<')) {
71 return false;
72 }
73
74 $clientVersion = $this->getMysqlClientInfo();
75 /*
76 * libmysql has supported utf8mb4 since 5.5.3, same as the MySQL server.
77 * mysqlnd has supported utf8mb4 since 5.0.9.
78 */
79 if (false !== strpos($clientVersion, 'mysqlnd')) {
80 $clientVersion = preg_replace('/^\D+([\d.]+).*/', '$1', $clientVersion);
81 return version_compare($clientVersion, '5.0.9', '>=');
82 }
83 else {
84 return version_compare($clientVersion, '5.5.3', '>=');
85 }
86 }
87 else if ($cap == 'utf8mb4_520') {
88 return version_compare(SG_MYSQL_VERSION, '5.6', '>=');
89 }
90
91 return false;
92 }
93 }
94