示例#1
2
 function render($atts)
 {
     $this->block_uid = td_global::td_generate_unique_id();
     //update unique id on each render
     extract(shortcode_atts(array('limit' => 3, 'sort' => '', 'category_id' => '', 'category_ids' => '', 'custom_title' => '', 'custom_url' => '', 'hide_title' => '', 'show_child_cat' => '', 'tag_slug' => '', 'header_color' => ''), $atts));
     $buffy = '';
     //output buffer
     $td_unique_id = td_global::td_generate_unique_id();
     $td_query =& td_data_source::get_wp_query($atts);
     //by ref  do the query
     //get the js for this block
     $buffy .= $this->get_block_js($atts, $td_query);
     $buffy .= '<div class="td_block_wrap td_block7">';
     //get the block title
     $buffy .= $this->get_block_title($atts);
     //get the sub category filter for this block
     $buffy .= $this->get_block_sub_cats($atts, $td_unique_id);
     $buffy .= '<div id=' . $this->block_uid . ' class="td_block_inner">';
     //inner content of the block
     $buffy .= $this->inner($td_query->posts);
     $buffy .= '</div>';
     //get the ajax pagination for this block
     $buffy .= $this->get_block_pagination($atts, $td_unique_id);
     $buffy .= '</div> <!-- ./block1 -->';
     return $buffy;
 }
示例#2
0
 /**
  * the base render function. This is called by all the child classes of this class
  * this function also adds the block specific css to the buffer (for hover and stuff)
  * @param $atts
  * @return string ''
  */
 function render($atts, $content = null)
 {
     $this->atts = $this->add_live_filter_atts($atts);
     //add live filter atts
     $this->block_uid = td_global::td_generate_unique_id();
     //update unique id on each render
     $this->td_query =& td_data_source::get_wp_query($this->atts);
     //by ref do the query
     /**
      * if we have an header color, add an unique class to this block and also add the css in the buffer
      *  - also does not add the class and color on specific blocks
      */
     if (!empty($atts['header_color']) and $this->block_id != 'td_block_14' and $this->block_id != 'td_slide') {
         $unique_block_class = $this->block_uid . '_inline';
         if (!empty($this->atts['class'])) {
             $this->atts['class'] = $this->atts['class'] . ' ' . $unique_block_class;
         } else {
             $this->atts['class'] = $unique_block_class;
         }
         $raw_css = "\n                <style>\n                    /* @header_color */\n                    .{$unique_block_class} .td_module_wrap:hover .entry-title a {\n                        color: @header_color;\n                    }\n\n                    .{$unique_block_class} .td-next-prev-wrap a:hover i {\n                        background-color: @header_color;\n                        border-color: @header_color;\n                    }\n                    .{$unique_block_class} .td_module_wrap .td-post-category:hover {\n                        background-color: @header_color;\n                    }\n\n                    .{$unique_block_class} .td-pulldown-filter-display-option:hover {\n                        color: @header_color !important;\n                    }\n\n                    .{$unique_block_class} a.td-pulldown-filter-link:hover {\n                        color: @header_color !important;\n                    }\n                </style>\n            ";
         if (strtolower($atts['header_color']) != 'ffffff' and strtolower($atts['header_color']) != '#ffffff') {
             $td_css_compiler = new td_css_compiler($raw_css);
             $td_css_compiler->load_setting_raw('header_color', $atts['header_color']);
             /**
              * this outputs the custom style for this block  scoped - http://www.w3schools.com/tags/att_style_scoped.asp
              */
             $buffy = '<style scoped>';
             $buffy .= $td_css_compiler->compile_css();
             $buffy .= '</style>';
             echo $buffy;
         }
     }
     return '';
 }
示例#3
0
 function render($atts)
 {
     $this->block_uid = td_global::td_generate_unique_id();
     //update unique id on each render
     extract(shortcode_atts(array('limit' => 5, 'sort' => '', 'category_id' => '', 'category_ids' => '', 'custom_title' => '', 'custom_url' => '', 'hide_title' => '', 'show_child_cat' => '', 'tag_slug' => '', 'force_columns' => '', 'autoplay' => '', 'header_color' => '', 'class' => ''), $atts));
     if (!empty($class)) {
         $class = ' ' . $class;
     }
     $buffy = '';
     //output buffer
     $td_unique_id = td_global::td_generate_unique_id();
     $td_query =& td_data_source::get_wp_query($atts);
     //by ref  do the query
     if ($td_query->have_posts()) {
         //get the js for this block
         $buffy .= $this->get_block_js($atts, $td_query);
         $buffy .= '<div class="td_block_wrap td_block_slide td_normal_slide' . $class . '">';
         //get the block title
         $buffy .= $this->get_block_title($atts);
         //get the sub category filter for this block
         $buffy .= $this->get_block_sub_cats($atts, $td_unique_id);
         $buffy .= '<div id=' . $this->block_uid . ' class="td_block_inner">';
         //inner content of the block
         $buffy .= $this->inner($td_query->posts, $force_columns, $autoplay);
         $buffy .= '</div>';
         $buffy .= '</div> <!-- ./block1 -->';
     }
     return $buffy;
 }
