コード例 #1
0
 public static function _get_tickets_widget_html($tickets)
 {
     global $zendesk_support;
     $agents = Zendesk_Wordpress_Agents::get_instance();
     $html = array();
     // Heading
     $html[] = '<p class="zendesk-heading">' . $zendesk_support->zendesk_user['default_view']['title'];
     if ($agents->_is_agent()) {
         $html[] = '<span class="zendesk-heading-link">(<a class="zendesk-change-view" href="#">' . __('change view', 'zendesk') . '</a>)</span>';
     }
     $html[] = '</p>';
     $html[] = '<table class="zendesk-tickets-table">';
     if (count($tickets) > 0 && is_array($tickets)) {
         foreach ($tickets as $ticket) {
             if (!strlen($ticket->subject)) {
                 $ticket->subject = Zendesk_Wordpress_Utilities::_excerpt($ticket->description, 15);
             }
             $html[] = '<tr>';
             $html[] = '<td class="zendesk-ticket-id"><div class="zendesk-loader" style="display: none"></div><a class="zendesk-ticket-id-text zendesk-ticket-view" data-id="' . $ticket->id . '" href="' . Zendesk_Wordpress_Utilities::_ticket_url($ticket->id) . '">#' . $ticket->id . '</a></td>';
             $html[] = '<td><a class="zendesk-ticket-view zendesk-ticket-subject" data-id="' . $ticket->id . '" href="' . Zendesk_Wordpress_Utilities::_ticket_url($ticket->id) . '">' . $ticket->subject . '</a></td>';
             $html[] = '<td class="zendesk-ticket-status"><a href="' . Zendesk_Wordpress_Utilities::_ticket_url($ticket->id) . '" target="_blank" class="zendesk-status-' . $ticket->status . '">' . $zendesk_support->_ticket_status($ticket->status) . '</a></td>';
             $html[] = '</tr>';
         }
     } else {
         $html[] = '<tr><td><span class="description">' . __('There are no tickets in this view.', 'zendesk') . '</span></td></tr>';
     }
     $html[] = '</table>';
     // Glue the HTML pieces and delimit with a line break
     return implode("\n", $html);
 }
コード例 #2
0
 public static function get_instance()
 {
     if (is_null(self::$instance)) {
         self::$instance = new self();
     }
     return self::$instance;
 }
