|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
use Xmf\Database\Tables; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Upgrade from 2.5.8 to 2.5.9 |
|
7
|
|
|
* |
|
8
|
|
|
* See the enclosed file license.txt for licensing information. |
|
9
|
|
|
* If you did not receive this file, get it at http://www.gnu.org/licenses/gpl-2.0.html |
|
10
|
|
|
* |
|
11
|
|
|
* @copyright (c) 2000-2016 XOOPS Project (www.xoops.org) |
|
12
|
|
|
* @license GNU GPL 2 (http://www.gnu.org/licenses/gpl-2.0.html) |
|
13
|
|
|
* @package Upgrade |
|
14
|
|
|
* @since 2.5.9 |
|
15
|
|
|
* @author XOOPS Team |
|
16
|
|
|
*/ |
|
17
|
|
|
class Upgrade_2510 extends XoopsUpgrade |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* __construct |
|
21
|
|
|
*/ |
|
22
|
|
|
public function __construct() |
|
23
|
|
|
{ |
|
24
|
|
|
parent::__construct(basename(__DIR__)); |
|
25
|
|
|
$this->tasks = array('metarobots', 'protectordata'); |
|
26
|
|
|
$this->usedFiles = array(); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Make meta_robots a textbox instead of a select |
|
31
|
|
|
* |
|
32
|
|
|
* @return bool |
|
33
|
|
|
*/ |
|
34
|
|
|
public function check_metarobots() |
|
35
|
|
|
{ |
|
36
|
|
|
/* @var $db XoopsMySQLDatabase */ |
|
37
|
|
|
$db = XoopsDatabaseFactory::getDatabaseConnection(); |
|
38
|
|
|
|
|
39
|
|
|
$table = $db->prefix('config'); |
|
40
|
|
|
|
|
41
|
|
|
$sql = sprintf( |
|
42
|
|
|
'SELECT count(*) FROM `%s` ' |
|
43
|
|
|
. "WHERE `conf_formtype` = 'select' AND `conf_name` = 'meta_robots' AND `conf_modid` = 0", |
|
44
|
|
|
$db->escape($table) |
|
45
|
|
|
); |
|
46
|
|
|
|
|
47
|
|
|
/** @var mysqli_result $result */ |
|
48
|
|
|
$result = $db->query($sql); |
|
|
|
|
|
|
49
|
|
|
if ($result) { |
|
50
|
|
|
$row = $db->fetchRow($result); |
|
51
|
|
|
if ($row) { |
|
52
|
|
|
$count = $row[0]; |
|
53
|
|
|
return (0 === (int) $count) ? true : false; |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
return false; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Make meta_robots a textbox instead of a select |
|
61
|
|
|
* |
|
62
|
|
|
* This will allow webmasters to utilize current robots meta tag standards |
|
63
|
|
|
* @link https://developers.google.com/search/reference/robots_meta_tag |
|
64
|
|
|
* |
|
65
|
|
|
* @return bool |
|
66
|
|
|
*/ |
|
67
|
|
|
public function apply_metarobots() |
|
68
|
|
|
{ |
|
69
|
|
|
// UPDATE `x569_config` SET `conf_formtype` = 'textbox' WHERE `conf_name` = 'meta_robots' and `conf_modid` = 0 |
|
70
|
|
|
|
|
71
|
|
|
$migrate = new Tables(); |
|
72
|
|
|
$migrate->useTable('config'); |
|
73
|
|
|
$migrate->update('config', array('conf_formtype' => 'textbox'), "WHERE `conf_name` = 'meta_robots' AND `conf_modid` = 0"); |
|
74
|
|
|
return $migrate->executeQueue(true); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Do we need to move protector writable data? |
|
79
|
|
|
* |
|
80
|
|
|
* @return bool |
|
81
|
|
|
*/ |
|
82
|
|
|
public function check_protectordata() |
|
83
|
|
|
{ |
|
84
|
|
|
$destinationPath = XOOPS_VAR_PATH . '/protector/'; |
|
85
|
|
|
return file_exists($destinationPath); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Move protector configs to xoops_data to segregate writable data for containerization |
|
90
|
|
|
* |
|
91
|
|
|
* @return bool |
|
92
|
|
|
*/ |
|
93
|
|
|
public function apply_protectordata() |
|
94
|
|
|
{ |
|
95
|
|
|
$returnResult = false; |
|
96
|
|
|
$sourcePath = XOOPS_PATH . '/modules/protector/configs/'; |
|
97
|
|
|
$destinationPath = XOOPS_VAR_PATH . '/protector/'; |
|
98
|
|
|
|
|
99
|
|
|
if (!file_exists($destinationPath)) { |
|
100
|
|
|
mkdir($destinationPath); |
|
101
|
|
|
} |
|
102
|
|
|
$directory = dir($sourcePath); |
|
103
|
|
|
if (false !== $directory) { |
|
104
|
|
|
$returnResult = true; |
|
105
|
|
|
while (false !== ($entry = $directory->read())) { |
|
106
|
|
|
if ('.' !== $entry && '..' !== $entry) { |
|
107
|
|
|
$src = $sourcePath . $entry; |
|
108
|
|
|
$dest = $destinationPath . $entry; |
|
109
|
|
|
$result = copy($src, $dest); |
|
110
|
|
|
if (false === $result) { |
|
111
|
|
|
$returnResult = false; |
|
112
|
|
|
$this->logs[] = sprintf('Protector file copy %s failed', $entry); |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
$directory->close(); |
|
117
|
|
|
} |
|
118
|
|
|
return $returnResult; |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
$upg = new Upgrade_2510(); |
|
123
|
|
|
return $upg; |
|
124
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.