示例#4
0
function td_ajax_search()
{
    $buffy = '';
    $buffy_msg = '';
    //the search string
    if (!empty($_POST['td_string'])) {
        $td_string = $_POST['td_string'];
    } else {
        $td_string = '';
    }
    //get the data
    $td_query =& td_data_source::get_wp_query_search($td_string);
    //by ref  do the query
    //build the results
    if (!empty($td_query->posts)) {
        foreach ($td_query->posts as $post) {
            $td_module_aj_search = new td_module_aj_search($post);
            $buffy .= $td_module_aj_search->render();
        }
    }
    if (count($td_query->posts) == 0) {
        //no results
        $buffy = '<div class="result-msg no-result">' . __td('No results') . '</div>';
    } else {
        //show the resutls
        $buffy_msg .= '<div class="result-msg"><a href="' . get_search_link($td_string) . '">' . __td('View all results') . '</a></div>';
        //add wrap
        $buffy = '<div class="td-aj-search-results">' . $buffy . '</div>' . $buffy_msg;
    }
    //prepare array for ajax
    $buffyArray = array('td_data' => $buffy, 'td_total_results' => 2, 'td_total_in_list' => count($td_query->posts), 'td_search_query' => $td_string);
    // Return the String
    die(json_encode($buffyArray));
}
 function render($atts, $content = null)
 {
     $this->block_uid = td_global::td_generate_unique_id();
     //update unique id on each render
     $buffy = '';
     //output buffer
     extract(shortcode_atts(array('limit' => 4, 'sort' => '', 'category_id' => '', 'category_ids' => '', 'tag_slug' => '', 'force_columns' => '', 'autoplay' => '', 'offset' => 0), $atts));
     if (empty($td_column_number)) {
         $td_column_number = td_util::vc_get_column_number();
         // get the column width of the block
     }
     if ($td_column_number == 3) {
         $current_limit = intval($limit);
         $post_limit = constant(get_class($this->internal_block_instance) . '::POST_LIMIT');
         $td_query = td_data_source::get_wp_query($atts);
         if (!empty($td_query->posts)) {
             if ($current_limit > $post_limit and count($td_query->posts) > $post_limit) {
                 $buffy .= '<div class="td-big-grid-slide td_block_wrap" id="iosSlider_' . $this->block_uid . '">';
                 $buffy .= '<div class="td-theme-slider td_block_inner" id="' . $this->block_uid . '">';
                 $current_offset = 0;
                 $atts['class'] = 'item';
                 while ($current_limit > 0) {
                     $atts['offset'] = $offset + $current_offset;
                     $buffy .= $this->internal_block_instance->render($atts);
                     $current_offset += $post_limit;
                     $current_limit -= $post_limit;
                 }
                 $buffy .= '</div>';
                 //end slider (if slider)
                 $buffy .= '<i class = "td-icon-left"></i>';
                 $buffy .= '<i class = "td-icon-right"></i>';
                 $buffy .= '</div>';
                 //end iosSlider (if slider)
                 $autoplay_settings = '';
                 $current_autoplay = filter_var($autoplay, FILTER_VALIDATE_INT);
                 if ($current_autoplay !== false) {
                     $autoplay_settings = 'autoSlide: true, autoSlideTimer: ' . $current_autoplay * 1000 . ',';
                 }
                 $slide_javascript = ';jQuery(document).ready(function() {
                     jQuery("#iosSlider_' . $this->block_uid . '").iosSlider({
                         snapToChildren: true,
                         desktopClickDrag: true,
                         keyboardControls: true,
                         responsiveSlides: true,
                         infiniteSlider: true,
                         ' . $autoplay_settings . '
                         navPrevSelector: jQuery("#iosSlider_' . $this->block_uid . ' .td-icon-left"),
                         navNextSelector: jQuery("#iosSlider_' . $this->block_uid . ' .td-icon-right")
                     });
                 });';
                 td_js_buffer::add_to_footer($slide_javascript);
             } else {
                 $buffy .= $this->internal_block_instance->render($atts);
             }
         }
     }
     return $buffy;
 }
