Your IP : 216.73.216.0


Current Path : /home/goldnueh/netsetsolution.com/wp-content/plugins/zeinet-addon/common/
Upload File :
Current File : /home/goldnueh/netsetsolution.com/wp-content/plugins/zeinet-addon/common/functions.php

<?php

/**
 * making array of custom icon classes
 * which is saved in transient
 * @return array
 */
if (!function_exists('zeinet_get_fa_icons')) :

    function zeinet_get_fa_icons()
    {
        $data = get_transient('zeinet_fa_icons');

        if (empty($data)) {
            global $wp_filesystem;
            require_once(ABSPATH . '/wp-admin/includes/file.php');
            WP_Filesystem();

            $fontAwesome_file =   ZEINET_ADDON_PATH . '/assets/vendors/fontawesome/css/all.min.css';
            $template_icon_file = ZEINET_ADDON_PATH . '/assets/vendors/zeinet-icons/style.css';
            $content = '';

            if ($wp_filesystem->exists($fontAwesome_file)) {
                $content = $wp_filesystem->get_contents($fontAwesome_file);
            } // End If Statement

            if ($wp_filesystem->exists($template_icon_file)) {
                $content .= $wp_filesystem->get_contents($template_icon_file);
            } // End If Statement

            $pattern = '/\.(fa-(?:\w+(?:-)?)+):before\s*{\s*content/';
            $pattern_two = '/\.(icon-(?:\w+(?:-)?)+):before\s*{\s*content/';

            $subject = $content;

            preg_match_all($pattern, $subject, $matches, PREG_SET_ORDER);
            preg_match_all($pattern_two, $subject, $matches_two, PREG_SET_ORDER);

            $all_matches = array_merge($matches, $matches_two);

            $icons = array();

            foreach ($all_matches as $match) {
                // $icons[] = array('value' => $match[1], 'label' => $match[1]);
                $icons[] = $match[1];
            }


            $data = $icons;
            set_transient('zeinet_fa_icons', $data, 10080); // saved for one week

        }



        return array_combine($data, $data); // combined for key = value
    }


endif;

// custom kses allowed html
if (!function_exists('zeinet_kses_allowed_html')) :
    function zeinet_kses_allowed_html($tags, $context)
    {
        switch ($context) {
            case 'zeinet_allowed_tags':
                $tags = array(
                    'a' => array('href' => array(), 'class' => array()),
                    'b' => array(),
                    'br' => array(),
                    'span' => array('class' => array(), 'data-count' => array()),
                    'del' => array('class' => array(), 'data-count' => array()),
                    'ins' => array('class' => array(), 'data-count' => array()),
                    'bdi' => array('class' => array(), 'data-count' => array()),
                    'img' => array('class' => array()),
                    'i' => array('class' => array()),
                    'p' => array('class' => array()),
                    'ul' => array('class' => array()),
                    'li' => array('class' => array()),
                    'div' => array('class' => array()),
                    'strong' => array(),
                    'sup' => array(),
                );
                return $tags;
            default:
                return $tags;
        }
    }

    add_filter('wp_kses_allowed_html', 'zeinet_kses_allowed_html', 10, 2);

endif;

if (!function_exists('zeinet_excerpt')) :

    // Post's excerpt text
    function zeinet_excerpt($get_limit_value, $echo = true)
    {
        $opt = $get_limit_value;
        $excerpt_limit = !empty($opt) ? $opt : 40;
        $excerpt = wp_trim_words(get_the_content(), $excerpt_limit, '');
        if ($echo == true) {
            echo esc_html($excerpt);
        } else {
            return esc_html($excerpt);
        }
    }

endif;


if (!function_exists('zeinet_posted_on')) :
    /**
     * Prints HTML with meta information for the current post-date/time.
     */
    function zeinet_posted_on()
    {
        $time_zeinettring = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
        if (get_the_time('U') !== get_the_modified_time('U')) {
            $time_zeinettring = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
        }

        $time_zeinettring = sprintf(
            $time_zeinettring,
            esc_attr(get_the_date(DATE_W3C)),
            esc_html(get_the_date()),
            esc_attr(get_the_modified_date(DATE_W3C)),
            esc_html(get_the_modified_date())
        );

        $posted_on = sprintf(
            /* translators: %s: post date. */
            esc_html_x(' %s', 'post date', 'zeinet'),
            '<a href="' . esc_url(get_permalink()) . '" rel="bookmark">' . $time_zeinettring . '</a>'
        );

        echo '<span class="posted-on"> ' . $posted_on . '</span>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped

    }
endif;

if (!function_exists('zeinet_posted_by')) :
    /**
     * Prints HTML with meta information for the current author.
     */
    function zeinet_posted_by()
    {
        $byline = sprintf(
            /* translators: %s: post author. */
            esc_html_x('%s', 'post author', 'zeinet'),
            '<span class="author vcard"><a class="url fn n" href="' . esc_url(get_author_posts_url(get_the_author_meta('ID'))) . '">' . esc_html(get_the_author()) . '</a></span>'
        );

        echo '<span class="byline"><i class="fas fa-user-circle"></i> ' . esc_html__('by ', 'zeinet') . $byline . '</span>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped

    }
endif;

if (!function_exists('zeinet_comment_count')) {
    function zeinet_comment_count()
    {
        if (!post_password_required() && (comments_open() || get_comments_number())) {
            echo '<span class="comments-link"><i class="fas fa-comments"></i> ';
            comments_popup_link(
                sprintf(
                    wp_kses(
                        /* translators: %s: post title */
                        __('Leave a Comment<span class="screen-reader-text"> on %s</span>', 'zeinet'),
                        array(
                            'span' => array(
                                'class' => array(),
                            ),
                        )
                    ),
                    wp_kses_post(get_the_title())
                )
            );
            echo '</span>';
        }
    }
}

if (!function_exists('zeinet_entry_footer')) :
    /**
     * Prints HTML with meta information for the categories, tags and comments.
     */
    function zeinet_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(esc_html__(' ', 'zeinet'));
            if ($categories_list) {
                /* translators: 1: list of categories. */
                printf('<span class="news-details__tags"><span>' . esc_html__('Posted in %1$s', 'zeinet') . '</span>', '</span>' . $categories_list); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
            }

            /* translators: used between list items, there is a space after the comma */
            $tags_list = get_the_tag_list('', esc_html_x(' ', 'list item separator', 'zeinet'));
            if ($tags_list) {
                /* translators: 1: list of tags. */
                printf('<span class="news-details__tags"><span>' . esc_html__('Tags %1$s', 'zeinet') . '</span>', '</span>' . $tags_list); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
            }
        }
    }
endif;


if (!function_exists('zeinet_post_thumbnail')) :
    /**
     * Displays an optional post thumbnail.
     *
     * Wraps the post thumbnail in an anchor element on index views, or a div
     * element when on single views.
     */
    function zeinet_post_thumbnail()
    {
        if (post_password_required() || is_attachment() || !has_post_thumbnail()) {
            return;
        }

        if (is_singular()) :
?>

            <div class="post-thumbnail blog-single__content-img news-details__img">
                <?php the_post_thumbnail(); ?>
                <div class="news-details__date">
                    <p><?php zeinet_posted_on(); ?></p>
                </div>
            </div><!-- .post-thumbnail -->

        <?php else : ?>
            <div class="news-sidebar__single">
                <a class="post-thumbnail blog-single__content-img" href="<?php the_permalink(); ?>" aria-hidden="true" tabindex="-1">
                    <?php
                    the_post_thumbnail(
                        'post-thumbnail',
                        array(
                            'alt' => the_title_attribute(
                                array(
                                    'echo' => false,
                                )
                            ),
                        )
                    );
                    ?>
                </a>
                <div class="news-sidebar__date">
                    <p><?php zeinet_posted_on(); ?></p>
                </div>
            </div>
        <?php
        endif; // End is_singular().
    }
endif;

if (!function_exists('zeinet_post_query')) {
    function zeinet_post_query($post_type)
    {
        $post_list = get_posts(array(
            'post_type' => $post_type,
            'showposts' => -1,
        ));
        $posts = array();

        if (!empty($post_list) && !is_wp_error($post_list)) {
            foreach ($post_list as $post) {
                $options[$post->ID] = $post->post_title;
            }
            return $options;
        }
    }
}

if (!function_exists('zeinet_custom_query_pagination')) :
    /**
     * Prints HTML with post pagination links.
     */
    function zeinet_custom_query_pagination($paged = '', $max_page = '')
    {
        global $wp_query;
        $big = 999999999; // need an unlikely integer
        if (!$paged)
            $paged = get_query_var('paged');
        if (!$max_page)
            $max_page = $wp_query->max_num_pages;

        $links = paginate_links(array(
            'base'       => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
            'format'     => '?paged=%#%',
            'current'    => max(1, $paged),
            'total'      => $max_page,
            'mid_size'   => 1,
            'prev_text' => '<i class="fa fa-angle-left"></i>',
            'next_text' => '<i class="fa fa-angle-right"></i>',
        ));

        echo wp_kses($links, 'zeinet_allowed_tags');
    }
endif;

if (!function_exists('zeinet_get_nav_menu')) :
    function zeinet_get_nav_menu()
    {
        $menu_list = get_terms(array(
            'taxonomy' => 'nav_menu',
            'hide_empty' => true,
        ));
        $options = [];
        if (!empty($menu_list) && !is_wp_error($menu_list)) {
            foreach ($menu_list as $menu) {
                $options[$menu->slug] = $menu->name;
            }
            return $options;
        }
    }
endif;

if (!function_exists('zeinet_get_taxonoy')) :
    function zeinet_get_taxonoy($taxonoy)
    {
        $taxonomy_list = get_terms(array(
            'taxonomy' => $taxonoy,
            'hide_empty' => true,
        ));
        $options = [];
        if (!empty($taxonomy_list) && !is_wp_error($taxonomy_list)) {
            foreach ($taxonomy_list as $taxonomy) {
                $options[$taxonomy->slug] = $taxonomy->name;
            }
            return $options;
        }
    }
endif;

if (!function_exists('zeinet_get_template')) :
    function zeinet_get_template($template_name = null)
    {
        $template_path = apply_filters('zeinet-elementor/template-path', 'elementor-templates/');
        $template = locate_template($template_path . $template_name);
        if (!$template) {
            $template = ZEINET_ADDON_PATH  . '/elementor-templates/' . $template_name;
        }
        if (file_exists($template)) {
            return $template;
        } else {
            return false;
        }
    }
endif;

if (!function_exists('zeinet_get_thumbnail_alt')) :
    function zeinet_get_thumbnail_alt($thumbnail_id)
    {
        return get_post_meta($thumbnail_id, '_wp_attachment_image_alt', true);
    }
endif;




if (!function_exists('zeinet_get_owl_options')) :
    function zeinet_get_owl_options($settings)
    {
        $loop_status = ('yes' == $settings['loop']) ? 'true' : 'false';
        $nav_status = ('yes' == $settings['enable_nav']) ? 'true' : 'false';
        $dots_status = ('yes' == $settings['enable_dots']) ? 'true' : 'false';
        if ('yes' == $settings['enable_nav']) {
            $nav_left_icon = $settings['nav_left_icon']['value'];
            $nav_right_icon = $settings['nav_right_icon']['value'];
        }
        $items = $settings['items']['size'];
        $margin = $settings['margin']['size'];
        $smart_speed = $settings['smart_speed']['size'];
        $breakpoint = $settings['breakpoint'];
        ob_start(); ?>
        {
        "loop": <?php echo esc_attr($loop_status) ?>,
        "margin": <?php echo esc_attr($margin) ?>,
        "items": <?php echo esc_attr($items) ?>
        ,"nav": <?php echo esc_attr($nav_status) ?>
        <?php if ('yes' == $settings['enable_nav']) :  ?>
            ,"navText": [
            "<i class=\" <?php echo esc_attr($nav_left_icon) ?>\"></i>",
            "<i class=\" <?php echo esc_attr($nav_right_icon) ?>\"></i>"
            ]
        <?php endif; ?>
        ,"dots": <?php echo esc_attr($dots_status) ?>
        ,"smartSpeed": <?php echo esc_attr($smart_speed) ?>

        <?php if (!empty($breakpoint)) :  ?>
            ,
            "responsive":
            {
            <?php foreach ($breakpoint as $item) : ?>
                "<?php echo esc_attr($item['screen_size']['size']); ?>": {
                "margin": <?php echo esc_attr($item['margin']['size']); ?>,
                "items": <?php echo esc_attr($item['item']['size']); ?>
                }<?php echo esc_attr($item != end($breakpoint) ? ',' : ''); ?>
            <?php endforeach; ?>
            }
        <?php endif; ?>
        }
    <?php return ob_get_clean();
    }
endif;

if (!function_exists('zeinet_get_swiper_options')) :
    function zeinet_get_swiper_options($settings, $pagination_id = false)
    {
        $loop_status = ('yes' == $settings['loop']) ? 'true' : 'false';
        $autoplay_status = ('yes' == $settings['autoplay']) ? 'true' : 'false';
        $delay = $settings['delay']['size'];
        $items = $settings['items']['size'];
        $margin = $settings['margin']['size'];
        $breakpoint = $settings['breakpoint'];
        ob_start(); ?>

        {
        "loop": <?php echo esc_attr($loop_status); ?>,
        "spaceBetween": <?php echo esc_attr($margin); ?>,
        "slidesPerView": <?php echo esc_attr($items); ?>
        <?php if ('true' == $autoplay_status) : ?>
            ,"autoplay": { "delay": <?php echo esc_attr($delay); ?> }
        <?php endif; ?>
        <?php if ('yes' == $settings['enable_dots']) : ?>
            ,"pagination": {
            "el": "#<?php echo esc_attr($pagination_id); ?>",
            "type": "bullets",
            "clickable": true
            }
        <?php endif; ?>
        <?php if (!empty($breakpoint)) :  ?>
            ,"breakpoints": {
            <?php foreach ($breakpoint as $item) : ?>
                "<?php echo esc_attr($item['screen_size']['size']); ?>": {
                "spaceBetween": <?php echo esc_attr($item['margin']['size']); ?>,
                "slidesPerView": <?php echo esc_attr($item['item']['size']); ?>
                }<?php echo esc_attr($item != end($breakpoint) ? ',' : ''); ?>
            <?php endforeach; ?>
            }
        <?php endif; ?>
        }
    <?php return ob_get_clean();
    }
endif;

if (!function_exists('zeinet_get_elementor_carousel_options')) :
    function zeinet_get_elementor_carousel_options($arg, $condition)
    {


        $arg->start_controls_section(
            'slider_options',
            [
                'label' => __('Slider Options', 'zeinet-addon'),
                'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
                'condition' => [
                    'layout_type' => $condition
                ]
            ]
        );



        $arg->add_control(
            'autoplay',
            [
                'label' => esc_html__('AutoPlay', 'zeinet-addon'),
                'type' => \Elementor\Controls_Manager::SWITCHER,
                'label_on' => esc_html__('Yes', 'zeinet-addon'),
                'label_off' => esc_html__('No', 'zeinet-addon'),
                'return_value' => 'yes',
                'default' => 'yes',
            ]
        );

        $arg->add_control(
            'delay',
            [
                'label' => __('AutoPlay Delay', 'zeinet-addon'),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => ['count'],

                'range' => [
                    'count' => [
                        'min' => 0,
                        'max' => 10000,
                        'step' => 1,
                    ],
                ],
                'default' => [
                    'unit' => 'count',
                    'size' => 5000,
                ],
            ]
        );

        $arg->add_control(
            'loop',
            [
                'label' => esc_html__('Loop', 'zeinet-addon'),
                'type' => \Elementor\Controls_Manager::SWITCHER,
                'label_on' => esc_html__('Yes', 'zeinet-addon'),
                'label_off' => esc_html__('No', 'zeinet-addon'),
                'return_value' => 'yes',
                'default' => 'yes',
            ]
        );

        $arg->add_control(
            'enable_nav',
            [
                'label' => esc_html__('Display Nav', 'zeinet-addon'),
                'type' => \Elementor\Controls_Manager::SWITCHER,
                'label_on' => esc_html__('Yes', 'zeinet-addon'),
                'label_off' => esc_html__('No', 'zeinet-addon'),
                'return_value' => 'yes',
                'default' => 'yes',
            ]
        );

        $arg->add_control(
            'nav_left_icon',
            [
                'label' => esc_html__('Nav Left Icon', 'zeinet-addon'),
                'type' => \Elementor\Controls_Manager::ICONS,
                'condition' => [
                    'enable_nav' => 'yes'
                ],
                'default' => [
                    'value' => 'fa fa-angle-left',
                    'library' => 'solid',
                ],
            ]
        );

        $arg->add_control(
            'nav_right_icon',
            [
                'label' => esc_html__('Nav Right Icon', 'zeinet-addon'),
                'type' => \Elementor\Controls_Manager::ICONS,
                'condition' => [
                    'enable_nav' => 'yes'
                ],
                'default' => [
                    'value' => 'fa fa-angle-right',
                    'library' => 'solid',
                ],
            ]
        );

        $arg->add_control(
            'enable_dots',
            [
                'label' => esc_html__('Display Dots', 'zeinet-addon'),
                'type' => \Elementor\Controls_Manager::SWITCHER,
                'label_on' => esc_html__('Yes', 'zeinet-addon'),
                'label_off' => esc_html__('No', 'zeinet-addon'),
                'return_value' => 'yes',
                'default' => 'yes',
            ]
        );


        $arg->add_control(
            'smart_speed',
            [
                'label' => __('Smart Speed', 'zeinet-addon'),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => ['count'],

                'range' => [
                    'count' => [
                        'min' => 0,
                        'max' => 10000,
                        'step' => 1,
                    ],
                ],
                'default' => [
                    'unit' => 'count',
                    'size' => 700,
                ],
            ]
        );


        $arg->add_control(
            'items',
            [
                'label' => __('Slide Items', 'zeinet-addon'),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => ['count'],
                'range' => [
                    'count' => [
                        'min' => 1,
                        'max' => 10,
                        'step' => 1,
                    ],
                ],
                'default' => [
                    'unit' => 'count',
                    'size' => 1,
                ],
            ]
        );

        $arg->add_control(
            'margin',
            [
                'label' => __('Margin', 'zeinet-addon'),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => ['count'],
                'range' => [
                    'count' => [
                        'min' => 1,
                        'max' => 200,
                        'step' => 1,
                    ],
                ],
                'default' => [
                    'unit' => 'count',
                    'size' => 0,
                ],
            ]
        );


        $breakpoint = new \Elementor\Repeater();

        $breakpoint->add_control(
            'screen_size',
            [
                'label' => __('Screen Size', 'zeinet-addon'),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => ['count'],
                'range' => [
                    'count' => [
                        'min' => 0,
                        'max' => 1920,
                        'step' => 1,
                    ],
                ],
                'default' => [
                    'unit' => 'count',
                    'size' => 0,
                ],
            ]
        );

        $breakpoint->add_control(
            'item',
            [
                'label' => __('Slide Item', 'zeinet-addon'),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => ['count'],
                'range' => [
                    'count' => [
                        'min' => 1,
                        'max' => 10,
                        'step' => 1,
                    ],
                ],
                'default' => [
                    'unit' => 'count',
                    'size' => 1,
                ],
            ]
        );

        $breakpoint->add_control(
            'margin',
            [
                'label' => __('Margin', 'zeinet-addon'),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => ['count'],
                'range' => [
                    'count' => [
                        'min' => 1,
                        'max' => 200,
                        'step' => 1,
                    ],
                ],
                'default' => [
                    'unit' => 'count',
                    'size' => 0,
                ],
            ]
        );

        $arg->add_control(
            'breakpoint',
            [
                'label' => __('Breakpoints', 'zeinet-addon'),
                'type' => \Elementor\Controls_Manager::REPEATER,
                'prevent_empty' => false,
                'fields' => $breakpoint->get_controls(),
            ]
        );

        $arg->end_controls_section();
    }
endif;


if (!function_exists('zeinet_typo_and_color_options')) :
    function zeinet_typo_and_color_options($agrs, $label, $selector, $condition, $style = 'color', $typo = true, $color = true)
    {

        if (false != $typo) :
            //title typography
            $agrs->add_group_control(
                \Elementor\Group_Control_Typography::get_type(),
                [
                    'name'           =>  str_replace(' ', '_', $label) . '_typo',
                    'label'          => esc_html__($label . ' Typography', 'zeinet-addon'),
                    'selector'       => $selector,
                    'condition' => [
                        'layout_type' => $condition
                    ]
                ]
            );

        endif;
        if (false != $color) :
            $agrs->add_control(
                str_replace(' ', '_', $label) . '_color',
                [
                    'label' => __($label . ' Color', 'zeinet-addon'),
                    'type' => \Elementor\Controls_Manager::COLOR,
                    'selectors' => [
                        $selector => $style . ': {{VALUE}}',
                    ],
                    'condition' => [
                        'layout_type' => $condition
                    ]
                ]
            );
        endif;
    }
endif;



// comment meta

if (!is_admin()) :
    add_filter('get_comment_author', 'zeinet_modify_comment');
    function zeinet_modify_comment($author)
    {
        if (is_singular('movie')) :
            if ($commentrating = get_comment_meta(get_comment_ID(), 'rating', true)) {

                return '<span class="movie-more-review__text-box-one">
            <span class="movie-more-review__text-box-left">
                <span class="reviewed-by">' . esc_html__('Reviewed by ', 'zeinet-addon') . '<span>' . $author . '</span></span>
            </span>
            <span class="movie-more-review__text-box-right">
                <span class="rating-count"><i class="fa fa-star"></i> ' . $commentrating . '</span>
            </span>
        </span>';
            } else {
                return $author;
            }
        endif;

        return $author;
    }
endif;

add_action('comment_post', 'zeinet_save_comment_meta_data');
function zeinet_save_comment_meta_data($comment_id)
{
    if ((isset($_POST['rating'])) && ($_POST['rating'] != ''))
        $rating = wp_filter_nohtml_kses($_POST['rating']);
    add_comment_meta($comment_id, 'rating', $rating);
}

// Add the filter to check if the comment meta data has been filled or not

add_filter('preprocess_comment', 'zeinet_verify_comment_meta_data');
function zeinet_verify_comment_meta_data($commentdata)
{
    if (is_singular('movie')) :
        if (!isset($_POST['rating']))
            wp_die(__('Error: You did not add your rating. Hit the BACK button of your Web browser and resubmit your comment with rating.', 'zeinet-addon'));
        return $commentdata;
    else :
        return $commentdata;
    endif;
}


add_action('comment_form_logged_in_after', 'zeinet_additional_fields');
add_action('comment_form_before_fields', 'zeinet_additional_fields');

function zeinet_additional_fields()
{
    if (is_singular('movie')) :
    ?>
        <div class="col-xl-12">
            <div class="movie-more-review__rate-box">
                <p><?php esc_html_e('Rate this movie?', 'zeinet-addon') ?></p>
                <div class="movie-more-review__star">
                    <i class="fa fa-star" data-value="1"></i>
                    <i class="fa fa-star" data-value="2"></i>
                    <i class="fa fa-star" data-value="3"></i>
                    <i class="fa fa-star" data-value="4"></i>
                    <i class="fa fa-star" data-value="5"></i>
                    <input type="hidden" name="rating" id="rating">
                </div>
            </div>
        </div>

<?php

    endif;
}


//Get the average rating of a post.
function zeinet_comment_rating_get_average_ratings($id)
{
    $comments = get_approved_comments($id);

    if ($comments) {
        $i = 0;
        $total = 0;
        foreach ($comments as $comment) {
            $rate = get_comment_meta($comment->comment_ID, 'rating', true);
            if (isset($rate) && '' !== $rate) {
                $i++;
                $total += $rate;
            }
        }

        if (0 === $i) {
            return false;
        } else {
            return round($total / $i, 1);
        }
    } else {
        return false;
    }
}


function zeinet_addon_body_classes($classes)
{
    $classes[] = 'zeinet-addon';

    return $classes;
}
add_filter('body_class', 'zeinet_addon_body_classes');


if (!is_rtl()) :

    function zeinet_set_rtl_mode($locale)
    {

        $zeinet_get_rtl_mode_status = get_theme_mod('zeinet_rtl_mode', false);

        // check page rtl
        $current_page = get_page_by_path($_SERVER['REQUEST_URI']);
        if (isset($current_page->ID)) {
            $check_page_rtl = get_post_meta($current_page->ID, 'zeinet_enable_rtl_mode', true);
            $zeinet_get_rtl_mode_status = empty($check_page_rtl) ? $zeinet_get_rtl_mode_status : $check_page_rtl;
        }

        //check home page
        $check_url = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
        $check_url_without_http = trim(str_replace(array('http://', 'https://'), '', $check_url), '/');

        $site = site_url();
        $site_without_http = trim(str_replace(array('http://', 'https://'), '', $site), '/');

        if ($check_url_without_http ==  $site_without_http) {
            $frontpage_id = get_option('page_on_front');
            $check_home_page_rtl = get_post_meta($frontpage_id, 'zeinet_enable_rtl_mode', true);
            $zeinet_get_rtl_mode_status = empty($check_home_page_rtl) ? $zeinet_get_rtl_mode_status : $check_home_page_rtl;
        }

        $zeinet_dynamic_rtl_mode_status = isset($_GET['rtl_mode']) ? $_GET['rtl_mode'] : $zeinet_get_rtl_mode_status;
        if ('yes' == $zeinet_dynamic_rtl_mode_status) {
            $locale = ($zeinet_dynamic_rtl_mode_status == 'yes') ? 'ar' : 'en_US';
        }

        return $locale;
    }

    add_filter('locale', 'zeinet_set_rtl_mode', 1, 1);

endif;



/**
 * Sourcing color metabox and customizer via json file
 */
function zeinet_source_color_meta($type = null, $set_option = null, $init = null)
{
    $data = get_transient('zeinet_css_variable');
    if (empty($data)) {
        global $wp_filesystem;
        require_once(ABSPATH . '/wp-admin/includes/file.php');
        WP_Filesystem();

        $json_file =   ZEINET_ADDON_PATH . '/assets/vendors/zeinet-css-var/zeinet-css-var.json';
        $content = '';

        if ($wp_filesystem->exists($json_file)) {
            $content = $wp_filesystem->get_contents($json_file);
        } // End If Statement
        $data = apply_filters('zeinet_css_variable', $content);
        set_transient('zeinet_css_variable', $data, 10080); // saved for one week
    }
    $values = json_decode($data);

    if ('get' === $type) {
        $cssvariable = '';
        foreach ($values as $name) {
            $cssvariable .= zeinet_get_color_meta($name, 'zeinet');
        }
        return $cssvariable;
    }
    if ('set' === $type) {
        zeinet_set_color_meta($set_option, $values);
    }
    if ('set_customizer' === $type) {
        zeinet_set_color_customizer($init, $set_option, $values);
    }
}


/**
 * Making color metaboxes from arrays
 */
function zeinet_set_color_meta($option_name = null, $value = null)
{
    foreach ($value as $name) {
        $option_name->add_field(
            array(
                'name' => ucwords(str_replace("-", " ", $name)),
                'id' => 'zeinet_' . str_replace("-", "_", $name),
                'type'    => 'colorpicker',
            )
        );
    }
}


/**
 * Making color customizer options from arrays
 */
function zeinet_set_color_customizer($init = null, $option_name = null, $value = null)
{
    foreach ($value as $name) {
        $init->customize_type_color(
            $option_name,
            'zeinet_theme_color',
            $name
        );
    }
}
/**
 * Printing color variables conditional
 */
function zeinet_get_color_meta($name = null, $prefix = null)
{
    $setting_name = str_replace("-", "_", $name);
    $customizer_option = get_theme_mod($setting_name);
    $page_meta_option = get_post_meta(get_the_ID(), $prefix . '_' . $setting_name, true);
    $value = !empty($page_meta_option) ? $page_meta_option : $customizer_option;

    return !empty($value) ? "--" . $name . ":" . $value . ";" . "--" . $name . "-rgb:" . zeinet_hex_to_rgb($value) . ";" : "";
}