Index: branches/5.2.x/units/poll_comments/poll_comment_eh.php =================================================================== diff -u -N -r14586 -r14624 --- branches/5.2.x/units/poll_comments/poll_comment_eh.php (.../poll_comment_eh.php) (revision 14586) +++ branches/5.2.x/units/poll_comments/poll_comment_eh.php (.../poll_comment_eh.php) (revision 14624) @@ -1,6 +1,6 @@ Application->isAdminUser) { return ; @@ -59,48 +62,41 @@ } /** - * Before New PollComment created + * Occurs before creating item * * @param kEvent $event + * @return void + * @access protected */ - function OnBeforeItemCreate(&$event) + protected function OnBeforeItemCreate(&$event) { - if ($this->Application->isAdminUser) { + if ( $this->Application->isAdminUser ) { return ; } $object =& $event->getObject(); /* @var $object kDBItem */ - // get Poll info - $parent_prefix = $this->Application->getUnitOption($this->Prefix, 'ParentPrefix'); - if($parent_prefix) { - $main_object =& $this->Application->recallObject($parent_prefix.'.'.$special, null,Array('raise_warnings' => 0)); - /* @var $main_object kDBItem */ + $parent_info = $object->getLinkedInfo($event->Special); + $poll_id = $parent_info['ParentId']; - if (!$main_object->isLoaded()) { - $main_object =& $this->Application->recallObject($parent_prefix); - } - - $poll_id = $main_object->GetDBField($this->Application->getUnitOption($event->Prefix, 'ForeignKey')); - } - - if ($poll_id) { + if ( $poll_id ) { $spam_helper =& $this->Application->recallObject('SpamHelper'); /* @var $spam_helper SpamHelper */ $spam_helper->InitHelper($poll_id, 'PollComment', 0); // ResourceId used for SpamControl only - if ($spam_helper->InSpamControl()) { + if ( $spam_helper->InSpamControl() ) { $event->status = kEvent::erFAIL; $object->SetError('CommentText', 'too_frequent', 'lu_error_AlreadyCommented'); return ; } + + $object->SetDBField('PollId', $poll_id); // PollId } $object->SetDBField('CreatedById', $this->Application->RecallVar('user_id')); $object->SetDBField('UserIP', $_SERVER['REMOTE_ADDR']); - $object->SetDBField('PollId', $poll_id); // PollId $object->SetDBField('Status', STATUS_ACTIVE); parent::OnBeforeItemCreate($event); @@ -127,17 +123,22 @@ } /** - * Updates item review counter + * Protects against spam * * @param kEvent $event + * @return void + * @access protected */ - function OnAfterItemCreate(&$event) + protected function OnAfterItemCreate(&$event) { - if (!$this->Application->isAdminUser) { + parent::OnAfterItemCreate($event); + + if ( !$this->Application->isAdminUser ) { $spam_helper =& $this->Application->recallObject('SpamHelper'); /* @var $spam_helper SpamHelper */ $object =& $event->getObject(); + /* @var $object kDBItem */ $comment_settings = 'poll_CommentDelay_Value:poll_CommentDelay_Interval'; $spam_helper->InitHelper($object->GetDBField('PollId'), 'PollComment', $comment_settings);