class-affiliate.php
5 years ago
class-polylang.php
5 years ago
class-review-box.php
5 years ago
class-wpml.php
5 years ago
folders.class.php
5 years ago
form.class.php
5 years ago
plugin.updates.php
5 years ago
tree.class.php
5 years ago
tree.class.php
172 lines
| 1 | <?php |
| 2 | if(!defined('ABSPATH')) exit; |
| 3 | class WCP_Tree { |
| 4 | |
| 5 | public function __construct() { |
| 6 | |
| 7 | } |
| 8 | |
| 9 | public static function get_full_tree_data($post_type, $order_by = "", $order = "") { |
| 10 | $isAjax = (defined('DOING_AJAX') && DOING_AJAX)?1:0; |
| 11 | $type = filter_input(INPUT_GET, $post_type, FILTER_SANITIZE_STRING); |
| 12 | if((isset($type) && !empty($type)) || ! $isAjax) { |
| 13 | update_option("selected_" . $post_type . "_folder", ""); |
| 14 | } |
| 15 | return self::get_folder_category_data($post_type, 0, 0, $order_by, $order); |
| 16 | } |
| 17 | |
| 18 | public static function get_folder_category_data($post_type, $parent = 0, $parentStatus = 0, $order_by = "", $order = "") { |
| 19 | |
| 20 | $arg = array( |
| 21 | 'hide_empty' => false, |
| 22 | 'parent' => $parent, |
| 23 | 'hierarchical' => false, |
| 24 | 'update_count_callback' => '_update_generic_term_count', |
| 25 | ); |
| 26 | if(!empty($order_by) && !empty($order)) { |
| 27 | $arg['orderby'] = $order_by; |
| 28 | $arg['order'] = $order; |
| 29 | } else { |
| 30 | $arg['orderby'] = 'meta_value_num'; |
| 31 | $arg['order'] = 'ASC'; |
| 32 | $arg['meta_query'] = [[ |
| 33 | 'key' => 'wcp_custom_order', |
| 34 | 'type' => 'NUMERIC', |
| 35 | ]]; |
| 36 | } |
| 37 | |
| 38 | $terms = get_terms( $post_type, $arg); |
| 39 | |
| 40 | $string = ""; |
| 41 | $sticky_string = ""; |
| 42 | $child = 0; |
| 43 | $isAjax = (defined('DOING_AJAX') && DOING_AJAX)?1:0; |
| 44 | if(!empty($terms)) { |
| 45 | $child = count($terms); |
| 46 | foreach($terms as $key=>$term) { |
| 47 | |
| 48 | if(!empty($order_by) && !empty($order)) { |
| 49 | update_term_meta($term->term_id, "wcp_custom_order", ($key+1)); |
| 50 | } |
| 51 | |
| 52 | $is_sticky = get_term_meta($term->term_id, "is_folder_sticky", true); |
| 53 | |
| 54 | $status = get_term_meta($term->term_id, "is_active", true); |
| 55 | $return = self::get_folder_category_data($post_type, $term->term_id, $status, $order_by, $order); |
| 56 | $class = ($status == 1 && $return['child']>0)?"active":""; |
| 57 | $class .= ($return['child'])>0?" has-sub-tree":""; |
| 58 | $term_var = filter_input(INPUT_GET, "term", FILTER_SANITIZE_STRING); |
| 59 | $type = filter_input(INPUT_GET, $post_type, FILTER_SANITIZE_STRING); |
| 60 | if($post_type == "attachment") { |
| 61 | $class .= (isset($term_var) && $term_var == $term->slug)?" active-item active-term":""; |
| 62 | if(isset($type) && $type == $term->slug) { |
| 63 | update_option("selected_".$post_type."_folder", $term->term_id); |
| 64 | } |
| 65 | if(!isset($type) && $isAjax) { |
| 66 | $termId = get_option("selected_".$post_type."_folder"); |
| 67 | $class .= ($termId == $term->term_id)?" active-item active-term":""; |
| 68 | } |
| 69 | } else { |
| 70 | $class .= (isset($type) && $type == $term->slug)?" active-item active-term":""; |
| 71 | if(isset($type) && $type == $term->slug) { |
| 72 | update_option("selected_" . $post_type . "_folder", $term->term_id); |
| 73 | } |
| 74 | if(!isset($type) && $isAjax) { |
| 75 | $termId = get_option("selected_".$post_type."_folder"); |
| 76 | $class .= ($termId == $term->term_id)?" active-item active-term":""; |
| 77 | } |
| 78 | } |
| 79 | $status = get_term_meta($term->term_id, "is_highlighted", true); |
| 80 | $class .= ($status == 1)?" is-high":""; |
| 81 | $sticky_class = ($status == 1)?"is-high":""; |
| 82 | $count = ($term->trash_count != 0)?$term->trash_count:0; |
| 83 | if($is_sticky == 1) { |
| 84 | $class .= " is-sticky"; |
| 85 | } |
| 86 | |
| 87 | $count_sticky = ($term->trash_count != 0)?"<span class='folder-count'>{$term->trash_count}</span>":""; |
| 88 | |
| 89 | if($is_sticky == 1) { |
| 90 | //$sticky_string .= "<li data-folder-id='{$term->term_id}' class='sticky-fldr {$sticky_class} sticky-folder-{$term->term_id}'><a href='javascript:;'><span class='folder-title'>{$term->name}</span>{$count_sticky}<span class='update-inline-record'><i class='pfolder-edit-folder'></i></span><span class='star-icon'><i class='pfolder-star'></i></span></a></li>"; |
| 91 | } |
| 92 | |
| 93 | /* Free/Pro URL Change*/ |
| 94 | // $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 wcp_folder_{$term->term_id} {$class}' id='wcp_folder_{$term->term_id}' data-folder-id='{$term->term_id}'>"; |
| 95 | // $string .= "<h3 class='title' title='{$term->name}' id='title_{$term->term_id}'>"; |
| 96 | // $string .= "<span class='ui-icon'>"; |
| 97 | // $string .= "<i class='wcp-icon pfolder-folder-close'></i>"; |
| 98 | // $string .= "<input type='checkbox' class='checkbox' value='{$term->term_id}' />"; |
| 99 | // $string .= "</span>"; |
| 100 | // $string .= "<span class='title-text'>{$term->name}</span>"; |
| 101 | // $string .= "{$count} <span class='update-inline-record'><i class='pfolder-edit-folder'></i></span> <span class='star-icon'><i class='pfolder-star'></i></span>"; |
| 102 | // $string .= "<span class='folder-sticky-icon'><i class='pfolder-pin'></i></span>"; |
| 103 | // //$string .= "<span class='move-folder-icon' ><i class='pfolder-move'></i></span>"; |
| 104 | // $string .= "</h3>"; |
| 105 | // $string .= "<span class='nav-icon'><i class='wcp-icon pfolder-arrow-down'></i></span>"; |
| 106 | // $string .= "<ul class='space' id='space_{$term->term_id}'>"; |
| 107 | // $string .= $return['string']; |
| 108 | // $string .= "</ul></li>"; |
| 109 | |
| 110 | // $parent = (empty($parent))?"#":$parent; |
| 111 | $nonce = wp_create_nonce('wcp_folder_term_'.$term->term_id); |
| 112 | $is_sticky = get_term_meta($term->term_id, "is_folder_sticky", true); |
| 113 | $status = get_term_meta($term->term_id, "is_highlighted", true); |
| 114 | $is_active = get_term_meta($term->term_id, "is_active", true); |
| 115 | $class = ""; |
| 116 | if($is_sticky == 1) { |
| 117 | $class .= " is-sticky"; |
| 118 | } |
| 119 | if($status == 1) { |
| 120 | $class .= " is-high"; |
| 121 | } |
| 122 | if($is_active == 1) { |
| 123 | $class .= " jstree-open"; |
| 124 | } |
| 125 | |
| 126 | $string .= "<li id='{$term->term_id}' class='{$class}' data-slug='{$term->slug}' data-nonce='{$nonce}' data-folder='{$term->term_id}' data-child='{$child}' data-count='{$count}' data-parent='{$parent}'> |
| 127 | {$term->name} |
| 128 | <ul>{$return['string']}</ul> |
| 129 | </li>"; |
| 130 | |
| 131 | $sticky_string .= $return['sticky_string']; |
| 132 | } |
| 133 | } |
| 134 | return array( |
| 135 | 'string' =>$string, |
| 136 | 'sticky_string' =>$sticky_string, |
| 137 | 'child' => $child |
| 138 | ); |
| 139 | } |
| 140 | |
| 141 | public static function get_option_data_for_select($post_type) { |
| 142 | $string = "<option value='0'>Parent Folder</option>"; |
| 143 | $string .= self::get_folder_option_data($post_type, 0, ''); |
| 144 | return $string; |
| 145 | } |
| 146 | |
| 147 | public static function get_folder_option_data($post_type, $parent = 0, $space = "") { |
| 148 | $terms = get_terms( $post_type, array( |
| 149 | 'hide_empty' => false, |
| 150 | 'parent' => $parent, |
| 151 | 'orderby' => 'meta_value_num', |
| 152 | 'order' => 'ASC', |
| 153 | 'hierarchical' => false, |
| 154 | 'meta_query' => [[ |
| 155 | 'key' => 'wcp_custom_order', |
| 156 | 'type' => 'NUMERIC', |
| 157 | ]] |
| 158 | ) ); |
| 159 | |
| 160 | $selected_term = get_option("selected_" . $post_type . "_folder"); |
| 161 | |
| 162 | $string = ""; |
| 163 | if(!empty($terms)) { |
| 164 | foreach($terms as $term) { |
| 165 | $selected = ($selected_term == $term->term_id)?"selected":""; |
| 166 | $string .= "<option {$selected} value='{$term->term_id}'>{$space}{$term->name}</option>"; |
| 167 | $string .= self::get_folder_option_data($post_type, $term->term_id, trim($space)."- "); |
| 168 | } |
| 169 | } |
| 170 | return $string; |
| 171 | } |
| 172 | } |