%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /var/www/html/shaban/laviva/wp-content/themes/levelup/inc/helpers/
Upload File :
Create Path :
Current File : /var/www/html/shaban/laviva/wp-content/themes/levelup/inc/helpers/html.php

<?php

// File Security Check
if ( ! defined( 'ABSPATH' ) ) { exit; }


if ( ! function_exists( 'levelup_convert_indexed2numeric_array' ) ) {

    function levelup_convert_indexed2numeric_array( $glue, $array, $prefix = '', $value_wrap = '%s' ) {
        $result = array();

        if ( is_array( $array ) && count( $array ) ) {
            foreach( $array as $key => $value ) {
                $result[] = $prefix . $key . $glue . sprintf( $value_wrap, $value );
            }
        }

        return $result;
    }

}


if ( ! function_exists( 'levelup_get_inline_style_attr' ) ) {

    function levelup_get_inline_style_attr( $css_style ) {
        if ( $css_style ) {
            return 'style="' . esc_attr( implode( ' ', levelup_convert_indexed2numeric_array( ':', $css_style, '', '%s;' ) ) ) . '"';
        }

        return '';
    }

}


if ( ! function_exists( 'levelup_get_inlide_data_attr' ) ) {

    function levelup_get_inlide_data_attr( $data_atts ) {
        if ( $data_atts ) {
            return implode( ' ', levelup_convert_indexed2numeric_array( '=', $data_atts, 'data-', '"%s"' ) );
        }

        return '';
    }

}


if ( ! function_exists( 'levelup_get_font_size_class' ) ) {

    function levelup_get_font_size_class( $font_size = '' ) {
        switch ( $font_size ) {
            case 'h1': $class = 'h1-size'; break;
            case 'h2': $class = 'h2-size'; break;
            case 'h3': $class = 'h3-size'; break;
            case 'h4': $class = 'h4-size'; break;
            case 'h5': $class = 'h5-size'; break;
            case 'h6': $class = 'h6-size'; break;

            default: $class = 'h1-size';
        }

        return $class;
    }

}


if ( ! function_exists( 'levelup_get_post_day_link' ) ) {

    function levelup_get_post_day_link() {

        $archive_year = get_the_time('Y');
        $archive_month = get_the_time('m');
        $archive_day = get_the_time('d');

        return get_day_link( $archive_year, $archive_month, $archive_day );
    }

}


if ( ! function_exists( 'levelup_get_post_data' ) ) {

    function levelup_get_post_data( $html = '' ) {

        $href = 'javascript: void(0);';

        if ( 'post' == get_post_type() ) {

            if ( !(is_day() && is_month() && is_year()) ) {

                $href = levelup_get_post_day_link();
            }
        }

        $html .= sprintf(
            '<a href="%s" title="%s" class="data-link" rel="bookmark"><time class="entry-date" datetime="%s">%s</time></a>',
            $href,
            esc_attr( get_the_time() ),
            esc_attr( get_the_date( 'c' ) ),
            esc_html( get_the_date() )
        );

        return $html;
    }

}


if ( ! function_exists( 'levelup_get_post_comments' ) ) {

    function levelup_get_post_comments( $html = '' ) {
        if ( ! post_password_required() && ( comments_open() || '0' != get_comments_number() ) ) :
            ob_start();
            comments_popup_link( esc_html__( 'Leave a comment', 'LEVELUP' ), esc_html__( '1 Comment', 'LEVELUP' ), esc_html__( '% Comments', 'LEVELUP' ), 'comment-link' );
            $html .= ob_get_clean();
        endif;

        return $html;
    }

}


if ( ! function_exists( 'levelup_get_post_categories' ) ) {

    function levelup_get_post_categories( $html = '' ) {
        $post_type = get_post_type();
        $divider = ', ';

        if ( 'post' == $post_type ) {

            $categories_list = get_the_category_list( $divider );
        } else {

            $categories_list = get_the_term_list( get_the_ID(), $post_type . '_category', '', $divider );
        }

        if ( $categories_list && !is_wp_error($categories_list) ) {

            $categories_list = str_replace( array( 'rel="tag"', 'rel="category tag"' ), '', $categories_list);
            $html .= '<span class="category-link">' . trim($categories_list) . '</span>';
        }

        return $html;
    }

}


if ( !function_exists( 'levelup_new_posted_on' ) ) {

    function levelup_new_posted_on( $type = '', $classes = array() ) {

        $post_meta_fields = levelup_get_post_meta_fields_array();
        $fields_to_show = array( 'date', 'comments', 'categories', 'author', 'media_count' );

        $html = '';
        foreach ( $fields_to_show as $field_name ) {

            if ( array_key_exists($field_name, $post_meta_fields) ) {
                $html .= $post_meta_fields[ $field_name ];
            }

        }

        if ( $type ) {
            $type = '-' . strtolower($type);
        }

        return apply_filters("levelup_new_posted_on{$type}", $html, $classes);
    }

}


if ( ! function_exists( 'levelup_get_post_meta_fields_array' ) ) {

    function levelup_get_post_meta_fields_array() {

        $config = Levelup_Config::get_instance();
        $post_meta_fields = array();

        if ( $config->get( 'post.meta.fields.date' ) ) {
            $post_meta_fields['date'] = levelup_get_post_data();
        }

        if ( $config->get( 'post.meta.fields.categories' ) ) {
            $post_meta_fields['categories'] = levelup_get_post_categories();
        }

        if ( $config->get( 'post.meta.fields.comments' ) ) {
            $post_meta_fields['comments'] = levelup_get_post_comments();
        }

        if ( $config->get( 'post.meta.fields.author' ) ) {
            $post_meta_fields['author'] = levelup_get_post_author();
        }

        if ( $config->get( 'post.meta.fields.media_number' ) && 'albums' == $config->get( 'template' ) ) {
            $post_meta_fields['media_count'] = levelup_get_post_media_count();
        }

        return $post_meta_fields;
    }

}


if ( ! function_exists( 'levelup_post_details_link' ) ) {

    function levelup_post_details_link( $post_id = null, $class = array('details', 'more-link'), $link_text = null ) {
        global $post;

        if ( !$post_id && !$post ) {
            return '';
        }elseif ( !$post_id ) {
            $post_id = $post->ID;
        }

        if ( post_password_required( $post_id ) ) {
            return '';
        }

        if ( ! is_array( $class ) ) {
            $class = explode( ' ', $class );
        }

        $output = '';
        $url = get_permalink( $post_id );

        if ( $url ) {
            $output = sprintf(
                '<a href="%1$s" class="%2$s" rel="nofollow">%3$s</a>',
                $url,
                esc_attr( implode( ' ', $class ) ),
                is_string( $link_text ) ? $link_text : esc_html__( 'Details', 'LEVELUP' )
            );
        }

        return apply_filters( 'levelup_post_details_link', $output, $post_id, $class );
    }

}


if ( ! function_exists( 'levelup_post_edit_link' ) ) {

    function levelup_post_edit_link( $post_id = null, $class = array() ) {
        $output = '';
        if ( current_user_can( 'edit_posts' ) ) {
            global $post;

            if ( !$post_id && !$post ) {
                return '';
            }

            if ( !$post_id ) {
                $post_id = $post->ID;
            }

            if ( !is_array( $class ) ) {
                $class = explode( ' ', $class );
            }

            $url = get_edit_post_link( $post_id );
            $default_classes = array( 'details', 'more-link', 'edit-link' );
            $final_classes = array_merge( $default_classes, $class );

            if ( $url ) {
                $output = sprintf(
                    '<a href="%1$s" class="%2$s" target="_blank">%3$s</a>',
                    $url,
                    esc_attr( implode( ' ', $final_classes ) ),
                    _x( 'Edit', 'edit button', 'LEVELUP' )
                );
            }
        }
        return apply_filters( 'levelup_post_edit_link', $output, $post_id, $class );
    }

}


if ( ! function_exists( 'levelup_display_share_buttons' ) ) {

    function levelup_display_share_buttons( $place = '', $options = array() ) {
        global $levelup_options;
        $default_options = array(
            'echo'			=> true,
            'class'			=> array( 'project-share-overlay' ),
            'id'			=> null,
            'title'			=> ''
        );
        $options = wp_parse_args($options, $default_options);

        $share_buttons = levelup_get_share_buttons_list( $place, $options['id'] );

        if ( empty( $share_buttons ) ) {
            return '';
        }

        $class = $options['class'];
        if ( ! is_array($class) ) {
            $class = explode( ' ', $class );
        }

        $title = esc_html( $options['title'] );

        $html =	'<div class="post-share ' . esc_attr( implode( ' ', $class ) ) . '">'
                   . '<div class="post-share-buttons soc-ico' . ( $levelup_options['social-icons-animation'] ? ' animation' : '' ) . '">'
                   . implode( '', $share_buttons )
                   . '</div>'
                   . '</div>';

        $html = apply_filters( 'levelup_display_share_buttons', $html );

        if ( $options['echo'] ) {
            echo $html;
        }
        return $html;
    }

}


