/** * @version $Id$ * @package ZF WordPress Category Accordion * @author ZuFusion * @copyright Copyright (C) 2014 ZuFusion All Rights Reserved. * @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html */ function zf_catetegory_accordion_shortcode($atts, $content = null) { global $zfwca; extract(shortcode_atts(array('title' => '', 'speed' => 'slow', 'event_type' => 'click', 'arrow_alignment' => 'right', 'color_scheme' => 'dark', 'category_type' => 'category', 'order_by' => 'name', 'order' => 'asc', 'exclude' => '', 'include' => '', 'open_default' => '', 'limit' => '', 'show_count' => 'false', 'hide_empty' => false, 'allow_parent_links' => 'true', 'toggle' => 'false'), $atts)); $shortcode_id = 'zfwac_shortcode_' . rand(1, 10000); $show_count = $show_count == 'true' ? '1' : '0'; $speed = is_numeric($speed) ? (int) $speed : '"' . $speed . '"'; $configs = array('show_count' => $show_count, 'hide_empty' => $hide_empty, 'exclude' => $exclude, 'include' => $include, 'orderby' => $order_by, 'order' => $order, 'number' => $limit, 'taxonomy' => $category_type); $title = empty($title) ? '' : apply_filters('zfwca_title', $title); $current_cats = ''; $open_ids = ''; if ($open_default != '') { $open_default = wp_parse_id_list($open_default); if (!empty($open_default)) { $open_default = array_unique($open_default); $open_ids = implode(',', $open_default); } } $current_arr = zfwca_get_current_terms($category_type); if (!empty($current_arr)) { $current_arr = array_unique($current_arr); $current_cats = implode(',', $current_arr); } $html = ''; $content = zfwca_get_theme_content($color_scheme); if (!empty($content)) { $html = '<style id="style-' . $shortcode_id . '">'; $html .= str_replace('.zfc-accordion', '#' . $shortcode_id, $content); $html .= '</style>'; } if (!empty($title)) { $html .= '<h3>' . $title . '</h3>'; } if ($configs['taxonomy'] != 'page') { if (!taxonomy_exists($configs['taxonomy'])) { echo __('Category type does not exist or it has not actived yet, you need to check it again'); return; } } $html .= '<div id="' . $shortcode_id . '" class="zfc-accordion">'; $html .= '<ul class="zfc-' . $arrow_alignment . '">'; if ($configs['taxonomy'] != 'page') { $html .= zfwca_list_categories($configs); } else { $html .= zfwca_list_pages($configs); } $html .= '</ul>'; $html .= '</div>'; ob_start(); ?> <script type="text/javascript"> /* <![CDATA[ */ (function ($) { $('#<?php echo $shortcode_id; ?> ').ZFCAccordion({ eventType: '<?php echo $event_type; ?> ', speed: <?php echo $speed; ?> , allowParentLinks: <?php echo $allow_parent_links; ?> , toggle: <?php echo $toggle; ?> , openIDs: '<?php echo $open_ids; ?> ', currentCats: '<?php echo $current_cats; ?> ' }); })(jQuery); /* ]]> */ </script> <?php $js = ob_get_clean(); $zfwca->add_footer_extra($js); return $html; }
public function widget($args, $instance) { global $zfwca; extract($args, EXTR_SKIP); $speed = $instance['speed']; $speed = is_numeric($speed) ? (int) $speed : '"' . $speed . '"'; $show_count = !empty($instance['show_count']) ? '1' : '0'; $hide_empty = !empty($instance['hide_empty']) ? true : false; $allow_parent_links = !empty($instance['allow_parent_links']) ? 'true' : 'false'; $ripple_effect = !empty($instance['ripple_effect']) ? 'true' : 'false'; $toggle = !empty($instance['toggle']) ? 'true' : 'false'; $orderby = empty($instance['orderby']) ? 'name' : $instance['orderby']; $order = empty($instance['order']) ? 'asc' : $instance['order']; $exclude = empty($instance['exclude']) ? '' : $instance['exclude']; $include = empty($instance['include']) ? '' : $instance['include']; $limit_categories = empty($instance['number']) ? '' : $instance['number']; $cat_type = empty($instance['cat_type']) ? 'category' : $instance['cat_type']; $theme = empty($instance['theme']) ? '' : $instance['theme']; $event_type = empty($instance['event_type']) ? 'click' : $instance['event_type']; $arrow_alignment = empty($instance['arrow_alignment']) ? 'right' : $instance['arrow_alignment']; $open_default = empty($instance['open_default']) ? '' : $instance['open_default']; $current_cats = ''; $open_ids = ''; if ($open_default != '') { $open_default = wp_parse_id_list($open_default); if (!empty($open_default)) { $open_default = array_unique($open_default); $open_ids = implode(',', $open_default); } } $current_arr = zfwca_get_current_terms($cat_type); if (!empty($current_arr)) { $current_arr = array_unique($current_arr); $current_cats = implode(',', $current_arr); } $content = zfwca_get_theme_content($theme); if (!empty($content)) { $style = '<style id="style-zfc-accordion-' . $this->id . '">'; $style .= str_replace('.zfc-accordion', '#zfc-accordion-' . $this->id, $content); $style .= '</style>'; echo $style; } $configs = array('show_count' => $show_count, 'hide_empty' => $hide_empty, 'exclude' => $exclude, 'include' => $include, 'orderby' => $orderby, 'order' => $order, 'number' => $limit_categories, 'taxonomy' => $cat_type); echo $before_widget; $title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']); if (!empty($title)) { echo $before_title . $title . $after_title; } if ($configs['taxonomy'] != 'page') { if (!taxonomy_exists($configs['taxonomy'])) { echo __('Category type does not exist or it has not actived yet, you need to check it again'); return; } } ?> <div id="zfc-accordion-<?php echo $this->id; ?> " class="zfc-accordion"> <ul class="<?php echo 'zfc-' . $arrow_alignment; ?> "> <?php if ($configs['taxonomy'] != 'page') { echo zfwca_list_categories($configs); } else { echo zfwca_list_pages($configs); } ?> </ul> </div> <?php ob_start(); ?> <script type="text/javascript"> /* <![CDATA[ */ (function ($) { $('#zfc-accordion-<?php echo $this->id; ?> ').ZFCAccordion({ eventType: '<?php echo $event_type; ?> ', speed: <?php echo $speed; ?> , allowParentLinks: <?php echo $allow_parent_links; ?> , rippleEffect: <?php echo $ripple_effect; ?> , toggle: <?php echo $toggle; ?> , openIDs: '<?php echo $open_ids; ?> ', currentCats: '<?php echo $current_cats; ?> ' }); })(jQuery); /* ]]> */ </script> <?php $js = ob_get_clean(); $zfwca->add_footer_extra($js); echo $after_widget; }