class-affiliate.php
6 years ago
folders.class.php
6 years ago
form.class.php
6 years ago
plugin.updates.php
6 years ago
tree.class.php
6 years ago
tree.class.php
113 lines
| 1 | <?php |
| 2 | defined('ABSPATH') or die('Nope, not accessing this'); |
| 3 | class WCP_Tree { |
| 4 | public function __construct() { |
| 5 | parent::__construct(); |
| 6 | } |
| 7 | |
| 8 | public static function get_full_tree_data($post_type) { |
| 9 | $isAjax = (defined('DOING_AJAX') && DOING_AJAX)?1:0; |
| 10 | $type = filter_input(INPUT_GET, $post_type, FILTER_SANITIZE_STRING); |
| 11 | if((isset($type) && !empty($type)) || ! $isAjax) { |
| 12 | update_option("selected_" . $post_type . "_folder", ""); |
| 13 | } |
| 14 | $string = self::get_folder_category_data($post_type, 0, 0); |
| 15 | return $string['string']; |
| 16 | } |
| 17 | |
| 18 | public static function get_folder_category_data($post_type, $parent = 0, $parentStatus = 0) { |
| 19 | // echo "<pre>"; print_r($post_type); die; |
| 20 | $terms = get_terms( $post_type, array( |
| 21 | 'hide_empty' => false, |
| 22 | 'parent' => $parent, |
| 23 | 'orderby' => 'meta_value_num', |
| 24 | 'order' => 'ASC', |
| 25 | 'hierarchical' => false, |
| 26 | 'update_count_callback' => '_update_generic_term_count', |
| 27 | 'meta_query' => [[ |
| 28 | 'key' => 'wcp_custom_order', |
| 29 | 'type' => 'NUMERIC', |
| 30 | ]] |
| 31 | )); |
| 32 | $string = ""; |
| 33 | $child = 0; |
| 34 | $isAjax = (defined('DOING_AJAX') && DOING_AJAX)?1:0; |
| 35 | if(!empty($terms)) { |
| 36 | $child = count($terms); |
| 37 | foreach($terms as $term) { |
| 38 | $status = get_term_meta($term->term_id, "is_active", true); |
| 39 | $return = self::get_folder_category_data($post_type, $term->term_id, $status); |
| 40 | $class = ($status == 1 && $return['child']>0)?"active":""; |
| 41 | $class .= ($return['child'])>0?" has-sub-tree":""; |
| 42 | $term_var = filter_input(INPUT_GET, "term", FILTER_SANITIZE_STRING); |
| 43 | $type = filter_input(INPUT_GET, $post_type, FILTER_SANITIZE_STRING); |
| 44 | if($post_type == "attachment") { |
| 45 | $class .= (isset($term_var) && $term_var == $term->slug)?" active-item active-term":""; |
| 46 | if(isset($type) && $type == $term->slug) { |
| 47 | update_option("selected_".$post_type."_folder", $term->term_id); |
| 48 | } |
| 49 | if(!isset($type) && $isAjax) { |
| 50 | $termId = get_option("selected_".$post_type."_folder"); |
| 51 | $class .= ($termId == $term->term_id)?" active-item active-term":""; |
| 52 | } |
| 53 | } else { |
| 54 | $class .= (isset($type) && $type == $term->slug)?" active-item active-term":""; |
| 55 | if(isset($type) && $type == $term->slug) { |
| 56 | update_option("selected_" . $post_type . "_folder", $term->term_id); |
| 57 | } |
| 58 | if(!isset($type) && $isAjax) { |
| 59 | $termId = get_option("selected_".$post_type."_folder"); |
| 60 | $class .= ($termId == $term->term_id)?" active-item active-term":""; |
| 61 | } |
| 62 | } |
| 63 | $status = get_term_meta($term->term_id, "is_highlighted", true); |
| 64 | $class .= ($status == 1)?" is-high":""; |
| 65 | $count = ($term->count != 0)?"<span class='total-count'>{$term->count}</span>":""; |
| 66 | $delete_nonce = wp_create_nonce('wcp_folder_delete_term_'.$term->term_id); |
| 67 | $rename_nonce = wp_create_nonce('wcp_folder_rename_term_'.$term->term_id); |
| 68 | $highlight_nonce = wp_create_nonce('wcp_folder_highlight_term_'.$term->term_id); |
| 69 | $term_nonce = wp_create_nonce('wcp_folder_term_'.$term->term_id); |
| 70 | $string .= "<li data-nonce='{$term_nonce}' data-star='{$highlight_nonce}' data-rename='{$rename_nonce}' data-delete='{$delete_nonce}' data-slug='{$term->slug}' class='ui-state-default route {$class}' id='wcp_folder_{$term->term_id}' data-folder-id='{$term->term_id}'><h3 class='title' title='{$term->name}' id='title_{$term->term_id}'><span class='ui-icon'><i class='wcp-icon folder-icon-folder'></i><img src='".esc_url(WCP_FOLDER_URL."assets/images/move-option.png")."' class='move-folder-icon' ></span><span class='title-text'>{$term->name}</span> <span class='update-inline-record'></span> {$count} <span class='star-icon'></span></h3><span class='nav-icon'><i class='wcp-icon folder-icon-arrow_right'></i></span> <ul class='space' id='space_{$term->term_id}'>"; |
| 71 | $string .= $return['string']; |
| 72 | $string .= "</ul></li>"; |
| 73 | } |
| 74 | } |
| 75 | return array( |
| 76 | 'string' =>$string, |
| 77 | 'child' => $child |
| 78 | ); |
| 79 | } |
| 80 | |
| 81 | public static function get_option_data_for_select($post_type) { |
| 82 | $string = "<option value='0'>Parent Folder</option>"; |
| 83 | $string .= self::get_folder_option_data($post_type, 0, ' '); |
| 84 | return $string; |
| 85 | } |
| 86 | |
| 87 | public static function get_folder_option_data($post_type, $parent = 0, $space = "") { |
| 88 | $terms = get_terms( $post_type, array( |
| 89 | 'hide_empty' => false, |
| 90 | 'parent' => $parent, |
| 91 | 'orderby' => 'meta_value_num', |
| 92 | 'order' => 'ASC', |
| 93 | 'hierarchical' => false, |
| 94 | 'meta_query' => [[ |
| 95 | 'key' => 'wcp_custom_order', |
| 96 | 'type' => 'NUMERIC', |
| 97 | ]] |
| 98 | ) ); |
| 99 | |
| 100 | $selected_term = get_option("selected_" . $post_type . "_folder"); |
| 101 | |
| 102 | |
| 103 | $string = ""; |
| 104 | if(!empty($terms)) { |
| 105 | foreach($terms as $term) { |
| 106 | $selected = ($selected_term == $term->term_id)?"selected":""; |
| 107 | $string .= "<option {$selected} value='{$term->term_id}'>{$space}{$term->name}</option>"; |
| 108 | $string .= self::get_folder_option_data($post_type, $term->term_id, $space."  "); |
| 109 | } |
| 110 | } |
| 111 | return $string; |
| 112 | } |
| 113 | } |