1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10:
11: if (!defined('XOOPS_ROOT_PATH')) exit();
12:
13: require_once XOOPS_LEGACY_PATH . "/admin/class/ModuleInstallInformation.class.php";
14: require_once XOOPS_LEGACY_PATH . "/admin/class/ModuleInstaller.class.php";
15: require_once XOOPS_LEGACY_PATH . "/admin/class/ModuleUpdater.class.php";
16: require_once XOOPS_LEGACY_PATH . "/admin/class/ModuleUninstaller.class.php";
17:
18: require_once XOOPS_ROOT_PATH."/class/template.php";
19:
20: define("MODINSTALL_LOGTYPE_REPORT", "report");
21: define("MODINSTALL_LOGTYPE_WARNING", "warning");
22: define("MODINSTALL_LOGTYPE_ERROR", "error");
23:
24: 25: 26:
27: class Legacy_ModuleInstallLog
28: {
29: var $mFetalErrorFlag = false;
30: var $mMessages = array();
31:
32: function add($msg)
33: {
34: $this->mMessages[] = array('type' => MODINSTALL_LOGTYPE_REPORT, 'message' => $msg);
35: }
36:
37: function addReport($msg)
38: {
39: $this->add($msg);
40: }
41:
42: function addWarning($msg)
43: {
44: $this->mMessages[] = array('type' => MODINSTALL_LOGTYPE_WARNING, 'message' => $msg);
45: }
46:
47: function addError($msg)
48: {
49: $this->mMessages[] = array('type' => MODINSTALL_LOGTYPE_ERROR, 'message' => $msg);
50: $this->mFetalErrorFlag = true;
51: }
52:
53: function hasError()
54: {
55: return $this->mFetalErrorFlag;
56: }
57: }
58:
59: 60: 61: 62: 63: 64: 65: 66: 67: 68:
69: class Legacy_ModuleInstallUtils
70: {
71: 72: 73: 74:
75: function &createInstaller($dirname)
76: {
77: $installer =& Legacy_ModuleInstallUtils::_createInstaller($dirname, 'installer', 'Legacy_ModuleInstaller');
78: return $installer;
79: }
80:
81: 82: 83: 84:
85: function &createUpdater($dirname)
86: {
87: $updater =& Legacy_ModuleInstallUtils::_createInstaller($dirname, 'updater', 'Legacy_ModulePhasedUpgrader');
88: return $updater;
89: }
90:
91: 92: 93: 94:
95: function &createUninstaller($dirname)
96: {
97: $uninstaller =& Legacy_ModuleInstallUtils::_createInstaller($dirname, 'uninstaller', 'Legacy_ModuleUninstaller');
98: return $uninstaller;
99: }
100:
101: 102: 103: 104: 105: 106: 107:
108: function &_createInstaller($dirname, $mode, $defaultClassName)
109: {
110: $info = array();
111:
112: $filepath = XOOPS_MODULE_PATH . "/${dirname}/xoops_version.php";
113: if (file_exists($filepath)) {
114: @include $filepath;
115: $info = $modversion;
116: }
117:
118: if (isset($info['legacy_installer']) && is_array($info['legacy_installer']) && isset($info['legacy_installer'][$mode])) {
119: $updateInfo = $info['legacy_installer'][$mode];
120:
121: $className = $updateInfo['class'];
122: $filePath = isset($updateInfo['filepath']) ? $updateInfo['filepath'] : XOOPS_MODULE_PATH . "/${dirname}/admin/class/${className}.class.php";
123: $namespace = isset($updateInfo['namespace']) ? $updateInfo['namespace'] : ucfirst($dirname);
124:
125: if ($namespace != null) {
126: $className = "${namespace}_${className}";
127: }
128:
129: if (!XC_CLASS_EXISTS($className) && file_exists($filePath)) {
130: require_once $filePath;
131: }
132:
133: if (XC_CLASS_EXISTS($className)) {
134: $installer =new $className();
135: return $installer;
136: }
137: }
138:
139: $installer =new $defaultClassName();
140: return $installer;
141: }
142:
143:
144: 145: 146: 147: 148: 149: 150: 151: 152: 153:
154: function installSQLAutomatically(&$module, &$log)
155: {
156: $sqlfileInfo =& $module->getInfo('sqlfile');
157: $dirname = $module->getVar('dirname');
158:
159: if (!isset($sqlfileInfo[XOOPS_DB_TYPE])) {
160: return;
161: }
162:
163: $sqlfile = $sqlfileInfo[XOOPS_DB_TYPE];
164: $sqlfilepath = XOOPS_MODULE_PATH . "/${dirname}/${sqlfile}";
165:
166: if (isset($module->modinfo['cube_style']) && $module->modinfo['cube_style'] == true) {
167: require_once XOOPS_MODULE_PATH . "/legacy/admin/class/Legacy_SQLScanner.class.php";
168: $scanner =new Legacy_SQLScanner();
169: $scanner->setDB_PREFIX(XOOPS_DB_PREFIX);
170: $scanner->setDirname($module->get('dirname'));
171:
172: if (!$scanner->loadFile($sqlfilepath)) {
173: $log->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_SQL_FILE_NOT_FOUND, $sqlfile));
174: return false;
175: }
176:
177: $scanner->parse();
178: $sqls = $scanner->getSQL();
179:
180: $root =& XCube_Root::getSingleton();
181: $db =& $root->mController->getDB();
182:
183:
184:
185:
186: foreach ($sqls as $sql) {
187: if (!$db->query($sql)) {
188: $log->addError($db->error());
189: return;
190: }
191: }
192:
193: $log->addReport(_AD_LEGACY_MESSAGE_DATABASE_SETUP_FINISHED);
194: }
195: else {
196: require_once XOOPS_ROOT_PATH.'/class/database/sqlutility.php';
197:
198: $reservedTables = array('avatar', 'avatar_users_link', 'block_module_link', 'xoopscomments', 'config', 'configcategory', 'configoption', 'image', 'imagebody', 'imagecategory', 'imgset', 'imgset_tplset_link', 'imgsetimg', 'groups','groups_users_link','group_permission', 'online', 'bannerclient', 'banner', 'bannerfinish', 'priv_msgs', 'ranks', 'session', 'smiles', 'users', 'newblocks', 'modules', 'tplfile', 'tplset', 'tplsource', 'xoopsnotifications');
199:
200: $root =& XCube_Root::getSingleton();
201: $db =& $root->mController->mDB;
202:
203: $sql_query = fread(fopen($sqlfilepath, 'r'), filesize($sqlfilepath));
204: $sql_query = trim($sql_query);
205: SqlUtility::splitMySqlFile($pieces, $sql_query);
206: $created_tables = array();
207: foreach ($pieces as $piece) {
208:
209:
210: $prefixed_query = SqlUtility::prefixQuery($piece, $db->prefix());
211: if (!$prefixed_query) {
212: $log->addError("${piece} is not a valid SQL!");
213: return;
214: }
215:
216:
217: if (!in_array($prefixed_query[4], $reservedTables)) {
218:
219: if (!$db->query($prefixed_query[0])) {
220: $log->addError($db->error());
221: return;
222: }
223: else {
224: if (!in_array($prefixed_query[4], $created_tables)) {
225: $log->addReport(' Table ' . $db->prefix($prefixed_query[4]) . ' created.');
226: $created_tables[] = $prefixed_query[4];
227: }
228: else {
229: $log->addReport(' Data inserted to table ' . $db->prefix($prefixed_query[4]));
230: }
231: }
232: }
233: else {
234:
235: $log->addError($prefixed_query[4] . " is a reserved table!");
236: return;
237: }
238: }
239: }
240: }
241:
242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259:
260: function installAllOfModuleTemplates(&$module, &$log)
261: {
262: $templates = $module->getInfo('templates');
263: if ($templates != false) {
264: foreach ($templates as $template) {
265: Legacy_ModuleInstallUtils::installModuleTemplate($module, $template, $log);
266: }
267: }
268: }
269:
270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286:
287: function installModuleTemplate($module, $template, &$log)
288: {
289: $tplHandler =& xoops_gethandler('tplfile');
290:
291: $fileName = trim($template['file']);
292:
293: $tpldata = Legacy_ModuleInstallUtils::readTemplateFile($module->get('dirname'), $fileName);
294: if ($tpldata == false)
295: return false;
296:
297:
298:
299:
300: $tplfile =& $tplHandler->create();
301: $tplfile->setVar('tpl_refid', $module->getVar('mid'));
302: $tplfile->setVar('tpl_lastimported', 0);
303: $tplfile->setVar('tpl_lastmodified', time());
304:
305: if (preg_match("/\.css$/i", $fileName)) {
306: $tplfile->setVar('tpl_type', 'css');
307: }
308: else {
309: $tplfile->setVar('tpl_type', 'module');
310: }
311:
312: $tplfile->setVar('tpl_source', $tpldata, true);
313: $tplfile->setVar('tpl_module', $module->getVar('dirname'));
314: $tplfile->setVar('tpl_tplset', 'default');
315: $tplfile->setVar('tpl_file', $fileName, true);
316:
317: $description = isset($template['description']) ? $template['description'] : '';
318: $tplfile->setVar('tpl_desc', $description, true);
319:
320: if ($tplHandler->insert($tplfile)) {
321: $log->addReport(XCube_Utils::formatMessage(_AD_LEGACY_MESSAGE_TEMPLATE_INSTALLED, $fileName));
322: }
323: else {
324: $log->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_COULD_NOT_INSTALL_TEMPLATE, $fileName));
325: return false;
326: }
327: }
328:
329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348:
349: function _uninstallAllOfModuleTemplates(&$module, $tplset, &$log)
350: {
351:
352:
353:
354: $tplHandler =& xoops_gethandler('tplfile');
355: $delTemplates = null;
356:
357: $delTemplates =& $tplHandler->find($tplset, 'module', $module->get('mid'));
358:
359: if (is_array($delTemplates) && count($delTemplates) > 0) {
360:
361:
362:
363: $xoopsTpl =new XoopsTpl();
364: $xoopsTpl->clear_cache(null, "mod_" . $module->get('dirname'));
365:
366: foreach ($delTemplates as $tpl) {
367: if (!$tplHandler->delete($tpl)) {
368: $log->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_TEMPLATE_UNINSTALLED, $tpl->get('tpl_file')));
369: }
370: }
371: }
372: }
373:
374: function uninstallAllOfModuleTemplates(&$module, &$log)
375: {
376: Legacy_ModuleInstallUtils::_uninstallAllOfModuleTemplates($module, null, $log);
377: }
378:
379: function clearAllOfModuleTemplatesForUpdate(&$module, &$log)
380: {
381: Legacy_ModuleInstallUtils::_uninstallAllOfModuleTemplates($module, 'default', $log);
382: }
383:
384: 385: 386: 387: 388: 389: 390: 391: 392: 393: 394:
395: function installAllOfBlocks(&$module, &$log)
396: {
397: $definedBlocks = $module->getInfo('blocks');
398: if($definedBlocks == false) {
399: return true;
400: }
401:
402: $func_num = 0;
403: foreach ($definedBlocks as $block) {
404: $successFlag = true;
405: $updateblocks = array();
406:
407:
408: foreach ($definedBlocks as $idx => $block) {
409: if (isset($block['func_num'])) {
410: $updateblocks[$idx] = $block;
411: } else {
412: $successFlag = false;
413: break;
414: }
415: }
416:
417:
418: if ($successFlag == false) {
419: $successFlag = true;
420: $updateblocks = array();
421: foreach ($definedBlocks as $idx => $block) {
422: if (is_int($idx)) {
423: $block['func_num'] = $idx;
424: $updateblocks[$idx] = $block;
425: } else {
426: $successFlag = false;
427: break;
428: }
429: }
430: }
431:
432:
433: if ($successFlag == false) {
434: $successFlag = true;
435: $updateblocks = array();
436:
437: $func_num = 0;
438: foreach ($definedBlocks as $block) {
439: $block['func_num'] = $func_num;
440: $updateblocks[] = $block;
441: }
442: }
443: }
444:
445: foreach ($updateblocks as $block) {
446: $newBlock =& Legacy_ModuleInstallUtils::createBlockByInfo($module, $block, $block['func_num']);
447: Legacy_ModuleInstallUtils::installBlock($module, $newBlock, $block, $log);
448: }
449: }
450:
451: 452: 453: 454: 455: 456: 457: 458: 459: 460: 461: 462: 463: 464:
465: function uninstallAllOfBlocks(&$module, &$log)
466: {
467: $handler =& xoops_gethandler('block');
468: $criteria = new Criteria('mid', $module->get('mid'));
469:
470: $blockArr =& $handler->getObjectsDirectly($criteria);
471:
472: $successFlag = true;
473:
474: foreach (array_keys($blockArr) as $idx) {
475: $successFlag &= Legacy_ModuleInstallUtils::uninstallBlock($blockArr[$idx], $log);
476: }
477:
478: return $successFlag;
479: }
480:
481: 482: 483: 484: 485: 486:
487: function &createBlockByInfo(&$module, $block, $func_num)
488: {
489: $options = isset($block['options']) ? $block['options'] : null;
490: $edit_func = isset($block['edit_func']) ? $block['edit_func'] : null;
491: $template = isset($block['template']) ? $block['template'] : null;
492: $visible = isset($block['visible']) ? $block['visible'] : (isset($block['visible_any']) ? $block['visible_any']: 0);
493: $blockHandler =& xoops_gethandler('block');
494: $blockObj =& $blockHandler->create();
495:
496: $blockObj->set('mid', $module->getVar('mid'));
497: $blockObj->set('options', $options);
498: $blockObj->set('name', $block['name']);
499: $blockObj->set('title', $block['name']);
500: $blockObj->set('block_type', 'M');
501: $blockObj->set('c_type', 1);
502: $blockObj->set('isactive', 1);
503: $blockObj->set('dirname', $module->getVar('dirname'));
504: $blockObj->set('func_file', $block['file']);
505:
506:
507:
508:
509: $show_func = "";
510: if (isset($block['class'])) {
511: $show_func = "cl::" . $block['class'];
512: }
513: else {
514: $show_func = $block['show_func'];
515: }
516:
517: $blockObj->set('show_func', $show_func);
518: $blockObj->set('edit_func', $edit_func);
519: $blockObj->set('template', $template);
520: $blockObj->set('last_modified', time());
521: $blockObj->set('visible', $visible);
522:
523: $func_num = isset($block['func_num']) ? intval($block['func_num']) : $func_num;
524: $blockObj->set('func_num', $func_num);
525:
526: return $blockObj;
527: }
528:
529: 530: 531: 532: 533: 534: 535:
536: function installBlock(&$module, &$blockObj, &$block, &$log)
537: {
538: $isNew = $blockObj->isNew();
539: $blockHandler =& xoops_gethandler('block');
540:
541: if (!empty($block['show_all_module'])) {
542: $autolink = false;
543: } else {
544: $autolink = true;
545: }
546: if (!$blockHandler->insert($blockObj, $autolink)) {
547: $log->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_COULD_NOT_INSTALL_BLOCK, $blockObj->getVar('name')));
548:
549: return false;
550: }
551: else {
552: $log->addReport(XCube_Utils::formatMessage(_AD_LEGACY_MESSAGE_BLOCK_INSTALLED, $blockObj->getVar('name')));
553:
554: $tplHandler =& xoops_gethandler('tplfile');
555:
556: Legacy_ModuleInstallUtils::installBlockTemplate($blockObj, $module, $log);
557:
558:
559:
560:
561: if ($isNew) {
562: if (!empty($block['show_all_module'])) {
563: $link_sql = "INSERT INTO " . $blockHandler->db->prefix('block_module_link') . " (block_id, module_id) VALUES (".$blockObj->getVar('bid').", 0)";
564: if (!$blockHandler->db->query($link_sql)) {
565: $log->addWarning(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_COULD_NOT_SET_LINK, $blockObj->getVar('name')));
566: }
567: }
568: $gpermHandler =& xoops_gethandler('groupperm');
569: $bperm =& $gpermHandler->create();
570: $bperm->setVar('gperm_itemid', $blockObj->getVar('bid'));
571: $bperm->setVar('gperm_name', 'block_read');
572: $bperm->setVar('gperm_modid', 1);
573:
574: if (!empty($block['visible_any'])) {
575: $memberHandler =& xoops_gethandler('member');
576: $groupObjects =& $memberHandler->getGroups();
577: foreach($groupObjects as $group) {
578: $bperm->setVar('gperm_groupid', $group->getVar('groupid'));
579: $bperm->setNew();
580: if (!$gpermHandler->insert($bperm)) {
581: $log->addWarning(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_COULD_NOT_SET_BLOCK_PERMISSION, $blockObj->getVar('name')));
582: }
583: }
584: } else {
585: $root =& XCube_Root::getSingleton();
586: $groups = $root->mContext->mXoopsUser->getGroups(true);
587: foreach ($groups as $mygroup) {
588: $bperm->setVar('gperm_groupid', $mygroup);
589: $bperm->setNew();
590: if (!$gpermHandler->insert($bperm)) {
591: $log->addWarning(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_COULD_NOT_SET_BLOCK_PERMISSION, $blockObj->getVar('name')));
592: }
593: }
594: }
595: }
596:
597: return true;
598: }
599: }
600:
601: 602: 603: 604: 605: 606: 607: 608: 609: 610:
611: function uninstallBlock(&$block, &$log)
612: {
613: $blockHandler =& xoops_gethandler('block');
614: $blockHandler->delete($block);
615: $log->addReport(XCube_Utils::formatMessage(_AD_LEGACY_MESSAGE_UNINSTALLATION_BLOCK_SUCCESSFUL, $block->get('name')));
616:
617:
618:
619:
620: $gpermHandler =& xoops_gethandler('groupperm');
621: $criteria =new CriteriaCompo();
622: $criteria->add(new Criteria('gperm_name', 'block_read'));
623: $criteria->add(new Criteria('gperm_itemid', $block->get('bid')));
624: $criteria->add(new Criteria('gperm_modid', 1));
625: $gpermHandler->deleteAll($criteria);
626: }
627:
628: 629: 630: 631: 632:
633: function installBlockTemplate(&$block, &$module, &$log)
634: {
635: if ($block->get('template') == null) {
636: return true;
637: }
638:
639: $tplHandler =& xoops_gethandler('tplfile');
640:
641: $criteria =new CriteriaCompo();
642: $criteria->add(new Criteria('tpl_type', 'block'));
643: $criteria->add(new Criteria('tpl_tplset', 'default'));
644: $criteria->add(new Criteria('tpl_module', $module->get('dirname')));
645: $criteria->add(new Criteria('tpl_file', $block->get('template')));
646: $tplfiles =& $tplHandler->getObjects($criteria);
647:
648: if (count($tplfiles) > 0) {
649: $tplfile =& $tplfiles[0];
650: }
651: else {
652: $tplfile =& $tplHandler->create();
653: $tplfile->set('tpl_refid', $block->get('bid'));
654: $tplfile->set('tpl_tplset', 'default');
655: $tplfile->set('tpl_file', $block->get('template'));
656: $tplfile->set('tpl_module', $module->get('dirname'));
657: $tplfile->set('tpl_type', 'block');
658:
659: $tplfile->set('tpl_lastimported', 0);
660: }
661:
662: $tplSource = Legacy_ModuleInstallUtils::readTemplateFile($module->get('dirname'), $block->get('template'), true);
663: $tplfile->set('tpl_source', $tplSource);
664: $tplfile->set('tpl_lastmodified', time());
665:
666: if ($tplHandler->insert($tplfile)) {
667: $log->addReport(XCube_Utils::formatMessage(_AD_LEGACY_MESSAGE_BLOCK_TEMPLATE_INSTALLED, $block->get('template')));
668: return true;
669: }
670: else {
671: $log->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_BLOCK_TEMPLATE_INSTALL, $block->get('name')));
672: return false;
673: }
674: }
675:
676: 677: 678: 679: 680:
681: function readTemplateFile($dirname, $fileName, $isblock = false)
682: {
683:
684:
685:
686: if ($isblock) {
687: $filePath = XOOPS_MODULE_PATH . "/" . $dirname . "/templates/blocks/" . $fileName;
688: }
689: else {
690: $filePath = XOOPS_MODULE_PATH . "/" . $dirname . "/templates/" . $fileName;
691: }
692:
693: if (!file_exists($filePath)) {
694: return false;
695: }
696:
697: $lines = file($filePath);
698: if ($lines == false) {
699: return false;
700: }
701:
702: $tpldata = "";
703: foreach ($lines as $line) {
704:
705:
706:
707: $tpldata .= str_replace("\n", "\r\n", str_replace("\r\n", "\n", $line));
708: }
709:
710: return $tpldata;
711: }
712:
713: function installAllOfConfigs(&$module, &$log)
714: {
715: $dirname = $module->get('dirname');
716:
717: $fileReader =new Legacy_ModinfoX2FileReader($dirname);
718: $preferences =& $fileReader->loadPreferenceInformations();
719:
720:
721:
722:
723: foreach (array_keys($preferences->mPreferences) as $idx) {
724: Legacy_ModuleInstallUtils::installPreferenceByInfo($preferences->mPreferences[$idx], $module, $log);
725: }
726:
727:
728:
729:
730: foreach (array_keys($preferences->mComments) as $idx) {
731: Legacy_ModuleInstallUtils::installPreferenceByInfo($preferences->mComments[$idx], $module, $log);
732: }
733:
734:
735:
736:
737: foreach (array_keys($preferences->mNotifications) as $idx) {
738: Legacy_ModuleInstallUtils::installPreferenceByInfo($preferences->mNotifications[$idx], $module, $log);
739: }
740: }
741:
742: function installPreferenceByInfo(&$info, &$module, &$log)
743: {
744: $handler =& xoops_gethandler('config');
745: $config =& $handler->createConfig();
746: $config->set('conf_modid', $module->get('mid'));
747: $config->set('conf_catid', 0);
748: $config->set('conf_name', $info->mName);
749: $config->set('conf_title', $info->mTitle);
750: $config->set('conf_desc', $info->mDescription);
751: $config->set('conf_formtype', $info->mFormType);
752: $config->set('conf_valuetype', $info->mValueType);
753: $config->setConfValueForInput($info->mDefault);
754: $config->set('conf_order', $info->mOrder);
755:
756: if (count($info->mOption->mOptions) > 0) {
757: foreach (array_keys($info->mOption->mOptions) as $idx) {
758: $option =& $handler->createConfigOption();
759: $option->set('confop_name', $info->mOption->mOptions[$idx]->mName);
760: $option->set('confop_value', $info->mOption->mOptions[$idx]->mValue);
761: $config->setConfOptions($option);
762: unset($option);
763: }
764: }
765:
766: if ($handler->insertConfig($config)) {
767: $log->addReport(XCube_Utils::formatMessage(_AD_LEGACY_MESSAGE_INSERT_CONFIG, $config->get('conf_name')));
768: }
769: else {
770: $log->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_COULD_NOT_INSERT_CONFIG, $config->get('conf_name')));
771: }
772: }
773:
774: 775: 776:
777: function &getConfigInfosFromManifesto(&$module)
778: {
779: $configInfos = $module->getInfo('config');
780:
781:
782:
783:
784: if ($module->getVar('hascomments') !=0 ) {
785: require_once XOOPS_ROOT_PATH . "/include/comment_constants.php";
786:
787: $configInfos[] = array('name' => 'com_rule',
788: 'title' => '_CM_COMRULES',
789: 'description' => '',
790: 'formtype' => 'select',
791: 'valuetype' => 'int',
792: 'default' => 1,
793: 'options' => array('_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE, '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL, '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER, '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN)
794: );
795:
796: $configInfos[] = array('name' => 'com_anonpost',
797: 'title' => '_CM_COMANONPOST',
798: 'description' => '',
799: 'formtype' => 'yesno',
800: 'valuetype' => 'int',
801: 'default' => 0
802: );
803: }
804:
805:
806:
807:
808: if ($module->get('hasnotification') != 0) {
809: require_once XOOPS_ROOT_PATH . '/include/notification_constants.php';
810: require_once XOOPS_ROOT_PATH . '/include/notification_functions.php';
811:
812: $t_options = array();
813: $t_options['_NOT_CONFIG_DISABLE'] = XOOPS_NOTIFICATION_DISABLE;
814: $t_options['_NOT_CONFIG_ENABLEBLOCK'] = XOOPS_NOTIFICATION_ENABLEBLOCK;
815: $t_options['_NOT_CONFIG_ENABLEINLINE'] = XOOPS_NOTIFICATION_ENABLEINLINE;
816: $t_options['_NOT_CONFIG_ENABLEBOTH'] = XOOPS_NOTIFICATION_ENABLEBOTH;
817:
818: $configInfos[] = array(
819: 'name' => 'notification_enabled',
820: 'title' => '_NOT_CONFIG_ENABLE',
821: 'description' => '_NOT_CONFIG_ENABLEDSC',
822: 'formtype' => 'select',
823: 'valuetype' => 'int',
824: 'default' => XOOPS_NOTIFICATION_ENABLEBOTH,
825: 'options' => $t_options
826: );
827:
828:
829:
830:
831:
832:
833: unset ($t_options);
834:
835: $t_options = array();
836: $t_categoryArr =& notificationCategoryInfo('', $module->get('mid'));
837: foreach ($t_categoryArr as $t_category) {
838: $t_eventArr =& notificationEvents($t_category['name'], false, $module->get('mid'));
839: foreach ($t_eventArr as $t_event) {
840: if (!empty($t_event['invisible'])) {
841: continue;
842: }
843: $t_optionName = $t_category['title'] . ' : ' . $t_event['title'];
844: $t_options[$t_optionName] = $t_category['name'] . '-' . $t_event['name'];
845: }
846: }
847:
848: $configInfos[] = array(
849: 'name' => 'notification_events',
850: 'title' => '_NOT_CONFIG_EVENTS',
851: 'description' => '_NOT_CONFIG_EVENTSDSC',
852: 'formtype' => 'select_multi',
853: 'valuetype' => 'array',
854: 'default' => array_values($t_options),
855: 'options' => $t_options
856: );
857: }
858:
859: return $configInfos;
860: }
861:
862: 863: 864: 865: 866:
867: function uninstallAllOfConfigs(&$module, &$log)
868: {
869: if ($module->get('hasconfig') == 0) {
870: return;
871: }
872:
873: $configHandler =& xoops_gethandler('config');
874: $configs =& $configHandler->getConfigs(new Criteria('conf_modid', $module->get('mid')));
875:
876: if (count($configs) == 0) {
877: return;
878: }
879:
880: foreach ($configs as $config) {
881: $configHandler->deleteConfig($config);
882: }
883: }
884:
885: function smartUpdateAllOfBlocks(&$module, &$log)
886: {
887: $dirname = $module->get('dirname');
888:
889: $fileReader =new Legacy_ModinfoX2FileReader($dirname);
890: $latestBlocks =& $fileReader->loadBlockInformations();
891:
892: $dbReader =new Legacy_ModinfoX2DBReader($dirname);
893: $currentBlocks =& $dbReader->loadBlockInformations();
894:
895: $currentBlocks->update($latestBlocks);
896:
897: foreach (array_keys($currentBlocks->mBlocks) as $idx) {
898: switch ($currentBlocks->mBlocks[$idx]->mStatus) {
899: case LEGACY_INSTALLINFO_STATUS_LOADED:
900: Legacy_ModuleInstallUtils::updateBlockTemplateByInfo($currentBlocks->mBlocks[$idx], $module, $log);
901: break;
902:
903: case LEGACY_INSTALLINFO_STATUS_UPDATED:
904: Legacy_ModuleInstallUtils::updateBlockByInfo($currentBlocks->mBlocks[$idx], $module, $log);
905: break;
906:
907: case LEGACY_INSTALLINFO_STATUS_NEW:
908: Legacy_ModuleInstallUtils::installBlockByInfo($currentBlocks->mBlocks[$idx], $module, $log);
909: break;
910:
911: case LEGACY_INSTALLINFO_STATUS_DELETED:
912: Legacy_ModuleInstallUtils::uninstallBlockByFuncNum($currentBlocks->mBlocks[$idx]->mFuncNum, $module, $log);
913: break;
914: }
915: }
916: }
917:
918: function smartUpdateAllOfPreferences(&$module, &$log)
919: {
920: $dirname = $module->get('dirname');
921:
922: $fileReader =new Legacy_ModinfoX2FileReader($dirname);
923: $latestPreferences =& $fileReader->loadPreferenceInformations();
924:
925: $dbReader =new Legacy_ModinfoX2DBReader($dirname);
926: $currentPreferences =& $dbReader->loadPreferenceInformations();
927:
928: $currentPreferences->update($latestPreferences);
929:
930:
931:
932:
933: foreach (array_keys($currentPreferences->mPreferences) as $idx) {
934: switch ($currentPreferences->mPreferences[$idx]->mStatus) {
935: case LEGACY_INSTALLINFO_STATUS_UPDATED:
936: Legacy_ModuleInstallUtils::updatePreferenceByInfo($currentPreferences->mPreferences[$idx], $module, $log);
937: break;
938:
939: case LEGACY_INSTALLINFO_STATUS_ORDER_UPDATED:
940: Legacy_ModuleInstallUtils::updatePreferenceOrderByInfo($currentPreferences->mPreferences[$idx], $module, $log);
941: break;
942:
943: case LEGACY_INSTALLINFO_STATUS_NEW:
944: Legacy_ModuleInstallUtils::installPreferenceByInfo($currentPreferences->mPreferences[$idx], $module, $log);
945: break;
946:
947: case LEGACY_INSTALLINFO_STATUS_DELETED:
948: Legacy_ModuleInstallUtils::uninstallPreferenceByOrder($currentPreferences->mPreferences[$idx]->mOrder, $module, $log);
949: break;
950: }
951: }
952:
953:
954:
955:
956: foreach (array_keys($currentPreferences->mComments) as $idx) {
957: switch ($currentPreferences->mComments[$idx]->mStatus) {
958: case LEGACY_INSTALLINFO_STATUS_UPDATED:
959: Legacy_ModuleInstallUtils::updatePreferenceByInfo($currentPreferences->mComments[$idx], $module, $log);
960: break;
961:
962: case LEGACY_INSTALLINFO_STATUS_ORDER_UPDATED:
963: Legacy_ModuleInstallUtils::updatePreferenceOrderByInfo($currentPreferences->mComments[$idx], $module, $log);
964: break;
965:
966: case LEGACY_INSTALLINFO_STATUS_NEW:
967: Legacy_ModuleInstallUtils::installPreferenceByInfo($currentPreferences->mComments[$idx], $module, $log);
968: break;
969:
970: case LEGACY_INSTALLINFO_STATUS_DELETED:
971: Legacy_ModuleInstallUtils::uninstallPreferenceByOrder($currentPreferences->mComments[$idx]->mOrder, $module, $log);
972: break;
973: }
974: }
975:
976:
977:
978:
979: foreach (array_keys($currentPreferences->mNotifications) as $idx) {
980: switch ($currentPreferences->mNotifications[$idx]->mStatus) {
981: case LEGACY_INSTALLINFO_STATUS_UPDATED:
982: Legacy_ModuleInstallUtils::updatePreferenceByInfo($currentPreferences->mNotifications[$idx], $module, $log);
983: break;
984:
985: case LEGACY_INSTALLINFO_STATUS_ORDER_UPDATED:
986: Legacy_ModuleInstallUtils::updatePreferenceOrderByInfo($currentPreferences->mNotifications[$idx], $module, $log);
987: break;
988:
989: case LEGACY_INSTALLINFO_STATUS_NEW:
990: Legacy_ModuleInstallUtils::installPreferenceByInfo($currentPreferences->mNotifications[$idx], $module, $log);
991: break;
992:
993: case LEGACY_INSTALLINFO_STATUS_DELETED:
994: Legacy_ModuleInstallUtils::uninstallPreferenceByOrder($currentPreferences->mNotifications[$idx]->mOrder, $module, $log);
995: break;
996: }
997: }
998: }
999:
1000: function updateBlockTemplateByInfo(&$info, &$module, &$log)
1001: {
1002: $handler =& xoops_getmodulehandler('newblocks', 'legacy');
1003:
1004: $criteria =new CriteriaCompo();
1005: $criteria->add(new Criteria('dirname', $module->get('dirname')));
1006: $criteria->add(new Criteria('func_num', $info->mFuncNum));
1007:
1008: $blockArr =& $handler->getObjects($criteria);
1009: foreach (array_keys($blockArr) as $idx) {
1010: Legacy_ModuleInstallUtils::clearBlockTemplateForUpdate($blockArr[$idx], $module, $log);
1011: Legacy_ModuleInstallUtils::installBlockTemplate($blockArr[$idx], $module, $log);
1012: }
1013: }
1014:
1015: function updateBlockByInfo(&$info, &$module, &$log)
1016: {
1017: $handler =& xoops_getmodulehandler('newblocks', 'legacy');
1018:
1019: $criteria =new CriteriaCompo();
1020: $criteria->add(new Criteria('dirname', $module->get('dirname')));
1021: $criteria->add(new Criteria('func_num', $info->mFuncNum));
1022:
1023: $blockArr =& $handler->getObjects($criteria);
1024: foreach (array_keys($blockArr) as $idx) {
1025: $blockArr[$idx]->set('options', $info->mOptions);
1026: $blockArr[$idx]->set('name', $info->mName);
1027: $blockArr[$idx]->set('func_file', $info->mFuncFile);
1028: $blockArr[$idx]->set('show_func', $info->mShowFunc);
1029: $blockArr[$idx]->set('edit_func', $info->mEditFunc);
1030: $blockArr[$idx]->set('template', $info->mTemplate);
1031:
1032: if ($handler->insert($blockArr[$idx])) {
1033: $log->addReport(XCube_Utils::formatMessage('Update {0} block successfully.', $blockArr[$idx]->get('name')));
1034: }
1035: else {
1036: $log->addError(XCube_Utils::formatMessage('Could not update {0} block.', $blockArr[$idx]->get('name')));
1037: }
1038:
1039: Legacy_ModuleInstallUtils::clearBlockTemplateForUpdate($blockArr[$idx], $module, $log);
1040: Legacy_ModuleInstallUtils::installBlockTemplate($blockArr[$idx], $module, $log);
1041: }
1042: }
1043:
1044: function updatePreferenceByInfo(&$info, &$module, &$log)
1045: {
1046: $handler =& xoops_gethandler('config');
1047:
1048: $criteria =new CriteriaCompo();
1049: $criteria->add(new Criteria('conf_modid', $module->get('mid')));
1050: $criteria->add(new Criteria('conf_catid', 0));
1051: $criteria->add(new Criteria('conf_name', $info->mName));
1052:
1053: $configArr =& $handler->getConfigs($criteria);
1054:
1055: if (!(count($configArr) > 0 && is_object($configArr[0]))) {
1056: $log->addError('Execption Error: Could not find config.');
1057: return;
1058: }
1059:
1060: $config =& $configArr[0];
1061:
1062: $config->set('conf_title', $info->mTitle);
1063: $config->set('conf_desc', $info->mDescription);
1064:
1065:
1066:
1067:
1068: if ($config->get('conf_formtype') != $info->mFormType && $config->get('conf_valuetype') != $info->mValueType) {
1069: $config->set('conf_formtype', $info->mFormType);
1070: $config->set('conf_valuetype', $info->mValueType);
1071: $config->setConfValueForInput($info->mDefault);
1072: }
1073: else {
1074: $config->set('conf_formtype', $info->mFormType);
1075: $config->set('conf_valuetype', $info->mValueType);
1076: }
1077:
1078: $config->set('conf_order', $info->mOrder);
1079:
1080: $optionArr =& $handler->getConfigOptions(new Criteria('conf_id', $config->get('conf_id')));
1081: if (is_array($optionArr)) {
1082: foreach (array_keys($optionArr) as $idx) {
1083: $handler->_oHandler->delete($optionArr[$idx]);
1084: }
1085: }
1086:
1087: if (count($info->mOption->mOptions) > 0) {
1088: foreach (array_keys($info->mOption->mOptions) as $idx) {
1089: $option =& $handler->createConfigOption();
1090: $option->set('confop_name', $info->mOption->mOptions[$idx]->mName);
1091: $option->set('confop_value', $info->mOption->mOptions[$idx]->mValue);
1092: $option->set('conf_id', $option->get('conf_id'));
1093: $config->setConfOptions($option);
1094: unset($option);
1095: }
1096: }
1097:
1098: if ($handler->insertConfig($config)) {
1099: $log->addReport(XCube_Utils::formatMessage("Preference '{0}' is updateded.", $config->get('conf_name')));
1100: }
1101: else {
1102: $log->addError(XCube_Utils::formatMessage("Could not update preference '{0}'.", $config->get('conf_name')));
1103: }
1104: }
1105:
1106: function updatePreferenceOrderByInfo(&$info, &$module, &$log)
1107: {
1108: $handler =& xoops_gethandler('config');
1109:
1110: $criteria =new CriteriaCompo();
1111: $criteria->add(new Criteria('conf_modid', $module->get('mid')));
1112: $criteria->add(new Criteria('conf_catid', 0));
1113: $criteria->add(new Criteria('conf_name', $info->mName));
1114:
1115: $configArr =& $handler->getConfigs($criteria);
1116:
1117: if (!(count($configArr) > 0 && is_object($configArr[0]))) {
1118: $log->addError('Execption Error: Could not find config.');
1119: return;
1120: }
1121:
1122: $config =& $configArr[0];
1123:
1124: $config->set('conf_order', $info->mOrder);
1125:
1126: if (!$handler->insertConfig($config)) {
1127: $log->addError(XCube_Utils::formatMessage("Could not update the order of preference '{0}'.", $config->get('conf_name')));
1128: }
1129: }
1130:
1131: function installBlockByInfo(&$info, &$module, &$log)
1132: {
1133: $handler =& xoops_gethandler('block');
1134: $block =& $handler->create();
1135:
1136: $block->set('mid', $module->get('mid'));
1137: $block->set('func_num', $info->mFuncNum);
1138: $block->set('options', $info->mOptions);
1139: $block->set('name', $info->mName);
1140: $block->set('title', $info->mName);
1141: $block->set('dirname', $module->get('dirname'));
1142: $block->set('func_file', $info->mFuncFile);
1143: $block->set('show_func', $info->mShowFunc);
1144: $block->set('edit_func', $info->mEditFunc);
1145: $block->set('template', $info->mTemplate);
1146: $block->set('block_type', 'M');
1147: $block->set('c_type', 1);
1148:
1149: if (!$handler->insert($block)) {
1150: $log->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_COULD_NOT_INSTALL_BLOCK, $block->get('name')));
1151: return false;
1152: }
1153: else {
1154: $log->addReport(XCube_Utils::formatMessage(_AD_LEGACY_MESSAGE_BLOCK_INSTALLED, $block->get('name')));
1155:
1156: Legacy_ModuleInstallUtils::installBlockTemplate($block, $module, $log);
1157:
1158: return true;
1159: }
1160: }
1161:
1162: 1163: 1164:
1165: function uninstallBlockByFuncNum($func_num, &$module, &$log)
1166: {
1167: $handler =& xoops_getmodulehandler('newblocks', 'legacy');
1168:
1169: $criteria =new CriteriaCompo();
1170: $criteria->add(new Criteria('dirname', $module->get('dirname')));
1171: $criteria->add(new Criteria('func_num', $func_num));
1172:
1173: $blockArr =& $handler->getObjects($criteria);
1174: foreach (array_keys($blockArr) as $idx) {
1175: if ($handler->delete($blockArr[$idx])) {
1176: $log->addReport(XCube_Utils::formatMessage(_AD_LEGACY_MESSAGE_UNINSTALLATION_BLOCK_SUCCESSFUL, $blockArr[$idx]->get('name')));
1177: }
1178: else {
1179:
1180: }
1181:
1182: Legacy_ModuleInstallUtils::uninstallBlockTemplate($blockArr[$idx], $module, $log);
1183: }
1184: }
1185:
1186: 1187: 1188: 1189: 1190: 1191: 1192: 1193: 1194: 1195: 1196: 1197:
1198: function _uninstallBlockTemplate(&$block, &$module, $tplset, &$log)
1199: {
1200: $handler =& xoops_gethandler('tplfile');
1201: $criteria =new CriteriaCompo();
1202: $criteria->add(new Criteria('tpl_refid', $block->get('bid')));
1203: $criteria->add(new Criteria('tpl_file', $block->get('template')));
1204: $criteria->add(new Criteria('tpl_module', $module->get('dirname')));
1205: $criteria->add(new Criteria('tpl_type', 'block'));
1206:
1207: if ($tplset != null) {
1208:
1209: $criteria->add(new Criteria('tpl_tplset', $tplset));
1210: }
1211:
1212: $handler->deleteAll($criteria);
1213: }
1214:
1215: function uninstallBlockTemplate(&$block, &$module, &$log)
1216: {
1217: Legacy_ModuleInstallUtils::_uninstallBlockTemplate($block, $module, null, $log);
1218: }
1219:
1220: 1221: 1222: 1223:
1224: function clearBlockTemplateForUpdate(&$block, &$module, &$log)
1225: {
1226: Legacy_ModuleInstallUtils::_uninstallBlockTemplate($block, $module, 'default', $log);
1227: }
1228:
1229: function uninstallPreferenceByOrder($order, &$module, &$log)
1230: {
1231: $handler =& xoops_gethandler('config');
1232:
1233: $criteria =new CriteriaCompo();
1234: $criteria->add(new Criteria('conf_modid', $module->get('mid')));
1235: $criteria->add(new Criteria('conf_catid', 0));
1236: $criteria->add(new Criteria('conf_order', $order));
1237:
1238: $configArr =& $handler->getConfigs($criteria);
1239:
1240: foreach (array_keys($configArr) as $idx) {
1241: if ($handler->deleteConfig($configArr[$idx])) {
1242: $log->addReport(XCube_Utils::formatMessage("Delete preference '{0}'.", $configArr[$idx]->get('conf_name')));
1243: }
1244: else {
1245: $log->addError(XCube_Utils::formatMessage("Could not delete preference '{0}'.", $configArr[$idx]->get('conf_name')));
1246: }
1247: }
1248: }
1249:
1250: 1251: 1252:
1253: function DBquery($query, &$module, $log)
1254: {
1255: require_once XOOPS_MODULE_PATH . "/legacy/admin/class/Legacy_SQLScanner.class.php";
1256:
1257: $successFlag = true;
1258:
1259: $scanner =new Legacy_SQLScanner();
1260: $scanner->setDB_PREFIX(XOOPS_DB_PREFIX);
1261: $scanner->setDirname($module->get('dirname'));
1262: $scanner->setBuffer($query);
1263: $scanner->parse();
1264: $sqlArr = $scanner->getSQL();
1265:
1266: $root =& XCube_Root::getSingleton();
1267:
1268: foreach ($sqlArr as $sql) {
1269: if ($root->mController->mDB->query($sql)) {
1270: $log->addReport("Success: ${sql}");
1271: $successFlag &= true;
1272: }
1273: else {
1274: $log->addError("Failure: ${sql}");
1275: $successFlag = false;
1276: }
1277: }
1278:
1279: return $successFlag;
1280: }
1281:
1282: function deleteAllOfNotifications(&$module, &$log)
1283: {
1284: $handler =& xoops_gethandler('notification');
1285: $criteria =new Criteria('not_modid', $module->get('mid'));
1286: $handler->deleteAll($criteria);
1287: }
1288:
1289: function deleteAllOfComments(&$module, &$log)
1290: {
1291: $handler =& xoops_gethandler('comment');
1292: $criteria =new Criteria('com_modid', $module->get('mid'));
1293: $handler->deleteAll($criteria);
1294: }
1295: }
1296:
1297: ?>
1298: