<?php
class Andy_SmilieCount_ControllerPublic_Thread extends XFCP_Andy_SmilieCount_ControllerPublic_Thread
{
//########################################
// the original actionAddReply() function is located in library/Xenforo/ControllerPublic/Thread.php
// this actionAddReply() will run instead of the original unless we return parent::actionSave()
//########################################
public function actionAddReply()
{
//########################################
// get data
// this is fetching $smilietext from XenForo_Model_Smilie
// the function getSmilieText() is initially not there
// we extended XenForo_Model_Smilie with Andy_SmilieCount_Model_Smilie
// all Andy_SmilieCount_Model_Smilie functions are now accessible from XenForo_Model_Smilie
// get smilie_text array
$smilietext = $this->getModelFromCache('XenForo_Model_Smilie')->getSmilieText();
// this is fetching $maxsmiliecount from XenForo_Model_Smilie
// the function getSmilieText() is initially not there
// we extended XenForo_Model_Smilie with Andy_SmilieCount_Model_Smilie
// all Andy_SmilieCount_Model_Smilie functions are now accessible from XenForo_Model_Smilie
// get $maxsmiliecount array
$maxsmiliecount = $this->getModelFromCache('XenForo_Model_Smilie')->getMaxSmilieCount();
//########################################
// get max smilie count
// we use the phrase "please_reduce_the_number_of_smilies_to_or_less" to store the data
// edit number between parentheses to adjust max smilie count
foreach ($maxsmiliecount as $k => $v)
{
$phrase_text = $v['phrase_text'];
}
$pos1 = strpos($phrase_text, '(');
$pos2 = strpos($phrase_text, ')');
$pos_length = $pos2 - $pos1;
$pos_length = $pos_length - 1;
$pos1 = $pos1 + 1;
$max_count = substr($phrase_text, $pos1, $pos_length);
//########################################
// default actionAddReply() code
$this->_assertPostOnly();
if ($this->_input->inRequest('more_options'))
{
return $this->responseReroute(__CLASS__, 'reply');
}
$threadId = $this->_input->filterSingle('thread_id', XenForo_Input::UINT);
$visitor = XenForo_Visitor::getInstance();
$ftpHelper = $this->getHelper('ForumThreadPost');
$threadFetchOptions = array('readUserId' => $visitor['user_id']);
$forumFetchOptions = array('readUserId' => $visitor['user_id']);
list($thread, $forum) = $ftpHelper->assertThreadValidAndViewable($threadId, $threadFetchOptions, $forumFetchOptions);
$this->_assertCanReplyToThread($thread, $forum);
if (!XenForo_Captcha_Abstract::validateDefault($this->_input))
{
return $this->responseCaptchaFailed();
}
$input = $this->_input->filter(array(
'attachment_hash' => XenForo_Input::STRING,
'watch_thread_state' => XenForo_Input::UINT,
'watch_thread' => XenForo_Input::UINT,
'watch_thread_email' => XenForo_Input::UINT,
'_set' => array(XenForo_Input::UINT, 'array' => true),
'discussion_open' => XenForo_Input::UINT,
'sticky' => XenForo_Input::UINT,
));
$input['message'] = $this->getHelper('Editor')->getMessageText('message', $this->_input);
$input['message'] = XenForo_Helper_String::autoLinkBbCode($input['message']);
//########################################
// count number of smilies in message
$smilie_count = 0;
foreach ($smilietext as $k => $v)
{
$smilie_count += substr_count($input['message'], $v['smilie_text']);
}
// show error message if $smilie_count exceeds limit
if ($smilie_count > $max_count)
{
return $this->responseError(new XenForo_Phrase('please_reduce_the_number_of_smilies_to_or_less'));
} else {
// run the original actionAddReply() function
return parent::actionAddReply();
}
}
}
?>