示例#6
0
 function render($atts)
 {
     $this->block_uid = td_global::td_generate_unique_id();
     //update unique id on each render
     extract(shortcode_atts(array('limit' => 5, 'sort' => '', 'category_id' => '', 'category_ids' => '', 'custom_title' => '', 'custom_url' => '', 'hide_title' => '', 'show_child_cat' => '', 'tag_slug' => '', 'header_color' => ''), $atts));
     $buffy = '';
     //output buffer
     $td_unique_id = td_global::td_generate_unique_id();
     //custom categories
     //get subcategories, it returns false if there are no categories
     $get_block_sub_cats = $this->get_block_sub_cats($atts, $td_unique_id);
     $buffy_categories = '';
     $td_no_subcats_class = '';
     //we have subcategories
     if ($get_block_sub_cats !== false) {
         $buffy_categories .= '<div class="td_mega_menu_sub_cats">';
         //get the sub category filter for this block
         $buffy_categories .= $get_block_sub_cats;
         $buffy_categories .= '</div>';
         $atts['limit'] = 4;
         //alter the loop because we don't have space now with the categories
     } else {
         $td_no_subcats_class = ' td-no-subcats';
     }
     //end custom categories
     $td_query =& td_data_source::get_wp_query($atts);
     //by ref  do the query
     //get the js for this block
     $buffy .= $this->get_block_js($atts, $td_query);
     $buffy .= '<div class="td_block_wrap td_block_mega_menu' . $td_no_subcats_class . '">';
     //get the block title
     //$buffy .= $this->get_block_title($atts);
     //add the categories IF we have some
     $buffy .= $buffy_categories;
     $buffy .= '<div id=' . $this->block_uid . ' class="td_block_inner animated fadeInDown">';
     //inner content of the block
     $buffy .= $this->inner($td_query->posts);
     $buffy .= '</div>';
     $buffy .= $this->get_block_pagination($atts, $td_unique_id);
     //get the ajax pagination for this block
     $buffy .= '<div class="clearfix"></div>';
     $buffy .= '</div> <!-- ./block1 -->';
     return $buffy;
 }
