Exemplo n.º 1
1
/**
 * Add ticket count in admin menu item.
 *
 * @return boolean True if the ticket count was added, false otherwise
 * @since  1.0.0
 */
function wpas_tickets_count()
{
    if (false === (bool) wpas_get_option('show_count')) {
        return false;
    }
    global $menu, $current_user;
    if (current_user_can('administrator') && false === boolval(wpas_get_option('admin_see_all')) || !current_user_can('administrator') && current_user_can('edit_ticket') && false === boolval(wpas_get_option('agent_see_all'))) {
        $agent = new WPAS_Member_Agent($current_user->ID);
        $count = $agent->open_tickets();
    } else {
        $count = count(wpas_get_tickets('open'));
    }
    if (0 === $count) {
        return false;
    }
    foreach ($menu as $key => $value) {
        if ($menu[$key][2] == 'edit.php?post_type=ticket') {
            $menu[$key][0] .= ' <span class="awaiting-mod count-' . $count . '"><span class="pending-count">' . $count . '</span></span>';
        }
    }
    return true;
}
/**
 * Check if the ticket is old.
 *
 * A simple check based on the value of the "Ticket old" option.
 * If the last reply (or the ticket itself if no reply) is older
 * than the post date + the allowed delay, then it is considered old.
 *
 * @since  3.0.0
 * @param  integer $post_id The ID of the ticket to check
 * @param  object  $latest  The object containing the ticket replies. If the object was previously generated we pass it directly in order to avoid re-querying
 * @return boolean          True if the ticket is old, false otherwise
 */
function wpas_is_ticket_old($post_id, $latest = null)
{
    if ('closed' === wpas_get_ticket_status($post_id)) {
        return false;
    }
    /* Prepare the new object */
    if (is_null($latest)) {
        $latest = new WP_Query(array('posts_per_page' => 1, 'orderby' => 'post_date', 'order' => 'DESC', 'post_type' => 'ticket_reply', 'post_parent' => $post_id, 'post_status' => array('unread', 'read'), 'no_found_rows' => true, 'cache_results' => false, 'update_post_term_cache' => false, 'update_post_meta_cache' => false));
    }
    /**
     * We check when was the last reply (if there was a reply).
     * Then, we compute the ticket age and if it is considered as 
     * old, we display an informational tag.
     */
    if (empty($latest->posts)) {
        $post = get_post($post_id);
        /* We get the post date */
        $date_created = $post->post_date;
    } else {
        /* We get the post date */
        $date_created = $latest->post->post_date;
    }
    $old_after = wpas_get_option('old_ticket');
    if (strtotime("{$date_created} +{$old_after} days") < strtotime('now')) {
        return true;
    }
    return false;
}
Exemplo n.º 3
0
 /**
  * Return the field markup for the front-end.
  *
  * @return string Field markup
  */
 public function display()
 {
     $editor = '';
     /**
      * Check if the description field should use the WYSIWYG editor
      *
      * @var string
      */
     $wysiwyg = boolval(wpas_get_option('frontend_wysiwyg_editor'));
     if (true === $wysiwyg || is_admin()) {
         $editor_defaults = array('media_buttons' => false, 'textarea_name' => $this->get_field_id(), 'textarea_rows' => 10, 'tabindex' => 2, 'editor_class' => $this->get_field_class(), 'quicktags' => false, 'tinymce' => array('toolbar1' => 'bold,italic,underline,strikethrough,hr,|,bullist,numlist,|,link,unlink', 'toolbar2' => ''));
         /* Merge custom editor settings if any */
         $args = isset($this->field_args['editor']) && is_array($this->field_args['editor']) ? wp_parse_args($this->field_args['editor'], $editor_defaults) : $editor_defaults;
         $wysiwyg_id = str_replace('_', '-', $this->get_field_id());
         // The codex says the opposite, but underscores causes issues while hyphens don't. Weird...
         ob_start();
         wp_editor($this->populate(), $wysiwyg_id, $args);
         /* Get the buffered content into a var */
         $editor = ob_get_contents();
         /* Clean buffer */
         ob_end_clean();
         $editor = "<label {{label_atts}}>{{label}}</label><div class='wpas-submit-ticket-wysiwyg'>{$editor}</div>";
     } else {
         $path = WPAS_PATH . "includes/custom-fields/field-types/class-cf-textarea.php";
         if (file_exists($path)) {
             include_once $path;
             $textarea = new WPAS_CF_Textarea($this->field_id, $this->field);
             $editor = $textarea->display();
         }
     }
     return $editor;
 }
