|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Class NewbbUtility |
|
5
|
|
|
*/ |
|
6
|
|
|
class NewbbUtility |
|
|
|
|
|
|
7
|
|
|
{ |
|
8
|
|
|
/** |
|
9
|
|
|
* Verify that a mysql table exists |
|
10
|
|
|
* |
|
11
|
|
|
* @package News |
|
12
|
|
|
* @author Hervé Thouzard (http://www.herve-thouzard.com) |
|
13
|
|
|
* @copyright (c) Hervé Thouzard |
|
14
|
|
|
* @param $tablename |
|
15
|
|
|
* @return bool |
|
16
|
|
|
*/ |
|
17
|
|
|
public function tableExists($tablename) |
|
18
|
|
|
{ |
|
19
|
|
|
global $xoopsDB; |
|
|
|
|
|
|
20
|
|
|
/** @var \XoopsMySQLDatabase $xoopsDB */ |
|
21
|
|
|
$result = $xoopsDB->queryF("SHOW TABLES LIKE '$tablename'"); |
|
22
|
|
|
|
|
23
|
|
|
return ($xoopsDB->getRowsNum($result) > 0); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Verify that a field exists inside a mysql table |
|
28
|
|
|
* |
|
29
|
|
|
* @package News |
|
30
|
|
|
* @author Hervé Thouzard (http://www.herve-thouzard.com) |
|
31
|
|
|
* @copyright (c) Hervé Thouzard |
|
32
|
|
|
* @param $fieldname |
|
33
|
|
|
* @param $table |
|
34
|
|
|
* @return bool |
|
35
|
|
|
*/ |
|
36
|
|
|
public function fieldExists($fieldname, $table) |
|
37
|
|
|
{ |
|
38
|
|
|
global $xoopsDB; |
|
|
|
|
|
|
39
|
|
|
$result = $xoopsDB->queryF("SHOW COLUMNS FROM $table LIKE '$fieldname'"); |
|
40
|
|
|
|
|
41
|
|
|
return ($xoopsDB->getRowsNum($result) > 0); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Add a field to a mysql table |
|
46
|
|
|
* |
|
47
|
|
|
* @package News |
|
48
|
|
|
* @author Hervé Thouzard (http://www.herve-thouzard.com) |
|
49
|
|
|
* @copyright (c) Hervé Thouzard |
|
50
|
|
|
* @param $field |
|
51
|
|
|
* @param $table |
|
52
|
|
|
* @return bool|\mysqli_result |
|
53
|
|
|
*/ |
|
54
|
|
|
public function addField($field, $table) |
|
55
|
|
|
{ |
|
56
|
|
|
global $xoopsDB; |
|
|
|
|
|
|
57
|
|
|
$result = $xoopsDB->queryF('ALTER TABLE ' . $table . " ADD $field;"); |
|
58
|
|
|
|
|
59
|
|
|
return $result; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Function responsible for checking if a directory exists, we can also write in and create an index.html file |
|
64
|
|
|
* |
|
65
|
|
|
* @param string $folder Le chemin complet du répertoire à vérifier |
|
66
|
|
|
* |
|
67
|
|
|
* @return void |
|
68
|
|
|
*/ |
|
69
|
|
|
public static function prepareFolder($folder) |
|
70
|
|
|
{ |
|
71
|
|
|
try { |
|
72
|
|
|
if (!@mkdir($folder) && !is_dir($folder)) { |
|
73
|
|
|
throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder)); |
|
74
|
|
|
} else { |
|
75
|
|
|
file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>'); |
|
76
|
|
|
} |
|
77
|
|
|
} catch (Exception $e) { |
|
78
|
|
|
echo 'Caught exception: ', $e->getMessage(), "\n", '<br>'; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public static function cleanCache() |
|
83
|
|
|
{ |
|
84
|
|
|
$cacheHelper = new \Xmf\Module\Helper\Cache('newbb'); |
|
85
|
|
|
if (method_exists($cacheHelper,'clear')) { |
|
86
|
|
|
$cacheHelper->clear(); |
|
87
|
|
|
return; |
|
88
|
|
|
} |
|
89
|
|
|
// for 2.5 systems, clear everything |
|
90
|
|
|
require_once XOOPS_ROOT_PATH . '/modules/system/class/maintenance.php'; |
|
91
|
|
|
$maintenance = new SystemMaintenance(); |
|
92
|
|
|
$cacheList = [ |
|
93
|
|
|
3, // xoops_cache |
|
94
|
|
|
]; |
|
95
|
|
|
$maintenance->CleanCache($cacheList); |
|
96
|
|
|
xoops_setActiveModules(); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Checks if a user is admin of NewBB |
|
101
|
|
|
* |
|
102
|
|
|
* @return boolean |
|
103
|
|
|
*/ |
|
104
|
|
|
public static function userIsAdmin() |
|
|
|
|
|
|
105
|
|
|
{ |
|
106
|
|
|
$helper = Newbb::getInstance(); |
|
107
|
|
|
|
|
108
|
|
|
static $newbbIsAdmin; |
|
109
|
|
|
|
|
110
|
|
|
if (isset($newbbIsAdmin)) { |
|
111
|
|
|
return $newbbIsAdmin; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
if (!$GLOBALS['xoopsUser']) { |
|
115
|
|
|
$newbbIsAdmin = false; |
|
116
|
|
|
} else { |
|
117
|
|
|
$newbbIsAdmin = $GLOBALS['xoopsUser']->isAdmin($helper->getModule()->getVar('mid')); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
return $newbbIsAdmin; |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.