1: <?php
2: /*
3: * You may not change or alter any portion of this comment or credits
4: * of supporting developers from this source code or any supporting source code
5: * which is considered copyrighted (c) material of the original comment or credit authors.
6: *
7: * This program is distributed in the hope that it will be useful,
8: * but WITHOUT ANY WARRANTY; without even the implied warranty of
9: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10: */
11:
12: /**
13: * @copyright XOOPS Project https://xoops.org/
14: * @license GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
15: * @package
16: * @since
17: * @author XOOPS Development Team, Kazumi Ono (AKA onokazu)
18: */
19:
20: /*
21: if ( !is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid()) ) {
22: exit("Access Denied");
23: }
24: */
25:
26: /**
27: * @param $dirname
28: *
29: * @return string
30: */
31: function xoops_module_install($dirname)
32: {
33: global $xoopsUser, $xoopsConfig;
34: $dirname = trim($dirname);
35: $db =& $GLOBALS['xoopsDB'];
36: $reservedTables = array(
37: 'avatar',
38: 'avatar_users_link',
39: 'block_module_link',
40: 'xoopscomments',
41: 'config',
42: 'configcategory',
43: 'configoption',
44: 'image',
45: 'imagebody',
46: 'imagecategory',
47: 'imgset',
48: 'imgset_tplset_link',
49: 'imgsetimg',
50: 'groups',
51: 'groups_users_link',
52: 'group_permission',
53: 'online',
54: 'bannerclient',
55: 'banner',
56: 'bannerfinish',
57: 'priv_msgs',
58: 'ranks',
59: 'session',
60: 'smiles',
61: 'users',
62: 'newblocks',
63: 'modules',
64: 'tplfile',
65: 'tplset',
66: 'tplsource',
67: 'xoopsnotifications',
68: 'banner',
69: 'bannerclient',
70: 'bannerfinish');
71: /** @var XoopsModuleHandler $module_handler */
72: $module_handler = xoops_getHandler('module');
73: if ($module_handler->getCount(new Criteria('dirname', $dirname)) == 0) {
74: $module = $module_handler->create();
75: $module->loadInfoAsVar($dirname);
76: $module->setVar('weight', 1);
77: $module->setVar('isactive', 1);
78: $module->setVar('last_update', time());
79: $error = false;
80: $errs = array();
81: $msgs = array();
82: $msgs[] = '<div id="xo-module-log"><div class="header">';
83: $msgs[] = $errs[] = '<h4>' . _AM_SYSTEM_MODULES_INSTALLING . $module->getInfo('name', 's') . '</h4>';
84: if ($module->getInfo('image') !== false && trim($module->getInfo('image')) != '') {
85: $msgs[] = '<a href="' . XOOPS_URL . '/modules/' . $module->getInfo('dirname', 'e') . '/' . $module->getInfo('adminindex') . '"><img src="' . XOOPS_URL . '/modules/' . $dirname . '/' . trim($module->getInfo('image')) . '" alt="" /></a>';
86: }
87: $msgs[] = '<strong>' . _VERSION . ':</strong> ' . $module->getInfo('version');
88: if ($module->getInfo('author') !== false && trim($module->getInfo('author')) != '') {
89: $msgs[] = '<strong>' . _AUTHOR . ':</strong> ' . htmlspecialchars(trim($module->getInfo('author')), ENT_QUOTES);
90: }
91: $msgs[] = '</div><div class="logger">';
92: // Load module specific install script if any
93: $install_script = $module->getInfo('onInstall');
94: if ($install_script && trim($install_script) != '') {
95: include_once XOOPS_ROOT_PATH . '/modules/' . $dirname . '/' . trim($install_script);
96: }
97: $func = "xoops_module_pre_install_{$dirname}";
98: // If pre-install function is defined, execute
99: if (function_exists($func)) {
100: $result = $func($module);
101: if (!$result) {
102: $error = true;
103: $errs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_EXECUTE, $func) . '</p>';
104: $errs = array_merge($errs, $module->getErrors());
105: } else {
106: $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_SUCESS, "<strong>{$func}</strong>") . '</p>';
107: $msgs += $module->getErrors();
108: }
109: }
110:
111: if ($error === false) {
112: $sqlfile = $module->getInfo('sqlfile');
113: if (is_array($sqlfile) && !empty($sqlfile[XOOPS_DB_TYPE])) {
114: $sql_file_path = XOOPS_ROOT_PATH . '/modules/' . $dirname . '/' . $sqlfile[XOOPS_DB_TYPE];
115: if (!file_exists($sql_file_path)) {
116: $errs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_SQL_NOT_FOUND, "<strong>{$sql_file_path}</strong>");
117: $error = true;
118: } else {
119: $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_SQL_FOUND, "<strong>{$sql_file_path}</strong>") . '<br />' . _AM_SYSTEM_MODULES_CREATE_TABLES;
120: include_once XOOPS_ROOT_PATH . '/class/database/sqlutility.php';
121: $sql_query = fread(fopen($sql_file_path, 'r'), filesize($sql_file_path));
122: $sql_query = trim($sql_query);
123: SqlUtility::splitMySqlFile($pieces, $sql_query);
124: $created_tables = array();
125: foreach ($pieces as $piece) {
126: // [0] contains the prefixed query
127: // [4] contains unprefixed table name
128: $prefixed_query = SqlUtility::prefixQuery($piece, $db->prefix());
129: if (!$prefixed_query) {
130: $errs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_SQL_NOT_VALID, '<strong>' . $piece . '</strong>');
131: $error = true;
132: break;
133: }
134: // check if the table name is reserved
135: if (!in_array($prefixed_query[4], $reservedTables)) {
136: // not reserved, so try to create one
137: if (!$db->query($prefixed_query[0])) {
138: $errs[] = $db->error();
139: $error = true;
140: break;
141: } else {
142: if (!in_array($prefixed_query[4], $created_tables)) {
143: $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_TABLE_CREATED, '<strong>' . $db->prefix($prefixed_query[4]) . '</strong>');
144: $created_tables[] = $prefixed_query[4];
145: } else {
146: $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_INSERT_DATA, '<strong>' . $db->prefix($prefixed_query[4]) . '</strong>');
147: }
148: }
149: } else {
150: // the table name is reserved, so halt the installation
151: $errs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_TABLE_RESERVED, '<strong>' . $prefixed_query[4] . '</strong>');
152: $error = true;
153: break;
154: }
155: }
156: // if there was an error, delete the tables created so far, so the next installation will not fail
157: if ($error === true) {
158: foreach ($created_tables as $ct) {
159: $db->query('DROP TABLE ' . $db->prefix($ct));
160: }
161: }
162: }
163: }
164: }
165: // if no error, save the module info and blocks info associated with it
166: if ($error === false) {
167: if (!$module_handler->insert($module)) {
168: $errs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_INSERT_DATA_FAILD, '<strong>' . $module->getVar('name') . '</strong>');
169: foreach ($created_tables as $ct) {
170: $db->query('DROP TABLE ' . $db->prefix($ct));
171: }
172: $ret = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILINS, '<strong>' . $module->name() . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br>';
173: foreach ($errs as $err) {
174: $ret .= ' - ' . $err . '<br>';
175: }
176: $ret .= '</p>';
177: unset($module, $created_tables, $errs, $msgs);
178:
179: return $ret;
180: } else {
181: $newmid = $module->getVar('mid');
182: unset($created_tables);
183: $msgs[] = '<p>' . _AM_SYSTEM_MODULES_INSERT_DATA_DONE . sprintf(_AM_SYSTEM_MODULES_MODULEID, '<strong>' . $newmid . '</strong>');
184: $tplfile_handler = xoops_getHandler('tplfile');
185: $templates = $module->getInfo('templates');
186: if ($templates !== false) {
187: $msgs[] = _AM_SYSTEM_MODULES_TEMPLATES_ADD;
188: foreach ($templates as $tpl) {
189: $tplfile = $tplfile_handler->create();
190: $type = (isset($tpl['type']) ? $tpl['type'] : 'module');
191: $tpldata =& xoops_module_gettemplate($dirname, $tpl['file'], $type);
192: $tplfile->setVar('tpl_source', $tpldata, true);
193: $tplfile->setVar('tpl_refid', $newmid);
194:
195: $tplfile->setVar('tpl_tplset', 'default');
196: $tplfile->setVar('tpl_file', $tpl['file']);
197: $tplfile->setVar('tpl_desc', $tpl['description'], true);
198: $tplfile->setVar('tpl_module', $dirname);
199: $tplfile->setVar('tpl_lastmodified', time());
200: $tplfile->setVar('tpl_lastimported', time());
201: $tplfile->setVar('tpl_type', $type);
202: if (!$tplfile_handler->insert($tplfile)) {
203: $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ADD_ERROR, '<strong>' . $tpl['file'] . '</strong>') . '</span>';
204: } else {
205: $newtplid = $tplfile->getVar('tpl_id');
206: $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ADD_DATA, '<strong>' . $tpl['file'] . '</strong>') . '(ID: <strong>' . $newtplid . '</strong>)';
207: // generate compiled file
208: include_once XOOPS_ROOT_PATH . '/class/template.php';
209: if (!xoops_template_touch($newtplid)) {
210: $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_COMPILED_FAILED, '<strong>' . $tpl['file'] . '</strong>') . '</span>';
211: } else {
212: $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_COMPILED, '<strong>' . $tpl['file'] . '</strong>');
213: }
214: }
215: unset($tplfile, $tpldata);
216: }
217: }
218: include_once XOOPS_ROOT_PATH . '/class/template.php';
219: xoops_template_clear_module_cache($newmid);
220: $blocks = $module->getInfo('blocks');
221: if ($blocks !== false) {
222: $msgs[] = _AM_SYSTEM_MODULES_BLOCKS_ADD;
223: foreach ($blocks as $blockkey => $block) {
224: // break the loop if missing block config
225: if (!isset($block['file']) || !isset($block['show_func'])) {
226: break;
227: }
228: $options = '';
229: if (!empty($block['options'])) {
230: if (is_array($block['options'])) {
231: $options = implode('|', $block['options']);
232: } else {
233: $options = $block['options'];
234: }
235: $options = trim($options);
236: }
237: $newbid = $db->genId($db->prefix('newblocks') . '_bid_seq');
238: $edit_func = isset($block['edit_func']) ? trim($block['edit_func']) : '';
239: $template = '';
240: if (isset($block['template']) && trim($block['template']) != '') {
241: $content =& xoops_module_gettemplate($dirname, $block['template'], 'blocks');
242: }
243: if (empty($content)) {
244: $content = '';
245: } else {
246: $template = trim($block['template']);
247: }
248: $block_name = addslashes(trim($block['name']));
249: $sql = 'INSERT INTO ' . $db->prefix('newblocks') . " (bid, mid, func_num, options, name, title, content, side, weight, visible, block_type, c_type, isactive, dirname, func_file, show_func, edit_func, template, bcachetime, last_modified) VALUES ($newbid, $newmid, " . (int)$blockkey . ", '$options', '" . $block_name . "','" . $block_name . "', '', 0, 0, 0, 'M', 'H', 1, '" . addslashes($dirname) . "', '" . addslashes(trim($block['file'])) . "', '" . addslashes(trim($block['show_func'])) . "', '" . addslashes($edit_func) . "', '" . $template . "', 0, " . time() . ')';
250: if (!$db->query($sql)) {
251: $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_BLOCK_ADD_ERROR, '<strong>' . $block['name'] . '</strong>') . sprintf(_AM_SYSTEM_MODULES_BLOCK_ADD_ERROR_DATABASE, '<strong>' . $db->error() . '</strong>') . '</span>';
252: } else {
253: if (empty($newbid)) {
254: $newbid = $db->getInsertId();
255: }
256: $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_BLOCK_ADD, '<strong>' . $block['name'] . '</strong>') . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, '<strong>' . $newbid . '</strong>');
257: $sql = 'INSERT INTO ' . $db->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newbid . ', -1)';
258: $db->query($sql);
259: if ($template != '') {
260: $tplfile = $tplfile_handler->create();
261: $tplfile->setVar('tpl_refid', $newbid);
262: $tplfile->setVar('tpl_source', $content, true);
263: $tplfile->setVar('tpl_tplset', 'default');
264: $tplfile->setVar('tpl_file', $block['template']);
265: $tplfile->setVar('tpl_module', $dirname);
266: $tplfile->setVar('tpl_type', 'block');
267: $tplfile->setVar('tpl_desc', $block['description'], true);
268: $tplfile->setVar('tpl_lastimported', 0);
269: $tplfile->setVar('tpl_lastmodified', time());
270: if (!$tplfile_handler->insert($tplfile)) {
271: $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ADD_ERROR, '<strong>' . $block['template'] . '</strong>') . '</span>';
272: } else {
273: $newtplid = $tplfile->getVar('tpl_id');
274: $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ADD_DATA, '<strong>' . $block['template'] . '</strong>') . ' (ID: <strong>' . $newtplid . '</strong>)';
275: // generate compiled file
276: include_once XOOPS_ROOT_PATH . '/class/template.php';
277: if (!xoops_template_touch($newtplid)) {
278: $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_COMPILED_FAILED, '<strong>' . $block['template'] . '</strong>') . '</span>';
279: } else {
280: $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_COMPILED, '<strong>' . $block['template'] . '</strong>');
281: }
282: }
283: unset($tplfile);
284: }
285: }
286: unset($content);
287: }
288: unset($blocks);
289: }
290: $configs = $module->getInfo('config');
291: if ($configs !== false) {
292: if ($module->getVar('hascomments') != 0) {
293: include_once XOOPS_ROOT_PATH . '/include/comment_constants.php';
294: $configs[] = array(
295: 'name' => 'com_rule',
296: 'title' => '_CM_COMRULES',
297: 'description' => '',
298: 'formtype' => 'select',
299: 'valuetype' => 'int',
300: 'default' => 1,
301: 'options' => array(
302: '_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE,
303: '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL,
304: '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER,
305: '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN));
306: $configs[] = array(
307: 'name' => 'com_anonpost',
308: 'title' => '_CM_COMANONPOST',
309: 'description' => '',
310: 'formtype' => 'yesno',
311: 'valuetype' => 'int',
312: 'default' => 0);
313: }
314: } else {
315: if ($module->getVar('hascomments') != 0) {
316: $configs = array();
317: include_once XOOPS_ROOT_PATH . '/include/comment_constants.php';
318: $configs[] = array(
319: 'name' => 'com_rule',
320: 'title' => '_CM_COMRULES',
321: 'description' => '',
322: 'formtype' => 'select',
323: 'valuetype' => 'int',
324: 'default' => 1,
325: 'options' => array(
326: '_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE,
327: '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL,
328: '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER,
329: '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN));
330: $configs[] = array(
331: 'name' => 'com_anonpost',
332: 'title' => '_CM_COMANONPOST',
333: 'description' => '',
334: 'formtype' => 'yesno',
335: 'valuetype' => 'int',
336: 'default' => 0);
337: }
338: }
339: // RMV-NOTIFY
340: if ($module->getVar('hasnotification') != 0) {
341: if (empty($configs)) {
342: $configs = array();
343: }
344: // Main notification options
345: include_once XOOPS_ROOT_PATH . '/include/notification_constants.php';
346: include_once XOOPS_ROOT_PATH . '/include/notification_functions.php';
347: $options = array();
348: $options['_NOT_CONFIG_DISABLE'] = XOOPS_NOTIFICATION_DISABLE;
349: $options['_NOT_CONFIG_ENABLEBLOCK'] = XOOPS_NOTIFICATION_ENABLEBLOCK;
350: $options['_NOT_CONFIG_ENABLEINLINE'] = XOOPS_NOTIFICATION_ENABLEINLINE;
351: $options['_NOT_CONFIG_ENABLEBOTH'] = XOOPS_NOTIFICATION_ENABLEBOTH;
352:
353: $configs[] = array(
354: 'name' => 'notification_enabled',
355: 'title' => '_NOT_CONFIG_ENABLE',
356: 'description' => '_NOT_CONFIG_ENABLEDSC',
357: 'formtype' => 'select',
358: 'valuetype' => 'int',
359: 'default' => XOOPS_NOTIFICATION_ENABLEBOTH,
360: 'options' => $options);
361: // Event-specific notification options
362: // FIXME: doesn't work when update module... can't read back the array of options properly... " changing to &quot;
363: $options = array();
364: $categories =& notificationCategoryInfo('', $module->getVar('mid'));
365: foreach ($categories as $category) {
366: $events =& notificationEvents($category['name'], false, $module->getVar('mid'));
367: foreach ($events as $event) {
368: if (!empty($event['invisible'])) {
369: continue;
370: }
371: $option_name = $category['title'] . ' : ' . $event['title'];
372: $option_value = $category['name'] . '-' . $event['name'];
373: $options[$option_name] = $option_value;
374: }
375: unset($events);
376: }
377: unset($categories);
378: $configs[] = array(
379: 'name' => 'notification_events',
380: 'title' => '_NOT_CONFIG_EVENTS',
381: 'description' => '_NOT_CONFIG_EVENTSDSC',
382: 'formtype' => 'select_multi',
383: 'valuetype' => 'array',
384: 'default' => array_values($options),
385: 'options' => $options);
386: }
387:
388: if ($configs !== false) {
389: $msgs[] = _AM_SYSTEM_MODULES_MODULE_DATA_ADD;
390: /** @var XoopsConfigHandler $config_handler */
391: $config_handler = xoops_getHandler('config');
392: $order = 0;
393: foreach ($configs as $config) {
394: $confobj = $config_handler->createConfig();
395: $confobj->setVar('conf_modid', $newmid);
396: $confobj->setVar('conf_catid', 0);
397: $confobj->setVar('conf_name', $config['name']);
398: $confobj->setVar('conf_title', $config['title'], true);
399: $confobj->setVar('conf_desc', isset($config['description']) ? $config['description'] : '', true);
400: $confobj->setVar('conf_formtype', $config['formtype']);
401: $confobj->setVar('conf_valuetype', $config['valuetype']);
402: $confobj->setConfValueForInput($config['default'], true);
403: $confobj->setVar('conf_order', $order);
404: $confop_msgs = '';
405: if (isset($config['options']) && \is_array($config['options'])) {
406: foreach ($config['options'] as $key => $value) {
407: $confop = $config_handler->createConfigOption();
408: $confop->setVar('confop_name', $key, true);
409: $confop->setVar('confop_value', $value, true);
410: $confobj->setConfOptions($confop);
411: $confop_msgs .= '<br>&nbsp;&nbsp;&nbsp;&nbsp; ' . _AM_SYSTEM_MODULES_CONFIG_ADD . _AM_SYSTEM_MODULES_NAME . ' <strong>' . (defined($key) ? constant($key) : $key) . '</strong> ' . _AM_SYSTEM_MODULES_VALUE . ' <strong>' . $value . '</strong> ';
412: unset($confop);
413: }
414: }
415: ++$order;
416: if ($config_handler->insertConfig($confobj) != false) {
417: $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_CONFIG_DATA_ADD, '<strong>' . $config['name'] . '</strong>') . $confop_msgs;
418: } else {
419: $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_CONFIG_DATA_ADD_ERROR, '<strong>' . $config['name'] . '</strong>') . '</span>';
420: }
421: unset($confobj);
422: }
423: unset($configs);
424: }
425: }
426: $groups = array(XOOPS_GROUP_ADMIN);
427: if ($module->getInfo('hasMain')) {
428: $groups = array(XOOPS_GROUP_ADMIN, XOOPS_GROUP_USERS, XOOPS_GROUP_ANONYMOUS);
429: }
430: // retrieve all block ids for this module
431: $blocks = XoopsBlock::getByModule($newmid, false);
432: $msgs[] = _AM_SYSTEM_MODULES_GROUP_SETTINGS_ADD;
433: /** @var XoopsGroupPermHandler $gperm_handler */
434: $gperm_handler = xoops_getHandler('groupperm');
435: foreach ($groups as $mygroup) {
436: if ($gperm_handler->checkRight('module_admin', 0, $mygroup)) {
437: /** @var XoopsGroupPerm $mperm */
438: $mperm = $gperm_handler->create();
439: $mperm->setVar('gperm_groupid', $mygroup);
440: $mperm->setVar('gperm_itemid', $newmid);
441: $mperm->setVar('gperm_name', 'module_admin');
442: $mperm->setVar('gperm_modid', 1);
443: if (!$gperm_handler->insert($mperm)) {
444: $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_ACCESS_ADMIN_ADD_ERROR, '<strong>' . $mygroup . '</strong>') . '</span>';
445: } else {
446: $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_ACCESS_ADMIN_ADD, '<strong>' . $mygroup . '</strong>');
447: }
448: unset($mperm);
449: }
450: $mperm = $gperm_handler->create();
451: $mperm->setVar('gperm_groupid', $mygroup);
452: $mperm->setVar('gperm_itemid', $newmid);
453: $mperm->setVar('gperm_name', 'module_read');
454: $mperm->setVar('gperm_modid', 1);
455: if (!$gperm_handler->insert($mperm)) {
456: $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_ACCESS_USER_ADD_ERROR, '<strong>' . $mygroup . '</strong>') . '</span>';
457: } else {
458: $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_ACCESS_USER_ADD_ERROR, '<strong>' . $mygroup . '</strong>');
459: }
460: unset($mperm);
461: foreach ($blocks as $blc) {
462: /** @var XoopsGroupPerm $bperm */
463: $bperm = $gperm_handler->create();
464: $bperm->setVar('gperm_groupid', $mygroup);
465: $bperm->setVar('gperm_itemid', $blc);
466: $bperm->setVar('gperm_name', 'block_read');
467: $bperm->setVar('gperm_modid', 1);
468: if (!$gperm_handler->insert($bperm)) {
469: $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _AM_SYSTEM_MODULES_BLOCK_ACCESS_ERROR . ' Block ID: <strong>' . $blc . '</strong> Group ID: <strong>' . $mygroup . '</strong></span>';
470: } else {
471: $msgs[] = '&nbsp;&nbsp;' . _AM_SYSTEM_MODULES_BLOCK_ACCESS . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, '<strong>' . $blc . '</strong>') . sprintf(_AM_SYSTEM_MODULES_GROUP_ID, '<strong>' . $mygroup . '</strong>');
472: }
473: unset($bperm);
474: }
475: }
476: unset($blocks, $groups);
477:
478: // execute module specific install script if any
479: $func = "xoops_module_install_{$dirname}";
480: if (function_exists($func)) {
481: if (!$lastmsg = $func($module)) {
482: $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_EXECUTE, $func) . '</p>';
483: } else {
484: $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_SUCESS, "<strong>{$func}</strong>") . '</p>';
485: if (is_string($lastmsg)) {
486: $msgs[] = $lastmsg;
487: }
488: }
489: }
490:
491: $msgs[] = sprintf(_AM_SYSTEM_MODULES_OKINS, '<strong>' . $module->getVar('name', 's') . '</strong>');
492: $msgs[] = '</div></div>';
493:
494: $blocks = $module->getInfo('blocks');
495: $redDevider = '<span class="red bold"> | </span>';
496: $msgs[] = '<div class="noininstall center"><a href="admin.php?fct=modulesadmin">' . _AM_SYSTEM_MODULES_BTOMADMIN . '</a> |
497: <a href="admin.php?fct=modulesadmin&op=installlist">' . _AM_SYSTEM_MODULES_TOINSTALL . '</a>';
498: $msgs[] = '<br><span class="red bold">' . _AM_SYSTEM_MODULES_MODULE . ' ' . $module->getInfo('name') . ': </span></div>';
499: if ($blocks !== false) {
500: $msgs[] = '<div class="noininstall center"><a href="admin.php?fct=blocksadmin&op=list&filter=1&selgen=' . $newmid . '&selmod=-2&selgrp=-1&selvis=-1&filsave=1">' . _AM_SYSTEM_BLOCKS . '</a></div>';
501: }
502: if ($module->getInfo('config') !== false) {
503: $msgs[] = '<div class="noininstall center"><a href="admin.php?fct=preferences&op=showmod&mod=' . $newmid . '">' . _AM_SYSTEM_PREF . '</a>';
504: } else {
505: $msgs[] = '<div class="noininstall center">';
506: }
507: if ($module->getInfo('adminindex') != ''){
508: $msgs[] = '<a href="' . XOOPS_URL . '/modules/' . $module->getInfo('dirname', 'e') . '/' . $module->getInfo('adminindex') . '">' . _AM_SYSTEM_MODULES_INSTALL_THISMODULE . '</a>';
509: }
510: $testdataDirectory = XOOPS_ROOT_PATH . '/modules/' . $module->getInfo('dirname', 'e') . '/testdata';
511: if (file_exists($testdataDirectory)) {
512: $msgs[] = '<a href="' . XOOPS_URL . '/modules/' . $module->getInfo('dirname', 'e') . '/testdata/index.php?op=load' . '">' . _AM_SYSTEM_MODULES_INSTALL_TESTDATA . '</a></div>';
513: } else {
514: $msgs[] = '</div>';
515: }
516:
517: $ret = implode('<br>', $msgs);
518: unset($blocks, $msgs, $errs, $module);
519:
520: return $ret;
521: } else {
522: $ret = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILINS, '<strong>' . $dirname . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br>' . implode('<br>', $errs) . '</p>';
523: unset($msgs, $errs);
524:
525: return $ret;
526: }
527: } else {
528: return '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILINS, '<strong>' . $dirname . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br>&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_ALEXISTS, $dirname) . '</p>';
529: }
530: }
531:
532: /**
533: * @param $dirname
534: * @param $template
535: * @param string $type
536: *
537: * @return string
538: */
539: function &xoops_module_gettemplate($dirname, $template, $type = '')
540: {
541: global $xoopsConfig;
542: $ret = '';
543: switch ($type) {
544: case 'blocks':
545: case 'admin':
546: $path = XOOPS_ROOT_PATH . '/modules/' . $dirname . '/templates/' . $type . '/' . $template;
547: break;
548: default:
549: $path = XOOPS_ROOT_PATH . '/modules/' . $dirname . '/templates/' . $template;
550: break;
551: }
552: if (!file_exists($path)) {
553: return $ret;
554: } else {
555: $lines = file($path);
556: }
557: if (!$lines) {
558: return $ret;
559: }
560: $count = count($lines);
561: for ($i = 0; $i < $count; ++$i) {
562: $ret .= str_replace("\n", "\r\n", str_replace("\r\n", "\n", $lines[$i]));
563: }
564:
565: return $ret;
566: }
567:
568: /**
569: * @param $dirname
570: *
571: * @return string
572: */
573: function xoops_module_uninstall($dirname)
574: {
575: global $xoopsConfig;
576: $reservedTables = array(
577: 'avatar',
578: 'avatar_users_link',
579: 'block_module_link',
580: 'xoopscomments',
581: 'config',
582: 'configcategory',
583: 'configoption',
584: 'image',
585: 'imagebody',
586: 'imagecategory',
587: 'imgset',
588: 'imgset_tplset_link',
589: 'imgsetimg',
590: 'groups',
591: 'groups_users_link',
592: 'group_permission',
593: 'online',
594: 'bannerclient',
595: 'banner',
596: 'bannerfinish',
597: 'priv_msgs',
598: 'ranks',
599: 'session',
600: 'smiles',
601: 'users',
602: 'newblocks',
603: 'modules',
604: 'tplfile',
605: 'tplset',
606: 'tplsource',
607: 'xoopsnotifications',
608: 'banner',
609: 'bannerclient',
610: 'bannerfinish');
611: $db = XoopsDatabaseFactory::getDatabaseConnection();
612: /** @var XoopsModuleHandler $module_handler */
613: $module_handler = xoops_getHandler('module');
614: $module = $module_handler->getByDirname($dirname);
615: include_once XOOPS_ROOT_PATH . '/class/template.php';
616: xoops_template_clear_module_cache($module->getVar('mid'));
617: if ($module->getVar('dirname') === 'system') {
618: return '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILUNINS, '<strong>' . $module->getVar('name') . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br> - ' . _AM_SYSTEM_MODULES_SYSNO . '</p>';
619: } elseif ($module->getVar('dirname') == $xoopsConfig['startpage']) {
620: return '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILUNINS, '<strong>' . $module->getVar('name') . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br> - ' . _AM_SYSTEM_MODULES_STRTNO . '</p>';
621: } else {
622: $msgs = array();
623: $msgs[] = '<div id="xo-module-log"><div class="header">';
624: $msgs[] = $errs[] = '<h4>' . _AM_SYSTEM_MODULES_UNINSTALL . ' ' . $module->getInfo('name', 's') . '</h4>';
625: if ($module->getInfo('image') !== false && trim($module->getInfo('image')) != '') {
626: $msgs[] = '<img src="' . XOOPS_URL . '/modules/' . $dirname . '/' . trim($module->getInfo('image')) . '" alt="" />';
627: }
628: $msgs[] = '<strong>' . _VERSION . ':</strong> ' . $module->getInfo('version');
629: if ($module->getInfo('author') !== false && trim($module->getInfo('author')) != '') {
630: $msgs[] = '<strong>' . _AUTHOR . ':</strong> ' . htmlspecialchars(trim($module->getInfo('author')), ENT_QUOTES);
631: }
632: $msgs[] = '</div><div class="logger">';
633: // Load module specific install script if any
634: $uninstall_script = $module->getInfo('onUninstall');
635: if ($uninstall_script && trim($uninstall_script) != '') {
636: include_once XOOPS_ROOT_PATH . '/modules/' . $dirname . '/' . trim($uninstall_script);
637: }
638: $func = "xoops_module_pre_uninstall_{$dirname}";
639: // If pre uninstall function is defined, execute
640: if (function_exists($func)) {
641: $result = $func($module);
642: if (false === $result) {
643: $errs = $module->getErrors();
644: $errs[] = sprintf(_AM_SYSTEM_MODULES_FAILED_EXECUTE, $func);
645:
646: return '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILUNINS, '<strong>' . $module->getVar('name') . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br>' . implode('<br>', $errs) . '</p>';
647: } else {
648: $prevErrs = $module->getErrors();
649: array_unshift($prevErrs, '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_SUCESS, "<strong>{$func}</strong>") . '</p>');
650: $msgs = array_merge($msgs, $prevErrs);
651: }
652: }
653:
654: if (false === $module_handler->delete($module)) {
655: $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_DELETE_ERROR, $module->getVar('name')) . '</span>';
656: } else {
657:
658: // delete template files
659: $tplfile_handler = xoops_getHandler('tplfile');
660: $templates = $tplfile_handler->find(null, 'module', $module->getVar('mid'));
661: $tcount = count($templates);
662: if ($tcount > 0) {
663: $msgs[] = _AM_SYSTEM_MODULES_TEMPLATES_DELETE;
664: for ($i = 0; $i < $tcount; ++$i) {
665: if (false === $tplfile_handler->delete($templates[$i])) {
666: $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_DELETE_DATA_FAILD, $templates[$i]->getVar('tpl_file')) . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ID, '<strong>' . $templates[$i]->getVar('tpl_id') . '</strong>') . '</span>';
667: } else {
668: $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_DELETE_DATA, '<strong>' . $templates[$i]->getVar('tpl_file') . '</strong>') . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ID, '<strong>' . $templates[$i]->getVar('tpl_id') . '</strong>');
669: }
670: }
671: }
672: unset($templates);
673:
674: // delete blocks and block tempalte files
675: $block_arr = XoopsBlock::getByModule($module->getVar('mid'));
676: if (is_array($block_arr)) {
677: $bcount = count($block_arr);
678: $msgs[] = _AM_SYSTEM_MODULES_BLOCKS_DELETE;
679: for ($i = 0; $i < $bcount; ++$i) {
680: if (false === $block_arr[$i]->delete()) {
681: $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_BLOCK_DELETE_ERROR, '<strong>' . $block_arr[$i]->getVar('name') . '</strong>') . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, '<strong>' . $block_arr[$i]->getVar('bid') . '</strong>') . '</span>';
682: } else {
683: $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_BLOCK_DELETE, '<strong>' . $block_arr[$i]->getVar('name') . '</strong>') . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, '<strong>' . $block_arr[$i]->getVar('bid') . '</strong>');
684: }
685: if ($block_arr[$i]->getVar('template') != '') {
686: $templates = $tplfile_handler->find(null, 'block', $block_arr[$i]->getVar('bid'));
687: $btcount = count($templates);
688: if ($btcount > 0) {
689: for ($j = 0; $j < $btcount; ++$j) {
690: if (!$tplfile_handler->delete($templates[$j])) {
691: $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_BLOCK_DELETE_TEMPLATE_ERROR, $templates[$j]->getVar('tpl_file')) . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ID, '<strong>' . $templates[$j]->getVar('tpl_id') . '</strong>') . '</span>';
692: } else {
693: $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_BLOCK_DELETE_DATA, '<strong>' . $templates[$j]->getVar('tpl_file') . '</strong>') . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ID, '<strong>' . $templates[$j]->getVar('tpl_id') . '</strong>');
694: }
695: }
696: }
697: unset($templates);
698: }
699: }
700: }
701:
702: // delete tables used by this module
703: $modtables = $module->getInfo('tables');
704: if ($modtables !== false && \is_array($modtables)) {
705: $msgs[] = _AM_SYSTEM_MODULES_DELETE_MOD_TABLES;
706: foreach ($modtables as $table) {
707: // prevent deletion of reserved core tables!
708: if (!in_array($table, $reservedTables)) {
709: $sql = 'DROP TABLE ' . $db->prefix($table);
710: if (!$db->query($sql)) {
711: $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TABLE_DROPPED_ERROR, '<strong>' . $db->prefix($table) . '</strong>') . '</span>';
712: } else {
713: $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_TABLE_DROPPED, '<strong>' . $db->prefix($table) . '</strong>');
714: }
715: } else {
716: $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TABLE_DROPPED_FAILDED, '<strong>' . $db->prefix($table) . '</strong>') . '</span>';
717: }
718: }
719: }
720:
721: // delete comments if any
722: if ($module->getVar('hascomments') != 0) {
723: $msgs[] = _AM_SYSTEM_MODULES_COMMENTS_DELETE;
724: $comment_handler = xoops_getHandler('comment');
725: if (false === $comment_handler->deleteByModule($module->getVar('mid'))) {
726: $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _AM_SYSTEM_MODULES_COMMENTS_DELETE_ERROR . '</span>';
727: } else {
728: $msgs[] = '&nbsp;&nbsp;' . _AM_SYSTEM_MODULES_COMMENTS_DELETED;
729: }
730: }
731:
732: // RMV-NOTIFY
733: // delete notifications if any
734: if ($module->getVar('hasnotification') != 0) {
735: $msgs[] = _AM_SYSTEM_MODULES_NOTIFICATIONS_DELETE;
736: if (false === xoops_notification_deletebymodule($module->getVar('mid'))) {
737: $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _AM_SYSTEM_MODULES_NOTIFICATIONS_DELETE_ERROR . '</span>';
738: } else {
739: $msgs[] = '&nbsp;&nbsp;' . _AM_SYSTEM_MODULES_NOTIFICATIONS_DELETED;
740: }
741: }
742:
743: // delete permissions if any
744: $gperm_handler = xoops_getHandler('groupperm');
745: if (false === $gperm_handler->deleteByModule($module->getVar('mid'))) {
746: $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _AM_SYSTEM_MODULES_GROUP_PERMS_DELETE_ERROR . '</span>';
747: } else {
748: $msgs[] = '&nbsp;&nbsp;' . _AM_SYSTEM_MODULES_GROUP_PERMS_DELETED;
749: }
750:
751: // delete module config options if any
752: if ($module->getVar('hasconfig') != 0 || $module->getVar('hascomments') != 0) {
753: /** @var XoopsConfigHandler $config_handler */
754: $config_handler = xoops_getHandler('config');
755: $configs = $config_handler->getConfigs(new Criteria('conf_modid', $module->getVar('mid')));
756: $confcount = count($configs);
757: if ($confcount > 0) {
758: $msgs[] = _AM_SYSTEM_MODULES_MODULE_DATA_DELETE;
759: for ($i = 0; $i < $confcount; ++$i) {
760: if (false === $config_handler->deleteConfig($configs[$i])) {
761: $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _AM_SYSTEM_MODULES_CONFIG_DATA_DELETE_ERROR . sprintf(_AM_SYSTEM_MODULES_GONFIG_ID, '<strong>' . $configs[$i]->getvar('conf_id') . '</strong>') . '</span>';
762: } else {
763: $msgs[] = '&nbsp;&nbsp;' . _AM_SYSTEM_MODULES_GONFIG_DATA_DELETE . sprintf(_AM_SYSTEM_MODULES_GONFIG_ID, '<strong>' . $configs[$i]->getvar('conf_id') . '</strong>');
764: }
765: }
766: }
767: }
768:
769: // execute module specific install script if any
770: $func = 'xoops_module_uninstall_' . $dirname;
771: if (function_exists($func)) {
772: if (!$func($module)) {
773: $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_EXECUTE, $func) . '</p>';
774: } else {
775: $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_SUCESS, "<strong>{$func}</strong>") . '</p>';
776: }
777: }
778: $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_OKUNINS, '<strong>' . $module->getVar('name') . '</strong>') . '</p>';
779: }
780: $msgs[] = '</div></div>';
781: $msgs[] = '<div class="center"><a href="admin.php?fct=modulesadmin">' . _AM_SYSTEM_MODULES_BTOMADMIN . '</a></div>';
782: $ret = implode('<br>', $msgs);
783:
784: return $ret;
785: }
786: }
787:
788: /**
789: * @param $dirname
790: * @return string
791: */
792: function xoops_module_update($dirname)
793: {
794: global $xoopsUser, $xoopsConfig, $xoopsTpl;
795: $dirname = trim($dirname);
796: $xoopsDB =& $GLOBALS['xoopsDB'];
797:
798: $myts = \MyTextSanitizer::getInstance();
799:
800: $dirname = $myts->htmlSpecialChars(trim($dirname));
801: /** @var XoopsModuleHandler $module_handler */
802: $module_handler = xoops_getHandler('module');
803: $module = $module_handler->getByDirname($dirname);
804: // Save current version for use in the update function
805: $prev_version = $module->getVar('version');
806: $clearTpl = new XoopsTpl();
807: $clearTpl->xoopsClearCache($dirname);
808:
809: // we don't want to change the module name set by admin
810: $temp_name = $module->getVar('name');
811: $module->loadInfoAsVar($dirname);
812: $module->setVar('name', $temp_name);
813: $module->setVar('last_update', time());
814: /*
815: // Call Header
816: // Define main template
817: $GLOBALS['xoopsOption']['template_main'] = 'system_header.html';
818: // Call Header
819: xoops_cp_header();
820: // Define Stylesheet
821: $xoTheme->addStylesheet(XOOPS_URL . '/modules/system/css/admin.css');
822: // Define Breadcrumb and tips
823: $xoBreadCrumb->addLink(_AM_SYSTEM_MODULES_ADMIN, system_adminVersion('modulesadmin', 'adminpath'));
824: $xoBreadCrumb->addLink(_AM_SYSTEM_MODULES_UPDATE);
825: $xoBreadCrumb->addHelp(system_adminVersion('modulesadmin', 'help') . '#update');https://www.facebook.com/photo.php?v=10154358806675333
826: $xoBreadCrumb->render();
827:
828: */
829: if (!$module_handler->insert($module)) {
830: echo '<p>Could not update ' . $module->getVar('name') . '</p>';
831: echo "<br><div class='center'><a href='admin.php?fct=modulesadmin'>" . _AM_SYSTEM_MODULES_BTOMADMIN . '</a></div>';
832: } else {
833: $newmid = $module->getVar('mid');
834: $msgs = array();
835: $msgs[] = '<div id="xo-module-log"><div class="header">';
836: $msgs[] = $errs[] = '<h4>' . _AM_SYSTEM_MODULES_UPDATING . $module->getInfo('name', 's') . '</h4>';
837: if ($module->getInfo('image') !== false && trim($module->getInfo('image')) != '') {
838: $msgs[] = '<img src="' . XOOPS_URL . '/modules/' . $dirname . '/' . trim($module->getInfo('image')) . '" alt="" />';
839: }
840: $msgs[] = '<strong>' . _VERSION . ':</strong> ' . $module->getInfo('version');
841: if ($module->getInfo('author') !== false && trim($module->getInfo('author')) != '') {
842: $msgs[] = '<strong>' . _AUTHOR . ':</strong> ' . $myts->htmlSpecialChars(trim($module->getInfo('author')));
843: }
844: $msgs[] = '</div><div class="logger">';
845:
846: $update_script = $module->getInfo('onUpdate');
847: if (!empty($update_script) && trim($update_script) != '') {
848: include_once XOOPS_ROOT_PATH . '/modules/' . $dirname . '/' . trim($update_script);
849: }
850: // execute module specific update script if any
851: if (function_exists('xoops_module_pre_update_' . $dirname)) {
852: $func = 'xoops_module_pre_update_' . $dirname;
853: if (!$func($module, $prev_version)) {
854: $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_EXECUTE, $func) . '</p>';
855: $msgs = array_merge($msgs, $module->getErrors());
856: } else {
857: $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_SUCESS, '<strong>' . $func . '</strong>') . '</p>';
858: $msgs += $module->getErrors();
859: }
860: }
861: $msgs[] = _AM_SYSTEM_MODULES_MODULE_DATA_UPDATE;
862: /** @var XoopsTplfileHandler $tplfile_handler */
863: $tplfile_handler = xoops_getHandler('tplfile');
864: // irmtfan bug fix: remove codes for delete templates
865: /*
866: $deltpl = $tplfile_handler->find('default', 'module', $module->getVar('mid'));
867: $delng = array();
868: if (is_array($deltpl)) {
869: // delete template file entry in db
870: $dcount = count($deltpl);
871: for ($i = 0; $i < $dcount; $i++) {
872: if (!$tplfile_handler->delete($deltpl[$i])) {
873: $delng[] = $deltpl[$i]->getVar('tpl_file');
874: }
875: }
876: }
877: */
878: // irmtfan bug fix: remove codes for delete templates
879: $templates = $module->getInfo('templates');
880: if ($templates !== false) {
881: $msgs[] = _AM_SYSTEM_MODULES_TEMPLATES_UPDATE;
882: foreach ($templates as $tpl) {
883: $tpl['file'] = trim($tpl['file']);
884: // START irmtfan solve templates duplicate issue
885: // if (!in_array($tpl['file'], $delng)) { // irmtfan bug fix: remove codes for delete templates
886: $type = (isset($tpl['type']) ? $tpl['type'] : 'module');
887: if (preg_match("/\.css$/i", $tpl['file'])) {
888: $type = 'css';
889: }
890: $criteria = new CriteriaCompo();
891: $criteria->add(new Criteria('tpl_refid', $newmid), 'AND');
892: $criteria->add(new Criteria('tpl_module', $dirname), 'AND');
893: $criteria->add(new Criteria('tpl_tplset', 'default'), 'AND');
894: $criteria->add(new Criteria('tpl_file', $tpl['file']), 'AND');
895: $criteria->add(new Criteria('tpl_type', $type), 'AND');
896: $tplfiles = $tplfile_handler->getObjects($criteria);
897:
898: $tpldata =& xoops_module_gettemplate($dirname, $tpl['file'], $type);
899: $tplfile = empty($tplfiles) ? $tplfile_handler->create() : $tplfiles[0];
900: // END irmtfan solve templates duplicate issue
901: $tplfile->setVar('tpl_refid', $newmid);
902: $tplfile->setVar('tpl_lastimported', 0);
903: $tplfile->setVar('tpl_lastmodified', time());
904: $tplfile->setVar('tpl_type', $type);
905: $tplfile->setVar('tpl_source', $tpldata, true);
906: $tplfile->setVar('tpl_module', $dirname);
907: $tplfile->setVar('tpl_tplset', 'default');
908: $tplfile->setVar('tpl_file', $tpl['file'], true);
909: $tplfile->setVar('tpl_desc', $tpl['description'], true);
910: if (!$tplfile_handler->insert($tplfile)) {
911: $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ADD_ERROR, '<strong>' . $tpl['file'] . '</strong>') . '</span>';
912: } else {
913: $newid = $tplfile->getVar('tpl_id');
914: $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_INSERT_DATA, '<strong>' . $tpl['file'] . '</strong>');
915: if ($xoopsConfig['template_set'] === 'default') {
916: if (!xoops_template_touch($newid)) {
917: $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE_ERROR, '<strong>' . $tpl['file'] . '</strong>') . '</span>';
918: } else {
919: $msgs[] = '&nbsp;&nbsp;<span>' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE, '<strong>' . $tpl['file'] . '</strong>') . '</span>';
920: }
921: }
922: }
923: unset($tpldata);
924: // irmtfan bug fix: remove codes for delete templates
925: /*
926: } else {
927: $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">'.sprintf(_AM_SYSTEM_MODULES_TEMPLATE_DELETE_OLD_ERROR, "<strong>".$tpl['file']."</strong>").'</span>';
928: }
929: */
930: // irmtfan bug fix: remove codes for delete templates
931: }
932: }
933: $blocks = $module->getInfo('blocks');
934: $msgs[] = _AM_SYSTEM_MODULES_BLOCKS_REBUILD;
935: if ($blocks !== false) {
936: $showfuncs = array();
937: $funcfiles = array();
938: foreach ($blocks as $i => $block) {
939: if (isset($block['show_func']) && $block['show_func'] != '' && isset($block['file']) && $block['file'] != '') {
940: $editfunc = isset($block['edit_func']) ? $block['edit_func'] : '';
941: $showfuncs[] = $block['show_func'];
942: $funcfiles[] = $block['file'];
943: $content = '';
944: $template = '';
945: if (isset($block['template']) && trim($block['template']) != '') {
946: $content =& xoops_module_gettemplate($dirname, $block['template'], 'blocks');
947: }
948: if (!$content) {
949: $content = '';
950: } else {
951: $template = $block['template'];
952: }
953: $options = '';
954: if (!empty($block['options'])) {
955: $options = $block['options'];
956: }
957: $sql = 'SELECT bid, name FROM ' . $xoopsDB->prefix('newblocks') . ' WHERE mid=' . $module->getVar('mid') . ' AND func_num=' . $i . " AND show_func='" . addslashes($block['show_func']) . "' AND func_file='" . addslashes($block['file']) . "'";
958: $fresult = $xoopsDB->query($sql);
959: if (!$xoopsDB->isResultSet($fresult)) {
960: throw new \RuntimeException(
961: \sprintf(_DB_QUERY_ERROR, $sql) . $xoopsDB->error(), E_USER_ERROR
962: );
963: }
964: $fcount = 0;
965: while (false !== ($fblock = $xoopsDB->fetchArray($fresult))) {
966: ++$fcount;
967: $sql = 'UPDATE ' . $xoopsDB->prefix('newblocks') . " SET name='" . addslashes($block['name']) . "', edit_func='" . addslashes($editfunc) . "', content='', template='" . $template . "', last_modified=" . time() . ' WHERE bid=' . $fblock['bid'];
968: $result = $xoopsDB->query($sql);
969: if (!$result) {
970: $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_UPDATE_ERROR, $fblock['name']);
971: } else {
972: $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_BLOCK_UPDATE, $fblock['name']) . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, '<strong>' . $fblock['bid'] . '</strong>');
973: if ($template != '') {
974: $tplfile = $tplfile_handler->find('default', 'block', $fblock['bid']);
975: if (count($tplfile) == 0) {
976: $tplfile_new = $tplfile_handler->create();
977: $tplfile_new->setVar('tpl_module', $dirname);
978: $tplfile_new->setVar('tpl_refid', $fblock['bid']);
979: $tplfile_new->setVar('tpl_tplset', 'default');
980: $tplfile_new->setVar('tpl_file', $block['template'], true);
981: $tplfile_new->setVar('tpl_type', 'block');
982: } else {
983: $tplfile_new = $tplfile[0];
984: }
985: $tplfile_new->setVar('tpl_source', $content, true);
986: $tplfile_new->setVar('tpl_desc', $block['description'], true);
987: $tplfile_new->setVar('tpl_lastmodified', time());
988: $tplfile_new->setVar('tpl_lastimported', 0);
989: $tplfile_new->setVar('tpl_file', $block['template'], true); // irmtfan bug fix: block template file will not be updated after update the module
990: if (!$tplfile_handler->insert($tplfile_new)) {
991: $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_UPDATE_ERROR, '<strong>' . $block['template'] . '</strong>') . '</span>';
992: } else {
993: $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_UPDATE, '<strong>' . $block['template'] . '</strong>');
994: if ($xoopsConfig['template_set'] === 'default') {
995: if (!xoops_template_touch($tplfile_new->getVar('tpl_id'))) {
996: $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE_ERROR, '<strong>' . $block['template'] . '</strong>') . '</span>';
997: } else {
998: $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE, '<strong>' . $block['template'] . '</strong>');
999: }
1000: }
1001: }
1002: }
1003: }
1004: }
1005: if ($fcount == 0) {
1006: $newbid = $xoopsDB->genId($xoopsDB->prefix('newblocks') . '_bid_seq');
1007: $block_name = addslashes($block['name']);
1008: $block_type = ($module->getVar('dirname') === 'system') ? 'S' : 'M';
1009: $sql = 'INSERT INTO ' . $xoopsDB->prefix('newblocks') . ' (bid, mid, func_num, options, name, title, content, side, weight, visible, block_type, isactive, dirname, func_file, show_func, edit_func, template, last_modified) VALUES (' . $newbid . ', ' . $module->getVar('mid') . ', ' . $i . ",'" . addslashes($options) . "','" . $block_name . "', '" . $block_name . "', '', 0, 0, 0, '{$block_type}', 1, '" . addslashes($dirname) . "', '" . addslashes($block['file']) . "', '" . addslashes($block['show_func']) . "', '" . addslashes($editfunc) . "', '" . $template . "', " . time() . ')';
1010: $result = $xoopsDB->query($sql);
1011: if (!$result) {
1012: $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_SQL_NOT_CREATE, $block['name']);
1013: echo $sql;
1014: } else {
1015: if (empty($newbid)) {
1016: $newbid = $xoopsDB->getInsertId();
1017: }
1018: if ($module->getInfo('hasMain')) {
1019: $groups = array(XOOPS_GROUP_ADMIN, XOOPS_GROUP_USERS, XOOPS_GROUP_ANONYMOUS);
1020: } else {
1021: $groups = array(XOOPS_GROUP_ADMIN);
1022: }
1023: $gperm_handler = xoops_getHandler('groupperm');
1024: foreach ($groups as $mygroup) {
1025: $bperm = $gperm_handler->create();
1026: $bperm->setVar('gperm_groupid', $mygroup);
1027: $bperm->setVar('gperm_itemid', $newbid);
1028: $bperm->setVar('gperm_name', 'block_read');
1029: $bperm->setVar('gperm_modid', 1);
1030: if (!$gperm_handler->insert($bperm)) {
1031: $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _AM_SYSTEM_MODULES_BLOCK_ACCESS_ERROR . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, '<strong>' . $newbid . '</strong>') . sprintf(_AM_SYSTEM_MODULES_GROUP_ID, '<strong>' . $mygroup . '</strong>') . '</span>';
1032: } else {
1033: $msgs[] = '&nbsp;&nbsp;' . _AM_SYSTEM_MODULES_BLOCK_ACCESS . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, '<strong>' . $newbid . '</strong>') . sprintf(_AM_SYSTEM_MODULES_GROUP_ID, '<strong>' . $mygroup . '</strong>');
1034: }
1035: }
1036:
1037: if ($template != '') {
1038: $tplfile = $tplfile_handler->create();
1039: $tplfile->setVar('tpl_module', $dirname);
1040: $tplfile->setVar('tpl_refid', $newbid);
1041: $tplfile->setVar('tpl_source', $content, true);
1042: $tplfile->setVar('tpl_tplset', 'default');
1043: $tplfile->setVar('tpl_file', $block['template'], true);
1044: $tplfile->setVar('tpl_type', 'block');
1045: $tplfile->setVar('tpl_lastimported', time());
1046: $tplfile->setVar('tpl_lastmodified', time());
1047: $tplfile->setVar('tpl_desc', $block['description'], true);
1048: if (!$tplfile_handler->insert($tplfile)) {
1049: $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ADD_ERROR, '<strong>' . $block['template'] . '</strong>') . '</span>';
1050: } else {
1051: $newid = $tplfile->getVar('tpl_id');
1052: $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ADD_DATA, '<strong>' . $block['template'] . '</strong>');
1053: if ($xoopsConfig['template_set'] === 'default') {
1054: if (!xoops_template_touch($newid)) {
1055: $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE_FAILD, '<strong>' . $block['template'] . '</strong>') . '</span>';
1056: } else {
1057: $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE, '<strong>' . $block['template'] . '</strong>');
1058: }
1059: }
1060: }
1061: }
1062: $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_BLOCK_CREATED, '<strong>' . $block['name'] . '</strong>') . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, '<strong>' . $newbid . '</strong>');
1063: $sql = 'INSERT INTO ' . $xoopsDB->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newbid . ', -1)';
1064: $xoopsDB->query($sql);
1065: }
1066: }
1067: }
1068: }
1069: $block_arr = XoopsBlock::getByModule($module->getVar('mid'));
1070: /** @var XoopsBlock $block */
1071: foreach ($block_arr as $block) {
1072: if (!in_array($block->getVar('show_func'), $showfuncs) || !in_array($block->getVar('func_file'), $funcfiles)) {
1073: $sql = sprintf('DELETE FROM %s WHERE bid = %u', $xoopsDB->prefix('newblocks'), $block->getVar('bid'));
1074: if (!$xoopsDB->query($sql)) {
1075: $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_BLOCK_DELETE_ERROR, '<strong>' . $block->getVar('name') . '</strong>') . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, '<strong>' . $block->getVar('bid') . '</strong>') . '</span>';
1076: } else {
1077: $msgs[] = '&nbsp;&nbsp;Block <strong>' . $block->getVar('name') . '</strong> deleted. Block ID: <strong>' . $block->getVar('bid') . '</strong>';
1078: if ($block->getVar('template') != '') {
1079: $tplfiles = $tplfile_handler->find(null, 'block', $block->getVar('bid'));
1080: if (is_array($tplfiles)) {
1081: $btcount = count($tplfiles);
1082: for ($k = 0; $k < $btcount; $k++) {
1083: if (!$tplfile_handler->delete($tplfiles[$k])) {
1084: $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _AM_SYSTEM_MODULES_BLOCK_DEPRECATED_ERROR . '(ID: <strong>' . $tplfiles[$k]->getVar('tpl_id') . '</strong>)</span>';
1085: } else {
1086: $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_BLOCK_DEPRECATED, '<strong>' . $tplfiles[$k]->getVar('tpl_file') . '</strong>');
1087: }
1088: }
1089: }
1090: }
1091: }
1092: }
1093: }
1094: }
1095:
1096: // reset compile_id
1097:
1098: // $xoTheme =& $xoopsThemeFactory->createInstance(array('contentTemplate' => @$GLOBALS['xoopsOption']['template_main']));
1099: // $xoopsTpl =& $xoTheme->template;
1100: // $xoopsTpl->setCompileId();
1101:
1102: $template = $clearTpl;
1103: $template->setCompileId();
1104: // $GLOBALS['xoopsTpl']->setCompileId();
1105: // $xoopsTpl->setCompileId();
1106:
1107: // first delete all config entries
1108: /** @var XoopsConfigHandler $config_handler */
1109: $config_handler = xoops_getHandler('config');
1110: $configs = $config_handler->getConfigs(new Criteria('conf_modid', $module->getVar('mid')));
1111: $confcount = count($configs);
1112: $config_delng = array();
1113: if ($confcount > 0) {
1114: $msgs[] = _AM_SYSTEM_MODULES_MODULE_DATA_DELETE;
1115: for ($i = 0; $i < $confcount; $i++) {
1116: if (!$config_handler->deleteConfig($configs[$i])) {
1117: $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _AM_SYSTEM_MODULES_CONFIG_DATA_DELETE_ERROR . sprintf(_AM_SYSTEM_MODULES_GONFIG_ID, '<strong>' . $configs[$i]->getvar('conf_id') . '</strong>') . '</span>';
1118: // save the name of config failed to delete for later use
1119: $config_delng[] = $configs[$i]->getvar('conf_name');
1120: } else {
1121: $config_old[$configs[$i]->getvar('conf_name')]['value'] = $configs[$i]->getvar('conf_value', 'N');
1122: $config_old[$configs[$i]->getvar('conf_name')]['formtype'] = $configs[$i]->getvar('conf_formtype');
1123: $config_old[$configs[$i]->getvar('conf_name')]['valuetype'] = $configs[$i]->getvar('conf_valuetype');
1124: $msgs[] = '&nbsp;&nbsp;' . _AM_SYSTEM_MODULES_GONFIG_DATA_DELETE . sprintf(_AM_SYSTEM_MODULES_GONFIG_ID, '<strong>' . $configs[$i]->getVar('conf_id') . '</strong>');
1125: }
1126: }
1127: }
1128:
1129: // now reinsert them with the new settings
1130: $configs = $module->getInfo('config');
1131: if ($configs !== false) {
1132: if ($module->getVar('hascomments') != 0) {
1133: include_once XOOPS_ROOT_PATH . '/include/comment_constants.php';
1134: array_push($configs, array(
1135: 'name' => 'com_rule',
1136: 'title' => '_CM_COMRULES',
1137: 'description' => '',
1138: 'formtype' => 'select',
1139: 'valuetype' => 'int',
1140: 'default' => 1,
1141: 'options' => array(
1142: '_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE,
1143: '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL,
1144: '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER,
1145: '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN)));
1146: array_push($configs, array(
1147: 'name' => 'com_anonpost',
1148: 'title' => '_CM_COMANONPOST',
1149: 'description' => '',
1150: 'formtype' => 'yesno',
1151: 'valuetype' => 'int',
1152: 'default' => 0));
1153: }
1154: } else {
1155: if ($module->getVar('hascomments') != 0) {
1156: $configs = array();
1157: include_once XOOPS_ROOT_PATH . '/include/comment_constants.php';
1158: $configs[] = array(
1159: 'name' => 'com_rule',
1160: 'title' => '_CM_COMRULES',
1161: 'description' => '',
1162: 'formtype' => 'select',
1163: 'valuetype' => 'int',
1164: 'default' => 1,
1165: 'options' => array(
1166: '_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE,
1167: '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL,
1168: '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER,
1169: '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN));
1170: $configs[] = array(
1171: 'name' => 'com_anonpost',
1172: 'title' => '_CM_COMANONPOST',
1173: 'description' => '',
1174: 'formtype' => 'yesno',
1175: 'valuetype' => 'int',
1176: 'default' => 0);
1177: }
1178: }
1179: // RMV-NOTIFY
1180: if ($module->getVar('hasnotification') != 0) {
1181: if (empty($configs)) {
1182: $configs = array();
1183: }
1184: // Main notification options
1185: include_once XOOPS_ROOT_PATH . '/include/notification_constants.php';
1186: include_once XOOPS_ROOT_PATH . '/include/notification_functions.php';
1187: $options = array();
1188: $options['_NOT_CONFIG_DISABLE'] = XOOPS_NOTIFICATION_DISABLE;
1189: $options['_NOT_CONFIG_ENABLEBLOCK'] = XOOPS_NOTIFICATION_ENABLEBLOCK;
1190: $options['_NOT_CONFIG_ENABLEINLINE'] = XOOPS_NOTIFICATION_ENABLEINLINE;
1191: $options['_NOT_CONFIG_ENABLEBOTH'] = XOOPS_NOTIFICATION_ENABLEBOTH;
1192:
1193: //$configs[] = array ('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLED', 'description' => '_NOT_CONFIG_ENABLEDDSC', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 1);
1194: $configs[] = array(
1195: 'name' => 'notification_enabled',
1196: 'title' => '_NOT_CONFIG_ENABLE',
1197: 'description' => '_NOT_CONFIG_ENABLEDSC',
1198: 'formtype' => 'select',
1199: 'valuetype' => 'int',
1200: 'default' => XOOPS_NOTIFICATION_ENABLEBOTH,
1201: 'options' => $options);
1202: // Event specific notification options
1203: // FIXME: for some reason the default doesn't come up properly
1204: // initially is ok, but not when 'update' module..
1205: $options = array();
1206: $categories =& notificationCategoryInfo('', $module->getVar('mid'));
1207: foreach ($categories as $category) {
1208: $events =& notificationEvents($category['name'], false, $module->getVar('mid'));
1209: foreach ($events as $event) {
1210: if (!empty($event['invisible'])) {
1211: continue;
1212: }
1213: $option_name = $category['title'] . ' : ' . $event['title'];
1214: $option_value = $category['name'] . '-' . $event['name'];
1215: $options[$option_name] = $option_value;
1216: //$configs[] = array ('name' => notificationGenerateConfig($category,$event,'name'), 'title' => notificationGenerateConfig($category,$event,'title_constant'), 'description' => notificationGenerateConfig($category,$event,'description_constant'), 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 1);
1217: }
1218: }
1219: $configs[] = array(
1220: 'name' => 'notification_events',
1221: 'title' => '_NOT_CONFIG_EVENTS',
1222: 'description' => '_NOT_CONFIG_EVENTSDSC',
1223: 'formtype' => 'select_multi',
1224: 'valuetype' => 'array',
1225: 'default' => array_values($options),
1226: 'options' => $options);
1227: }
1228:
1229: if ($configs !== false) {
1230: $msgs[] = 'Adding module config data...';
1231: /** @var XoopsConfigHandler $config_handler */
1232: $config_handler = xoops_getHandler('config');
1233: $order = 0;
1234: foreach ($configs as $config) {
1235: // only insert ones that have been deleted previously with success
1236: if (!in_array($config['name'], $config_delng)) {
1237: $confobj = $config_handler->createConfig();
1238: $confobj->setVar('conf_modid', $newmid);
1239: $confobj->setVar('conf_catid', 0);
1240: $confobj->setVar('conf_name', $config['name']);
1241: $confobj->setVar('conf_title', $config['title'], true);
1242: $confobj->setVar('conf_desc', $config['description'], true);
1243: $confobj->setVar('conf_formtype', $config['formtype']);
1244: if (isset($config['valuetype'])) {
1245: $confobj->setVar('conf_valuetype', $config['valuetype']);
1246: }
1247: if (isset($config_old[$config['name']]['value']) && $config_old[$config['name']]['formtype'] == $config['formtype'] && $config_old[$config['name']]['valuetype'] == $config['valuetype']) {
1248: // preserver the old value if any
1249: // form type and value type must be the same
1250: $confobj->setVar('conf_value', $config_old[$config['name']]['value'], true);
1251: } else {
1252: $confobj->setConfValueForInput($config['default'], true);
1253:
1254: //$confobj->setVar('conf_value', $config['default'], true);
1255: }
1256: $confobj->setVar('conf_order', $order);
1257: $confop_msgs = '';
1258: if (isset($config['options']) && \is_array($config['options'])) {
1259: foreach ($config['options'] as $key => $value) {
1260: $confop = $config_handler->createConfigOption();
1261: $confop->setVar('confop_name', $key, true);
1262: $confop->setVar('confop_value', $value, true);
1263: $confobj->setConfOptions($confop);
1264: $confop_msgs .= '<br>&nbsp;&nbsp;&nbsp;&nbsp; ' . _AM_SYSTEM_MODULES_CONFIG_ADD . _AM_SYSTEM_MODULES_NAME . ' <strong>' . (defined($key) ? constant($key) : $key) . '</strong> ' . _AM_SYSTEM_MODULES_VALUE . ' <strong>' . $value . '</strong> ';
1265: unset($confop);
1266: }
1267: }
1268: $order++;
1269: if (false !== $config_handler->insertConfig($confobj)) {
1270: //$msgs[] = '&nbsp;&nbsp;Config <strong>'.$config['name'].'</strong> added to the database.'.$confop_msgs;
1271: $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_CONFIG_DATA_ADD, '<strong>' . $config['name'] . '</strong>') . $confop_msgs;
1272: } else {
1273: $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_CONFIG_DATA_ADD_ERROR, '<strong>' . $config['name'] . '</strong>') . '</span>';
1274: }
1275: unset($confobj);
1276: }
1277: }
1278: unset($configs);
1279: }
1280:
1281: // execute module specific update script if any
1282: if (function_exists('xoops_module_update_' . $dirname)) {
1283: $func = 'xoops_module_update_' . $dirname;
1284: if (!$func($module, $prev_version)) {
1285: $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_EXECUTE, $func) . '</p>';
1286: $msgs = array_merge($msgs, $module->getErrors());
1287: } else {
1288: $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_SUCESS, '<strong>' . $func . '</strong>') . '</p>';
1289: $msgs += $module->getErrors();
1290: }
1291: }
1292: $msgs[] = sprintf(_AM_SYSTEM_MODULES_OKUPD, '<strong>' . $module->getVar('name', 's') . '</strong>');
1293: $msgs[] = '</div></div>';
1294: $msgs[] = '<div class="center"><a href="admin.php?fct=modulesadmin">' . _AM_SYSTEM_MODULES_BTOMADMIN . '</a> | <a href="' . XOOPS_URL . '/modules/' . $module->getInfo('dirname', 'e') . '/' . $module->getInfo('adminindex') . '">' . _AM_SYSTEM_MODULES_INSTALL_THISMODULE . '</a></div>';
1295: // foreach ($msgs as $msg) {
1296: // echo $msg . '<br>';
1297: // }
1298: }
1299: // Call Footer
1300: // xoops_cp_footer();
1301: // Flush cache files for cpanel GUIs
1302: // xoops_load("cpanel", "system");
1303: // XoopsSystemCpanel::flush();
1304: //
1305: // require_once XOOPS_ROOT_PATH . '/modules/system/class/maintenance.php';
1306: // $maintenance = new SystemMaintenance();
1307: // $folder = array(1, 3);
1308: // $maintenance->CleanCache($folder);
1309: //Set active modules in cache folder
1310: // xoops_setActiveModules();
1311: // break;
1312: //-----------------------------------------------
1313:
1314: $ret = implode('<br>', $msgs);
1315:
1316: return $ret;
1317: }
1318:
1319: /**
1320: * @param $mid
1321: *
1322: * @return string
1323: */
1324: function xoops_module_activate($mid)
1325: {
1326: // Get module handler
1327:
1328: $module_handler = xoops_getHandler('module');
1329: /** @var \XoopsModule $module */
1330: $module = $module_handler->get($mid);
1331: include_once XOOPS_ROOT_PATH . '/class/template.php';
1332: xoops_template_clear_module_cache($module->getVar('mid'));
1333: // Display header
1334: $msgs = array();
1335: $msgs[] = '<div id="xo-module-log">';
1336:
1337: $logHeader = xoops_module_log_header($module, _AM_SYSTEM_MODULES_ACTIVATE);
1338: $msgs[] = implode('<br>', $logHeader);
1339:
1340: // Change value
1341: $module->setVar('isactive', 1);
1342: if (!$module_handler->insert($module)) {
1343: $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILACT, '<strong>' . $module->getVar('name', 's') . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br>' . $module->getHtmlErrors() . '</p>';
1344: } else {
1345: $blocks = XoopsBlock::getByModule($module->getVar('mid'));
1346: $bcount = count($blocks);
1347: for ($i = 0; $i < $bcount; ++$i) {
1348: $blocks[$i]->setVar('isactive', 1);
1349: $blocks[$i]->store();
1350: }
1351: // provide a link to the activated module
1352: $moduleName = $module->getVar('name', 's');
1353: $moduleLink = '<a href="' . XOOPS_URL . '/modules/' . $module->getInfo('dirname', 'e') . '/' . $module->getInfo('adminindex') . '">' . $moduleName . '</a>';
1354: $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_OKACT, '<strong>' . $moduleLink . '</strong>') . '</p></div>';
1355:
1356: }
1357: //$msgs[] = '</div>';
1358: $msgs[] = '<div class="center"><a href="admin.php?fct=modulesadmin">' . _AM_SYSTEM_MODULES_BTOMADMIN . '</a></div>';
1359: $ret = implode('<br>', $msgs);
1360:
1361: return $ret;
1362: }
1363:
1364: /**
1365: * @param $mid
1366: *
1367: * @return string
1368: */
1369: function xoops_module_deactivate($mid)
1370: {
1371: global $xoopsConfig;
1372: // Get module handler
1373:
1374: $module_handler = xoops_getHandler('module');
1375: $module = $module_handler->get($mid);
1376: include_once XOOPS_ROOT_PATH . '/class/template.php';
1377: xoops_template_clear_module_cache($mid);
1378: // Display header
1379: $msgs = array();
1380: $msgs[] = '<div id="xo-module-log">';
1381:
1382: $logHeader = xoops_module_log_header($module, _AM_SYSTEM_MODULES_DEACTIVATE);
1383: $msgs[] = implode('<br>', $logHeader);
1384:
1385: // Change value
1386: $module->setVar('isactive', 0);
1387: if ($module->getVar('dirname') === 'system') {
1388: $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILDEACT, '<strong>' . $module->getVar('name') . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br> - ' . _AM_SYSTEM_MODULES_SYSNO . '</p>';
1389: } elseif ($module->getVar('dirname') == $xoopsConfig['startpage']) {
1390: $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILDEACT, '<strong>' . $module->getVar('name') . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br> - ' . _AM_SYSTEM_MODULES_STRTNO . '</p>';
1391: } else {
1392: if (!$module_handler->insert($module)) {
1393: $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILDEACT, '<strong>' . $module->getVar('name') . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br>' . $module->getHtmlErrors() . '</p>';
1394: } else {
1395: $blocks = XoopsBlock::getByModule($module->getVar('mid'));
1396: $bcount = count($blocks);
1397: for ($i = 0; $i < $bcount; ++$i) {
1398: $blocks[$i]->setVar('isactive', 0);
1399: $blocks[$i]->store();
1400: }
1401: $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_OKDEACT, '<strong>' . $module->getVar('name') . '</strong>') . '</p>';
1402: }
1403: }
1404: $msgs[] = '<div class="center"><a href="admin.php?fct=modulesadmin">' . _AM_SYSTEM_MODULES_BTOMADMIN . '</a></div>';
1405: $ret = implode('<br>', $msgs);
1406:
1407: return $ret;
1408: }
1409:
1410: /**
1411: * @param $mid
1412: * @param $name
1413: *
1414: * @return string
1415: */
1416: function xoops_module_change($mid, $name)
1417: {
1418:
1419: $module_handler = xoops_getHandler('module');
1420: $module = $module_handler->get($mid);
1421: $module->setVar('name', $name);
1422: $myts = \MyTextSanitizer::getInstance();
1423: if (!$module_handler->insert($module)) {
1424: $ret = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILORDER, '<strong>' . $myts->stripSlashesGPC($name) . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br>';
1425: $ret .= $module->getHtmlErrors() . '</p>';
1426:
1427: return $ret;
1428: }
1429:
1430: return '<p>' . sprintf(_AM_SYSTEM_MODULES_OKORDER, '<strong>' . $myts->stripSlashesGPC($name) . '</strong>') . '</p>';
1431: }
1432:
1433: /**
1434: * @param $module
1435: * @param $title
1436: *
1437: * @return array
1438: */
1439: function xoops_module_log_header($module, $title)
1440: {
1441: $msgs[] = '<div class="header">';
1442: $msgs[] = $errs[] = '<h4>' . $title . $module->getInfo('name', 's') . '</h4>';
1443:
1444: if ($module->getInfo('image') !== false && trim($module->getInfo('image')) != '') {
1445: if (_AM_SYSTEM_MODULES_ACTIVATE === $title) {
1446: $msgs[] = '<a href="' . XOOPS_URL . '/modules/' . $module->getInfo('dirname', 'e') . '/' . $module->getInfo('adminindex') . '"><img src="' . XOOPS_URL . '/modules/' . $module->getInfo('dirname', 'e') . '/' . trim($module->getInfo('image')) . '" alt="" /></a>';
1447: } else {
1448: $msgs[] = '<img src="' . XOOPS_URL . '/modules/' . $module->getVar('dirname') . '/' . trim($module->getInfo('image')) . '" alt="" />';
1449: }
1450: }
1451: $msgs[] = '<strong>' . _VERSION . ':</strong> ' . $module->getInfo('version');
1452: if ($module->getInfo('author') !== false && trim($module->getInfo('author')) != '') {
1453: $msgs[] = '<strong>' . _AUTHOR . ':</strong> ' . htmlspecialchars(trim($module->getInfo('author')), ENT_QUOTES);
1454: }
1455: $msgs[] = '</div>';
1456:
1457: return $msgs;
1458: }
1459:
1460: /**
1461: * Clean cache 'xoops_data/caches/smarty_cache'
1462: *
1463: * @param array|null $cacheList int[] of cache "ids"
1464: * 1 = smarty cache
1465: * 2 = smarty compile
1466: * 3 = xoops cache
1467: * or null to clear all
1468: * @return bool
1469: */
1470: function xoops_module_delayed_clean_cache($cacheList = null)
1471: {
1472: if (empty($cacheList)) {
1473: $cacheList = array (1,2,3);
1474: }
1475: require_once XOOPS_ROOT_PATH . '/modules/system/class/maintenance.php';
1476: $maintenance = new SystemMaintenance();
1477: register_shutdown_function(array($maintenance, 'CleanCache'), $cacheList);
1478: }
1479: