post_excerpt)) {
return $post->post_excerpt;
} else {
return $this->generateExcerpt($post->post_content);
}
} else {
return $post->post_content;
}
}
function filterContent($content) {
$content = self::stripShortCodes($content);
$content = self::convertEmbeddedContent($content);
// convert h4 h5 h6 to h3
$content = preg_replace('/<([\/])?h[456](.*?)>/', '<$1h3$2>', $content);
// convert currency signs
$content = str_replace(
array('$', '€', '£', '¥'),
array('$', '€', '£', '¥'),
$content
);
// strip useless tags
$tags_not_being_stripped = array(
'', '
', '', '', '', '', '', '',
'
', '
', '', '
', '
', '
'
);
$content = strip_tags($content, implode('', $tags_not_being_stripped));
$content = wpautop($content);
return $content;
}
private function generateExcerpt($content) {
// if excerpt is empty then try to find the "more" tag
$excerpts = explode('', $content);
if(count($excerpts) > 1) {
// separator was present
return $excerpts[0];
} else {
// Separator not present, try to shorten long posts
return wp_trim_words($content, self::MAX_EXCERPT_LENGTH, ' …');
}
}
private function stripShortCodes($content) {
// remove captions
$content = preg_replace(
"/\[caption.*?\](.*<\/a>)(.*?)\[\/caption\]/",
'$1',
$content
);
// remove other shortcodes
$content = preg_replace('/\[[^\[\]]*\]/', '', $content);
return $content;
}
private function convertEmbeddedContent($content = '') {
// remove embedded video and replace with links
$content = preg_replace(
'#