/**
  * Inserts tag links into an HTML-formatted text.
  *
  * @param string $html
  * @param array $tags
  * @param array $options
  * @return string
  */
 public static function autoTag($html, array $tags, array &$options = array())
 {
     if (empty($tags)) {
         return $html;
     }
     $html = strval($html);
     $htmlNullified = utf8_strtolower($html);
     $htmlNullified = preg_replace_callback('#<a[^>]+>.+?</a>#', array(__CLASS__, '_autoTag_nullifyHtmlCallback'), $htmlNullified);
     $htmlNullified = preg_replace_callback('#<[^>]+>#', array(__CLASS__, '_autoTag_nullifyHtmlCallback'), $htmlNullified);
     // prepare the options
     $onceOnly = empty($options['onceOnly']) ? false : true;
     $options['autoTagged'] = array();
     // reset this
     // sort tags with the longest one first
     // since 1.0.3
     usort($tags, array(__CLASS__, '_autoTag_sortTagsByLength'));
     foreach ($tags as $tag) {
         $offset = 0;
         $tagText = utf8_strtolower($tag['tag']);
         $tagLength = utf8_strlen($tagText);
         while (true) {
             $pos = utf8_strpos($htmlNullified, $tagText, $offset);
             if ($pos !== false) {
                 // the tag has been found
                 if (self::_autoTag_hasValidCharacterAround($html, $pos, $tagText)) {
                     // and it has good surrounding characters
                     // start replacing
                     $displayText = utf8_substr($html, $pos, $tagLength);
                     $template = new XenForo_Template_Public('tinhte_xentag_bb_code_tag_tag');
                     $template->setParam('tag', $tag);
                     $template->setParam('displayText', $displayText);
                     $replacement = $template->render();
                     if (strlen($replacement) === 0) {
                         // in case template system hasn't been initialized
                         $replacement = sprintf('<a href="%s">%s</a>', XenForo_Link::buildPublicLink('tags', $tag), $displayText);
                     }
                     $html = utf8_substr_replace($html, $replacement, $pos, $tagLength);
                     $htmlNullified = utf8_substr_replace($htmlNullified, str_repeat('_', utf8_strlen($replacement)), $pos, $tagLength);
                     // sondh@2012-09-20
                     // keep track of the auto tagged tags
                     $options['autoTagged'][$tagText][$pos] = $replacement;
                     $offset = $pos + utf8_strlen($replacement);
                     if ($onceOnly) {
                         // auto link only once per tag
                         // break the loop now
                         break;
                         // while (true)
                     }
                 } else {
                     $offset = $pos + $tagLength;
                 }
             } else {
                 // no match has been found, stop working with this tag
                 break;
                 // while (true)
             }
         }
     }
     return $html;
 }
/**
* Callback function for preg_replace_callback call in utf8_ucwords
* You don't need to call this yourself
* @param array of matches corresponding to a single word
* @return string with first char of the word in uppercase
* @see utf8_ucwords
* @see utf8_strtoupper
* @package utf8
* @subpackage strings
*/
function utf8_ucwords_callback($matches)
{
    $leadingws = $matches[2];
    $ucfirst = utf8_strtoupper($matches[3]);
    $ucword = utf8_substr_replace(ltrim($matches[0]), $ucfirst, 0, 1);
    return $leadingws . $ucword;
}
 public static function update($targetClass, $targetPath, $sourceClass, $sourcesContents)
 {
     $targetContents = str_replace($sourceClass, $targetClass, $sourcesContents);
     $php = '<?php';
     $pos = utf8_strpos($targetContents, $php);
     if ($pos !== false) {
         $replacement = sprintf("%s\n\n// updated by %s at %s", $php, __CLASS__, date('c'));
         $targetContents = utf8_substr_replace($targetContents, $replacement, $pos, utf8_strlen($php));
     }
     $classPrefix = substr($targetClass, 0, strpos($targetClass, 'ShippableHelper_'));
     $offset = 0;
     while (true) {
         if (!preg_match('#DevHelper_Helper_ShippableHelper_[a-zA-Z_]+#', $targetContents, $matches, PREG_OFFSET_CAPTURE, $offset)) {
             break;
         }
         $siblingSourceClass = $matches[0][0];
         $offset = $matches[0][1];
         $siblingTargetClass = str_replace('DevHelper_Helper_', $classPrefix, $siblingSourceClass);
         $targetContents = substr_replace($targetContents, $siblingTargetClass, $offset, strlen($siblingSourceClass));
         class_exists($siblingTargetClass);
         $offset += 1;
     }
     $targetContents = preg_replace('#\\* @version \\d+\\s*\\n#', '$0 * @see ' . $sourceClass . "\n", $targetContents, -1, $count);
     return DevHelper_Generator_File::filePutContents($targetPath, $targetContents);
 }