コード例 #3
0
 public function _ajax_view_ticket($agents = null)
 {
     global $zendesk_support;
     if (empty($agents)) {
         $agents = Zendesk_Wordpress_Agents::get_instance();
     }
     if (isset($_REQUEST['ticket_id']) && is_numeric($_REQUEST['ticket_id'])) {
         $ticket_id = $_REQUEST['ticket_id'];
         // API requests based on the Zendesk role.
         if ($agents->_is_agent()) {
             $ticket = $zendesk_support->api->get_ticket_info($ticket_id);
         } else {
             $request = $zendesk_support->api->get_request_info($ticket_id);
             $ticket = $request->request;
         }
         // If there was no error fetch further
         if (!is_wp_error($ticket)) {
             // If there's a requester ID let's resolve it
             if (isset($ticket->requester_id)) {
                 $requester = $zendesk_support->api->get_user($ticket->requester_id);
                 if (!is_wp_error($requester)) {
                     $requester = $requester->user->name;
                 } else {
                     $requester = __('Unknown', 'zendesk');
                 }
                 // Otherwise set it to blank, blank fields don't show up.
             } else {
                 $requester = '';
             }
             // Updated field is not viewable by end-users, so if it's
             // not set then set it to blank.
             if (!isset($ticket->updated_at)) {
                 $ticket->updated_at = '';
             }
             // Create the table values, where key is the label and value
             // is the value, doh!
             $table_values = array(__('Subject:', 'zendesk') => htmlspecialchars($ticket->subject), __('Description:', 'zendesk') => nl2br(htmlspecialchars($ticket->description)), __('Ticket Status:', 'zendesk') => '<span class="zendesk-status-' . $ticket->status . '">' . $zendesk_support->_ticket_status($ticket->status) . '</span>', __('Requested by:', 'zendesk') => '<a target="_blank" href="' . Zendesk_Wordpress_Utilities::_user_url($ticket->requester_id) . '">' . $requester . '</a>', __('Created:', 'zendesk') => date(get_option('date_format') . ' \\a\\t ' . get_option('time_format'), strtotime($ticket->created_at)), __('Updated:', 'zendesk') => date(get_option('date_format') . ' \\a\\t ' . get_option('time_format'), strtotime($ticket->updated_at)));
             // Agents only data
             if ($agents->_is_agent()) {
                 // Custom fields
                 $table_custom_fields = array();
                 $ticket_fields = $zendesk_support->api->get_ticket_fields();
                 // Perhaps optimize this a little bit, though this is
                 // the way values come in from Zendesk.
                 if (!is_wp_error($ticket_fields) && !empty($ticket->custom_fields)) {
                     $custom_fields_array = array();
                     // Build an array with custom field values and ID as index
                     foreach ($ticket->custom_fields as $custom_field) {
                         $custom_fields_array[$custom_field->id] = $custom_field->value;
                     }
                     $custom_fields_ids = array_keys($custom_fields_array);
                     foreach ($ticket_fields as $ticket_field) {
                         if (!in_array($ticket_field->id, $custom_fields_ids)) {
                             continue;
                         }
                         // Use numeric index in case there are duplicate field titles
                         $table_custom_fields[$ticket_field->id] = array('title' => $ticket_field->title, 'value' => '');
                         // Use readable value for 'tagger' types
                         if ('tagger' === $ticket_field->type) {
                             foreach ($ticket_field->custom_field_options as $custom_field_option) {
                                 if ($custom_fields_array[$ticket_field->id] === $custom_field_option->value) {
                                     $table_custom_fields[$ticket_field->id]['value'] = $custom_field_option->name;
                                 }
                             }
                         } else {
                             $table_custom_fields[$ticket_field->id]['value'] = $custom_fields_array[$ticket_field->id];
                         }
                     }
                 }
                 $table_actions = array(__('Comments:', 'zendesk') => '<a data-id="' . $ticket->id . '" href="#" class="zendesk-view-comments">' . __('View the comments thread', 'zendesk') . '</a>', __('View:', 'zendesk') => '<a target="_blank" href="' . Zendesk_Wordpress_Utilities::_ticket_url($ticket->id) . '">' . __('View this ticket on Zendesk', 'zendesk') . '</a>');
             }
             // Use these for debug values
             //$table_values['Ticket'] = print_r($ticket, true);
             //$table_values['Fields'] = print_r($ticket_fields, true);
             // Start formatting the general HTML table.
             $html = '<table id="zendesk-ticket-details-table" class="zendesk-ticket-details-table">';
             foreach ($table_values as $label => $value) {
                 if (strlen($value) < 1) {
                     continue;
                 }
                 $html .= '<tr><td class="zendesk-first"><span class="description">' . $label . '</span></td>';
                 $html .= '<td>' . $value . '</td></tr>';
             }
             // Custom Fields Table (agents only)
             if (isset($table_custom_fields) && !empty($table_custom_fields)) {
                 $html .= '<tr><td colspan="2"><p class="zendesk-heading" style="margin-bottom: 0px;">' . __('Custom Fields', 'zendesk') . '</p></td></tr>';
                 foreach ($table_custom_fields as $table_custom_field) {
                     if (strlen($table_custom_field['value']) < 1) {
                         continue;
                     }
                     $html .= '<tr><td class="zendesk-first"><span class="description">' . esc_html($table_custom_field['title']) . '</span></td>';
                     $html .= '<td>' . esc_html($table_custom_field['value']) . '</td></tr>';
                 }
             }
             // Actions Table (agents only)
             if (isset($table_actions) && !empty($table_actions)) {
                 $html .= '<tr><td colspan="2"><p class="zendesk-heading" style="margin-bottom: 0px;">' . __('Actions', 'zendesk') . '</p></td></tr>';
                 foreach ($table_actions as $label => $value) {
                     $html .= '<tr><td class="zendesk-first"><span class="description">' . $label . '</span></td>';
                     $html .= '<td>' . $value . '</td></tr>';
                 }
             }
             $html .= '</table>';
             // Format the response to output.
             $response = array('status' => 200, 'ticket' => $ticket, 'html' => $html);
         } else {
             // Something went wrong
             $response = array('status' => 404, 'data' => $ticket->get_error_message());
         }
     } else {
         // Something went really wrong
         $response = array('status' => 404, 'data' => __('Ticket was not found.', 'zendesk'));
     }
     // Output the response array as a JSON object.
     echo json_encode($response);
     $this->terminate();
 }