Exemplo n.º 4
0
/**
 * Upgrade function for version 3.2.0
 *
 * @since 3.2.0
 * @return void
 */
function wpas_upgrade_320()
{
    $registrations = (bool) wpas_get_option('allow_registrations', true);
    if (true === $registrations) {
        wpas_update_option('allow_registrations', 'allow');
    } else {
        wpas_update_option('allow_registrations', 'disallow');
    }
}
Exemplo n.º 5
0
 /**
  * Return the field markup for the front-end.
  *
  * @return string Field markup
  */
 public function display()
 {
     $multiple = true === $this->field_args['multiple'] ? 'multiple' : '';
     $filetypes = explode(',', apply_filters('wpas_attachments_filetypes', wpas_get_option('attachments_filetypes')));
     $accept = array();
     foreach ($filetypes as $key => $type) {
         $filetypes[$key] = "<code>.{$type}</code>";
         array_push($accept, ".{$type}");
     }
     $accept = implode(',', $accept);
     return sprintf('<label {{label_atts}}>{{label}}</label><input type="file" value="%s" {{atts}} accept="%s" %s>', $this->populate(), $accept, $multiple);
 }
/**
 * 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;
}
/**
 * Add link to agent's tickets.
 *
 * @since  3.0.0
 *
 * @param  object $wp_admin_bar The WordPress toolbar object
 *
 * @return void
 */
function wpas_toolbar_tickets_link($wp_admin_bar)
{
    if (!current_user_can('edit_ticket')) {
        return;
    }
    $hide = (bool) wpas_get_option('hide_closed');
    $agent_see_all = (bool) wpas_get_option('agent_see_all');
    $admin_see_all = (bool) wpas_get_option('admin_see_all');
    $args = array('post_type' => 'ticket');
    // In case the current user can only see his own tickets
    if (current_user_can('administrator') && false === $admin_see_all || !current_user_can('administrator') && false === $agent_see_all) {
        global $current_user;
        $agent = new WPAS_Member_Agent($current_user->ID);
        $tickets_count = $agent->open_tickets();
    } else {
        $tickets_count = count(wpas_get_tickets('open', $args));
    }
    if (true === $hide) {
        $args['wpas_status'] = 'open';
    }
    $node = array('id' => 'wpas_tickets', 'parent' => null, 'group' => null, 'title' => '<span class="ab-icon"></span> ' . $tickets_count, 'href' => add_query_arg($args, admin_url('edit.php')), 'meta' => array('target' => '_self', 'title' => esc_html__('Open tickets assigned to you', 'awesome-support'), 'class' => 'wpas-my-tickets'));
    $wp_admin_bar->add_node($node);
}
function as_pastebin_send_paste($data = array())
{
    if (empty($data) && !empty($_POST)) {
        $data = $_POST;
    }
    // Make sure we have data to paste
    if (empty($data)) {
        return new WP_Error('no_data', esc_html__('Not data to send to Pastebin', 'as-pastebin'));
    }
    $post_id = isset($data['post_id']) ? (int) $data['post_id'] : '';
    // Make sure we have a post to attach the paste to
    if (empty($post_id)) {
        return new WP_Error('no_post_id', esc_html__('Impossible to identify the post to which this paste is related', 'as-pastebin'));
    }
    $post = get_post($post_id);
    // Make sure the post is either a ticket or a ticket reply
    if (!is_object($post) || !is_a($post, 'WP_Post') || !in_array($post->post_type, array('ticket', 'ticket_reply'))) {
        return new WP_Error('no_ticket', esc_html__('A paste must be attached to a ticket or a reply only', 'as-pastebin'));
    }
    $dev_key = trim(wpas_get_option('pastebin_dev_key', ''));
    // A developer key is required for using Pastebin API
    if (empty($dev_key)) {
        return new WP_Error('no_dev_key', esc_html__('A developer API key is required', 'as-pastebin'));
    }
    // Make sure we have some code to paste
    if (empty($data['code'])) {
        return new WP_Error('no_code', esc_html__('There is no code to paste', 'as-pastebin'));
    }
    // Get the code format and fallback on default if there is no format in $data
    $format = isset($data['paste_format']) && !empty($data['paste_format']) ? filter_input('string', $data['paste_format']) : wpas_get_option('pastebin_paste_format', '');
    // Get the paste name
    $name = isset($data['paste_name']) && !empty($data['paste_name']) ? filter_input('string', $data['paste_name']) : "Paste for post ";
    $args = array('body' => array('api_option' => 'paste', 'api_paste_private' => wpas_get_option('pastebin_paste_private', '1'), 'api_paste_name' => sanitize_text_field($name), 'api_paste_expire_date' => wpas_get_option('pastebin_paste_expire', '10M'), 'api_paste_format' => $format, 'api_dev_key' => $dev_key, 'api_paste_code' => $data['code']));
    $response = wp_remote_post(esc_url('http://pastebin.com/api/api_post.php'), $args);
    return $response;
}
 protected function get_api_key()
 {
     return wpas_get_option('mailgun_api_key', '');
 }