function truncate($text, $length = 30, $truncateString = '...')
{
    if (utf8_strlen($text) > $length) {
        return utf8_substr_replace($text, $truncateString, $length - utf8_strlen($truncateString));
    } else {
        return $text;
    }
}
Exemple #5
0
 public function renderTagUrl(array $tag, array $rendererStates)
 {
     if (!empty($tag['option'])) {
         $url = $tag['option'];
         $text = $this->renderSubTree($tag['children'], $rendererStates);
     } else {
         $url = $this->stringifyTree($tag['children']);
         $text = urldecode($url);
         if (!preg_match('/./u', $text)) {
             $text = $url;
         }
         $text = XenForo_Helper_String::censorString($text);
         if (!empty($rendererStates['shortenUrl'])) {
             $length = utf8_strlen($text);
             if ($length > 100) {
                 $text = utf8_substr_replace($text, '...', 35, $length - 35 - 45);
             }
         }
         $text = htmlspecialchars($text);
     }
     $url = $this->_getValidUrl($url);
     if (!$url) {
         return $text;
     } else {
         list($class, $target, $type) = XenForo_Helper_String::getLinkClassTarget($url);
         $class = $class ? " class=\"{$class}\"" : '';
         $target = $target ? " target=\"{$target}\"" : '';
         if ($type == 'internal') {
             $noFollow = '';
         } else {
             $noFollow = empty($rendererStates['noFollowDefault']) ? '' : ' rel="nofollow"';
         }
         $url = XenForo_Helper_String::censorString($url);
         $test = $this->isImage($url);
         if ($test) {
             return sprintf($this->_imageTemplate, htmlspecialchars($url), $rendererStates['lightBox'] ? ' LbImage' : '');
         }
         return $this->_wrapInHtml('<a href="' . htmlspecialchars($url) . '"' . $target . $class . $noFollow . '>', '</a>', $text);
     }
 }
Exemple #6
0
 /**
  * Renders a URL tag.
  *
  * @param array $tag Information about the tag reference; keys: tag, option, children
  * @param array $rendererStates Renderer states to push down
  *
  * @return string Rendered tag
  */
 public function renderTagUrl(array $tag, array $rendererStates)
 {
     if (!empty($tag['option'])) {
         $url = $tag['option'];
         $text = $this->renderSubTree($tag['children'], $rendererStates);
     } else {
         $url = $this->stringifyTree($tag['children']);
         $text = rawurldecode($url);
         if (!preg_match('/./u', $text)) {
             $text = $url;
         }
         $text = XenForo_Helper_String::censorString($text);
         if (!empty($rendererStates['shortenUrl'])) {
             $length = utf8_strlen($text);
             if ($length > 100) {
                 $text = utf8_substr_replace($text, '...', 35, $length - 35 - 45);
             }
         }
         $text = htmlspecialchars($text);
     }
     $url = $this->_getValidUrl($url);
     if (!$url) {
         return $text;
     } else {
         list($class, $target, $type) = XenForo_Helper_String::getLinkClassTarget($url);
         if ($type == 'internal') {
             $noFollow = '';
         } else {
             $noFollow = empty($rendererStates['noFollowDefault']) ? '' : ' rel="nofollow"';
         }
         $href = XenForo_Helper_String::censorString($url);
         if ($rendererStates['disableProxying']) {
             $proxyHref = false;
         } else {
             $proxyHref = $this->_handleLinkProxyOption($href, $type);
         }
         $proxyAttr = '';
         if ($proxyHref) {
             $proxyAttr = ' data-proxy-href="' . htmlspecialchars($proxyHref) . '"';
             $class .= ' ProxyLink';
         }
         $class = $class ? " class=\"{$class}\"" : '';
         $target = $target ? " target=\"{$target}\"" : '';
         return $this->_wrapInHtml('<a href="' . htmlspecialchars($href) . '"' . $target . $class . $proxyAttr . $noFollow . '>', '</a>', $text);
     }
 }
/**
 * Spellchecker. Called by an AJAX request
 *
 * Runs the given Text through Aspell and prints XHTML with
 * markup. The first char represents the error code:
 *
 * 0 - No spelling mistakes
 * 1 - Spelling mistakes found
 * 2 - An error occurred error message follows
 *
 * @author Andreas Gohr <*****@*****.**>
 */
