Viewing File: /home/maglabs/2vsa/wp-content/themes/cargohub/inc/functions/entry.php
<?php
/**
* Custom functions for entry.
*
* @package CargoHub
*/
if ( ! function_exists( 'wp_body_open' ) ) {
/**
* Shim for wp_body_open, ensuring backward compatibility with versions of WordPress older than 5.2.
*/
function wp_body_open() {
do_action( 'wp_body_open' );
}
}
/**
* Prints HTML with meta information for the current post-date/time and author.
*
* @since 1.0.0
*/
function cargohub_posted_on( $echo = true ) {
$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
$time_string = sprintf( $time_string,
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() )
);
$posted_on = sprintf(
_x( '%s', 'post date', 'cargohub' ),
'<a href="' . esc_url( get_permalink() ) . '" rel="bookmark"><i class="fa fa-clock-o" aria-hidden="true"></i>' . $time_string . '</a>'
);
$output = '<span class="meta posted-on">' . $posted_on . '</span>';
if ( $echo != true ) {
return $output;
} else {
echo wp_kses_post($output);
}
}
/**
* Prints HTML with meta information for the current post-date/time and author.
*/
function cargohub_entry_meta() {
$fields = (array) cargohub_get_option( 'entry_meta' );
foreach ( $fields as $field ) {
switch ( $field ) {
case 'author':
echo '<span class="meta author vcard">' . esc_html__( 'by', 'cargohub' )
. ' <a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) )
. '">' . esc_html( get_the_author() ) . '</a></span>';
break;
case 'cat':
if ( 'post' === get_post_type() ) {
/* translators: used between list items, there is a space after the comma */
$categories_list = get_the_category_list( esc_html__( ', ', 'cargohub' ) );
if ( $categories_list ) {
echo '<span class="meta cat-links">' . $categories_list . '</span>'; // WPCS: XSS OK.
}
}
break;
case 'comment':
if ( ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
echo '<span class="meta comments-link">';
comments_popup_link();
echo '</span>';
}
break;
}
}
}
/**
* Prints HTML with meta information for the categories, tags and comments.
*
* @since 1.0.0
*/
function cargohub_entry_footer() {
// Hide category and tag text for pages.
if ( 'post' == get_post_type() ) {
/* translators: used between list items, there is a space after the comma */
$categories_list = get_the_category_list( ', ' );
if ( $categories_list ) {
printf( '<span class="cat-links">' . esc_html__( 'Posted in %1$s', 'cargohub' ) . '</span>', $categories_list );
}
/* translators: used between list items, there is a space after the comma */
$tags_list = get_the_tag_list( '', ', ' );
if ( $tags_list ) {
printf( '<span class="tags-links">' . esc_html__( 'Tagged %1$s', 'cargohub' ) . '</span>', $tags_list );
}
}
if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
echo '<span class="comments-link">';
comments_popup_link( esc_html__( 'Leave a comment', 'cargohub' ), esc_html__( '1 Comment', 'cargohub' ), esc_html__( '% Comments', 'cargohub' ) );
echo '</span>';
}
edit_post_link( esc_html__( 'Edit', 'cargohub' ), '<span class="edit-link">', '</span>' );
}
/**
* Get or display limited words from given string.
* Strips all tags and shortcodes from string.
*
* @since 1.0.0
* @param integer $num_words The maximum number of words
* @param string $more More link.
* @param bool $echo Echo or return output
*
* @return string|void Limited content.
*/
function cargohub_content_limit( $num_words, $more = "…", $echo = true ) {
$content = get_the_content();
// Strip tags and shortcodes so the content truncation count is done correctly
$content = strip_tags( strip_shortcodes( $content ), apply_filters( 'cargohub_content_limit_allowed_tags', '<script>,<style>' ) );
// Remove inline styles / scripts
$content = trim( preg_replace( '#<(s(cript|tyle)).*?</\1>#si', '', $content ) );
// Truncate $content to $max_char
$content = wp_trim_words( $content, $num_words );
if ( $more )
{
$output = sprintf(
'<p>%s <a href="%s" class="more-link" title="%s">%s</a></p>',
$content,
get_permalink(),
sprintf( esc_html__( 'Continue reading "%s"', 'cargohub' ), the_title_attribute( 'echo=0' ) ),
esc_html( $more )
);
}
else
{
$output = sprintf( '<p>%s</p>', $content );
}
if ( !$echo )
return $output;
echo wp_kses_post($output);
}
/**
* Show entry thumbnail base on its format
*
* @since 1.0
*/
function cargohub_entry_thumbnail( $size = 'thumbnail' ) {
$html = '';
$css_class = 'format-' . get_post_format();
switch ( get_post_format() ) {
case 'image':
$image = cargohub_get_image( array(
'size' => $size,
'format' => 'src',
'meta_key' => 'image',
'echo' => false,
) );
if ( ! $image ) {
break;
}
$html = sprintf(
'<a class="entry-image" href="%1$s" title="%2$s"><img src="%3$s" alt="%2$s"></a>',
esc_url( get_permalink() ),
the_title_attribute( 'echo=0' ),
esc_url( $image )
);
break;
case 'gallery':
$images = cargohub_get_meta( 'images', "type=image&size=$size" );
if ( empty( $images ) ) {
break;
}
$gallery = array();
foreach ( $images as $image ) {
$gallery[] = '<li>' . '<img src="' . esc_url( $image['url'] ) .'" alt="' . the_title_attribute( 'echo=0' ) . '">' . '</li>';
}
$html .= '<div class="format-gallery-slider entry-image"><ul class="slides">' . implode( '', $gallery ) . '</ul></div>';
break;
case 'audio':
$thumb = get_the_post_thumbnail( get_the_ID(), $size );
if ( !empty( $thumb ) ) {
$html .= '<a class="entry-image" href="' . get_permalink() . '">' . $thumb . '</a>';
} else {
$css_class .= ' no-thumb';
}
$audio = cargohub_get_meta( 'audio' );
if ( ! $audio ) {
break;
}
// If URL: show oEmbed HTML or jPlayer
if ( filter_var( $audio, FILTER_VALIDATE_URL ) ) {
// Try oEmbed first
if ( $oembed = @wp_oembed_get( $audio ) ) {
$html .= $oembed;
}
// Use audio shortcode
else {
$html .= '<div class="audio-player">' . wp_audio_shortcode( array( 'src' => $audio ) ) . '</div>';
}
}
// If embed code: just display
else {
$html .= $audio;
}
break;
case 'video':
$video = cargohub_get_meta( 'video' );
if ( ! $video ) {
break;
}
// If URL: show oEmbed HTML
if ( filter_var( $video, FILTER_VALIDATE_URL ) ) {
if ( $oembed = @wp_oembed_get( $video ) ) {
$html .= $oembed;
}
else {
$atts = array(
'src' => $video,
'width' => 848,
);
if ( has_post_thumbnail() ) {
$atts['poster'] = cargohub_get_image( 'format=src&echo=0&size=full' );
}
$html .= wp_video_shortcode( $atts );
}
}
// If embed code: just display
else {
$html .= $video;
}
break;
case 'link':
$thumb = get_the_post_thumbnail( get_the_ID(), $size );
if ( !empty( $thumb ) ) {
$html .= '<a class="entry-image" href="' . get_permalink() . '">' . $thumb . '</a>';
} else {
$css_class .= ' no-thumb';
}
$link = cargohub_get_meta( 'url' );
$text = cargohub_get_meta( 'url_text' );
if ( ! $link ) {
break;
}
$html .= sprintf( '<a href="%s" class="link-block">%s</a>', esc_url( $link ), $text ? $text : $link );
break;
case 'quote':
$thumb = get_the_post_thumbnail( get_the_ID(), $size );
if ( !empty( $thumb ) ) {
$html .= '<a class="entry-image" href="' . get_permalink() . '">' . $thumb . '</a>';
} else {
$css_class .= ' no-thumb';
}
$quote = cargohub_get_meta( 'quote' );
$author = cargohub_get_meta( 'quote_author' );
$author_url = cargohub_get_meta( 'author_url' );
if ( ! $quote ) {
break;
}
$html .= sprintf(
'<blockquote>%s<cite>%s</cite></blockquote>',
esc_html( $quote ),
empty( $author_url ) ? $author : '<a href="' . esc_url( $author_url ) . '"> - ' . $author . '</a>'
);
break;
default:
$thumb = cargohub_get_image( array(
'size' => $size,
'meta_key' => 'image',
'echo' => false,
) );
if ( empty( $thumb ) ) {
break;
}
$html .= '<a class="entry-image" href="' . get_permalink() . '">' . $thumb . '</a>';
break;
}
if ( $html = apply_filters( __FUNCTION__, $html, get_post_format() ) ) {
$css_class = esc_attr( $css_class );
echo "<div class='entry-format $css_class'>$html</div>";
}
}
/**
* Check is blog
*
* @since 1.0
*/
if ( ! function_exists( 'cargohub_is_blog' ) ) :
function cargohub_is_blog() {
if ( ( is_archive() || is_author() || is_category() || is_home() || is_tag() ) && 'post' == get_post_type() ) {
return true;
}
return false;
}
endif;
/**
* Get author meta
*
* @since 1.0
*
*/
function cargohub_author_box() {
if ( cargohub_get_option( 'show_author_box' ) == 0 ) {
return;
}
?>
<div class="post-author">
<h2 class="box-title"><?php esc_html_e( 'About Author', 'cargohub' ) ?></h2>
<div class="post-author-box clearfix">
<div class="post-author-avatar">
<?php echo get_avatar( get_the_author_meta( 'ID' ), 85 ); ?>
</div>
<div class="post-author-info">
<h3 class="author-name"><?php the_author_meta( 'display_name' ); ?></h3>
<p><?php the_author_meta( 'description' ); ?></p>
</div>
</div>
</div>
<?php
}
/**
* Print HTML for post sharing
*
* @param null $post_id
*/
function cargohub_social_share( $post_id = null ) {
$post_id = $post_id ? $post_id : get_the_ID();
?>
<ul class="socials-share">
<li>
<a target="_blank" class="share-facebook social"
href="http://www.facebook.com/sharer.php?u=<?php echo urlencode( get_permalink( $post_id ) ); ?>&t=<?php echo urlencode( get_the_title( $post_id ) ); ?>">
<i class="fa fa-facebook"></i>
</a>
</li>
<li>
<a class="share-twitter social"
href="http://twitter.com/share?text=<?php echo esc_attr( get_the_title( $post_id ) ); ?>&url=<?php echo urlencode( get_permalink( $post_id ) ); ?>"
target="_blank">
<i class="fa fa-twitter"></i>
</a>
</li>
<li>
<a target="_blank" class="share-google-plus social"
href="https://plus.google.com/share?url=<?php echo urlencode( get_permalink( $post_id ) ); ?>&text=<?php echo urlencode( get_the_title( $post_id ) ); ?>"><i
class="fa fa-google-plus"></i>
</a>
</li>
<li>
<a class="share-linkedin social"
href="https://www.linkedin.com/shareArticle?mini=true&url=<?php echo urlencode( get_permalink( $post_id ) ); ?>&title=<?php echo esc_attr( get_the_title( $post_id ) ); ?>"
target="_blank">
<i class="fa fa-linkedin"></i>
</a>
</li>
</ul>
<?php
}
if ( ! function_exists( 'cargohub_has_page_header' ) ) :
/**
* Check if current page has page header
*
* @return bool
*/
function cargohub_has_page_header() {
if ( is_front_page() && ! is_home() ) {
return false;
} elseif ( ( is_page() || is_singular( 'service' ) ) && get_post_meta( get_the_ID(), 'hide_page_header', true ) ) {
return false;
} elseif ( is_page_template( 'template-homepage.php' ) ) {
return false;
}
return cargohub_get_option( 'page_header_enable' );
}
endif;
if ( ! function_exists( 'cargohub_get_page_header_image' ) ) :
/**
* Get page header image URL
*
* @return string
*/
function cargohub_get_page_header_image() {
if ( ! cargohub_has_page_header() ) {
return '';
}
if ( is_page() || is_singular(array( 'service', 'project' )) ) {
$image = get_post_meta( get_the_ID(), 'title_area_bg', true );
$image = $image ? wp_get_attachment_image_src( $image, 'full' ) : wp_get_attachment_image_url( get_the_ID(), 'full' );
$image = $image ? $image[0] : cargohub_get_option( 'page_header_bg' );
} else {
$image = cargohub_get_option( 'page_header_bg' );
}
return $image;
}
endif;
if ( ! function_exists( 'cargohub_menu_icon' ) ) :
/**
* Get menu icon
*/
function cargohub_menu_icon() {
printf(
'<a href="#" class="navbar-toggle">
<span class="navbar-icon">
<span class="navbars-line"></span>
</span>
</a>'
);
}
endif;
/**
* Get socials
*
* @since 1.0.0
*
*
* @return string
*/
function cargohub_get_socials() {
$socials = array(
'facebook' => esc_html__( 'Facebook', 'cargohub' ),
'twitter' => esc_html__( 'Twitter', 'cargohub' ),
'google' => esc_html__( 'Google', 'cargohub' ),
'tumblr' => esc_html__( 'Tumblr', 'cargohub' ),
'flickr' => esc_html__( 'Flickr', 'cargohub' ),
'vimeo' => esc_html__( 'Vimeo', 'cargohub' ),
'youtube' => esc_html__( 'Youtube', 'cargohub' ),
'linkedin' => esc_html__( 'LinkedIn', 'cargohub' ),
'pinterest' => esc_html__( 'Pinterest', 'cargohub' ),
'dribbble' => esc_html__( 'Dribbble', 'cargohub' ),
'spotify' => esc_html__( 'Spotify', 'cargohub' ),
'instagram' => esc_html__( 'Instagram', 'cargohub' ),
'tumbleupon' => esc_html__( 'Tumbleupon', 'cargohub' ),
'wordpress' => esc_html__( 'WordPress', 'cargohub' ),
'rss' => esc_html__( 'Rss', 'cargohub' ),
'deviantart' => esc_html__( 'Deviantart', 'cargohub' ),
'share' => esc_html__( 'Share', 'cargohub' ),
'skype' => esc_html__( 'Skype', 'cargohub' ),
'behance' => esc_html__( 'Behance', 'cargohub' ),
'apple' => esc_html__( 'Apple', 'cargohub' ),
'yelp' => esc_html__( 'Yelp', 'cargohub' ),
);
return apply_filters( 'cargohub_header_socials', $socials );
}
// Rating reviews
function cargohub_rating_stars( $score ) {
$score = min( 10, abs( $score ) );
$full_star = $score / 2;
$half_star = $score % 2;
$stars = array();
for ( $i = 1; $i <= 5; $i ++ ) {
if ( $i <= $full_star ) {
$stars[] = '<i class="fa fa-star"></i>';
} elseif ( $half_star ) {
$stars[] = '<i class="fa fa-star-half-o"></i>';
$half_star = false;
} else {
$stars[] = '<i class="fa fa-star-o"></i>';
}
}
echo join( "\n", $stars );
}
Back to Directory
File Manager