Exemplo n.º 10
0
/**
 * 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;
}
 /**
  * Add status dropdown in the filters bar.
  *
  * @since  2.0.0
  * @return void
  */
 public function status_filter()
 {
     global $typenow;
     if ('ticket' != $typenow) {
         echo '';
     }
     if (isset($_GET['post_status'])) {
         echo '';
     }
     $this_sort = isset($_GET['wpas_status']) ? filter_input(INPUT_GET, 'wpas_status', FILTER_SANITIZE_STRING) : '';
     $all_selected = '' === $this_sort ? 'selected="selected"' : '';
     $open_selected = !isset($_GET['wpas_status']) && true === (bool) wpas_get_option('hide_closed') || 'open' === $this_sort ? 'selected="selected"' : '';
     $closed_selected = 'closed' === $this_sort ? 'selected="selected"' : '';
     $dropdown = '<select id="wpas_status" name="wpas_status">';
     $dropdown .= "<option value='' {$all_selected}>" . __('Any Status', 'wpas') . "</option>";
     $dropdown .= "<option value='open' {$open_selected}>" . __('Open', 'wpas') . "</option>";
     $dropdown .= "<option value='closed' {$closed_selected}>" . __('Closed', 'wpas') . "</option>";
     $dropdown .= '</select>';
     echo $dropdown;
 }
Exemplo n.º 13
0
 /**
  * Limit upload filetypes.
  *
  * Gets the list of allowed file extensions from the plugin settings
  * and compare the processed file. If the extension is not in the list we
  * simply return an error message to prevent uploading it.
  *
  * @since  3.0.0
  * @param  array $file Currently processed file details
  * @return array       File details with a possible error message
  */
 public function limit_upload($file)
 {
     global $post;
     if (empty($post)) {
         $protocol = stripos($_SERVER['SERVER_PROTOCOL'], 'https') === true ? 'https://' : 'http://';
         $post_id = url_to_postid($protocol . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']);
         $post = get_post($post_id);
     }
     $submission = (int) wpas_get_option('ticket_submit');
     $post_type = filter_input(INPUT_GET, 'post_type', FILTER_SANITIZE_STRING);
     /**
      * On the front-end we only want to limit upload size
      * on the submission page or on a ticket details page.
      */
     if (!is_admin()) {
         if ('ticket' !== $post->post_type && $submission !== $post->ID) {
             return $file;
         }
     }
     /**
      * In the admin we only want to limit upload size on the ticket creation screen
      * or on the ticket edit screen.
      */
     if (is_admin()) {
         if (!isset($post) && empty($post_type)) {
             return $file;
         }
         if (isset($post) && 'ticket' !== $post->post_type) {
             return $file;
         }
         if (!empty($post_type) && 'ticket' !== $post_type) {
             return $file;
         }
     }
     $filetypes = explode(',', $this->get_allowed_filetypes());
     $ext = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION));
     $max_size = wpas_get_option('filesize_max', 1);
     $max_size_bytes = $max_size * 1024 * 1024;
     if (!in_array($ext, $filetypes)) {
         $file['error'] = sprintf(__('You are not allowed to upload files of this type (%s)', 'awesome-support'), $ext);
     }
     if ($file['size'] <= 0) {
         $file['error'] = __('You cannot upload empty attachments. You attachments weights 0 bytes', 'awesome-support');
     }
     if ($file['size'] > $max_size_bytes) {
         $file['error'] = sprintf(__('Your attachment is too big. You are allowed to attach files up to %s', 'awesome-support'), "{$max_size} Mo");
     }
     return $file;
 }
Exemplo n.º 14
0
/**
 * Register user account.
 *
 * @param array|bool $data User data
 *
 * @since  1.0.0
 * @return void
 */
