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