コード例 #4
0
    public function _settings_field_contact_form_anonymous_user()
    {
        global $zendesk_support;
        $agents = Zendesk_Wordpress_Agents::get_instance();
        // Fetch the agents
        $users = $agents->_get_agents();
        // Let's see if the current user *is* an agent.
        $contains_current_user = false;
        foreach ($users as $user) {
            if ($user->ID == $zendesk_support->user->ID) {
                $contains_current_user = true;
                break;
            }
        }
        // If the current user's not an agent append them to the beginning of the list.
        if (!$contains_current_user) {
            array_unshift($users, $zendesk_support->user);
        }
        ?>
    <select id="zendesk_contact_form_anonymous_user" name="zendesk-settings[contact_form_anonymous_user]">
      <?php 
        foreach ($users as $user) {
            ?>
        <option <?php 
            selected($user->ID == $zendesk_support->settings['contact_form_anonymous_user']);
            ?>
          value="<?php 
            echo $user->ID;
            ?>
"><?php 
            echo $user->display_name;
            ?>
 (<?php 
            echo $user->user_email;
            ?>
)
        </option>
      <?php 
        }
        ?>
    </select><br/>
    <span class="description">
      <?php 
        _e('Contact form submissions will be done "via" this agent, through the Zendesk API. <br /> This agent must be authenticated into Zendesk via the Wordpress for Zendesk widget.<br /> Agents not authenticated via the dashboard widget are not shown here.', 'zendesk');
        ?>
      <br/><a target="_blank"
              href="https://support.zendesk.com/entries/20116518-setting-up-anonymous-ticket-submissions-with-zendesk-for-wordpress"><?php 
        _e('Learn more at Zendesk.com', 'zendesk');
        ?>
</a>
    </span>
  <?php 
    }
コード例 #5
0
 public function _wp_admin_notices()
 {
     global $zendesk_support;
     $agents = Zendesk_Wordpress_Agents::get_instance();
     if (isset($zendesk_support->settings['contact_form_anonymous']) && $zendesk_support->settings['contact_form_anonymous']) {
         $agent = $zendesk_support->settings['contact_form_anonymous_user'];
         if ($zendesk_support->settings['account'] && !$agents->_is_agent($agent) && current_user_can('manage_options')) {
             ?>
     <div id="message" class="error"><p>
         <?php 
             printf(__('<strong>Whoops!</strong> The user specified as the anonymous requests author is not logged in to Zendesk! You can %s or kindly ask them to log in.', 'zendesk'), sprintf('<a href="' . admin_url('admin.php?page=zendesk-support') . '">%s</a>', __('change the user', 'zendesk')));
             ?>
       </p></div>
   <?php 
         }
     }
 }