示例#7
0
 /**
  * converts a pagebuilde array to a wordpress query args array
  * creates the $args array from shortcodes - used by the pagebuilde + widgets + by the metabox_to_args
  * @param string $atts : the shortcode string
  * @param string $paged : page number  /1  or  /2
  * @return array
  */
 static function shortcode_to_args($atts = '', $paged = '')
 {
     //print_r($atts);
     extract(shortcode_atts(array('category_ids' => '', 'category_id' => '', 'tag_slug' => '', 'sort' => '', 'limit' => '', 'autors_id' => '', 'installed_post_types' => '', 'posts_per_page' => '', 'offset' => '', 'live_filter' => '', 'live_filter_cur_post_id' => '', 'live_filter_cur_post_author' => ''), $atts));
     //init the array
     $wp_query_args = array('ignore_sticky_posts' => 1);
     //the query goes only via $category_ids - for both options ($category_ids and $category_id) also $category_ids overwrites $category_id
     if (!empty($category_id) and empty($category_ids)) {
         $category_ids = $category_id;
     }
     if (!empty($category_ids)) {
         $wp_query_args['cat'] = $category_ids;
     }
     if (!empty($tag_slug)) {
         $wp_query_args['tag'] = str_replace(' ', '-', $tag_slug);
     }
     switch ($sort) {
         case 'featured':
             if (!empty($category_ids)) {
                 //for each category, get the object and compose the slug
                 $cat_id_array = explode(',', $category_ids);
                 foreach ($cat_id_array as &$cat_id) {
                     $cat_id = trim($cat_id);
                     //get the category object
                     $td_tmp_cat_obj = get_category($cat_id);
                     //make the $args
                     if (empty($wp_query_args['category_name'])) {
                         $wp_query_args['category_name'] = $td_tmp_cat_obj->slug;
                         //get by slug (we get the children categories too)
                     } else {
                         $wp_query_args['category_name'] .= ',' . $td_tmp_cat_obj->slug;
                         //get by slug (we get the children categories too)
                     }
                     unset($td_tmp_cat_obj);
                 }
             }
             $wp_query_args['cat'] = get_cat_ID(TD_FEATURED_CAT);
             //add the fetured cat
             break;
         case 'popular':
             $wp_query_args['meta_key'] = td_page_views::$post_view_counter_key;
             $wp_query_args['orderby'] = 'meta_value_num';
             $wp_query_args['order'] = 'DESC';
             break;
         case 'popular7':
             $wp_query_args['meta_key'] = td_page_views::$post_view_counter_7_day_total;
             $wp_query_args['orderby'] = 'meta_value_num';
             $wp_query_args['order'] = 'DESC';
             break;
         case 'review_high':
             $wp_query_args['meta_key'] = td_review::$td_review_key;
             $wp_query_args['orderby'] = 'meta_value_num';
             $wp_query_args['order'] = 'DESC';
             break;
         case 'random_posts':
             $wp_query_args['orderby'] = 'rand';
             break;
         case 'alphabetical_order':
             $wp_query_args['orderby'] = 'title';
             $wp_query_args['order'] = 'ASC';
             break;
         case 'comment_count':
             $wp_query_args['orderby'] = 'comment_count';
             $wp_query_args['order'] = 'DESC';
             break;
         case 'random_today':
             $wp_query_args['orderby'] = 'rand';
             $wp_query_args['year'] = date('Y');
             $wp_query_args['monthnum'] = date('n');
             $wp_query_args['day'] = date('j');
             break;
         case 'random_7_day':
             $wp_query_args['orderby'] = 'rand';
             $wp_query_args['date_query'] = array('column' => 'post_date_gmt', 'after' => '1 week ago');
             break;
     }
     if (!empty($autors_id)) {
         $wp_query_args['author'] = $autors_id;
     }
     //add post_type to query
     if (!empty($installed_post_types)) {
         $array_selected_post_types = array();
         $expl_installed_post_types = explode(',', $installed_post_types);
         foreach ($expl_installed_post_types as $val_this_post_type) {
             if (trim($val_this_post_type) != '') {
                 $array_selected_post_types[] = trim($val_this_post_type);
             }
         }
         $wp_query_args['post_type'] = $array_selected_post_types;
         //$installed_post_types;
     }
     /**
      * the live filters are generated in td_block.php and are added when the block is rendered on the page in the atts of the block
      * @see td_block::add_live_filter_atts
      */
     if (!empty($live_filter)) {
         switch ($live_filter) {
             case 'cur_post_same_tags':
                 $tags = wp_get_post_tags($live_filter_cur_post_id);
                 if ($tags) {
                     $taglist = array();
                     for ($i = 0; $i <= 4; $i++) {
                         if (!empty($tags[$i])) {
                             $taglist[] = $tags[$i]->term_id;
                         } else {
                             break;
                         }
                     }
                     $wp_query_args['tag__in'] = $taglist;
                     $wp_query_args['post__not_in'] = array($live_filter_cur_post_id);
                     //print_r($wp_query_args);
                     //die;
                 }
                 break;
             case 'cur_post_same_author':
                 $wp_query_args['author'] = $live_filter_cur_post_author;
                 $wp_query_args['post__not_in'] = array($live_filter_cur_post_id);
                 break;
             case 'cur_post_same_categories':
                 //print_r($atts);
                 $wp_query_args['category__in'] = wp_get_post_categories($live_filter_cur_post_id);
                 $wp_query_args['post__not_in'] = array($live_filter_cur_post_id);
                 break;
         }
     }
     //only show published posts
     $wp_query_args['post_status'] = 'publish';
     //show only unique posts if that setting is enabled on the template
     /*if (td_unique_posts::$show_only_unique == true) {
           $wp_query_args['post__not_in'] = td_unique_posts::$rendered_posts_ids;
       }*/
     if (td_unique_posts::$unique_articles_enabled == true) {
         $wp_query_args['post__not_in'] = td_unique_posts::$rendered_posts_ids;
     }
     //custom pagination limit
     if (empty($limit)) {
         $limit = get_option('posts_per_page');
     }
     $wp_query_args['posts_per_page'] = $limit;
     //custom pagination
     if (!empty($paged)) {
         $wp_query_args['paged'] = $paged;
     } else {
         $wp_query_args['paged'] = 1;
     }
     // offset + custom pagination - if we have offset, wordpress overwrites the pagination and works with offset + limit
     if (!empty($offset) and $paged > 1) {
         $wp_query_args['offset'] = $offset + ($paged - 1) * $limit;
     } else {
         $wp_query_args['offset'] = $offset;
     }
     //set this variable to pass it to the filter that fixes the pagination on the templates with fake loops. It is not used on blocks because the blocks have custom pagination
     self::$fake_loop_offset = $offset;
     //print_r($wp_query_args);
     return $wp_query_args;
 }
