function bbconnect_work_queues_page() { bbconnect_admin_scripts(); // Enqueue CRM styles echo '<div class="wrap">' . "\n"; $selected_queue = isset($_GET['queue_id']) ? $_GET['queue_id'] : null; $queue_name = ''; $available_types = array(); $all_notes = bbconnect_workqueues_get_action_items(); foreach ($all_notes as $note) { $note_types = wp_get_post_terms($note->ID, 'bb_note_type'); foreach ($note_types as $note_type) { if ($note_type->parent > 0) { $available_types[$note_type->term_id]['name'] = $note_type->name; $available_types[$note_type->term_id]['notes'][] = $note; break; } } } echo '<div class="options-row">' . "\n"; echo '<h2>Work Queues <a class="add-new-h2" href="/edit-tags.php?taxonomy=bb_note_type&post_type=bb_note">Add New</a></h2>' . "\n"; echo '<select name="queue_id" id="queue_id">' . "\n"; echo '<option value="">Please Select</option>' . "\n"; foreach ($available_types as $term_id => $details) { if ($selected_queue == $term_id) { $queue_name = $details['name']; } echo '<option value="' . $term_id . '" ' . selected($selected_queue, $term_id) . '>' . $details['name'] . '</option>' . "\n"; } echo '</select>' . "\n"; if (!empty($selected_queue)) { $contacts = array(); $note_ids = array(); foreach ($available_types[$selected_queue]['notes'] as $note) { $note_user = get_userdata($note->post_author); $contacts[$note->post_author] = $note_user; $groups[$note_user->display_name . ' (' . $note_user->user_email . ')'][] = $note; $note_ids[] = $note->ID; } echo '</div>' . "\n"; bbconnect_workqueues_output_action_items($groups); } echo '</div>' . "\n"; ?> <script type="text/javascript"> jQuery('#queue_id').on('change', function() { window.location.href = '/wp-admin/users.php?page=work_queues_submenu&queue_id='+jQuery(this).val(); }); </script> <?php }
function bbconnect_user_work_queues() { $args = array('author' => $_GET['user_id']); $notes = bbconnect_workqueues_get_action_items($args); $groups = array(); foreach ($notes as $note) { $note_types = wp_get_post_terms($note->ID, 'bb_note_type'); foreach ($note_types as $note_type) { if ($note_type->parent > 0) { $groups[$note_type->name][] = $note; $groups[$note_type->name]['id'] = $note_type->term_id; break; } } } bbconnect_workqueues_output_action_items($groups); }
function bbconnect_helper_work_queue() { $work_queues = array(); $all_notes = bbconnect_workqueues_get_action_items(); foreach ($all_notes as $note) { $note_types = wp_get_post_terms($note->ID, 'bb_note_type'); foreach ($note_types as $note_type) { if ($note_type->parent > 0) { $work_queues[$note_type->term_id] = $note_type->name; break; } } } return $work_queues; }
function bbconnect_rows($args = null) { global $wpdb; global $totalValues, $fieldInfos; $positionInarray = 0; //determine which position we have in array $blog_prefix = $wpdb->get_blog_prefix(get_current_blog_id()); // SET THE DEFAULTS TO BE OVERRIDDEN AS DESIRED $defaults = array('user_id' => false, 'action_search' => false, 'action_array' => false, 'post_vars' => false, 'table_body' => false, 'action' => 'view', 'bbconnect_address_count' => 0, 'return' => false, 'tdw' => false, 'thiskey' => '', 'return_def' => true); // PARSE THE INCOMING ARGS $args = wp_parse_args($args, $defaults); // EXTRACT THE VARIABLES extract($args, EXTR_SKIP); // SET A LOOKUP ARRAY FOR THE INITIAL QUERY $post_matches = array(); if (isset($post_vars['search'])) { foreach ($post_vars['search'] as $k => $v) { if (isset($v['type']) && 'user' == $v['type'] && isset($v['field']) && isset($v['query'])) { $post_matches[$v['field']] = $v['query']; } } } // GET THE USER DATA $current_member = get_userdata($user_id); if (!$current_member) { return false; } // CHANGE DISPLAY BASED ON ACTION if ('edit' == $action) { $display = ' style="display: block;"'; } else { $display = ' disabled="disabled"'; } // RETRIEVE THE USER ROW if (false == $return) { // RETRIEVE THE AVATAR $user_avatar = apply_filters('bbconnect_reports_user_avatar', get_avatar($current_member->user_email, 32), $current_member); // RETRIEVE THE PROFILE FIELDS $user_fields = array($current_member->first_name . ' ' . $current_member->last_name); $user_fields = apply_filters('bbconnect_reports_user_fields', $user_fields, $current_member); // RETRIEVE THE ACTIONS $user_actions = array(); if (is_admin()) { $user_actions['edit'] = '<a href="' . admin_url('/users.php?page=bbconnect_edit_user&user_id=' . $current_member->ID) . '">' . __('edit') . '</a>'; $user_actions['edit in new tab'] = '<a href="' . admin_url('/users.php?page=bbconnect_edit_user&user_id=' . $current_member->ID) . '" target="_blank">' . __('edit in new tab') . '</a>'; $user_actions['email'] = '<a href="mailto:' . $current_member->user_email . '">' . __('email') . '</a>'; } else { $user_actions['view'] = '<a href="' . home_url('/bbconnect/?rel=viewprofile&uid=' . $current_member->ID) . '" class="bbconnectpanels-toggle" title="profile-' . $current_member->ID . '">' . __('view', 'bbconnect') . '</a>'; } $user_actions = apply_filters('bbconnect_reports_user_actions', $user_actions, $current_member); // USER SETUP $return_html = '<tr>'; // if ( is_admin() ) { // $return_html .= '<td class="gredit-column" width="3%">'; // $return_html .= '<input type="checkbox" name="gredit_users[]" value="'.$current_member->ID.'" class="gredit-user subgredit"'.$display.' />'; // $return_html .= '<input type="hidden" value="'.$current_member->user_email.'" disabled="disabled" />'; // $return_html .= '</td>'; // } $return_html .= '<td style="text-align:left;" class="bbconnect-column-default" width="' . $tdw . '%">'; $return_html .= '<div class="username column-username">'; // USER AVATAR $return_html .= '<div class="bbconnect-reports-user-avatar">' . $user_avatar . '</div>'; // USER INFO - OPEN $return_html .= '<div class="bbconnect-reports-user-info">'; // USER FIELDS $return_html .= '<div class="bbconnect-reports-user-fields">'; $return_html .= implode('<br />', $user_fields); $return_html .= '</span>'; $return_html .= '<br />'; // USER ACTIONS $return_html .= '<div class="bbconnect-reports-user-actions">'; $return_html .= implode(' | ', $user_actions); $return_html .= '</span>'; // USER INFO - CLOSE $return_html .= '</div>'; // USER CLOSEOUT $return_html .= '</div>'; $return_html .= '</td>'; // RESOURCE CLEANUP unset($user_avatar); unset($user_fields); unset($user_actions); } else { $return_val = array(); if (false != $return_def) { $return_val['ID'] = $current_member->ID; $return_val['email'] = $current_member->user_email; $return_val['first_name'] = $current_member->first_name; $return_val['last_name'] = $current_member->last_name; //$return_val['organization'] = $current_member->bbconnect_organization; } } if (!empty($table_body)) { $tempTotals = array(); foreach ($table_body as $key => $value) { //declare an empty array to hold temporal total values $positionInarray++; // HORRIBLY HACKISH MANIPULATIONS FOR ADDRESSES... if (false != strstr($key, 'address')) { // THE KEY WITH THE NUMERIC IDENTIFIER $origkey = $key; // THE NUMERIC IDENTIFIER $thiskey = str_replace('_', '', substr($key, -2)); // THE KEY WITH THE NUMERIC IDENTIFIER REMOVED if (is_numeric($thiskey)) { $key = substr($key, 0, -2); } } // SET THE ARRAY KEY //if ( isset( $post_vars['search'] ) ) //$thiskey = in_array_r($value, $post_vars['search'], true); if (false == $return) { $align = is_numeric($current_member->{$key}) ? 'right' : 'right'; $return_html .= '<td width="' . $tdw . '%" style="text-align: ' . $align . ';">'; //$return_html .= $key . ' ' . $value; } // TAXONOMIES if (is_array($value)) { // KEYS USED AS OBJECT VARS CANNOT HAVE DASHES $alt_key = str_replace('-', '', $key); if (!empty($current_member->{$key})) { foreach ($current_member->{$key} as $subkey => $subvalue) { if ('bbconnect' == substr($key, 0, 9)) { $key = substr($key, 10); } $term_name = get_term_by('id', $subvalue, $key); if (in_array_r($subvalue, $value)) { $ret_arr[] = '<span class="highlight">' . $term_name->name . '</span>'; } else { $ret_arr[] = $term_name->name; } } } else { if (!empty($current_member->{$alt_key})) { foreach ($current_member->{$alt_key} as $subkey => $subvalue) { $term_name = get_term_by('id', $subvalue, substr($key, 10)); if (in_array_r($subvalue, $value)) { $ret_arr[] = '<span class="highlight">' . $term_name->name . '</span>'; } else { $ret_arr[] = $term_name->name; } } } else { $ret_arr = ''; //bbconnect_grex_input( array( 'u_key' => $current_member->ID, 'g_key' => $key, 'g_val' => $current_member->$key ) ); } } if (false == $return) { if (!is_array($ret_arr)) { $return_html .= ''; //$return_html .= bbconnect_grex_input( array( 'u_key' => $current_member->ID, 'g_key' => $key, 'g_val' => $current_member->$key ) ); } else { $return_html .= implode(', ', $ret_arr); //$return_html .= bbconnect_grex_input( array( 'u_key' => $current_member->ID, 'g_key' => $key, 'g_val' => strip_tags( implode( '|', $ret_arr ) ) ) ); } } else { if (!is_array($ret_arr)) { $return_val[$key] = $current_member->{$key}; } else { $return_val[$key] = strip_tags(implode(',', $ret_arr)); } } unset($ret_arr); // META } else { if (is_array($current_member->{$key})) { $marray_out = array(); foreach ($current_member->{$key} as $meta_key => $meta_value) { if (is_array($meta_value)) { if (is_assoc($meta_value)) { if (!empty($meta_value['value'])) { $hlpre = ''; $hlpos = ''; $meta_type = ''; if (isset($post_matches[$key]) && !empty($post_matches[$key])) { if (false !== strpos($meta_value['value'], $post_matches[$key])) { $hlpre = '<span class="highlight">'; $hlpos = '</span>'; } } if (isset($meta_value['type']) && !empty($meta_value['type'])) { $meta_type = $meta_value['type'] . ': '; } $marray_out[] = $hlpre . $meta_type . $meta_value['value'] . $hlpos; } } } else { if ($blog_prefix . 'capabilities' == $key) { if (in_array($meta_key, $current_member->roles)) { $marray_out[] = $meta_key; } } elseif (1 == $meta_value || 'true' == $meta_value) { $marray_out[] = 'yes'; } elseif (0 == $meta_value || 'false' == $meta_value) { $marray_out[] = 'no'; } else { $marray_out[] = $meta_value; } } } if (false == $return) { $return_html .= implode('<br />', $marray_out); //$return_html .= bbconnect_grex_input( array( 'u_key' => $current_member->ID, 'g_key' => $key, 'g_val' => implode( '|', $marray_out ) ) ); } else { $return_val[$key] = implode('|', $marray_out); } unset($marray_out); } else { // IF THIS IS AN ADDRESS FIELD, LOOP THROUGH AND PRESENT ALL RESULTS if (false != strstr($key, 'address') && is_numeric($thiskey)) { // PRE-PROCESS THE META KEY FOR THE GENERAL CHARACTERISTIC // UPON-WHICH THE INDIVIDUAL ADDRESSES CAN BE APPENDED... $pre_add_base = strrchr($key, '_'); $pro_add_base = 0 - strlen($pre_add_base); $add_base = substr($key, 0, $pro_add_base); // IF THERE ARE POST-OPS INVOLVED, LIMIT THE DISPLAY TO THE INTERESECT if (isset($post_vars['search'][$thiskey]['post_ops']) && !empty($post_vars['search'][$thiskey]['post_ops'])) { $post_op_arr = $post_vars['search'][$thiskey]['post_ops']; $po_s = array(); // GET THE SUFFIX foreach ($post_op_arr as $pkey => $pval) { $cur_po_preval = 'bbconnect_' . $pval; $origkey = substr($key, 0, -2) . substr($pval, 2); $cur_po_val = $current_member->{$cur_po_preval}; $pre_po_s = strrchr($cur_po_val, '_'); $po_s[] = substr($pre_po_s, 1); } $po_s_array = array_unique($po_s); if (count($po_s_array) == 1) { $po_add = $po_s_array[0]; } } // SET THE VARS $cur_address = array(); for ($i = 1; $i <= $bbconnect_address_count; $i++) { $cur_ite = $add_base . '_' . $i; if (isset($po_add)) { if ($i != $po_add) { continue; } else { $sub_ite = $add_base . '_' . $po_add; $cur_address[$cur_ite] = $current_member->{$cur_ite}; $cur_grex_key = $cur_ite; } } else { if (isset($post_vars['search'][$thiskey]['query']) && !empty($post_vars['search'][$thiskey]['query'])) { if (is_array($post_vars['search'][$thiskey]['query'])) { foreach ($post_vars['search'][$thiskey]['query'] as $val) { if (false !== stripos($current_member->{$cur_ite}, $val)) { $cur_address[$cur_ite] = $current_member->{$cur_ite}; $cur_grex_key = $cur_ite; break; } } } else { if (false !== stripos($current_member->{$cur_ite}, $post_vars['search'][$thiskey]['query'])) { $cur_address[$cur_ite] = $current_member->{$cur_ite}; $cur_grex_key = $cur_ite; break; } } } else { if ($current_member->{$cur_ite}) { $cur_address[$cur_ite] = $current_member->{$cur_ite}; $cur_grex_key[] = $cur_ite; } else { $cur_address[$cur_ite] = false; $cur_grex_key[] = $cur_ite; } } } } if (false == $return) { // EXCEPTIONS FOR STATES $cur_address_filtered = array(); if (false !== strpos($key, 'address_state')) { array_filter($cur_address); foreach ($cur_address as $ck => $cv) { $cur_address_filtered[$ck] = bbconnect_state_lookdown($cur_ite, $cv); } $cur_address = $cur_address_filtered; } elseif (false !== strpos($key, 'address_country')) { $bbconnect_helper_country = bbconnect_helper_country(); array_filter($cur_address); foreach ($cur_address as $ck => $cv) { if (array_key_exists($cv, $bbconnect_helper_country)) { $cur_address_filtered[$ck] = $bbconnect_helper_country[$cv]; } else { $cur_address_filtered[$ck] = $cv; } } $cur_address = $cur_address_filtered; } $return_html .= implode('<br />', array_filter($cur_address)); if (isset($cur_grex_key) && is_array($cur_grex_key)) { $cur_grex_val = $cur_address; } else { $cur_grex_val = urlencode(serialize($cur_address)); $cur_grex_key = array(); //if ( !isset( $cur_grex_key ) ) $return_html .= ''; //<p>'.$value.'</p> } //$return_html .= bbconnect_grex_input( array( 'u_key' => $current_member->ID, 'g_key' => $cur_grex_key, 'g_val' => $cur_grex_val ) ); } else { if (false === $post_vars) { if (false !== strpos($origkey, 'address_state')) { $return_val[$origkey] = bbconnect_state_lookdown($origkey, $current_member->{$origkey}); } else { $return_val[$origkey] = $current_member->{$origkey}; } } else { foreach ($cur_address as $ka => $va) { // EXCEPTIONS FOR STATES if (false !== strpos($ka, 'address_state')) { $return_val[$ka] = bbconnect_state_lookdown($ka, $va); } else { $return_val[$ka] = $va; } } //$return_val[$origkey] = implode( '|', $cur_address ); } } unset($cur_address); unset($cur_grex_key); } else { if (false == $return) { $fieldInfo = get_option('bbconnect_' . $key); $fieldInfos[$positionInarray] = $fieldInfo; if ($key == 'bbconnect_bb_work_queue' && function_exists('bbconnect_workqueues_get_action_items')) { $args = array('author' => $current_member->ID); $notes = bbconnect_workqueues_get_action_items($args); $type_list = array(); foreach ($notes as $note) { $note_types = wp_get_post_terms($note->ID, 'bb_note_type'); foreach ($note_types as $note_type) { if ($note_type->parent > 0) { $type_list[$note_type->name] = $note_type->name; break; } } } $return_html .= implode(', ', $type_list); } elseif ($key == 'bbconnect_category_id' || $key == 'bbconnect_segment_id') { if (!empty($current_member->{$key})) { $return_html .= get_the_title($current_member->{$key}); } } elseif ($fieldInfo['options']['field_type'] == 'date' && is_real_date($current_member->{$key})) { $new_date_string = date('d F Y', strtotime($current_member->{$key})); $return_html .= $new_date_string; } elseif ($fieldInfo['options']['field_type'] == 'number' && $fieldInfo['options']['is_currency'] && $current_member->{$key} != '') { $return_html .= '$' . number_format($current_member->{$key}, 2); } else { if (is_string($current_member->{$key})) { $return_html .= $current_member->{$key}; } } //check if value is numeric and find total if ($fieldInfo['options']['field_type'] == 'number' && is_numeric($current_member->{$key}) && $current_member->{$key} > 0) { $tempTotals[$positionInarray] = !empty($totalValues[$positionInarray]) ? $totalValues[$positionInarray] + $current_member->{$key} : $current_member->{$key}; } else { $tempTotals[$positionInarray] = !empty($totalValues[$positionInarray]) ? $totalValues[$positionInarray] : 0; } //$positionInarray++; //if reached the max position in array, then go back to zero if ($positionInarray == count($table_body)) { foreach ($tempTotals as $keytemp => $valuetemp) { if ($valuetemp) { $totalValues = $tempTotals; break; } } $positionInarray = 0; $tempTotals = array(); } //insert into totals array if tempvalues not empty //$return_html .= bbconnect_grex_input( array( 'u_key' => $current_member->ID, 'g_key' => $key, 'g_val' => $current_member->$key ) ); } else { $return_val[$key] = $current_member->{$key}; } } } } if (false == $return) { $return_html .= '</td>'; } } } //global $action_array; if (is_array($action_array)) { if (false == $return) { $return_html .= '<td width="' . $tdw * 2 . '%"><table width="100%">'; } if (isset($action_array[$current_member->ID])) { foreach ($action_array[$current_member->ID] as $key => $value) { if (false == $return) { $return_html .= '<tr>'; if (is_admin()) { $return_html .= '<td class="gredit-column" width="3%"><input type="checkbox" name="gredit_actions[' . $current_member->ID . '][]" value="' . $value['ID'] . '" class="gredit-action subgredit"' . $display . ' /></td>'; } $return_html .= '<td width="' . round($tdw * 2 - 7, 2) . '%" class="action-detail ' . $value['post_type'] . '">'; $inner_return_hmtl = ''; if (is_admin()) { $return_html .= apply_filters('bbconnect_action_detail_html', $inner_return_hmtl, $value); } else { $return_html .= apply_filters('bbconnect_action_detail_html_public', $inner_return_hmtl, $value); } $return_html .= '</td></tr>'; } else { $return_val = apply_filters('bbconnect_action_detail_val', $return_val, $value); } } } if (false == $return) { $return_html .= '</table></td>'; } } unset($current_member); if (false == $return) { $return_html .= '</tr>'; } if (false == $return) { return $return_html; } else { return $return_val; } }
function bbconnect_filter_process($post_data) { // LOCAL VARIABLES global $wpdb, $memberquery, $membervalue, $users_per_page, $max_num_pages, $table_head, $table_body, $blog_prefix, $bid, $page_num, $query_diff, $action_search, $all_search; $bid = get_current_blog_id(); $blog_prefix = $wpdb->get_blog_prefix($bid); $mtc = 0; $page_num = 1; $mtjoin = array(); $mtquery = array(); $mtselect = array("DISTINCT {$wpdb->users}.ID"); // as id $skip_arr = array(); // IF THERE'S A SORT BY REQUEST, PROCESS THAT if (!empty($post_data['order_by'])) { $order_by = apply_filters('bbcpres_filter_order_by', $post_data['order_by']); // STANDARDIZE WORDPRESS INCONSISTENCIES FOR RESERVED FIELDS // EMAIL switch ($order_by) { case 'ID': $order_by = 'ID'; break; case 'email': $order_by = 'user_email'; break; case 'url': $order_by = 'user_url'; break; case 'user_login': $order_by = 'user_login'; break; case 'display_name': $order_by = 'display_name'; break; case 'user_registered': $order_by = 'user_registered'; break; case 'role': $order_by = $blog_prefix . 'capabilities'; $ometa = true; break; case 'first_name': $order_by = $order_by; $ometa = true; break; case 'last_name': $order_by = $order_by; $ometa = true; break; default: $order_by = $order_by; $ometa = true; break; } } else { $order_by = 'ID'; } // SET THE SORT DIRECTION, IF IT HASN'T BEEN SET ALREADY if (!isset($post_data['order'])) { $post_data['order'] = 'DESC'; } if ('DESC' === $post_data['order']) { //uksort( $all_sort, 'insensitive_uksort_rev' ); $order = 'DESC'; } else { //uksort( $all_sort, 'insensitive_uksort' ); $order = 'ASC'; } /* // SET UP THE SORTING ARRAY $all_sort = array(); foreach ( $all_search as $user ) { // IF THERE'S A SORT BY REQUEST, PROCESS THAT if ( isset( $order_by ) ) { // GET THE VALUE TO ORDER BY $current_user = get_userdata( $user ); // INCLUDE IT IF IT EXISTS AND APPEND THE USER ID TO ENSURE THE KEYS ARE UNIQUE if ( isset( $current_user->$order_by ) ) { $all_key = str_replace( '-', '_', $current_user->$order_by ) . '_' . $user; } else { $all_key = $user; } } else { $all_key = $user; } $all_val = $user; $all_sort[$all_key] = $all_val; } */ // WE CAN TRY BYPASSING THIS FOR IMPORTS BY SETTING IT THROUGH POSTDATA if (!isset($post_data['all_search'])) { // RETURN VALUES $table_head = array(); $table_body = array(); $all_search = array(); $member_search = array(); $users_count = ''; // THE POST-OPERATOR $post_operator = array(); // THE COUNTER TO KEEP TRACK OF HOW MANY QUERIES WE'VE MADE global $u_count; $u_count = '0'; // THE QUERY ARRAY CONTAINING THE RESULTING ARRAY OF USER IDS if (isset($post_data['search'])) { $q_array = array(); } // LET'S GET STARTED! // MERGE TAGS: LOOP THROUGH THE POST VALUES AND BUILD THE QUERY if (isset($post_data['search'])) { foreach ($post_data['search'] as $key => $value) { if ('user' != $value['type']) { continue; } // GO AHEAD AND TALLY $u_count++; // SET THE FIELD KEY $fkey = $value['field']; // DETERMINE THE OPERATOR switch ($value['operator']) { case '': $op = 'skip'; $sop = '||'; break; case 'is': $op = '='; $sop = '||'; break; case 'not': $op = '!='; $sop = '&&'; break; case 'like': $op = 'LIKE'; $sop = '||'; break; case 'notlike': $op = 'NOT LIKE'; $sop = '&&'; break; case 'null': $op = 'IS NULL'; $sop = '||'; break; case 'notnull': $op = 'IS NOT NULL'; $sop = '||'; break; case 'lt': $op = '<'; $sop = '||'; break; case 'gt': $op = '>'; $sop = '||'; break; } // DETERMINE THE SUB OPERATOR if (isset($value['sub_operator'])) { switch ($value['sub_operator']) { case 'all': $sop = '&&'; break; case 'any': $sop = '||'; break; } } // PREP THE RESULTS TABLE && DISTINGUISH BETWEEN TAXONOMIES & META if ('bbconnect' != substr($fkey, 0, 9)) { $option_key = 'bbconnect_' . $fkey; } else { $option_key = $fkey; } // EVALUATE THE FIELD $user_meta = get_option($option_key); // STANDARDIZE WORDPRESS INCONSISTENCIES FOR RESERVED FIELDS if (isset($user_meta['source']) && 'wpr' == $user_meta['source']) { // EMAIL if ('email' == $user_meta['meta_key']) { $wp_col = 'user_email'; } // USER ID if ('ID' == $user_meta['meta_key']) { $wp_col = 'ID'; } // USER CREATED DATE if ('user_registered' == $user_meta['meta_key']) { $wp_col = 'user_registered'; } // URL if ('url' == $user_meta['meta_key']) { $wp_col = 'user_url'; } // LOGIN if ('user_login' == $user_meta['meta_key']) { $wp_col = 'user_login'; } // DISPLAY NAME if ('display_name' == $user_meta['meta_key']) { $wp_col = 'display_name'; } // ROLE if ('role' == $user_meta['meta_key']) { $wp_meta_col = $blog_prefix . 'capabilities'; //if ( 'skip' != $op ) //$op = 'LIKE'; } } // SPECIAL CASE FOR SERIALIZED DATA if ('taxonomy' == $user_meta['options']['field_type'] || 'role' == $user_meta['meta_key']) { if ('=' == $op && isset($value['query'])) { $op = 'LIKE'; } else { if ('!=' == $op && isset($value['query'])) { $op = 'NOT LIKE'; } } } // Even special-er case for Work Queues etc if ('bb_work_queue' == $user_meta['meta_key']) { $wp_col = 'ID'; if ('=' == $op && isset($value['query'])) { $op = 'IN'; } else { if ('!=' == $op && isset($value['query'])) { $op = 'NOT IN'; } } } // STANDARDIZE WORDPRESS META FIELDS if (isset($user_meta['source'])) { if ('wp' == $user_meta['source'] && 'taxonomy' != $user_meta['options']['field_type']) { $wp_meta_col = $fkey; } else { if ('wp' == $user_meta['source'] && 'taxonomy' == $user_meta['options']['field_type']) { $user_meta_col = ''; } else { if ('user' == $user_meta['source']) { $user_meta_col = ''; } else { $user_meta_col = 'bbconnect_'; } } } } // IF WE'RE JUST DISPLAYING RESULTS, SIT THIS PART OUT if ('skip' != $op) { // SET THE QUERY PREFIX if (0 === $mtc) { $mtc_as = ''; $mtc_dot = "{$wpdb->usermeta}."; } else { $mtc_as = 'AS mt' . $mtc . ' '; $mtc_dot = 'mt' . $mtc . '.'; // FUTURE $mtselect[] = 'mt' . $mtc.'.meta_value'; } // THIS IS A SUBQUERY if (isset($value['query'])) { $value_query = $value['query']; } else { $value_query = ''; } if (is_array($value_query)) { // SETUP A TEMP ARRAY TO JOIN $temp_arr = array(); foreach ($value_query as $subkey => $subvalue) { // MIMIC THE SERIALIZED STRUCTURE FOR ROLES AND TAXONOMIES if ('taxonomy' == $user_meta['options']['field_type'] || 'role' == $user_meta['meta_key']) { $subvalue = substr($wpdb->prepare("%s", $subvalue), 1, -1); $q_val = '\'%s:' . strlen($subvalue) . ':"' . $subvalue . '"%\''; // Work Queues are rather special... } else { if ('bb_work_queue' == $user_meta['meta_key'] && function_exists('bbconnect_workqueues_get_action_items')) { $args = array('tax_query' => array(array('taxonomy' => 'bb_note_type', 'field' => 'term_id', 'terms' => array($subvalue)))); $notes = bbconnect_workqueues_get_action_items($args); $note_users = array(); foreach ($notes as $note) { $note_users[$note->post_author] = $note->post_author; } $q_val = '(' . implode(',', $note_users) . ')'; // } elseif ($key == 'category_id' || $key == 'segment_id') { // CONDITIONS FOR THE VALUE } else { if ('LIKE' === $op || 'NOT LIKE' === $op) { $q_val = $wpdb->prepare("%s", '%' . $subvalue . '%'); } else { if ('IS NULL' === $op || 'IS NOT NULL' === $op) { $q_val = ""; } else { if ('<' === $op || '>' === $op) { if (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])\$/", $value_query)) { $is_date = true; } else { $is_date = false; } if ($is_date) { $q_val = "DATE('" . $value_query . "')"; } else { $q_val = strpos($subvalue, '.') !== false ? floatval($subvalue) : intval($subvalue); } } else { if (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])\$/", $subvalue) && $wp_col != 'user_registered') { if (date('Y-m-d', strtotime($subvalue)) == $subvalue) { $temp_date_arr[] = "DATE('" . $subvalue . "')"; } } else { $q_val = $wpdb->prepare("%s", $subvalue); } } } } } } // THIS IS A WORDPRESS USER FIELD if (isset($wp_col)) { if ($wp_col == 'user_registered') { if (date('Y-m-d', strtotime($subvalue)) == $subvalue) { $temp_arr[] = "DATE('" . $subvalue . "')"; } } else { $temp_arr[] = "(" . $wp_col . " " . $op . " " . $q_val . ")"; } } else { if (isset($wp_meta_col)) { $temp_arr[] = $mtc_dot . "meta_value " . $op . " " . $q_val; } else { $temp_arr[] = $mtc_dot . "meta_value " . $op . " " . $q_val; } } } // JOIN THE JOIN if (isset($wp_col)) { if ($wp_col == 'user_registered') { if ('!=' == $op || 'NOT LIKE' == $op) { $reg_op = " NOT BETWEEN "; } else { $reg_op = " BETWEEN "; } $mtquery[$mtc] = "(" . $wp_col . $reg_op . implode(' AND ', $temp_arr) . ")"; } else { $mtquery[$mtc] = "(" . implode(' ' . $sop . ' ', $temp_arr) . ")"; } } else { //if ( !isset( $wp_col ) ) $mtjoin[$mtc] = "INNER JOIN {$wpdb->usermeta} " . $mtc_as . "ON ({$wpdb->users}.ID = " . $mtc_dot . "user_id)"; // JOIN THE QUERY TEMP ARRAY if (isset($wp_meta_col)) { $mtquery[$mtc] = "(" . $mtc_dot . "meta_key = '" . $wp_meta_col . "' AND " . implode(' ' . $sop . ' ', $temp_arr) . ")"; } else { if (isset($user_meta['group']) && false !== strpos($user_meta['group'], 'address')) { $mod_key = substr($fkey, 0, -1); // PREPARE $mod_comp = "meta_key LIKE '%".$user_meta_col. $mod_key . "%'"; $mod_comp = $wpdb->prepare("meta_key LIKE %s", "%" . $user_meta_col . $mod_key . "%"); } else { $mod_key = $fkey; // PREPARE $mod_comp = "meta_key = '".$user_meta_col. $mod_key . "'"; $mod_comp = $wpdb->prepare("meta_key = %s", $user_meta_col . $mod_key); } if (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])\$/", $subvalue)) { if ('!=' == $op || 'NOT LIKE' == $op) { $reg_op = " NOT BETWEEN "; } else { $reg_op = " BETWEEN "; } $mtquery[$mtc] = "(" . $mtc_dot . $mod_comp . " AND " . $mtc_dot . "meta_value " . $reg_op . implode(' AND ', $temp_date_arr) . ")"; } else { $mtquery[$mtc] = "(" . $mtc_dot . $mod_comp . " AND " . implode(' ' . $sop . ' ', $temp_arr) . ")"; } } } } else { /* MIMIC THE SERIALIZED STRUCTURE FOR ROLES AND TAXONOMIES if ( 'taxonomy' == $user_meta['options']['field_type'] || 'role' == $user_meta['meta_key'] ) { if ( '' != $value_query ) $value_query = 's:'.strlen($value_query).':"'.$value_query.'"'; } */ // CONDITIONS FOR THE VALUE // AND THE OPERATOR IF APPLICABLE if ('LIKE' === $op || 'NOT LIKE' === $op) { // PREPARE $q_val = "'%" . $value_query . "%'"; $q_val = $wpdb->prepare("%s", '%' . $value_query . '%'); } else { if ('IS NULL' === $op || 'IS NOT NULL' === $op || '' == $value_query || empty($value_query) || !isset($value_query)) { if (isset($wp_col)) { if ('IS NULL' === $op || '=' === $op) { $op = "="; } else { $op = "!="; } $q_val = "''"; } else { if ('' == $value_query || empty($value_query) || !isset($value_query)) { if ('=' === $op && !isset($wp_meta_col)) { $op = "IS NULL"; $q_val = ""; } else { if ('!=' == $op && !isset($wp_meta_col)) { $op = "IS NOT NULL"; $q_val = ""; } else { // PREPARE $q_val = "'" . $value_query . "'"; $q_val = $wpdb->prepare("'%s'", $value_query); } } } } } else { if ('<' === $op || '>' === $op) { if (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])\$/", $value_query)) { $is_date = true; } else { $is_date = false; } if ($is_date) { $q_val = "DATE('" . $value_query . "')"; } else { $q_val = strpos($value_query, '.') !== false ? floatval($value_query) : intval($value_query); } } else { // PREPARE $q_val = "'" . $value_query . "'"; $q_val = $wpdb->prepare("'%s'", $value_query); } } } // THIS IS A WORDPRESS USER FIELD if (isset($wp_col)) { $mtquery[$mtc] = "(" . $wp_col . " " . $op . " " . $q_val . ")"; } else { $mtjoin[$mtc] = "INNER JOIN {$wpdb->usermeta} " . $mtc_as . "ON ({$wpdb->users}.ID = " . $mtc_dot . "user_id)"; // TEST FOR NULL COMPARISONS if ('IS NULL' === $op) { if (isset($wp_meta_col)) { $mtquery[$mtc] = "(" . $mtc_dot . "meta_key = '" . $wp_meta_col . "' AND " . $mtc_dot . "meta_value = '')"; } else { if (isset($user_meta['group']) && false !== strpos($user_meta['group'], 'address')) { $mod_key = substr($fkey, 0, -1); // PREPARE $mod_comp = "meta_key = '%".$user_meta_col. $mod_key . "%'"; $mod_comp = $wpdb->prepare("meta_key LIKE %s", "%" . $user_meta_col . $mod_key . "%"); } else { $mod_key = $fkey; // PREPARE $mod_comp = "meta_key = '".$user_meta_col. $mod_key . "'"; $mod_comp = $wpdb->prepare("meta_key = %s", $user_meta_col . $mod_key); } $mtquery[$mtc] = "( " . $mtc_dot . "user_id NOT IN(SELECT DISTINCT " . $wpdb->usermeta . ".user_id FROM " . $wpdb->usermeta . " WHERE " . $wpdb->usermeta . "." . $mod_comp . ") )"; } } else { if (isset($wp_meta_col)) { $mtquery[$mtc] = "(" . $mtc_dot . "meta_key = '" . $wp_meta_col . "' AND " . $mtc_dot . "meta_value " . $op . " " . $q_val . ")"; } else { if (isset($user_meta['group']) && false !== strpos($user_meta['group'], 'address')) { $mod_key = substr($fkey, 0, -1); // PREPARE $mod_comp = "meta_key LIKE '%".$user_meta_col. $mod_key . "%'"; $mod_comp = $wpdb->prepare("meta_key LIKE %s", "%" . $user_meta_col . $mod_key . "%"); } else { $mod_key = $fkey; // PREPARE $mod_comp = "meta_key = '".$user_meta_col. $mod_key . "'"; $mod_comp = $wpdb->prepare("meta_key = %s", $user_meta_col . $mod_key); } $mtquery[$mtc] = "(" . $mtc_dot . $mod_comp . " AND " . $mtc_dot . "meta_value " . $op . " " . $q_val . ")"; } } } } // DETERMINE ANY QUERY POST-OPS if (isset($value['post_ops'])) { // SET THE SELECT FIELD FOR THE PRECEDING VALUE $mtselect[] = $mtc_dot . "meta_key AS mv" . $mtc; foreach ($value['post_ops'] as $post_op) { // PUSH THE COMPARITORS $kpost_op = array('meta' => $fkey, 'type' => $post_op, 'incl' => $value['operator']); array_push($post_operator, $kpost_op); // INCREMENT THE QUERY COUNTER $mtc++; // SET THE QUERY PREFIX if (0 === $mtc) { $mtc_as = ''; $mtc_dot = "{$wpdb->usermeta}."; } else { $mtc_as = 'AS mt' . $mtc . ' '; $mtc_dot = 'mt' . $mtc . '.'; } $mtjoin[$mtc] = "INNER JOIN {$wpdb->usermeta} " . $mtc_as . "ON ({$wpdb->users}.ID = " . $mtc_dot . "user_id)"; // PREPARE $mtquery[$mtc] = "(" . $mtc_dot . "meta_key = 'bbconnect_" . $post_op . "')"; $mtquery[$mtc] = $wpdb->prepare("(" . $mtc_dot . "meta_key = %s)", "bbconnect_{$post_op}"); $mtselect[] = $mtc_dot . "meta_value AS mv" . $mtc; } } } else { $skip_arr[] = 'bbconnect_' . $value['field']; } // NO MATTER WHAT, SAVE THE DATA FOR THE COLUMNS // IT'S A TAXONOMY! if ('taxonomy' == $user_meta['options']['field_type']) { // PULL THE TAXONOMY DATA AND ASSIGN THE DISPLAY VALUES $tab_head = get_taxonomy($fkey); // ASSIGN THE DISPLAY VALUES $table_head[] = array(false, $tab_head->labels->name); if ('bbconnect' != $user_meta['source']) { $switch_key = $fkey; } elseif ('bbconnect' == $user_meta['source']) { $switch_key = $option_key; } // TEST FOR DISPLAY PURPOSES if (empty($value['query'])) { $table_body[$switch_key][] = ''; // GET ALL THE TERMS! } else { foreach ($value['query'] as $term) { // GET THE TERM ID $table_body[$switch_key][] = $term; } } // IT'S A META! } else { // THE HEADER $table_head[] = array($user_meta['meta_key'], $user_meta['name']); // THE BODY if ('wpr' == $user_meta['source']) { if (isset($wp_col)) { $table_body[$wp_col] = $fkey; } else { if (isset($wp_meta_col)) { $table_body[$wp_meta_col] = $fkey; } } } elseif ('bbconnect' != $user_meta['source']) { $table_body[$fkey] = $fkey; } elseif ('bbconnect' == $user_meta['source']) { if ('address' == substr($user_meta['group'], 0, 7)) { if (2 != count($key)) { $atk = '_' . $key; } else { $atk = $key; } $table_body[$option_key . $atk] = $fkey; } else { $table_body[$option_key] = $fkey; } } } // CLEANUP $mtc++; if (isset($temp_arr)) { unset($temp_arr); } if (isset($wp_col)) { unset($wp_col); } if (isset($wp_meta_col)) { unset($wp_meta_col); } if (isset($user_meta_col)) { unset($user_meta_col); } } // SET UP THE ORDER CLAUSE if (isset($ometa)) { // SET THE QUERY PREFIX if (0 === $mtc) { $mtc_as = ''; $mtc_dot = "{$wpdb->usermeta}."; } else { $mtc_as = 'AS mt' . $mtc . ' '; $mtc_dot = 'mt' . $mtc . '.'; } $mtjoin[$mtc] = "INNER JOIN {$wpdb->usermeta} " . $mtc_as . "ON ({$wpdb->users}.ID = " . $mtc_dot . "user_id)"; if (in_array($order_by, $skip_arr)) { // GET THE META TO TEST $t_order_by = bbconnect_get_option($order_by); if (false != $t_order_by) { if ('bbconnect' == $t_order_by['source']) { $order_by = 'bbconnect_' . $order_by; } } $nullquo = $wpdb->prepare("IFNULL(" . $mtc_dot . "meta_key = %s,0) = %s", $order_by, $order_by); $nullval = " ORDER BY IFNULL(" . $mtc_dot . "meta_value," . $mtc_dot . "meta_key) {$order}"; } else { // GET THE META TO TEST $t_order_by = bbconnect_get_option($order_by); if (false != $t_order_by) { if ('bbconnect' == $t_order_by['source']) { $order_by = 'bbconnect_' . $order_by; } } if (isset($t_order_by['group']) && false !== strpos($t_order_by['group'], 'address')) { $addext = count(strrchr($t_order_by['meta_key'], '_')); $addapp = substr($t_order_by['meta_key'], 0, -$addext); $nullquo = $wpdb->prepare($mtc_dot . "meta_key LIKE %s", '%bbconnect_' . $addapp . '%'); } else { $nullquo = $wpdb->prepare($mtc_dot . "meta_key = %s", $order_by); } $nullval = " ORDER BY " . $mtc_dot . "meta_value {$order}"; } $mtquery[$mtc] = $nullquo; $mtorder = $nullval; // CASE FOR ACTIONS //$actusers = "INNER JOIN $wpdb->usermeta ON ($wpdb->posts.post_author = $wpdb->usermeta.user_id)"; //$actquery = "$wpdb->usermeta.meta_key = '$order_by' AND"; //$mtc++; } else { $mtorder = " ORDER BY {$wpdb->users}.{$order_by} {$order}"; // CASE FOR ACTIONS //$actusers = "INNER JOIN $wpdb->users ON ($wpdb->posts.post_author = $wpdb->users.ID)"; //$actquery = ""; // "$wpdb->usermeta.meta_key = '$order_by' AND"; } // JOIN THE QUERY $q_join = implode(' ', $mtjoin); $q_query = implode(' ' . $post_data['mod_results'] . ' ', $mtquery); $q_select = implode(', ', $mtselect); $wpdb->flush(); if (empty($q_query)) { $all_query = "SELECT {$wpdb->users}.ID FROM {$wpdb->users} {$mtorder}"; $all_search = $wpdb->get_col($all_query); } else { $all_query = "SELECT {$q_select} FROM {$wpdb->users} {$q_join} WHERE 1=1 AND {$q_query} {$mtorder}"; if (count($mtselect) > 1) { $all_search = $wpdb->get_results($all_query, ARRAY_N); } else { $all_search = $wpdb->get_col($all_query); } } $wpdb->flush(); } else { // ASSUME THEY WANT TO SEARCH EVERYONE... if (isset($ometa)) { $all_order = "INNER JOIN {$wpdb->usermeta} ON ({$wpdb->users}.ID = {$wpdb->usermeta}.user_id) WHERE {$wpdb->usermeta}.meta_key = '{$order_by}' ORDER BY {$wpdb->usermeta}.meta_value {$order}"; } else { $all_order = "ORDER BY {$wpdb->users}.{$order_by} {$order}"; } $all_query = "SELECT {$wpdb->users}.ID FROM {$wpdb->users} {$all_order}"; // $all_search = $wpdb->get_col($all_query); $wpdb->flush(); } //echo $all_query; //print_r($post_data); // IF THE POST OPERATOR IS SET, FILTER THE RESULTS if (!empty($post_operator)) { // SET THE REFRESHED OPERATOR $po_all_search = array(); // LOOP THROUGH THE OPERATORS AND TEST WHETHER THEY SHOULD BE INCLUDED foreach ($all_search as $key => $value) { // COUNT THE ELEMENTS IN THE RESULTS ARRAY if (!isset($po_arr_count)) { $po_arr_count = count($value) - 1; } // LOCATE THE TARGET INTEGER FOR ADDRESSES //if ( !isset( $po_index ) ) { $pre_po_index = strrchr($value[1], '_'); $po_index = substr($pre_po_index, 1); $po_count = 0 - strlen($po_index); //} // LOOP THROUGH THE VALUES AND IF THEY DON'T AGREE, UNSET THE VALUE for ($i = 2; $i <= $po_arr_count; $i++) { if (substr($value[$i], $po_count) != $po_index) { $cur_[$key] = true; } } // IF THERE'S A MATCH, RE-BUILD THE ALL SEARCH ARRAY if (!isset($cur_[$key])) { $po_all_search[] = $value[0]; } } $all_search = $po_all_search; unset($po_all_search); } do_action('bbconnect_search_extend', $post_data, $all_search); } else { $all_search = $post_data['all_search']; } // CONTINUE ON WITH THE PAGINATION AND SORTING ACTIVITY... if (!empty($all_search)) { $users_count = count($all_search); // GET THE REQUESTED PAGE NUMBER if (isset($_GET['page_num'])) { $page_num = $_GET['page_num']; } else { if (isset($post_data['page_num'])) { $page_num = $post_data['page_num']; } } // GET THE REQUESTED RESULT SET if (isset($post_data['users_per_page'])) { //check if user per page is all if (strtolower($post_data['users_per_page']) == 'all') { $users_per_page = $users_count; } else { $users_per_page = $post_data['users_per_page']; } } else { $users_per_page = 25; // THIS NEEDS TO BE AN OPTION!!! } // GET THE NUMBER OF PAGES $max_num_pages = ceil($users_count / $users_per_page); $pages = (int) $page_num; if ($pages > $max_num_pages) { $pages = $max_num_pages; } if ($pages < 1) { $pages = 1; } // GET THE PAGE RANGE $page_low = ($pages - 1) * $users_per_page; $page_high = $users_per_page; // FINALLY, IF WE'RE PAGINATING, SLICE THE ARRAY $member_search = array_slice($all_search, $page_low, $page_high); } if (!isset($action_search)) { $action_search = false; } $ret_arr = array('all_search' => $all_search, 'member_search' => $member_search, 'action_search' => $action_search, 'post_vars' => $post_data, 'max_num_pages' => $max_num_pages, 'users_count' => $users_count, 'users_per_page' => $users_per_page, 'page_num' => $page_num, 'errors' => false, 'table_head' => $table_head, 'table_body' => $table_body); unset($all_search); unset($member_search); unset($action_search); return $ret_arr; }