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; }
/** * 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 ''; }
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; }
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; }
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; }
function td_ajax_block() { //get the data from ajax() call $td_atts = ''; //original block atts $td_column_number = 0; //should not be 0 (1 - 2 - 3) $td_current_page = 1; //the current page of the block $td_block_id = ''; //block uid $block_type = ''; //the type of the block? /** * ajax magic filtering works like this: * * each block has a js object generated by it that is hardcoded in the page @see td_block::get_block_js * * 1. ($_POST[td_atts]) -> $td_atts['td_ajax_filter_type'] - the ajax filter type is hardcoded in the block's javascript object in the td_atts variable $td_atts['td_ajax_filter_type'] * 2. $_POST['td_filter_value'] - the filter value td_filter_value is sent via post $_POST['td_filter_value'] * 3. $_POST['td_filter_value'] - overwrites the blocks default filters ! * 4. live_filter - is hardcoded in block's js object or changed by the code here. live_filter's are used to filter content based on current page's author/tags/categories etc */ /** * this is retrieved by js from the data-td_filter_value="" attribute of the link that the user has clicked @see td_block::generate_pull_down */ $td_filter_value = ''; /** * this is used to change the new ui filter into focus when the ajax replies ( when a user clicks on 'popular', 'popular' will have this id and it will be put into focus via javascript) */ $td_filter_ui_uid = ''; if (!empty($_POST['td_atts'])) { $td_atts = json_decode(stripslashes($_POST['td_atts']), true); //current block args } if (!empty($_POST['td_column_number'])) { $td_column_number = $_POST['td_column_number']; //the block is on x columns } if (!empty($_POST['td_current_page'])) { $td_current_page = $_POST['td_current_page']; } if (!empty($_POST['td_block_id'])) { $td_block_id = $_POST['td_block_id']; } if (!empty($_POST['block_type'])) { $block_type = $_POST['block_type']; } //read the id for this specific filter type if (!empty($_POST['td_filter_value'])) { $td_filter_value = $_POST['td_filter_value']; //the new id filter } //the clicked filter ui UID from the list if (!empty($_POST['td_filter_ui_uid'])) { $td_filter_ui_uid = $_POST['td_filter_ui_uid']; //the new id filter } /* * HANDLES THE PULL DOWN FILTER + TABS ON RELATED POSTS * read the block atts - td filter type and overwrite the default values at runtime! (ex: the user changed the category from the dropbox, we overwrite the static default category of the block) */ if (!empty($td_atts['td_ajax_filter_type'])) { //dynamic filtering switch ($td_atts['td_ajax_filter_type']) { case 'td_category_ids_filter': // by category - the user selected a category from the drop down. if it's empty, we show the default block atts if (!empty($td_filter_value)) { $td_atts['category_ids'] = $td_filter_value; unset($td_atts['category_id']); } break; case 'td_author_ids_filter': // by author if (!empty($td_filter_value)) { $td_atts['autors_id'] = $td_filter_value; } break; case 'td_tag_slug_filter': // by tag - due to wp query and for combining the tags with categories we have to convert tag_ids to tag_slugs if (!empty($td_filter_value)) { $term_obj = get_term($td_filter_value, 'post_tag'); $td_atts['tag_slug'] = $term_obj->slug; } break; case 'td_popularity_filter_fa': // by popularity (sort) if (!empty($td_filter_value)) { $td_atts['sort'] = $td_filter_value; } break; /** * used by the related posts block * - if $td_atts['td_ajax_filter_type'] == td_custom_related ( this is hardcoded in the block atts @see td_module_single.php:764) * - overwrite the live_filter for this block - ( the default live_filter is also hardcoded in the block atts @see td_module_single.php:764) * the default live_filter for this block is: 'live_filter' => 'cur_post_same_categories' * @var $td_filter_value comes via ajax */ /** * used by the related posts block * - if $td_atts['td_ajax_filter_type'] == td_custom_related ( this is hardcoded in the block atts @see td_module_single.php:764) * - overwrite the live_filter for this block - ( the default live_filter is also hardcoded in the block atts @see td_module_single.php:764) * the default live_filter for this block is: 'live_filter' => 'cur_post_same_categories' * @var $td_filter_value comes via ajax */ case 'td_custom_related': if ($td_filter_value == 'td_related_more_from_author') { $td_atts['live_filter'] = 'cur_post_same_author'; // change the live filter for the related posts } break; } } //file_put_contents('d:\filename.txt', print_r($_POST, true)); $td_query =& td_data_source::get_wp_query($td_atts, $td_current_page); //by ref do the query $buffy = ''; $buffy .= td_global_blocks::get_instance($block_type)->inner($td_query->posts, $td_column_number, '', true); //pagination $td_hide_prev = false; $td_hide_next = false; if ($td_current_page == 1) { $td_hide_prev = true; //hide link on page 1 } if (!empty($td_atts['offset']) && !empty($td_atts['limit']) && $td_atts['limit'] != 0) { if ($td_current_page >= ceil(($td_query->found_posts - $td_atts['offset']) / $td_atts['limit'])) { $td_hide_next = true; //hide link on last page } } else { if ($td_current_page >= $td_query->max_num_pages) { $td_hide_next = true; //hide link on last page } } // if ($td_current_page >= $td_query->max_num_pages ) { // $td_hide_next = true; //hide link on last page // } $buffyArray = array('td_data' => $buffy, 'td_block_id' => $td_block_id, 'td_hide_prev' => $td_hide_prev, 'td_hide_next' => $td_hide_next, 'td_filter_ui_uid' => $td_filter_ui_uid); // Return the String die(json_encode($buffyArray)); }
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; }
function td_ajax_loop() { $loopState = td_util::get_http_post_val('loopState'); //print_r($loopState); $buffy = ''; /** * @var WP_Query */ $td_query =& td_data_source::get_wp_query($loopState['atts'], $loopState['currentPage']); //by ref do the query if (!empty($td_query->posts)) { td_global::$is_wordpress_loop = true; ///if we are in wordpress loop; used by quotes in blocks to check if the blocks are displayed in blocks or in loop $td_template_layout = new td_template_layout($loopState['sidebarPosition']); $td_module_class = td_util::get_module_class_from_loop_id($loopState['moduleId']); //disable the grid for some of the modules $td_module_api = td_api_module::get_by_id($td_module_class); if ($td_module_api['uses_columns'] === false) { $td_template_layout->disable_output(); } foreach ($td_query->posts as $post) { $buffy .= $td_template_layout->layout_open_element(); if (class_exists($td_module_class)) { $td_mod = new $td_module_class($post); $buffy .= $td_mod->render(); } else { td_util::error(__FILE__, 'Missing module: ' . $td_module_class); } $buffy .= $td_template_layout->layout_close_element(); $td_template_layout->layout_next(); } $buffy .= $td_template_layout->close_all_tags(); } else { // no posts } $loopState['server_reply_html_data'] = $buffy; die(json_encode($loopState)); }
/** * 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 ''; }
function td_ajax_block() { global $post; //get the data from ajax() call if (!empty($_POST['td_atts'])) { $td_atts = json_decode(stripslashes($_POST['td_atts']), true); //current block args } else { $td_atts = ''; //not ok } if (!empty($_POST['td_cur_cat'])) { $td_cur_cat = $_POST['td_cur_cat']; //the new id filter } else { $td_cur_cat = ''; } if (!empty($_POST['td_column_number'])) { $td_column_number = $_POST['td_column_number']; //the block is on x columns } else { $td_column_number = 0; //not ok } if (!empty($_POST['td_current_page'])) { $td_current_page = $_POST['td_current_page']; } else { $td_current_page = 1; } if (!empty($td_cur_cat)) { $td_atts['category_ids'] = $td_cur_cat; unset($td_atts['category_id']); } if (!empty($_POST['td_block_id'])) { $td_block_id = $_POST['td_block_id']; } else { $td_block_id = ''; //not ok } if (!empty($_POST['block_type'])) { $block_type = $_POST['block_type']; } else { $block_type = ''; } $td_query =& td_data_source::get_wp_query($td_atts, $td_current_page); //by ref do the query $buffy = ''; $buffy .= td_global_blocks::get_instance($block_type)->inner($td_query->posts, $td_column_number, '', true); //pagination $td_hide_prev = false; $td_hide_next = false; if ($td_current_page == 1) { $td_hide_prev = true; //hide link on page 1 } if ($td_current_page >= $td_query->max_num_pages) { $td_hide_next = true; //hide link on last page } $buffyArray = array('td_data' => $buffy, 'td_block_id' => $td_block_id, 'td_cur_cat' => $td_cur_cat, 'td_hide_prev' => $td_hide_prev, 'td_hide_next' => $td_hide_next); // Return the String die(json_encode($buffyArray)); }