示例#8
0
function td_ajax_search()
{
    $buffy = '';
    $buffy_msg = '';
    //the search string
    if (!empty($_POST['td_string'])) {
        $td_string = $_POST['td_string'];
    } else {
        $td_string = '';
    }
    //get the data
    $td_query =& td_data_source::get_wp_query_search($td_string);
    //by ref  do the query
    //build the results
    if (!empty($td_query->posts)) {
        foreach ($td_query->posts as $post) {
            $td_module_mx2 = new td_module_mx2($post);
            $buffy .= $td_module_mx2->render();
        }
    }
    if (count($td_query->posts) == 0) {
        //no results
        $buffy = '<div class="result-msg no-result">' . __td('No results', TD_THEME_NAME) . '</div>';
    } else {
        //show the resutls
        /**
         * @note:
         * we use esc_url(home_url( '/' )) instead of the WordPress @see get_search_link function because that's what the internal
         * WordPress widget it's using and it was creating duplicate links like: yoursite.com/search/search_query and yoursite.com?s=search_query
         */
        $buffy_msg .= '<div class="result-msg"><a href="' . esc_url(home_url('/?s=' . $td_string)) . '">' . __td('View all results', TD_THEME_NAME) . '</a></div>';
        //add wrap
        $buffy = '<div class="td-aj-search-results">' . $buffy . '</div>' . $buffy_msg;
    }
    //prepare array for ajax
    $buffyArray = array('td_data' => $buffy, 'td_total_results' => 2, 'td_total_in_list' => count($td_query->posts), 'td_search_query' => $td_string);
    // Return the String
    die(json_encode($buffyArray));
}
示例#9
0
        break;
        //sidebar right
    //sidebar right
    default:
        ?>
            <div class="span8 column_container">
                <?php 
        if ((empty($paged) or $paged < 2) and $list_custom_title_show === true) {
            ?>
                    <h4 class="block-title"><span><?php 
            echo $td_list_custom_title;
            ?>
</span></h4>
                <?php 
        }
        query_posts(td_data_source::metabox_to_args($td_homepage_loop_filter, $paged));
        locate_template('loop.php', true);
        echo td_page_generator::get_pagination();
        ?>
            </div>
            <div class="span4 column_container">
                <?php 
        get_sidebar();
        ?>
            </div>
        <?php 
        break;
}
echo '</div>';
//close the .row
echo td_page_generator::wrap_no_row_end();
    function render($atts)
    {
        $this->block_uid = td_global::td_generate_unique_id();
        //update unique id on each render
        //global $post;
        extract(shortcode_atts(array('limit' => 4, 'sort' => '', 'category_id' => '', 'category_ids' => '', 'tag_slug' => '', 'force_columns' => '', 'autoplay' => ''), $atts));
        //echo $atts['limit'];
        //$atts['limit'] = 4;//set 4 to remove the slide
        $buffy = '';
        //output buffer
        $id_slider = '';
        $class_iosSlider = '';
        $this->td_create_slider = 0;
        //if there are more then 4 images then make big grid a slide
        if ($atts['limit'] > 4) {
            $this->td_create_slider = 1;
            $id_slider = 'id="iosSlider_' . $this->block_uid . '"';
            $class_iosSlider = 'iosSlider';
        }
        $buffy .= '<div class="' . $class_iosSlider . ' td_block_wrap td_block_big_grid" ' . $id_slider . '>';
        $buffy .= '<div class="slider td_block_inner" id="' . $this->block_uid . '">';
        //do the query
        $td_query = td_data_source::get_wp_query($atts);
        //by ref  do the query
        //get the js for this block - last parm is block id
        $buffy .= $this->get_block_js($atts, $td_query);
        //$buffy .= '<div class="td_block_wrap td_block_big_grid">';
        //get the sub category filter for this block
        $buffy .= $this->get_block_sub_cats($atts);
        //$buffy .= '<div id=' . $this->block_uid . ' class="td_block_inner">';
        //inner content of the block
        $buffy .= $this->inner($td_query->posts, $force_columns);
        //$buffy .= '</div>';
        //$buffy .= '</div> <!-- ./td_block_big_grid -->';
        $buffy .= '</div>';
        //end slider (if slider)
        if ($this->td_create_slider == 1) {
            $buffy .= '<i class = "td-icon-left"></i>';
            $buffy .= '<i class = "td-icon-right"></i>';
        }
        $buffy .= '</div>';
        //end iosSlider (if slider)
        //close the ios slider wrappers
        if ($this->td_create_slider == 1) {
            //autoplay option for
            $autoplay_string = '';
            if (!empty($autoplay)) {
                $autoplay_string = 'autoSlide: true,
                            autoSlideTimer: ' . $autoplay * 1000 . ',';
            }
            $slide_javascript = '
                    jQuery(document).ready(function() {
                        jQuery("#iosSlider_' . $this->block_uid . '").iosSlider({
                            snapToChildren: true,
                            desktopClickDrag: true,
                            keyboardControls: false,
                            responsiveSlides: true,
                            infiniteSlider: true,
                            ' . $autoplay_string . '
                            navPrevSelector: jQuery("#iosSlider_' . $this->block_uid . ' .td-icon-left"),
                            navNextSelector: jQuery("#iosSlider_' . $this->block_uid . ' .td-icon-right"),
                            onSliderLoaded : td_resize_page_sliders,
		                    onSliderResize : td_resize_big_grid_update_vars_' . $this->block_uid . ',//td_resize_slide,
		                    onSlideChange : td_resize_slide
                        });
                    });


                    /*
                    * Resize the iosSlider when the page is resided (fixes bug on Android devices)
                    * For big grid the code runs on all devices because the big slider changes its height
                    * and we change the td_resize_slide function with this one
                    */
                    function td_resize_big_grid_update_vars_' . $this->block_uid . '(args) {
                        //if(tdDetect.isAndroid) {
                            setTimeout(function(){
                                jQuery("#iosSlider_' . $this->block_uid . '").iosSlider("update");
                            }, 1000);
                        //}
                    }
            ';
            td_js_buffer::add_to_footer($slide_javascript);
        }
        return $buffy;
    }
