XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
ModuleInstallInformation.class.php
1<?php
12
13define('LEGACY_INSTALLINFO_STATUS_LOADED', 'loaded');
14define('LEGACY_INSTALLINFO_STATUS_UPDATED', 'updated');
15define('LEGACY_INSTALLINFO_STATUS_ORDER_UPDATED', 'order_updated');
16define('LEGACY_INSTALLINFO_STATUS_NEW', 'new');
17define('LEGACY_INSTALLINFO_STATUS_DELETED', 'deleted');
18
24{
25 public $mStatus = LEGACY_INSTALLINFO_STATUS_LOADED;
26
27 public $mFuncNum = 0;
28
29 public $mName = '';
30
31 public $mOptions = '';
32
33 public $mFuncFile = '';
34 public $mShowFunc = '';
35 public $mEditFunc = '';
36 public $mTemplate = '';
37
38 public function __construct($funcNum, $name, $funcFile, $showFunc, $editFunc, $template, $options = null)
39 {
40 $this->mFuncNum = (int)$funcNum;
41 $this->mName = $name;
42 $this->mFuncFile = $funcFile;
43 $this->mShowFunc = $showFunc;
44 $this->mEditFunc = $editFunc;
45 $this->mTemplate = $template;
46 $this->mOptions = $options;
47 }
48
53 public function isEqual(&$block)
54 {
55 if ($this->mFuncNum != $block->mFuncNum) {
56 return false;
57 }
58
59 if ($this->mName != $block->mName) {
60 return false;
61 }
62
63 if ($this->mFuncFile != $block->mFuncFile) {
64 return false;
65 }
66
67 if ($this->mShowFunc != $block->mShowFunc) {
68 return false;
69 }
70
71 if ($this->mEditFunc != $block->mEditFunc) {
72 return false;
73 }
74
75 if ($this->mTemplate != $block->mTemplate) {
76 return false;
77 }
78
79 return true;
80 }
81
82 public function update(&$block)
83 {
84 $this->mStatus = LEGACY_INSTALLINFO_STATUS_UPDATED;
85
86 $this->mName = $block->mName;
87 $this->mFuncFile = $block->mFuncFile;
88 $this->mShowFunc = $block->mShowFunc;
89 $this->mEditFunc = $block->mEditFunc;
90 $this->mTemplate = $block->mTemplate;
91 }
92}
93
95{
96 public $mBlocks = [];
97 public $mShowFuncs = [];
98 public $mFuncFiles = [];
99
100 public function add(&$info)
101 {
102 if (isset($this->mBlocks[$info->mFuncNum])) {
103 return false;
104 }
105
106 $this->mBlocks[$info->mFuncNum] =& $info;
107 $this->mShowFuncs[] = $info->mShowFunc;
108 $this->mFuncFiles[] = $info->mFuncFile;
109
110 ksort($this->mBlocks);
111
112 return true;
113 }
114
115 public function &get($funcNum)
116 {
117 if (isset($this->mBlocks[$funcNum])) {
118 return $this->mBlocks[$funcNum];
119 }
120
121 $ret = null;
122 return $ret;
123 }
124
125 public function funcExists($info)
126 {
127 return (in_array($info->mShowFunc, $this->mShowFuncs, true) && in_array($info->mFuncFile, $this->mFuncFiles, true));
128 }
129
134 public function update(&$collection)
135 {
136 foreach (array_keys($this->mBlocks) as $idx) {
137 $t_block =& $collection->get($this->mBlocks[$idx]->mFuncNum);
138 if (null == $t_block) {
139 if (!$collection->funcExists($this->mBlocks[$idx])) {
140 $this->mBlocks[$idx]->mStatus = LEGACY_INSTALLINFO_STATUS_DELETED;
141 } else {
142 $this->mBlocks[$idx]->mStatus = LEGACY_INSTALLINFO_STATUS_UPDATED; // No Action.
143 }
144 } elseif (!$this->mBlocks[$idx]->isEqual($t_block)) {
145 $this->mBlocks[$idx]->update($t_block);
146 }
147 }
148
149 foreach (array_keys($collection->mBlocks) as $idx) {
150 $func_num = $collection->mBlocks[$idx]->mFuncNum;
151 if (!isset($this->mBlocks[$func_num])) {
152 $this->add($collection->mBlocks[$idx]);
153 $this->mBlocks[$func_num]->mStatus = LEGACY_INSTALLINFO_STATUS_NEW;
154 }
155 }
156 }
157
158 public function reset()
159 {
160 unset($this->mBlocks);
161 $this->mBlocks = [];
162 }
163}
164
170{
171 public $mStatus = LEGACY_INSTALLINFO_STATUS_LOADED;
172
173 public $mOrder = 0;
174
175 public $mName = '';
176
177 public $mTitle = '';
178
179 public $mDescription = '';
180
181 public $mFormType = '';
182
183 public $mValueType = '';
184
185 public $mDefault = null;
186
187 public $mOption = null;
188
189 public function __construct($name, $title, $description, $formType, $valueType, $default, $order = 0)
190 {
191 $this->mName = $name;
192 $this->mTitle = $title;
193 $this->mDescription = $description;
194 $this->mFormType = $formType;
195 $this->mValueType = $valueType;
196 $this->mDefault = $default;
197 $this->mOrder = (int)$order;
198
199 $this->mOption =new Legacy_PreferenceOptionInfoCollection();
200 }
201
206 public function isEqual(&$preference)
207 {
208 if ($this->mName != $preference->mName) {
209 return false;
210 }
211
212 if ($this->mTitle != $preference->mTitle) {
213 return false;
214 }
215
216 if ($this->mDescription != $preference->mDescription) {
217 return false;
218 }
219
220 if ($this->mFormType != $preference->mFormType) {
221 return false;
222 }
223
224 if ($this->mValueType != $preference->mValueType) {
225 return false;
226 }
227
228 if ($this->mOrder != $preference->mOrder) {
229 return false;
230 }
231
232 if (!$this->mOption->isEqual($preference->mOption)) {
233 return false;
234 }
235
236 return true;
237 }
238
239 public function update(&$preference)
240 {
241 $this->mStatus = LEGACY_INSTALLINFO_STATUS_UPDATED;
242
243 $this->mName = $preference->mName;
244 $this->mTitle = $preference->mTitle;
245 $this->mDescription = $preference->mDescription;
246 $this->mFormType = $preference->mFormType;
247 $this->mValueType = $preference->mValueType;
248 $this->mDefault = $preference->mDefault;
249 $this->mOrder = $preference->mOrder;
250
251 unset($this->mOption);
252 $this->mOption =& $preference->mOption;
253 }
254}
255
257{
258 public $mPreferences = [];
259
260 public $mComments = [];
261
262 public $mNotifications = [];
263
264 public function __construct()
265 {
266 }
267
268 public function add(&$preference)
269 {
270 if ('com_rule' == $preference->mName || 'com_anonpost' == $preference->mName) {
271 if (isset($this->mComments[$preference->mName])) {
272 return false;
273 }
274 $this->mComments[$preference->mName] =& $preference;
275 $this->_sort();
276 return true;
277 }
278
279 if ('notification_enabled' == $preference->mName || 'notification_events' == $preference->mName) {
280 if (isset($this->mNotifications[$preference->mName])) {
281 return false;
282 }
283 $this->mNotifications[$preference->mName] =& $preference;
284 $this->_sort();
285 return true;
286 }
287
288 if (isset($this->mPreferences[$preference->mName])) {
289 return false;
290 }
291
292 $this->mPreferences[$preference->mName] =& $preference;
293 $this->_sort();
294
295 return true;
296 }
297
302 public function _sort()
303 {
304 $currentOrder = 0;
305 foreach (array_keys($this->mPreferences) as $idx) {
306 if ($this->mPreferences[$idx]->mOrder != $currentOrder) {
307 $this->mPreferences[$idx]->mStatus = LEGACY_INSTALLINFO_STATUS_ORDER_UPDATED;
308 $this->mPreferences[$idx]->mOrder = $currentOrder;
309 }
310
311 $currentOrder++;
312 }
313
314 foreach (array_keys($this->mComments) as $idx) {
315 if ($this->mComments[$idx]->mOrder != $currentOrder) {
316 $this->mComments[$idx]->mStatus = LEGACY_INSTALLINFO_STATUS_ORDER_UPDATED;
317 $this->mComments[$idx]->mOrder = $currentOrder;
318 }
319
320 $currentOrder++;
321 }
322
323 foreach (array_keys($this->mNotifications) as $idx) {
324 if ($this->mNotifications[$idx]->mOrder != $currentOrder) {
325 $this->mNotifications[$idx]->mStatus = LEGACY_INSTALLINFO_STATUS_ORDER_UPDATED;
326 $this->mNotifications[$idx]->mOrder = $currentOrder;
327 }
328
329 $currentOrder++;
330 }
331 }
332
333 public function &get($name)
334 {
335 $ret = null;
336
337 if (isset($this->mPreferences[$name])) {
338 return $this->mPreferences[$name];
339 }
340
341 return $ret;
342 }
343
344 public function &getNotify($name)
345 {
346 $ret = null;
347
348 if (isset($this->mNotifications[$name])) {
349 return $this->mNotifications[$name];
350 }
351
352 return $ret;
353 }
354
361 public function update($collection)
362 {
363 //
364 // Preferences
365 //
366 foreach (array_keys($this->mPreferences) as $idx) {
367 $t_preference =& $collection->get($this->mPreferences[$idx]->mName);
368 if (null == $t_preference) {
369 $this->mPreferences[$idx]->mStatus = LEGACY_INSTALLINFO_STATUS_DELETED;
370 } elseif (!$this->mPreferences[$idx]->isEqual($t_preference)) {
371 $this->mPreferences[$idx]->update($t_preference);
372 }
373 }
374
375 foreach (array_keys($collection->mPreferences) as $idx) {
376 $name = $collection->mPreferences[$idx]->mName;
377 if (!isset($this->mPreferences[$name])) {
378 $this->add($collection->mPreferences[$name]);
379 $this->mPreferences[$name]->mStatus = LEGACY_INSTALLINFO_STATUS_NEW;
380 }
381 }
382
383 //
384 // Comments
385 //
386 if (count($this->mComments) > 0 && 0 == count($collection->mComments)) {
387 foreach (array_keys($this->mComments) as $idx) {
388 $this->mComments[$idx]->mStatus = LEGACY_INSTALLINFO_STATUS_DELETED;
389 }
390 } elseif (0 == count($this->mComments) && count($collection->mComments) > 0) {
391 $this->mComments =& $collection->mComments;
392 foreach (array_keys($this->mComments) as $idx) {
393 $this->mComments[$idx]->mStatus = LEGACY_INSTALLINFO_STATUS_NEW;
394 }
395 }
396
397 //
398 // Notifications
399 //
400 foreach (array_keys($this->mNotifications) as $idx) {
401 $t_preference =& $collection->getNotify($this->mNotifications[$idx]->mName);
402 if (null == $t_preference) {
403 $this->mNotifications[$idx]->mStatus = LEGACY_INSTALLINFO_STATUS_DELETED;
404 } elseif (!$this->mNotifications[$idx]->isEqual($t_preference)) {
405 $this->mNotifications[$idx]->update($t_preference);
406 }
407 }
408
409 foreach (array_keys($collection->mNotifications) as $idx) {
410 $name = $collection->mNotifications[$idx]->mName;
411 if (!isset($this->mNotifications[$name])) {
412 $this->add($collection->mNotifications[$name]);
413 $this->mNotifications[$name]->mStatus = LEGACY_INSTALLINFO_STATUS_NEW;
414 }
415 }
416 }
417
418 public function reset()
419 {
420 unset($this->mPreferences);
421 $this->mPreferences = [];
422 }
423}
424
426{
427 public $mName = '';
428 public $mValue = '';
429
430 public function __construct($name, $value)
431 {
432 $this->mName = $name;
433 $this->mValue = $value;
434 }
435
436 public function isEqual($option)
437 {
438 return (($this->mName == $option->mName) && ($this->mValue == $option->mValue));
439 }
440}
441
443{
444 public $mOptions = [];
445
446 public function __construct()
447 {
448 }
449
450 public function add($option)
451 {
452 $this->mOptions[] = $option;
453 return true;
454 }
455
456 public function isEqual($collection)
457 {
458 if (count($this->mOptions) != count($collection->mOptions)) {
459 return false;
460 }
461
462 foreach (array_keys($this->mOptions) as $idx) {
463 if (!$this->mOptions[$idx]->isEqual($collection->mOptions[$idx])) {
464 return false;
465 }
466 }
467
468 return true;
469 }
470
471 public function reset()
472 {
473 unset($this->mOptions);
474 $this->mOptions = [];
475 }
476}
477
479{
480 public function __construct()
481 {
482 }
483
487 public function &loadBlockInformations()
488 {
489 }
490
494 public function &loadPreferenceInformations()
495 {
496 }
497}
498
503{
507 public $_mDirname;
508
509 public function __construct($dirname)
510 {
511 $this->_mDirname = $dirname;
512 }
513
520 public function &_createBlockInformation($funcNum, $arr)
521 {
522 $showFunc = '';
523 if (isset($arr['class'])) {
524 $showFunc = 'cl::' . $arr['class'];
525 } else {
526 $showFunc = $arr['show_func'];
527 }
528
529 //$editFunc = isset($arr['edit_func']) ? $arr['edit_func'] : null;
530 $editFunc = $arr['edit_func'] ?? null;
531 //$template = isset($arr['template']) ? $arr['template'] : null;
532 $template = $arr['template'] ?? null;
533 //$options = isset($arr['options']) ? $arr['options'] : null;
534 $options = $arr['options'] ?? null;
535
536 $info =new Legacy_BlockInformation($funcNum, $arr['name'], $arr['file'], $showFunc, $editFunc, $template, $options);
537
538 return $info;
539 }
540
544 public function &loadBlockInformations()
545 {
546 $modversion = [];
547 $collection =new Legacy_BlockInfoCollection();
548
549 $t_filePath = XOOPS_ROOT_PATH . '/modules/' . $this->_mDirname . '/xoops_version.php';
550 if (!file_exists($t_filePath)) {
551 return $collection;
552 }
553
554 include $t_filePath;
555
556 if (!isset($modversion['blocks'])) {
557 return $collection;
558 }
559
560 $blockArr = $modversion['blocks'];
561
562 //
563 // Try (1) --- func_num
564 //
565 $successFlag = true;
566 foreach ($blockArr as $idx => $block) {
567 if (isset($block['func_num'])) {
568 $info =& $this->_createBlockInformation($block['func_num'], $block);
569 $successFlag &= $collection->add($info);
570 unset($info);
571 } else {
572 $successFlag = false;
573 break;
574 }
575 }
576
577 if ($successFlag) {
578 return $collection;
579 }
580
581 //
582 // Try (2) --- index pattern
583 //
584 $collection->reset();
585
586 $successFlag = true;
587 foreach ($blockArr as $idx => $block) {
588 if (is_int($idx)) {
589 $info =& $this->_createBlockInformation($idx, $block);
590 $successFlag &= $collection->add($info);
591 unset($info);
592 } else {
593 $successFlag = false;
594 break;
595 }
596 }
597
598 if ($successFlag) {
599 return $collection;
600 }
601
602 //
603 // Try (3) --- automatic
604 //
605 $collection->reset();
606
607 $idx = 1;
608 foreach ($blockArr as $block) {
609 $info =& $this->_createBlockInformation($idx++, $block);
610 $successFlag &= $collection->add($info);
611 unset($info);
612 }
613
614 return $collection;
615 }
616
617 public function &_createPreferenceInformation($arr)
618 {
619 //$arr['description'] = isset($arr['description']) ? $arr['description'] : null;
620 $arr['description'] ??= null;
621 $info =new Legacy_PreferenceInformation($arr['name'], $arr['title'], $arr['description'], $arr['formtype'], $arr['valuetype'], $arr['default']);
622 if (isset($arr['options'])) {
623 foreach ($arr['options'] as $name => $value) {
624 $option =new Legacy_PreferenceOptionInformation($name, $value);
625 $info->mOption->add($option);
626 unset($option);
627 }
628 }
629
630 return $info;
631 }
632
633 public function _loadCommentPreferenceInfomations($modversion, $collection)
634 {
635 if (isset($modversion['hasComments']) && true == $modversion['hasComments']) {
636 require_once XOOPS_ROOT_PATH . '/include/comment_constants.php';
637
638 $comRule = [
639 'name' => 'com_rule',
640 'title' => '_CM_COMRULES',
641 'description' => '',
642 'formtype' => 'select',
643 'valuetype' => 'int',
644 'default' => 1,
645 'options' => ['_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE, '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL, '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER, '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN]
646 ];
647 $info =& $this->_createPreferenceInformation($comRule);
648 $collection->add($info);
649 unset($info);
650
651 $comAnonpost = [
652 'name' => 'com_anonpost',
653 'title' => '_CM_COMANONPOST',
654 'description' => '',
655 'formtype' => 'yesno',
656 'valuetype' => 'int',
657 'default' => 0
658 ];
659 $info =& $this->_createPreferenceInformation($comAnonpost);
660 $collection->add($info);
661 unset($info);
662 }
663 }
664
665 public function _loadNotificationPreferenceInfomations($modversion, $collection)
666 {
667 if (isset($modversion['hasNotification']) && true == $modversion['hasNotification']) {
668 require_once XOOPS_ROOT_PATH . '/include/notification_constants.php';
669 require_once XOOPS_ROOT_PATH . '/include/notification_functions.php';
670
671 $t_options = [];
672 $t_options['_NOT_CONFIG_DISABLE'] = XOOPS_NOTIFICATION_DISABLE;
673 $t_options['_NOT_CONFIG_ENABLEBLOCK'] = XOOPS_NOTIFICATION_ENABLEBLOCK;
674 $t_options['_NOT_CONFIG_ENABLEINLINE'] = XOOPS_NOTIFICATION_ENABLEINLINE;
675 $t_options['_NOT_CONFIG_ENABLEBOTH'] = XOOPS_NOTIFICATION_ENABLEBOTH;
676
677 $notifyEnable = [
678 'name' => 'notification_enabled',
679 'title' => '_NOT_CONFIG_ENABLE',
680 'description' => '_NOT_CONFIG_ENABLEDSC',
681 'formtype' => 'select',
682 'valuetype' => 'int',
683 'default' => XOOPS_NOTIFICATION_ENABLEBOTH,
684 'options' => $t_options
685 ];
686 $info =& $this->_createPreferenceInformation($notifyEnable);
687 $collection->add($info);
688
689
690 //
691 // FIXME: doesn't work when update module... can't read back the
692 // array of options properly... " changing to &quot;
693 //
694 unset($info, $t_options);
695 //
696 // Get the module object to get mid.
697 //
698 $handler =& xoops_gethandler('module');
699 $module =& $handler->getByDirname($this->_mDirname);
700
701 $t_options = [];
702 $t_categoryArr =& notificationCategoryInfo('', $module->get('mid'));
703 foreach ($t_categoryArr as $t_category) {
704 $t_eventArr =& notificationEvents($t_category['name'], false, $module->get('mid'));
705 foreach ($t_eventArr as $t_event) {
706 if (!empty($t_event['invisible'])) {
707 continue;
708 }
709 $t_optionName = $t_category['title'] . ' : ' . $t_event['title'];
710 $t_options[$t_optionName] = $t_category['name'] . '-' . $t_event['name'];
711 }
712 }
713
714 $notifyEvents = [
715 'name' => 'notification_events',
716 'title' => '_NOT_CONFIG_EVENTS',
717 'description' => '_NOT_CONFIG_EVENTSDSC',
718 'formtype' => 'select_multi',
719 'valuetype' => 'array',
720 'default' => array_values($t_options),
721 'options' => $t_options
722 ];
723 $info =& $this->_createPreferenceInformation($notifyEvents);
724 $collection->add($info);
725 unset($info);
726 }
727 }
728
734 public function &loadPreferenceInformations()
735 {
736 $modversion = [];
737 $collection =new Legacy_PreferenceInfoCollection();
738
739 $t_filePath = XOOPS_ROOT_PATH . '/modules/' . $this->_mDirname . '/xoops_version.php';
740 if (!file_exists($t_filePath)) {
741 return $collection;
742 }
743
744 include $t_filePath;
745
746 //
747 // If the module does not have any preferences, check comments & notifications, and return.
748 //
749 if (!isset($modversion['config'])) {
750 $this->_loadCommentPreferenceInfomations($modversion, $collection);
751 $this->_loadNotificationPreferenceInfomations($modversion, $collection);
752 return $collection;
753 }
754
755 $preferenceArr = $modversion['config'];
756
757 //
758 // Try (1) --- name index pattern
759 //
760 $successFlag = true;
761 foreach ($preferenceArr as $idx => $preference) {
762 if (is_string($idx)) {
763 $preference['name'] = $idx;
764 $info =& $this->_createPreferenceInformation($preference);
765 $successFlag &= $collection->add($info);
766 unset($info);
767 } else {
768 $successFlag = false;
769 break;
770 }
771 }
772
773 //
774 // Try (2) --- auto number
775 //
776 if (!$successFlag) {
777 $collection->reset();
778
779 foreach ($preferenceArr as $preference) {
780 $info =& $this->_createPreferenceInformation($preference);
781 $collection->add($info);
782 unset($info);
783 }
784 }
785
786 //
787 // Add comments & notifications
788 //
789 $this->_loadCommentPreferenceInfomations($modversion, $collection);
790 $this->_loadNotificationPreferenceInfomations($modversion, $collection);
791
792 return $collection;
793 }
794}
795
797{
801 public $_mDirname;
802
803 public function __construct($dirname)
804 {
805 $this->_mDirname = $dirname;
806 }
807
808 public function &_createBlockInformation(&$block)
809 {
810 // Blocks must be return by reference
811 $info =new Legacy_BlockInformation(
812 $block->get('func_num'),
813 $block->get('name'),
814 $block->get('func_file'),
815 $block->get('show_func'),
816 $block->get('edit_func'),
817 $block->get('template'),
818 $block->get('options'));
819 return $info;
820
821 }
822
823 public function &loadBlockInformations()
824 {
825 $collection =new Legacy_BlockInfoCollection();
826
827 $handler =& xoops_getmodulehandler('newblocks', 'legacy');
828
829 $criteria =new CriteriaCompo();
830 $criteria->add(new Criteria('dirname', $this->_mDirname));
831 $criteria->add(new Criteria('block_type', 'M'));
832
833 $blockArr =& $handler->getObjects($criteria);
834
835 foreach (array_keys($blockArr) as $idx) {
836 $info =& $this->_createBlockInformation($blockArr[$idx]);
837 while (!$collection->add($info)) {
838 $info->mFuncNum++;
839 }
840 }
841
842 return $collection;
843 }
844
845 public function &_createPreferenceInformation($config)
846 {
847 $info =new Legacy_PreferenceInformation($config->get('conf_name'), $config->get('conf_title'), $config->get('conf_desc'), $config->get('conf_formtype'), $config->get('conf_valuetype'), $config->get('conf_value'));
848
849 $configOptionArr =& $config->getOptionItems();
850
851 foreach (array_keys($configOptionArr) as $idx) {
852 $option =new Legacy_PreferenceOptionInformation($configOptionArr[$idx]->get('confop_name'), $configOptionArr[$idx]->get('confop_value'));
853 $info->mOption->add($option);
854 unset($option);
855 }
856
857 return $info;
858 }
859
860 public function &loadPreferenceInformations()
861 {
862 $collection =new Legacy_PreferenceInfoCollection();
863
864 $handler =& xoops_gethandler('module');
865 $module =& $handler->getByDirname($this->_mDirname);
866
867 $handler =& xoops_gethandler('config');
868 $criteria =new Criteria('conf_modid', $module->get('mid'));
869 $criteria->setOrder('conf_order');
870 $configArr =& $handler->getConfigs($criteria);
871
872 foreach (array_keys($configArr) as $idx) {
873 $info =& $this->_createPreferenceInformation($configArr[$idx]);
874 $collection->add($info);
875 }
876
877 return $collection;
878 }
879}