コード例 #6
0
 public function _wp_admin_notices()
 {
     global $zendesk_support;
     $agents = Zendesk_Wordpress_Agents::get_instance();
     if (isset($zendesk_support->settings['contact_form_anonymous']) && $zendesk_support->settings['contact_form_anonymous']) {
         $agent = $zendesk_support->settings['contact_form_anonymous_user'];
         if ($zendesk_support->settings['account'] && !$agents->_is_agent($agent) && current_user_can('manage_options')) {
             $this->_show_non_admin_message();
         }
     }
 }
    public function _dashboard_widget_tickets()
    {
        global $zendesk_support;
        $agents = Zendesk_Wordpress_Agents::get_instance();
        ?>
    <div class="inside">
      <?php 
        // API requests based on the Zendesk role.
        if ($agents->_is_agent()) {
            $tickets = $zendesk_support->api->get_tickets_from_view((int) $zendesk_support->zendesk_user['default_view']['id']);
            $views = $zendesk_support->api->get_views();
        } else {
            $tickets = $zendesk_support->api->get_requests();
            $views = array();
        }
        // Empty the arrays if they are errors.
        if (is_wp_error($views)) {
            $notices = Zendesk_Wordpress_Notices::get_instance();
            $notices->_add_notice('zendesk_tickets_widget', $views->get_error_message(), 'alert');
            $views = array();
        }
        if (is_wp_error($tickets)) {
            $notices = Zendesk_Wordpress_Notices::get_instance();
            $notices->_add_notice('zendesk_tickets_widget', $tickets->get_error_message(), 'alert');
            $tickets = array();
        }
        // Notifications
        $notices = Zendesk_Wordpress_Notices::get_instance();
        $notices->_do_notices('zendesk_login');
        $notices->_do_notices('zendesk_tickets_widget');
        ?>
    </div>
    <div class="zendesk-tickets-widget">

      <!-- Dashboard Widget Main View -->
      <div class="zendesk-tickets-widget-main">
        <?php 
        echo Zendesk_Wordpress_Tickets::_get_tickets_widget_html($tickets);
        ?>
      </div>

      <!-- Dashboard Widget Select View -->
      <div class="zendesk-tickets-widget-views" style="display: none;">
        <p class="zendesk-heading"><?php 
        _e('Change view', 'zendesk');
        ?>
 <span class="zendesk-heading-link">(<a
              class="zendesk-change-view-cancel"
              href="<?php 
        echo admin_url();
        ?>
"><?php 
        _e('cancel', 'zendesk');
        ?>
</a>)</span></p>
        <table class="zendesk-views-table">
          <?php 
        if (count($views) > 0 && is_array($views)) {
            foreach ($views as $view) {
                ?>
              <tr>
                <td>
                  <?php 
                if ($view->active != 1) {
                    ?>
                    <span class="zendesk-view-empty">
                <?php 
                    echo $view->title;
                    ?>
              </span>
                  <?php 
                } else {
                    ?>
                    <a data-id="<?php 
                    echo $view->id;
                    ?>
"
                       href="<?php 
                    echo admin_url();
                    ?>
?zendesk-tickets-change-view=<?php 
                    echo $view->id;
                    ?>
">
                      <?php 
                    echo $view->title;
                    ?>
                    </a>
                  <?php 
                }
                ?>
                </td>
              </tr>
            <?php 
            }
        } else {
            // no views
            ?>
            <tr>
              <td><span
                  class="description"><?php 
            _e('There are no views available for this account.', 'zendesk');
            ?>
</span>
              </td>
            </tr>
          <?php 
        }
        ?>
        </table>
      </div>

      <!-- Dashboard Widget Single View -->
      <div class="zendesk-tickets-widget-single" style="display: none;">
        <p class="zendesk-heading"><?php 
        _e('Viewing Ticket', 'zendesk');
        ?>
 <span id="zendesk-ticket-title"></span>
          <span class="zendesk-heading-link">(<a class="zendesk-change-single-cancel"
                                                 href="<?php 
        echo admin_url();
        ?>
"><?php 
        _e('back', 'zendesk');
        ?>
</a>)</span>
        </p>

        <div id="zendesk-ticket-details-placeholder"></div>
      </div>

      <!-- Dashboard Widget Bottom -->
      <br class="clear"/>

      <div class="zendesk-tickets-bottom">
        <p>
          <a target="_blank" href="<?php 
        echo trailingslashit($zendesk_support->zendesk_url);
        ?>
"
             class="button"><?php 
        _e('My Helpdesk', 'zendesk');
        ?>
</a>
          <?php 
        _e('Logged in as', 'zendesk');
        ?>
          <strong><?php 
        echo $zendesk_support->zendesk_user['username'];
        ?>
</strong> (<a
            href="?zendesk-logout=true"><?php 
        _e('logout', 'zendesk');
        ?>
</a>)
          <a target="_blank" href="http://zendesk.com/?source=wordpress-plugin"
             class="powered-by-zendesk"><?php 
        _e('powered by Zendesk', 'zendesk');
        ?>
</a>
        </p>
      </div>

    </div>
    <br class="clear"/>
  <?php 
    }
コード例 #8
0
 public function _comments_columns_action($column)
 {
     global $comment;
     $agents = Zendesk_Wordpress_Agents::get_instance();
     if ($column == 'zendesk' && $agents->_is_agent()) {
         $ticket_id = get_comment_meta($comment->comment_ID, 'zendesk-ticket', true);
         // Make sure it's valid before printing.
         if ($comment->comment_type != 'pingback' && $ticket_id) {
             echo '<a target="_blank" class="zendesk-comment-ticket-id" href="' . Zendesk_Wordpress_Utilities::_ticket_url($ticket_id) . '">#' . $ticket_id . '</a>';
         }
     }
 }