示例#11
0
 /**
  * converts a pagebuilde array to a wordpress query args array
  * creates the $args array from shortcodes - used by the pagebuilde + widgets + by the metabox_to_args
  * @param string $atts : the shortcode string
  * @param string $paged : page number  /1  or  /2
  * @return array
  */
 static function shortcode_to_args($atts = '', $paged = '')
 {
     //print_r($atts);
     extract(shortcode_atts(array('category_ids' => '', 'category_id' => '', 'tag_slug' => '', 'sort' => '', 'limit' => '', 'autors_id' => '', 'installed_post_types' => '', 'posts_per_page' => '', 'offset' => '', 'live_filter' => '', 'live_filter_cur_post_id' => '', 'live_filter_cur_post_author' => ''), $atts));
     //init the array
     $wp_query_args = array('ignore_sticky_posts' => 1, 'post_status' => 'publish');
     /*  ----------------------------------------------------------------------
             jetpack sorting - this will return here if that's the case because it dosn't work with other filters (it's site wide, no category + this or other combinations)
         */
     if ($sort == 'jetpack_popular_2') {
         if (function_exists('stats_get_csv')) {
             // the damn jetpack api cannot return only posts so it may return pages. That's why we query with a bigger + 5 limit
             // so that if the api returns also 5 pages mixed with the post we will still have the desired number of posts
             $jetpack_api_posts = stats_get_csv('postviews', array('days' => 2, 'limit' => $limit + 5));
             if (!empty($jetpack_api_posts) and is_array($jetpack_api_posts)) {
                 $wp_query_args['post__in'] = wp_list_pluck($jetpack_api_posts, 'post_id');
                 $wp_query_args['posts_per_page'] = $limit;
                 return $wp_query_args;
             }
         }
         return array();
         // empty array makes WP_Query not run
     }
     //the query goes only via $category_ids - for both options ($category_ids and $category_id) also $category_ids overwrites $category_id
     if (!empty($category_id) and empty($category_ids)) {
         $category_ids = $category_id;
     }
     if (!empty($category_ids)) {
         $wp_query_args['cat'] = $category_ids;
     }
     if (!empty($tag_slug)) {
         $wp_query_args['tag'] = str_replace(' ', '-', $tag_slug);
     }
     switch ($sort) {
         case 'featured':
             if (!empty($category_ids)) {
                 //for each category, get the object and compose the slug
                 $cat_id_array = explode(',', $category_ids);
                 foreach ($cat_id_array as &$cat_id) {
                     $cat_id = trim($cat_id);
                     //get the category object
                     $td_tmp_cat_obj = get_category($cat_id);
                     //make the $args
                     if (empty($wp_query_args['category_name'])) {
                         $wp_query_args['category_name'] = $td_tmp_cat_obj->slug;
                         //get by slug (we get the children categories too)
                     } else {
                         $wp_query_args['category_name'] .= ',' . $td_tmp_cat_obj->slug;
                         //get by slug (we get the children categories too)
                     }
                     unset($td_tmp_cat_obj);
                 }
             }
             $wp_query_args['cat'] = get_cat_ID(TD_FEATURED_CAT);
             //add the fetured cat
             break;
         case 'popular':
             $wp_query_args['meta_key'] = td_page_views::$post_view_counter_key;
             $wp_query_args['orderby'] = 'meta_value_num';
             $wp_query_args['order'] = 'DESC';
             break;
         case 'popular7':
             $wp_query_args['meta_key'] = td_page_views::$post_view_counter_7_day_total;
             $wp_query_args['orderby'] = 'meta_value_num';
             $wp_query_args['order'] = 'DESC';
             break;
         case 'review_high':
             $wp_query_args['meta_key'] = td_review::$td_review_key;
             $wp_query_args['orderby'] = 'meta_value_num';
             $wp_query_args['order'] = 'DESC';
             break;
         case 'random_posts':
             $wp_query_args['orderby'] = 'rand';
             break;
         case 'alphabetical_order':
             $wp_query_args['orderby'] = 'title';
             $wp_query_args['order'] = 'ASC';
             break;
         case 'comment_count':
             $wp_query_args['orderby'] = 'comment_count';
             $wp_query_args['order'] = 'DESC';
             break;
         case 'random_today':
             $wp_query_args['orderby'] = 'rand';
             $wp_query_args['year'] = date('Y');
             $wp_query_args['monthnum'] = date('n');
             $wp_query_args['day'] = date('j');
             break;
         case 'random_7_day':
             $wp_query_args['orderby'] = 'rand';
             $wp_query_args['date_query'] = array('column' => 'post_date_gmt', 'after' => '1 week ago');
             break;
     }
     if (!empty($autors_id)) {
         $wp_query_args['author'] = $autors_id;
     }
     //add post_type to query
     if (!empty($installed_post_types)) {
         $array_selected_post_types = array();
         $expl_installed_post_types = explode(',', $installed_post_types);
         foreach ($expl_installed_post_types as $val_this_post_type) {
             if (trim($val_this_post_type) != '') {
                 $array_selected_post_types[] = trim($val_this_post_type);
             }
         }
         $wp_query_args['post_type'] = $array_selected_post_types;
         //$installed_post_types;
     }
     /**
      * the live filters are generated in td_block.php and are added when the block is rendered on the page in the atts of the block
      * @see td_block::add_live_filter_atts
      */
     if (!empty($live_filter)) {
         switch ($live_filter) {
             case 'cur_post_same_tags':
                 $tags = wp_get_post_tags($live_filter_cur_post_id);
                 if ($tags) {
                     $taglist = array();
                     for ($i = 0; $i <= 4; $i++) {
                         if (!empty($tags[$i])) {
                             $taglist[] = $tags[$i]->term_id;
                         } else {
                             break;
                         }
                     }
                     $wp_query_args['tag__in'] = $taglist;
                     $wp_query_args['post__not_in'] = array($live_filter_cur_post_id);
                     //print_r($wp_query_args);
                     //die;
                 }
                 break;
             case 'cur_post_same_author':
                 $wp_query_args['author'] = $live_filter_cur_post_author;
                 $wp_query_args['post__not_in'] = array($live_filter_cur_post_id);
                 break;
             case 'cur_post_same_categories':
                 //print_r($atts);
                 $wp_query_args['category__in'] = wp_get_post_categories($live_filter_cur_post_id);
                 $wp_query_args['post__not_in'] = array($live_filter_cur_post_id);
                 break;
                 // ZA Custom
             // ZA Custom
             case 'cur_post_same_tags_happy':
                 $wp_query_args['tag__in'] = "44";
                 break;
             case 'cur_post_same_tags_funny':
                 $wp_query_args['tag__in'] = "45";
                 break;
             case 'cur_post_same_tags_romantic':
                 $wp_query_args['tag__in'] = "46";
                 break;
             case 'cur_post_same_tags_surprised':
                 $wp_query_args['tag__in'] = "47";
                 break;
             case 'cur_post_same_tags_sad':
                 $wp_query_args['tag__in'] = "48";
                 break;
         }
     }
     //show only unique posts if that setting is enabled on the template
     /*if (td_unique_posts::$show_only_unique == true) {
           $wp_query_args['post__not_in'] = td_unique_posts::$rendered_posts_ids;
       }*/
     if (td_unique_posts::$unique_articles_enabled == true) {
         $wp_query_args['post__not_in'] = td_unique_posts::$rendered_posts_ids;
     }
     //custom pagination limit
     if (empty($limit)) {
         $limit = get_option('posts_per_page');
     }
     $wp_query_args['posts_per_page'] = $limit;
     //custom pagination
     if (!empty($paged)) {
         $wp_query_args['paged'] = $paged;
     } else {
         $wp_query_args['paged'] = 1;
     }
     // offset + custom pagination - if we have offset, wordpress overwrites the pagination and works with offset + limit
     if (!empty($offset) and $paged > 1) {
         $wp_query_args['offset'] = $offset + ($paged - 1) * $limit;
     } else {
         $wp_query_args['offset'] = $offset;
     }
     //set this variable to pass it to the filter that fixes the pagination on the templates with fake loops. It is not used on blocks because the blocks have custom pagination
     self::$fake_loop_offset = $offset;
     //print_r($wp_query_args);
     return $wp_query_args;
 }
