/** * Plugin Activation * */ public function activate() { if (!class_exists('\\WP_CRM_F')) { include_once ud_get_wp_crm()->path("lib/class_functions.php", 'dir'); } \WP_CRM_F::maybe_install_tables(); \WP_CRM_F::manual_activation('auto_redirect=false&update_caps=true'); }
/** * Replaced notification variables with actual values * * @param array $notification_data * @param array $replace_with * @since 0.21 * */ static function replace_notification_values($notification_data = false, $replace_with = false) { if (!is_array($replace_with)) { return; } $notification_keys = array_keys($notification_data); foreach ($replace_with as $key => $value) { if (is_array($value)) { $value = WP_CRM_F::get_first_value($value); } foreach ($notification_data as $n_key => $n_value) { $notification_data[$n_key] = str_replace('[' . $key . ']', $value, $n_value); } } return $notification_data; }
/** * Replaced notification variables with actual values * * @param array $notification_data * @param array $replace_with * @since 0.21 * */ static function replace_notification_values($notification_data = false, $replace_with = false) { if (!is_array($replace_with)) { return; } $associated_object = !empty($_REQUEST['associated_object']) ? get_post($_REQUEST['associated_object']) : false; $notification_keys = array_keys($notification_data); $replace_with['post_id'] = !empty($associated_object) ? $associated_object->ID : ''; $replace_with['post_title'] = !empty($associated_object) ? $associated_object->post_title : ''; $replace_with['post_link'] = !empty($associated_object) ? get_permalink($associated_object->ID) : ''; $replace_with = apply_filters('wp_crm_notification_replace_values', $replace_with); foreach ($replace_with as $key => $value) { if (is_array($value)) { $value = WP_CRM_F::get_first_value($value); } foreach ($notification_data as $n_key => $n_value) { $notification_data[$n_key] = str_replace('[' . $key . ']', $value, $n_value); } } return $notification_data; }
if (is_array($wp_crm_js)) { echo '<script type="text/javascript">var wp_crm = jQuery.parseJSON(' . json_encode(json_encode($wp_crm_js)) . '); </script>'; } ?> <div class="wp_crm_profile_wrapper wrap"> <div class="wp_crm_ajax_result"></div> <?php screen_icon(); ?> <h2 class="wp_crm_page_title"><?php echo $title; ?> </h2> <?php WP_CRM_F::print_messages(); ?> <form enctype="multipart/form-data" name="crm_user" action="admin.php?page=wp_crm_add_new<?php echo $user_id ? "&user_id={$user_id}" : ''; ?> " method="post" id="crm_user"> <input type="hidden" id="user_id" name="wp_crm[user_data][user_id][0][value]" value="<?php echo $user_id; ?> " /> <?php wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); wp_nonce_field('wp_crm_update_user', 'wp_crm_update_user', false); ?>
<input type="button" value="<?php _e('Show WP_CRM_F::user_object_structure()', 'wp_crm'); ?> " id="" class='wp_crm_toggle_something'> <span id="" class="wp_crm_toggle_something wp_crm_link hidden"><?php _e('Cancel', 'wp_crm'); ?> </span> <pre class="wp_crm_class_pre hidden"><?php _e('All possible meta keys:', 'wp_crm'); ?> <?php print_r(WP_CRM_F::user_object_structure()); ?> <?php _e('Root Only:', 'wp_crm'); print_r(WP_CRM_F::user_object_structure('root_only=true')); ?> </pre> </div> <div class="wp_crm_settings_block"> <?php _e('Lookup a user object by its ID.', 'wp_crm'); ?> <input type="input" value="<?php echo get_current_user_id(); ?> " id="wp_crm_user_id"> <input type="button" value="<?php _e('Load User', 'wp_crm');
/** * Only load code that needs BuddyPress to run once BP is loaded and initialized. * * @author potanin@UD */ function bp_init() { WP_CRM_F::console_log(sprintf(__('Executing: %1s.', 'wp_crm'), 'WPC_BuddyPress::bb_init()')); add_filter('wp_crm_settings_lower', array('WPC_BuddyPress', 'wp_crm_settings_lower')); add_filter('wp_crm_user_action', array('WPC_BuddyPress', 'wp_crm_user_action')); }
/** * * @global type $wp_crm * @param type $user_object */ static function primary_information($user_object) { global $wp_crm; $user_role = WP_CRM_F::get_first_value(!empty($user_object['role']) ? $user_object['role'] : array()); ?> <table class="form-table"> <?php if (isset($_GET['user_id'])) { $user_id = $_GET['user_id']; $user_info = get_user_meta($user_id); $stripe_id = $user_info['stripe_customer_id'][0]; ?> <h2>Order History</h2> <tr> <td><strong>Order No.</strong></td> <td><strong>Order Date</strong></td> <td><strong>Status</strong></td> <td><strong>Tracking #</strong></td> </tr> <?php $boxes = get_user_boxes($user_id); foreach ($boxes as $box) { ?> <tr> <td><?php echo $box['order_id']; ?> </td> <td><?php echo $box['date_requested']; ?> </td> <td><?php echo $box['ship_status']; ?> </td> <td><?php if ($box['tracking_id'] == '') { if ($box['ship_status'] == 'Awaiting Shipment') { echo 'N/A'; } else { $_SESSION['order_id'] = $box['order_id']; $_SESSION['user_id'] = $user_id; $_SESSION['date_requested'] = $box['date_requested']; ?> <a href="/process-shipments.php" class="button add-new-h2"><?php _e('Sync Shipment', 'wp_crm'); ?> </a> <?php } } else { echo $box['tracking_id']; } ?> </td> </tr> <?php } } ?> </table> <table class="form-table"> <?php if (!empty($wp_crm['data_structure']) && is_array($wp_crm['data_structure']['attributes'])) { ?> <?php foreach (apply_filters('wp_crm_primary_information_attributes', $wp_crm['data_structure']['attributes']) as $slug => $attribute) { /* we already have an Actions box to change user pass, so we can just skip it here */ if ($slug == 'user_pass') { continue; } $row_classes = array(); $row_classes[] = @$attribute['has_options'] ? 'wp_crm_has_options' : 'wp_crm_no_options'; $row_classes[] = @$attribute['required'] == 'true' ? 'wp_crm_required_field' : ''; $row_classes[] = @$attribute['primary'] == 'true' ? 'primary' : 'not_primary'; $row_classes[] = !empty($wp_crm['hidden_attributes'][$user_role]) && is_array($wp_crm['hidden_attributes'][$user_role]) && in_array($slug, $wp_crm['hidden_attributes'][$user_role]) ? 'hidden' : ''; $row_classes[] = 'wp_crm_user_entry_row'; $row_classes[] = "wp_crm_{$slug}_row"; ?> <tr meta_key="<?php echo esc_attr($slug); ?> " wp_crm_input_type="<?php echo esc_attr($attribute['input_type']); ?> " class="<?php echo implode(' ', $row_classes); ?> "> <th> <?php ob_start(); ?> <label for="wp_crm_<?php echo $slug; ?> _field"> <?php echo $attribute['title']; ?> </label> <div class="wp_crm_description"><?php echo !empty($attribute['description']) ? $attribute['description'] : ''; ?> </div> <?php $label = ob_get_contents(); ob_end_clean(); ?> <?php echo apply_filters('wp_crm_user_input_label', $label, $slug, $attribute, $user_object); ?> </th> <td class="wp_crm_user_data_row" wp_crm_attribute="<?php echo $slug; ?> "> <div class="blank_slate hidden" show_attribute="<?php echo $slug; ?> "><?php echo !empty($attribute['blank_message']) ? $attribute['blank_message'] : "Add {$attribute['title']}"; ?> </div> <?php echo WP_CRM_F::user_input_field($slug, !empty($user_object[$slug]) ? $user_object[$slug] : '', $attribute, $user_object); ?> <?php if (isset($attribute['allow_multiple']) && $attribute['allow_multiple'] == 'true') { ?> <div class="add_another"><?php _('Add Another'); ?> </div> <?php } ?> </td> </tr> <?php } ?> <?php } ?> </table> <!--<table class="form-table"> <?php if (isset($_GET['user_id'])) { $user_id = $_GET['user_id']; $user_info = get_user_meta($user_id); $stripe_id = $user_info['stripe_customer_id'][0]; ?> <h2>Order History</h2> <tr> <td><strong>Order No.</strong></td> <td><strong>Order Date</strong></td> <td><strong>Status</strong></td> <td><strong>Tracking #</strong></td> </tr> <?php $boxes = get_user_boxes($user_id); foreach ($boxes as $box) { ?> <tr> <td><?php echo $box['order_id']; ?> </td> <td><?php echo $box['date_requested']; ?> </td> <td><?php echo $box['ship_status']; ?> </td> <td><?php echo $box['tracking_id']; ?> </td> </tr> <?php } } ?> </table>--> <?php }
/** * Check email for duplication */ static function check_email_for_duplicates() { die(WP_CRM_F::check_email_for_duplicates($_REQUEST['email'], $_REQUEST['user_id'])); }
/** * Processes contact form via ajax request. * * @todo add security precautions to filter out potential SQL injections or bad data (such as account escalation) * @version 1.0 * Copyright 2011 Andy Potanin, Usability Dynamics, Inc. <*****@*****.**> */ function process_crm_message() { global $wp_crm; //** Server seems to return nothing somethines, adding space in beginning seems to solve */ /** This needs to be removed - it causes a warning when the header items are set later in the code, when then causes the form NOT to work echo ' '; */ //** watch for spam */ if (!empty($_REQUEST['comment']) || !empty($_REQUEST['email']) || !empty($_REQUEST['name']) || !empty($_REQUEST['url'])) { die(json_encode(array('success' => 'false', 'message' => __('If you see this message, WP-CRM through you were a robot. Please contact admin if you do not think are you one.', 'wp_crm')))); } $data = $_REQUEST['wp_crm']; $crm_action = $_REQUEST['crm_action']; if (empty($data)) { die; } //** Some other security */ if (isset($data['user_data']['user_id'])) { //** Fail - user_id will never be passed in this manner unless somebody is screwing around */ die(json_encode(array('success' => 'false', 'message' => __('Form could not be submitted.', 'wp_crm')))); } $md5_form_slug = $_REQUEST['form_slug']; $associated_object = $_REQUEST['associated_object']; foreach ($wp_crm['wp_crm_contact_system_data'] as $form_slug => $form_data) { if ($md5_form_slug == md5($form_slug)) { $confirmed_form_slug = $form_slug; $confirmed_form_data = $form_data; continue; } } if (!$confirmed_form_slug) { die; } if (isset($data['user_id'])) { //** User ID was passsed. Verify that current user is logged in */ $current_user = wp_get_current_user(); if (0 == $current_user->ID || $data['user_id'] != $current_user->ID) { //** User ID not found, or passed doesn't match. Either way, fail with ambigous messages. die(json_encode(array('success' => 'false', 'message' => __('Form could not be submitted.', 'wp_crm')))); } else { //** We have User ID, we are updating an existing profile */ $data['user_data']['user_id']['default'][] = $current_user->ID; } } //** Get required fields */ foreach ($wp_crm['data_structure']['attributes'] as $field_slug => $field_data) { if ($field_data['required']) { $required_fields[] = $field_slug; } } $check_fields = apply_filters('wp_crm_distinct_user_fields', array('user_email')); //** Do not check any fields if nothing to check */ foreach ($data['user_data'] as $field_slug => $field_data) { foreach ($field_data as $value) { $value = WP_CRM_F::get_first_value($value); //** Check for completion */ if ($wp_crm['data_structure']['attributes'][$field_slug]['required']) { $error = apply_filters('wp_crm_contact_form_data_validation', false, array('field' => $field_slug, 'value' => $value)); if ($error) { $bad_fields[$field_slug] = $error; continue; } if (empty($value)) { $bad_fields[$field_slug] = sprintf(__('%1s cannot be empty.', 'wp_crm'), $wp_crm['data_structure']['attributes'][$field_slug]['title']); } } //** Check for data conlicts */ if (is_array($check_fields) && in_array($field_slug, $check_fields)) { //** Current field needs to be checked to avoid conflict */ if ($conflict_user_id = WP_CRM_F::check_data_field($field_slug, $value)) { if ($data['user_data']['user_id']['default'][0] != $conflict_user_id) { $bad_fields[$field_slug] = sprintf(__('This %1s belongs to a registered user, please login.', 'wp_crm'), $wp_crm['data_structure']['attributes'][$field_slug]['title']); } } } } } //** If this is a validation request, we check to make sure everything is good */ if ($crm_action == 'system_validate') { if ($bad_fields) { die(json_encode(array('success' => true, 'validation_passed' => false, 'bad_fields' => $bad_fields))); } else { die(json_encode(array('success' => true, 'validation_passed' => true))); } } if ($bad_fields) { die(json_encode(array('success' => 'false', 'bad_fields' => $bad_fields, 'message' => __('Form could not be submitted. Please make sure you have entered your information properly.', 'wp_crm')))); } $user_data = @wp_crm_save_user_data($data['user_data'], 'default_role=' . $wp_crm['configuration']['new_contact_role'] . '&use_global_messages=false&match_login=true&no_redirect=true&return_detail=true'); if (!$user_data) { if ($confirmed_form_data['message_field'] == 'on') { //** If contact form includes a message, notify that message could not be sent */ die(json_encode(array('success' => 'false', 'message' => __('Message could not be sent. Please make sure you have entered your information properly.', 'wp_crm')))); } else { //** If contact form DOES NOT include a message, notify that it could not be submitted */ die(json_encode(array('success' => 'false', 'message' => __('Form could not be submitted. Please make sure you have entered your information properly.', 'wp_crm')))); } } else { $user_id = $user_data['user_id']; if ($user_data['new_user']) { //** Log in DB that this account was created automatically via contact form */ update_user_meta($user_id, 'wpc_cm_generated_account', true); } } $message = WP_CRM_F::get_first_value($_REQUEST['wp_crm']['user_data']['message_field']); if ($confirmed_form_data['notify_with_blank_message'] != 'on' && empty($message)) { //** No message submitted */ } else { if (empty($message)) { $message = __(' -- No message. -- ', 'wp_crm'); } //** Message is submitted. Do stuff. */ $message_id = class_contact_messages::insert_message($user_id, $message, $confirmed_form_slug); $associated_object = !empty($associated_object) ? $associated_object : false; if ($associated_object) { class_contact_messages::insert_message_meta($message_id, 'associated_object', $associated_object); } //** Build default notification arguments */ foreach ($wp_crm['data_structure']['attributes'] as $attribute => $attribute_data) { $notification_info[$attribute] = wp_crm_get_value($attribute, $user_id); } $notification_info['message_content'] = stripslashes($message); $notification_info['trigger_action'] = $confirmed_form_data['title']; $notification_info['profile_link'] = admin_url("admin.php?page=wp_crm_add_new&user_id={$user_id}"); /** Add extra filters */ $maybe_notification_info = apply_filters('wp_crm_notification_info', $notification_info, $associated_object); //** Make sure our array wasn't overwritten by a poorly written hooked in function, it shuold never be blank */ if (!empty($maybe_notification_info) || !is_array($maybe_notification_info)) { $notification_info = $maybe_notification_info; } //** Pass the trigger and array of notification arguments to sender function */ wp_crm_send_notification($confirmed_form_slug, $notification_info); } $result = array('success' => 'true', 'message' => $data['success_message']); if (current_user_can('manage_options')) { $result['user_id'] = $user_id; } echo json_encode($result); die; }
/** * Format company on overview page in the main_view cell * * @todo add link to filter down by company * @since 0.1 */ static function wp_crm_display_company($current, $user_id, $user_object, $scope) { if ($scope == 'main_view') { return (WP_CRM_F::get_first_value($user_object['title']) ? WP_CRM_F::get_first_value($user_object['title']) . ' at ' : '') . '<a href="">' . WP_CRM_F::get_first_value($user_object['company']) . '</a>'; } return $current; }
/** * Get search results based on query. * * @todo user_search() should be removed from here since this is a "general" function * */ function prepare_items($wp_crm_search = false, $args = array()) { $args = wp_parse_args($args, array('order_by' => 'user_registered', 'sort_order' => 'DESC')); if (!isset($this->all_items)) { $this->all_items = WP_CRM_F::user_search($wp_crm_search, $args); } //** Do pagination */ if ($this->_args['per_page'] != -1) { $this->item_pages = array_chunk($this->all_items, $this->_args['per_page']); //** figure out what page chunk we are on based on iDisplayStart $this_chunk = $this->_args['iDisplayStart'] / $this->_args['per_page']; //** Get page items */ $this->items = !empty($this->item_pages[$this_chunk]) ? $this->item_pages[$this_chunk] : array(); } else { $this->items = $this->all_items; } }
/** * Displays user activity stream for display. * * @since 0.1 */ function get_user_activity_stream($args = '', $passed_result = false) { global $wpdb, $current_user; $defaults = array(); $args = wp_parse_args($args, $defaults); if (empty($args['user_id'])) { return; } if (isset($messages)) { $result = $passed_result; } if (!$result) { $result = WP_CRM_F::get_events(array('object_id' => $args['user_id'], 'attribute' => array('contact_form_message', 'note'))); } if (!$result) { return; } $result = stripslashes_deep($result); foreach ($result as $entry) { //echo "<pre>";print_r($entry);echo "<pre>"; $entry_classes[] = $entry->attribute; $entry_classes[] = $entry->object_type; $entry_classes[] = $entry->action; $entry_classes = apply_filters('wp_crm_entry_classes', $entry_classes, $entry); $entry_type = apply_filters('wp_crm_entry_type_label', $entry->attribute, $entry); $left_by = $wpdb->get_var("SELECT display_name FROM {$wpdb->users} WHERE ID = '{$entry->user_id}'"); if (empty($left_by)) { // $left_by = __('System', 'wp_crm'); } ?> <tr class="wp_crm_activity_single <?php echo @implode(' ', $entry_classes); ?> "> <td class="left"> <ul class='message_meta'> <li class='timestamp'> <span class='time'><?php echo date(get_option('time_format'), strtotime($entry->time)); ?> </span> <span class='date'><?php echo date(get_option('date_format'), strtotime($entry->time)); ?> </span> </li> <?php if ($entry_type) { ?> <li class="entry_type"><?php echo $entry_type; ?> </li><?php } ?> <?php if ($left_by) { ?> <li class="by_user">by <?php echo $left_by; ?> </li><?php } ?> <li class="wp_crm_log_actions"> <span verify_action="true" instant_hide="true" class="wp_crm_message_quick_action wp_crm_subtle_link" object_id="<?php echo $entry->id; ?> " wp_crm_action="delete_log_entry"><?php _e('Delete'); ?> </span> </li> </ul> </td> <td class="right"> <p class="wp_crm_entry_content"><?php echo apply_filters('wp_crm_activity_single_content', nl2br($entry->text), array('entry' => $entry, 'args' => $args)); ?> </p> </td> </tr> <?php } }
/** * Runs pre-header functions on admin-side only - ran on ALL admin pages * * Checks if plugin has been updated. * * @since 0.1 * */ function admin_init() { global $wp_rewrite, $wp_roles, $wp_crm, $wpdb, $current_user; //** Check if current page is profile page, and load global variable */ WP_CRM_F::maybe_load_profile(); do_action('wp_crm_metaboxes'); //** Add overview table rows. Static because admin_menu is not loaded on ajax calls. */ add_filter("manage_toplevel_page_wp_crm_columns", array('WP_CRM_Core', "overview_columns")); add_action('admin_print_scripts-' . $wp_crm['system']['pages']['settings'], create_function('', "wp_enqueue_script('jquery-ui-tabs');wp_enqueue_script('jquery-cookie');")); add_action('load-crm_page_wp_crm_add_new', array('WP_CRM_Core', 'wp_crm_save_user_data')); // Add metaboxes if (is_array($wp_crm['system']['pages'])) { $sidebar_boxes = array('special_actions'); foreach ($wp_crm['system']['pages'] as $screen) { if (!class_exists($screen)) { continue; } $location_prefixes = array('side_', 'normal_', 'advanced_'); foreach (get_class_methods($screen) as $box) { // Set context and priority if specified for box $context = 'normal'; if (strpos($box, "side_") === 0 || in_array($box, $sidebar_boxes)) { $context = 'side'; } if (strpos($box, "advanced_") === 0) { $context = 'advanced'; } // Get name from slug $label = CRM_UD_F::slug_to_label(str_replace($location_prefixes, '', $box)); add_meta_box($box, $label, array($screen, $box), $screen, $context, 'default'); } } } //** Handle actions */ if (isset($_REQUEST['wp_crm_action'])) { $_wpnonce = $_REQUEST['_wpnonce']; switch ($_REQUEST['wp_crm_action']) { case 'delete_user': $user_id = $_REQUEST['user_id']; if (wp_verify_nonce($_wpnonce, 'wp-crm-delete-user-' . $user_id)) { //** Get IDs of users posts */ $post_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_author = %d", $user_id)); //** Delete user and reassign all their posts to the current user */ if (wp_delete_user($user_id, $current_user->data->ID)) { //** Trash all posts */ if (is_array($post_ids)) { foreach ($post_ids as $trash_post) { wp_trash_post($trash_post); } } wp_redirect(admin_url('admin.php?page=wp_crm&message=user_deleted')); } } break; } } if ($wp_crm['configuration']['replace_default_user_page'] == 'true') { add_filter('admin_user_info_links', array('WP_CRM_Core', 'admin_user_info_links'), 10, 2); } add_filter('admin_title', array('WP_CRM_F', 'admin_title')); }
/** * Handles current screen * * @author peshkov@UD */ static function current_screen($current_screen) { global $current_user, $current_screen; static $called = false; //** Determine if the current screen is profile we re-set it to 'edit user' (crm_page_wp_crm_add_new) screen */ if (is_object($current_screen) && $current_screen->id == 'crm_page_wp_crm_my_profile') { $called = true; if (empty($_REQUEST['user_id'])) { $_GET['user_id'] = $_REQUEST['user_id'] = $current_user->ID; //** Re-set global $wp_crm_user. It was set earlier on admin_init action. */ WP_CRM_F::maybe_load_profile($current_user->ID, true); } $_GET['redirect_to'] = $_REQUEST['redirect_to'] = urlencode(admin_url('admin.php?page=wp_crm_my_profile')); set_current_screen('crm_page_wp_crm_add_new'); } return $current_screen; }
function primary_information($user_object) { global $wp_crm; $user_role = WP_CRM_F::get_first_value($user_object['role']); ?> <table class="form-table"> <?php if (!empty($wp_crm['data_structure']) && is_array($wp_crm['data_structure']['attributes'])) { ?> <?php foreach ($wp_crm['data_structure']['attributes'] as $slug => $attribute) { $row_classes = array(); $row_classes[] = @$attribute['has_options'] ? 'wp_crm_has_options' : 'wp_crm_no_options'; $row_classes[] = @$attribute['required'] == 'true' ? 'wp_crm_required_field' : ''; $row_classes[] = @$attribute['primary'] == 'true' ? 'primary' : 'not_primary'; $row_classes[] = is_array($wp_crm['hidden_attributes'][$user_role]) && in_array($slug, $wp_crm['hidden_attributes'][$user_role]) ? 'hidden' : ''; $row_classes[] = 'wp_crm_user_entry_row'; $row_classes[] = "wp_crm_{$slug}_row"; ?> <tr meta_key="<?php echo esc_attr($slug); ?> " wp_crm_input_type="<?php echo esc_attr($attribute['input_type']); ?> " class="<?php echo implode(' ', $row_classes); ?> "> <th> <?php if (@$attribute['input_type'] != 'checkbox' || isset($attribute['options'])) { ?> <?php ob_start(); ?> <label for="wp_crm_<?php echo $slug; ?> _field"> <?php echo $attribute['title']; ?> </label> <div class="wp_crm_description"><?php echo $attribute['description']; ?> </div> <?php $label = ob_get_contents(); ob_end_clean(); ?> <?php echo apply_filters('wp_crm_user_input_label', $label, $slug, $attribute, $user_object); ?> <?php } ?> </th> <td class="wp_crm_user_data_row" wp_crm_attribute="<?php echo $slug; ?> "> <div class="blank_slate hidden" show_attribute="<?php echo $slug; ?> "><?php echo !empty($attribute['blank_message']) ? $attribute['blank_message'] : "Add {$attribute['title']}"; ?> </div> <?php echo WP_CRM_F::user_input_field($slug, $user_object[$slug], $attribute, $user_object); ?> <?php if (isset($attribute['allow_multiple']) && $attribute['allow_multiple'] == 'true') { ?> <div class="add_another"><?php _('Add Another'); ?> </div> <?php } ?> </td> </tr> <?php } ?> <?php } ?> </table> <?php }
function single_cell($full_column_name, $user_object, $user_id) { global $wp_crm; $column_name = str_replace('wp_crm_', '', $full_column_name); $this_attribute = $wp_crm['data_structure']['attributes'][$column_name]; switch ($column_name) { case 'cb': $r .= "<input type='checkbox' name='users[]' id='user_{$user_id}' value='{$user_id}' />"; break; case 'user_card': $r .= WP_CRM_F::render_user_card(array('user_id' => $user_id, 'user_object' => $user_object, 'full_column_name' => $full_column_name, 'show_user_actions' => true)); break; case 'role': $r .= $role_name; break; case 'posts': if ($numposts > 0) { $r .= "<a href='edit.php?author={$user_id}' title='" . esc_attr__('View posts by this author') . "' class='edit'>"; $r .= $numposts; $r .= '</a>'; } else { $r .= 0; } break; default: if (is_array($user_object[$column_name])) { foreach ($user_object[$column_name] as $option_slug => $values) { if (($this_attribute['input_type'] == 'text' || $this_attribute['input_type'] == 'date' || $this_attribute['input_type'] == 'textarea') && $this_attribute['has_options']) { //** We have a text input with options (dropdown) */ $r .= wp_crm_get_value($column_name, $user_id); } elseif ($wp_crm['data_structure']['attributes'][$column_name]['has_options']) { //** Get label and only show when enabled */ $visible_options = WP_CRM_F::list_options($user_object, $column_name); } else { //** Regular value, no need to get option title */ foreach ($values as $single_value) { $visible_options[] = nl2br($single_value); } } } } if (is_array($visible_options)) { foreach ($visible_options as $key => $single_value) { $visible_options[$key] = nl2br($single_value); } $r .= '<ul><li>' . implode('</li><li>', $visible_options) . '</li></ul>'; } $r = apply_filters('wp_crm_overview_cell', $r, array('column_name' => $column_name, 'user_object' => $user_object, 'user_id' => $user_id)); break; } return $r; }
/** * Render custom attributes metabox * @global array $wp_crm * @param array $post * @param array $metabox * @return null * @author korotkov@ud * @todo Maybe we can use crm_page_wp_crm_add_new::primary_information function for this because they are similar */ static function custom_group_metabox($post, $metabox) { global $wp_crm; if (empty($metabox['args']['fields']) && !is_array($metabox['args']['fields'])) { return; } $user_role = WP_CRM_F::get_first_value($post['role']); ?> <table class="form-table"> <?php if (!empty($wp_crm['data_structure']) && is_array($wp_crm['data_structure']['attributes'])) { ?> <?php foreach ($metabox['args']['fields'] as $slug => $attribute) { $row_classes = array(); $row_classes[] = @$attribute['has_options'] ? 'wp_crm_has_options' : 'wp_crm_no_options'; $row_classes[] = @$attribute['required'] == 'true' ? 'wp_crm_required_field' : ''; $row_classes[] = @$attribute['primary'] == 'true' ? 'primary' : 'not_primary'; $row_classes[] = !empty($wp_crm['hidden_attributes'][$user_role]) && is_array($wp_crm['hidden_attributes'][$user_role]) && in_array($slug, $wp_crm['hidden_attributes'][$user_role]) ? 'hidden' : ''; $row_classes[] = 'wp_crm_user_entry_row'; $row_classes[] = "wp_crm_{$slug}_row"; $continue = apply_filters("wp_crm_before_{$slug}_frontend", array('continue' => false, 'values' => $post[$slug], 'attribute' => $attribute, 'args' => $metabox['args'])); if ($continue['continue']) { continue; } ?> <tr meta_key="<?php echo esc_attr($slug); ?> " wp_crm_input_type="<?php echo esc_attr($attribute['input_type']); ?> " class="<?php echo implode(' ', $row_classes); ?> "> <th> <?php if (@$attribute['input_type'] != 'checkbox' || isset($attribute['options'])) { ?> <?php ob_start(); ?> <label for="wp_crm_<?php echo $slug; ?> _field"> <?php echo $attribute['title']; ?> </label> <div class="wp_crm_description"><?php echo $attribute['description']; ?> </div> <?php $label = ob_get_contents(); ob_end_clean(); ?> <?php echo apply_filters('wp_crm_user_input_label', $label, $slug, $attribute, $post); ?> <?php } ?> </th> <td class="wp_crm_user_data_row" wp_crm_attribute="<?php echo $slug; ?> "> <div class="blank_slate hidden" show_attribute="<?php echo $slug; ?> "><?php echo !empty($attribute['blank_message']) ? $attribute['blank_message'] : "Add {$attribute['title']}"; ?> </div> <?php echo WP_CRM_F::user_input_field($slug, $post[$slug], $attribute, $post); ?> <?php if (isset($attribute['allow_multiple']) && $attribute['allow_multiple'] == 'true') { ?> <div class="add_another"><?php _('Add Another'); ?> </div> <?php } ?> </td> </tr> <?php do_action("wp_crm_after_{$slug}", array('values' => !empty($values) ? $values : false, 'attribute' => $attribute, 'user_object' => !empty($user_object) ? $user_object : false, 'args' => !empty($args) ? $args : array())); } ?> <?php } ?> </table> <?php }
/** * Saves Buddypress profile data. * * @uses WP_CRM_Core::wp_crm_save_user_data() * @param array $data. Request (POST,GET) * @author peshkov@UD */ static function bp_save_profile_data($data) { global $bp; if (empty($data['bp']) || empty($data['user_id'])) { return; } //* Set necessary variables */ $user_id = $data['user_id']; $user_data = $data['wp_crm']['user_data']; $data = $data['bp']; $errors = false; $posted_field_ids = array(); $is_required = array(); //* Set xprofile full name from display_name */ $display_name = WP_CRM_F::get_first_value($user_data['display_name']); if (!empty($display_name)) { $fullname_field_name = bp_xprofile_fullname_field_name(); $fullname_field_id = xprofile_get_field_id_from_name($fullname_field_name); $data["field_{$fullname_field_id}"] = $display_name; } //* Get all posted field ids */ foreach ($data as $name => $value) { $field_id = str_replace(array('field_', '_day', '_month', '_year'), '', $name); array_push($posted_field_ids, $field_id); } $posted_field_ids = array_unique($posted_field_ids); //* Validate the field */ foreach ($posted_field_ids as $field_id) { if (!isset($data['field_' . $field_id])) { if (!empty($data['field_' . $field_id . '_day']) && !empty($data['field_' . $field_id . '_month']) && !empty($data['field_' . $field_id . '_year'])) { /* Concatenate the values */ $date_value = $data['field_' . $field_id . '_day'] . ' ' . $data['field_' . $field_id . '_month'] . ' ' . $data['field_' . $field_id . '_year']; /* Turn the concatenated value into a timestamp */ $data['field_' . $field_id] = date('Y-m-d H:i:s', strtotime($date_value)); } } $is_required[$field_id] = xprofile_check_is_required_field($field_id); if ($is_required[$field_id] && empty($data['field_' . $field_id])) { $errors = true; } } //** There are errors */ if ($errors) { WP_CRM_F::add_message(__('Please make sure you fill in all required Buddypress fields in this profile field group before saving.', ud_get_wp_crm()->domain), 'bad'); //** No errors */ } else { //** Now we've checked for required fields, lets save the values. */ foreach ($posted_field_ids as $field_id) { //** Certain types of fields (checkboxes, multiselects) may come through empty. */ //** Save them as an empty array so that they don't get overwritten by the default on the next edit. */ if (empty($data['field_' . $field_id])) { $value = array(); } else { $value = $data['field_' . $field_id]; } if (!xprofile_set_field_data($field_id, $user_id, $value, $is_required[$field_id])) { $errors = true; } else { do_action('xprofile_profile_field_data_updated', $field_id, $value); } } //** Set the feedback message if we have error */ if ($errors) { WP_CRM_F::add_message(__('There was a problem updating some of Buddypress profile information, please try again.', ud_get_wp_crm()->domain), 'bad'); } } }
/** * Get search results based on query. * * @todo user_search() should be removed from here since this is a "general" function * */ function prepare_items($wp_crm_search = false) { global $role, $usersearch; if (!isset($this->all_items)) { $this->all_items = WP_CRM_F::user_search($wp_crm_search); } //** Do pagination */ if ($this->_args['per_page'] != -1) { $this->item_pages = array_chunk($this->all_items, $this->_args['per_page']); $total_chunks = count($this->item_pages); //** figure out what page chunk we are on based on iDisplayStart $this_chunk = $this->_args['iDisplayStart'] / $this->_args['per_page']; //** Get page items */ $this->items = $this->item_pages[$this_chunk]; } else { $this->items = $this->all_items; } }
<?php /** * Display User Activity Logs * * */ $activity_log = WP_CRM_F::get_detailed_activity_log(); ?> <div class="wrap"> <h2><?php _e('Activity Logs', ud_get_wp_crm()->domain); ?> </h2> <table class="wp_crm_activity_log widefat"> <thead> <tr> <th class="user"><?php _e('User', ud_get_wp_crm()->domain); ?> </th> <th class="activity"><?php _e('Activity', ud_get_wp_crm()->domain); ?> </th> <th class="location"><?php _e('Location', ud_get_wp_crm()->domain); ?> </th>