1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/* |
3
|
|
|
You may not change or alter any portion of this comment or credits of |
4
|
|
|
supporting developers from this source code or any supporting source code |
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit |
6
|
|
|
authors. |
7
|
|
|
|
8
|
|
|
This program is distributed in the hope that it will be useful, but |
9
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of |
10
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
11
|
|
|
*/ |
12
|
|
|
/** |
13
|
|
|
* Module: RandomQuote |
14
|
|
|
* |
15
|
|
|
* @category Module |
16
|
|
|
* @package randomquote |
17
|
|
|
* @author XOOPS Module Development Team |
18
|
|
|
* @author Mamba |
19
|
|
|
* @author Herve Thouzard |
20
|
|
|
* @copyright {@link http://xoops.org 2001-2016 XOOPS Project} |
21
|
|
|
* @coypright Herve Thouzard |
22
|
|
|
* @license {@link http://www.fsf.org/copyleft/gpl.html GNU public license} |
23
|
|
|
* @link http://xoops.org XOOPS |
24
|
|
|
* @since 2.00 |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
if ((!defined('XOOPS_ROOT_PATH')) |
28
|
|
|
|| !($GLOBALS['xoopsUser'] instanceof XoopsUser) |
|
|
|
|
29
|
|
|
|| !($GLOBALS['xoopsUser']->IsAdmin())) |
30
|
|
|
{ |
31
|
|
|
exit("Restricted access" . PHP_EOL); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param string $tablename |
36
|
|
|
* |
37
|
|
|
* @return bool |
38
|
|
|
*/ |
39
|
|
|
function tableExists($tablename) |
|
|
|
|
40
|
|
|
{ |
41
|
|
|
$result = $GLOBALS['xoopsDB']->queryF("SHOW TABLES LIKE '$tablename'"); |
42
|
|
|
return ($GLOBALS['xoopsDB']->getRowsNum($result) > 0) ? true : false; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* |
47
|
|
|
* Prepares system prior to attempting to install module |
48
|
|
|
* @param obj $module {@link XoopsModule} |
49
|
|
|
* |
50
|
|
|
* @return bool true if ready to install, false if not |
51
|
|
|
*/ |
52
|
|
View Code Duplication |
function xoops_module_pre_update_randomquote(&$module) |
|
|
|
|
53
|
|
|
{ |
54
|
|
|
|
55
|
|
|
if (!class_exists('RandomquoteUtilities')) { |
56
|
|
|
xoops_load('utilities', 'randomquote'); |
57
|
|
|
} |
58
|
|
|
//check for minimum XOOPS version |
59
|
|
|
if (!RandomquoteUtilities::checkXoopsVer($module)) { |
60
|
|
|
return false; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
// check for minimum PHP version |
64
|
|
|
if (!RandomquoteUtilities::checkPHPVer($module)) { |
65
|
|
|
return false; |
66
|
|
|
} |
67
|
|
|
return true; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return bool |
72
|
|
|
*/ |
73
|
|
|
function xoops_module_update_randomquote(&$module, $installedVersion = null) |
|
|
|
|
74
|
|
|
{ |
75
|
|
|
xoops_loadLanguage('admin', $module->dirname()); |
76
|
|
|
$errors = 0; |
77
|
|
|
if (tableExists($GLOBALS['xoopsDB']->prefix('citas'))) { |
78
|
|
|
|
79
|
|
|
$sql = sprintf('ALTER TABLE ' |
80
|
|
|
. $GLOBALS['xoopsDB']->prefix('citas') |
81
|
|
|
. ' CHANGE `citas` `quote` TEXT' |
82
|
|
|
); |
83
|
|
|
$result = $GLOBALS['xoopsDB']->queryF($sql); |
84
|
|
|
if (!$result) { |
85
|
|
|
$module->setErrors(_AM_RANDOMQUOTE_UPGRADEFAILED0); |
86
|
|
|
++$errors; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
$sql = sprintf('ALTER TABLE ' |
90
|
|
|
. $GLOBALS['xoopsDB']->prefix('citas') |
91
|
|
|
. " ADD COLUMN `quote_status` int (10) NOT NULL default '0'," |
92
|
|
|
. " ADD COLUMN `quote_waiting` int (10) NOT NULL default '0'," |
93
|
|
|
. " ADD COLUMN `quote_online` int (10) NOT NULL default '0';" |
94
|
|
|
); |
95
|
|
|
$result = $GLOBALS['xoopsDB']->queryF($sql); |
96
|
|
|
if (!$result) { |
97
|
|
|
$module->setErrors(_AM_RANDOMQUOTE_UPGRADEFAILED1); |
98
|
|
|
++$errors; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
$sql = sprintf('ALTER TABLE ' |
102
|
|
|
. $GLOBALS['xoopsDB']->prefix('citas') |
103
|
|
|
. ' RENAME ' |
104
|
|
|
. $GLOBALS['xoopsDB']->prefix('randomquote_quotes') |
105
|
|
|
); |
106
|
|
|
$result = $GLOBALS['xoopsDB']->queryF($sql); |
107
|
|
|
if (!$result) { |
108
|
|
|
$module->setErrors(_AM_RANDOMQUOTE_UPGRADEFAILED2); |
109
|
|
|
++$errors; |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
if ($installedVersion < 211) { |
114
|
|
|
// add column for quotes table for date created |
115
|
|
|
$result = $GLOBALS['xoopsDB']->queryF("SHOW COLUMNS FROM " . $GLOBALS['xoopsDB']->prefix('randomquote_quotes') . " LIKE 'create_date'"); |
116
|
|
|
$foundCreate = $GLOBALS['xoopsDB']->getRowsNum($result); |
117
|
|
|
if (empty($foundCreate)) { |
118
|
|
|
// column doesn't exist, so try and add it |
119
|
|
|
$success = $GLOBALS['xoopsDB']->queryF("ALTER TABLE " . $GLOBALS['xoopsDB']->prefix('reandomquote_quotes') . " ADD create_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP AFTER quote_status"); |
120
|
|
|
if (!$success) { |
121
|
|
|
$module->setErrors(sprintf(_AM_RANDOMQUOTE_ERROR_COLUMN, 'create_date')); |
122
|
|
|
++$errors; |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
// change status to indicate quote waiting approval |
127
|
|
|
$sql = "UPDATE " . $GLOBALS['xoopsDB']->prefix('randomquote_quotes') . " SET quote_status=2 WHERE `quote_waiting` > 0"; |
128
|
|
|
$result = $GLOBALS['xoopsDB']->queryF($sql); |
129
|
|
|
if (!$result) { |
130
|
|
|
$module->setErrors(_AM_RANDOMQUOTE_UPGRADEFAILED1); |
131
|
|
|
++$errors; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
// change status to indicate quote online |
135
|
|
|
$sql = "UPDATE " . $GLOBALS['xoopsDB']->prefix('randomquote_quotes') . " SET quote_status=1 WHERE `quote_online` > 0"; |
136
|
|
|
$result = $GLOBALS['xoopsDB']->queryF($sql); |
137
|
|
|
if (!$result) { |
138
|
|
|
$module->setErrors(_AM_RANDOMQUOTE_UPGRADEFAILED1); |
139
|
|
|
++$errors; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
// drop the waiting and online columns |
143
|
|
|
$sql = sprintf('ALTER TABLE ' |
144
|
|
|
. $GLOBALS['xoopsDB']->prefix('randomquote_quotes') |
145
|
|
|
. " DROP COLUMN `quote_waiting`," |
146
|
|
|
. " DROP COLUMN `quote_online`;" |
147
|
|
|
); |
148
|
|
|
$result = $GLOBALS['xoopsDB']->queryF($sql); |
149
|
|
|
if (!$result) { |
150
|
|
|
$module->setErrors(_AM_RANDOMQUOTE_UPGRADEFAILED1); |
151
|
|
|
++$errors; |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
return ($errors) ? false : true; |
156
|
|
|
} |
157
|
|
|
|
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.