示例#12
0
 /**
  * the base render function. This is called by all the child classes of this class
  * this function also ECHOES the block specific css to the buffer (for hover and stuff)
  * WARNING! THIS FUNCTIONS ECHOs THE CSS - it was made to work this way as a hack because the blocks do not get the returned value of render in a buffer
  * @param $atts
  * @return string ''
  */
 function render($atts, $content = null)
 {
     $this->atts = $this->add_live_filter_atts($atts);
     //add live filter atts
     $this->block_uid = td_global::td_generate_unique_id();
     //update unique id on each render
     // This makes sure that the limit is set to the default magic value of 5
     // @todo trebuie refactoriata partea cu limita, in paginatie e hardcodat tot 5 si deja este setat in constructor aici
     if (!isset($this->atts['limit'])) {
         // this should be a general block limit setting defined in global/config file
         $this->atts['limit'] = 5;
     }
     $this->td_query =& td_data_source::get_wp_query($this->atts);
     //by ref do the query
     extract(shortcode_atts(array('td_ajax_filter_type' => '', 'td_ajax_filter_ids' => '', 'td_filter_default_txt' => __td('All', TD_THEME_NAME)), $this->atts));
     // add the visual composer class for the designer option
     // $vc_class = preg_replace( '/\s*\.([^\{]+)\s*\{\s*([^\}]+)\s*\}\s*/', '$1', $css);
     // $this->add_class($vc_class);
     $td_pull_down_items = array();
     // td_block_mega_menu has it's own pull down implementation!
     if (get_class($this) != 'td_block_mega_menu') {
         // prepare the array for the td_pull_down_items, we send this array to the block_template
         if (!empty($td_ajax_filter_type)) {
             // make the default current pull down item (the first one is the default)
             $td_pull_down_items[0] = array('name' => $td_filter_default_txt, 'id' => '');
             switch ($td_ajax_filter_type) {
                 case 'td_category_ids_filter':
                     // by category
                     $td_categories = get_categories(array('include' => $td_ajax_filter_ids, 'exclude' => '1', 'number' => 100));
                     foreach ($td_categories as $td_category) {
                         $td_pull_down_items[] = array('name' => $td_category->name, 'id' => $td_category->cat_ID);
                     }
                     break;
                 case 'td_author_ids_filter':
                     // by author
                     $td_authors = get_users(array('who' => 'authors', 'include' => $td_ajax_filter_ids));
                     foreach ($td_authors as $td_author) {
                         $td_pull_down_items[] = array('name' => $td_author->display_name, 'id' => $td_author->ID);
                     }
                     break;
                 case 'td_tag_slug_filter':
                     // by tag slug
                     $td_tags = get_tags(array('include' => $td_ajax_filter_ids));
                     foreach ($td_tags as $td_tag) {
                         $td_pull_down_items[] = array('name' => $td_tag->name, 'id' => $td_tag->term_id);
                     }
                     break;
                 case 'td_popularity_filter_fa':
                     // by popularity
                     $td_pull_down_items[] = array('name' => __td('Featured', TD_THEME_NAME), 'id' => 'featured');
                     $td_pull_down_items[] = array('name' => __td('All time popular', TD_THEME_NAME), 'id' => 'popular');
                     break;
             }
         }
     }
     // add a persistent atts based block class (crc32 of atts + block_id)
     if (is_array($this->atts)) {
         // double check to prevent warnings if no atts
         $this->add_class('td_block_id_' . sanitize_html_class(str_replace('-', '', crc32(implode($this->atts) . $this->block_id))));
     }
     // add a unique class to the block
     $unique_block_class = $this->block_uid . '_rand';
     $this->add_class($unique_block_class);
     /**
      * Make a new block template instance (NOTE: ON EACH RENDER WE GENERATE A NEW BLOCK TEMPLATE)
      * td_block_template_x - Loaded via autoload
      * @see td_autoload_classes::loading_classes
      */
     $td_block_template_id = 'td_block_template_1';
     $this->td_block_template_data = array('atts' => $this->atts, 'block_uid' => $this->block_uid, 'unique_block_class' => $unique_block_class, 'td_pull_down_items' => $td_pull_down_items);
     $this->td_block_template_instance = new $td_block_template_id($this->td_block_template_data);
     // echo the default style of the block
     echo $this->block_template()->get_css();
     return '';
 }