function spell_check()
{
    global $spell;
    $string = $_POST['data'];
    $misspell = false;
    // for streamlined line endings
    $string = preg_replace("/(\r\n)|(\r)/", "\n", $string);
    $string = htmlspecialchars($string);
    // make sure multiple spaces and leading are kept
    $string = preg_replace('/^ /m', '&nbsp;', $string);
    $string = preg_replace('/  /', '&nbsp; ', $string);
    // we need the text as array later
    $data = explode("\n", $string);
    // don't check links and medialinks for spelling errors
    $string = preg_replace_callback('/\\{\\{(.*?)(\\|(.*?))?(\\}\\})/', 'spaceslink', $string);
    $string = preg_replace_callback('/\\[\\[(.*?)(\\|(.*?))?(\\]\\])/', 'spaceslink', $string);
    // run aspell in terse sgml mode, ignore nbsp as correct word
    if (!$spell->runAspell($string, $out, $err, array('!', '+html', '@nbsp'))) {
        print '2';
        //to indicate an error
        print "An error occurred while trying to run the spellchecker:\n";
        print $err;
        return;
    }
    #use this to debug raw aspell output
    #print "1$out"; return;
    // go through the result
    $lines = split("\n", $out);
    $rcnt = count($lines) - 1;
    // aspell result count
    $lcnt = count($data) + 1;
    // original line counter
    for ($i = $rcnt; $i >= 0; $i--) {
        $line = trim($lines[$i]);
        if ($line[0] == '@') {
            continue;
        }
        // comment
        if ($line[0] == '*') {
            continue;
        }
        // no mistake in this word
        if ($line[0] == '+') {
            continue;
        }
        // root of word was found
        if ($line[0] == '?') {
            continue;
        }
        // word was guessed
        if (empty($line)) {
            // empty line -> new source line
            $lcnt--;
            continue;
        }
        // now get the misspelled words
        if (preg_match('/^& ([^ ]+) (\\d+) (\\d+): (.*)/', $line, $match)) {
            // match with suggestions
            $word = $match[1];
            $off = $match[3] - 1;
            $sug = split(', ', $match[4]);
        } elseif (preg_match('/^# ([^ ]+) (\\d+)/', $line, $match)) {
            // match without suggestions
            $word = $match[1];
            $off = $match[2] - 1;
            $sug = null;
        } else {
            // couldn't parse output
            print '2';
            print "The spellchecker output couldn't be parsed.\n";
            print "Line {$i}:" . $line;
            return;
        }
        $misspell = true;
        //aspell < 0.60 returns singlebyte offsets
        if ($spell->version >= 600) {
            $len = utf8_strlen($word);
            $data[$lcnt] = utf8_substr_replace($data[$lcnt], spell_formatword($word, $sug), $off, $len);
        } else {
            $len = strlen($word);
            $data[$lcnt] = substr_replace($data[$lcnt], spell_formatword($word, $sug), $off, $len);
        }
    }
    //end of output parsing
    // the first char returns the spell info
    if ($misspell) {
        $string = '1' . join('<br />', $data);
    } else {
        $string = '0' . join('<br />', $data);
    }
    if (!$_POST['utf8']) {
        // encode multibyte chars as entities for broken Konqueror
        $string = utf8_tohtml($string);
    }
    //output
    print $string;
}
Exemple #8
0
 /**
  * Inserts tag links into an HTML-formatted text.
  *
  * @param string $html
  * @param array $tags
  * @param array $options
  */
 public static function autoTag($html, array $tagsOrTexts, array &$options = array())
 {
     if (empty($tagsOrTexts)) {
         return $html;
     }
     $html = strval($html);
     $tagTexts = Tinhte_XenTag_Helper::getTextsFromTagsOrTexts($tagsOrTexts);
     // prepare the options
     $onceOnly = empty($options['onceOnly']) ? false : true;
     $options['autoTagged'] = array();
     // reset this
     // sort tags with the longest one first
     // since 1.0.3
     usort($tagTexts, array(__CLASS__, '_autoTag_sortTagsByLength'));
     foreach ($tagTexts as $tagText) {
         $offset = 0;
         $tagLength = utf8_strlen($tagText);
         while (true) {
             $pos = Tinhte_XenTag_Helper::utf8_stripos($html, $tagText, $offset);
             if ($pos !== false) {
                 // the tag has been found
                 if (!self::_autoTag_isBetweenHtmlTags($html, $pos) and self::_autoTag_hasValidCharacterAround($html, $pos, $tagText)) {
                     // and it's not between HTML tags,
                     // with good surrounding characters
                     // start replacing
                     $template = new XenForo_Template_Public('tinhte_xentag_bb_code_tag_tag');
                     $template->setParam('tag', $tagText);
                     $template->setParam('displayText', utf8_substr($html, $pos, $tagLength));
                     $replacement = $template->render();
                     $html = utf8_substr_replace($html, $replacement, $pos, $tagLength);
                     // sondh@2012-09-20
                     // keep track of the auto tagged tags
                     $options['autoTagged'][$tagText][$pos] = $replacement;
                     $offset = $pos + utf8_strlen($replacement);
                     if ($onceOnly) {
                         // auto link only once per tag
                         // break the loop now
                         break;
                         // while (true)
                     }
                 } else {
                     $offset = $pos + $tagLength;
                 }
             } else {
                 // no match has been found, stop working with this tag
                 break;
                 // while (true)
             }
         }
     }
     return $html;
 }
Exemple #9
0
 /**
  * @param string $string
  * @param int $maxLength
  * @param array $options
  *
  * @return string
  */
 public static function snippet($string, $maxLength = 0, array $options = array())
 {
     $options = array_merge(array('previewBreakBbCode' => 'prbreak', 'ellipsis' => '…'), $options);
     if (!empty($options['previewBreakBbCode']) && preg_match(sprintf('#\\[%1$s\\](?<preview>.*)\\[/%1$s\\]#', preg_quote($options['previewBreakBbCode'], '#')), $string, $matches, PREG_OFFSET_CAPTURE)) {
         // preview break bbcode found
         if (!empty($matches['preview'][0])) {
             // preview text specified, use it directly
             $string = $matches['preview'][0];
             $maxLength = 0;
         } else {
             // use content before the found bbcode to continue
             $string = substr($string, 0, $matches[0][1]);
             $maxLength = 0;
         }
     }
     $snippet = XenForo_Template_Helper_Core::callHelper('snippet', array($string, $maxLength, $options));
     // TODO: find better way to avoid having to call this
     $snippet = htmlspecialchars_decode($snippet);
     if ($maxLength == 0 || $maxLength > utf8_strlen($string)) {
         return $snippet;
     }
     $offset = 0;
     $stack = array();
     while (true) {
         $startPos = utf8_strpos($snippet, '<', $offset);
         if ($startPos !== false) {
             $endPos = utf8_strpos($snippet, '>', $startPos);
             if ($endPos === false) {
                 // we found a partial open tag, best to delete the whole thing
                 $snippet = utf8_substr($snippet, 0, $startPos) . $options['ellipsis'];
                 break;
             }
             $foundLength = $endPos - $startPos - 1;
             $found = utf8_substr($snippet, $startPos + 1, $foundLength);
             $offset = $endPos;
             if (preg_match('#^(?<closing>/?)(?<tag>\\w+)#', $found, $matches)) {
                 $tag = $matches['tag'];
                 $isClosing = !empty($matches['closing']);
                 $isSelfClosing = !$isClosing && utf8_substr($found, $foundLength - 1, 1) === '/';
                 if ($isClosing) {
                     $lastInStack = null;
                     if (count($stack) > 0) {
                         $lastInStack = array_pop($stack);
                     }
                     if ($lastInStack !== $tag) {
                         // found tag does not match the one in stack
                         $replacement = '';
                         // first we have to close the one in stack
                         if ($lastInStack !== null) {
                             $replacement .= sprintf('</%s>', $tag);
                         }
                         // then we have to self close the found tag
                         $replacement .= utf8_substr($snippet, $startPos, $endPos - $startPos - 1);
                         $replacement .= '/>';
                         // do the replacement
                         $snippet = utf8_substr_replace($snippet, $replacement, $startPos, $endPos - $startPos);
                         $offset = $startPos + utf8_strlen($snippet);
                     }
                 } elseif ($isSelfClosing) {
                     // do nothing
                 } else {
                     // is opening tag
                     $stack[] = $tag;
                 }
             }
         } else {
             break;
         }
     }
     while (!empty($stack)) {
         $snippet .= sprintf('</%s>', array_pop($stack));
     }
     $snippet = utf8_trim($snippet);
     if ($snippet === '') {
         // this is bad...
         // happens if the $maxLength is too low and for some reason the very first tag cannot finish
         $snippet = utf8_trim(strip_tags($string));
         if ($snippet !== '') {
             $snippet = XenForo_Template_Helper_Core::callHelper('snippet', array($snippet, $maxLength, $options));
         } else {
             // this is super bad...
             // the string is one big html tag and it is too damn long
             $snippet = $options['ellipsis'];
         }
     }
     return $snippet;
 }
