Permalink
Browse files

SyndicatedPost::excerpt: Use mb_substr in place of substr when you ne…

…ed to generate an excerpt; some feeds are multibyte, etc.
  • Loading branch information...
Rad Geek
Rad Geek committed Oct 4, 2017
1 parent b15228c commit 04623aab2fd89e285c5e12a5d38546f1d00e4df7
Showing with 12 additions and 6 deletions.
  1. +12 −6 syndicatedpost.class.php
View
@@ -129,6 +129,7 @@ function __construct ($item, &$source) {
);
$excerpt = apply_filters('syndicated_item_excerpt', $this->excerpt(), $this);
if (!empty($excerpt)):
$this->post['post_excerpt'] = $excerpt;
endif;
@@ -258,7 +259,6 @@ function __construct ($item, &$source) {
$this->post['post_type'] = apply_filters('syndicated_post_type', $this->link->setting('syndicated post type', 'syndicated_post_type', 'post'), $this);
endif;
} /* SyndicatedPost::__construct() */
#####################################
@@ -413,18 +413,23 @@ function excerpt () {
$content = $this->content();
// Ignore whitespace, case, and tag cruft.
$theExcerpt = preg_replace('/\s+/', '', strtolower(strip_tags($excerpt)));
$theContent = preg_replace('/\s+/', '', strtolower(strip_tags($content)));
$theExcerpt = preg_replace('/\s+/', '', strtolower(strip_tags(html_entity_decode($excerpt))));
$theContent = preg_replace('/\s+/', '', strtolower(strip_tags(html_entity_decode($content))));
if ( empty($excerpt) or $theExcerpt == $theContent ) :
# If content is available, generate an excerpt.
if ( strlen(trim($content)) > 0 ) :
$excerpt = strip_tags($content);
if (strlen($excerpt) > 255) :
$excerpt = substr($excerpt,0,252).'...';
if (is_object($this->link) and is_object($this->link->simplepie)) :
$encoding = $this->link->simplepie->get_encoding();
else :
$encoding = get_option('blog_charset', 'utf8');
endif;
$excerpt = mb_substr($excerpt,0,252,$encoding).'...';
endif;
endif;
endif;
return $excerpt;
} /* SyndicatedPost::excerpt() */
@@ -1449,7 +1454,7 @@ function wp_id () {
return $this->_wp_id;
}
function store () {
public function store () {
global $wpdb;
if ($this->filtered()) : // This should never happen.
@@ -1711,6 +1716,7 @@ function insert_post ($update = false, $freshness = 2) {
// Go ahead and insert the first post record to
// anchor the revision history.
$this->_wp_id = wp_insert_post($sdbpost, /*return wp_error=*/ true);
$dbpost['ID'] = $this->_wp_id;

0 comments on commit 04623aa

Please sign in to comment.