if ( ! function_exists( 'levelup_get_share_buttons_list' ) ) {

    function levelup_get_share_buttons_list( $place, $post_id = null ) {
        global $post, $levelup_options;

        $buttons = array('facebook', 'twitter', 'google+', 'pinterest', 'linkedin');

        if ( empty( $buttons ) ) {
            return array();
        }

        // get title
        if ( ! $post_id ) {
            $post_id = $post->ID;
            $t = isset( $post->post_title ) ? $post->post_title : '';
        } else {
            $_post = get_post( $post_id );
            $t = isset( $_post->post_title ) ? $_post->post_title : '';
        }

        // get permalink
        $u = get_permalink( $post_id );

        $buttons_list = array(
            'facebook' 	=> esc_html__('Facebook', 'LEVELUP'),
            'twitter' 	=> esc_html__('Twitter', 'LEVELUP'),
            'google+' 	=> esc_html__('Google+', 'LEVELUP'),
            'pinterest' => esc_html__('Pinterest', 'LEVELUP'),
            'linkedin' 	=> esc_html__('LinkedIn', 'LEVELUP'),
        );
        $protocol = is_ssl() ? "https" : "http";
        $share_buttons = array();

        foreach ( $buttons as $button ) {
            $icon_class = '';
            $url = '';
            $desc = $buttons_list[ $button ];
            $custom = '';

            switch( $button ) {
                case 'twitter':
                    if(!$levelup_options['blog-twitter-sharing']) break;

                    $alt_title = esc_html__('Tweet this.', 'LEVELUP');
                    $icon_class = 'fa fa-twitter';

                    break;
                case 'facebook':
                    if(!$levelup_options['blog-facebook-sharing']) break;

                    $alt_title = esc_html__('Share this.', 'LEVELUP');
	                $icon_class = 'fa fa-facebook';

                    break;
                case 'google+':
                    if(!$levelup_options['blog-google-plus-sharing']) break;

                    $alt_title = esc_html__('Share this.', 'LEVELUP');
                    $icon_class = 'fa fa-google-plus';

                    break;
                case 'pinterest':
                    if(!$levelup_options['blog-pinterest-sharing']) break;

                    $alt_title = esc_html__('Pin this.', 'LEVELUP');
                    $icon_class = 'fa fa-pinterest';

	                // if image
	                if ( has_post_thumbnail($post_id) ) {
		                $thumbnail_id = get_post_thumbnail_id($post_id);
		                $image = wp_get_attachment_image_src($thumbnail_id, 'full');

		                if ( !empty($image) ) {
			                $custom = ' data-featured-image="' . esc_url( $image[0] ) . '"';
		                }
	                }

                    break;
                case 'linkedin':
                    if(!$levelup_options['blog-linkedin-sharing']) break;

                    $alt_title = esc_html__('Share this.', 'LEVELUP');
                    $icon_class = 'fa fa-linkedin';

                    break;
            }

            if(!$icon_class) continue;

            $desc = '';
//            $url = esc_url( $url );

            $share_button = sprintf(
                '<a href="%2$s" class="%1$s" title="%5$s" %4$s><span class="assistive-text">%3$s</span></a>',
                $icon_class,
                '#',#$url0,
                '',
                $custom,
                $alt_title
            );

            $share_buttons[] = apply_filters( 'levelup_share_button', $share_button, $button, $icon_class, $url, $desc, $t, $u );
        }

        return $share_buttons;
    }

}


if ( ! function_exists( 'levelup_set_image_width_options' ) ) {

    function levelup_set_image_width_options() {

        $config = levelup_config();
        $target_image_width = $config->get('post.preview.width.min');

        if ( 'wide' == $config->get( 'post.preview.width' ) && !$config->get('all_the_same_width') ) {
            $target_image_width *= 3;
            $image_options = array( 'w' => absint( round( $target_image_width ) ), 'z' => 0, 'hd_convert' => false );

        } else {
            $target_image_width *= 1.5;
            $image_options = array( 'w' => absint( round( $target_image_width ) ), 'z' => 0 );

        }

        return $image_options;
    }

}


if ( ! function_exists( 'levelup_get_post_media_count' ) ) {

    function levelup_get_post_media_count( $html = '' ) {
        $config = Levelup_Config::get_instance();

        $media_items = $config->get( 'post.media.library' );

        if ( !$media_items ) {
            $media_items = array();
        }

        // add thumbnail to attachments list
        if ( has_post_thumbnail() && $config->get( 'post.media.featured_image.enabled' ) ) {
            array_unshift( $media_items, get_post_thumbnail_id() );
        }

        // if pass protected - show only cover image
        if ( $media_items && post_password_required() ) {
            $media_items = array( $media_items[0] );
        }

        list( $images_count, $videos_count ) = levelup_get_attachments_data_count( $media_items );

        $output = '';

        if ( $images_count || $videos_count ) {

            $output .= '<span class="num-of-images">';

            $counters = array();

            if ( $images_count ) {
                $counters[] = sprintf( _n( '1 image', '%s images', $images_count, 'LEVELUP' ), $images_count );
            }

            if ( $videos_count ) {
                $counters[] = sprintf( _n( '1 video', '%s video', $videos_count, 'LEVELUP' ), $videos_count );
            }

            $output .= implode( ' &amp; ', $counters );

            $output .= '</span>';
        }

        return $html . $output;
    }

}


if ( ! function_exists( 'levelup_get_post_author' ) ) {

    function levelup_get_post_author( $html = '' ) {
        $html .= sprintf(
            '<a class="author vcard" href="%s" title="%s" rel="author">%s<span class="fn">%s</span></a>',
            esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
            esc_attr( sprintf( _x( 'View all posts by %s', 'frontend post meta', 'LEVELUP' ), get_the_author() ) ),
            _x( 'By ', 'frontend post meta', 'LEVELUP' ),
            get_the_author()
        );

        return $html;
    }

}


if ( ! function_exists( 'levelup_get_image_with_srcset' ) ) {

    function levelup_get_image_with_srcset( $logo, $r_logo, $default, $custom = '', $class = '' ) {

        $logos = array( '1x' => $logo, '2x' => $r_logo );
        $srcset = array();

        foreach ( $logos as $xx => $_logo ) {
            if ( ! empty( $_logo ) ) {
                $srcset[] = "{$_logo} {$xx}";
            }
        }

        $srcset = implode( ', ', $srcset );

        $image_hw = '';
        if($default){
            $image_hw = image_hwstring( $default[1], $default[2] );
        }

        $output = '<img class="' . esc_attr( $class . ' preload-me' ) . '" alt="' . esc_attr( get_bloginfo() ) . '" src="' . esc_attr( $logo ) . '" srcset="' . esc_attr( $srcset ) . '" ' . $image_hw . $custom . ' />';

        return $output;
    }

}


if ( ! function_exists( 'levelup_substring' ) ) {

    function levelup_substring( $str, $max_chars = 30 ) {

        if ( function_exists('mb_strlen') && function_exists('mb_substr') ) {

            if ( mb_strlen( $str ) > $max_chars ) {

                $str = mb_substr( $str, 0, $max_chars );
                $str .= '&hellip;';
            }

        }
        return $str;
    }

}


if ( ! function_exists( 'levelup_get_terms_list_by_slug' ) ) {

    function levelup_get_terms_list_by_slug( $args = array() ) {

        $default_args = array(
            'slugs' => array(),
            'taxonomy' => 'category',
            'separator' => ', ',
            'titles' => array()
        );

        $default_titles = array(
            'empty_slugs' => esc_html__( 'All', 'LEVELUP' ),
            'no_result' => esc_html__('There is no categories', 'LEVELUP')
        );

        $args = wp_parse_args( $args, $default_args );
        $args['titles'] = wp_parse_args( $args['titles'], $default_titles );

        // get categories names list or show all
        if ( empty( $args['slugs'] ) ) {
            $output = $args['titles']['empty_slugs'];

        } else {

            $terms_names = array();
            foreach ( $args['slugs'] as $term_slug ) {
                $term = get_term_by( 'slug', $term_slug, $args['taxonomy'] );

                if ( $term ) {
                    $terms_names[] = $term->name;
                }

            }

            if ( $terms_names ) {
                asort( $terms_names );
                $output = join( $args['separator'], $terms_names );

            } else {
                $output = $args['titles']['no_result'];

            }

        }

        return $output;
    }

}


if ( ! function_exists( 'levelup_make_class' ) ) {

    function levelup_make_class( $class = '' ) {
        echo 'class="' . join( ' ', $class ) . '"';
    }

}


if ( ! function_exists( 'levelup_sanitize_classes' ) ) {

    function levelup_sanitize_classes( $classes ) {

        if ( $classes ) {
            if ( is_array( $classes ) ) {
                $classes = implode( ' ', $classes );
            }
        } else {
            $classes = '';
        }

        return esc_attr( $classes );
    }

}

Zerion Mini Shell 1.0