@@ -5,12 +5,12 @@ |
||
5 | 5 | // Функция вызывается при добавлении комментария |
6 | 6 | function instruction_com_update($pageid, $total_num) |
7 | 7 | { |
8 | - $db = XoopsDatabaseFactory::getDatabaseConnection(); |
|
9 | - $sql = 'UPDATE ' . $db->prefix('instruction_page') . ' SET comments = ' . $total_num . ' WHERE pageid = ' . $pageid; |
|
10 | - $db->query($sql); |
|
8 | + $db = XoopsDatabaseFactory::getDatabaseConnection(); |
|
9 | + $sql = 'UPDATE ' . $db->prefix('instruction_page') . ' SET comments = ' . $total_num . ' WHERE pageid = ' . $pageid; |
|
10 | + $db->query($sql); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | function instruction_com_approve(&$comment) |
14 | 14 | { |
15 | - // notification mail here |
|
15 | + // notification mail here |
|
16 | 16 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | // Типы страницы |
3 | 3 | return [ |
4 | - 0 => _AM_INSTR_PT_0, |
|
5 | - 1 => _AM_INSTR_PT_1 |
|
4 | + 0 => _AM_INSTR_PT_0, |
|
5 | + 1 => _AM_INSTR_PT_1 |
|
6 | 6 | ]; |
@@ -18,14 +18,14 @@ discard block |
||
18 | 18 | */ |
19 | 19 | |
20 | 20 | if (!defined('INSTRUCTION_MODULE_PATH')) { |
21 | - define('INSTRUCTION_DIRNAME', basename(dirname(__DIR__))); |
|
22 | - define('INSTRUCTION_URL', XOOPS_URL . '/modules/' . INSTRUCTION_DIRNAME); |
|
23 | - define('INSTRUCTION_IMAGE_URL', INSTRUCTION_URL . '/assets/images/'); |
|
24 | - define('INSTRUCTION_ROOT_PATH', XOOPS_ROOT_PATH . '/modules/' . INSTRUCTION_DIRNAME); |
|
25 | - define('INSTRUCTION_IMAGE_PATH', INSTRUCTION_ROOT_PATH . '/assets/images'); |
|
26 | - define('INSTRUCTION_ADMIN_URL', INSTRUCTION_URL . '/admin/'); |
|
27 | - define('INSTRUCTION_UPLOAD_URL', XOOPS_UPLOAD_URL . '/' . INSTRUCTION_DIRNAME); |
|
28 | - define('INSTRUCTION_UPLOAD_PATH', XOOPS_UPLOAD_PATH . '/' . INSTRUCTION_DIRNAME); |
|
21 | + define('INSTRUCTION_DIRNAME', basename(dirname(__DIR__))); |
|
22 | + define('INSTRUCTION_URL', XOOPS_URL . '/modules/' . INSTRUCTION_DIRNAME); |
|
23 | + define('INSTRUCTION_IMAGE_URL', INSTRUCTION_URL . '/assets/images/'); |
|
24 | + define('INSTRUCTION_ROOT_PATH', XOOPS_ROOT_PATH . '/modules/' . INSTRUCTION_DIRNAME); |
|
25 | + define('INSTRUCTION_IMAGE_PATH', INSTRUCTION_ROOT_PATH . '/assets/images'); |
|
26 | + define('INSTRUCTION_ADMIN_URL', INSTRUCTION_URL . '/admin/'); |
|
27 | + define('INSTRUCTION_UPLOAD_URL', XOOPS_UPLOAD_URL . '/' . INSTRUCTION_DIRNAME); |
|
28 | + define('INSTRUCTION_UPLOAD_PATH', XOOPS_UPLOAD_PATH . '/' . INSTRUCTION_DIRNAME); |
|
29 | 29 | } |
30 | 30 | xoops_loadLanguage('common', INSTRUCTION_DIRNAME); |
31 | 31 | |
@@ -46,8 +46,8 @@ discard block |
||
46 | 46 | $instruction->loadLanguage('common'); |
47 | 47 | |
48 | 48 | if (!isset($GLOBALS['xoopsTpl']) || !($GLOBALS['xoopsTpl'] instanceof XoopsTpl)) { |
49 | - require_once $GLOBALS['xoops']->path('class/template.php'); |
|
50 | - $xoopsTpl = new XoopsTpl(); |
|
49 | + require_once $GLOBALS['xoops']->path('class/template.php'); |
|
50 | + $xoopsTpl = new XoopsTpl(); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | $moduleDirName = basename(dirname(__DIR__)); |
@@ -3,66 +3,66 @@ |
||
3 | 3 | // Информация об теге |
4 | 4 | function instruction_tag_iteminfo(&$items) |
5 | 5 | { |
6 | - if (empty($items) || !is_array($items)) { |
|
7 | - return false; |
|
8 | - } |
|
6 | + if (empty($items) || !is_array($items)) { |
|
7 | + return false; |
|
8 | + } |
|
9 | 9 | |
10 | - $items_id = []; |
|
11 | - foreach (array_keys($items) as $cat_id) { |
|
12 | - foreach (array_keys($items[$cat_id]) as $item_id) { |
|
13 | - $items_id[] = (int)$item_id; |
|
14 | - } |
|
15 | - } |
|
10 | + $items_id = []; |
|
11 | + foreach (array_keys($items) as $cat_id) { |
|
12 | + foreach (array_keys($items[$cat_id]) as $item_id) { |
|
13 | + $items_id[] = (int)$item_id; |
|
14 | + } |
|
15 | + } |
|
16 | 16 | |
17 | - $itemHandler = xoops_getModuleHandler('instruction', 'instruction'); |
|
18 | - $items_obj = $itemHandler->getObjects(new Criteria('instrid', '(' . implode(', ', $items_id) . ')', 'IN'), true); |
|
17 | + $itemHandler = xoops_getModuleHandler('instruction', 'instruction'); |
|
18 | + $items_obj = $itemHandler->getObjects(new Criteria('instrid', '(' . implode(', ', $items_id) . ')', 'IN'), true); |
|
19 | 19 | |
20 | - foreach (array_keys($items) as $cat_id) { |
|
21 | - foreach (array_keys($items[$cat_id]) as $item_id) { |
|
22 | - if (isset($items_obj[$item_id])) { |
|
23 | - $item_obj = $items_obj[$item_id]; |
|
24 | - $items[$cat_id][$item_id] = [ |
|
25 | - 'title' => $item_obj->getVar('title'), |
|
26 | - 'uid' => $item_obj->getVar('uid'), |
|
27 | - 'link' => "instr.php?id={$item_id}", |
|
28 | - 'time' => $item_obj->getVar('datecreated'), |
|
29 | - 'tags' => '', |
|
30 | - 'content' => '', |
|
31 | - ]; |
|
32 | - } |
|
33 | - } |
|
34 | - } |
|
35 | - unset($items_obj); |
|
20 | + foreach (array_keys($items) as $cat_id) { |
|
21 | + foreach (array_keys($items[$cat_id]) as $item_id) { |
|
22 | + if (isset($items_obj[$item_id])) { |
|
23 | + $item_obj = $items_obj[$item_id]; |
|
24 | + $items[$cat_id][$item_id] = [ |
|
25 | + 'title' => $item_obj->getVar('title'), |
|
26 | + 'uid' => $item_obj->getVar('uid'), |
|
27 | + 'link' => "instr.php?id={$item_id}", |
|
28 | + 'time' => $item_obj->getVar('datecreated'), |
|
29 | + 'tags' => '', |
|
30 | + 'content' => '', |
|
31 | + ]; |
|
32 | + } |
|
33 | + } |
|
34 | + } |
|
35 | + unset($items_obj); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | // Синхронизация тегов |
39 | 39 | function instruction_tag_synchronization($mid) |
40 | 40 | { |
41 | - $itemHandler = xoops_getModuleHandler('instruction', 'instruction'); |
|
42 | - $linkHandler = xoops_getModuleHandler('link', 'tag'); |
|
41 | + $itemHandler = xoops_getModuleHandler('instruction', 'instruction'); |
|
42 | + $linkHandler = xoops_getModuleHandler('link', 'tag'); |
|
43 | 43 | |
44 | - /* clear tag-item links */ |
|
45 | - if (version_compare(mysqli_get_server_info(), '4.1.0', 'ge')): |
|
46 | - $sql = " DELETE FROM {$linkHandler->table}" |
|
47 | - . ' WHERE ' |
|
48 | - . " tag_modid = {$mid}" |
|
49 | - . ' AND ' |
|
50 | - . ' ( tag_itemid NOT IN ' |
|
51 | - . " ( SELECT DISTINCT {$itemHandler->keyName} " |
|
52 | - . " FROM {$itemHandler->table} " |
|
53 | - . " WHERE {$itemHandler->table}.status > 0" |
|
54 | - . ' ) ' |
|
55 | - . ' )'; else: |
|
56 | - $sql = " DELETE {$linkHandler->table} FROM {$linkHandler->table}" |
|
57 | - . " LEFT JOIN {$itemHandler->table} AS aa ON {$linkHandler->table}.tag_itemid = aa.{$itemHandler->keyName} " |
|
58 | - . ' WHERE ' |
|
59 | - . " tag_modid = {$mid}" |
|
60 | - . ' AND ' |
|
61 | - . " ( aa.{$itemHandler->keyName} IS NULL" |
|
62 | - . ' OR aa.status < 1' |
|
63 | - . ' )'; |
|
64 | - endif; |
|
65 | - if (!$result = $linkHandler->db->queryF($sql)) { |
|
66 | - //xoops_error($linkHandler->db->error()); |
|
67 | - } |
|
44 | + /* clear tag-item links */ |
|
45 | + if (version_compare(mysqli_get_server_info(), '4.1.0', 'ge')): |
|
46 | + $sql = " DELETE FROM {$linkHandler->table}" |
|
47 | + . ' WHERE ' |
|
48 | + . " tag_modid = {$mid}" |
|
49 | + . ' AND ' |
|
50 | + . ' ( tag_itemid NOT IN ' |
|
51 | + . " ( SELECT DISTINCT {$itemHandler->keyName} " |
|
52 | + . " FROM {$itemHandler->table} " |
|
53 | + . " WHERE {$itemHandler->table}.status > 0" |
|
54 | + . ' ) ' |
|
55 | + . ' )'; else: |
|
56 | + $sql = " DELETE {$linkHandler->table} FROM {$linkHandler->table}" |
|
57 | + . " LEFT JOIN {$itemHandler->table} AS aa ON {$linkHandler->table}.tag_itemid = aa.{$itemHandler->keyName} " |
|
58 | + . ' WHERE ' |
|
59 | + . " tag_modid = {$mid}" |
|
60 | + . ' AND ' |
|
61 | + . " ( aa.{$itemHandler->keyName} IS NULL" |
|
62 | + . ' OR aa.status < 1' |
|
63 | + . ' )'; |
|
64 | + endif; |
|
65 | + if (!$result = $linkHandler->db->queryF($sql)) { |
|
66 | + //xoops_error($linkHandler->db->error()); |
|
67 | + } |
|
68 | 68 | } |
@@ -28,8 +28,8 @@ discard block |
||
28 | 28 | $criteria->add(new Criteria('pageid ', $pageid)); |
29 | 29 | $criteria->add(new Criteria('status ', '0', '>')); |
30 | 30 | if (0 == $inspageHandler->getCount($criteria)) { |
31 | - redirect_header('index.php', 3, _MD_INSTRUCTION_PAGENOTEXIST); |
|
32 | - exit(); |
|
31 | + redirect_header('index.php', 3, _MD_INSTRUCTION_PAGENOTEXIST); |
|
32 | + exit(); |
|
33 | 33 | } |
34 | 34 | // |
35 | 35 | unset($criteria); |
@@ -41,8 +41,8 @@ discard block |
||
41 | 41 | |
42 | 42 | // Если админ и ссылка на отключение кэша |
43 | 43 | if (is_object($GLOBALS['xoopsUser']) && $GLOBALS['xoopsUser']->isAdmin() && $nocache) { |
44 | - // Отключаем кэш |
|
45 | - $GLOBALS['xoopsConfig']['module_cache'][$GLOBALS['xoopsModule']->getVar('mid')] = 0; |
|
44 | + // Отключаем кэш |
|
45 | + $GLOBALS['xoopsConfig']['module_cache'][$GLOBALS['xoopsModule']->getVar('mid')] = 0; |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | // Задание тайтла |
@@ -59,8 +59,8 @@ discard block |
||
59 | 59 | // Права на просмотр инструкции |
60 | 60 | $categories = InstructionUtility::getItemIds(); |
61 | 61 | if (!in_array($objInsinstr->getVar('cid'), $categories)) { |
62 | - redirect_header(XOOPS_URL . '/modules/' . $moduleDirName . '/', 3, _NOPERM); |
|
63 | - exit(); |
|
62 | + redirect_header(XOOPS_URL . '/modules/' . $moduleDirName . '/', 3, _NOPERM); |
|
63 | + exit(); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | // Массив данных о странице |
@@ -77,9 +77,9 @@ discard block |
||
77 | 77 | $footnote = $objInspage->getVar('footnote'); |
78 | 78 | // Если есть сноски |
79 | 79 | if ($footnote) { |
80 | - $pages['footnotes'] = explode('|', $objInspage->getVar('footnote')); |
|
80 | + $pages['footnotes'] = explode('|', $objInspage->getVar('footnote')); |
|
81 | 81 | } else { |
82 | - $pages['footnotes'] = false; |
|
82 | + $pages['footnotes'] = false; |
|
83 | 83 | } |
84 | 84 | // Мета-теги ключевых слов |
85 | 85 | $pages['keywords'] = $objInspage->getVar('keywords'); |
@@ -88,39 +88,39 @@ discard block |
||
88 | 88 | // |
89 | 89 | // Если админ, рисуем админлинк |
90 | 90 | if (is_object($GLOBALS['xoopsUser']) && $GLOBALS['xoopsUser']->isAdmin($GLOBALS['xoopsModule']->mid())) { |
91 | - $pages['adminlink'] = ' <a href="' |
|
92 | - . XOOPS_URL |
|
93 | - . '/modules/' |
|
94 | - . $moduleDirName |
|
95 | - . '/admin/instr.php?op=editpage&pageid=' |
|
96 | - . $pages['pageid'] |
|
97 | - . '"><img style="width:16px;" src="./assets/icons/edit_mini.png" alt=' |
|
98 | - . _EDIT |
|
99 | - . ' title=' |
|
100 | - . _EDIT |
|
101 | - . '></a> <a href="' |
|
102 | - . XOOPS_URL |
|
103 | - . '/modules/' |
|
104 | - . $moduleDirName |
|
105 | - . '/admin/instr.php?op=delpage&pageid=' |
|
106 | - . $pages['pageid'] |
|
107 | - . '"><img style="width:16px;" src="./assets/icons/delete_mini.png" alt=' |
|
108 | - . _DELETE |
|
109 | - . ' title=' |
|
110 | - . _DELETE |
|
111 | - . '></a> '; |
|
91 | + $pages['adminlink'] = ' <a href="' |
|
92 | + . XOOPS_URL |
|
93 | + . '/modules/' |
|
94 | + . $moduleDirName |
|
95 | + . '/admin/instr.php?op=editpage&pageid=' |
|
96 | + . $pages['pageid'] |
|
97 | + . '"><img style="width:16px;" src="./assets/icons/edit_mini.png" alt=' |
|
98 | + . _EDIT |
|
99 | + . ' title=' |
|
100 | + . _EDIT |
|
101 | + . '></a> <a href="' |
|
102 | + . XOOPS_URL |
|
103 | + . '/modules/' |
|
104 | + . $moduleDirName |
|
105 | + . '/admin/instr.php?op=delpage&pageid=' |
|
106 | + . $pages['pageid'] |
|
107 | + . '"><img style="width:16px;" src="./assets/icons/delete_mini.png" alt=' |
|
108 | + . _DELETE |
|
109 | + . ' title=' |
|
110 | + . _DELETE |
|
111 | + . '></a> '; |
|
112 | 112 | } else { |
113 | - $pages['adminlink'] = ' '; |
|
114 | - // Если можно редактировать |
|
115 | - if ($gpermHandler->checkRight($moduleDirName . '_edit', $objInsinstr->getVar('cid'), $groups, $GLOBALS['xoopsModule']->getVar('mid'))) { |
|
116 | - $pages['adminlink'] .= '<a href="' . XOOPS_URL . '/modules/' . $moduleDirName . '/submit.php?op=editpage&pageid=' . $pages['pageid'] . '"><img style="width:16px;" src="./assets/icons/edit_mini.png" alt=' . _EDIT . ' title=' . _EDIT . '></a>'; |
|
117 | - } |
|
118 | - |
|
119 | - $pages['adminlink'] .= ' '; |
|
120 | - // Если нет админлика |
|
121 | - if ('[ ]' == $pages['adminlink']) { |
|
122 | - $pages['adminlink'] = ''; |
|
123 | - } |
|
113 | + $pages['adminlink'] = ' '; |
|
114 | + // Если можно редактировать |
|
115 | + if ($gpermHandler->checkRight($moduleDirName . '_edit', $objInsinstr->getVar('cid'), $groups, $GLOBALS['xoopsModule']->getVar('mid'))) { |
|
116 | + $pages['adminlink'] .= '<a href="' . XOOPS_URL . '/modules/' . $moduleDirName . '/submit.php?op=editpage&pageid=' . $pages['pageid'] . '"><img style="width:16px;" src="./assets/icons/edit_mini.png" alt=' . _EDIT . ' title=' . _EDIT . '></a>'; |
|
117 | + } |
|
118 | + |
|
119 | + $pages['adminlink'] .= ' '; |
|
120 | + // Если нет админлика |
|
121 | + if ('[ ]' == $pages['adminlink']) { |
|
122 | + $pages['adminlink'] = ''; |
|
123 | + } |
|
124 | 124 | } |
125 | 125 | // Выводим в шаблон |
126 | 126 | $GLOBALS['xoopsTpl']->assign('insPage', $pages); |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | $nav_parent_id = array_reverse($nav_parent_id); |
140 | 140 | $navigation = '<a href="' . XOOPS_URL . '/modules/' . $moduleDirName . '/">' . $GLOBALS['xoopsModule']->name() . '</a> : '; |
141 | 141 | foreach (array_keys($nav_parent_id) as $i) { |
142 | - $navigation .= '<a href="' . XOOPS_URL . '/modules/' . $moduleDirName . '/index.php?cid=' . $nav_parent_id[$i]->getVar('cid') . '">' . $nav_parent_id[$i]->getVar('title') . '</a> : '; |
|
142 | + $navigation .= '<a href="' . XOOPS_URL . '/modules/' . $moduleDirName . '/index.php?cid=' . $nav_parent_id[$i]->getVar('cid') . '">' . $nav_parent_id[$i]->getVar('title') . '</a> : '; |
|
143 | 143 | } |
144 | 144 | $navigation .= '<a href="' . XOOPS_URL . '/modules/' . $moduleDirName . '/index.php?cid=' . $objInscat->getVar('cid') . '">' . $objInscat->getVar('title') . '</a> : '; |
145 | 145 | $navigation .= '<a href="' . XOOPS_URL . '/modules/' . $moduleDirName . '/instr.php?id=' . $pages['instrid'] . '">' . $objInsinstr->getVar('title') . '</a>'; |
@@ -171,9 +171,9 @@ discard block |
||
171 | 171 | |
172 | 172 | // Рейтинг |
173 | 173 | if (xoops_getModuleOption('userat', 'instruction')) { |
174 | - $xoopsTpl->assign('insUserat', true); |
|
174 | + $xoopsTpl->assign('insUserat', true); |
|
175 | 175 | } else { |
176 | - $xoopsTpl->assign('insUserat', false); |
|
176 | + $xoopsTpl->assign('insUserat', false); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | // Мета теги |
@@ -16,60 +16,60 @@ |
||
16 | 16 | */ |
17 | 17 | trait ServerStats |
18 | 18 | { |
19 | - /** |
|
20 | - * serverStats() |
|
21 | - * |
|
22 | - * @return string |
|
23 | - */ |
|
24 | - public static function getServerStats() |
|
25 | - { |
|
26 | - //mb $wfdownloads = WfdownloadsWfdownloads::getInstance(); |
|
27 | - $moduleDirName = basename(dirname(dirname(__DIR__))); |
|
28 | - $moduleDirNameUpper = strtoupper($moduleDirName); |
|
29 | - xoops_loadLanguage('common', $moduleDirName); |
|
30 | - $html = ''; |
|
31 | - // $sql = 'SELECT metavalue'; |
|
32 | - // $sql .= ' FROM ' . $GLOBALS['xoopsDB']->prefix('wfdownloads_meta'); |
|
33 | - // $sql .= " WHERE metakey='version' LIMIT 1"; |
|
34 | - // $query = $GLOBALS['xoopsDB']->query($sql); |
|
35 | - // list($meta) = $GLOBALS['xoopsDB']->fetchRow($query); |
|
36 | - $html .= "<fieldset><legend style='font-weight: bold; color: #900;'>" . constant('CO_' . $moduleDirNameUpper . '_IMAGEINFO') . "</legend>\n"; |
|
37 | - $html .= "<div style='padding: 8px;'>\n"; |
|
38 | - // $html .= '<div>' . constant('CO_' . $moduleDirNameUpper . '_METAVERSION') . $meta . "</div>\n"; |
|
39 | - // $html .= "<br>\n"; |
|
40 | - // $html .= "<br>\n"; |
|
41 | - $html .= '<div>' . constant('CO_' . $moduleDirNameUpper . '_SPHPINI') . "</div>\n"; |
|
42 | - $html .= "<ul>\n"; |
|
43 | - // |
|
44 | - $gdlib = function_exists('gd_info') ? '<span style="color: green;">' . constant('CO_' . $moduleDirNameUpper . '_GDON') . '</span>' : '<span style="color: red;">' . constant('CO_' . $moduleDirNameUpper . '_GDOFF') . '</span>'; |
|
45 | - $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_GDLIBSTATUS') . $gdlib; |
|
46 | - if (function_exists('gd_info')) { |
|
47 | - if ($gdlib = true === gd_info()) { |
|
48 | - $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_GDLIBVERSION') . '<b>' . $gdlib['GD Version'] . '</b>'; |
|
49 | - } |
|
50 | - } |
|
51 | - // |
|
52 | - // $safemode = ini_get('safe_mode') ? constant('CO_' . $moduleDirNameUpper . '_ON') . constant('CO_' . $moduleDirNameUpper . '_SAFEMODEPROBLEMS : constant('CO_' . $moduleDirNameUpper . '_OFF'); |
|
53 | - // $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_SAFEMODESTATUS . $safemode; |
|
54 | - // |
|
55 | - // $registerglobals = (!ini_get('register_globals')) ? "<span style=\"color: green;\">" . constant('CO_' . $moduleDirNameUpper . '_OFF') . '</span>' : "<span style=\"color: red;\">" . constant('CO_' . $moduleDirNameUpper . '_ON') . '</span>'; |
|
56 | - // $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_REGISTERGLOBALS . $registerglobals; |
|
57 | - // |
|
58 | - $downloads = ini_get('file_uploads') ? '<span style="color: green;">' . constant('CO_' . $moduleDirNameUpper . '_ON') . '</span>' : '<span style="color: red;">' . constant('CO_' . $moduleDirNameUpper . '_OFF') . '</span>'; |
|
59 | - $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_SERVERUPLOADSTATUS') . $downloads; |
|
60 | - // |
|
61 | - $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_MAXUPLOADSIZE') . ' <b><span style="color: blue;">' . ini_get('upload_max_filesize') . "</span></b>\n"; |
|
62 | - $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_MAXPOSTSIZE') . ' <b><span style="color: blue;">' . ini_get('post_max_size') . "</span></b>\n"; |
|
63 | - $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_MEMORYLIMIT') . ' <b><span style="color: blue;">' . ini_get('memory_limit') . "</span></b>\n"; |
|
64 | - $html .= "</ul>\n"; |
|
65 | - $html .= "<ul>\n"; |
|
66 | - $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_SERVERPATH') . ' <b>' . XOOPS_ROOT_PATH . "</b>\n"; |
|
67 | - $html .= "</ul>\n"; |
|
68 | - $html .= "<br>\n"; |
|
69 | - $html .= constant('CO_' . $moduleDirNameUpper . '_UPLOADPATHDSC') . "\n"; |
|
70 | - $html .= '</div>'; |
|
71 | - $html .= '</fieldset><br>'; |
|
19 | + /** |
|
20 | + * serverStats() |
|
21 | + * |
|
22 | + * @return string |
|
23 | + */ |
|
24 | + public static function getServerStats() |
|
25 | + { |
|
26 | + //mb $wfdownloads = WfdownloadsWfdownloads::getInstance(); |
|
27 | + $moduleDirName = basename(dirname(dirname(__DIR__))); |
|
28 | + $moduleDirNameUpper = strtoupper($moduleDirName); |
|
29 | + xoops_loadLanguage('common', $moduleDirName); |
|
30 | + $html = ''; |
|
31 | + // $sql = 'SELECT metavalue'; |
|
32 | + // $sql .= ' FROM ' . $GLOBALS['xoopsDB']->prefix('wfdownloads_meta'); |
|
33 | + // $sql .= " WHERE metakey='version' LIMIT 1"; |
|
34 | + // $query = $GLOBALS['xoopsDB']->query($sql); |
|
35 | + // list($meta) = $GLOBALS['xoopsDB']->fetchRow($query); |
|
36 | + $html .= "<fieldset><legend style='font-weight: bold; color: #900;'>" . constant('CO_' . $moduleDirNameUpper . '_IMAGEINFO') . "</legend>\n"; |
|
37 | + $html .= "<div style='padding: 8px;'>\n"; |
|
38 | + // $html .= '<div>' . constant('CO_' . $moduleDirNameUpper . '_METAVERSION') . $meta . "</div>\n"; |
|
39 | + // $html .= "<br>\n"; |
|
40 | + // $html .= "<br>\n"; |
|
41 | + $html .= '<div>' . constant('CO_' . $moduleDirNameUpper . '_SPHPINI') . "</div>\n"; |
|
42 | + $html .= "<ul>\n"; |
|
43 | + // |
|
44 | + $gdlib = function_exists('gd_info') ? '<span style="color: green;">' . constant('CO_' . $moduleDirNameUpper . '_GDON') . '</span>' : '<span style="color: red;">' . constant('CO_' . $moduleDirNameUpper . '_GDOFF') . '</span>'; |
|
45 | + $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_GDLIBSTATUS') . $gdlib; |
|
46 | + if (function_exists('gd_info')) { |
|
47 | + if ($gdlib = true === gd_info()) { |
|
48 | + $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_GDLIBVERSION') . '<b>' . $gdlib['GD Version'] . '</b>'; |
|
49 | + } |
|
50 | + } |
|
51 | + // |
|
52 | + // $safemode = ini_get('safe_mode') ? constant('CO_' . $moduleDirNameUpper . '_ON') . constant('CO_' . $moduleDirNameUpper . '_SAFEMODEPROBLEMS : constant('CO_' . $moduleDirNameUpper . '_OFF'); |
|
53 | + // $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_SAFEMODESTATUS . $safemode; |
|
54 | + // |
|
55 | + // $registerglobals = (!ini_get('register_globals')) ? "<span style=\"color: green;\">" . constant('CO_' . $moduleDirNameUpper . '_OFF') . '</span>' : "<span style=\"color: red;\">" . constant('CO_' . $moduleDirNameUpper . '_ON') . '</span>'; |
|
56 | + // $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_REGISTERGLOBALS . $registerglobals; |
|
57 | + // |
|
58 | + $downloads = ini_get('file_uploads') ? '<span style="color: green;">' . constant('CO_' . $moduleDirNameUpper . '_ON') . '</span>' : '<span style="color: red;">' . constant('CO_' . $moduleDirNameUpper . '_OFF') . '</span>'; |
|
59 | + $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_SERVERUPLOADSTATUS') . $downloads; |
|
60 | + // |
|
61 | + $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_MAXUPLOADSIZE') . ' <b><span style="color: blue;">' . ini_get('upload_max_filesize') . "</span></b>\n"; |
|
62 | + $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_MAXPOSTSIZE') . ' <b><span style="color: blue;">' . ini_get('post_max_size') . "</span></b>\n"; |
|
63 | + $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_MEMORYLIMIT') . ' <b><span style="color: blue;">' . ini_get('memory_limit') . "</span></b>\n"; |
|
64 | + $html .= "</ul>\n"; |
|
65 | + $html .= "<ul>\n"; |
|
66 | + $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_SERVERPATH') . ' <b>' . XOOPS_ROOT_PATH . "</b>\n"; |
|
67 | + $html .= "</ul>\n"; |
|
68 | + $html .= "<br>\n"; |
|
69 | + $html .= constant('CO_' . $moduleDirNameUpper . '_UPLOADPATHDSC') . "\n"; |
|
70 | + $html .= '</div>'; |
|
71 | + $html .= '</fieldset><br>'; |
|
72 | 72 | |
73 | - return $html; |
|
74 | - } |
|
73 | + return $html; |
|
74 | + } |
|
75 | 75 | } |
@@ -16,77 +16,77 @@ |
||
16 | 16 | */ |
17 | 17 | trait VersionChecks |
18 | 18 | { |
19 | - /** |
|
20 | - * |
|
21 | - * Verifies XOOPS version meets minimum requirements for this module |
|
22 | - * @static |
|
23 | - * @param XoopsModule $module |
|
24 | - * |
|
25 | - * @param null|string $requiredVer |
|
26 | - * @return bool true if meets requirements, false if not |
|
27 | - */ |
|
28 | - public static function checkVerXoops(XoopsModule $module = null, $requiredVer = null) |
|
29 | - { |
|
30 | - $moduleDirName = basename(dirname(__DIR__)); |
|
31 | - if (null === $module) { |
|
32 | - $module = XoopsModule::getByDirname($moduleDirName); |
|
33 | - } |
|
34 | - xoops_loadLanguage('admin', $moduleDirName); |
|
35 | - //check for minimum XOOPS version |
|
36 | - $currentVer = substr(XOOPS_VERSION, 6); // get the numeric part of string |
|
37 | - $currArray = explode('.', $currentVer); |
|
38 | - if (null === $requiredVer) { |
|
39 | - $requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string |
|
40 | - } |
|
41 | - $reqArray = explode('.', $requiredVer); |
|
42 | - $success = true; |
|
43 | - foreach ($reqArray as $k => $v) { |
|
44 | - if (isset($currArray[$k])) { |
|
45 | - if ($currArray[$k] > $v) { |
|
46 | - break; |
|
47 | - } elseif ($currArray[$k] == $v) { |
|
48 | - continue; |
|
49 | - } else { |
|
50 | - $success = false; |
|
51 | - break; |
|
52 | - } |
|
53 | - } else { |
|
54 | - if ((int)$v > 0) { // handles versions like x.x.x.0_RC2 |
|
55 | - $success = false; |
|
56 | - break; |
|
57 | - } |
|
58 | - } |
|
59 | - } |
|
19 | + /** |
|
20 | + * |
|
21 | + * Verifies XOOPS version meets minimum requirements for this module |
|
22 | + * @static |
|
23 | + * @param XoopsModule $module |
|
24 | + * |
|
25 | + * @param null|string $requiredVer |
|
26 | + * @return bool true if meets requirements, false if not |
|
27 | + */ |
|
28 | + public static function checkVerXoops(XoopsModule $module = null, $requiredVer = null) |
|
29 | + { |
|
30 | + $moduleDirName = basename(dirname(__DIR__)); |
|
31 | + if (null === $module) { |
|
32 | + $module = XoopsModule::getByDirname($moduleDirName); |
|
33 | + } |
|
34 | + xoops_loadLanguage('admin', $moduleDirName); |
|
35 | + //check for minimum XOOPS version |
|
36 | + $currentVer = substr(XOOPS_VERSION, 6); // get the numeric part of string |
|
37 | + $currArray = explode('.', $currentVer); |
|
38 | + if (null === $requiredVer) { |
|
39 | + $requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string |
|
40 | + } |
|
41 | + $reqArray = explode('.', $requiredVer); |
|
42 | + $success = true; |
|
43 | + foreach ($reqArray as $k => $v) { |
|
44 | + if (isset($currArray[$k])) { |
|
45 | + if ($currArray[$k] > $v) { |
|
46 | + break; |
|
47 | + } elseif ($currArray[$k] == $v) { |
|
48 | + continue; |
|
49 | + } else { |
|
50 | + $success = false; |
|
51 | + break; |
|
52 | + } |
|
53 | + } else { |
|
54 | + if ((int)$v > 0) { // handles versions like x.x.x.0_RC2 |
|
55 | + $success = false; |
|
56 | + break; |
|
57 | + } |
|
58 | + } |
|
59 | + } |
|
60 | 60 | |
61 | - if (false === $success) { |
|
62 | - $module->setErrors(sprintf(_AM_WFL_ERROR_BAD_XOOPS, $requiredVer, $currentVer)); |
|
63 | - } |
|
61 | + if (false === $success) { |
|
62 | + $module->setErrors(sprintf(_AM_WFL_ERROR_BAD_XOOPS, $requiredVer, $currentVer)); |
|
63 | + } |
|
64 | 64 | |
65 | - return $success; |
|
66 | - } |
|
65 | + return $success; |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * |
|
70 | - * Verifies PHP version meets minimum requirements for this module |
|
71 | - * @static |
|
72 | - * @param XoopsModule $module |
|
73 | - * |
|
74 | - * @return bool true if meets requirements, false if not |
|
75 | - */ |
|
76 | - public static function checkVerPhp(XoopsModule $module) |
|
77 | - { |
|
78 | - xoops_loadLanguage('admin', $module->dirname()); |
|
79 | - // check for minimum PHP version |
|
80 | - $success = true; |
|
81 | - $verNum = PHP_VERSION; |
|
82 | - $reqVer = $module->getInfo('min_php'); |
|
83 | - if (false !== $reqVer && '' !== $reqVer) { |
|
84 | - if (version_compare($verNum, $reqVer, '<')) { |
|
85 | - $module->setErrors(sprintf(_AM_WFL_ERROR_BAD_PHP, $reqVer, $verNum)); |
|
86 | - $success = false; |
|
87 | - } |
|
88 | - } |
|
68 | + /** |
|
69 | + * |
|
70 | + * Verifies PHP version meets minimum requirements for this module |
|
71 | + * @static |
|
72 | + * @param XoopsModule $module |
|
73 | + * |
|
74 | + * @return bool true if meets requirements, false if not |
|
75 | + */ |
|
76 | + public static function checkVerPhp(XoopsModule $module) |
|
77 | + { |
|
78 | + xoops_loadLanguage('admin', $module->dirname()); |
|
79 | + // check for minimum PHP version |
|
80 | + $success = true; |
|
81 | + $verNum = PHP_VERSION; |
|
82 | + $reqVer = $module->getInfo('min_php'); |
|
83 | + if (false !== $reqVer && '' !== $reqVer) { |
|
84 | + if (version_compare($verNum, $reqVer, '<')) { |
|
85 | + $module->setErrors(sprintf(_AM_WFL_ERROR_BAD_PHP, $reqVer, $verNum)); |
|
86 | + $success = false; |
|
87 | + } |
|
88 | + } |
|
89 | 89 | |
90 | - return $success; |
|
91 | - } |
|
90 | + return $success; |
|
91 | + } |
|
92 | 92 | } |
@@ -32,48 +32,48 @@ |
||
32 | 32 | */ |
33 | 33 | class PedigreeBreadcrumb |
34 | 34 | { |
35 | - public $dirname; |
|
36 | - private $bread = []; |
|
35 | + public $dirname; |
|
36 | + private $bread = []; |
|
37 | 37 | |
38 | - /** |
|
39 | - * |
|
40 | - */ |
|
41 | - public function __construct() |
|
42 | - { |
|
43 | - $this->dirname = basename(dirname(__DIR__)); |
|
44 | - } |
|
38 | + /** |
|
39 | + * |
|
40 | + */ |
|
41 | + public function __construct() |
|
42 | + { |
|
43 | + $this->dirname = basename(dirname(__DIR__)); |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Add link to breadcrumb |
|
48 | - * |
|
49 | - * @param string $title |
|
50 | - * @param string $link |
|
51 | - */ |
|
52 | - public function addLink($title = '', $link = '') |
|
53 | - { |
|
54 | - $this->bread[] = [ |
|
55 | - 'link' => $link, |
|
56 | - 'title' => $title |
|
57 | - ]; |
|
58 | - } |
|
46 | + /** |
|
47 | + * Add link to breadcrumb |
|
48 | + * |
|
49 | + * @param string $title |
|
50 | + * @param string $link |
|
51 | + */ |
|
52 | + public function addLink($title = '', $link = '') |
|
53 | + { |
|
54 | + $this->bread[] = [ |
|
55 | + 'link' => $link, |
|
56 | + 'title' => $title |
|
57 | + ]; |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Render Pedigree BreadCrumb |
|
62 | - * |
|
63 | - */ |
|
64 | - public function render() |
|
65 | - { |
|
66 | - if (!isset($GLOBALS['xoTheme']) || !is_object($GLOBALS['xoTheme'])) { |
|
67 | - require_once $GLOBALS['xoops']->path('class/theme.php'); |
|
68 | - $GLOBALS['xoTheme'] = new xos_opal_Theme(); |
|
69 | - } |
|
60 | + /** |
|
61 | + * Render Pedigree BreadCrumb |
|
62 | + * |
|
63 | + */ |
|
64 | + public function render() |
|
65 | + { |
|
66 | + if (!isset($GLOBALS['xoTheme']) || !is_object($GLOBALS['xoTheme'])) { |
|
67 | + require_once $GLOBALS['xoops']->path('class/theme.php'); |
|
68 | + $GLOBALS['xoTheme'] = new xos_opal_Theme(); |
|
69 | + } |
|
70 | 70 | |
71 | - require_once $GLOBALS['xoops']->path('class/template.php'); |
|
72 | - $breadcrumbTpl = new XoopsTpl(); |
|
73 | - $breadcrumbTpl->assign('breadcrumb', $this->bread); |
|
74 | - $html = $breadcrumbTpl->fetch('db:' . $this->dirname . '_common_breadcrumb.tpl'); |
|
75 | - unset($breadcrumbTpl); |
|
71 | + require_once $GLOBALS['xoops']->path('class/template.php'); |
|
72 | + $breadcrumbTpl = new XoopsTpl(); |
|
73 | + $breadcrumbTpl->assign('breadcrumb', $this->bread); |
|
74 | + $html = $breadcrumbTpl->fetch('db:' . $this->dirname . '_common_breadcrumb.tpl'); |
|
75 | + unset($breadcrumbTpl); |
|
76 | 76 | |
77 | - return $html; |
|
78 | - } |
|
77 | + return $html; |
|
78 | + } |
|
79 | 79 | } |
@@ -16,226 +16,226 @@ |
||
16 | 16 | */ |
17 | 17 | trait FilesManagement |
18 | 18 | { |
19 | - /** |
|
20 | - * Function responsible for checking if a directory exists, we can also write in and create an index.html file |
|
21 | - * |
|
22 | - * @param string $folder The full path of the directory to check |
|
23 | - * |
|
24 | - * @return void |
|
25 | - */ |
|
26 | - public static function createFolder($folder) |
|
27 | - { |
|
28 | - try { |
|
29 | - if (!file_exists($folder)) { |
|
30 | - if (!mkdir($folder) && !is_dir($folder)) { |
|
31 | - throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder)); |
|
32 | - } |
|
33 | - |
|
34 | - file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>'); |
|
35 | - } |
|
36 | - } catch (Exception $e) { |
|
37 | - echo 'Caught exception: ', $e->getMessage(), "\n", '<br>'; |
|
38 | - } |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * @param $file |
|
43 | - * @param $folder |
|
44 | - * @return bool |
|
45 | - */ |
|
46 | - public static function copyFile($file, $folder) |
|
47 | - { |
|
48 | - return copy($file, $folder); |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * @param $src |
|
53 | - * @param $dst |
|
54 | - */ |
|
55 | - public static function recurseCopy($src, $dst) |
|
56 | - { |
|
57 | - $dir = opendir($src); |
|
58 | - @mkdir($dst); |
|
59 | - while (false !== ($file = readdir($dir))) { |
|
60 | - if (('.' !== $file) && ('..' !== $file)) { |
|
61 | - if (is_dir($src . '/' . $file)) { |
|
62 | - self::recurseCopy($src . '/' . $file, $dst . '/' . $file); |
|
63 | - } else { |
|
64 | - copy($src . '/' . $file, $dst . '/' . $file); |
|
65 | - } |
|
66 | - } |
|
67 | - } |
|
68 | - closedir($dir); |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * |
|
73 | - * Remove files and (sub)directories |
|
74 | - * |
|
75 | - * @param string $src source directory to delete |
|
76 | - * |
|
77 | - * @uses \Xmf\Module\Helper::getHelper() |
|
78 | - * @uses \Xmf\Module\Helper::isUserAdmin() |
|
79 | - * |
|
80 | - * @return bool true on success |
|
81 | - */ |
|
82 | - public static function deleteDirectory($src) |
|
83 | - { |
|
84 | - // Only continue if user is a 'global' Admin |
|
85 | - if (!($GLOBALS['xoopsUser'] instanceof XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
86 | - return false; |
|
87 | - } |
|
88 | - |
|
89 | - $success = true; |
|
90 | - // remove old files |
|
91 | - $dirInfo = new SplFileInfo($src); |
|
92 | - // validate is a directory |
|
93 | - if ($dirInfo->isDir()) { |
|
94 | - $fileList = array_diff(scandir($src, SCANDIR_SORT_NONE), ['..', '.']); |
|
95 | - foreach ($fileList as $k => $v) { |
|
96 | - $fileInfo = new SplFileInfo("{$src}/{$v}"); |
|
97 | - if ($fileInfo->isDir()) { |
|
98 | - // recursively handle subdirectories |
|
99 | - if (!$success = self::deleteDirectory($fileInfo->getRealPath())) { |
|
100 | - break; |
|
101 | - } |
|
102 | - } else { |
|
103 | - // delete the file |
|
104 | - if (!($success = unlink($fileInfo->getRealPath()))) { |
|
105 | - break; |
|
106 | - } |
|
107 | - } |
|
108 | - } |
|
109 | - // now delete this (sub)directory if all the files are gone |
|
110 | - if ($success) { |
|
111 | - $success = rmdir($dirInfo->getRealPath()); |
|
112 | - } |
|
113 | - } else { |
|
114 | - // input is not a valid directory |
|
115 | - $success = false; |
|
116 | - } |
|
117 | - return $success; |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * |
|
122 | - * Recursively remove directory |
|
123 | - * |
|
124 | - * @todo currently won't remove directories with hidden files, should it? |
|
125 | - * |
|
126 | - * @param string $src directory to remove (delete) |
|
127 | - * |
|
128 | - * @return bool true on success |
|
129 | - */ |
|
130 | - public static function rrmdir($src) |
|
131 | - { |
|
132 | - // Only continue if user is a 'global' Admin |
|
133 | - if (!($GLOBALS['xoopsUser'] instanceof XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
134 | - return false; |
|
135 | - } |
|
136 | - |
|
137 | - // If source is not a directory stop processing |
|
138 | - if (!is_dir($src)) { |
|
139 | - return false; |
|
140 | - } |
|
141 | - |
|
142 | - $success = true; |
|
143 | - |
|
144 | - // Open the source directory to read in files |
|
145 | - $iterator = new DirectoryIterator($src); |
|
146 | - foreach ($iterator as $fObj) { |
|
147 | - if ($fObj->isFile()) { |
|
148 | - $filename = $fObj->getPathname(); |
|
149 | - $fObj = null; // clear this iterator object to close the file |
|
150 | - if (!unlink($filename)) { |
|
151 | - return false; // couldn't delete the file |
|
152 | - } |
|
153 | - } elseif (!$fObj->isDot() && $fObj->isDir()) { |
|
154 | - // Try recursively on directory |
|
155 | - self::rrmdir($fObj->getPathname()); |
|
156 | - } |
|
157 | - } |
|
158 | - $iterator = null; // clear iterator Obj to close file/directory |
|
159 | - return rmdir($src); // remove the directory & return results |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * Recursively move files from one directory to another |
|
164 | - * |
|
165 | - * @param string $src - Source of files being moved |
|
166 | - * @param string $dest - Destination of files being moved |
|
167 | - * |
|
168 | - * @return bool true on success |
|
169 | - */ |
|
170 | - public static function rmove($src, $dest) |
|
171 | - { |
|
172 | - // Only continue if user is a 'global' Admin |
|
173 | - if (!($GLOBALS['xoopsUser'] instanceof XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
174 | - return false; |
|
175 | - } |
|
176 | - |
|
177 | - // If source is not a directory stop processing |
|
178 | - if (!is_dir($src)) { |
|
179 | - return false; |
|
180 | - } |
|
181 | - |
|
182 | - // If the destination directory does not exist and could not be created stop processing |
|
183 | - if (!is_dir($dest) && !mkdir($dest, 0755)) { |
|
184 | - return false; |
|
185 | - } |
|
186 | - |
|
187 | - // Open the source directory to read in files |
|
188 | - $iterator = new DirectoryIterator($src); |
|
189 | - foreach ($iterator as $fObj) { |
|
190 | - if ($fObj->isFile()) { |
|
191 | - rename($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
192 | - } elseif (!$fObj->isDot() && $fObj->isDir()) { |
|
193 | - // Try recursively on directory |
|
194 | - self::rmove($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
195 | - // rmdir($fObj->getPath()); // now delete the directory |
|
196 | - } |
|
197 | - } |
|
198 | - $iterator = null; // clear iterator Obj to close file/directory |
|
199 | - return rmdir($src); // remove the directory & return results |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * Recursively copy directories and files from one directory to another |
|
204 | - * |
|
205 | - * @param string $src - Source of files being moved |
|
206 | - * @param string $dest - Destination of files being moved |
|
207 | - * |
|
208 | - * @uses \Xmf\Module\Helper::getHelper() |
|
209 | - * @uses \Xmf\Module\Helper::isUserAdmin() |
|
210 | - * |
|
211 | - * @return bool true on success |
|
212 | - */ |
|
213 | - public static function rcopy($src, $dest) |
|
214 | - { |
|
215 | - // Only continue if user is a 'global' Admin |
|
216 | - if (!($GLOBALS['xoopsUser'] instanceof XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
217 | - return false; |
|
218 | - } |
|
219 | - |
|
220 | - // If source is not a directory stop processing |
|
221 | - if (!is_dir($src)) { |
|
222 | - return false; |
|
223 | - } |
|
224 | - |
|
225 | - // If the destination directory does not exist and could not be created stop processing |
|
226 | - if (!is_dir($dest) && !mkdir($dest, 0755)) { |
|
227 | - return false; |
|
228 | - } |
|
229 | - |
|
230 | - // Open the source directory to read in files |
|
231 | - $iterator = new DirectoryIterator($src); |
|
232 | - foreach ($iterator as $fObj) { |
|
233 | - if ($fObj->isFile()) { |
|
234 | - copy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
235 | - } elseif (!$fObj->isDot() && $fObj->isDir()) { |
|
236 | - self::rcopy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
237 | - } |
|
238 | - } |
|
239 | - return true; |
|
240 | - } |
|
19 | + /** |
|
20 | + * Function responsible for checking if a directory exists, we can also write in and create an index.html file |
|
21 | + * |
|
22 | + * @param string $folder The full path of the directory to check |
|
23 | + * |
|
24 | + * @return void |
|
25 | + */ |
|
26 | + public static function createFolder($folder) |
|
27 | + { |
|
28 | + try { |
|
29 | + if (!file_exists($folder)) { |
|
30 | + if (!mkdir($folder) && !is_dir($folder)) { |
|
31 | + throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder)); |
|
32 | + } |
|
33 | + |
|
34 | + file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>'); |
|
35 | + } |
|
36 | + } catch (Exception $e) { |
|
37 | + echo 'Caught exception: ', $e->getMessage(), "\n", '<br>'; |
|
38 | + } |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * @param $file |
|
43 | + * @param $folder |
|
44 | + * @return bool |
|
45 | + */ |
|
46 | + public static function copyFile($file, $folder) |
|
47 | + { |
|
48 | + return copy($file, $folder); |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * @param $src |
|
53 | + * @param $dst |
|
54 | + */ |
|
55 | + public static function recurseCopy($src, $dst) |
|
56 | + { |
|
57 | + $dir = opendir($src); |
|
58 | + @mkdir($dst); |
|
59 | + while (false !== ($file = readdir($dir))) { |
|
60 | + if (('.' !== $file) && ('..' !== $file)) { |
|
61 | + if (is_dir($src . '/' . $file)) { |
|
62 | + self::recurseCopy($src . '/' . $file, $dst . '/' . $file); |
|
63 | + } else { |
|
64 | + copy($src . '/' . $file, $dst . '/' . $file); |
|
65 | + } |
|
66 | + } |
|
67 | + } |
|
68 | + closedir($dir); |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * |
|
73 | + * Remove files and (sub)directories |
|
74 | + * |
|
75 | + * @param string $src source directory to delete |
|
76 | + * |
|
77 | + * @uses \Xmf\Module\Helper::getHelper() |
|
78 | + * @uses \Xmf\Module\Helper::isUserAdmin() |
|
79 | + * |
|
80 | + * @return bool true on success |
|
81 | + */ |
|
82 | + public static function deleteDirectory($src) |
|
83 | + { |
|
84 | + // Only continue if user is a 'global' Admin |
|
85 | + if (!($GLOBALS['xoopsUser'] instanceof XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
86 | + return false; |
|
87 | + } |
|
88 | + |
|
89 | + $success = true; |
|
90 | + // remove old files |
|
91 | + $dirInfo = new SplFileInfo($src); |
|
92 | + // validate is a directory |
|
93 | + if ($dirInfo->isDir()) { |
|
94 | + $fileList = array_diff(scandir($src, SCANDIR_SORT_NONE), ['..', '.']); |
|
95 | + foreach ($fileList as $k => $v) { |
|
96 | + $fileInfo = new SplFileInfo("{$src}/{$v}"); |
|
97 | + if ($fileInfo->isDir()) { |
|
98 | + // recursively handle subdirectories |
|
99 | + if (!$success = self::deleteDirectory($fileInfo->getRealPath())) { |
|
100 | + break; |
|
101 | + } |
|
102 | + } else { |
|
103 | + // delete the file |
|
104 | + if (!($success = unlink($fileInfo->getRealPath()))) { |
|
105 | + break; |
|
106 | + } |
|
107 | + } |
|
108 | + } |
|
109 | + // now delete this (sub)directory if all the files are gone |
|
110 | + if ($success) { |
|
111 | + $success = rmdir($dirInfo->getRealPath()); |
|
112 | + } |
|
113 | + } else { |
|
114 | + // input is not a valid directory |
|
115 | + $success = false; |
|
116 | + } |
|
117 | + return $success; |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * |
|
122 | + * Recursively remove directory |
|
123 | + * |
|
124 | + * @todo currently won't remove directories with hidden files, should it? |
|
125 | + * |
|
126 | + * @param string $src directory to remove (delete) |
|
127 | + * |
|
128 | + * @return bool true on success |
|
129 | + */ |
|
130 | + public static function rrmdir($src) |
|
131 | + { |
|
132 | + // Only continue if user is a 'global' Admin |
|
133 | + if (!($GLOBALS['xoopsUser'] instanceof XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
134 | + return false; |
|
135 | + } |
|
136 | + |
|
137 | + // If source is not a directory stop processing |
|
138 | + if (!is_dir($src)) { |
|
139 | + return false; |
|
140 | + } |
|
141 | + |
|
142 | + $success = true; |
|
143 | + |
|
144 | + // Open the source directory to read in files |
|
145 | + $iterator = new DirectoryIterator($src); |
|
146 | + foreach ($iterator as $fObj) { |
|
147 | + if ($fObj->isFile()) { |
|
148 | + $filename = $fObj->getPathname(); |
|
149 | + $fObj = null; // clear this iterator object to close the file |
|
150 | + if (!unlink($filename)) { |
|
151 | + return false; // couldn't delete the file |
|
152 | + } |
|
153 | + } elseif (!$fObj->isDot() && $fObj->isDir()) { |
|
154 | + // Try recursively on directory |
|
155 | + self::rrmdir($fObj->getPathname()); |
|
156 | + } |
|
157 | + } |
|
158 | + $iterator = null; // clear iterator Obj to close file/directory |
|
159 | + return rmdir($src); // remove the directory & return results |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * Recursively move files from one directory to another |
|
164 | + * |
|
165 | + * @param string $src - Source of files being moved |
|
166 | + * @param string $dest - Destination of files being moved |
|
167 | + * |
|
168 | + * @return bool true on success |
|
169 | + */ |
|
170 | + public static function rmove($src, $dest) |
|
171 | + { |
|
172 | + // Only continue if user is a 'global' Admin |
|
173 | + if (!($GLOBALS['xoopsUser'] instanceof XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
174 | + return false; |
|
175 | + } |
|
176 | + |
|
177 | + // If source is not a directory stop processing |
|
178 | + if (!is_dir($src)) { |
|
179 | + return false; |
|
180 | + } |
|
181 | + |
|
182 | + // If the destination directory does not exist and could not be created stop processing |
|
183 | + if (!is_dir($dest) && !mkdir($dest, 0755)) { |
|
184 | + return false; |
|
185 | + } |
|
186 | + |
|
187 | + // Open the source directory to read in files |
|
188 | + $iterator = new DirectoryIterator($src); |
|
189 | + foreach ($iterator as $fObj) { |
|
190 | + if ($fObj->isFile()) { |
|
191 | + rename($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
192 | + } elseif (!$fObj->isDot() && $fObj->isDir()) { |
|
193 | + // Try recursively on directory |
|
194 | + self::rmove($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
195 | + // rmdir($fObj->getPath()); // now delete the directory |
|
196 | + } |
|
197 | + } |
|
198 | + $iterator = null; // clear iterator Obj to close file/directory |
|
199 | + return rmdir($src); // remove the directory & return results |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * Recursively copy directories and files from one directory to another |
|
204 | + * |
|
205 | + * @param string $src - Source of files being moved |
|
206 | + * @param string $dest - Destination of files being moved |
|
207 | + * |
|
208 | + * @uses \Xmf\Module\Helper::getHelper() |
|
209 | + * @uses \Xmf\Module\Helper::isUserAdmin() |
|
210 | + * |
|
211 | + * @return bool true on success |
|
212 | + */ |
|
213 | + public static function rcopy($src, $dest) |
|
214 | + { |
|
215 | + // Only continue if user is a 'global' Admin |
|
216 | + if (!($GLOBALS['xoopsUser'] instanceof XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
217 | + return false; |
|
218 | + } |
|
219 | + |
|
220 | + // If source is not a directory stop processing |
|
221 | + if (!is_dir($src)) { |
|
222 | + return false; |
|
223 | + } |
|
224 | + |
|
225 | + // If the destination directory does not exist and could not be created stop processing |
|
226 | + if (!is_dir($dest) && !mkdir($dest, 0755)) { |
|
227 | + return false; |
|
228 | + } |
|
229 | + |
|
230 | + // Open the source directory to read in files |
|
231 | + $iterator = new DirectoryIterator($src); |
|
232 | + foreach ($iterator as $fObj) { |
|
233 | + if ($fObj->isFile()) { |
|
234 | + copy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
235 | + } elseif (!$fObj->isDot() && $fObj->isDir()) { |
|
236 | + self::rcopy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
237 | + } |
|
238 | + } |
|
239 | + return true; |
|
240 | + } |
|
241 | 241 | } |