$charlength) {
$subex = mb_substr($excerpt, 0, $charlength - 5);
$exwords = explode(' ', $subex);
$excut = -(mb_strlen($exwords[count($exwords) - 1]));
if ($excut < 0) {
echo mb_substr($subex, 0, $excut) . '...';
} else {
echo $subex . '...';
}
} else {
echo str_replace('[…]', '', $excerpt);
}
}
public static function remove_last_comma($string = '')
{
if (substr($string, -1) == ',')
return substr($string, 0, -1);
else
return $string;
}
/**
*
* Generate image for post thumbnail
*
*/
public static function display_thumbnail($width, $height)
{
if (has_post_thumbnail()) {
the_post_thumbnail(array($width, $height));
} elseif (self::is_empty_thumb()) {
return self::first_image($width, $height); /*first image or no image placeholder*/
} else {
return '';
}
}
public static function is_empty_thumb()
{
global $post;
$thumb = get_post_custom_values("Image");
return empty($thumb);
}
public static function first_image($width, $height, $url_or_img = 0)
{
$image_parametr = self::catch_that_image();
$thumb = $image_parametr['src'];
$class = '';
if (!$image_parametr['image_catched'])
$class = 'class="no_image"';
if ($thumb) {
$str = "
';
return $str;
}
}
/**
* Get first image of post for thumbnail
*/
public static function catch_that_image()
{
global $post, $posts;
$first_img = array('src' => '', 'image_catched' => true);
$output = preg_match_all('//i', $post->post_content, $matches);
if (isset($matches [1] [0])) {
$first_img['src'] = $matches [1] [0];
}
if (empty($first_img['src'])) {
$first_img['src'] = WDWT_IMG . 'default.jpg';
$first_img['image_catched'] = false;
}
return $first_img;
}
public static function thumbnail($width, $height)
{
if (has_post_thumbnail()) {
the_post_thumbnail(array($width, $height));
} elseif (self::is_empty_thumb()) {
return '';
}
}
public static function fixed_thumbnail($width, $height, $grab_image = true, $id = 0)
{
if ($id == 0)
$post_id = get_the_ID();
else
$post_id = $id;
$tumb_id = get_post_thumbnail_id($post_id);
$thumb_url = wp_get_attachment_image_src($tumb_id, array($width, $height));
$thumb_url = $thumb_url[0];
if ($grab_image) {
if (!$thumb_url) {
$thumb_url = self::catch_that_image();
$thumb_url = $thumb_url['src'];
}
}
if ($thumb_url) {
return '
';
} else {
return '';
}
}
public static function auto_thumbnail($grab_image = true)
{
$tumb_id = get_post_thumbnail_id(get_the_ID());
$thumb_url = wp_get_attachment_image_src($tumb_id, 'full');
$thumb_url = $thumb_url[0];
if ($grab_image) {
if (!$thumb_url) {
$thumb_url = self::catch_that_image();
$thumb_url = $thumb_url['src'];
}
}
if ($thumb_url) {
return '
';
} else {
return '';
}
}
/**
* @return url of first image in the post content, or empty string if has no image
*/
public static function post_image_url()
{
$thumb_url = self::catch_that_image();
if (isset($thumb_url['image_catched'])) {
if (!$thumb_url['image_catched']) {
$thumb_url = '';
} else {
$thumb_url = $thumb_url['src'];
}
}
return $thumb_url;
}
/**
* get postthumb url @param size =full or medium
* use inside loop
*/
public static function get_post_thumb($size = 'large')
{
$tumb_id = get_post_thumbnail_id(get_the_ID());
$thumb_url = wp_get_attachment_image_src($tumb_id, $size);
if ($thumb_url) {
$thumb_url = $thumb_url[0];
} else {
$thumb_url = self::catch_that_image();
}
if (is_array($thumb_url) && isset($thumb_url['image_catched'])) {
if (!$thumb_url['image_catched']) {
$thumb_url = '';
} else {
$thumb_url = $thumb_url['src'];
}
}
return $thumb_url;
}
public static function post_nav()
{
global $post;
$previous = (is_attachment()) ? get_post($post->post_parent) : get_adjacent_post(false, '', true);
$next = get_adjacent_post(false, '', false);
if (!$next && !$previous)
return;
?>