XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
CommentEditAction.class.php
1<?php
11
12if (!defined('XOOPS_ROOT_PATH')) {
13 exit();
14}
15
16require_once XOOPS_MODULE_PATH . '/legacy/class/AbstractEditAction.class.php';
17require_once XOOPS_MODULE_PATH . '/legacy/admin/forms/CommentAdminEditForm.class.php';
18require_once XOOPS_ROOT_PATH . '/include/comment_constants.php';
19
21{
27 public function prepare(&$controller, &$xoopsUser)
28 {
29 $this->_setupObject();
30 $this->_setupActionForm();
31 }
32
33 public function _getId()
34 {
35 return isset($_REQUEST['com_id']) ? (int)xoops_getrequest('com_id') : 0;
36 }
37
38 public function &_getHandler()
39 {
40 $handler =& xoops_getmodulehandler('comment');
41 return $handler;
42 }
43
44 public function isEnableCreate()
45 {
46 return false;
47 }
48
52 public function _setupActionForm()
53 {
54 if (XOOPS_COMMENT_PENDING == $this->mObject->get('com_status')) {
55 $this->mActionForm =new Legacy_PendingCommentAdminEditForm();
56 $this->mObjectHandler->mUpdateSuccess->add([&$this, 'doApprove']);
57 $this->mObjectHandler->mUpdateSuccess->add([&$this, 'doUpdate']);
58 } else {
59 $this->mActionForm =new Legacy_ApprovalCommentAdminEditForm();
60 $this->mObjectHandler->mUpdateSuccess->add([&$this, 'doUpdate']);
61 }
62 $this->mActionForm->prepare();
63 }
64
65 public function executeViewInput(&$controller, &$xoopsUser, &$render)
66 {
67 $this->mObject->loadUser();
68 $this->mObject->loadModule();
69 $this->mObject->loadStatus();
70
71 $render->setTemplateName('comment_edit.html');
72 $render->setAttribute('actionForm', $this->mActionForm);
73 $render->setAttribute('object', $this->mObject);
74
75 $subjectHandler =& xoops_gethandler('subjecticon');
76 $subjectIconArr =& $subjectHandler->getObjects();
77
78 $render->setAttribute('subjectIconArr', $subjectIconArr);
79
80 $statusHandler =& xoops_getmodulehandler('commentstatus');
81 if (XOOPS_COMMENT_PENDING == $this->mObject->get('com_status')) {
82 $statusArr =& $statusHandler->getObjects();
83 } else {
84 $statusArr = [];
85 $statusArr[0] =& $statusHandler->get(XOOPS_COMMENT_ACTIVE);
86 $statusArr[1] =& $statusHandler->get(XOOPS_COMMENT_HIDDEN);
87 }
88
89 $render->setAttribute('statusArr', $statusArr);
90 }
91
92 public function executeViewSuccess(&$controller, &$xoopsUser, &$render)
93 {
94 $controller->executeForward('./index.php?action=CommentList');
95 }
96
97 public function executeViewError(&$controller, &$xoopsUser, &$render)
98 {
99 $controller->executeRedirect('./index.php?action=CommentList', 1, _MD_LEGACY_ERROR_DBUPDATE_FAILED);
100 }
101
102 public function executeViewCancel(&$controller, &$xoopsUser, &$render)
103 {
104 $controller->executeForward('./index.php?action=CommentList');
105 }
106
112 public function loadCallbackFile(&$comment)
113 {
114 $handler =& xoops_gethandler('module');
115 $module =& $handler->get($comment->get('com_modid'));
116
117 if (!is_object($module)) {
118 return false;
119 }
120
121 $comment_config = $module->getInfo('comments');
122
123 if (!isset($comment_config['callbackFile'])) {
124 return false;
125 }
126
127 //
128 // Load call-back file
129 //
130 $file = XOOPS_MODULE_PATH . '/' . $module->get('dirname') . '/' . $comment_config['callbackFile'];
131 if (!is_file($file)) {
132 return false;
133 }
134
135 require_once $file;
136
137 return $comment_config;
138 }
139
140 public function doApprove($comment)
141 {
142 $comment_config = (new Legacy_CommentEditAction())->loadCallbackFile($comment);
143
144 if (false == $comment_config) {
145 return;
146 }
147
148 $function = $comment_config['callback']['approve'];
149
150 if (function_exists($function)) {
151 call_user_func($function, $comment);
152 }
153
154 $handler =& xoops_gethandler('member');
155
156 //
157 // TODO We should adjust the following lines and handler's design.
158 // We think we should not use getUser() and updateUserByField in XCube 2.1.
159 //
160 $user =& $handler->getUser($comment->get('com_uid'));
161 if (is_object($user)) {
162 $handler->updateUserByField($user, 'posts', $user->get('posts') + 1);
163 }
164 }
165
166 public function doUpdate($comment)
167 {
168 //
169 // call back
170 //
171 $comment_config = (new Legacy_CommentEditAction())->loadCallbackFile($comment);
172
173 if (false == $comment_config) {
174 return;
175 }
176
177 $function = $comment_config['callback']['update'];
178
179 if (function_exists($function)) {
180 $criteria = new CriteriaCompo(new Criteria('com_modid', $comment->get('com_modid')));
181 $criteria->add(new Criteria('com_itemid', $comment->get('com_itemid')));
182 $criteria->add(new Criteria('com_status', XOOPS_COMMENT_ACTIVE));
183
184 $handler =& xoops_gethandler('comment');
185 $commentCount = $handler->getCount($criteria);
186
187 call_user_func_array($function, [$comment->get('com_itemid'), $commentCount, $comment->get('com_id')]);
188 }
189 }
190}
prepare(&$controller, &$xoopsUser)