function pun_tags_parse_string($text)
{
    global $lang_pun_tags;
    if (utf8_strlen(forum_trim($text)) > 100) {
        message($lang_pun_tags['Count error']);
    }
    // Remove symbols and multiple whitespace
    $text = preg_replace('/[\'\\^\\$&\\(\\)<>`"\\|@_\\?%~\\+\\[\\]{}:=\\/#\\\\;!\\*\\.]+/', '', preg_replace('/[\\s]+/', ' ', $text));
    $text = censor_words($text);
    $text = explode(',', $text);
    $results = array();
    foreach ($text as $tag) {
        $tmp_tag = utf8_trim($tag);
        if (!empty($tmp_tag)) {
            $results[] = utf8_substr_replace($tmp_tag, '', 50);
        }
    }
    return array_unique($results);
}
Exemple #11
0
 public static function substr_replace($str, $repl, $start, $length = null)
 {
     if ($length === false) {
         return utf8_substr_replace($str, $repl, $start);
     } else {
         return utf8_substr_replace($str, $repl, $start, $length);
     }
 }
 function testLinefeedReplace()
 {
     $str = "Iñ\ntërnâtiônàlizætiøn";
     $replaced = "Iñ\ntërnâtX\nY";
     $this->assertEqual(utf8_substr_replace($str, "X\nY", 9), $replaced);
 }
