/** * Assignes the acl values to the template. * * @param integer $objectTypeID */ public function assignVariables($objectTypeID) { if (WCF::getTPL()->get('aclValues') === null) { WCF::getTPL()->assign('aclValues', array()); } if (!$this->assignVariablesDisabled && isset($_POST['aclValues'])) { $values = $_POST['aclValues']; $data = $this->getPermissions($objectTypeID, array(), null, true); foreach ($values as $type => $optionData) { if ($type === 'user') { $users = User::getUsers(array_keys($optionData)); } $values[$type] = array('label' => array(), 'option' => array()); foreach ($optionData as $typeID => $optionValues) { foreach ($optionValues as $optionID => $optionValue) { if (!isset($data['options'][$optionID])) { unset($optionValues[$optionID]); } } if (empty($optionValues)) { continue; } $values[$type]['option'][$typeID] = $optionValues; if ($type === 'group') { $values[$type]['label'][$typeID] = UserGroup::getGroupByID($typeID)->getName(); } else { $values[$type]['label'][$typeID] = $users[$typeID]->username; } } } $values['options'] = $data['options']; $values['categories'] = $data['categories']; WCF::getTPL()->append('aclValues', array($objectTypeID => $values)); } }
/** * Handles the saved event. * * @param array $parameter */ protected function saved(array $parameter) { // get message, check by difference is quickreply or postadd $message = $parameter == null ? $this->eventObj->text : $parameter['message']->message; //if (!\wcf\system\Regex::compile('(^Butler.*$)')->match($message, true)) return; // get cached questions from cache, filter it by array functions, easier then foreach $questions = \wbb\data\post\butler\question\QuestionCache::getInstance()->getQuestions(); $questions = array_filter(array_map(function ($question) use($message) { if (!\wcf\system\Regex::compile(sprintf('(^%s.*$)', empty($question->prefixUsername) ? 'Butler' : $question->prefixUsername))->match($message, true)) { return false; } else { return $question->matches($message); } }, $questions), function ($value) { if ($value) { return $value; } }); // check if a value is given, otherwise abort continue of function if ($questions == null) { return; } else { $question = \wbb\data\post\butler\question\QuestionCache::getInstance()->getQuestionByID(array_rand($questions, 1)); } // get cached answers from cache, try to get only assigned answers $answers = \wbb\data\post\butler\answer\AnswerCache::getInstance()->getAnswers(); $answers = $answers[$question->questionID]; // check if a value is given and declare variable on success, otherwise abort function if ($answers == null) { return; } else { $answer = $answers[array_rand($answers, 1)]; } $threadID = 0; if ($parameter == null) { $threadActionObject = $this->eventObj->objectAction->getReturnValues(); $threadID = $threadActionObject['returnValues']->threadID; } else { $threadID = $this->eventObj->getContainer()->threadID; } $author = null; if ($question->prefixUserID > 0) { $author = \wcf\data\user\User::getUsers(array($question->prefixUserID)); if (count($author) == 1) { $author = array_shift($author); } } $postData = array('threadID' => $threadID, 'userID' => $question->prefixUserID == 0 ? null : $question->prefixUserID, 'username' => $author == null ? empty($question->prefixUsername) ? 'Butler' : $question->prefixUsername : $author->username, 'message' => $answer->getFormattedMessage(), 'time' => TIME_NOW, 'enableSmilies' => $answer->enableSmilies, 'enableHtml' => $answer->enableHtml, 'enableBBCodes' => $answer->enableBBCodes, 'showSignature' => 0); $objectAction = new \wbb\data\post\PostAction(array(), 'create', array('data' => $postData)); $objectAction->executeAction(); }