1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Xmf\Request; |
4
|
|
|
|
5
|
|
|
require_once __DIR__ . '/common/traitversionchecks.php'; |
6
|
|
|
require_once __DIR__ . '/common/traitserverstats.php'; |
7
|
|
|
require_once __DIR__ . '/common/traitfilesmgmt.php'; |
8
|
|
|
|
9
|
|
|
require_once __DIR__ . '/../include/common.php'; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class InstructionUtility |
13
|
|
|
*/ |
14
|
|
|
class InstructionUtility |
15
|
|
|
{ |
16
|
|
|
use VersionChecks; //checkVerXoops, checkVerPhp Traits |
17
|
|
|
|
18
|
|
|
use ServerStats; // getServerStats Trait |
19
|
|
|
|
20
|
|
|
use FilesManagement; // Files Management Trait |
21
|
|
|
|
22
|
|
|
// Права |
23
|
|
|
public static function getItemIds($permtype = 'instruction_view') |
24
|
|
|
{ |
25
|
|
|
//global $xoopsUser; |
26
|
|
|
static $permissions = []; |
27
|
|
|
// Если есть в статике |
28
|
|
|
if (is_array($permissions) && array_key_exists($permtype, $permissions)) { |
29
|
|
|
return $permissions[$permtype]; |
30
|
|
|
} |
31
|
|
|
// Находим из базы |
32
|
|
|
$moduleHandler = xoops_getHandler('module'); |
33
|
|
|
$instrModule = $moduleHandler->getByDirname('instruction'); |
34
|
|
|
$groups = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getGroups() : XOOPS_GROUP_ANONYMOUS; |
35
|
|
|
$gpermHandler = xoops_getHandler('groupperm'); |
36
|
|
|
$categories = $gpermHandler->getItemIds($permtype, $groups, $instrModule->getVar('mid')); |
37
|
|
|
$permissions[$permtype] = $categories; |
38
|
|
|
return $categories; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
// Редактор |
42
|
|
|
public static function getWysiwygForm($caption, $name, $value = '') |
43
|
|
|
{ |
44
|
|
|
$editor = false; |
|
|
|
|
45
|
|
|
$editor_configs = []; |
46
|
|
|
$editor_configs['name'] = $name; |
47
|
|
|
$editor_configs['value'] = $value; |
48
|
|
|
$editor_configs['rows'] = 35; |
49
|
|
|
$editor_configs['cols'] = 60; |
50
|
|
|
$editor_configs['width'] = '100%'; |
51
|
|
|
$editor_configs['height'] = '350px'; |
52
|
|
|
$editor_configs['editor'] = strtolower(xoops_getModuleOption('form_options', 'instruction')); |
53
|
|
|
|
54
|
|
|
$editor = new XoopsFormEditor($caption, $name, $editor_configs); |
55
|
|
|
return $editor; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
// Получение значения переменной, переданной через GET или POST запрос |
59
|
|
|
public static function cleanVars(&$global, $key, $default = '', $type = 'int') |
60
|
|
|
{ |
61
|
|
|
switch ($type) { |
62
|
|
|
case 'string': |
63
|
|
|
$ret = isset($global[$key]) ? $global[$key] : $default; |
64
|
|
|
break; |
65
|
|
|
case 'int': |
66
|
|
|
default: |
67
|
|
|
$ret = isset($global[$key]) ? (int)$global[$key] : (int)$default; |
68
|
|
|
break; |
69
|
|
|
} |
70
|
|
|
if (false === $ret) { |
71
|
|
|
return $default; |
72
|
|
|
} |
73
|
|
|
return $ret; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.