Exemple #13
0
 private function getBlogsReviews($thislist, $type = 'reviews')
 {
     //$this->load->helper('utf8blog');
     require_once DIR_SYSTEM . 'helper/utf8blog.php';
     if (file_exists(DIR_IMAGE . 'no_image.jpg')) {
         $no_image = 'no_image.jpg';
     }
     if (file_exists(DIR_IMAGE . 'no_image.png')) {
         $no_image = 'no_image.png';
     }
     $this->data['settings'] = $thislist;
     $hash = md5(serialize($thislist));
     $this->data['settings_hash'] = $hash;
     if ($this->customer->isLogged()) {
         $this->data['customer_group_id'] = $this->customer_group_id;
     } else {
         $this->data['customer_group_id'] = $this->config->get('config_customer_group_id');
     }
     $rate = array();
     $this->language->load('record/blog');
     $this->load->model('catalog/comment');
     $this->load->model('catalog/blog');
     $this->load->model('catalog/fields');
     $this->load->model('tool/image');
     $this->data['text_manufacturer'] = $this->language->get('text_manufacturer');
     $this->data['text_karma'] = $this->language->get('text_karma');
     if (isset($thislist['title_list_latest'][$this->config->get('config_language_id')])) {
         $this->data['heading_title'] = $thislist['title_list_latest'][$this->config->get('config_language_id')];
     } else {
         $this->data['heading_title'] = "";
     }
     $this->data['text_comments'] = $this->language->get('text_comments');
     $this->data['text_viewed'] = $this->language->get('text_viewed');
     $row = $this->cache->get('product.blog.reviews.' . (int) $this->config->get('config_language_id') . '.' . (int) $this->config->get('config_store_id') . '.' . (int) $this->data['customer_group_id'] . '.' . $hash);
     if (0 == 0 || empty($row)) {
         $this->data['fields'] = $this->model_catalog_fields->getFieldsDBlang();
         $comments = $this->model_catalog_comment->getCommentsByBlogsIN($thislist, 3);
         if (isset($comments) && count($comments) > 0) {
             foreach ($comments as $comment) {
                 if ($comment['type'] == 'blogs') {
                     $blog_href = $this->model_catalog_blog->getPathByBlog($comment['blog_id']);
                     $blog_link = $this->url->link('record/blog', 'blog_id=' . $blog_href['path']);
                     $record_link = $this->url->link('record/record', 'record_id=' . $comment['record_id']);
                     $rate = $this->model_catalog_comment->getRatesByCommentId($comment['comment_id']);
                     $this->data['text_category'] = $this->language->get('text_blog');
                     $this->data['text_record'] = $this->language->get('text_record');
                     $comment['mark'] = 'record_id';
                 }
                 if ($comment['type'] == 'categories') {
                     $comment['mark'] = 'product_id';
                     if (isset($comment['review_id'])) {
                         $comment['comment_id'] = $comment['review_id'];
                     } else {
                         $comment['comment_id'] = '';
                     }
                     if (isset($comment['commentid'])) {
                         $comment['comment_id'] = $comment['commentid'];
                     } else {
                         $comment['comment_id'] = '';
                     }
                     if (isset($comment['product_id'])) {
                         $comment['record_id'] = $comment['product_id'];
                     } else {
                         if (!isset($comment['record_id'])) {
                             $comment['record_id'] = '';
                         }
                     }
                 }
                 if ($comment['type'] == 'categories') {
                     $blog_href = $this->model_catalog_blog->getPathByCategory($comment['blog_id']);
                     $blog_link = $this->url->link('product/category', 'path=' . $blog_href['path']);
                     $record_link = $this->url->link('product/product', 'product_id=' . $comment['record_id'] . "&path=" . $blog_href['path']);
                     $rate = array();
                     $this->data['text_category'] = $this->language->get('text_category');
                     $this->data['text_record'] = $this->language->get('text_product');
                 }
                 $comment_total = $comment['total'];
                 $rate_count = 0;
                 $rate_delta = 0;
                 $rate_delta_blog_plus = 0;
                 $rate_delta_blog_minus = 0;
                 foreach ($rate as $r) {
                     $rate_count = $r['rate_count'];
                     $rate_delta = $r['rate_delta'];
                     $rate_delta_blog_plus = $r['rate_delta_blog_plus'];
                     $rate_delta_blog_minus = $r['rate_delta_blog_minus'];
                 }
                 $this->load->model('tool/image');
                 if ($comment) {
                     if ($comment['image']) {
                         if (isset($this->data['settings']['image']['width']) && isset($this->data['settings']['image']['height']) && $this->data['settings']['image']['width'] != "" && $this->data['settings']['image']['height'] != "") {
                             $thumb = $this->model_tool_image->resizeme($comment['image'], $this->data['settings']['image']['width'], $this->data['settings']['image']['height'], $this->data['settings']['image_adaptive_status']);
                         } else {
                             $thumb = $this->model_tool_image->resizeme($comment['image'], 150, 150, $this->data['settings']['image_adaptive_status']);
                         }
                     } else {
                         $thumb = '';
                     }
                 } else {
                     $thumb = '';
                 }
                 if (!isset($comment['text'])) {
                     $comment['text'] = '';
                 }
                 $text = '';
                 if ($comment['text'] != '') {
                     $flag_desc = 'none';
                     if ($thislist['desc_symbols'] != '') {
                         $amount = $thislist['desc_symbols'];
                         $flag_desc = 'symbols';
                     }
                     if ($thislist['desc_words'] != '') {
                         $amount = $thislist['desc_words'];
                         $flag_desc = 'words';
                     }
                     if ($thislist['desc_pred'] != '') {
                         $amount = $thislist['desc_pred'];
                         $flag_desc = 'pred';
                     }
                     //if ($flag_desc != 'none')
                     //$comment['text'] = preg_replace('/\[(.*?)\]/', '', $comment['text']);
                     switch ($flag_desc) {
                         case 'symbols':
                             $limit = $amount;
                             $source = strip_tags(html_entity_decode($comment['text'], ENT_QUOTES, 'UTF-8'));
                             $counter = 0;
                             $matches = array();
                             utf8_preg_match_all('/(?:\\[.*\\].*\\[\\/.*\\])|(.)/Usiu', $source, $matches, PREG_OFFSET_CAPTURE);
                             foreach ($matches[1] as $num => $val) {
                                 if (is_array($val)) {
                                     $counter++;
                                     if ($counter == $limit) {
                                         $source = utf8_substr_replace($source, '', $val[1] + 1);
                                         break;
                                     }
                                 }
                             }
                             $text = $source;
                             //$pattern = ('/((.*?)\S){0,' . $amount . '}/isu');
                             //preg_match_all($pattern, strip_tags(html_entity_decode($comment['text'], ENT_QUOTES, 'UTF-8')), $out);
                             //$text = $out[0][0];
                             break;
                         case 'words':
                             $limit = $amount;
                             $source = strip_tags(html_entity_decode($comment['text'], ENT_QUOTES, 'UTF-8'));
                             $counter = 0;
                             $matches = array();
                             utf8_preg_match_all('/(?:\\[.*\\].*\\[\\/.*\\])|(\\x20)/Usiu', $source, $matches, PREG_OFFSET_CAPTURE);
                             foreach ($matches[1] as $num => $val) {
                                 if (is_array($val)) {
                                     $counter++;
                                     if ($counter == $limit) {
                                         $source = utf8_substr_replace($source, '', $val[1] + 1);
                                         break;
                                     }
                                 }
                             }
                             $text = $source;
                             /*
                             								$pattern = ('/((.*?)\x20){0,' . $amount . '}/isu');
                             								preg_match_all($pattern, strip_tags(html_entity_decode($comment['text'], ENT_QUOTES, 'UTF-8')), $out);
                             								$text = $out[0][0];*/
                             break;
                         case 'pred':
                             $limit = $amount;
                             $source = strip_tags(html_entity_decode($comment['text'], ENT_QUOTES, 'UTF-8'));
                             $counter = 0;
                             $matches = array();
                             utf8_preg_match_all('/(?:\\[.*\\].*\\[\\/.*\\])|(\\.)/Usiu', $source, $matches, PREG_OFFSET_CAPTURE);
                             foreach ($matches[1] as $num => $val) {
                                 if (is_array($val)) {
                                     $counter++;
                                     if ($counter == $limit) {
                                         $source = utf8_substr_replace($source, '', $val[1] + 1);
                                         break;
                                     }
                                 }
                             }
                             $text = $source;
                             /*
                             $pattern = ('/((.*?)\.){0,' . $amount . '}/isu');
                             preg_match_all($pattern, strip_tags(html_entity_decode($comment['text'], ENT_QUOTES, 'UTF-8')), $out);
                             $text = $out[0][0];
                             */
                             break;
                         case 'none':
                             $text = html_entity_decode($comment['text'], ENT_QUOTES, 'UTF-8');
                             break;
                     }
                 }
                 if ($text == '') {
                     $text = html_entity_decode($comment['text'], ENT_QUOTES, 'UTF-8');
                 }
                 if (isset($this->data['settings_general']['format_date'])) {
                 } else {
                     $this->data['settings_general']['format_date'] = $this->language->get('text_date');
                 }
                 if (isset($this->data['settings_general']['format_hours'])) {
                 } else {
                     $this->data['settings_general']['format_hours'] = $this->language->get('text_hours');
                 }
                 if (isset($this->data['settings_general']['format_time']) && $this->data['settings_general']['format_time'] && date($this->data['settings_general']['format_date']) == date($this->data['settings_general']['format_date'], strtotime($comment['date_added']))) {
                     $date_str = $this->language->get('text_today');
                 } else {
                     $date_str = rdate($this, $this->data['settings_general']['format_date'], strtotime($comment['date_added']));
                 }
                 $date_available = $date_str . rdate($this, $this->data['settings_general']['format_hours'], strtotime($comment['date_added']));
                 require_once DIR_SYSTEM . 'library/bbcode/Parser.php';
                 $text = nl2br(strip_tags($text));
                 $width = '160px';
                 require_once DIR_SYSTEM . 'library/bbcode/Parser.php';
                 $parser = new JBBCode\Parser();
                 $parser->addBBCode("quote", '<div class="quote">{param}</div>', true, true);
                 $parser->addBBCode("quote", '<div class="quote">{param}</div>', false, false);
                 $parser->addBBCode("size", '<span style="font-size:{option}%;">{param}</span>', true, true);
                 $parser->addBBCode("code", '<pre class="code">{param}</pre>', false, false, 1);
                 $parser->addBBCode("video", '<div style="overflow:hidden; "><iframe width="300" height="200" src="http://www.youtube.com/embed/{param}" frameborder="0" allowfullscreen></iframe></div>', false, false, 1);
                 $parser->addBBCode("img", '<a href="{param}" class="imagebox" rel="imagebox" style="overflow: hidden;"><img class="bbimage" alt="" width="' . $width . '" src="{param}"></a>');
                 $parser->addCodeDefinitionSet(new JBBCode\DefaultCodeDefinitionSet());
                 $parser->parse($text);
                 $text = $parser->getAsHtml();
                 $data = array('review_id' => $comment['comment_id'], 'mark' => $comment['mark']);
                 $fields = $this->model_catalog_fields->getFields($data);
                 $fields_new = array();
                 foreach ($fields as $num => $field) {
                     foreach ($field as $pole => $val) {
                         if ($pole != 'review_id' && $pole != 'mark') {
                             if ($val != '') {
                                 $fields_new[$pole]['field_value'] = $val;
                                 $fields_new[$pole]['value'] = $val;
                                 foreach ($this->data['fields'] as $n => $value) {
                                     if ($value['field_name'] == $pole) {
                                         $fields_new[$pole]['field_description'] = '';
                                         if ($value['field_description'][(int) $this->config->get('config_language_id')] != '') {
                                             $fields_new[$pole]['field_description'] = $value['field_description'];
                                             $fields_new[$pole]['field_name'] = $value['field_name'];
                                             $fields_new[$pole]['field'] = $value['field'];
                                             $fields_new[$pole]['field_image'] = $value['field_image'];
                                             $fields_new[$pole]['field_type'] = $value['field_type'];
                                             $fields_new[$pole]['field_order'] = $value['field_order'];
                                             $fields_new[$pole]['field_status'] = $value['field_status'];
                                             break;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
                 if (isset($fields_new) && !empty($fields_new)) {
                     usort($fields_new, 'comp_field');
                 }
                 $comment['info'] = '';
                 if ($this->data['settings_widget']['buyer_status'] || $this->data['settings_widget']['avatar_status'] || $this->data['settings_widget']['karma_status'] || $this->data['settings_widget']['manufacturer_status']) {
                     if ($comment['type'] == 'blogs') {
                         $table = 'record';
                     }
                     if ($comment['type'] == 'categories') {
                         $table = 'product';
                     }
                     if (isset($this->data['settings_widget']['admin_name']) && $this->data['settings_widget']['admin_name'] != '') {
                         $this->data['admin_name'] = array_flip(explode(";", trim($this->data['settings_widget']['admin_name'])));
                     } else {
                         $this->data['admin_name'] = array();
                     }
                     if (isset($this->data['settings_widget']['avatar_width']) && $this->data['settings_widget']['avatar_width'] != '') {
                         $width = $this->data['settings_widget']['avatar_width'];
                     } else {
                         if (isset($this->data['settings_general']['avatar_width']) && $this->data['settings_general']['avatar_width'] != '') {
                             $width = $this->data['settings_general']['avatar_width'];
                         } else {
                             $width = '100';
                         }
                     }
                     if (isset($this->data['settings_widget']['avatar_height']) && $this->data['settings_widget']['avatar_height'] != '') {
                         $height = $this->data['settings_widget']['avatar_height'];
                     } else {
                         if (isset($this->data['settings_general']['avatar_height']) && $this->data['settings_general']['avatar_height'] != '') {
                             $height = $this->data['settings_general']['avatar_height'];
                         } else {
                             $height = '100';
                         }
                     }
                     $this->data['avatar_width'] = $width;
                     $this->data['avatar_height'] = $height;
                     $comment['info'] = $this->getAvatarComment($comment, $table, $this->data);
                     if ($comment['info']['avatar'] == '') {
                         if (isset($this->data['settings_general']['avatar_admin']) && $this->data['settings_general']['avatar_admin'] != '' && isset($this->data['admin_name'][trim($comment['author'])])) {
                             $comment['info']['avatar'] = $this->model_tool_image->resizeme($this->data['settings_general']['avatar_admin'], $this->data['avatar_width'], $this->data['avatar_height'], $this->data['settings']['image_adaptive_status']);
                         } else {
                             if (isset($this->data['settings_general']['avatar_buyproduct']) && $this->data['settings_general']['avatar_buyproduct'] != '' && isset($comment['info']['buyproduct']) && $comment['info']['buyproduct'] != '') {
                                 $comment['info']['avatar'] = $this->model_tool_image->resizeme($this->data['settings_general']['avatar_buyproduct'], $this->data['avatar_width'], $this->data['avatar_height'], $this->data['settings']['image_adaptive_status']);
                             } else {
                                 if (isset($this->data['settings_general']['avatar_buy']) && $this->data['settings_general']['avatar_buy'] != '' && isset($comment['info']['buy']) && $comment['info']['buy'] != '') {
                                     $comment['info']['avatar'] = $this->model_tool_image->resizeme($this->data['settings_general']['avatar_buy'], $this->data['avatar_width'], $this->data['avatar_height'], $this->data['settings']['image_adaptive_status']);
                                 } else {
                                     if (isset($this->data['settings_general']['avatar_reg']) && $this->data['settings_general']['avatar_reg'] != '' && isset($comment['info']['customer_id']) && $comment['info']['customer_id'] > 0) {
                                         $comment['info']['avatar'] = $this->model_tool_image->resizeme($this->data['settings_general']['avatar_reg'], $this->data['avatar_width'], $this->data['avatar_height'], $this->data['settings']['image_adaptive_status']);
                                     } else {
                                         if (isset($this->data['settings_general']['avatar_default']) && $this->data['settings_general']['avatar_default'] != '') {
                                             $comment['info']['avatar'] = $this->model_tool_image->resizeme($this->data['settings_general']['avatar_default'], $this->data['avatar_width'], $this->data['avatar_height'], $this->data['settings']['image_adaptive_status']);
                                         } else {
                                             $comment['info']['avatar'] = $this->model_tool_image->resizeme($no_image, $this->data['avatar_width'], $this->data['avatar_height'], $this->data['settings']['image_adaptive_status']);
                                         }
                                     }
                                 }
                             }
                         }
                     } else {
                         $comment['info']['avatar'] = $this->model_tool_image->resizeme($comment['info']['avatar'], $this->data['avatar_width'], $this->data['avatar_height'], $this->data['settings']['image_adaptive_status']);
                     }
                     if (isset($comment['info']['manufacturer_id']) && $comment['info']['manufacturer_id']) {
                         $comment['info']['manufacturer_url'] = $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $comment['info']['manufacturer_id']);
                     }
                 }
                 if ($comment['rating_mark'] != '0') {
                     $comment['rating'] = 0;
                 }
                 $this->data['comments'][] = array('comment_id' => $comment['comment_id'], 'fields' => $fields_new, 'parent_id' => $comment['parent_id'], 'blog_id' => $comment['blog_id'], 'blog_name' => $comment['blog_name'], 'blog_href' => $blog_link, 'blog_path' => $blog_href['path'], 'record_id' => $comment['record_id'], 'cmswidget' => $comment['cmswidget'], 'record_comments' => $comment['record_comments'], 'record_viewed' => $comment['record_viewed'], 'record_name' => $comment['record_name'], 'record_rating' => (int) $comment['rating_avg'], 'record_href' => $record_link, 'customer_id' => $comment['customer_id'], 'author' => $comment['author'], 'text' => $text, 'rating' => (int) $comment['rating'], 'rate_count' => $rate_count, 'rate_delta' => $rate_delta, 'rate_delta_blog_plus' => $rate_delta_blog_plus, 'rate_delta_blog_minus' => $rate_delta_blog_minus, 'date' => $date_available, 'image' => $comment['image'], 'thumb' => $thumb, 'text_category' => $this->data['text_category'], 'text_record' => $this->data['text_record'], 'info' => $comment['info']);
             }
             $this->data['comment_total'] = $comment_total;
         }
         $this->cache->set('product.blog.reviews.' . (int) $this->config->get('config_language_id') . '.' . (int) $this->config->get('config_store_id') . '.' . (int) $this->data['customer_group_id'] . '.' . $hash, $this->data);
     } else {
         $this->data = $row;
     }
     return $this->data;
 }
Exemple #14
0
 /**
  * UTF-8 aware substr_replace
  * Replace text within a portion of a string
  *
  * @param   string   $str     The haystack
  * @param   string   $repl    The replacement string
  * @param   integer  $start   Start
  * @param   integer  $length  Length (optional)
  *
  * @return  string
  *
  * @see     http://www.php.net/substr_replace
  * @since   11.1
  */
 public static function substr_replace($str, $repl, $start, $length = null)
 {
     // Loaded by library loader
     if ($length === false) {
         return utf8_substr_replace($str, $repl, $start);
     } else {
         return utf8_substr_replace($str, $repl, $start, $length);
     }
 }
Exemple #15
0
 /**
  * UTF-8 aware substr_replace
  * Replace text within a portion of a string
  *
  * @static
  * @access public
  * @param string the haystack
  * @param string the replacement string
  * @param int start
  * @param int length (optional)
  * @see http://www.php.net/substr_replace
  */
 public static function substr_replace($str, $repl, $start, $length = NULL)
 {
     // loaded by library loader
     if ($length === FALSE) {
         return utf8_substr_replace($str, $repl, $start);
     } else {
         return utf8_substr_replace($str, $repl, $start, $length);
     }
 }
Exemple #16
0
 public function filterString($string, array $rendererStates)
 {
     $isString = true;
     if (is_array($string)) {
         // array is our way of marking tag originals prepend/append text
         $isString = false;
         $string = reset($string);
     }
     if ($isString) {
         // checks if the string is an URI of some kind
         $isString = !Zend_Uri::check($string);
     }
     if ($isString) {
         // checks if the parent tag has some strange requirements
         $tagDataStack = $rendererStates['tagDataStack'];
         $lastTagDataStack = array_pop($tagDataStack);
         if ($lastTagDataStack['tag'] === 'hashtag') {
             // well, this is a hashtag already...
             $isString = false;
         } else {
             $parentTagInfo = $this->_parent__getTagRule($lastTagDataStack['tag']);
             if (!empty($parentTagInfo['plainChildren'])) {
                 // parent tag asks for plain children, we should do nothing
                 $isString = false;
             } elseif (!empty($parentTagInfo['stopSmilies']) or !empty($parentTagInfo['stopLineBreakConversion'])) {
                 // parent tag asks for some functionalities disabled, we should disable ourself
                 // too
                 $isString = false;
             }
         }
     }
     if ($isString) {
         $offset = 0;
         while (true) {
             $pos = utf8_strpos($string, '#', $offset);
             if ($pos === false) {
                 break;
             }
             $offset = $pos + 1;
             if ($pos > 0) {
                 $beforeTagText = utf8_substr($string, $pos - 1, 1);
                 if (!preg_match(Tinhte_XenTag_Integration::REGEX_VALID_CHARACTER_AROUND, $beforeTagText)) {
                     // the before character of tag text is not a valid character, dismiss the found
                     // tag text
                     continue;
                 }
             }
             $stringForPregMatch = utf8_substr($string, $pos + 1);
             if (preg_match('/[^a-zA-Z0-9]/', $stringForPregMatch, $matches, PREG_OFFSET_CAPTURE)) {
                 $nonTagTextPos = $matches[0][1];
             } else {
                 // get all of the remaining characters
                 $nonTagTextPos = utf8_strlen($stringForPregMatch);
             }
             $nonTagTextPos += $pos + 1;
             $tagText = utf8_trim(utf8_substr($string, $pos + 1, $nonTagTextPos - 1 - $pos));
             if (utf8_strlen($tagText) < Tinhte_XenTag_Option::get('tagMinLength')) {
                 // too short
                 continue;
             }
             $afterTagText = utf8_substr($string, $nonTagTextPos, 1);
             if (!empty($afterTagText)) {
                 if (!preg_match(Tinhte_XenTag_Integration::REGEX_VALID_CHARACTER_AROUND, $afterTagText)) {
                     // the after character of tag text is not a valid character, dismiss the found
                     // tag text
                     $tagText = '';
                 }
             }
             if (!empty($tagText)) {
                 $this->_Tinhte_XenTag_autoHashtagTexts[Tinhte_XenTag_Helper::getSafeTagTextForSearch($tagText)] = $tagText;
                 // add bb code wrapping
                 $replacement = sprintf('[HASHTAG]#%s[/HASHTAG]', $tagText);
                 $string = utf8_substr_replace($string, $replacement, $pos, $nonTagTextPos - $pos);
                 $pos += utf8_strlen($replacement) - 1;
             }
             $offset = $pos + 1;
         }
     }
     return parent::filterString($string, $rendererStates);
 }
Exemple #17
0
 protected function _filterHashtagsFromMessage($message)
 {
     $bbCodeOpen = '[HASHTAG]';
     $bbCodeClose = '[/HASHTAG]';
     $dbTags = $this->getModelFromCache('Tinhte_XenTag_Model_Tag')->getTagsOfContent('post', $this->get('post_id'));
     $dbTagTexts = Tinhte_XenTag_Helper::getTextsFromTagsOrTexts($dbTags);
     $dbSafeTags = Tinhte_XenTag_Helper::getSafeTagsTextArrayForSearch($dbTagTexts);
     $offset = 0;
     while (true) {
         $posOpen = Tinhte_XenTag_Helper::utf8_stripos($message, $bbCodeOpen, $offset);
         if ($posOpen === false) {
             break;
         }
         $posClose = Tinhte_XenTag_Helper::utf8_stripos($message, $bbCodeClose, $posOpen);
         if ($posClose === false) {
             break;
         }
         $offset = $posOpen + 1;
         $posTagTextOffset = $posOpen + utf8_strlen($bbCodeOpen) + 1;
         $posTagTextLength = $posClose - $posTagTextOffset;
         $posTagText = utf8_substr($message, $posTagTextOffset, $posTagTextLength);
         $posSafeTag = Tinhte_XenTag_Helper::getSafeTagTextForSearch($posTagText);
         if (!in_array($posSafeTag, $dbSafeTags)) {
             $message = utf8_substr_replace($message, '#' . $posTagText, $posOpen, $posClose + utf8_strlen($bbCodeClose) - $posOpen);
         }
     }
     return $message;
 }