function wpas_register_account($data = false)
{
    global $post;
    /* Make sure registrations are open */
    $registration = boolval(wpas_get_option('allow_registrations', true));
    if (true !== $registration) {
        wp_redirect(add_query_arg(array('message' => wpas_create_notification(__('Registrations are currently not allowed.', 'wpas')), get_permalink($post->ID))));
        exit;
    }
    if (false === $data) {
        $data = $_POST;
    }
    $email = isset($data['email']) && !empty($data['email']) ? sanitize_email($data['email']) : false;
    $first_name = isset($data['first_name']) && !empty($data['first_name']) ? sanitize_text_field($data['first_name']) : false;
    $last_name = isset($data['last_name']) && !empty($data['last_name']) ? sanitize_text_field($data['last_name']) : false;
    $pwd = isset($data['pwd']) && !empty($data['pwd']) ? $data['pwd'] : false;
    /* Save the user information in session to pre populate the form in case of error. */
    $_SESSION['wpas_registration_form'] = array('first_name' => $first_name, 'last_name' => $last_name, 'email' => $email);
    /**
     * wpas_pre_register_account hook
     *
     * This hook is triggered all the time
     * even if the checks don't pass.
     *
     * @since  3.0.1
     */
    do_action('wpas_pre_register_account', $data);
    if (wpas_get_option('terms_conditions', false) && !isset($data['terms'])) {
        wp_redirect(add_query_arg(array('message' => wpas_create_notification(__('You did not accept the terms and conditions.', 'wpas')), get_permalink($post->ID))));
        exit;
    }
    /* Make sure we have all the necessary data. */
    if (false === ($email || $first_name || $last_name || $pwd)) {
        wp_redirect(add_query_arg(array('message' => wpas_create_notification(__('You didn\'t correctly fill all the fields.', 'wpas')), get_permalink($post->ID))));
        exit;
    }
    $username = sanitize_user(strtolower($first_name) . strtolower($last_name));
    $user = get_user_by('login', $username);
    /* Check for existing username */
    if (is_a($user, 'WP_User')) {
        $suffix = 1;
        do {
            $alt_username = sanitize_user($username . $suffix);
            $user = get_user_by('login', $alt_username);
            $suffix++;
        } while (is_a($user, 'WP_User'));
        $username = $alt_username;
    }
    /**
     * wpas_insert_user_data filter
     *
     * @since  3.1.5
     * @var    array User account arguments
     */
    $args = apply_filters('wpas_insert_user_data', array('user_login' => $username, 'user_email' => $email, 'first_name' => $first_name, 'last_name' => $last_name, 'display_name' => "{$first_name} {$last_name}", 'user_pass' => $pwd, 'role' => 'wpas_user'));
    /**
     * wpas_register_account_before hook
     *
     * Fired right before the user is added to the database.
     */
    do_action('wpas_register_account_before', $args);
    $user_id = wp_insert_user(apply_filters('wpas_user_registration_data', $args));
    if (is_wp_error($user_id)) {
        /**
         * wpas_register_account_before hook
         *
         * Fired right after a failed attempt to register a user.
         *
         * @since  3.0.1
         */
        do_action('wpas_register_account_failed', $user_id, $args);
        $error = $user_id->get_error_message();
        wp_redirect(add_query_arg(array('message' => wpas_create_notification($error), get_permalink($post->ID))));
        exit;
    } else {
        /**
         * wpas_register_account_before hook
         *
         * Fired right after the user is successfully added to the database.
         *
         * @since  3.0.1
         */
        do_action('wpas_register_account_after', $user_id, $args);
        /* Delete the user information data from session. */
        unset($_SESSION['wpas_registration_form']);
        wp_new_user_notification($user_id, $pwd);
        if (headers_sent()) {
            wp_redirect(add_query_arg(array('message' => wpas_create_notification(__('Your account has been created. Please log-in.', 'wpas')), get_permalink($post->ID))));
            exit;
        }
        if (!is_user_logged_in()) {
            /* Automatically log the user in */
            wp_set_current_user($user_id, $email);
            wp_set_auth_cookie($user_id);
            wp_redirect(get_permalink($post->ID));
            exit;
        }
    }
}
Exemplo n.º 15
0
			<div class="updated below-h2" style="margin-top: 2em;">
				<h2 style="margin: 0.5em 0; padding: 0; line-height: 100%;"><?php 
    _e('Create Ticket', 'awesome-support');
    ?>
</h2>
				<p><?php 
    _e('Please save this ticket to reveal all options.', 'awesome-support');
    ?>
