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/AbstractDeleteAction.class.php";
14: require_once XOOPS_MODULE_PATH . "/legacy/admin/forms/CommentAdminDeleteForm.class.php";
15: require_once XOOPS_MODULE_PATH . "/legacy/admin/actions/CommentEditAction.class.php";
16:
17: class Legacy_CommentDeleteAction extends Legacy_AbstractDeleteAction
18: {
19: function _getId()
20: {
21: return isset($_REQUEST['com_id']) ? xoops_getrequest('com_id') : 0;
22: }
23:
24: function &_getHandler()
25: {
26: $handler =& xoops_getmodulehandler('comment');
27: $handler->mDeleteSuccess->add(array(&$this, "doDelete"));
28: return $handler;
29: }
30:
31: function _setupActionForm()
32: {
33: $this->mActionForm =new Legacy_CommentAdminDeleteForm();
34: $this->mActionForm->prepare();
35: }
36:
37: function executeViewInput(&$controller, &$xoopsUser, &$render)
38: {
39:
40:
41:
42: $this->mObject->loadUser();
43: $this->mObject->loadModule();
44: $this->mObject->loadStatus();
45:
46:
47:
48:
49: $handler =& xoops_getmodulehandler('comment');
50: $criteria =new Criteria('com_pid', $this->mObject->get('com_id'));
51: $children =& $handler->getObjects($criteria);
52:
53: if (count($children) > 0) {
54: foreach (array_keys($children) as $key) {
55: $children[$key]->loadModule();
56: $children[$key]->loadUser();
57: }
58: }
59:
60: $render->setTemplateName("comment_delete.html");
61: $render->setAttribute('actionForm', $this->mActionForm);
62: $render->setAttribute('object', $this->mObject);
63: $render->setAttribute('children', $children);
64: }
65:
66: function executeViewSuccess(&$controller, &$xoopsUser, &$render)
67: {
68: $controller->executeForward("./index.php?action=CommentList");
69: }
70:
71: function executeViewError(&$controller, &$xoopsUser, &$render)
72: {
73: $controller->executeRedirect("./index.php?action=CommentList", 1, _MD_LEGACY_ERROR_DBUPDATE_FAILED);
74: }
75:
76: function executeViewCancel(&$controller, &$xoopsUser, &$render)
77: {
78: $controller->executeForward("./index.php?action=CommentList");
79: }
80:
81: function doDelete($comment)
82: {
83:
84:
85:
86: if ($comment->get('com_status') != 1 && $comment->get('com_uid') > 0) {
87: $handler =& xoops_gethandler('member');
88:
89:
90:
91:
92:
93: $user =& $handler->getUser($comment->get('com_uid'));
94: if (is_object($user)) {
95: $count = $user->get('posts');
96:
97: if($count > 0) {
98: $handler->updateUserByField($user, 'posts', $count - 1);
99: }
100: }
101: }
102:
103:
104:
105:
106: $comment_config = Legacy_CommentEditAction::loadCallbackFile($comment);
107:
108: if ($comment_config == false) {
109: return;
110: }
111:
112: $function = $comment_config['callback']['update'];
113:
114: if (function_exists($function)) {
115: $criteria = new CriteriaCompo(new Criteria('com_modid', $comment->get('com_modid')));
116: $criteria->add(new Criteria('com_itemid', $comment->get('com_itemid')));
117: $criteria->add(new Criteria('com_status', XOOPS_COMMENT_ACTIVE));
118:
119: $handler =& xoops_gethandler('comment');
120: $commentCount = $handler->getCount($criteria);
121:
122: call_user_func($function, $comment->get('com_id'), $commentCount);
123: }
124: }
125: }
126:
127: ?>
128: