/**
  * @param $posttype
  * @param $name
  * @param array $args
  */
 function __construct($id, $posttype, $name, $args = array())
 {
     $this->id = $id;
     $this->posttype = $posttype;
     $this->name = $name;
     $this->start = 0;
     $order = isset($args['order']) && !empty($args['order']) ? $args['order'] : 10;
     $this->class = isset($args['class']) && !empty($args['class']) ? $args['class'] : 'fa-list';
     rcl_bxslider_scripts();
     add_filter('posts_button_rcl', array($this, 'add_postlist_button'), $order, 2);
     add_filter('posts_block_rcl', array($this, 'add_postlist_block'), $order, 2);
     add_action('wp_ajax_rcl_posts_list', array($this, 'rcl_posts_list'));
     add_action('wp_ajax_nopriv_rcl_posts_list', array($this, 'rcl_posts_list'));
 }
function rcl_block($place, $callback, $args = false)
{
    $data = array('place' => $place, 'callback' => $callback, 'args' => $args);
    $data = apply_filters('block_data_rcl', $data);
    if (is_admin()) {
        return false;
    }
    if (isset($data['args']['gallery'])) {
        rcl_bxslider_scripts();
    }
    if (!class_exists('Rcl_Blocks')) {
        include_once plugin_dir_path(__FILE__) . 'functions/rcl_blocks.php';
    }
    $block = new Rcl_Blocks($data);
}
 private function init_hooks()
 {
     global $user_ID, $user_LK, $rcl_options;
     register_activation_hook(__FILE__, array('RCL_Install', 'install'));
     add_action('init', array($this, 'init'), 0);
     if (is_admin()) {
         add_action('save_post', 'rcl_postmeta_update', 0);
         add_action('admin_head', 'rcl_admin_scrips');
         add_action('admin_menu', 'rcl_options_panel', 19);
     } else {
         add_action('wp_enqueue_scripts', 'rcl_frontend_scripts');
         add_action('wp_head', 'rcl_update_timeaction_user');
         if (!$user_ID) {
             if (!isset($rcl_options['login_form_recall']) || !$rcl_options['login_form_recall']) {
                 add_filter('wp_footer', 'rcl_login_form', 99);
                 add_filter('wp_enqueue_scripts', 'rcl_floatform_scripts');
             } else {
                 add_filter('wp_enqueue_scripts', 'rcl_pageform_scripts');
             }
         }
         if ($user_LK) {
             rcl_bxslider_scripts();
         }
     }
 }
function rcl_slider($atts, $content = null)
{
    rcl_bxslider_scripts();
    extract(shortcode_atts(array('num' => 5, 'term' => '', 'type' => 'post', 'post_meta' => false, 'meta_value' => false, 'tax' => 'category', 'exclude' => false, 'include' => false, 'orderby' => 'post_date', 'title' => true, 'desc' => 280, 'order' => 'DESC', 'size' => '9999,300'), $atts));
    $args = array('numberposts' => $num, 'orderby' => $orderby, 'order' => $order, 'exclude' => $exclude, 'post_type' => $type, 'post_status' => 'publish', 'meta_key' => '_thumbnail_id');
    if ($term) {
        $args['tax_query'] = array(array('taxonomy' => $tax, 'field' => 'id', 'terms' => explode(',', $term)));
    }
    if ($post_meta) {
        $args['meta_query'] = array(array('key' => $post_meta, 'value' => $meta_value));
    }
    //print_r($args);
    $posts = get_posts($args);
    if (!$posts) {
        return false;
    }
    $size = explode(',', $size);
    $size = isset($size[1]) ? $size : $size[0];
    $plslider = '<ul class="slider-rcl">';
    foreach ($posts as $post) {
        //if( !has_post_thumbnail($post->ID)) continue;
        $thumb_id = get_post_thumbnail_id($post->ID);
        $large_url = wp_get_attachment_image_src($thumb_id, 'full');
        $thumb_url = wp_get_attachment_image_src($thumb_id, $size);
        $plslider .= '<li><a href="' . get_permalink($post->ID) . '">';
        if ($type = 'products') {
            $plslider .= rcl_get_price($post->ID);
        }
        $plslider .= '<img src=' . $thumb_url[0] . '>';
        if ($post->post_excerpt) {
            $post_content = strip_tags($post->post_excerpt);
        } else {
            $post_content = apply_filters('the_content', strip_tags($post->post_content));
        }
        if ($desc > 0 && strlen($post_content) > $desc) {
            $post_content = substr($post_content, 0, $desc);
            $post_content = preg_replace('@(.*)\\s[^\\s]*$@s', '\\1 ...', $post_content);
        }
        $plslider .= '<div class="content-slide">';
        if ($title) {
            $plslider .= '<h3>' . $post->post_title . '</h3>';
        }
        if ($desc > 0) {
            $plslider .= '<p>' . $post_content . '</p>';
        }
        $plslider .= '</div>';
        $plslider .= '</a></li>';
    }
    $plslider .= '</ul>';
    return $plslider;
}
function rcl_gallery_product($content)
{
    global $post;
    if (get_post_type($post->ID) == 'products') {
        if (get_post_meta($post->ID, 'recall_slider', 1) != 1 || !is_single()) {
            return $content;
        }
        if (!class_exists('Attachments')) {
            $postmeta = get_post_meta($post->ID, 'children_prodimage', 1);
            if ($postmeta) {
                rcl_bxslider_scripts();
                $values = explode(',', $postmeta);
                $gallery = '<div id="product-gallery">' . '<ul class="rcl-gallery">';
                foreach ((array) $values as $children) {
                    $large = wp_get_attachment_image_src($children, 'large');
                    $gallery .= '<li><a class="fancybox" href="' . $large[0] . '"><img src="' . $large[0] . '"></a></li>';
                    $thumbs[] = $large[0];
                }
                $gallery .= '</ul>';
                if (count($thumbs) > 1) {
                    $gallery .= '<div id="bx-pager">';
                    foreach ($thumbs as $k => $src) {
                        $gallery .= '<a data-slide-index="' . $k . '" href=""><img src="' . $src . '" /></a>';
                    }
                    $gallery .= '</div>';
                }
                $gallery .= '</div>';
            }
            return $gallery . $content;
        } else {
            $attachments = new Attachments('attachments_products');
            if ($attachments->exist()) {
                rcl_bxslider_scripts();
                $num = 0;
                $gallery = '<div id="product-gallery">' . '<ul class="rcl-gallery">';
                while ($attachments->get()) {
                    $num++;
                    $large = wp_get_attachment_image_src($children, 'large');
                    $gallery .= '<li><a class="fancybox" href="' . $attachments->src('full') . '"><img src="' . $attachments->src('thumbnail') . '"></a></li>';
                    $thumbs[] = $large[0];
                }
                $gallery .= '</ul>';
                $gallery .= '<div id="bx-pager">';
                foreach ($thumbs as $k => $src) {
                    $gallery .= '<a data-slide-index="' . $k . '" href=""><img src="' . $src . '" /></a>';
                }
                $gallery .= '</div>';
            }
            $gallery .= '</div>';
            return $gallery . $content;
        }
    } else {
        return $content;
    }
}
function rcl_shortcode_gallery($atts, $content = null)
{
    global $post;
    rcl_bxslider_scripts();
    extract(shortcode_atts(array('post_id' => false), $atts));
    $post_id = $post->ID;
    $args = array('post_parent' => $post_id, 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => 'any', 'post_mime_type' => 'image');
    $childrens = get_children($args);
    if ($childrens) {
        $gallery = '<ul class="rcl-gallery">';
        foreach ((array) $childrens as $children) {
            $large = wp_get_attachment_image_src($children->ID, 'large');
            $gallery .= '<li><a class="fancybox" href="' . $large[0] . '"><img src="' . $large[0] . '"></a></li>';
            $thumbs[] = $large[0];
        }
        $gallery .= '</ul>';
        if (count($thumbs) > 1) {
            $gallery .= '<div id="bx-pager">';
            foreach ($thumbs as $k => $src) {
                $gallery .= '<a data-slide-index="' . $k . '" href=""><img src="' . $src . '" /></a>';
            }
            $gallery .= '</div>';
        }
    }
    return $gallery;
}