@@ -37,195 +37,195 @@ |
||
37 | 37 | |
38 | 38 | switch ($op) { |
39 | 39 | |
40 | - case 'editpage': |
|
41 | - |
|
42 | - // Задание тайтла |
|
43 | - $xoopsOption['xoops_pagetitle'] = ''; |
|
44 | - // Шаблон |
|
45 | - $GLOBALS['xoopsOption']['template_main'] = $moduleDirName . '_editpage.tpl'; |
|
46 | - // Заголовок |
|
47 | - include_once $GLOBALS['xoops']->path('header.php'); |
|
48 | - |
|
49 | - // Если мы редактируем страницу |
|
50 | - if ($pageid) { |
|
51 | - // Получаем объект страницы |
|
52 | - $objInspage = $pageHandler->get($pageid); |
|
53 | - // ID инструкции |
|
54 | - $instrid = $objInspage->getVar('instrid'); |
|
55 | - // Объект инструкции |
|
56 | - $objInsinstr = $instructionHandler->get($instrid); |
|
57 | - // Можно ли редактировать инструкцию в данной категории |
|
58 | - if (!in_array($objInsinstr->getVar('cid'), $cat_edit)) { |
|
59 | - redirect_header('index.php', 3, _MD_INSTRUCTION_NOPERM_EDITPAGE); |
|
60 | - } |
|
61 | - // Создание новой страницы |
|
62 | - } elseif ($instrid) { |
|
63 | - |
|
64 | - // Если нельзя добавлять не в одну категорию |
|
65 | - //if( ! count( $cat_submit ) ) redirect_header( 'index.php', 3, _MD_INSTRUCTION_NOPERM_SUBMIT_PAGE ); |
|
66 | - // Создаём объект страницы |
|
67 | - $objInspage = $pageHandler->create(); |
|
68 | - // Объект инструкции |
|
69 | - $objInsinstr = $instructionHandler->get($instrid); |
|
70 | - // Можно ли добавлять инструкции в данной категории |
|
71 | - if (!in_array($objInsinstr->getVar('cid'), $cat_submit)) { |
|
72 | - redirect_header('index.php', 3, _MD_INSTRUCTION_NOPERM_SUBMITPAGE); |
|
73 | - } |
|
74 | - } else { |
|
75 | - redirect_header('index.php', 3, _MD_INSTRUCTION_BADREQUEST); |
|
76 | - } |
|
77 | - |
|
78 | - // Информация об инструкции |
|
79 | - |
|
80 | - // Массив данных об инструкции |
|
81 | - $instrs = []; |
|
82 | - // ID инструкции |
|
83 | - $instrs['instrid'] = $objInsinstr->getVar('instrid'); |
|
84 | - // Название страницы |
|
85 | - $instrs['title'] = $objInsinstr->getVar('title'); |
|
86 | - // Описание |
|
87 | - $instrs['description'] = $objInsinstr->getVar('description'); |
|
88 | - |
|
89 | - // Выводим в шаблон |
|
90 | - $GLOBALS['xoopsTpl']->assign('insInstr', $instrs); |
|
91 | - |
|
92 | - // |
|
93 | - |
|
94 | - $form = $objInspage->getForm('submit.php', $instrid); |
|
95 | - // Форма |
|
96 | - $GLOBALS['xoopsTpl']->assign('insFormPage', $form->render()); |
|
97 | - |
|
98 | - // Подвал |
|
99 | - include_once $GLOBALS['xoops']->path('footer.php'); |
|
100 | - |
|
101 | - break; |
|
102 | - // Сохранение страницы |
|
103 | - case 'savepage': |
|
104 | - |
|
105 | - // Проверка |
|
106 | - if (!$GLOBALS['xoopsSecurity']->check()) { |
|
107 | - redirect_header('index.php', 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors())); |
|
108 | - } |
|
109 | - |
|
110 | - $err = false; |
|
111 | - $message_err = ''; |
|
112 | - |
|
113 | - // Если мы редактируем |
|
114 | - if ($pageid) { |
|
115 | - $objInspage = $pageHandler->get($pageid); |
|
116 | - // Объект инструкции |
|
117 | - $objInsinstr = $instructionHandler->get($objInspage->getVar('instrid')); |
|
118 | - // Можно ли редактировать инструкцию в данной категории |
|
119 | - if (!in_array($objInsinstr->getVar('cid'), $cat_edit)) { |
|
120 | - redirect_header('index.php', 3, _MD_INSTRUCTION_NOPERM_EDITPAGE); |
|
121 | - } |
|
122 | - } elseif ($instrid) { |
|
123 | - $objInspage = $pageHandler->create(); |
|
124 | - // Объект инструкции |
|
125 | - $objInsinstr = $instructionHandler->get($instrid); |
|
126 | - // Можно ли добавлять инструкции в данной категории |
|
127 | - if (!in_array($objInsinstr->getVar('cid'), $cat_submit)) { |
|
128 | - redirect_header('index.php', 3, _MD_INSTRUCTION_NOPERM_SUBMITPAGE); |
|
129 | - } |
|
130 | - |
|
131 | - // Если мы создаём страницу необходимо указать к какой инструкции |
|
132 | - $objInspage->setVar('instrid', $instrid); |
|
133 | - // Указываем дату создания |
|
134 | - $objInspage->setVar('datecreated', $time); |
|
135 | - // Указываем пользователя |
|
136 | - $objInspage->setVar('uid', $uid); |
|
137 | - } else { |
|
138 | - redirect_header('index.php', 3, _MD_INSTRUCTION_BADREQUEST); |
|
139 | - } |
|
140 | - |
|
141 | - // Родительская страница |
|
142 | - $objInspage->setVar('pid', $pid); |
|
143 | - // Дата обновления |
|
144 | - $objInspage->setVar('dateupdated', $time); |
|
145 | - // |
|
146 | - $objInspage->setVar('title', $_POST['title']); |
|
147 | - $objInspage->setVar('weight', $weight); |
|
148 | - $objInspage->setVar('hometext', $_POST['hometext']); |
|
149 | - // Сноска |
|
150 | - $objInspage->setVar('footnote', $_POST['footnote']); |
|
151 | - $objInspage->setVar('status', $_POST['status']); |
|
152 | - $objInspage->setVar('keywords', $_POST['keywords']); |
|
153 | - $objInspage->setVar('description', $_POST['description']); |
|
154 | - |
|
155 | - // Проверка категорий |
|
156 | - if (!$pageid && !$instrid) { |
|
157 | - $err = true; |
|
158 | - $message_err .= _MD_INSTRUCTION_ERR_INSTR . '<br>'; |
|
159 | - } |
|
160 | - // Проверка веса |
|
161 | - if (0 == $weight) { |
|
162 | - $err = true; |
|
163 | - $message_err .= _MD_INSTRUCTION_ERR_WEIGHT . '<br>'; |
|
164 | - } |
|
165 | - // Проверка родительской страницы |
|
166 | - if ($pageid && ($pageid == $pid)) { |
|
167 | - $err = true; |
|
168 | - $message_err .= _MD_INSTRUCTION_ERR_PPAGE . '<br>'; |
|
169 | - } |
|
170 | - // Если были ошибки |
|
171 | - if (true === $err) { |
|
172 | - // Задание тайтла |
|
173 | - $xoopsOption['xoops_pagetitle'] = ''; |
|
174 | - // Шаблон |
|
175 | - $GLOBALS['xoopsOption']['template_main'] = $moduleDirName . '_savepage.tpl'; |
|
176 | - // Заголовок |
|
177 | - include_once $GLOBALS['xoops']->path('header.php'); |
|
178 | - // Сообщение об ошибке |
|
179 | - $message_err = '<div class="errorMsg" style="text-align: left;">' . $message_err . '</div>'; |
|
180 | - // Выводим ошибки в шаблон |
|
181 | - $GLOBALS['xoopsTpl']->assign('insErrorMsg', $message_err); |
|
182 | - // Если небыло ошибок |
|
183 | - } else { |
|
184 | - // Вставляем данные в БД |
|
185 | - if ($pageHandler->insert($objInspage)) { |
|
186 | - // Если мы редактируем |
|
187 | - if ($pageid) { |
|
188 | - // Обновление даты |
|
189 | - $sql = sprintf('UPDATE %s SET `dateupdated` = %u WHERE `instrid` = %u', $GLOBALS['xoopsDB']->prefix($moduleDirName . '_instr'), $time, $instrid); |
|
190 | - $GLOBALS['xoopsDB']->query($sql); |
|
191 | - // Запись в лог |
|
192 | - xoops_loadLanguage('main', 'userslog'); |
|
193 | - //userslog_insert( $objInsinstr->getVar('title') . ': ' . $objInspage->getVar('title'), _MD_USERSLOG_MODIFY_PAGE ); |
|
194 | - // |
|
195 | - redirect_header('index.php', 3, _MD_INSTRUCTION_PAGEMODIFY); |
|
196 | - // Если мы добавляем |
|
197 | - } else { |
|
198 | - // Инкримент комментов |
|
199 | - $pageHandler->updateposts($uid, $_POST['status'], 'add'); |
|
200 | - // Инкремент страниц и обновление даты |
|
201 | - $sql = sprintf('UPDATE %s SET `pages` = `pages` + 1, `dateupdated` = %u WHERE `instrid` = %u', $GLOBALS['xoopsDB']->prefix($moduleDirName . '_instr'), $time, $instrid); |
|
202 | - $GLOBALS['xoopsDB']->query($sql); |
|
203 | - // Запись в лог |
|
204 | - xoops_loadLanguage('main', 'userslog'); |
|
205 | - //userslog_insert( $objInsinstr->getVar('title') . ': ' . $objInspage->getVar('title'), _MD_USERSLOG_SUBMIT_PAGE ); |
|
206 | - // |
|
207 | - redirect_header('index.php', 3, _MD_INSTRUCTION_PAGEADDED); |
|
208 | - } |
|
209 | - } |
|
210 | - |
|
211 | - // Задание тайтла |
|
212 | - $xoopsOption['xoops_pagetitle'] = ''; |
|
213 | - // Шаблон |
|
214 | - $GLOBALS['xoopsOption']['template_main'] = $moduleDirName . '_savepage.tpl'; |
|
215 | - // Заголовок |
|
216 | - include_once $GLOBALS['xoops']->path('header.php'); |
|
217 | - |
|
218 | - // Выводим ошибки в шаблон |
|
219 | - $GLOBALS['xoopsTpl']->assign('insErrorMsg', $objInspage->getHtmlErrors()); |
|
220 | - } |
|
221 | - // Получаем форму |
|
222 | - $form = $objInspage->getForm('submit.php', $instrid); |
|
223 | - |
|
224 | - // Форма |
|
225 | - $GLOBALS['xoopsTpl']->assign('insFormPage', $form->render()); |
|
226 | - |
|
227 | - // Подвал |
|
228 | - include_once $GLOBALS['xoops']->path('footer.php'); |
|
229 | - |
|
230 | - break; |
|
40 | + case 'editpage': |
|
41 | + |
|
42 | + // Задание тайтла |
|
43 | + $xoopsOption['xoops_pagetitle'] = ''; |
|
44 | + // Шаблон |
|
45 | + $GLOBALS['xoopsOption']['template_main'] = $moduleDirName . '_editpage.tpl'; |
|
46 | + // Заголовок |
|
47 | + include_once $GLOBALS['xoops']->path('header.php'); |
|
48 | + |
|
49 | + // Если мы редактируем страницу |
|
50 | + if ($pageid) { |
|
51 | + // Получаем объект страницы |
|
52 | + $objInspage = $pageHandler->get($pageid); |
|
53 | + // ID инструкции |
|
54 | + $instrid = $objInspage->getVar('instrid'); |
|
55 | + // Объект инструкции |
|
56 | + $objInsinstr = $instructionHandler->get($instrid); |
|
57 | + // Можно ли редактировать инструкцию в данной категории |
|
58 | + if (!in_array($objInsinstr->getVar('cid'), $cat_edit)) { |
|
59 | + redirect_header('index.php', 3, _MD_INSTRUCTION_NOPERM_EDITPAGE); |
|
60 | + } |
|
61 | + // Создание новой страницы |
|
62 | + } elseif ($instrid) { |
|
63 | + |
|
64 | + // Если нельзя добавлять не в одну категорию |
|
65 | + //if( ! count( $cat_submit ) ) redirect_header( 'index.php', 3, _MD_INSTRUCTION_NOPERM_SUBMIT_PAGE ); |
|
66 | + // Создаём объект страницы |
|
67 | + $objInspage = $pageHandler->create(); |
|
68 | + // Объект инструкции |
|
69 | + $objInsinstr = $instructionHandler->get($instrid); |
|
70 | + // Можно ли добавлять инструкции в данной категории |
|
71 | + if (!in_array($objInsinstr->getVar('cid'), $cat_submit)) { |
|
72 | + redirect_header('index.php', 3, _MD_INSTRUCTION_NOPERM_SUBMITPAGE); |
|
73 | + } |
|
74 | + } else { |
|
75 | + redirect_header('index.php', 3, _MD_INSTRUCTION_BADREQUEST); |
|
76 | + } |
|
77 | + |
|
78 | + // Информация об инструкции |
|
79 | + |
|
80 | + // Массив данных об инструкции |
|
81 | + $instrs = []; |
|
82 | + // ID инструкции |
|
83 | + $instrs['instrid'] = $objInsinstr->getVar('instrid'); |
|
84 | + // Название страницы |
|
85 | + $instrs['title'] = $objInsinstr->getVar('title'); |
|
86 | + // Описание |
|
87 | + $instrs['description'] = $objInsinstr->getVar('description'); |
|
88 | + |
|
89 | + // Выводим в шаблон |
|
90 | + $GLOBALS['xoopsTpl']->assign('insInstr', $instrs); |
|
91 | + |
|
92 | + // |
|
93 | + |
|
94 | + $form = $objInspage->getForm('submit.php', $instrid); |
|
95 | + // Форма |
|
96 | + $GLOBALS['xoopsTpl']->assign('insFormPage', $form->render()); |
|
97 | + |
|
98 | + // Подвал |
|
99 | + include_once $GLOBALS['xoops']->path('footer.php'); |
|
100 | + |
|
101 | + break; |
|
102 | + // Сохранение страницы |
|
103 | + case 'savepage': |
|
104 | + |
|
105 | + // Проверка |
|
106 | + if (!$GLOBALS['xoopsSecurity']->check()) { |
|
107 | + redirect_header('index.php', 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors())); |
|
108 | + } |
|
109 | + |
|
110 | + $err = false; |
|
111 | + $message_err = ''; |
|
112 | + |
|
113 | + // Если мы редактируем |
|
114 | + if ($pageid) { |
|
115 | + $objInspage = $pageHandler->get($pageid); |
|
116 | + // Объект инструкции |
|
117 | + $objInsinstr = $instructionHandler->get($objInspage->getVar('instrid')); |
|
118 | + // Можно ли редактировать инструкцию в данной категории |
|
119 | + if (!in_array($objInsinstr->getVar('cid'), $cat_edit)) { |
|
120 | + redirect_header('index.php', 3, _MD_INSTRUCTION_NOPERM_EDITPAGE); |
|
121 | + } |
|
122 | + } elseif ($instrid) { |
|
123 | + $objInspage = $pageHandler->create(); |
|
124 | + // Объект инструкции |
|
125 | + $objInsinstr = $instructionHandler->get($instrid); |
|
126 | + // Можно ли добавлять инструкции в данной категории |
|
127 | + if (!in_array($objInsinstr->getVar('cid'), $cat_submit)) { |
|
128 | + redirect_header('index.php', 3, _MD_INSTRUCTION_NOPERM_SUBMITPAGE); |
|
129 | + } |
|
130 | + |
|
131 | + // Если мы создаём страницу необходимо указать к какой инструкции |
|
132 | + $objInspage->setVar('instrid', $instrid); |
|
133 | + // Указываем дату создания |
|
134 | + $objInspage->setVar('datecreated', $time); |
|
135 | + // Указываем пользователя |
|
136 | + $objInspage->setVar('uid', $uid); |
|
137 | + } else { |
|
138 | + redirect_header('index.php', 3, _MD_INSTRUCTION_BADREQUEST); |
|
139 | + } |
|
140 | + |
|
141 | + // Родительская страница |
|
142 | + $objInspage->setVar('pid', $pid); |
|
143 | + // Дата обновления |
|
144 | + $objInspage->setVar('dateupdated', $time); |
|
145 | + // |
|
146 | + $objInspage->setVar('title', $_POST['title']); |
|
147 | + $objInspage->setVar('weight', $weight); |
|
148 | + $objInspage->setVar('hometext', $_POST['hometext']); |
|
149 | + // Сноска |
|
150 | + $objInspage->setVar('footnote', $_POST['footnote']); |
|
151 | + $objInspage->setVar('status', $_POST['status']); |
|
152 | + $objInspage->setVar('keywords', $_POST['keywords']); |
|
153 | + $objInspage->setVar('description', $_POST['description']); |
|
154 | + |
|
155 | + // Проверка категорий |
|
156 | + if (!$pageid && !$instrid) { |
|
157 | + $err = true; |
|
158 | + $message_err .= _MD_INSTRUCTION_ERR_INSTR . '<br>'; |
|
159 | + } |
|
160 | + // Проверка веса |
|
161 | + if (0 == $weight) { |
|
162 | + $err = true; |
|
163 | + $message_err .= _MD_INSTRUCTION_ERR_WEIGHT . '<br>'; |
|
164 | + } |
|
165 | + // Проверка родительской страницы |
|
166 | + if ($pageid && ($pageid == $pid)) { |
|
167 | + $err = true; |
|
168 | + $message_err .= _MD_INSTRUCTION_ERR_PPAGE . '<br>'; |
|
169 | + } |
|
170 | + // Если были ошибки |
|
171 | + if (true === $err) { |
|
172 | + // Задание тайтла |
|
173 | + $xoopsOption['xoops_pagetitle'] = ''; |
|
174 | + // Шаблон |
|
175 | + $GLOBALS['xoopsOption']['template_main'] = $moduleDirName . '_savepage.tpl'; |
|
176 | + // Заголовок |
|
177 | + include_once $GLOBALS['xoops']->path('header.php'); |
|
178 | + // Сообщение об ошибке |
|
179 | + $message_err = '<div class="errorMsg" style="text-align: left;">' . $message_err . '</div>'; |
|
180 | + // Выводим ошибки в шаблон |
|
181 | + $GLOBALS['xoopsTpl']->assign('insErrorMsg', $message_err); |
|
182 | + // Если небыло ошибок |
|
183 | + } else { |
|
184 | + // Вставляем данные в БД |
|
185 | + if ($pageHandler->insert($objInspage)) { |
|
186 | + // Если мы редактируем |
|
187 | + if ($pageid) { |
|
188 | + // Обновление даты |
|
189 | + $sql = sprintf('UPDATE %s SET `dateupdated` = %u WHERE `instrid` = %u', $GLOBALS['xoopsDB']->prefix($moduleDirName . '_instr'), $time, $instrid); |
|
190 | + $GLOBALS['xoopsDB']->query($sql); |
|
191 | + // Запись в лог |
|
192 | + xoops_loadLanguage('main', 'userslog'); |
|
193 | + //userslog_insert( $objInsinstr->getVar('title') . ': ' . $objInspage->getVar('title'), _MD_USERSLOG_MODIFY_PAGE ); |
|
194 | + // |
|
195 | + redirect_header('index.php', 3, _MD_INSTRUCTION_PAGEMODIFY); |
|
196 | + // Если мы добавляем |
|
197 | + } else { |
|
198 | + // Инкримент комментов |
|
199 | + $pageHandler->updateposts($uid, $_POST['status'], 'add'); |
|
200 | + // Инкремент страниц и обновление даты |
|
201 | + $sql = sprintf('UPDATE %s SET `pages` = `pages` + 1, `dateupdated` = %u WHERE `instrid` = %u', $GLOBALS['xoopsDB']->prefix($moduleDirName . '_instr'), $time, $instrid); |
|
202 | + $GLOBALS['xoopsDB']->query($sql); |
|
203 | + // Запись в лог |
|
204 | + xoops_loadLanguage('main', 'userslog'); |
|
205 | + //userslog_insert( $objInsinstr->getVar('title') . ': ' . $objInspage->getVar('title'), _MD_USERSLOG_SUBMIT_PAGE ); |
|
206 | + // |
|
207 | + redirect_header('index.php', 3, _MD_INSTRUCTION_PAGEADDED); |
|
208 | + } |
|
209 | + } |
|
210 | + |
|
211 | + // Задание тайтла |
|
212 | + $xoopsOption['xoops_pagetitle'] = ''; |
|
213 | + // Шаблон |
|
214 | + $GLOBALS['xoopsOption']['template_main'] = $moduleDirName . '_savepage.tpl'; |
|
215 | + // Заголовок |
|
216 | + include_once $GLOBALS['xoops']->path('header.php'); |
|
217 | + |
|
218 | + // Выводим ошибки в шаблон |
|
219 | + $GLOBALS['xoopsTpl']->assign('insErrorMsg', $objInspage->getHtmlErrors()); |
|
220 | + } |
|
221 | + // Получаем форму |
|
222 | + $form = $objInspage->getForm('submit.php', $instrid); |
|
223 | + |
|
224 | + // Форма |
|
225 | + $GLOBALS['xoopsTpl']->assign('insFormPage', $form->render()); |
|
226 | + |
|
227 | + // Подвал |
|
228 | + include_once $GLOBALS['xoops']->path('footer.php'); |
|
229 | + |
|
230 | + break; |
|
231 | 231 | } |
@@ -29,8 +29,8 @@ discard block |
||
29 | 29 | $criteria->add(new \Criteria('pageid ', $pageid)); |
30 | 30 | $criteria->add(new \Criteria('status ', '0', '>')); |
31 | 31 | if (0 == $pageHandler->getCount($criteria)) { |
32 | - redirect_header('index.php', 3, _MD_INSTRUCTION_PAGENOTEXIST); |
|
33 | - exit(); |
|
32 | + redirect_header('index.php', 3, _MD_INSTRUCTION_PAGENOTEXIST); |
|
33 | + exit(); |
|
34 | 34 | } |
35 | 35 | // |
36 | 36 | unset($criteria); |
@@ -42,8 +42,8 @@ discard block |
||
42 | 42 | |
43 | 43 | // Если админ и ссылка на отключение кэша |
44 | 44 | if (is_object($GLOBALS['xoopsUser']) && $GLOBALS['xoopsUser']->isAdmin() && $nocache) { |
45 | - // Отключаем кэш |
|
46 | - $GLOBALS['xoopsConfig']['module_cache'][$GLOBALS['xoopsModule']->getVar('mid')] = 0; |
|
45 | + // Отключаем кэш |
|
46 | + $GLOBALS['xoopsConfig']['module_cache'][$GLOBALS['xoopsModule']->getVar('mid')] = 0; |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | // Задание тайтла |
@@ -60,8 +60,8 @@ discard block |
||
60 | 60 | // Права на просмотр инструкции |
61 | 61 | $categories = Xoopsmodules\instruction\Utility::getItemIds(); |
62 | 62 | if (!in_array($objInsinstr->getVar('cid'), $categories)) { |
63 | - redirect_header(XOOPS_URL . '/modules/' . $moduleDirName . '/', 3, _NOPERM); |
|
64 | - exit(); |
|
63 | + redirect_header(XOOPS_URL . '/modules/' . $moduleDirName . '/', 3, _NOPERM); |
|
64 | + exit(); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | // Массив данных о странице |
@@ -78,9 +78,9 @@ discard block |
||
78 | 78 | $footnote = $objInspage->getVar('footnote'); |
79 | 79 | // Если есть сноски |
80 | 80 | if ($footnote) { |
81 | - $pages['footnotes'] = explode('|', $objInspage->getVar('footnote')); |
|
81 | + $pages['footnotes'] = explode('|', $objInspage->getVar('footnote')); |
|
82 | 82 | } else { |
83 | - $pages['footnotes'] = false; |
|
83 | + $pages['footnotes'] = false; |
|
84 | 84 | } |
85 | 85 | // Мета-теги ключевых слов |
86 | 86 | $pages['keywords'] = $objInspage->getVar('keywords'); |
@@ -89,39 +89,39 @@ discard block |
||
89 | 89 | // |
90 | 90 | // Если админ, рисуем админлинк |
91 | 91 | if (is_object($GLOBALS['xoopsUser']) && $GLOBALS['xoopsUser']->isAdmin($GLOBALS['xoopsModule']->mid())) { |
92 | - $pages['adminlink'] = ' <a href="' |
|
93 | - . XOOPS_URL |
|
94 | - . '/modules/' |
|
95 | - . $moduleDirName |
|
96 | - . '/admin/instr.php?op=editpage&pageid=' |
|
97 | - . $pages['pageid'] |
|
98 | - . '"><img style="width:16px;" src="./assets/icons/edit_mini.png" alt=' |
|
99 | - . _EDIT |
|
100 | - . ' title=' |
|
101 | - . _EDIT |
|
102 | - . '></a> <a href="' |
|
103 | - . XOOPS_URL |
|
104 | - . '/modules/' |
|
105 | - . $moduleDirName |
|
106 | - . '/admin/instr.php?op=delpage&pageid=' |
|
107 | - . $pages['pageid'] |
|
108 | - . '"><img style="width:16px;" src="./assets/icons/delete_mini.png" alt=' |
|
109 | - . _DELETE |
|
110 | - . ' title=' |
|
111 | - . _DELETE |
|
112 | - . '></a> '; |
|
92 | + $pages['adminlink'] = ' <a href="' |
|
93 | + . XOOPS_URL |
|
94 | + . '/modules/' |
|
95 | + . $moduleDirName |
|
96 | + . '/admin/instr.php?op=editpage&pageid=' |
|
97 | + . $pages['pageid'] |
|
98 | + . '"><img style="width:16px;" src="./assets/icons/edit_mini.png" alt=' |
|
99 | + . _EDIT |
|
100 | + . ' title=' |
|
101 | + . _EDIT |
|
102 | + . '></a> <a href="' |
|
103 | + . XOOPS_URL |
|
104 | + . '/modules/' |
|
105 | + . $moduleDirName |
|
106 | + . '/admin/instr.php?op=delpage&pageid=' |
|
107 | + . $pages['pageid'] |
|
108 | + . '"><img style="width:16px;" src="./assets/icons/delete_mini.png" alt=' |
|
109 | + . _DELETE |
|
110 | + . ' title=' |
|
111 | + . _DELETE |
|
112 | + . '></a> '; |
|
113 | 113 | } else { |
114 | - $pages['adminlink'] = ' '; |
|
115 | - // Если можно редактировать |
|
116 | - if ($gpermHandler->checkRight($moduleDirName . '_edit', $objInsinstr->getVar('cid'), $groups, $GLOBALS['xoopsModule']->getVar('mid'))) { |
|
117 | - $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>'; |
|
118 | - } |
|
119 | - |
|
120 | - $pages['adminlink'] .= ' '; |
|
121 | - // Если нет админлика |
|
122 | - if ('[ ]' === $pages['adminlink']) { |
|
123 | - $pages['adminlink'] = ''; |
|
124 | - } |
|
114 | + $pages['adminlink'] = ' '; |
|
115 | + // Если можно редактировать |
|
116 | + if ($gpermHandler->checkRight($moduleDirName . '_edit', $objInsinstr->getVar('cid'), $groups, $GLOBALS['xoopsModule']->getVar('mid'))) { |
|
117 | + $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>'; |
|
118 | + } |
|
119 | + |
|
120 | + $pages['adminlink'] .= ' '; |
|
121 | + // Если нет админлика |
|
122 | + if ('[ ]' === $pages['adminlink']) { |
|
123 | + $pages['adminlink'] = ''; |
|
124 | + } |
|
125 | 125 | } |
126 | 126 | // Выводим в шаблон |
127 | 127 | $GLOBALS['xoopsTpl']->assign('insPage', $pages); |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | $nav_parent_id = array_reverse($nav_parent_id); |
141 | 141 | $navigation = '<a href="' . XOOPS_URL . '/modules/' . $moduleDirName . '/">' . $GLOBALS['xoopsModule']->name() . '</a> : '; |
142 | 142 | foreach (array_keys($nav_parent_id) as $i) { |
143 | - $navigation .= '<a href="' . XOOPS_URL . '/modules/' . $moduleDirName . '/index.php?cid=' . $nav_parent_id[$i]->getVar('cid') . '">' . $nav_parent_id[$i]->getVar('title') . '</a> : '; |
|
143 | + $navigation .= '<a href="' . XOOPS_URL . '/modules/' . $moduleDirName . '/index.php?cid=' . $nav_parent_id[$i]->getVar('cid') . '">' . $nav_parent_id[$i]->getVar('title') . '</a> : '; |
|
144 | 144 | } |
145 | 145 | $navigation .= '<a href="' . XOOPS_URL . '/modules/' . $moduleDirName . '/index.php?cid=' . $objInscat->getVar('cid') . '">' . $objInscat->getVar('title') . '</a> : '; |
146 | 146 | $navigation .= '<a href="' . XOOPS_URL . '/modules/' . $moduleDirName . '/instr.php?id=' . $pages['instrid'] . '">' . $objInsinstr->getVar('title') . '</a>'; |
@@ -172,9 +172,9 @@ discard block |
||
172 | 172 | |
173 | 173 | // Рейтинг |
174 | 174 | if (xoops_getModuleOption('userat', 'instruction')) { |
175 | - $xoopsTpl->assign('insUserat', true); |
|
175 | + $xoopsTpl->assign('insUserat', true); |
|
176 | 176 | } else { |
177 | - $xoopsTpl->assign('insUserat', false); |
|
177 | + $xoopsTpl->assign('insUserat', false); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | // Мета теги |
@@ -22,12 +22,12 @@ |
||
22 | 22 | */ |
23 | 23 | class InstructionCorePreload extends XoopsPreloadItem |
24 | 24 | { |
25 | - // to add PSR-4 autoloader |
|
26 | - /** |
|
27 | - * @param $args |
|
28 | - */ |
|
29 | - public static function eventCoreIncludeCommonEnd($args) |
|
30 | - { |
|
31 | - include __DIR__ . '/autoloader.php'; |
|
32 | - } |
|
25 | + // to add PSR-4 autoloader |
|
26 | + /** |
|
27 | + * @param $args |
|
28 | + */ |
|
29 | + public static function eventCoreIncludeCommonEnd($args) |
|
30 | + { |
|
31 | + include __DIR__ . '/autoloader.php'; |
|
32 | + } |
|
33 | 33 | } |
@@ -4,29 +4,29 @@ |
||
4 | 4 | * @see http://www.php-fig.org/psr/psr-4/examples/ |
5 | 5 | */ |
6 | 6 | spl_autoload_register(function ($class) { |
7 | - // project-specific namespace prefix |
|
8 | - $prefix = 'Xoopsmodules\\instruction\\'; |
|
7 | + // project-specific namespace prefix |
|
8 | + $prefix = 'Xoopsmodules\\instruction\\'; |
|
9 | 9 | |
10 | - // base directory for the namespace prefix |
|
11 | - $base_dir = __DIR__ . '/../class/'; |
|
10 | + // base directory for the namespace prefix |
|
11 | + $base_dir = __DIR__ . '/../class/'; |
|
12 | 12 | |
13 | - // does the class use the namespace prefix? |
|
14 | - $len = strlen($prefix); |
|
13 | + // does the class use the namespace prefix? |
|
14 | + $len = strlen($prefix); |
|
15 | 15 | |
16 | - if (0 !== strncmp($prefix, $class, $len)) { |
|
17 | - return; |
|
18 | - } |
|
16 | + if (0 !== strncmp($prefix, $class, $len)) { |
|
17 | + return; |
|
18 | + } |
|
19 | 19 | |
20 | - // get the relative class name |
|
21 | - $relative_class = substr($class, $len); |
|
20 | + // get the relative class name |
|
21 | + $relative_class = substr($class, $len); |
|
22 | 22 | |
23 | - // replace the namespace prefix with the base directory, replace namespace |
|
24 | - // separators with directory separators in the relative class name, append |
|
25 | - // with .php |
|
26 | - $file = $base_dir . str_replace('\\', '/', $relative_class) . '.php'; |
|
23 | + // replace the namespace prefix with the base directory, replace namespace |
|
24 | + // separators with directory separators in the relative class name, append |
|
25 | + // with .php |
|
26 | + $file = $base_dir . str_replace('\\', '/', $relative_class) . '.php'; |
|
27 | 27 | |
28 | - // if the file exists, require it |
|
29 | - if (file_exists($file)) { |
|
30 | - require $file; |
|
31 | - } |
|
28 | + // if the file exists, require it |
|
29 | + if (file_exists($file)) { |
|
30 | + require $file; |
|
31 | + } |
|
32 | 32 | }); |
@@ -48,11 +48,11 @@ discard block |
||
48 | 48 | $module = $helper->getModule(); |
49 | 49 | |
50 | 50 | if (Xoopsmodules\instruction\Utility::checkVerXoops($module, '2.5.9')) { |
51 | - $cat_select = $mytree->makeSelectElement('cid', 'title', '--', $cid, true, 0, "onChange='javascript: document.insformselcat.submit()'", ''); |
|
52 | - $GLOBALS['xoopsTpl']->assign('insFormSelCat', $cat_select->render()); |
|
51 | + $cat_select = $mytree->makeSelectElement('cid', 'title', '--', $cid, true, 0, "onChange='javascript: document.insformselcat.submit()'", ''); |
|
52 | + $GLOBALS['xoopsTpl']->assign('insFormSelCat', $cat_select->render()); |
|
53 | 53 | } else { |
54 | - $cat_select = $mytree->makeSelBox('cid', 'title', '--', $cid, true, 0, "onChange='javascript: document.insformselcat.submit()'"); |
|
55 | - $GLOBALS['xoopsTpl']->assign('insFormSelCat', $cat_select); |
|
54 | + $cat_select = $mytree->makeSelBox('cid', 'title', '--', $cid, true, 0, "onChange='javascript: document.insformselcat.submit()'"); |
|
55 | + $GLOBALS['xoopsTpl']->assign('insFormSelCat', $cat_select); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | // Находим список всех инструкций |
@@ -62,14 +62,14 @@ discard block |
||
62 | 62 | $criteria->add(new \Criteria('status', '0', '>')); |
63 | 63 | // Если есть категория |
64 | 64 | if ($cid) { |
65 | - // Если нельзя просматривать эту категорию |
|
66 | - if (!in_array($cid, $categories)) { |
|
67 | - redirect_header('index.php', 3, _MD_INSTRUCTION_NOPERM_CAT); |
|
68 | - } |
|
69 | - $criteria->add(new \Criteria('cid', $cid, '=')); |
|
70 | - // Иначе находим список всех |
|
65 | + // Если нельзя просматривать эту категорию |
|
66 | + if (!in_array($cid, $categories)) { |
|
67 | + redirect_header('index.php', 3, _MD_INSTRUCTION_NOPERM_CAT); |
|
68 | + } |
|
69 | + $criteria->add(new \Criteria('cid', $cid, '=')); |
|
70 | + // Иначе находим список всех |
|
71 | 71 | } else { |
72 | - $criteria->add(new \Criteria('cid', '( ' . implode(', ', $categories) . ' )', 'IN')); |
|
72 | + $criteria->add(new \Criteria('cid', '( ' . implode(', ', $categories) . ' )', 'IN')); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | // Число инструкций, удовлетворяющих данному условию |
@@ -86,10 +86,10 @@ discard block |
||
86 | 86 | $instr_arr = $instructionHandler->getall($criteria); |
87 | 87 | // Если записей больше чем $limit, то выводим пагинатор |
88 | 88 | if ($numrows > $limit) { |
89 | - $pagenav = new \XoopsPageNav($numrows, $limit, $start, 'start', 'cid=' . $cid); |
|
90 | - $pagenav = $pagenav->renderNav(4); |
|
89 | + $pagenav = new \XoopsPageNav($numrows, $limit, $start, 'start', 'cid=' . $cid); |
|
90 | + $pagenav = $pagenav->renderNav(4); |
|
91 | 91 | } else { |
92 | - $pagenav = ''; |
|
92 | + $pagenav = ''; |
|
93 | 93 | } |
94 | 94 | // Выводим пагинатор в шаблон |
95 | 95 | $GLOBALS['xoopsTpl']->assign('insPagenav', $pagenav); |
@@ -100,53 +100,53 @@ discard block |
||
100 | 100 | |
101 | 101 | // Если есть записи |
102 | 102 | if ($numrows > 0) { |
103 | - $class = 'odd'; |
|
104 | - foreach (array_keys($instr_arr) as $i) { |
|
105 | - |
|
106 | - // |
|
107 | - $class = ('even' === $class) ? 'odd' : 'even'; |
|
108 | - // ID |
|
109 | - $insinstr_instrid = $instr_arr[$i]->getVar('instrid'); |
|
110 | - // Название |
|
111 | - $insinstr_title = $instr_arr[$i]->getVar('title'); |
|
112 | - // Статус |
|
113 | - $insinstr_status = $instr_arr[$i]->getVar('status'); |
|
114 | - // Количество страниц |
|
115 | - $insinstr_pages = $instr_arr[$i]->getVar('pages'); |
|
116 | - // Категория |
|
117 | - $insinstr_cid = $instr_arr[$i]->getVar('cid'); |
|
118 | - $insinstr_cat = $categoryHandler->get($insinstr_cid); |
|
119 | - // Права на добавление |
|
120 | - $perm_submit = in_array($insinstr_cid, $cat_submit) ? true : false; |
|
121 | - // Права на редактирование |
|
122 | - $perm_edit = in_array($insinstr_cid, $cat_edit) ? true : false; |
|
123 | - //Мета-теги ключевых слов |
|
124 | - $insinstr_metakeywords = $instr_arr[$i]->getVar('metakeywords'); |
|
125 | - // Если есть - добавляем в мета-теги страницы |
|
126 | - if ($insinstr_metakeywords) { |
|
127 | - $index_metakeywords[] = $insinstr_metakeywords; |
|
128 | - } |
|
129 | - // Мета-теги описания |
|
130 | - $insinstr_metadescript = $instr_arr[$i]->getVar('metadescription'); |
|
131 | - // Если есть - добавляем в мета-теги страницы |
|
132 | - if ($insinstr_metadescript) { |
|
133 | - $index_metadescript[] = $insinstr_metadescript; |
|
134 | - } |
|
135 | - |
|
136 | - // Выводим в шаблон |
|
137 | - $GLOBALS['xoopsTpl']->append('insListInstr', |
|
138 | - ['instrid' => $insinstr_instrid, 'title' => $insinstr_title, 'status' => $insinstr_status, 'pages' => $insinstr_pages, 'ctitle' => $insinstr_cat->getVar('title'), 'cid' => $insinstr_cid, 'permsubmit' => $perm_submit, 'permedit' => $perm_edit, 'class' => $class]); |
|
139 | - } |
|
140 | - |
|
141 | - // Языковые константы |
|
103 | + $class = 'odd'; |
|
104 | + foreach (array_keys($instr_arr) as $i) { |
|
105 | + |
|
106 | + // |
|
107 | + $class = ('even' === $class) ? 'odd' : 'even'; |
|
108 | + // ID |
|
109 | + $insinstr_instrid = $instr_arr[$i]->getVar('instrid'); |
|
110 | + // Название |
|
111 | + $insinstr_title = $instr_arr[$i]->getVar('title'); |
|
112 | + // Статус |
|
113 | + $insinstr_status = $instr_arr[$i]->getVar('status'); |
|
114 | + // Количество страниц |
|
115 | + $insinstr_pages = $instr_arr[$i]->getVar('pages'); |
|
116 | + // Категория |
|
117 | + $insinstr_cid = $instr_arr[$i]->getVar('cid'); |
|
118 | + $insinstr_cat = $categoryHandler->get($insinstr_cid); |
|
119 | + // Права на добавление |
|
120 | + $perm_submit = in_array($insinstr_cid, $cat_submit) ? true : false; |
|
121 | + // Права на редактирование |
|
122 | + $perm_edit = in_array($insinstr_cid, $cat_edit) ? true : false; |
|
123 | + //Мета-теги ключевых слов |
|
124 | + $insinstr_metakeywords = $instr_arr[$i]->getVar('metakeywords'); |
|
125 | + // Если есть - добавляем в мета-теги страницы |
|
126 | + if ($insinstr_metakeywords) { |
|
127 | + $index_metakeywords[] = $insinstr_metakeywords; |
|
128 | + } |
|
129 | + // Мета-теги описания |
|
130 | + $insinstr_metadescript = $instr_arr[$i]->getVar('metadescription'); |
|
131 | + // Если есть - добавляем в мета-теги страницы |
|
132 | + if ($insinstr_metadescript) { |
|
133 | + $index_metadescript[] = $insinstr_metadescript; |
|
134 | + } |
|
135 | + |
|
136 | + // Выводим в шаблон |
|
137 | + $GLOBALS['xoopsTpl']->append('insListInstr', |
|
138 | + ['instrid' => $insinstr_instrid, 'title' => $insinstr_title, 'status' => $insinstr_status, 'pages' => $insinstr_pages, 'ctitle' => $insinstr_cat->getVar('title'), 'cid' => $insinstr_cid, 'permsubmit' => $perm_submit, 'permedit' => $perm_edit, 'class' => $class]); |
|
139 | + } |
|
140 | + |
|
141 | + // Языковые константы |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | // Если есть мета-теги |
145 | 145 | if (count($index_metakeywords)) { |
146 | - $xoTheme->addMeta('meta', 'keywords', implode(', ', $index_metakeywords)); |
|
146 | + $xoTheme->addMeta('meta', 'keywords', implode(', ', $index_metakeywords)); |
|
147 | 147 | } |
148 | 148 | if (count($index_metadescript)) { |
149 | - $xoTheme->addMeta('meta', 'description', implode(', ', $index_metadescript)); |
|
149 | + $xoTheme->addMeta('meta', 'description', implode(', ', $index_metadescript)); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | // Подвал |
@@ -17,77 +17,77 @@ |
||
17 | 17 | */ |
18 | 18 | trait VersionChecks |
19 | 19 | { |
20 | - /** |
|
21 | - * |
|
22 | - * Verifies XOOPS version meets minimum requirements for this module |
|
23 | - * @static |
|
24 | - * @param \XoopsModule|null $module |
|
25 | - * |
|
26 | - * @param null|string $requiredVer |
|
27 | - * @return bool true if meets requirements, false if not |
|
28 | - */ |
|
29 | - public static function checkVerXoops(\XoopsModule $module = null, $requiredVer = null) |
|
30 | - { |
|
31 | - $moduleDirName = basename(dirname(dirname(__DIR__))); |
|
32 | - if (null === $module) { |
|
33 | - $module = \XoopsModule::getByDirname($moduleDirName); |
|
34 | - } |
|
35 | - xoops_loadLanguage('admin', $moduleDirName); |
|
36 | - //check for minimum XOOPS version |
|
37 | - $currentVer = substr(XOOPS_VERSION, 6); // get the numeric part of string |
|
38 | - $currArray = explode('.', $currentVer); |
|
39 | - if (null === $requiredVer) { |
|
40 | - $requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string |
|
41 | - } |
|
42 | - $reqArray = explode('.', $requiredVer); |
|
43 | - $success = true; |
|
44 | - foreach ($reqArray as $k => $v) { |
|
45 | - if (isset($currArray[$k])) { |
|
46 | - if ($currArray[$k] > $v) { |
|
47 | - break; |
|
48 | - } elseif ($currArray[$k] == $v) { |
|
49 | - continue; |
|
50 | - } else { |
|
51 | - $success = false; |
|
52 | - break; |
|
53 | - } |
|
54 | - } else { |
|
55 | - if ((int)$v > 0) { // handles versions like x.x.x.0_RC2 |
|
56 | - $success = false; |
|
57 | - break; |
|
58 | - } |
|
59 | - } |
|
60 | - } |
|
20 | + /** |
|
21 | + * |
|
22 | + * Verifies XOOPS version meets minimum requirements for this module |
|
23 | + * @static |
|
24 | + * @param \XoopsModule|null $module |
|
25 | + * |
|
26 | + * @param null|string $requiredVer |
|
27 | + * @return bool true if meets requirements, false if not |
|
28 | + */ |
|
29 | + public static function checkVerXoops(\XoopsModule $module = null, $requiredVer = null) |
|
30 | + { |
|
31 | + $moduleDirName = basename(dirname(dirname(__DIR__))); |
|
32 | + if (null === $module) { |
|
33 | + $module = \XoopsModule::getByDirname($moduleDirName); |
|
34 | + } |
|
35 | + xoops_loadLanguage('admin', $moduleDirName); |
|
36 | + //check for minimum XOOPS version |
|
37 | + $currentVer = substr(XOOPS_VERSION, 6); // get the numeric part of string |
|
38 | + $currArray = explode('.', $currentVer); |
|
39 | + if (null === $requiredVer) { |
|
40 | + $requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string |
|
41 | + } |
|
42 | + $reqArray = explode('.', $requiredVer); |
|
43 | + $success = true; |
|
44 | + foreach ($reqArray as $k => $v) { |
|
45 | + if (isset($currArray[$k])) { |
|
46 | + if ($currArray[$k] > $v) { |
|
47 | + break; |
|
48 | + } elseif ($currArray[$k] == $v) { |
|
49 | + continue; |
|
50 | + } else { |
|
51 | + $success = false; |
|
52 | + break; |
|
53 | + } |
|
54 | + } else { |
|
55 | + if ((int)$v > 0) { // handles versions like x.x.x.0_RC2 |
|
56 | + $success = false; |
|
57 | + break; |
|
58 | + } |
|
59 | + } |
|
60 | + } |
|
61 | 61 | |
62 | - if (false === $success) { |
|
63 | - $module->setErrors(sprintf(_AM_WFL_ERROR_BAD_XOOPS, $requiredVer, $currentVer)); |
|
64 | - } |
|
62 | + if (false === $success) { |
|
63 | + $module->setErrors(sprintf(_AM_WFL_ERROR_BAD_XOOPS, $requiredVer, $currentVer)); |
|
64 | + } |
|
65 | 65 | |
66 | - return $success; |
|
67 | - } |
|
66 | + return $success; |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * |
|
71 | - * Verifies PHP version meets minimum requirements for this module |
|
72 | - * @static |
|
73 | - * @param \XoopsModule $module |
|
74 | - * |
|
75 | - * @return bool true if meets requirements, false if not |
|
76 | - */ |
|
77 | - public static function checkVerPhp(\XoopsModule $module) |
|
78 | - { |
|
79 | - xoops_loadLanguage('admin', $module->dirname()); |
|
80 | - // check for minimum PHP version |
|
81 | - $success = true; |
|
82 | - $verNum = PHP_VERSION; |
|
83 | - $reqVer = $module->getInfo('min_php'); |
|
84 | - if (false !== $reqVer && '' !== $reqVer) { |
|
85 | - if (version_compare($verNum, $reqVer, '<')) { |
|
86 | - $module->setErrors(sprintf(_AM_WFL_ERROR_BAD_PHP, $reqVer, $verNum)); |
|
87 | - $success = false; |
|
88 | - } |
|
89 | - } |
|
69 | + /** |
|
70 | + * |
|
71 | + * Verifies PHP version meets minimum requirements for this module |
|
72 | + * @static |
|
73 | + * @param \XoopsModule $module |
|
74 | + * |
|
75 | + * @return bool true if meets requirements, false if not |
|
76 | + */ |
|
77 | + public static function checkVerPhp(\XoopsModule $module) |
|
78 | + { |
|
79 | + xoops_loadLanguage('admin', $module->dirname()); |
|
80 | + // check for minimum PHP version |
|
81 | + $success = true; |
|
82 | + $verNum = PHP_VERSION; |
|
83 | + $reqVer = $module->getInfo('min_php'); |
|
84 | + if (false !== $reqVer && '' !== $reqVer) { |
|
85 | + if (version_compare($verNum, $reqVer, '<')) { |
|
86 | + $module->setErrors(sprintf(_AM_WFL_ERROR_BAD_PHP, $reqVer, $verNum)); |
|
87 | + $success = false; |
|
88 | + } |
|
89 | + } |
|
90 | 90 | |
91 | - return $success; |
|
92 | - } |
|
91 | + return $success; |
|
92 | + } |
|
93 | 93 | } |
@@ -17,60 +17,60 @@ |
||
17 | 17 | */ |
18 | 18 | trait ServerStats |
19 | 19 | { |
20 | - /** |
|
21 | - * serverStats() |
|
22 | - * |
|
23 | - * @return string |
|
24 | - */ |
|
25 | - public static function getServerStats() |
|
26 | - { |
|
27 | - //mb $wfdownloads = WfdownloadsWfdownloads::getInstance(); |
|
28 | - $moduleDirName = basename(dirname(dirname(__DIR__))); |
|
29 | - $moduleDirNameUpper = strtoupper($moduleDirName); |
|
30 | - xoops_loadLanguage('common', $moduleDirName); |
|
31 | - $html = ''; |
|
32 | - // $sql = 'SELECT metavalue'; |
|
33 | - // $sql .= ' FROM ' . $GLOBALS['xoopsDB']->prefix('wfdownloads_meta'); |
|
34 | - // $sql .= " WHERE metakey='version' LIMIT 1"; |
|
35 | - // $query = $GLOBALS['xoopsDB']->query($sql); |
|
36 | - // list($meta) = $GLOBALS['xoopsDB']->fetchRow($query); |
|
37 | - $html .= "<fieldset><legend style='font-weight: bold; color: #900;'>" . constant('CO_' . $moduleDirNameUpper . '_IMAGEINFO') . "</legend>\n"; |
|
38 | - $html .= "<div style='padding: 8px;'>\n"; |
|
39 | - // $html .= '<div>' . constant('CO_' . $moduleDirNameUpper . '_METAVERSION') . $meta . "</div>\n"; |
|
40 | - // $html .= "<br>\n"; |
|
41 | - // $html .= "<br>\n"; |
|
42 | - $html .= '<div>' . constant('CO_' . $moduleDirNameUpper . '_SPHPINI') . "</div>\n"; |
|
43 | - $html .= "<ul>\n"; |
|
44 | - // |
|
45 | - $gdlib = function_exists('gd_info') ? '<span style="color: green;">' . constant('CO_' . $moduleDirNameUpper . '_GDON') . '</span>' : '<span style="color: red;">' . constant('CO_' . $moduleDirNameUpper . '_GDOFF') . '</span>'; |
|
46 | - $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_GDLIBSTATUS') . $gdlib; |
|
47 | - if (function_exists('gd_info')) { |
|
48 | - if ($gdlib = (true === gd_info())) { |
|
49 | - $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_GDLIBVERSION') . '<b>' . $gdlib['GD Version'] . '</b>'; |
|
50 | - } |
|
51 | - } |
|
52 | - // |
|
53 | - // $safemode = ini_get('safe_mode') ? constant('CO_' . $moduleDirNameUpper . '_ON') . constant('CO_' . $moduleDirNameUpper . '_SAFEMODEPROBLEMS : constant('CO_' . $moduleDirNameUpper . '_OFF'); |
|
54 | - // $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_SAFEMODESTATUS . $safemode; |
|
55 | - // |
|
56 | - // $registerglobals = (!ini_get('register_globals')) ? "<span style=\"color: green;\">" . constant('CO_' . $moduleDirNameUpper . '_OFF') . '</span>' : "<span style=\"color: red;\">" . constant('CO_' . $moduleDirNameUpper . '_ON') . '</span>'; |
|
57 | - // $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_REGISTERGLOBALS . $registerglobals; |
|
58 | - // |
|
59 | - $downloads = ini_get('file_uploads') ? '<span style="color: green;">' . constant('CO_' . $moduleDirNameUpper . '_ON') . '</span>' : '<span style="color: red;">' . constant('CO_' . $moduleDirNameUpper . '_OFF') . '</span>'; |
|
60 | - $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_SERVERUPLOADSTATUS') . $downloads; |
|
61 | - // |
|
62 | - $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_MAXUPLOADSIZE') . ' <b><span style="color: blue;">' . ini_get('upload_max_filesize') . "</span></b>\n"; |
|
63 | - $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_MAXPOSTSIZE') . ' <b><span style="color: blue;">' . ini_get('post_max_size') . "</span></b>\n"; |
|
64 | - $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_MEMORYLIMIT') . ' <b><span style="color: blue;">' . ini_get('memory_limit') . "</span></b>\n"; |
|
65 | - $html .= "</ul>\n"; |
|
66 | - $html .= "<ul>\n"; |
|
67 | - $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_SERVERPATH') . ' <b>' . XOOPS_ROOT_PATH . "</b>\n"; |
|
68 | - $html .= "</ul>\n"; |
|
69 | - $html .= "<br>\n"; |
|
70 | - $html .= constant('CO_' . $moduleDirNameUpper . '_UPLOADPATHDSC') . "\n"; |
|
71 | - $html .= '</div>'; |
|
72 | - $html .= '</fieldset><br>'; |
|
20 | + /** |
|
21 | + * serverStats() |
|
22 | + * |
|
23 | + * @return string |
|
24 | + */ |
|
25 | + public static function getServerStats() |
|
26 | + { |
|
27 | + //mb $wfdownloads = WfdownloadsWfdownloads::getInstance(); |
|
28 | + $moduleDirName = basename(dirname(dirname(__DIR__))); |
|
29 | + $moduleDirNameUpper = strtoupper($moduleDirName); |
|
30 | + xoops_loadLanguage('common', $moduleDirName); |
|
31 | + $html = ''; |
|
32 | + // $sql = 'SELECT metavalue'; |
|
33 | + // $sql .= ' FROM ' . $GLOBALS['xoopsDB']->prefix('wfdownloads_meta'); |
|
34 | + // $sql .= " WHERE metakey='version' LIMIT 1"; |
|
35 | + // $query = $GLOBALS['xoopsDB']->query($sql); |
|
36 | + // list($meta) = $GLOBALS['xoopsDB']->fetchRow($query); |
|
37 | + $html .= "<fieldset><legend style='font-weight: bold; color: #900;'>" . constant('CO_' . $moduleDirNameUpper . '_IMAGEINFO') . "</legend>\n"; |
|
38 | + $html .= "<div style='padding: 8px;'>\n"; |
|
39 | + // $html .= '<div>' . constant('CO_' . $moduleDirNameUpper . '_METAVERSION') . $meta . "</div>\n"; |
|
40 | + // $html .= "<br>\n"; |
|
41 | + // $html .= "<br>\n"; |
|
42 | + $html .= '<div>' . constant('CO_' . $moduleDirNameUpper . '_SPHPINI') . "</div>\n"; |
|
43 | + $html .= "<ul>\n"; |
|
44 | + // |
|
45 | + $gdlib = function_exists('gd_info') ? '<span style="color: green;">' . constant('CO_' . $moduleDirNameUpper . '_GDON') . '</span>' : '<span style="color: red;">' . constant('CO_' . $moduleDirNameUpper . '_GDOFF') . '</span>'; |
|
46 | + $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_GDLIBSTATUS') . $gdlib; |
|
47 | + if (function_exists('gd_info')) { |
|
48 | + if ($gdlib = (true === gd_info())) { |
|
49 | + $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_GDLIBVERSION') . '<b>' . $gdlib['GD Version'] . '</b>'; |
|
50 | + } |
|
51 | + } |
|
52 | + // |
|
53 | + // $safemode = ini_get('safe_mode') ? constant('CO_' . $moduleDirNameUpper . '_ON') . constant('CO_' . $moduleDirNameUpper . '_SAFEMODEPROBLEMS : constant('CO_' . $moduleDirNameUpper . '_OFF'); |
|
54 | + // $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_SAFEMODESTATUS . $safemode; |
|
55 | + // |
|
56 | + // $registerglobals = (!ini_get('register_globals')) ? "<span style=\"color: green;\">" . constant('CO_' . $moduleDirNameUpper . '_OFF') . '</span>' : "<span style=\"color: red;\">" . constant('CO_' . $moduleDirNameUpper . '_ON') . '</span>'; |
|
57 | + // $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_REGISTERGLOBALS . $registerglobals; |
|
58 | + // |
|
59 | + $downloads = ini_get('file_uploads') ? '<span style="color: green;">' . constant('CO_' . $moduleDirNameUpper . '_ON') . '</span>' : '<span style="color: red;">' . constant('CO_' . $moduleDirNameUpper . '_OFF') . '</span>'; |
|
60 | + $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_SERVERUPLOADSTATUS') . $downloads; |
|
61 | + // |
|
62 | + $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_MAXUPLOADSIZE') . ' <b><span style="color: blue;">' . ini_get('upload_max_filesize') . "</span></b>\n"; |
|
63 | + $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_MAXPOSTSIZE') . ' <b><span style="color: blue;">' . ini_get('post_max_size') . "</span></b>\n"; |
|
64 | + $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_MEMORYLIMIT') . ' <b><span style="color: blue;">' . ini_get('memory_limit') . "</span></b>\n"; |
|
65 | + $html .= "</ul>\n"; |
|
66 | + $html .= "<ul>\n"; |
|
67 | + $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_SERVERPATH') . ' <b>' . XOOPS_ROOT_PATH . "</b>\n"; |
|
68 | + $html .= "</ul>\n"; |
|
69 | + $html .= "<br>\n"; |
|
70 | + $html .= constant('CO_' . $moduleDirNameUpper . '_UPLOADPATHDSC') . "\n"; |
|
71 | + $html .= '</div>'; |
|
72 | + $html .= '</fieldset><br>'; |
|
73 | 73 | |
74 | - return $html; |
|
75 | - } |
|
74 | + return $html; |
|
75 | + } |
|
76 | 76 | } |
@@ -17,228 +17,228 @@ |
||
17 | 17 | */ |
18 | 18 | trait FilesManagement |
19 | 19 | { |
20 | - /** |
|
21 | - * Function responsible for checking if a directory exists, we can also write in and create an index.html file |
|
22 | - * |
|
23 | - * @param string $folder The full path of the directory to check |
|
24 | - * |
|
25 | - * @return void |
|
26 | - * @throws \RuntimeException |
|
27 | - */ |
|
28 | - public static function createFolder($folder) |
|
29 | - { |
|
30 | - try { |
|
31 | - if (!file_exists($folder)) { |
|
32 | - if (!mkdir($folder) && !is_dir($folder)) { |
|
33 | - throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder)); |
|
34 | - } |
|
35 | - |
|
36 | - file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>'); |
|
37 | - } |
|
38 | - } |
|
39 | - catch (\Exception $e) { |
|
40 | - echo 'Caught exception: ', $e->getMessage(), "\n", '<br>'; |
|
41 | - } |
|
42 | - } |
|
43 | - |
|
44 | - /** |
|
45 | - * @param $file |
|
46 | - * @param $folder |
|
47 | - * @return bool |
|
48 | - */ |
|
49 | - public static function copyFile($file, $folder) |
|
50 | - { |
|
51 | - return copy($file, $folder); |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * @param $src |
|
56 | - * @param $dst |
|
57 | - */ |
|
58 | - public static function recurseCopy($src, $dst) |
|
59 | - { |
|
60 | - $dir = opendir($src); |
|
61 | - @mkdir($dst); |
|
62 | - while (false !== ($file = readdir($dir))) { |
|
63 | - if (('.' !== $file) && ('..' !== $file)) { |
|
64 | - if (is_dir($src . '/' . $file)) { |
|
65 | - self::recurseCopy($src . '/' . $file, $dst . '/' . $file); |
|
66 | - } else { |
|
67 | - copy($src . '/' . $file, $dst . '/' . $file); |
|
68 | - } |
|
69 | - } |
|
70 | - } |
|
71 | - closedir($dir); |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * |
|
76 | - * Remove files and (sub)directories |
|
77 | - * |
|
78 | - * @param string $src source directory to delete |
|
79 | - * |
|
80 | - * @uses \Xmf\Module\Helper::getHelper() |
|
81 | - * @uses \Xmf\Module\Helper::isUserAdmin() |
|
82 | - * |
|
83 | - * @return bool true on success |
|
84 | - */ |
|
85 | - public static function deleteDirectory($src) |
|
86 | - { |
|
87 | - // Only continue if user is a 'global' Admin |
|
88 | - if (!($GLOBALS['xoopsUser'] instanceof XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
89 | - return false; |
|
90 | - } |
|
91 | - |
|
92 | - $success = true; |
|
93 | - // remove old files |
|
94 | - $dirInfo = new \SplFileInfo($src); |
|
95 | - // validate is a directory |
|
96 | - if ($dirInfo->isDir()) { |
|
97 | - $fileList = array_diff(scandir($src, SCANDIR_SORT_NONE), ['..', '.']); |
|
98 | - foreach ($fileList as $k => $v) { |
|
99 | - $fileInfo = new \SplFileInfo("{$src}/{$v}"); |
|
100 | - if ($fileInfo->isDir()) { |
|
101 | - // recursively handle subdirectories |
|
102 | - if (!$success = self::deleteDirectory($fileInfo->getRealPath())) { |
|
103 | - break; |
|
104 | - } |
|
105 | - } else { |
|
106 | - // delete the file |
|
107 | - if (!($success = unlink($fileInfo->getRealPath()))) { |
|
108 | - break; |
|
109 | - } |
|
110 | - } |
|
111 | - } |
|
112 | - // now delete this (sub)directory if all the files are gone |
|
113 | - if ($success) { |
|
114 | - $success = rmdir($dirInfo->getRealPath()); |
|
115 | - } |
|
116 | - } else { |
|
117 | - // input is not a valid directory |
|
118 | - $success = false; |
|
119 | - } |
|
120 | - return $success; |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * |
|
125 | - * Recursively remove directory |
|
126 | - * |
|
127 | - * @todo currently won't remove directories with hidden files, should it? |
|
128 | - * |
|
129 | - * @param string $src directory to remove (delete) |
|
130 | - * |
|
131 | - * @return bool true on success |
|
132 | - */ |
|
133 | - public static function rrmdir($src) |
|
134 | - { |
|
135 | - // Only continue if user is a 'global' Admin |
|
136 | - if (!($GLOBALS['xoopsUser'] instanceof XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
137 | - return false; |
|
138 | - } |
|
139 | - |
|
140 | - // If source is not a directory stop processing |
|
141 | - if (!is_dir($src)) { |
|
142 | - return false; |
|
143 | - } |
|
144 | - |
|
145 | - $success = true; |
|
146 | - |
|
147 | - // Open the source directory to read in files |
|
148 | - $iterator = new \DirectoryIterator($src); |
|
149 | - foreach ($iterator as $fObj) { |
|
150 | - if ($fObj->isFile()) { |
|
151 | - $filename = $fObj->getPathname(); |
|
152 | - $fObj = null; // clear this iterator object to close the file |
|
153 | - if (!unlink($filename)) { |
|
154 | - return false; // couldn't delete the file |
|
155 | - } |
|
156 | - } elseif (!$fObj->isDot() && $fObj->isDir()) { |
|
157 | - // Try recursively on directory |
|
158 | - self::rrmdir($fObj->getPathname()); |
|
159 | - } |
|
160 | - } |
|
161 | - $iterator = null; // clear iterator Obj to close file/directory |
|
162 | - return rmdir($src); // remove the directory & return results |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * Recursively move files from one directory to another |
|
167 | - * |
|
168 | - * @param string $src - Source of files being moved |
|
169 | - * @param string $dest - Destination of files being moved |
|
170 | - * |
|
171 | - * @return bool true on success |
|
172 | - */ |
|
173 | - public static function rmove($src, $dest) |
|
174 | - { |
|
175 | - // Only continue if user is a 'global' Admin |
|
176 | - if (!($GLOBALS['xoopsUser'] instanceof XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
177 | - return false; |
|
178 | - } |
|
179 | - |
|
180 | - // If source is not a directory stop processing |
|
181 | - if (!is_dir($src)) { |
|
182 | - return false; |
|
183 | - } |
|
184 | - |
|
185 | - // If the destination directory does not exist and could not be created stop processing |
|
186 | - if (!is_dir($dest) && !mkdir($dest, 0755)) { |
|
187 | - return false; |
|
188 | - } |
|
189 | - |
|
190 | - // Open the source directory to read in files |
|
191 | - $iterator = new \DirectoryIterator($src); |
|
192 | - foreach ($iterator as $fObj) { |
|
193 | - if ($fObj->isFile()) { |
|
194 | - rename($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
195 | - } elseif (!$fObj->isDot() && $fObj->isDir()) { |
|
196 | - // Try recursively on directory |
|
197 | - self::rmove($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
198 | - // rmdir($fObj->getPath()); // now delete the directory |
|
199 | - } |
|
200 | - } |
|
201 | - $iterator = null; // clear iterator Obj to close file/directory |
|
202 | - return rmdir($src); // remove the directory & return results |
|
203 | - } |
|
204 | - |
|
205 | - /** |
|
206 | - * Recursively copy directories and files from one directory to another |
|
207 | - * |
|
208 | - * @param string $src - Source of files being moved |
|
209 | - * @param string $dest - Destination of files being moved |
|
210 | - * |
|
211 | - * @uses \Xmf\Module\Helper::getHelper() |
|
212 | - * @uses \Xmf\Module\Helper::isUserAdmin() |
|
213 | - * |
|
214 | - * @return bool true on success |
|
215 | - */ |
|
216 | - public static function rcopy($src, $dest) |
|
217 | - { |
|
218 | - // Only continue if user is a 'global' Admin |
|
219 | - if (!($GLOBALS['xoopsUser'] instanceof XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
220 | - return false; |
|
221 | - } |
|
222 | - |
|
223 | - // If source is not a directory stop processing |
|
224 | - if (!is_dir($src)) { |
|
225 | - return false; |
|
226 | - } |
|
227 | - |
|
228 | - // If the destination directory does not exist and could not be created stop processing |
|
229 | - if (!is_dir($dest) && !mkdir($dest, 0755)) { |
|
230 | - return false; |
|
231 | - } |
|
232 | - |
|
233 | - // Open the source directory to read in files |
|
234 | - $iterator = new \DirectoryIterator($src); |
|
235 | - foreach ($iterator as $fObj) { |
|
236 | - if ($fObj->isFile()) { |
|
237 | - copy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
238 | - } elseif (!$fObj->isDot() && $fObj->isDir()) { |
|
239 | - self::rcopy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
240 | - } |
|
241 | - } |
|
242 | - return true; |
|
243 | - } |
|
20 | + /** |
|
21 | + * Function responsible for checking if a directory exists, we can also write in and create an index.html file |
|
22 | + * |
|
23 | + * @param string $folder The full path of the directory to check |
|
24 | + * |
|
25 | + * @return void |
|
26 | + * @throws \RuntimeException |
|
27 | + */ |
|
28 | + public static function createFolder($folder) |
|
29 | + { |
|
30 | + try { |
|
31 | + if (!file_exists($folder)) { |
|
32 | + if (!mkdir($folder) && !is_dir($folder)) { |
|
33 | + throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder)); |
|
34 | + } |
|
35 | + |
|
36 | + file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>'); |
|
37 | + } |
|
38 | + } |
|
39 | + catch (\Exception $e) { |
|
40 | + echo 'Caught exception: ', $e->getMessage(), "\n", '<br>'; |
|
41 | + } |
|
42 | + } |
|
43 | + |
|
44 | + /** |
|
45 | + * @param $file |
|
46 | + * @param $folder |
|
47 | + * @return bool |
|
48 | + */ |
|
49 | + public static function copyFile($file, $folder) |
|
50 | + { |
|
51 | + return copy($file, $folder); |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * @param $src |
|
56 | + * @param $dst |
|
57 | + */ |
|
58 | + public static function recurseCopy($src, $dst) |
|
59 | + { |
|
60 | + $dir = opendir($src); |
|
61 | + @mkdir($dst); |
|
62 | + while (false !== ($file = readdir($dir))) { |
|
63 | + if (('.' !== $file) && ('..' !== $file)) { |
|
64 | + if (is_dir($src . '/' . $file)) { |
|
65 | + self::recurseCopy($src . '/' . $file, $dst . '/' . $file); |
|
66 | + } else { |
|
67 | + copy($src . '/' . $file, $dst . '/' . $file); |
|
68 | + } |
|
69 | + } |
|
70 | + } |
|
71 | + closedir($dir); |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * |
|
76 | + * Remove files and (sub)directories |
|
77 | + * |
|
78 | + * @param string $src source directory to delete |
|
79 | + * |
|
80 | + * @uses \Xmf\Module\Helper::getHelper() |
|
81 | + * @uses \Xmf\Module\Helper::isUserAdmin() |
|
82 | + * |
|
83 | + * @return bool true on success |
|
84 | + */ |
|
85 | + public static function deleteDirectory($src) |
|
86 | + { |
|
87 | + // Only continue if user is a 'global' Admin |
|
88 | + if (!($GLOBALS['xoopsUser'] instanceof XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
89 | + return false; |
|
90 | + } |
|
91 | + |
|
92 | + $success = true; |
|
93 | + // remove old files |
|
94 | + $dirInfo = new \SplFileInfo($src); |
|
95 | + // validate is a directory |
|
96 | + if ($dirInfo->isDir()) { |
|
97 | + $fileList = array_diff(scandir($src, SCANDIR_SORT_NONE), ['..', '.']); |
|
98 | + foreach ($fileList as $k => $v) { |
|
99 | + $fileInfo = new \SplFileInfo("{$src}/{$v}"); |
|
100 | + if ($fileInfo->isDir()) { |
|
101 | + // recursively handle subdirectories |
|
102 | + if (!$success = self::deleteDirectory($fileInfo->getRealPath())) { |
|
103 | + break; |
|
104 | + } |
|
105 | + } else { |
|
106 | + // delete the file |
|
107 | + if (!($success = unlink($fileInfo->getRealPath()))) { |
|
108 | + break; |
|
109 | + } |
|
110 | + } |
|
111 | + } |
|
112 | + // now delete this (sub)directory if all the files are gone |
|
113 | + if ($success) { |
|
114 | + $success = rmdir($dirInfo->getRealPath()); |
|
115 | + } |
|
116 | + } else { |
|
117 | + // input is not a valid directory |
|
118 | + $success = false; |
|
119 | + } |
|
120 | + return $success; |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * |
|
125 | + * Recursively remove directory |
|
126 | + * |
|
127 | + * @todo currently won't remove directories with hidden files, should it? |
|
128 | + * |
|
129 | + * @param string $src directory to remove (delete) |
|
130 | + * |
|
131 | + * @return bool true on success |
|
132 | + */ |
|
133 | + public static function rrmdir($src) |
|
134 | + { |
|
135 | + // Only continue if user is a 'global' Admin |
|
136 | + if (!($GLOBALS['xoopsUser'] instanceof XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
137 | + return false; |
|
138 | + } |
|
139 | + |
|
140 | + // If source is not a directory stop processing |
|
141 | + if (!is_dir($src)) { |
|
142 | + return false; |
|
143 | + } |
|
144 | + |
|
145 | + $success = true; |
|
146 | + |
|
147 | + // Open the source directory to read in files |
|
148 | + $iterator = new \DirectoryIterator($src); |
|
149 | + foreach ($iterator as $fObj) { |
|
150 | + if ($fObj->isFile()) { |
|
151 | + $filename = $fObj->getPathname(); |
|
152 | + $fObj = null; // clear this iterator object to close the file |
|
153 | + if (!unlink($filename)) { |
|
154 | + return false; // couldn't delete the file |
|
155 | + } |
|
156 | + } elseif (!$fObj->isDot() && $fObj->isDir()) { |
|
157 | + // Try recursively on directory |
|
158 | + self::rrmdir($fObj->getPathname()); |
|
159 | + } |
|
160 | + } |
|
161 | + $iterator = null; // clear iterator Obj to close file/directory |
|
162 | + return rmdir($src); // remove the directory & return results |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * Recursively move files from one directory to another |
|
167 | + * |
|
168 | + * @param string $src - Source of files being moved |
|
169 | + * @param string $dest - Destination of files being moved |
|
170 | + * |
|
171 | + * @return bool true on success |
|
172 | + */ |
|
173 | + public static function rmove($src, $dest) |
|
174 | + { |
|
175 | + // Only continue if user is a 'global' Admin |
|
176 | + if (!($GLOBALS['xoopsUser'] instanceof XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
177 | + return false; |
|
178 | + } |
|
179 | + |
|
180 | + // If source is not a directory stop processing |
|
181 | + if (!is_dir($src)) { |
|
182 | + return false; |
|
183 | + } |
|
184 | + |
|
185 | + // If the destination directory does not exist and could not be created stop processing |
|
186 | + if (!is_dir($dest) && !mkdir($dest, 0755)) { |
|
187 | + return false; |
|
188 | + } |
|
189 | + |
|
190 | + // Open the source directory to read in files |
|
191 | + $iterator = new \DirectoryIterator($src); |
|
192 | + foreach ($iterator as $fObj) { |
|
193 | + if ($fObj->isFile()) { |
|
194 | + rename($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
195 | + } elseif (!$fObj->isDot() && $fObj->isDir()) { |
|
196 | + // Try recursively on directory |
|
197 | + self::rmove($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
198 | + // rmdir($fObj->getPath()); // now delete the directory |
|
199 | + } |
|
200 | + } |
|
201 | + $iterator = null; // clear iterator Obj to close file/directory |
|
202 | + return rmdir($src); // remove the directory & return results |
|
203 | + } |
|
204 | + |
|
205 | + /** |
|
206 | + * Recursively copy directories and files from one directory to another |
|
207 | + * |
|
208 | + * @param string $src - Source of files being moved |
|
209 | + * @param string $dest - Destination of files being moved |
|
210 | + * |
|
211 | + * @uses \Xmf\Module\Helper::getHelper() |
|
212 | + * @uses \Xmf\Module\Helper::isUserAdmin() |
|
213 | + * |
|
214 | + * @return bool true on success |
|
215 | + */ |
|
216 | + public static function rcopy($src, $dest) |
|
217 | + { |
|
218 | + // Only continue if user is a 'global' Admin |
|
219 | + if (!($GLOBALS['xoopsUser'] instanceof XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
220 | + return false; |
|
221 | + } |
|
222 | + |
|
223 | + // If source is not a directory stop processing |
|
224 | + if (!is_dir($src)) { |
|
225 | + return false; |
|
226 | + } |
|
227 | + |
|
228 | + // If the destination directory does not exist and could not be created stop processing |
|
229 | + if (!is_dir($dest) && !mkdir($dest, 0755)) { |
|
230 | + return false; |
|
231 | + } |
|
232 | + |
|
233 | + // Open the source directory to read in files |
|
234 | + $iterator = new \DirectoryIterator($src); |
|
235 | + foreach ($iterator as $fObj) { |
|
236 | + if ($fObj->isFile()) { |
|
237 | + copy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
238 | + } elseif (!$fObj->isDot() && $fObj->isDir()) { |
|
239 | + self::rcopy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
240 | + } |
|
241 | + } |
|
242 | + return true; |
|
243 | + } |
|
244 | 244 | } |
@@ -33,48 +33,48 @@ |
||
33 | 33 | */ |
34 | 34 | class Breadcrumb |
35 | 35 | { |
36 | - public $dirname; |
|
37 | - private $bread = []; |
|
36 | + public $dirname; |
|
37 | + private $bread = []; |
|
38 | 38 | |
39 | - /** |
|
40 | - * |
|
41 | - */ |
|
42 | - public function __construct() |
|
43 | - { |
|
44 | - $this->dirname = basename(dirname(__DIR__)); |
|
45 | - } |
|
39 | + /** |
|
40 | + * |
|
41 | + */ |
|
42 | + public function __construct() |
|
43 | + { |
|
44 | + $this->dirname = basename(dirname(__DIR__)); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Add link to breadcrumb |
|
49 | - * |
|
50 | - * @param string $title |
|
51 | - * @param string $link |
|
52 | - */ |
|
53 | - public function addLink($title = '', $link = '') |
|
54 | - { |
|
55 | - $this->bread[] = [ |
|
56 | - 'link' => $link, |
|
57 | - 'title' => $title |
|
58 | - ]; |
|
59 | - } |
|
47 | + /** |
|
48 | + * Add link to breadcrumb |
|
49 | + * |
|
50 | + * @param string $title |
|
51 | + * @param string $link |
|
52 | + */ |
|
53 | + public function addLink($title = '', $link = '') |
|
54 | + { |
|
55 | + $this->bread[] = [ |
|
56 | + 'link' => $link, |
|
57 | + 'title' => $title |
|
58 | + ]; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * Render Pedigree BreadCrumb |
|
63 | - * |
|
64 | - */ |
|
65 | - public function render() |
|
66 | - { |
|
67 | - if (!isset($GLOBALS['xoTheme']) || !is_object($GLOBALS['xoTheme'])) { |
|
68 | - require_once $GLOBALS['xoops']->path('class/theme.php'); |
|
69 | - $GLOBALS['xoTheme'] = new xos_opal_Theme(); |
|
70 | - } |
|
61 | + /** |
|
62 | + * Render Pedigree BreadCrumb |
|
63 | + * |
|
64 | + */ |
|
65 | + public function render() |
|
66 | + { |
|
67 | + if (!isset($GLOBALS['xoTheme']) || !is_object($GLOBALS['xoTheme'])) { |
|
68 | + require_once $GLOBALS['xoops']->path('class/theme.php'); |
|
69 | + $GLOBALS['xoTheme'] = new xos_opal_Theme(); |
|
70 | + } |
|
71 | 71 | |
72 | - require_once $GLOBALS['xoops']->path('class/template.php'); |
|
73 | - $breadcrumbTpl = new \XoopsTpl(); |
|
74 | - $breadcrumbTpl->assign('breadcrumb', $this->bread); |
|
75 | - $html = $breadcrumbTpl->fetch('db:' . $this->dirname . '_common_breadcrumb.tpl'); |
|
76 | - unset($breadcrumbTpl); |
|
72 | + require_once $GLOBALS['xoops']->path('class/template.php'); |
|
73 | + $breadcrumbTpl = new \XoopsTpl(); |
|
74 | + $breadcrumbTpl->assign('breadcrumb', $this->bread); |
|
75 | + $html = $breadcrumbTpl->fetch('db:' . $this->dirname . '_common_breadcrumb.tpl'); |
|
76 | + unset($breadcrumbTpl); |
|
77 | 77 | |
78 | - return $html; |
|
79 | - } |
|
78 | + return $html; |
|
79 | + } |
|
80 | 80 | } |