/** * Define the columns that should be displayed for the KBS ticket post lists screen * * @since 0.1 * @param arr $columns An array of column name ⇒ label. The label is shown as the column header. * @return arr $columns Filtered array of column name => label to be shown as the column header. */ function kbs_set_kbs_ticket_post_columns($columns) { $columns = array('cb' => '<input type="checkbox" />', 'id' => '#', 'dates' => __('Date', 'kb-support'), 'title' => __('Title', 'kb-support'), 'customer' => __('Customer', 'kb-support'), 'categories' => __('Category', 'kb-support'), 'agent' => __('Agent', 'kb-support')); if (kbs_get_option('sla_tracking')) { $columns['sla'] = __('SLA Status', 'kbs-support'); } return apply_filters('kbs_ticket_post_columns', $columns); }
/** * Retrieve all agents. * * @since 1.0 * @param * @return mixed */ function kbs_get_agents() { $role = array('support_agent', 'support_manager'); if (kbs_get_option('admin_agents', false)) { $role[] = 'administrator'; } $users = kbs_get_users_by_role($role); return $users; }
/** * Assigns the currently logged in agent to the ticket if the current * is unassigned. * * @since 1.0 * @return void */ function kbs_auto_assign_agent_to_ticket_action() { if (!isset($_GET['post']) || 'kbs_ticket' != get_post_type($_GET['post']) || !kbs_get_option('auto_assign_agent', false)) { return; } $kbs_ticket = new KBS_Ticket($_GET['post']); if ('new' != $kbs_ticket->post_status || !empty($kbs_ticket->agent)) { return; } kbs_assign_agent($kbs_ticket->ID); }
/** * Whether or not a user can view a KB Article. * * @since 1.0 * @param int|obj $kb_article A KB Article ID or post object. * @param int $user_id The user ID. * @return bool True if the user can view the KB Article. */ function kbs_user_can_view_article($kb_article, $user_id = 0) { if (is_int($kb_article)) { $kb_article = get_post($kb_article); } $can_view = true; $logged_in_only = kbs_get_option('kb_logged_in', false); if ($logged_in_only && !is_user_logged_in()) { $can_view = false; } /** * Allow plugins to filter the response. * * @since 1.0 */ return apply_filters('kbs_user_can_view_article', $can_view, $kb_article, $user_id); }
/** * Register Styles * * Checks the styles option and hooks the required filter. * * @since 1.0 * @return void */ function kbs_register_styles() { if (kbs_get_option('disable_styles', false)) { return; } // Use minified libraries if SCRIPT_DEBUG is turned off $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : ''; //'.min'; $file = 'kbs' . $suffix . '.css'; $templates_dir = kbs_get_theme_template_dir_name(); $child_theme_style_sheet = trailingslashit(get_stylesheet_directory()) . $templates_dir . $file; $child_theme_style_sheet_2 = trailingslashit(get_stylesheet_directory()) . $templates_dir . 'kbs.css'; $parent_theme_style_sheet = trailingslashit(get_template_directory()) . $templates_dir . $file; $parent_theme_style_sheet_2 = trailingslashit(get_template_directory()) . $templates_dir . 'kbs.css'; $kbs_plugin_style_sheet = trailingslashit(kbs_get_templates_dir()) . $file; // Look in the child theme directory first, followed by the parent theme, followed by the KBS core templates directory // Also look for the min version first, followed by non minified version, even if SCRIPT_DEBUG is not enabled. // This allows users to copy just kbs.css to their theme if (file_exists($child_theme_style_sheet) || !empty($suffix) && ($nonmin = file_exists($child_theme_style_sheet_2))) { if (!empty($nonmin)) { $url = trailingslashit(get_stylesheet_directory_uri()) . $templates_dir . 'kbs.css'; } else { $url = trailingslashit(get_stylesheet_directory_uri()) . $templates_dir . $file; } } elseif (file_exists($parent_theme_style_sheet) || !empty($suffix) && ($nonmin = file_exists($parent_theme_style_sheet_2))) { if (!empty($nonmin)) { $url = trailingslashit(get_template_directory_uri()) . $templates_dir . 'kbs.css'; } else { $url = trailingslashit(get_template_directory_uri()) . $templates_dir . $file; } } elseif (file_exists($kbs_plugin_style_sheet) || file_exists($kbs_plugin_style_sheet)) { $url = trailingslashit(kbs_get_templates_url()) . $file; } wp_register_style('kbs-font-awesome', '//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css', array(), KBS_VERSION, 'all'); wp_enqueue_style('kbs-font-awesome'); wp_register_style('kbs-styles', $url, array(), KBS_VERSION, 'all'); wp_enqueue_style('kbs-styles'); }
/** * Get the enabled email template * * @since 0.1 * * @return string|null */ public function get_template() { if (!$this->template) { $this->template = kbs_get_option('email_template', 'default'); } return apply_filters('kbs_email_template', $this->template); }
/** * Whether or not a user needs to be logged in before submitting a ticket. * * @since 1.0 * @return true|false */ function kbs_user_must_be_logged_in() { return kbs_get_option('logged_in_only'); }
/** * Determines the target resolution time for the ticket. * * @since 1.0 * @param * @return str Date/Time for targetted resolution time. */ function kbs_calculate_sla_target_resolution() { $now = current_time('timestamp'); $target = strtotime('+' . kbs_get_option('sla_resolve_time'), $now); return apply_filters('kbs_calculate_sla_target_resolution', date('Y-m-d H:i:s', $target)); }
* @package KB Support/Templates/Emails * @version 0.1 */ if (!defined('ABSPATH')) { exit; } // Exit if accessed directly // For gmail compatibility, including CSS styles in head/body are stripped out therefore styles need to be inline. These variables contain rules which are added to the template inline. !important; is a gmail hack to prevent styles being stripped if it doesn't like something. $body = "\n\tbackground-color: #f6f6f6;\n\tfont-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;\n"; $wrapper = "\n\twidth:100%;\n\t-webkit-text-size-adjust:none !important;\n\tmargin:0;\n\tpadding: 70px 0 70px 0;\n"; $template_container = "\n\tbox-shadow:0 0 0 1px #f3f3f3 !important;\n\tborder-radius:3px !important;\n\tbackground-color: #ffffff;\n\tborder: 1px solid #e9e9e9;\n\tborder-radius:3px !important;\n\tpadding: 20px;\n"; $template_header = "\n\tcolor: #00000;\n\tborder-top-left-radius:3px !important;\n\tborder-top-right-radius:3px !important;\n\tborder-bottom: 0;\n\tfont-weight:bold;\n\tline-height:100%;\n\ttext-align: center;\n\tvertical-align:middle;\n"; $body_content = "\n\tborder-radius:3px !important;\n\tfont-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;\n"; $body_content_inner = "\n\tcolor: #000000;\n\tfont-size:14px;\n\tfont-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;\n\tline-height:150%;\n\ttext-align:left;\n"; $header_content_h1 = "\n\tcolor: #000000;\n\tmargin:0;\n\tpadding: 28px 24px;\n\tdisplay:block;\n\tfont-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;\n\tfont-size:32px;\n\tfont-weight: 500;\n\tline-height: 1.2;\n"; $header_img = kbs_get_option('email_logo', ''); $heading = KBS()->emails->get_heading(); ?> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title><?php echo get_bloginfo('name'); ?> </title> </head> <body leftmargin="0" marginwidth="0" topmargin="0" marginheight="0" offset="0" style="<?php echo $body; ?> ">
/** * Display the ticket files row. * * @since 1.0 * @global obj $kbs_ticket KBS_Ticket class object * @global bool $kbs_ticket_update True if this ticket is being updated, false if new. * @param int $ticket_id The ticket post ID. * @return str */ function kbs_ticket_metabox_files_row($ticket_id) { global $kbs_ticket, $kbs_ticket_update; if (!kbs_get_option('file_uploads')) { return; } ?> <?php if ($kbs_ticket_update && !empty($kbs_ticket->files)) { ?> <div id="kbs-original-ticket-files-wrap" class="kbs_ticket_files_wrap"> <p><strong><?php _e('Attached Files', 'kb-support'); ?> </strong></p> <?php foreach ($kbs_ticket->files as $file) { ?> <p><a href="<?php echo wp_get_attachment_url($file->ID); ?> " target="_blank"><?php echo basename(get_attached_file($file->ID)); ?> </a></p> <?php } ?> </div> <?php } }
/** * Get ticket notification email text * * Returns the stored email text if available, the standard email text if not * * @since 1.0 * @param * @return str $message */ function kbs_get_default_sale_notification_email() { $default_email_body = __('Hello', 'kb-support') . "\n\n" . sprintf(__('A %s has been logged', 'kb-support'), kbs_get_ticket_label_singular()) . ".\n\n"; $default_email_body .= '{ticket_details}' . "\n\n"; $default_email_body .= __('Thank you', 'kb-support'); $message = kbs_get_option('ticket_notification', false); $message = !empty($message) ? $message : $default_email_body; return $message; }
/** * Checks if users can only purchase downloads when logged in * * @since 1.0 * @return bool $ret Whether or not the logged_in_only setting is set */ function kbs_logged_in_only() { $ret = kbs_get_option('logged_in_only', false); return (bool) apply_filters('kbs_logged_in_only', $ret); }
/** * Render the rows for setting field options. * * @since 0.1 * @param int $post_id The form post ID. * @param arr $args Function arguments * @return str */ function kbs_render_field_options_rows($post_id) { global $kbs_edit_field; ?> <div id="kbs_meta_field_select_options_wrap"> <p><strong><?php _e('Options', 'kb-support'); ?> </strong><br /> <label for="kbs_field_select_options"> <?php echo KBS()->html->textarea(array('name' => 'kbs_field_select_options', 'value' => !empty($kbs_edit_field->settings['select_options']) ? implode("\n", $kbs_edit_field->settings['select_options']) : null, 'placeholder' => __('One entry per line', 'kb-support'), 'class' => 'kbs_input')); ?> </label></p> </div> <div id="kbs_meta_field_select_multiple_wrap"> <p><label for="kbs_field_select_multiple"> <?php echo KBS()->html->checkbox(array('name' => 'kbs_field_select_multiple', 'current' => !empty($kbs_edit_field->settings['select_multiple']) ? $kbs_edit_field->settings['select_multiple'] : null)); ?> <strong><?php _e('Multiple Select?', 'kb-support'); ?> </strong></label> </p> </div> <div id="kbs_meta_field_option_selected_wrap"> <p><label for="kbs_field_option_selected"> <?php echo KBS()->html->checkbox(array('name' => 'kbs_field_option_selected', 'current' => !empty($kbs_edit_field->settings['selected']) ? $kbs_edit_field->settings['selected'] : null)); ?> <strong><?php _e('Initially Selected?', 'kb-support'); ?> </strong></label> </p> </div> <div id="kbs_meta_field_select_searchable_wrap"> <p><label for="kbs_field_select_chosen"> <?php echo KBS()->html->checkbox(array('name' => 'kbs_field_select_chosen', 'current' => !empty($kbs_edit_field->settings['chosen']) ? $kbs_edit_field->settings['chosen'] : null)); ?> <strong><?php _e('Searchable?', 'kb-support'); ?> </strong></label> </p> </div> <div id="kbs_meta_field_maxfiles_wrap"> <p><strong><?php _e('Maximum Files', 'kb-support'); ?> </strong><br /> <label for="kbs_field_maxfiles"> <?php echo KBS()->html->number(array('name' => 'kbs_field_maxfiles', 'value' => !empty($kbs_edit_field->settings['maxfiles']) ? $kbs_edit_field->settings['maxfiles'] : null, 'class' => 'small-text kbs_input', 'min' => 1, 'max' => kbs_get_option('file_uploads'))); ?> </label></p> </div> <div id="kbs_meta_field_placeholder_wrap"> <p><strong><?php _e('Placeholder', 'kb-support'); ?> </strong><br /> <label for="kbs_field_placeholder"> <?php echo KBS()->html->text(array('name' => 'kbs_field_placeholder', 'value' => !empty($kbs_edit_field->settings['placeholder']) ? $kbs_edit_field->settings['placeholder'] : null, 'class' => 'kbs_input')); ?> </label></p> </div> <div id="kbs_meta_field_hide_label_wrap"> <p><label for="kbs_field_hide_label"> <?php echo KBS()->html->checkbox(array('name' => 'kbs_field_hide_label', 'current' => !empty($kbs_edit_field->settings['hide_label']) ? $kbs_edit_field->settings['hide_label'] : null)); ?> <strong><?php _e('Hide Label?', 'kb-support'); ?> </strong></label> </p> </div> <?php }
/** * Ticket Notification Template Body * * @since 0.1 * @param int $ticket_id Ticket ID * @param arr $ticket_data Ticket Data * @return str $email_body Body of the email */ function kbs_get_ticket_notification_body_content($ticket_id = 0, $ticket_data = array()) { $user_info = maybe_unserialize($ticket_data['user_info']); if (isset($user_info['id']) && $user_info['id'] > 0) { $user_data = get_userdata($user_info['id']); $name = $user_data->display_name; } elseif (isset($user_info['first_name']) && isset($user_info['last_name'])) { $name = $user_info['first_name'] . ' ' . $user_info['last_name']; } else { $name = $email; } $default_email_body = __('Hello', 'kb-support') . "\n\n" . sprintf(__('A Support %s has been received', 'kb-support'), kbs_get_ticket_label_plural()) . ".\n\n"; $default_email_body .= sprintf(__('%s sold:', 'kb-support'), kbs_get_ticket_label_plural()) . "\n\n"; $default_email_body .= $download_list . "\n\n"; $default_email_body .= __('Submitted by: ', 'kb-support') . " " . html_entity_decode($name, ENT_COMPAT, 'UTF-8') . "\n"; $default_email_body .= __('Thank you', 'kb-support'); $email = kbs_get_option('ticket_notification', false); $email = $email ? stripslashes($email) : $default_email_body; $email_body = kbs_email_template_tags($email, $ticket_data, $ticket_id, true); $email_body = kbs_do_email_tags($email, $ticket_id); $email_body = apply_filters('kbs_email_template_wpautop', true) ? wpautop($email_body) : $email_body; return apply_filters('kbs_ticket_notification', $email_body, $ticket_id, $ticket_data); }
/** * Display a form file upload field. * * @since 1.0 * @param obj $field Field post object * @param arr $settings Field settings * @return str $type input field */ function kbs_display_form_file_upload_field($field, $settings) { if (!kbs_file_uploads_are_enabled()) { return; } $placeholder = !empty($settings['placeholder']) ? ' placeholder="' . esc_attr($settings['placeholder']) . '"' : ''; $class = !empty($settings['input_class']) ? esc_attr($settings['input_class']) : ''; $multiple = kbs_get_option('file_uploads') > 1 ? ' multiple' : ''; $class = implode(' ', array_map('sanitize_html_class', explode(' ', $class))); do_action('kbs_before_form_field', $field, $settings); do_action('kbs_before_form_' . $settings['type'] . '_field', $field, $settings); $output = sprintf('<input type="file" name="%1$s[]" id="%1$s"%2$s%3$s%4$s />', esc_attr($field->post_name), !empty($class) ? ' class="' . $class . ' kbs-input"' : '', $placeholder, $multiple); $output = apply_filters('kbs_display_form_file_upload_field', $output, $field, $settings); echo $output; do_action('kbs_after_form_field', $field, $settings); do_action('kbs_after_form_' . $settings['type'] . '_field', $field, $settings); }
/** * Validate a ticket submission form. * * @since 1.0 * @return void */ function kbs_ajax_validate_form_submission() { $form = new KBS_Form($_POST['kbs_form_id']); $error = false; $agree_to_terms = kbs_get_option('show_agree_to_terms', false); foreach ($form->get_fields() as $field) { $settings = $form->get_field_settings($field->ID); if (!empty($settings['required']) && empty($_POST[$field->post_name])) { $error = kbs_form_submission_errors($field->ID, 'required'); $field = $field->post_name; } elseif ('email' == $settings['type'] || 'customer_email' == $settings['mapping']) { if (!is_email($_POST[$field->post_name])) { $error = kbs_form_submission_errors($field->ID, 'invalid_email'); $field = $field->post_name; } } if ($error) { wp_send_json(array('error' => $error, 'field' => $field)); } } if ($agree_to_terms && empty($_POST['kbs_agree_terms'])) { wp_send_json(array('error' => kbs_form_submission_errors(0, 'agree_to_terms'), 'field' => 'kbs_agree_terms')); } wp_send_json_success(array('error' => $error)); }