</p>
			</div>

		<?php 
    /* Now let's display the real content */
} else {
    /* We're going to get all the posts part of the ticket history */
    $replies_args = array('posts_per_page' => -1, 'orderby' => 'post_date', 'order' => wpas_get_option('replies_order', 'ASC'), 'post_type' => apply_filters('wpas_replies_post_type', array('ticket_history', 'ticket_reply')), 'post_parent' => $post->ID, 'post_status' => apply_filters('wpas_replies_post_status', array('publish', 'inherit', 'private', 'trash', 'read', 'unread')));
    $history = new WP_Query($replies_args);
    if (!empty($history->posts)) {
        foreach ($history->posts as $row) {
            // Set the author data (if author is known)
            if ($row->post_author != 0) {
                $user_data = get_userdata($row->post_author);
                $user_id = $user_data->data->ID;
                $user_name = $user_data->data->display_name;
            } else {
                $user_name = __('Anonymous', 'awesome-support');
                $user_id = 0;
            }
            $user_avatar = get_avatar($user_id, '64', get_option('avatar_default'));
            $date = human_time_diff(get_the_time('U', $row->ID), current_time('timestamp'));
            $post_type = $row->post_type;
Exemplo n.º 16
0
<?php

/**
 * This is a built-in template file. If you need to customize it, please,
 * DO NOT modify this file directly. Instead, copy it to your theme's directory
 * and then modify the code. If you modify this file directly, your changes
 * will be overwritten during next update of the plugin.
 */
/**
 * Make the post data and the pre-form message global
 */
global $post, $wpas_notification;
$submit = get_permalink(wpas_get_option('ticket_list'));
$registration = boolval(wpas_get_option('allow_registrations', true));
// Make sure registrations are open
$redirect_to = get_permalink($post->ID);
$wrapper_class = true !== $registration ? 'wpas-login-only' : 'wpas-login-register';
?>

<div class="wpas <?php 
echo $wrapper_class;
?>
">

	<form class="wpas-form" method="post" role="form" action="<?php 
echo wpas_get_login_url();
?>
">
		<h3><?php 
_e('Log in');
?>
Exemplo n.º 17
0
 *
 * @since 3.3
 * @var WP_User $user The user object
 * @var WP_Post $post Post object of the current ticket
 */
do_action('wpas_user_profile_metabox_after_stats', $user, $post);
?>

	<div class="wpas-up-tickets">
		<?php 
foreach ($by_status as $status => $tickets) {
    if (empty($tickets)) {
        continue;
    }
    $status_label = 'closed' === $status ? esc_html__('Closed', 'awesome-support') : $all_status[$status];
    $lis = sprintf('<li><span class="wpas-label" style="background-color:%1$s;">%2$s ▾</span></li>', wpas_get_option("color_{$status}", '#dd3333'), $status_label);
    foreach ($tickets as $t) {
        $created = sprintf(esc_html_x('Created on %s', 'Ticket date creation', 'awesome-support'), date(get_option('date_format'), strtotime($t->post_date)));
        $title = apply_filters('the_title', $t->post_title);
        $link = esc_url(admin_url("post.php?post={$t->ID}&action=edit"));
        if ($t->ID !== (int) $post->ID) {
            $lis .= sprintf('<li data-hint="%1$s" class="hint-left hint-anim"><a href="%3$s">%2$s</a></li>', $created, $title, $link);
        } else {
            $lis .= sprintf('<li data-hint="%1$s" class="hint-left hint-anim">%2$s (%3$s)</li>', $created, $title, esc_html_x('current', 'Identifies the ticket in a list as being the ticket displayed on the current screen', 'awesome-support'));
        }
    }
    printf('<ul>%s</ul>', $lis);
}
?>

		<!-- @todo <a href="/wp-admin/edit.php?post_type=ticket" class="button">View all tickets</a> -->
/**
 * Register user account.
 *
 * This function is hooked onto wpas_do_register so that the registration process can be triggered
 * when the registration form is submitted.
 *
 * @param array $data User data
 *
 * @since  1.0.0
 * @return void
 */
function wpas_register_account($data)
{
    // Get the redirect URL
    $redirect_to = home_url();
    if (isset($data['redirect_to'])) {
        $redirect_to = wp_sanitize_redirect($data['redirect_to']);
        // If a redirect URL is specified we use it
    } else {
        global $post;
        // Otherwise we try to get the URL of the originating page
        if (isset($post) && $post instanceof WP_Post) {
            $redirect_to = wp_sanitize_redirect(get_permalink($post->ID));
        }
    }
    /* Make sure registrations are open */
    $registration = wpas_get_option('allow_registrations', 'allow');
    if ('allow' !== $registration) {
        wpas_add_error('registration_not_allowed', __('Registrations are currently not allowed.', 'awesome-support'));
        wp_safe_redirect($redirect_to);
        exit;
    }
    // Prepare user data
    $user = array('email' => isset($data['wpas_email']) ? $data['wpas_email'] : '', 'first_name' => isset($data['wpas_first_name']) ? $data['wpas_first_name'] : '', 'last_name' => isset($data['wpas_last_name']) ? $data['wpas_last_name'] : '', 'pwd' => isset($data['wpas_password']) ? $data['wpas_password'] : '');
    /**
     * wpas_pre_register_account hook
     *
     * This hook is triggered all the time
     * even if the checks don't pass.
     *
     * @since  3.0.1
     */
    do_action('wpas_pre_register_account', $user);
    if (wpas_get_option('terms_conditions', false) && !isset($data['wpas_terms'])) {
        wpas_add_error('accept_terms_conditions', esc_html__('You did not accept the terms and conditions.', 'awesome-support'));
        wp_safe_redirect($redirect_to);
        exit;
    }
    /**
     * wpas_register_account_before hook
     *
     * Fired right before the user is added to the database.
     */
    do_action('wpas_register_account_before', $user);
    // Try and insert the new user in the database
    $user_id = wpas_insert_user($user);
    if (is_wp_error($user_id)) {
        /**
         * wpas_register_account_before hook
         *
         * Fired right after a failed attempt to register a user.
         *
         * @since  3.0.1
         */
        do_action('wpas_register_account_failed', $user_id, $user);
        $errors = implode('<br>', $user_id->get_error_messages());
        wpas_add_error('missing_fields', $errors);
        wp_safe_redirect($redirect_to);
        exit;
    } else {
        /**
         * wpas_register_account_before hook
         *
         * Fired right after the user is successfully added to the database.
         *
         * @since  3.0.1
         */
        do_action('wpas_register_account_after', $user_id, $user);
        if (headers_sent()) {
            wpas_add_notification('account_created', esc_html__('Your account has been created. Please log-in.', 'awesome-support'));
            wp_safe_redirect($redirect_to);
            exit;
        }
        if (!is_user_logged_in()) {
            /* Automatically log the user in */
            wp_set_current_user($user_id, get_user_by('ID', $user_id)->data->user_email);
            wp_set_auth_cookie($user_id);
            wp_safe_redirect($redirect_to);
            exit;
        }
    }
}
function wpas_make_button($label = null, $args = array())
{
    if (is_null($label)) {
        $label = __('Submit', 'wpas');
    }
    $defaults = array('type' => 'button', 'link' => '', 'class' => wpas_get_option('buttons_class', 'wpas-btn wpas-btn-default'), 'name' => 'submit', 'value' => '', 'onsubmit' => '');
    $args = wp_parse_args($args, $defaults);
    extract(shortcode_atts($defaults, $args));
    if ('link' === $args['type'] && !empty($args['link'])) {
        ?>
<a href="<?php 
        echo esc_url($args['link']);
        ?>
" class="<?php 
        echo $args['class'];
        ?>
" <?php 
        if (!empty($args['onsubmit'])) {
            echo "data-onsubmit='{$args['onsubmit']}'";
        }
        ?>
><?php 
        echo $label;
        ?>
</a><?php 
    } else {
        ?>
<button type="submit" class="<?php 
        echo $args['class'];
        ?>
" name="<?php 
        echo $args['name'];
        ?>
" value="<?php 
        echo $args['value'];
        ?>
" <?php 
        if (!empty($args['onsubmit'])) {
            echo "data-onsubmit='{$args['onsubmit']}'";
        }
        ?>
><?php 
        echo $label;
        ?>
</button><?php 
    }
}
Exemplo n.º 20
0
 /**
  * Get the agent's departments
  *
  * @since 3.3
  * @return bool|array
  */
 public function in_department()
 {
     if (false === wpas_get_option('departments', false)) {
         return false;
     }
     if (is_null($this->department)) {
         $this->department = get_the_author_meta('wpas_department', $this->user_id);
         if (empty($this->department)) {
             $this->department = array();
         }
     }
     return apply_filters('wpas_agent_department', $this->department, $this->user_id);
 }
 /**
  * Filter the link query arguments to remove completely internal links from the list.
  *
  * @since 3.2.0
  *
  * @param array $query An array of WP_Query arguments.
  *
  * @return array $query
  */
 public function remove_tinymce_links_internal($query)
 {
     /**
      * Getting the post ID this way is quite dirty but it seems to be the only way
      * as we are in an Ajax query and the only given parameter is the $query
      */
     $url = wp_get_referer();
     $post_id = url_to_postid($url);
     if ($post_id === wpas_get_option('ticket_submit')) {
         $query['post_type'] = array('none');
     }
     return $query;
 }
Exemplo n.º 22
0
/**
 * Get URL of the tickets list page
 *
 * @since 3.2.2
 *
 * @return string
 */
function wpas_get_tickets_list_page_url()
{
    $list = wpas_get_option('ticket_list');
    if (empty($list)) {
        return '';
    }
    if (is_array($list) && !empty($list)) {
        $list = $list[0];
    }
    return wp_sanitize_redirect(get_permalink((int) $list));
}
/**
 * Shows the message field.
 *
 * The function echoes the textarea where the user
 * may input the ticket description. The field can be
 * either a textarea or a WYSIWYG depending on the plugin settings.
 * The WYSIWYG editor uses TinyMCE with a minimal configuration.
 *
 * @since  3.0.0
 * @param  array  $editor_args Arguments used for TinyMCE
 * @return void
 */
function wpas_get_message_textarea($editor_args = array())
{
    /**
     * Check if the description field should use the WYSIWYG editor
     * 
     * @var string
     */
    $textarea_class = true === ($wysiwyg = boolval(wpas_get_option('frontend_wysiwyg_editor'))) ? 'wpas-wysiwyg' : 'wpas-textarea';
    if (true === $wysiwyg) {
        $editor_defaults = apply_filters('wpas_ticket_editor_args', array('media_buttons' => false, 'textarea_name' => 'wpas_message', 'textarea_rows' => 10, 'tabindex' => 2, 'editor_class' => wpas_get_field_class('wpas_message', $textarea_class, false), 'quicktags' => false, 'tinymce' => array('toolbar1' => 'bold,italic,underline,strikethrough,hr,|,bullist,numlist,|,link,unlink', 'toolbar2' => '')));
        ?>
<div class="wpas-submit-ticket-wysiwyg"><?php 
        wp_editor(wpas_get_field_value('wpas_message'), 'wpas-ticket-message', apply_filters('wpas_reply_wysiwyg_args', $editor_defaults));
        ?>
</div><?php 
    } else {
        /**
         * Define if the body can be submitted empty or not.
         *
         * @since  3.0.0
         * @var boolean
         */
        $can_submit_empty = apply_filters('wpas_can_message_be_empty', false);
        ?>
		<div class="wpas-submit-ticket-wysiwyg">
			<textarea <?php 
        wpas_get_field_class('wpas_message', $textarea_class);
        ?>
 id="wpas-ticket-message" name="wpas_message" placeholder="<?php 
        echo apply_filters('wpas_form_field_placeholder_wpas_message', __('Describe your problem as accurately as possible', 'wpas'));
        ?>
" rows="10" <?php 
        if (false === $can_submit_empty) {
            ?>
required="required"<?php 
        }
        ?>
><?php 
        echo wpas_get_field_value('wpas_message');
        ?>
</textarea>
		</div>
	<?php 
    }
}
Exemplo n.º 24
0
/**
 * 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;
}
Exemplo n.º 25
0
echo '<div class="wpas-reply-content">' . make_clickable(apply_filters('the_content', $post->post_content)) . '</div>';
/**
 * wpas_frontend_ticket_content_after hook
 *
 * @since  3.0.0
 */
do_action('wpas_frontend_ticket_content_after', $post->ID, $post);
?>

				</td>

			</tr>

			<?php 
// Set the number of replies
$replies_per_page = wpas_get_option('replies_per_page', 10);
$force_all_replies = WPAS()->session->get('force_all_replies');
// 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];
 /**
  * Get e-mail content.
  *
  * Get the content for the given part.
  *
  * @since  3.0.2
  * @param  string $part Part of the e-mail to retrieve
  * @param  string $case Which notification is requested
  * @return string       The content with tags converted into their values
  */
 private function get_content($part, $case)
 {
     if (!in_array($part, array('subject', 'content'))) {
         return false;
     }
     /* Set the output value */
     $value = '';
     switch ($case) {
         case 'submission_confirmation':
             $value = wpas_get_option("{$part}_confirmation", "");
             break;
         case 'new_ticket_assigned':
             $value = wpas_get_option("{$part}_assignment", "");
             break;
         case 'agent_reply':
             $value = wpas_get_option("{$part}_reply_agent", "");
             break;
         case 'client_reply':
             $value = wpas_get_option("{$part}_reply_client", "");
             break;
         case 'ticket_closed':
         case 'ticket_closed_agent':
         case 'ticket_closed_client':
             $value = wpas_get_option("{$part}_closed", "");
             break;
     }
     return $this->fetch(apply_filters('wpas_email_notifications_pre_fetch_' . $part, $value, $this->post_id));
 }
Exemplo n.º 27
0
 /**
  * Display a link to the plugin page.
  *
  * @since  3.1.3
  * @return void
  */
 public function credit()
 {
     if (true === (bool) wpas_get_option('credit_link')) {
         echo '<p class="wpas-credit">Built with Awesome Support,<br> the most versatile <a href="https://wordpress.org/plugins/awesome-support/" target="_blank" title="The best support plugin for WordPress">WordPress Support Plugin</a></p>';
     }
 }
Exemplo n.º 28
0
<?php

/**
 * This is a built-in template file. If you need to customize it, please,
 * DO NOT modify this file directly. Instead, copy it to your theme's directory
 * and then modify the code. If you modify this file directly, your changes
 * will be overwritten during next update of the plugin.
 */
/**
 * Make the post data and the pre-form message global
 */
global $post;
$submit = get_permalink(wpas_get_option('ticket_list'));
$registration = wpas_get_option('allow_registrations', 'allow');
// Make sure registrations are open
$redirect_to = get_permalink($post->ID);
$wrapper_class = 'allow' !== $registration ? 'wpas-login-only' : 'wpas-login-register';
?>

<div class="wpas <?php 
echo $wrapper_class;
?>
">
	<?php 
do_action('wpas_before_login_form');
?>

	<form class="wpas-form" id="wpas_form_login" method="post" role="form" action="<?php 
echo wpas_get_login_url();
?>
">
Exemplo n.º 29
0
/**
 * Get pagination link
 *
 * This is used for pagination throughout Awesome Support.
 * It is used for paginating ticket replies as well as tickets lists.
 *
 * @since 3.2
 *
 * @param string $direction Direction of the link (prev or next)
 * @param int $posts Total number of pages
 *
 * @return string Link to the prev/next page
 */
function wpas_pagination_link($direction = 'next', $posts = 0)
{
    global $post;
    if (!isset($post)) {
        return '';
    }
    $current_page = isset($_GET['as-page']) ? filter_input(INPUT_GET, 'as-page', FILTER_SANITIZE_NUMBER_INT) : 1;
    $posts_per_page = (int) wpas_get_option('replies_per_page', 10);
    $link = '';
    switch ($direction) {
        case 'prev':
            if ($current_page > 1) {
                $page = $current_page - 1;
                $link = get_permalink($post->ID) . '?as-page=' . $page;
            }
            break;
        case 'next':
            if (0 !== $posts && 0 !== $posts_per_page && $current_page < ceil($posts / $posts_per_page)) {
                $page = $current_page + 1;
                $link = get_permalink($post->ID) . '?as-page=' . $page;
            }
            break;
    }
    return empty($link) ? $link : esc_url($link);
}
Exemplo n.º 30
0
        echo '<tr>';
        foreach ($columns as $column_id => $column) {
            echo '<td';
            /* If current column is the date we add the date attribute for sorting purpose */
            if ('date' === $column_id) {
                echo ' data-order="' . strtotime(get_the_time()) . '"';
            }
            /* We don't forget to close the <td> tag */
            echo '>';
            /* Display the content for this column */
            wpas_get_tickets_list_column_content($column_id, $column);
            echo '</td>';
        }
        echo '</tr>';
    }
    wp_reset_query();
    ?>
            </tbody>
        </table>
        <?php 
    echo paginate_links(array('base' => str_replace(999999999, '%#%', esc_url(get_pagenum_link(999999999))), 'format' => '?paged=%#%', 'current' => max(1, get_query_var('paged')), 'total' => $wpas_tickets->max_num_pages));
    ?>

        <?php 
    wpas_make_button(__('Open a ticket', 'wpas'), array('type' => 'link', 'link' => esc_url(get_permalink(wpas_get_option('ticket_submit'))), 'class' => 'wpas-btn wpas-btn-default'));
    ?>
    </div>
<?php 
} else {
    wpas_notification('info', sprintf(__('You haven\'t submitted a ticket yet. <a href="%s">Click here to submit your first ticket</a>.', 'wpas'), esc_url(get_permalink(wpas_get_option('ticket_submit')))));
}