';
}
function eightstore_lite_wrapper_end() {
echo '
';
}
/**
* Truncates text without breaking HTML Code
*/
function eightstore_lite_excerpt($eightstore_lite_text, $eightstore_lite_length = 100, $eightstore_lite_ending = '...', $eightstore_lite_exact = true, $eightstore_lite_considerHtml = true) {
if ($eightstore_lite_considerHtml) {
// if the plain text is shorter than the maximum length, return the whole text
if (strlen(preg_replace('/<.*?>/', '', $eightstore_lite_text)) <= $eightstore_lite_length) {
return $eightstore_lite_text;
}
// splits all html-tags to scanable lines
preg_match_all('/(<.+?>)?([^<>]*)/s', $eightstore_lite_text, $eightstore_lite_lines, PREG_SET_ORDER);
$eightstore_lite_total_length = strlen($eightstore_lite_ending);
$eightstore_lite_open_tags = array();
$eightstore_lite_truncate = '';
foreach ($eightstore_lite_lines as $eightstore_lite_line_matchings) {
// if there is any html-tag in this line, handle it and add it (uncounted) to the output
if (!empty($eightstore_lite_line_matchings[1])) {
// if it’s an “empty element” with or without xhtml-conform closing slash (f.e.)
if (preg_match('/^<(\s*.+?\/\s*|\s*(img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param)(\s.+?)?)>$/is', $eightstore_lite_line_matchings[1])) {
// do nothing
// if tag is a closing tag (f.e.)
} else if (preg_match('/^<\s*\/([^\s]+?)\s*>$/s', $eightstore_lite_line_matchings[1], $eightstore_lite_tag_matchings)) {
// delete tag from $open_tags list
$eightstore_lite_pos = array_search($eightstore_lite_tag_matchings[1], $eightstore_lite_open_tags);
if ($eightstore_lite_pos !== false) {
unset($eightstore_lite_open_tags[$eightstore_lite_pos]);
}
// if tag is an opening tag (f.e. )
} else if (preg_match('/^<\s*([^\s>!]+).*?>$/s', $eightstore_lite_line_matchings[1], $eightstore_lite_tag_matchings)) {
// add tag to the beginning of $open_tags list
array_unshift($eightstore_lite_open_tags, strtolower($eightstore_lite_tag_matchings[1]));
}
// add html-tag to $truncate’d text
$eightstore_lite_truncate .= $eightstore_lite_line_matchings[1];
}
// calculate the length of the plain text part of the line; handle entities as one character
$eightstore_lite_content_length = strlen(preg_replace('/&[0-9a-z]{2,8};|[0-9]{1,7};|[0-9a-f]{1,6};/i', ' ', $eightstore_lite_line_matchings[2]));
if ($eightstore_lite_total_length+$eightstore_lite_content_length > $eightstore_lite_length) {
// the number of characters which are left
$eightstore_lite_left = $eightstore_lite_length - $eightstore_lite_total_length;
$eightstore_lite_entities_length = 0;
// search for html entities
if (preg_match_all('/&[0-9a-z]{2,8};|[0-9]{1,7};|[0-9a-f]{1,6};/i', $eightstore_lite_line_matchings[2], $eightstore_lite_entities, PREG_OFFSET_CAPTURE)) {
// calculate the real length of all entities in the legal range
foreach ($eightstore_lite_entities[0] as $eightstore_lite_entity) {
if ($eightstore_lite_entity[1]+1-$eightstore_lite_entities_length <= $eightstore_lite_left) {
$eightstore_lite_left--;
$eightstore_lite_entities_length += strlen($eightstore_lite_entity[0]);
} else {
// no more characters left
break;
}
}
}
$eightstore_lite_truncate .= substr($eightstore_lite_line_matchings[2], 0, $eightstore_lite_left+$eightstore_lite_entities_length);
// maximum lenght is reached, so get off the loop
break;
} else {
$eightstore_lite_truncate .= $eightstore_lite_line_matchings[2];
$eightstore_lite_total_length += $eightstore_lite_content_length;
}
// if the maximum length is reached, get off the loop
if($eightstore_lite_total_length >= $eightstore_lite_length) {
break;
}
}
} else {
if (strlen($eightstore_lite_text) <= $eightstore_lite_length) {
return $eightstore_lite_text;
} else {
$eightstore_lite_truncate = substr($eightstore_lite_text, 0, $eightstore_lite_length - strlen($eightstore_lite_ending));
}
}
// if the words shouldn't be cut in the middle...
if (!$eightstore_lite_exact) {
// ...search the last occurance of a space...
$eightstore_lite_spacepos = strrpos($eightstore_lite_truncate, ' ');
if (isset($eightstore_lite_spacepos)) {
// ...and cut the text in this position
$eightstore_lite_truncate = substr($eightstore_lite_truncate, 0, $eightstore_lite_spacepos);
}
}
// add the defined ending to the text
$eightstore_lite_truncate .= $eightstore_lite_ending;
if($eightstore_lite_considerHtml) {
// close all unclosed html-tags
foreach ($eightstore_lite_open_tags as $eightstore_lite_tag) {
$eightstore_lite_truncate .= '';
}
}
return $eightstore_lite_truncate;
}
function eightstore_lite_fonts_cb(){
echo "";
}
add_action('wp_footer', 'eightstore_lite_fonts_cb');