/** * Inserts a separator in a very long continuous sequences of characters * @param string $text The input string. * @param int $maxLength The maximum length of sequence. * @param string $customBreaker The custom string to be used as breaker. * @return string Returns the altered string. */ public static function fixLongWords($text, $maxLength, $customBreaker = '') { $maxLength = (int) min(65535, $maxLength); if ($maxLength > 5) { ob_start(); if ($customBreaker == '') { if (!empty($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== false) { $breaker = '<span style="margin: 0 -0.65ex 0 -1px;padding:0;"> </span>'; } else { $breaker = '<span style="font-size:0;padding:0;margin:0;"> </span>'; } } else { $breaker = $customBreaker; } $plainText = $text; $plainText = preg_replace(_JC_REGEXP_EMAIL, '', $plainText); $plainText = preg_replace('#<br\\s?/?>#is' . JCOMMENTS_PCRE_UTF8, '', $plainText); $plainText = preg_replace('#<img[^\\>]+/>#is' . JCOMMENTS_PCRE_UTF8, '', $plainText); $plainText = preg_replace('#<a.*?>(.*?)</a>#is' . JCOMMENTS_PCRE_UTF8, '', $plainText); $plainText = preg_replace('#<span class="quote">(.*?)</span>#is', '', $plainText); $plainText = preg_replace('#<span[^\\>]*?>(.*?)</span>#is', '\\1', $plainText); $plainText = preg_replace('#<pre.*?>(.*?)</pre>#isU' . JCOMMENTS_PCRE_UTF8, '', $plainText); $plainText = preg_replace('#<blockquote.*?>(.*?)</blockquote>#isU' . JCOMMENTS_PCRE_UTF8, '\\1 ', $plainText); $plainText = preg_replace('#<code.*?>(.*?)</code>#isU' . JCOMMENTS_PCRE_UTF8, '', $plainText); $plainText = preg_replace('#<embed.*?>(.*?)</embed>#is' . JCOMMENTS_PCRE_UTF8, '', $plainText); $plainText = preg_replace('#<object.*?>(.*?)</object>#is' . JCOMMENTS_PCRE_UTF8, '', $plainText); $plainText = preg_replace('#(^|\\s|\\>|\\()((http://|https://|news://|ftp://|www.)\\w+[^\\s\\[\\]\\<\\>\\"\'\\)]+)#i' . JCOMMENTS_PCRE_UTF8, '', $plainText); $plainText = preg_replace('#<(b|strong|i|em|u|s|del|sup|sub|li)>(.*?)</(b|strong|i|em|u|s|del|sup|sub|li)>#is' . JCOMMENTS_PCRE_UTF8, '\\2 ', $plainText); $words = explode(' ', $plainText); foreach ($words as $word) { if (JCommentsText::strlen($word) > $maxLength) { $text = str_replace($word, JCommentsText::wordwrap($word, $maxLength, $breaker, true), $text); } } ob_end_clean(); } return $text; }
function saveComment($values = array()) { if (JCommentsSecurity::badRequest() == 1) { JCommentsSecurity::notAuth(); } $db =& JCommentsFactory::getDBO(); $config =& JCommentsFactory::getConfig(); $response =& JCommentsFactory::getAjaxResponse(); $values = JCommentsAJAX::prepareValues($_POST); $comment = new JCommentsDB($db); $id = (int) $values['id']; if ($comment->load($id)) { $acl =& JCommentsFactory::getACL(); if ($acl->canEdit($comment)) { if ($values['comment'] == '') { JCommentsAJAX::showErrorMessage(JText::_('ERROR_EMPTY_COMMENT'), 'comment'); } else { if ($config->getInt('comment_maxlength') != 0 && $acl->check('enable_comment_length_check') == 1 && JCommentsText::strlen($values['comment']) > $config->getInt('comment_maxlength')) { JCommentsAJAX::showErrorMessage(JText::_('ERROR_TOO_LONG_COMMENT'), 'comment'); } else { if ($config->getInt('comment_minlength') != 0 && $acl->check('enable_comment_length_check') == 1 && JCommentsText::strlen($values['comment']) < $config->getInt('comment_minlength')) { JCommentsAJAX::showErrorMessage(JText::_('Your comment is too short'), 'comment'); } else { $bbcode =& JCommentsFactory::getBBCode(); $comment->comment = $values['comment']; $comment->comment = $bbcode->filter($comment->comment); $comment->published = $acl->check('autopublish'); if ($config->getInt('comment_title') != 0 && isset($values['title'])) { $comment->title = stripslashes((string) $values['title']); } if ($config->getInt('author_homepage') == 1 && isset($values['homepage'])) { $comment->homepage = JCommentsText::url($values['homepage']); } else { $comment->homepage = ''; } $allowed = true; if ($config->getInt('enable_mambots') == 1) { require_once JCOMMENTS_HELPERS . DS . 'plugin.php'; JCommentsPluginHelper::importPlugin('jcomments'); JCommentsPluginHelper::trigger('onBeforeCommentChanged', array(&$comment, &$response, &$allowed)); } if ($allowed == false) { return $response; } $comment->store(); $comment->checkin(); $comment->datetime = $comment->date; if ($config->getInt('enable_mambots') == 1) { JCommentsPluginHelper::importPlugin('jcomments'); JCommentsPluginHelper::trigger('onAfterCommentChanged', array(&$comment, &$response)); } if ($config->getInt('enable_notification') == 1) { if ($config->check('notification_type', 1) == true) { JComments::sendNotification($comment, false); } } JComments::prepareComment($comment); $tmpl =& JCommentsFactory::getTemplate(); $tmpl->load('tpl_comment'); $tmpl->addVar('tpl_comment', 'get_comment_body', 1); $tmpl->addObject('tpl_comment', 'comment', $comment); $html = $tmpl->renderTemplate('tpl_comment'); $html = JCommentsText::jsEscape($html); $response->addScript("jcomments.updateComment(" . $comment->id . ", '{$html}');"); } } } } else { $response->addAlert(JText::_('ERROR_CANT_EDIT')); } } unset($comment); return $response; }
public static function saveComment($values = array()) { if (JCommentsSecurity::badRequest() == 1) { JCommentsSecurity::notAuth(); } $db = JCommentsFactory::getDBO(); $config = JCommentsFactory::getConfig(); $response = JCommentsFactory::getAjaxResponse(); $values = self::prepareValues($_POST); $comment = new JCommentsTableComment($db); $id = (int) $values['id']; if ($comment->load($id)) { $acl = JCommentsFactory::getACL(); if ($acl->canEdit($comment)) { if ($values['comment'] == '') { self::showErrorMessage(JText::_('ERROR_EMPTY_COMMENT'), 'comment'); } else { if ($config->getInt('comment_maxlength') != 0 && $acl->check('enable_comment_length_check') == 1 && JCommentsText::strlen($values['comment']) > $config->getInt('comment_maxlength')) { self::showErrorMessage(JText::_('ERROR_TOO_LONG_COMMENT'), 'comment'); } else { if ($config->getInt('comment_minlength') != 0 && $acl->check('enable_comment_length_check') == 1 && JCommentsText::strlen($values['comment']) < $config->getInt('comment_minlength')) { self::showErrorMessage(JText::_('ERROR_YOUR_COMMENT_IS_TOO_SHORT'), 'comment'); } else { $bbcode = JCommentsFactory::getBBCode(); $comment->comment = $values['comment']; $comment->comment = $bbcode->filter($comment->comment); $comment->published = $acl->check('autopublish'); if ($config->getInt('comment_title') != 0 && isset($values['title'])) { $comment->title = stripslashes((string) $values['title']); } if ($config->getInt('author_homepage') == 1 && isset($values['homepage'])) { $comment->homepage = JCommentsText::url($values['homepage']); } else { $comment->homepage = ''; } $result = JCommentsEvent::trigger('onJCommentsCommentBeforeChange', array(&$comment)); if (in_array(false, $result, true)) { return $response; } $comment->store(); $comment->checkin(); JCommentsEvent::trigger('onJCommentsCommentAfterChange', array(&$comment)); if ($config->getInt('enable_notification') == 1) { if ($config->check('notification_type', 1) == true) { JComments::sendNotification($comment, false); } } $html = JCommentsText::jsEscape(JComments::getCommentItem($comment)); $response->addScript("jcomments.updateComment(" . $comment->id . ", '{$html}');"); } } } } else { $response->addAlert(JText::_('ERROR_CANT_EDIT')); } } return $response; }