/** * Registration page shortcode. */ function wpas_sc_client_account() { global $wpas_tickets, $current_user, $post; /** * For some reason when the user ID is set to 0 * the query returns posts whose author has ID 1. * In order to avoid that (for non logged users) * we set the user ID to -1 if it is 0. * * @var integer */ $author = 0 !== $current_user->ID ? $current_user->ID : -1; $args = apply_filters('wpas_tickets_shortcode_query_args', array('author' => $author, 'post_type' => 'ticket', 'post_status' => 'any', 'order' => 'DESC', 'orderby' => 'date', 'posts_per_page' => -1, 'no_found_rows' => false, 'cache_results' => false, 'update_post_term_cache' => false, 'update_post_meta_cache' => false)); $wpas_tickets = new WP_Query($args); /* Get the ticket content */ ob_start(); /** * wpas_frontend_plugin_page_top is executed at the top * of every plugin page on the front end. */ do_action('wpas_frontend_plugin_page_top', $post->ID, $post); /** * wpas_before_tickets_list hook */ do_action('wpas_before_tickets_list'); /* If user is not logged in we display the register form */ if (!is_user_logged_in()) { $registration = wpas_get_option('login_page', false); if (false !== $registration && !empty($registration) && !is_null(get_post(intval($registration)))) { /* As the headers are already sent we can't use wp_redirect. */ echo '<meta http-equiv="refresh" content="0; url=' . get_permalink($registration) . '" />'; wpas_get_notification_markup('info', __('You are being redirected...', 'awesome-support')); exit; } wpas_get_template('registration'); } else { /** * Get the custom template. */ wpas_get_template('list'); } /** * wpas_after_tickets_list hook */ do_action('wpas_after_tickets_list'); /** * Finally get the buffer content and return. * * @var string */ $content = ob_get_clean(); return $content; }
/** * Alter page content for single ticket. * * In order to ensure maximum compatibility with all themes, * we hook onto the_content instead of changing the entire template * for ticket single. * * However, if the theme author has customized the single ticket template * we do not apply those modifications as the custom template will do the job. * * @since 3.0.0 * @param string $content Post content * @return string Ticket single */ function wpas_single_ticket($content) { global $post; $slug = 'ticket'; /* Don't touch the admin */ if (is_admin()) { return $content; } /* Only apply this on the ticket single. */ if ($post && $slug !== $post->post_type) { return $content; } /* Only apply this on the main query. */ if (!is_main_query()) { return $content; } /* Only apply this if it's inside of a loop. */ if (!in_the_loop()) { return $content; } /* Remove the filter to avoid infinite loops. */ remove_filter('the_content', 'wpas_single_ticket'); /* Check if the current user can view the ticket */ if (!wpas_can_view_ticket($post->ID)) { if (is_user_logged_in()) { return wpas_get_notification_markup('failure', __('You are not allowed to view this ticket.', 'awesome-support')); } else { $output = ''; $output .= wpas_get_notification_markup('failure', __('You are not allowed to view this ticket.', 'awesome-support')); ob_start(); wpas_get_template('registration'); $output .= ob_get_clean(); return $output; } } /* Get template name */ $template_path = get_page_template(); $template = explode('/', $template_path); $count = count($template); $template = $template[$count - 1]; /* Don't apply the modifications on a custom template */ if ("single-{$slug}.php" === $template) { return $content; } /* Get the ticket content */ ob_start(); /** * wpas_frontend_plugin_page_top is executed at the top * of every plugin page on the front end. */ do_action('wpas_frontend_plugin_page_top', $post->ID, $post); /** * Get the custom template. */ wpas_get_template('details'); /** * Finally get the buffer content and return. * * @var string */ $content = ob_get_clean(); return $content; }
/** * Submission for shortcode. */ function wpas_sc_submit_form() { global $post; /* Start the buffer */ ob_start(); /* Open main container */ ?> <div class="wpas"><?php /** * wpas_before_ticket_submit hook */ do_action('wpas_before_ticket_submit'); /** * wpas_frontend_plugin_page_top is executed at the top * of every plugin page on the front end. */ do_action('wpas_frontend_plugin_page_top', $post->ID, $post); /* If user is not logged in we display the register form */ if (!is_user_logged_in()) { $registration = wpas_get_option('login_page', false); if (false !== $registration && !empty($registration) && !is_null(get_post(intval($registration)))) { /* As the headers are already sent we can't use wp_redirect. */ echo '<meta http-equiv="refresh" content="0; url=' . get_permalink($registration) . '" />'; echo wpas_get_notification_markup('info', __('You are being redirected...', 'wpas')); exit; } wpas_get_template('registration'); /** * If user is logged in we display the ticket submission form */ } else { /** * wpas_before_ticket_submission_form hook */ do_action('wpas_before_ticket_submission_form_before_wrapper'); /* Namespace our content */ echo '<div class="wpas">'; /** * wpas_before_all_templates hook. * * This hook is called at the top of every template * used for the plugin front-end. This allows for adding actions * (like notifications for instance) on all plugin related pages. */ do_action('wpas_before_all_templates'); /** * wpas_before_ticket_submission_form hook */ do_action('wpas_before_ticket_submission_form'); /** * Check if the current user is logged in */ if (false === is_user_logged_in()) { echo wpas_get_notification_markup('failure', sprintf(__('You need to <a href="%s">log-in</a> to submit a ticket.', 'wpas'), esc_url(''))); } else { /** * Make sure the current user can submit a ticket. */ if (false === wpas_can_submit_ticket()) { echo wpas_get_notification_markup('failure', __('You are not allowed to submit a ticket.', 'wpas')); } else { /** * We check if the user is authorized to submit a ticket. * User must be logged-in and can't have the capability. If the * user isn't authorized to submit, we return the error message hereafter. * * Basically, admins and agents aren't allowed to submit a ticket as they * need to do it in the back-end. * * If you want to allow admins and agents to submit tickets through the * front-end, please use the filter wpas_agent_submit_front_end and set the value to (bool) true. */ if (is_user_logged_in() && current_user_can('edit_ticket') && false === apply_filters('wpas_agent_submit_front_end', false)) { /** * Keep in mind that if you allow agents to open ticket through the front-end, actions * will not be tracked. */ echo wpas_get_notification_markup('info', sprintf(__('Sorry, support team members cannot submit tickets from here. If you need to open a ticket, please go to your admin panel or <a href="%s">click here to open a new ticket</a>.', 'wpas'), add_query_arg(array('post_type' => 'ticket'), admin_url('post-new.php')))); /** * If the user is authorized to post a ticket, we display the submit form */ } else { global $post; /** * wpas_submission_form_before hook * * @since 3.0.0 */ do_action('wpas_submission_form_before'); wpas_get_template('submission'); /** * wpas_submission_form_after hook * * @since 3.0.0 */ do_action('wpas_submission_form_after'); } } } /** * wpas_after_ticket_submission_form hook */ do_action('wpas_after_ticket_submission_form'); echo '</div>'; } /** * wpas_after_ticket_submit hook */ do_action('wpas_after_ticket_submit'); ?> </div> <?php /* Get buffer content */ $sc = ob_get_contents(); /* Clean the buffer */ ob_end_clean(); /* Return shortcode's content */ return $sc; }
// Check if we need to force displaying all the replies (direct link to a specific reply for instance) if (true === $force_all_replies) { $replies_per_page = -1; WPAS()->session->clean('force_all_replies'); // Clean the session } $args = array('posts_per_page' => $replies_per_page, 'no_found_rows' => false); $replies = wpas_get_replies($post->ID, array('read', 'unread'), $args, 'wp_query'); if ($replies->have_posts()) { while ($replies->have_posts()) { $replies->the_post(); $user = get_userdata($post->post_author); $user_role = get_the_author_meta('roles'); $user_role = $user_role[0]; $time_ago = human_time_diff(get_the_time('U', $post->ID), current_time('timestamp')); wpas_get_template('partials/ticket-reply', array('time_ago' => $time_ago, 'user' => $user, 'post' => $post)); } } wp_reset_query(); ?> </tbody> </table> <?php if ($replies_per_page !== -1 && (int) $replies->found_posts > $replies_per_page) { $current = $replies->post_count; $total = (int) $replies->found_posts; ?> <div class="wpas-alert wpas-alert-info wpas-pagi"> <div class="wpas-pagi-loader"><?php
/** * Registration page shortcode. */ function wpas_sc_client_account() { global $wpas_tickets, $current_user, $post; /** * For some reason when the user ID is set to 0 * the query returns posts whose author has ID 1. * In order to avoid that (for non logged users) * we set the user ID to -1 if it is 0. * * @var integer */ $author = 0 !== $current_user->ID ? $current_user->ID : -1; // Custom Code By spgandhi@live.com if (isset($_GET['view'])) { $view = $_GET['view']; } else { $view = 'mine'; } // End - Custom Code by spgandhi@live.com $args = array('post_type' => 'ticket', 'post_status' => 'any', 'order' => 'DESC', 'orderby' => 'date', 'posts_per_page' => -1, 'no_found_rows' => false, 'cache_results' => false, 'update_post_term_cache' => false, 'update_post_meta_cache' => false); // Custom Code by spgandhi@live.com if ($view == 'mine') { $args['author'] = $author; } else { if ($view == 'hmc') { if (current_user_can('supervisor_view')) { echo '<h3>You will see all complains here.</h3>'; } else { if (current_user_can('hmc_view')) { $current_user_id = wp_get_current_user()->ID; $wing = get_user_meta($current_user_id, 'pie_dropdown_4', true); $room = get_user_meta($current_user_id, 'pie_number_5', true); $room_start = substr($room, 0, 1); $args['meta_query'] = array('relation' => 'AND', array('key' => '_wpas_wing', 'value' => $wing), array('key' => '_wpas_room_no', 'value' => array($room_start * 100, $room_start * 100 + 20), 'type' => 'numeric', 'compare' => 'BETWEEN')); echo '<h3>You will see all the complains of your floor here.</h3>'; $args['meta_key'] = '_wpas_wing'; $args['meta_value'] = $wing; } else { $args['author'] = $author; } } } else { $args['author'] = $author; } } // End - Custom code by spgandhi@live.com $wpas_tickets = new WP_Query($args); /* Get the ticket content */ ob_start(); /** * wpas_frontend_plugin_page_top is executed at the top * of every plugin page on the front end. */ do_action('wpas_frontend_plugin_page_top', $post->ID, $post); /** * wpas_before_tickets_list hook */ do_action('wpas_before_tickets_list'); /* If user is not logged in we display the register form */ if (!is_user_logged_in()) { $registration = wpas_get_option('login_page', false); if (false !== $registration && !empty($registration) && !is_null(get_post(intval($registration)))) { /* As the headers are already sent we can't use wp_redirect. */ echo '<meta http-equiv="refresh" content="0; url=' . get_permalink($registration) . '" />'; wpas_get_notification_markup('info', __('You are being redirected...', 'awesome-support')); exit; } wpas_get_template('registration'); } else { /** * Get the custom template. */ wpas_get_template('list'); } /** * wpas_after_tickets_list hook */ do_action('wpas_after_tickets_list'); /** * Finally get the buffer content and return. * * @var string */ $content = ob_get_clean(); return $content; }
/** * Ajax function that returns a number of ticket replies * * @since 3.3 * @return void */ function wpas_get_ticket_replies_ajax() { // Make sure we have a ticket ID to work with if (!isset($_POST['ticket_id'])) { echo json_encode(array('error' => esc_html__('No ticket ID given', 'awesome-support'))); die; } $ticket_id = (int) $_POST['ticket_id']; $offset = isset($_POST['ticket_replies_total']) ? (int) $_POST['ticket_replies_total'] : 0; $ticket = get_post($ticket_id); // Make sure the ID exists if (!is_object($ticket) || !is_a($ticket, 'WP_Post')) { echo json_encode(array('error' => esc_html__('Invalid ticket ID', 'awesome-support'))); die; } // Make sure the post is actually a ticket if ('ticket' !== $ticket->post_type) { echo json_encode(array('error' => esc_html__('Given ID is not a ticket', 'awesome-support'))); die; } $number_replies = apply_filters('wpas_get_ticket_replies_ajax_replies', wpas_get_option('replies_per_page', 10)); $replies = wpas_get_replies($ticket_id, 'any', array('posts_per_page' => $number_replies, 'no_found_rows' => false, 'offset' => $offset), 'wp_query'); if (empty($replies->posts)) { echo json_encode(array()); die; } $output = array('total' => (int) $replies->found_posts, 'current' => $offset + (int) $replies->post_count, 'html' => ''); $html = array(); while ($replies->have_posts()) { $replies->the_post(); $user = get_userdata($replies->post->post_author); $time_ago = human_time_diff(get_the_time('U', $replies->post->ID), current_time('timestamp')); ob_start(); wpas_get_template('partials/ticket-reply', array('time_ago' => $time_ago, 'user' => $user, 'post' => $replies->post)); $reply = ob_get_contents(); ob_end_clean(); $html[] = $reply; } $output['html'] = implode('', $html); echo json_encode($output); die; }
/** * Load Awesome Support's theme functions if any * * @since 3.2.0 * @return void */ function wpas_load_theme_functions() { wpas_get_template('functions'); }
<?php /* Get the tickets object */ global $wpas_tickets; if ($wpas_tickets->have_posts()) { $columns = wpas_get_tickets_list_columns(); ?> <div class="wpas wpas-ticket-list"> <?php wpas_get_template('partials/ticket-navigation'); ?> <!-- Filters & Search tickets --> <div class="wpas-row" id="wpas_ticketlist_filters"> <div class="wpas-one-third"> <select class="wpas-form-control wpas-filter-status"> <option value=""><?php esc_html_e('Any status', 'awesome-support'); ?> </option> </select> </div> <div class="wpas-one-third"></div> <div class="wpas-one-third" id="wpas_filter_wrap"> <input class="wpas-form-control" id="wpas_filter" type="text" placeholder="<?php esc_html_e('Search tickets...', 'awesome-support'); ?> "> <span class="wpas-clear-filter" title="<?php esc_html_e('Clear Filter', 'awesome-support');
/** * Load Awesome Support's theme functions if any * * @since 3.2.0 * @return void */ public function load_theme_functions() { wpas_get_template('functions'); }
/** * Retrieve the e-mail template to use and input the content * * @since 3.3.3 * * @param string $content The e-mail contents to inject into the template * * @return string */ private function get_formatted_email($content = '') { if (false === (bool) wpas_get_option('use_email_template', true)) { return $content; } ob_start(); // Get the e-mail notification template. This template can be customized by the user. // See https://getawesomesupport.com/documentation-new/documentation-awesome-support-core-customization/ wpas_get_template('email-notification'); $template = ob_get_contents(); // Clean buffer ob_end_clean(); $template = str_replace('{content}', wpautop($content), $template); // Inject content $template = str_replace('{footer}', wpas_get_option('email_template_footer', ''), $template); // Inject footer $template = str_replace('{header}', wpas_get_option('email_template_header', ''), $template); // Inject header if ('' !== ($logo = wpas_get_option('email_template_logo', ''))) { $logo = wp_get_attachment_image_src($logo, 'full'); $logo = '<img src="' . $logo[0] . '">'; } $template = str_replace('{logo}', $logo, $template); // Inject logo return $template; }