Plugin Directory

Changeset 3265917


Ignore:
Timestamp:
04/02/2025 09:49:44 PM (10 months ago)
Author:
hippooo
Message:

1.0.7 - Minor Improvements

Location:
hippoo-ticket/trunk
Files:
6 added
12 edited

Legend:

Unmodified
Added
Removed
  • hippoo-ticket/trunk/app/config.php

    r3007682 r3265917  
    1 <?php
     1<?php // phpcs:disable PluginCheck.CodeAnalysis.ImageFunctions.NonEnqueuedImage
    22    if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly     
    33?>
    44<div class="wrap">
    5     <h1 class="wh-heading"><?php esc_html_e( 'Hippoo Settings', 'hippoo' ); ?></h1>
     5    <h1 class="wh-heading"><?php esc_html_e( 'Hippoo Settings', 'hippoo-ticket' ); ?></h1>
    66   
    77    <div class="settings">
     
    99        if ( isset( $_POST['save'] ) ) {
    1010            // Verify nonce for security
    11             if ( isset( $_POST['_wpnonce'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'hippoo_nonce' ) ) {
     11            if ( isset( $_POST['_wpnonce'] ) && wp_verify_nonce( sanitize_key( $_POST['_wpnonce'] ), 'hippoo_nonce' ) ) {
    1212                // Check user permissions here (if needed)
    1313                if ( current_user_can( 'manage_options' ) ) {
    1414                    $opt = [
    15                         'sms'        => sanitize_text_field( $_POST['sms'] ),
    16                         'email'      => sanitize_text_field( $_POST['email'] ),
    17                         'pg_ticket'  => sanitize_text_field( $_POST['pg_ticket'] ),
     15                        'sms'       => isset( $_POST['sms'] ) ? sanitize_text_field( wp_unslash( $_POST['sms'] ) ) : '',
     16                        'email'     => isset( $_POST['email'] ) ? wp_kses_post( wp_unslash( $_POST['email'] ) ) : '',
     17                        'pg_ticket' => isset( $_POST['pg_ticket'] ) ? sanitize_text_field( wp_unslash( $_POST['pg_ticket'] ) ) : '',
    1818                    ];
    1919
    2020                    // Update options only if the user has the required permissions
    2121                    update_option( 'hippoo_ticket', $opt );
    22                     echo esc_html('<div class="updated"><p>' . __('Settings Saved.', 'hippoo') . '</p></div>');
     22                    echo wp_kses_post('<div class="updated"><p>' . __( 'Settings Saved.', 'hippoo-ticket' ) . '</p></div>');
    2323                } else {
    2424                    // Handle lack of permissions
    25                     echo esc_html('<div class="error"><p>' . __( 'Unauthorized Access.', 'hippoo' ) . '</p></div>');
     25                    echo wp_kses_post('<div class="error"><p>' . __( 'Unauthorized Access.', 'hippoo-ticket' ) . '</p></div>');
    2626                }
    2727            } else {
    2828                // Nonce verification failed
    29                 echo esc_html('<div class="error"><p>' . __( 'Security check failed.', 'hippoo' ) . '</p></div>');
     29                echo wp_kses_post('<div class="error"><p>' . __( 'Security check failed.', 'hippoo-ticket' ) . '</p></div>');
    3030            }
    3131        }
    32 
    33 
    3432
    3533        $opt = get_option( 'hippoo_ticket', [] );
     
    4038                <thead>
    4139                    <tr>
    42                         <th colspan="2"><?php esc_html_e( 'Settings', 'hippoo' ); ?></th>
     40                        <th colspan="2"><?php esc_html_e( 'Settings', 'hippoo-ticket' ); ?></th>
    4341                    </tr>
    4442                </thead>
     
    5250                        <?php wp_editor( ( isset( $opt['email'] ) ? $opt['email'] : '' ), 'email', [ 'media_buttons' => false, 'textarea_rows' => 5 ] ); ?>
    5351                        <p>
    54                             <small><?php esc_html_e( 'Use these values for Email %user%, Ticket Name %ticket%, Ticket URL %url%', 'hippoo' ); ?></small>
     52                            <small>
     53                                <?php esc_html_e( 'Use these values for Email %user%, Ticket Name %ticket%, Ticket URL %url%', 'hippoo-ticket' ); // phpcs:ignore ?>
     54                            </small>
    5555                        </p>
    5656                    </td>
    5757                </tr>
    5858                <tr>
    59                     <th colspan="2"><?php esc_html_e( 'Pages', 'hippoo' ); ?></th>
     59                    <th colspan="2"><?php esc_html_e( 'Pages', 'hippoo-ticket' ); ?></th>
    6060                </tr>
    6161                <tr>
    6262                    <td>Ticket Page</td>
    63                     <td><?php wp_dropdown_pages( [ 'name' => 'pg_ticket', 'selected' => ( isset( $opt['pg_ticket'] ) ? $opt['pg_ticket'] : '' ) ] ); ?></td>
     63                    <td><?php wp_dropdown_pages( [ 'name' => 'pg_ticket', 'selected' => esc_attr( isset( $opt['pg_ticket'] ) ? $opt['pg_ticket'] : '' ) ] ); ?></td>
    6464                </tr>
    6565                <tfoot>
     
    7474            <thead>
    7575                <tr>
    76                     <th><?php esc_html_e( 'Shortcode List', 'hippoo' ); ?></th>
     76                    <th><?php esc_html_e( 'Shortcode List', 'hippoo-ticket' ); ?></th>
    7777                </tr>
    7878            </thead>
     
    8383    </div>
    8484
    85 
    8685    <div class="short-desc">
    8786        <div class="left">
    88             <p><?php esc_html_e( "Hippoo! is not just a shop management app, it's also a platform that enables you to extend its capabilities. With the ability to install extensions, you can customize your experience and add new features to the app. Browse and purchase WooCommerce plugins from our shop to enhance your store's functionality.", 'Hippoo-Ticket' ); ?></p>
     87            <p><?php esc_html_e( "Hippoo! is not just a shop management app, it's also a platform that enables you to extend its capabilities. With the ability to install extensions, you can customize your experience and add new features to the app. Browse and purchase WooCommerce plugins from our shop to enhance your store's functionality.", 'hippoo-ticket' ); ?></p>
    8988            <a href="https://hippoo.app">
    9089                <img class="hippoo-download" src="<?php echo wp_kses_post( hippoo_ticket_url . 'images/play-store.png' ); ?>" alt="Play Store">
     
    9493   
    9594    <div class="extentions">
    96         <strong><?php esc_html_e( 'Hippoo extensions', 'hippoo' ); ?></strong>
    97         <p><?php esc_html_e( 'Customize Hippoo! with extensions! Browse and buy Hippoo plugins to add new features and enhance your experience. Download now and take your shop management to the next level!', 'hippoo' ); ?></p>
     95        <strong><?php esc_html_e( 'Hippoo extensions', 'hippoo-ticket' ); ?></strong>
     96        <p><?php esc_html_e( 'Customize Hippoo! with extensions! Browse and buy Hippoo plugins to add new features and enhance your experience. Download now and take your shop management to the next level!', 'hippoo-ticket' ); ?></p>
    9897
    9998        <?php
     
    133132                ';
    134133
    135                 // echo wp_kses_post( $html );
    136                 echo ( $html );
     134                echo wp_kses_post( $html );
    137135            }
    138136        }
  • hippoo-ticket/trunk/app/hooks.php

    r3007682 r3265917  
    66 *
    77 */
     8
    89function hippoo_ticket_wc_add_my_account_orders_column( $columns ) {
    9 
    1010    $columns['ticket'] = 'Support';
    1111    $columns['ticket_status'] = 'Status';
    12 
    1312    return $columns;
    1413}
     14
    1515add_filter( 'woocommerce_account_orders_columns', 'hippoo_ticket_wc_add_my_account_orders_column' );
    16 
    1716
    1817function hippoo_ticket_wc_custom_column_display( $order ) {
    1918    global $wpdb;
    2019   
    21     if(in_array($order->get_status(),['completed','cancelled'])){
    22         echo esc_html('-');
     20    if ( in_array( $order->get_status(), [ 'completed', 'cancelled' ] ) ) {
     21        echo esc_html( '-' );
    2322        return;
    2423    }
    2524
    26     $opt = get_option('hippoo_ticket', []);
     25    $opt = get_option( 'hippoo_ticket', [] );
    2726    $url = esc_url( get_permalink( $opt['pg_ticket'] ) . '?oid=' . absint( $order->get_id() ) );
     27
     28    // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
    2829    $tid = absint( $wpdb->get_var( $wpdb->prepare(
    29         "SELECT ID FROM $wpdb->posts WHERE post_type = 'hippoo_ticket' AND post_status IN ('hippoo_waiting','hippoo_answered','hippoo_close') AND post_parent = %d",
     30        "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'hippoo_ticket' AND post_status IN ('hippoo_waiting','hippoo_answered','hippoo_close') AND post_parent = %d",
    3031        absint( $order->get_id() )
    3132    ) ) );
    32 
    33     echo wp_kses_post("<a href='" . esc_url($url) . "' class='woocommerce-button wp-element-button button' target='_blank'>Ticket</a>");
    34 
    35 }
     33    // phpcs:enable
     34
     35    echo wp_kses_post( "<a href='" . esc_url( $url ) . "' class='woocommerce-button wp-element-button button' target='_blank'>Ticket</a>" );
     36}
     37
    3638add_action( 'woocommerce_my_account_my_orders_column_ticket', 'hippoo_ticket_wc_custom_column_display' );
    3739
     
    3941    global $wpdb;
    4042
    41     if ( in_array( $order->get_status(), ['completed', 'cancelled'] ) ) {
    42         echo esc_html('-');
     43    if ( in_array( $order->get_status(), [ 'completed', 'cancelled' ] ) ) {
     44        echo esc_html( '-' );
    4345        return;
    4446    }
    4547
     48    // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
    4649    $tid = absint( $wpdb->get_var( $wpdb->prepare(
    47         "SELECT ID FROM $wpdb->posts WHERE post_type = 'hippoo_ticket' AND post_status IN ('hippoo_waiting','hippoo_answered','hippoo_close') AND post_parent = %d",
     50        "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'hippoo_ticket' AND post_status IN ('hippoo_waiting','hippoo_answered','hippoo_close') AND post_parent = %d",
    4851        absint( $order->get_id() )
    4952    ) ) );
     53    // phpcs:enable
    5054
    5155    echo wp_kses_post( hippoo_ticket_status( $tid ) );
    5256}
     57
    5358add_action( 'woocommerce_my_account_my_orders_column_ticket_status', 'hippoo_ticket_wc_custom_column_display_status' );
    5459
     
    5661 * add column to ticket post type
    5762 *
    58 **/
    59 
    60 add_filter('manage_hippoo_ticket_posts_columns','hippoo_ticket_columns');
     63 */
     64
    6165function hippoo_ticket_columns( $columns ) {
    6266    // this will add the column to the end of the array
     
    6771}
    6872
    69 add_action( 'manage_hippoo_ticket_posts_custom_column','hippoo_ticket_action_custom_columns_content', 10, 2 );
     73add_filter( 'manage_hippoo_ticket_posts_columns', 'hippoo_ticket_columns' );
    7074
    7175function hippoo_ticket_action_custom_columns_content( $column_id, $post_id ) {
     
    7377        $pid = absint( get_post_field( 'post_parent', $post_id ) );
    7478        $url = esc_url( admin_url( "post.php?post=$pid&action=edit" ) );
    75         echo wp_kses_post("<a href='$url' target='_blank'>#$pid</a>");
     79        echo wp_kses_post( "<a href='$url' target='_blank'>#$pid</a>" );
    7680    }
    7781
    78     if ( $column_id == 'ticket_id' )
     82    if ( $column_id == 'ticket_id' ) {
    7983        echo wp_kses_post( $post_id );
    80 
    81     if ( $column_id == 'ticket_status' )
     84    }
     85
     86    if ( $column_id == 'ticket_status' ) {
    8287        echo wp_kses_post( hippoo_ticket_status( $post_id ) );
    83 }
    84 
     88    }
     89}
     90
     91add_action( 'manage_hippoo_ticket_posts_custom_column','hippoo_ticket_action_custom_columns_content', 10, 2 );
    8592
    8693/**
    8794 * init
    88  */
    89 add_action( 'init', 'hippoo_ticket_hook_init' );
     95 *
     96 */
     97
    9098function hippoo_ticket_hook_init() {
    9199    $labels = array(
     
    126134        'show_in_admin_all_list'    => true,
    127135        'show_in_admin_status_list' => true,
    128         'label_count'               => _n_noop( 'Waiting for reply <span class="count">(%s)</span>', 'Waiting for reply <span class="count">(%s)</span>' ),
     136        /* translators: %s: number of tickets */
     137        'label_count'               => _n_noop( 'Waiting for reply <span class="count">(%s)</span>', 'Waiting for reply <span class="count">(%s)</span>', 'hippoo-ticket' ),
    129138    ) );
     139
    130140    register_post_status( 'hippoo_answered', array(
    131141        'label'                     => 'Answered',
     
    134144        'show_in_admin_all_list'    => true,
    135145        'show_in_admin_status_list' => true,
    136         'label_count'               => _n_noop( 'Answered <span class="count">(%s)</span>', 'Answered <span class="count">(%s)</span>' ),
     146        /* translators: %s: number of tickets */
     147        'label_count'               => _n_noop( 'Answered <span class="count">(%s)</span>', 'Answered <span class="count">(%s)</span>', 'hippoo-ticket' ),
    137148    ) );
     149
    138150    register_post_status( 'hippoo_close', array(
    139151        'label'                     => 'Closed',
     
    142154        'show_in_admin_all_list'    => true,
    143155        'show_in_admin_status_list' => true,
    144         'label_count'               => _n_noop( 'Closed <span class="count">(%s)</span>', 'Closed <span class="count">(%s)</span>' ),
     156        /* translators: %s: number of tickets */
     157        'label_count'               => _n_noop( 'Closed <span class="count">(%s)</span>', 'Closed <span class="count">(%s)</span>', 'hippoo-ticket' ),
    145158    ) );
    146159}
    147160
    148 
    149 add_action('admin_footer-post.php', 'hippoo_ticket_append_post_status_list');
    150 
    151 function hippoo_ticket_append_post_status_list(){
     161add_action( 'init', 'hippoo_ticket_hook_init' );
     162
     163function hippoo_ticket_append_post_status_list() {
    152164    global $post;
    153165
    154     if($post->post_type == 'hippoo_ticket'){
     166    if ( $post->post_type == 'hippoo_ticket' ) {
    155167        $statuses = [
    156             'hippoo_waiting' => 'Waiting for reply',
     168            'hippoo_waiting'  => 'Waiting for reply',
    157169            'hippoo_answered' => 'Answered',
    158             'hippoo_close' => 'Closed'
     170            'hippoo_close'    => 'Closed'
    159171        ];
    160172
     
    162174        $label = '';
    163175
    164         foreach($statuses as $state => $text){
     176        foreach ( $statuses as $state => $text ) {
    165177            $selected = selected( $post->post_status, $state, false );
    166178            $status_options .= "<option value='" . esc_attr($state) . "' $selected>" . esc_html($text) . "</option>";
    167179
    168             if($post->post_status == $state){
     180            if ( $post->post_status == $state ) {
    169181                $label = $text;
    170182            }
     
    175187                var statusSelect = document.querySelector("select#post_status");
    176188                if (statusSelect) {
    177                     statusSelect.innerHTML = "<?php echo esc_html($status_options); ?>";
     189                    statusSelect.innerHTML = "<?php echo esc_html( $status_options ); ?>";
    178190                }
    179191
    180192                var statusDisplay = document.querySelector("#post-status-display");
    181193                if (statusDisplay) {
    182                     statusDisplay.innerHTML += "<?php echo esc_html($label); ?>";
     194                    statusDisplay.innerHTML += "<?php echo esc_html( $label ); ?>";
    183195                }
    184196
     
    193205}
    194206
     207add_action( 'admin_footer-post.php', 'hippoo_ticket_append_post_status_list' );
    195208
    196209/**
    197210 * manage ticket table list
    198  */
    199     function hippoo_ticket_remove_quick_edit( $actions, $post ) {
    200         if($post->post_type == 'hippoo_ticket') {
    201             unset($actions['inline hide-if-no-js']);
     211 *
     212 */
     213
     214function hippoo_ticket_remove_quick_edit( $actions, $post ) {
     215    if ( $post->post_type == 'hippoo_ticket' ) {
     216        unset( $actions['inline hide-if-no-js'] );
     217    }
     218
     219    return $actions;
     220}
     221
     222add_filter( 'post_row_actions', 'hippoo_ticket_remove_quick_edit', 10, 2 );
     223
     224
     225function hippoo_ticket_custom_bulk_actions( $actions ) {
     226    $actions['status_close'] = 'Close Ticket';
     227    return $actions;
     228}
     229
     230add_filter( 'bulk_actions-edit-hippoo_ticket', 'hippoo_ticket_custom_bulk_actions' );
     231
     232function hippoo_ticket_handle_bulk_actions( $redirect_url, $action, $post_ids ) {
     233    if ( $action == 'status_close' ) {
     234        foreach ( $post_ids as $post_id ) {
     235            wp_update_post( [
     236                'ID' => $post_id,
     237                'post_status' => 'hippoo_close'
     238            ] );
    202239        }
    203 
    204         return $actions;
    205     }
    206     add_filter('post_row_actions','hippoo_ticket_remove_quick_edit',10,2);
    207 
    208 
    209     function hippoo_ticket_custom_bulk_actions($actions) {
    210         $actions['status_close']='Close Ticket';
    211         return $actions;
    212     }
    213     add_filter('bulk_actions-edit-hippoo_ticket','hippoo_ticket_custom_bulk_actions');
    214 
    215     add_filter('handle_bulk_actions-edit-hippoo_ticket', function($redirect_url, $action, $post_ids) {
    216         if ($action == 'status_close') {
    217             foreach ($post_ids as $post_id) {
    218                 wp_update_post([
    219                     'ID' => $post_id,
    220                     'post_status' => 'hippoo_close'
    221                 ]);
    222             }
    223             $redirect_url = add_query_arg('status_close', count($post_ids), $redirect_url);
    224         }
    225         return $redirect_url;
    226     }, 10, 3);
    227 
    228 
    229     add_action( 'after_delete_post', 'hippoo_ticket_delete_ticket_hook', 10, 2 );
    230     function hippoo_ticket_delete_ticket_hook( $post_id, $post ) {
    231         if ( 'hippoo_ticket' !== $post->post_type )
    232             return;
    233         global $wpdb;
    234         $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}hippoo_ticket WHERE pid = %d", $post_id));
    235     }
    236 
    237 
    238     function hippoo_ticket_change_the_author( $name ) {
    239         if(is_admin()){
    240             if ( !function_exists( 'get_current_screen' ) ) {
    241                require_once ABSPATH . '/wp-admin/includes/screen.php';
    242             }
    243             $screen = get_current_screen();
    244             if($screen->id != 'edit-hippoo_ticket')
    245                 return $name;
    246 
    247             global $post;
    248             return get_post_meta($post->post_parent,'_billing_first_name',true).' '.get_post_meta($post->post_parent,'_billing_last_name',true);
     240        $redirect_url = add_query_arg( 'status_close', count( $post_ids ), $redirect_url );
     241    }
     242    return $redirect_url;
     243}
     244
     245add_filter( 'handle_bulk_actions-edit-hippoo_ticket', 'hippoo_ticket_handle_bulk_actions', 10, 3 );
     246
     247function hippoo_ticket_delete_ticket_hook( $post_id, $post ) {
     248    global $wpdb;
     249    if ( 'hippoo_ticket' !== $post->post_type ) {
     250        return;
     251    }
     252    // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
     253    $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}hippoo_ticket WHERE pid = %d", $post_id ) );
     254    // phpcs:enable
     255}
     256
     257add_action( 'after_delete_post', 'hippoo_ticket_delete_ticket_hook', 10, 2 );
     258
     259function hippoo_ticket_change_the_author( $name ) {
     260    global $post;
     261
     262    if ( is_admin() ) {
     263        if ( ! function_exists( 'get_current_screen' ) ) {
     264            require_once ABSPATH . '/wp-admin/includes/screen.php';
    249265        }
    250     }
    251     add_filter( 'the_author', 'hippoo_ticket_change_the_author', 10, 1);
    252 
    253     function hippoo_ticket_admin_footer(){
    254         if(is_admin() && isset($_GET['post_type']) && $_GET['post_type'] == 'hippoo_ticket'){
    255         ?>
    256             <style type="text/css">
    257                 {
    258                     display: none;
    259                 }
    260             </style>
    261             <script type="text/javascript">
    262                 jQuery('a[href="post-new.php?post_type=hippoo_ticket"]').hide();
    263                 jQuery('a.page-title-action').hide();
    264             </script>
    265         <?php
     266
     267        $screen = get_current_screen();
     268        if ( $screen->id != 'edit-hippoo_ticket' ) {
     269            return $name;
    266270        }
    267     }
    268     add_action('admin_footer','hippoo_ticket_admin_footer');
    269 
    270 ?>
     271
     272        return get_post_meta( $post->post_parent, '_billing_first_name', true ) . ' ' . get_post_meta( $post->post_parent, '_billing_last_name', true );
     273    }
     274}
     275
     276add_filter( 'the_author', 'hippoo_ticket_change_the_author', 10, 1 );
  • hippoo-ticket/trunk/app/utils.php

    r3007682 r3265917  
    11<?php
    2     function hippoo_add_ticket($post_id, $content, $media_ids, $type, $user_id=0){
    3 
    4         # type:
    5         #    1 User
    6         #    2 Support
    7         $user_id = !empty($user_id) ? $user_id : get_current_user_id();
    8 
    9         // Check if $user_id is still empty or 0, then attempt to fetch author ID
    10         global $wpdb;
    11         if (empty($user_id)) {
    12             $author_id = $wpdb->get_var(
    13                 $wpdb->prepare("SELECT post_author FROM $wpdb->posts WHERE ID = %d", esc_sql($post_id))
     2
     3function hippoo_add_ticket( $post_id, $content, $media_ids, $type, $user_id = 0 ) {
     4    global $wpdb;
     5
     6    # type:
     7    #    1 User
     8    #    2 Support
     9    $user_id = ! empty( $user_id ) ? $user_id : get_current_user_id();
     10
     11    // Check if $user_id is still empty or 0, then attempt to fetch author ID
     12    if ( empty( $user_id ) ) {
     13        // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
     14        $author_id = $wpdb->get_var(
     15            $wpdb->prepare(
     16                "SELECT post_author FROM {$wpdb->posts} WHERE ID = %d",
     17                esc_sql( $post_id )
     18            )
     19        );
     20        // phpcs:enable
     21
     22        // Assign the retrieved author ID to $user_id only if it's not empty
     23        if ( $author_id ) {
     24            $user_id = $author_id;
     25        }
     26    }
     27   
     28    $post = get_post( $post_id );
     29
     30    if ( empty( $post ) ) {
     31        return array(
     32            "ticket_submited" => false,
     33            "message"         => "The post_id is not found"
     34        );
     35    }
     36   
     37    // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
     38    $ticket_id = $wpdb->get_var(
     39        $wpdb->prepare(
     40            "SELECT ID FROM {$wpdb->posts} WHERE post_type='hippoo_ticket' AND post_parent=%d",
     41            esc_sql( $post_id )
     42        )
     43    );
     44    // phpcs:enable
     45       
     46    if ( empty( $ticket_id ) ) {
     47        $args = [
     48            'post_title'  => "Ticket Number #$post_id",
     49            'post_author' => $user_id,
     50            'post_type'   => 'hippoo_ticket',
     51            'post_status' => 'hippoo_waiting',
     52            'post_parent' => $post_id
     53        ];
     54
     55        $ticket_id = wp_insert_post( $args );
     56    }
     57       
     58    if ( empty( $ticket_id ) ) {
     59        return array(
     60            "ticket_submited" => false,
     61            "message"         => "Unable to insert ticket"
     62        );
     63    }
     64       
     65    wp_update_post( [ 'ID' => $ticket_id, 'post_status' => ( $type == 1 ? 'hippoo_waiting' : 'hippoo_answered' ) ] );
     66   
     67    if ( function_exists('parsidate') ) {
     68        $date = parsidate( 'Y-m-d H:i:s', 'now', 'eng' );
     69    } else {
     70        $date = gmdate( 'Y-m-d H:i:s' );
     71    }
     72   
     73    $args = [
     74        'pid'       => $ticket_id,
     75        'uid'       => $user_id,
     76        'type'      => ( $type == 1 ? 'User' : 'Support' ),
     77        'date'      => $date,
     78        'content'   => esc_sql( $content ),
     79        'media_ids' => esc_sql( $media_ids ),
     80        'see'       => 0,
     81    ];
     82   
     83    // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
     84    $insert_result = $wpdb->insert( "{$wpdb->prefix}hippoo_ticket", $args );
     85    // phpcs:enable
     86
     87    if ( $insert_result != true ) {
     88        return array(
     89            "ticket_submited" => false,
     90            "message"         => "Unable to insert hippoo ticket"
     91        );
     92    }
     93   
     94    return array(
     95        "ticket_submited" => true,
     96        "message"         => "Ticket submited successfully"
     97    );
     98}
     99
     100function hippoo_ticket_status( $post_id, $item=3 ) {
     101    $status = get_post_status( $post_id );
     102    if ( ! in_array( $status, [ 'hippoo_waiting', 'hippoo_answered', 'hippoo_close' ] ) ) {
     103        return '';
     104    }
     105   
     106    if ( $item == 1 ) {
     107        return $status;
     108    }
     109   
     110    $label = get_post_status_object( $status )->label;
     111   
     112    if ( $item == 2 ) {
     113        return $label;
     114    }
     115   
     116    $color = $status == 'hippoo_answered' ? 'green' : ( $status == 'hippoo_close' ? 'red' : 'blue' );
     117    return "<span class='hippoo-status status-$color' style='color:$color'>$label</span>";
     118}
     119
     120function hippoo_ticket_sms( $ticket_id ){
     121    $opt = get_option( 'hippoo_ticket',[] );
     122}
     123
     124function hippoo_ticket_email( $ticket_id ) {
     125    global $wpdb;
     126
     127    $opt  = get_option( 'hippoo_ticket', [] );
     128    $url  = get_permalink( $opt['pg_ticket'] ) . "?oid=$ticket_id";
     129   
     130    // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
     131    $row = $wpdb->get_row(
     132        $wpdb->prepare(
     133            "SELECT post_title, user_login, user_email FROM {$wpdb->posts} p JOIN {$wpdb->users} u ON u.ID = post_author AND p.ID = %d",
     134            $ticket_id
     135        )
     136    );
     137    // phpcs:enable
     138
     139    $subj  = 'Tickets reply URL ' . home_url();
     140    $email = str_replace( [ '%user%', '%ticket%', '%url%' ], [ $row->user_login, $row->post_title, $url ], $opt['email'] );
     141
     142    wp_mail( $row->user_email, $subj, $email, [ 'Content-Type: text/html; charset=UTF-8' ] );
     143}
     144
     145function hippoo_ticket_get_ticket_order( $order_id ) {
     146    global $wpdb;
     147
     148    // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
     149    return $wpdb->get_row(
     150        $wpdb->prepare(
     151            "SELECT * FROM {$wpdb->posts} WHERE post_type='hippoo_ticket' AND post_parent=%d AND post_status IN ('hippoo_waiting', 'hippoo_answered', 'hippoo_close')",
     152            $order_id
     153        )
     154    );
     155    // phpcs:enable
     156}
     157
     158function hippoo_ticket_get_ticket( $ticket_id ) {
     159    global $wpdb;
     160
     161    // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
     162    return $wpdb->get_row(
     163        $wpdb->prepare(
     164            "SELECT * FROM {$wpdb->posts} WHERE post_type='hippoo_ticket' AND ID=%d",
     165            $ticket_id
     166        )
     167    );
     168    // phpcs:enable
     169}
     170
     171function hippoo_ticket_get_media_urls( $media_ids ) {
     172    $media_ids_array = explode( ',', $media_ids );
     173    $media_urls = array();
     174    foreach ( $media_ids_array as $media_id ) {
     175        $attachment_metadata = wp_get_attachment_metadata( $media_id );
     176        if ( $attachment_metadata ) {
     177            $media_url = wp_get_attachment_url( $media_id );
     178            $media_urls[] = $media_url;
     179        }
     180    }
     181    return $media_urls;
     182}
     183
     184function hippoo_ticket_get_media_urls_html( $media_ids ) {
     185    // phpcs:disable PluginCheck.CodeAnalysis.ImageFunctions.NonEnqueuedImage
     186    $html_img_template = "<li>
     187                <a href='#URL' target='BLANK'>
     188                    <img src='#URL' />
     189                </a>
     190                </li>";
     191    // phpcs:enable
     192    $html = "";
     193    $media_urls = hippoo_ticket_get_media_urls( $media_ids );
     194    foreach ( $media_urls as $media_url ) {
     195        $html .= str_replace( "#URL", $media_url, $html_img_template );
     196    }
     197    return $html;
     198}
     199
     200function hippoo_ticket_generate_tickets_table_body_html( $ticket_id ) {
     201    global $wpdb;
     202    $rows = null;
     203    if ( ! empty( $ticket_id ) ) {
     204        // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
     205        $rows = $wpdb->get_results(
     206            $wpdb->prepare(
     207                "SELECT * FROM {$wpdb->prefix}hippoo_ticket WHERE pid = %d ORDER BY id DESC",
     208                $ticket_id
     209            )
     210        );
     211        // phpcs:enable
     212
     213        foreach ( $rows as $row ) {
     214            $row->media_urls_html = hippoo_ticket_get_media_urls_html( $row->media_ids );
     215            $row->content = str_replace( '\"', '"', $row->content );
     216        }
     217    }
     218    return $rows;
     219}
     220               
     221function hippoo_ticket_media_upload() {
     222    // phpcs:ignore
     223    if ( empty( $_FILES['file'] ) ) {
     224        return new WP_Error( 'invalid_file', 'Invalid file.', [ 'status' => 400 ] );
     225    }
     226   
     227    $attachment_ids = array();
     228    $files = isset( $_FILES['file'] ) ? $_FILES['file'] : array(); // phpcs:ignore
     229   
     230    foreach ( $files['name'] as $index => $name ) {
     231        $file = array(
     232            'name'     => $name,
     233            'type'     => $files['type'][$index],
     234            'tmp_name' => $files['tmp_name'][$index],
     235            'error'    => $files['error'][$index],
     236            'size'     => $files['size'][$index]
     237        );
     238       
     239        // Check file size
     240        $file_size_limit = 350 * 1024; // 350 KB
     241        if ( $file['size'] > $file_size_limit ) {
     242            return new WP_Error( 'file_size_exceeded', 'File size exceeded the limit.', [ 'status' => 400 ] );
     243        }
     244       
     245        // Check file extension
     246        $allowed_extensions = array( 'png', 'jpg', 'jpeg' );
     247        $file_extension = strtolower( pathinfo( $file['name'], PATHINFO_EXTENSION ) );
     248        if ( ! in_array( $file_extension, $allowed_extensions ) ) {
     249            return new WP_Error( 'invalid_extension', 'Invalid file extension.', [ 'status' => 400 ] );
     250        }
     251       
     252        $upload = wp_upload_bits( $file['name'], null, file_get_contents( $file['tmp_name'] ) );
     253       
     254        if ( ! $upload['error'] ) {
     255            $attachment = array(
     256                'post_mime_type' => $upload['type'],
     257                'post_title'     => sanitize_file_name( $upload['file'] ),
     258                'post_content'   => '',
     259                'post_status'    => 'inherit'
    14260            );
    15261           
    16             // Assign the retrieved author ID to $user_id only if it's not empty
    17             if ($author_id) {
    18                 $user_id = $author_id;
    19             }
    20         }
    21        
    22         $post = get_post($post_id);
    23         if (empty($post))
    24             return array(
    25                 "ticket_submited" => false,
    26                 "message" => "The post_id is not found"
    27             );
    28 
    29         $ticket_id = $wpdb->get_var(
    30             $wpdb->prepare(
    31                 "SELECT ID FROM $wpdb->posts WHERE post_type='hippoo_ticket' AND post_parent=%d",
    32                  esc_sql($post_id))
    33             );
    34 
    35         if(empty($ticket_id)){
    36             $args = [
    37                 'post_title' =>"Ticket Number #$post_id",
    38                 'post_author'=>$user_id,
    39                 'post_type'  =>'hippoo_ticket',
    40                 'post_status'=>'hippoo_waiting',
    41                 'post_parent'=>$post_id
    42                 ];
    43             $ticket_id = wp_insert_post($args);
    44         }
    45 
    46         if (empty($ticket_id))
    47             return array(
    48                 "ticket_submited" => false,
    49                 "message" => "Unable to insert ticket"
    50             );
    51 
    52         wp_update_post(['ID' => $ticket_id,'post_status' => ($type==1?'hippoo_waiting':'hippoo_answered')]);
    53        
    54         if( function_exists('parsidate') ){
    55             $date = parsidate('Y-m-d H:i:s','now','eng');
    56         } else {
    57             $date = date('Y-m-d H:i:s');
    58         }
    59        
    60         $args = [
    61             'pid'       =>$ticket_id,
    62             'uid'       =>$user_id,
    63             'type'      =>($type==1?'User':'Support'),
    64             'date'      =>$date,
    65             'content'   =>esc_sql($content),
    66             'media_ids' =>esc_sql($media_ids),
    67             'see'       => 0,
    68             ];
    69        
    70         $insert_result = $wpdb->insert("{$wpdb->prefix}hippoo_ticket", $args);
    71         if ($insert_result != true)
    72             return array(
    73                 "ticket_submited" => false,
    74                 "message" => "Unable to insert hippoo ticket"
    75         );
    76 
    77         return array(
    78                 "ticket_submited" => true,
    79                 "message" => "Ticket submited successfully"
    80         );
    81     }
    82 
    83     function hippoo_ticket_status($post_id, $item=3){
    84         $status = get_post_status($post_id);
    85         if(!in_array($status,['hippoo_waiting','hippoo_answered','hippoo_close']))
    86             return '';
    87        
    88         if($item == 1)
    89             return $status;
    90        
    91         $label = get_post_status_object($status)->label;
    92        
    93         if($item == 2)
    94             return $label;
    95        
    96         $color = $status=='hippoo_waiting'?'green':($status=='hippoo_close'?'red':'blue');
    97         return "<span style='color:$color'>$label</span>";
    98     }
    99 
    100     function hippoo_ticket_sms($ticket_id){
    101         $opt = get_option('hippoo_ticket',[]);
    102     }
    103 
    104     function hippoo_ticket_email($ticket_id){
    105 
    106         global $wpdb;
    107         $opt  = get_option('hippoo_ticket',[]);
    108         $url  = get_permalink($opt['pg_ticket'])."?oid=$ticket_id";
    109         $row = $wpdb->get_row(
    110             $wpdb->prepare(
    111                 "SELECT post_title, user_login, user_email FROM $wpdb->posts p JOIN $wpdb->users u ON u.ID = post_author AND p.ID = %d",
    112                 $ticket_id
    113                 )
    114             );
    115         $subj = 'Tickets reply URL '.home_url();
    116         $email= str_replace(['%user%','%ticket%','%url%'],[$row->user_login,$row->post_title,$url],$opt['email']);
    117         wp_mail($row->user_email,$subj,$email,['Content-Type: text/html; charset=UTF-8']);
    118     }
    119 
    120     function hippoo_ticket_get_ticket_order($order_id){
    121         global $wpdb;
    122         return $wpdb->get_row(
    123                 $wpdb->prepare(
    124                     "SELECT * FROM $wpdb->posts WHERE post_type='hippoo_ticket' AND post_parent=%d AND post_status IN ('hippoo_waiting', 'hippoo_answered', 'hippoo_close')",
    125                 $order_id
    126             )
    127         );
    128     }
    129 
    130 
    131     function hippoo_ticket_get_ticket($ticket_id){
    132         global $wpdb;
    133         return $wpdb->get_row(
    134                 $wpdb->prepare(
    135                     "SELECT * FROM $wpdb->posts WHERE post_type='hippoo_ticket' AND ID = %d",
    136                     $ticket_id
    137                     )
    138                 );
    139     }
    140 
    141     function hippoo_ticket_get_media_urls($media_ids) {
    142         $media_ids_array = explode(',', $media_ids);
    143         $media_urls = array();
    144         foreach ($media_ids_array as $media_id) {
    145             $attachment_metadata = wp_get_attachment_metadata($media_id);
    146             if ($attachment_metadata) {
    147                 $media_url = wp_get_attachment_url($media_id);
    148                 $media_urls[] = $media_url;
    149             }
    150         }
    151         return $media_urls;
    152     }
    153    
    154     function hippoo_ticket_get_media_urls_html($media_ids) {
    155         $html_img_template = "<li>
    156                                 <a href='#URL' target='BLANK'>
    157                                     <img src='#URL' />
    158                                 </a>
    159                              </li>";
    160         $html = "";
    161         $media_urls = hippoo_ticket_get_media_urls($media_ids);
    162         foreach ($media_urls as $media_url) {
    163             $html .= str_replace("#URL", $media_url, $html_img_template);
    164         }
    165        
    166         return $html;
    167     }
    168 
    169     function hippoo_ticket_generate_tickets_table_body_html($ticket_id){
    170         $rows = null;
    171         global $wpdb;
    172         $table_name = $wpdb->prefix . 'hippoo_ticket';
    173         if (!empty($ticket_id)) {
    174             $prepared_query = $wpdb->prepare(
    175                 "SELECT * FROM $table_name
    176                 WHERE pid = %d
    177                 ORDER BY id DESC",
    178                 $ticket_id
    179             );
    180 
    181             $rows = $wpdb->get_results($prepared_query);
    182 
    183             foreach ($rows as $row) {
    184                 $row->media_urls_html = hippoo_ticket_get_media_urls_html($row->media_ids);
    185                 $row->content = str_replace('\"', '"', $row->content);
    186             }
    187         }
    188         return $rows;
    189     }
    190 
    191     function hippoo_ticket_media_upload(){
    192     if (empty($_FILES['file'])) {
    193         return new WP_Error('invalid_file', 'Invalid file.', ['status' => 400]);
    194     }
    195 
    196     $attachment_ids = array();
    197     $files = isset($_FILES['file']) ? $_FILES['file'] : array();
    198 
    199     foreach ($files['name'] as $index => $name) {
    200         $file = array(
    201             'name' => $name,
    202             'type' => $files['type'][$index],
    203             'tmp_name' => $files['tmp_name'][$index],
    204             'error' => $files['error'][$index],
    205             'size' => $files['size'][$index]
    206         );
    207 
    208         // Check file size
    209         $file_size_limit = 350 * 1024; // 350 KB
    210         if ($file['size'] > $file_size_limit) {
    211             return new WP_Error('file_size_exceeded', 'File size exceeded the limit.', ['status' => 400]);
    212         }
    213 
    214         // Check file extension
    215         $allowed_extensions = array('png', 'jpg', 'jpeg');
    216         $file_extension = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION));
    217         if (!in_array($file_extension, $allowed_extensions)) {
    218             return new WP_Error('invalid_extension', 'Invalid file extension.', ['status' => 400]);
    219         }
    220 
    221         $upload = wp_upload_bits($file['name'], null, file_get_contents($file['tmp_name']));
    222 
    223         if (!$upload['error']) {
    224             $attachment = array(
    225                 'post_mime_type' => $upload['type'],
    226                 'post_title' => sanitize_file_name($upload['file']),
    227                 'post_content' => '',
    228                 'post_status' => 'inherit'
    229             );
    230 
    231             $attachment_id = wp_insert_attachment($attachment, $upload['file']);
    232 
    233             if (!is_wp_error($attachment_id)) {
    234                 $attachment_data = wp_generate_attachment_metadata($attachment_id, $upload['file']);
    235                 wp_update_attachment_metadata($attachment_id, $attachment_data);
     262            $attachment_id = wp_insert_attachment( $attachment, $upload['file'] );
     263           
     264            if ( ! is_wp_error( $attachment_id ) ) {
     265                $attachment_data = wp_generate_attachment_metadata( $attachment_id, $upload['file'] );
     266                wp_update_attachment_metadata( $attachment_id, $attachment_data );
    236267                $attachment_ids[] = $attachment_id;
    237268            }
    238269        }
    239270    }
    240     $attachment_ids = implode(',', $attachment_ids);
     271    $attachment_ids = implode( ',', $attachment_ids );
    241272    return $attachment_ids;
    242     }
    243 
    244 ?>
     273}
  • hippoo-ticket/trunk/app/web_api.php

    r3007682 r3265917  
    22if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly     
    33
    4 add_action('rest_api_init', function () {
    5     require_once __DIR__ . DIRECTORY_SEPARATOR .'web_api_auth.php';
     4add_action( 'rest_api_init', function () {
     5    require_once hippoo_ticket_path . 'app/web_api_auth.php';
    66    $controller = new HippooTicketControllerWithAuth();
    77    $controller->register_routes();
    8 });
    9 ?>
     8} );
  • hippoo-ticket/trunk/app/web_api_auth.php

    r3038770 r3265917  
    33class HippooTicketControllerWithAuth extends WC_REST_Customers_Controller {
    44
    5     public function register_routes()
    6     {
     5    public function register_routes() {
    76        #
    87        $args_hippoo_ticket_insert = array(
     
    1716        $args_hippoo_ticket_list = array(
    1817            'methods'  => 'GET',
    19             'callback' => array( $this, 'hippoo_ticket_list'),
     18            'callback' => array( $this, 'hippoo_ticket_list' ),
    2019            'permission_callback' => array( $this, 'hippo_edit_other_post_permissions_check' ),
    2120            'args'                => array(
     
    3130        $args_hippoo_ticket_get_ticket_info_by_ticket_id = array(
    3231            'methods'  => 'GET',
    33             'callback' => array( $this, 'hippoo_ticket_get_ticket_info_by_ticket_id'),
     32            'callback' => array( $this, 'hippoo_ticket_get_ticket_info_by_ticket_id' ),
    3433            'permission_callback' => array( $this, 'hippo_edit_other_post_permissions_check' ),
    3534            'args'                => array(
    3635                                            'id' => array(
    3736                                                'required' => true,
    38                                                 'validate_callback' => function ($param, $request, $key) {
    39                                                     return is_numeric($param);
     37                                                'validate_callback' => function ( $param, $request, $key ) {
     38                                                    return is_numeric( $param );
    4039                                                }
    4140                                            ),
     
    4645        );
    4746        register_rest_route( 'wc-hippoo/v1', 'wp/tickets/(?P<id>\d+)', $args_hippoo_ticket_get_ticket_info_by_ticket_id );
    48 
    4947       
    5048        #
    5149        $args_hippoo_ticket_get_ticket_info_by_order = array(
    5250            'methods'  => 'GET',
    53             'callback' => array( $this, 'args_hippoo_ticket_get_ticket_info_by_order'),
     51            'callback' => array( $this, 'args_hippoo_ticket_get_ticket_info_by_order' ),
    5452            'permission_callback' => array( $this, 'hippo_edit_other_post_permissions_check' )
    5553
     
    6058        $args_hippoo_ticket_delete = array(
    6159            'methods'  => 'GET',
    62             'callback' => array( $this, 'hippoo_ticket_delete'),
    63             'permission_callback' => array( $this, 'hippo_edit_other_post_permissions_check' )
    64 
    65         );
    66         register_rest_route( 'wc-hippoo/v1', 'wp/tickets/(?P<id>\d+)/delete', $args_hippoo_ticket_delete);
     60            'callback' => array( $this, 'hippoo_ticket_delete' ),
     61            'permission_callback' => array( $this, 'hippo_edit_other_post_permissions_check' )
     62
     63        );
     64        register_rest_route( 'wc-hippoo/v1', 'wp/tickets/(?P<id>\d+)/delete', $args_hippoo_ticket_delete );
    6765       
    6866        #
    6967        $args_hippoo_ticket_update_status = array(
    7068            'methods'  => 'POST',
    71             'callback' => array( $this, 'hippoo_ticket_update_status'),
    72             'permission_callback' => array( $this, 'hippo_edit_other_post_permissions_check' )
    73 
    74         );
    75         register_rest_route( 'wc-hippoo/v1', 'wp/tickets/(?P<id>\d+)/status', $args_hippoo_ticket_update_status);
    76        
     69            'callback' => array( $this, 'hippoo_ticket_update_status' ),
     70            'permission_callback' => array( $this, 'hippo_edit_other_post_permissions_check' )
     71
     72        );
     73        register_rest_route( 'wc-hippoo/v1', 'wp/tickets/(?P<id>\d+)/status', $args_hippoo_ticket_update_status );
    7774       
    7875        #
    7976        $args_hippoo_ticket_count = array(
    8077            'methods'  => 'GET',
    81             'callback' => array( $this, 'hippoo_ticket_count'),
    82             'permission_callback' => array( $this, 'hippo_edit_other_post_permissions_check' )
    83 
    84         );
    85         register_rest_route( 'wc-hippoo/v1', 'wp/tickets/count', $args_hippoo_ticket_count);
    86     }
    87 
    88     function hippo_edit_other_post_permissions_check(){
     78            'callback' => array( $this, 'hippoo_ticket_count' ),
     79            'permission_callback' => array( $this, 'hippo_edit_other_post_permissions_check' )
     80
     81        );
     82        register_rest_route( 'wc-hippoo/v1', 'wp/tickets/count', $args_hippoo_ticket_count );
     83    }
     84
     85    function hippo_edit_other_post_permissions_check() {
    8986        return current_user_can( 'edit_posts' );
    9087    }
    9188
    92     function hippoo_ticket_delete($data){
    93        
    94         $ticket = hippoo_ticket_get_ticket_order($data['id']);
    95        
    96         if(empty($ticket))
     89    function hippoo_ticket_delete( $data ) {
     90        $ticket = hippoo_ticket_get_ticket_order( $data['id'] );
     91        if ( empty( $ticket ) ) {
    9792            $response =  array(
    98                     'message' => 'No ticket found',
    99                 );
    100             return new WP_REST_Response($response, 200);
    101            
    102 
    103         wp_delete_post($ticket->ID);
     93                'message' => 'No ticket found',
     94            );
     95            return new WP_REST_Response( $response, 200 );
     96        }
     97        wp_delete_post( $ticket->ID );
    10498        $response =  array(
    105                     'message' => 'Ticket deleted',
    106                     );
    107         return new WP_REST_Response($response, 200);
    108     }
    109 
    110     function hippoo_ticket_update_status($data){
     99            'message' => 'Ticket deleted',
     100        );
     101        return new WP_REST_Response( $response, 200 );
     102    }
     103
     104    function hippoo_ticket_update_status( $data ) {
    111105        $status = $data->get_json_params()['status'];
    112         $ticket = hippoo_ticket_get_ticket_order($data['id']);
    113         wp_update_post(['ID' => $ticket->ID,'post_status' => $status]);
     106        $ticket = hippoo_ticket_get_ticket_order( $data['id'] );
     107        wp_update_post( [ 'ID' => $ticket->ID, 'post_status' => $status ] );
    114108        $response =  array(
    115                     'message' => 'Ticket status updated',
    116                     );
    117         return new WP_REST_Response($response, 200);
    118     }
    119 
    120     function hippoo_ticket_insert($data){
    121         global $wpdb,$hippoo_ticket_api_page;
    122         $arr = $data->get_json_params();
    123 
    124         $post_id    = $arr['post_id'];
    125         $content    = $arr['content'];
    126         $media_ids  = implode(',', $arr['media_ids']);
    127         $user_id    = get_post_meta($post_id, '_customer_user', true);
    128         $type       = 2;
    129 
    130         $hippoo_add_ticket_submmited = hippoo_add_ticket($post_id, $content, $media_ids, $type, $user_id);
    131 
    132         return new WP_REST_Response($hippoo_add_ticket_submmited, 200);
    133     }
    134 
    135     function hippoo_ticket_list($data){
    136         global $wpdb,$hippoo_ticket_api_page;
    137 
    138         if (!empty($data['page'])) {
    139             $page = esc_sql($data['page']);
     109            'message' => 'Ticket status updated',
     110        );
     111        return new WP_REST_Response( $response, 200 );
     112    }
     113
     114    function hippoo_ticket_insert( $data ) {
     115        global $wpdb, $hippoo_ticket_api_page;
     116        $arr       = $data->get_json_params();
     117        $post_id   = $arr['post_id'];
     118        $content   = $arr['content'];
     119        $media_ids = implode( ',', $arr['media_ids'] );
     120        $user_id   = get_post_meta( $post_id, '_customer_user', true );
     121        $type      = 2;
     122        $hippoo_add_ticket_submmited = hippoo_add_ticket( $post_id, $content, $media_ids, $type, $user_id );
     123        return new WP_REST_Response( $hippoo_add_ticket_submmited, 200 );
     124    }
     125
     126    function hippoo_ticket_list( $data ) {
     127        global $wpdb, $hippoo_ticket_api_page;
     128
     129        if ( ! empty( $data['page'] ) ) {
     130            $page = esc_sql( $data['page'] );
    140131        } else {
    141132            $page = "1";
    142133        }
     134
    143135        $page = --$page * $hippoo_ticket_api_page;
    144136
    145         $hippoo_ticket_table_name = $wpdb->prefix . 'hippoo_ticket';
    146         $query = $wpdb->prepare(
    147             "SELECT p.*, (
    148                 SELECT content FROM $hippoo_ticket_table_name WHERE pid = p.id ORDER BY id DESC LIMIT 1
    149             ) AS latest
    150             FROM $wpdb->posts p
    151             WHERE p.post_type = 'hippoo_ticket' AND p.post_status IN ('hippoo_waiting', 'hippoo_answered', 'hippoo_close')
    152             ORDER BY p.ID DESC
    153             LIMIT %d, %d",
    154             $page,
    155             $hippoo_ticket_api_page
    156         );
    157         $rows = $wpdb->get_results($query);
    158         if(empty($rows))
    159         {
    160             $response =  array();
    161             return new WP_REST_Response($response, 200);
    162         }
     137        // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
     138        $rows = $wpdb->get_results(
     139            $wpdb->prepare(
     140                "SELECT p.*, (
     141                    SELECT content FROM {$wpdb->prefix}hippoo_ticket WHERE pid = p.id ORDER BY id DESC LIMIT 1
     142                ) AS latest
     143                FROM $wpdb->posts p
     144                WHERE p.post_type = 'hippoo_ticket' AND p.post_status IN ('hippoo_waiting', 'hippoo_answered', 'hippoo_close')
     145                ORDER BY p.ID DESC
     146                LIMIT %d, %d",
     147                $page,
     148                $hippoo_ticket_api_page
     149            )
     150        );
     151        // phpcs:enable
     152
     153        if ( empty( $rows ) ) {
     154            $response = array();
     155            return new WP_REST_Response( $response, 200 );
     156        }
     157
    163158        $out = [];
    164         foreach($rows as $ticket){
    165 
     159        foreach ( $rows as $ticket ) {
    166160            $out[] = [
    167161                'ticket_id'=> $ticket->ID,
    168162                'order_id' => $ticket->post_parent,
    169                 'customer_name' => get_post_meta($ticket->post_parent,'_billing_first_name',true).' '.get_post_meta($ticket->post_parent,'_billing_last_name',true),
    170                 'customer_phone'=> get_post_meta($ticket->post_parent,'_billing_phone',true),
    171                 'customer_email'=> get_post_meta($ticket->post_parent,'_billing_email',true),
     163                'customer_name' => get_post_meta( $ticket->post_parent, '_billing_first_name', true ) . ' '. get_post_meta( $ticket->post_parent, '_billing_last_name', true ),
     164                'customer_phone'=> get_post_meta( $ticket->post_parent, '_billing_phone', true ),
     165                'customer_email'=> get_post_meta( $ticket->post_parent, '_billing_email', true ),
    172166                'date'         => $ticket->post_date,
    173167                'latest_reply' => $ticket->latest,
     
    175169            ];
    176170        }
     171       
    177172        return new WP_REST_Response( $out, 200 );
    178173    }
    179174
    180     function hippoo_ticket_get_ticket_info_by_order_id($data){
    181 
    182         $order   = wc_get_order( $data['id'] );
    183         if(empty($order))
    184         {
    185             $response =  array();
    186             return new WP_REST_Response($response, 200);
    187         }
    188 
    189         $ticket  = hippoo_ticket_get_ticket_order($data['id']);
    190         return $this->hippoo_ticket_get_tickets_and_replies($ticket);
    191     }
    192 
    193     function hippoo_ticket_get_ticket_info_by_ticket_id($data){
    194 
    195         if (empty($data['id'])) {
    196             $response =  array(
    197                     'message' => 'ticket_id not found',
     175    function hippoo_ticket_get_ticket_info_by_order_id( $data ) {
     176        $order = wc_get_order( $data['id'] );
     177        if ( empty( $order ) ) {
     178            $response = array();
     179            return new WP_REST_Response( $response, 200 );
     180        }
     181        $ticket = hippoo_ticket_get_ticket_order( $data['id'] );
     182        return $this->hippoo_ticket_get_tickets_and_replies( $ticket );
     183    }
     184
     185    function hippoo_ticket_get_ticket_info_by_ticket_id( $data ) {
     186        if ( empty( $data['id'] ) ) {
     187            $response = array(
     188                'message' => 'ticket_id not found',
    198189            );
    199             return new WP_REST_Response($response, 200);
     190            return new WP_REST_Response( $response, 200 );
    200191        }
    201192        $ticket_id = $data['id'];
    202         $ticket = hippoo_ticket_get_ticket($ticket_id);
    203 
    204         if (empty($ticket)) {
    205             $response =  array();
    206             return new WP_REST_Response($response, 200);
    207         }
    208         return $this->hippoo_ticket_get_tickets_and_replies($ticket,$data);
    209     }
    210 
    211     function hippoo_ticket_get_tickets_and_replies($ticket, $data){
    212         global $wpdb,$hippoo_ticket_api_page;
    213 
    214         if (!empty($data['page'])) {
    215             $page = esc_sql($data['page']);
     193        $ticket = hippoo_ticket_get_ticket( $ticket_id );
     194        if ( empty( $ticket ) ) {
     195            $response = array();
     196            return new WP_REST_Response( $response, 200 );
     197        }
     198        return $this->hippoo_ticket_get_tickets_and_replies( $ticket, $data );
     199    }
     200
     201    function hippoo_ticket_get_tickets_and_replies( $ticket, $data ){
     202        global $wpdb, $hippoo_ticket_api_page;
     203
     204        if ( ! empty( $data['page'] ) ) {
     205            $page = esc_sql( $data['page'] );
    216206        } else {
    217207            $page = "1";
    218208        }
     209
    219210        $page = --$page * $hippoo_ticket_api_page;
    220         $query = $wpdb->prepare(
    221             "SELECT id, date, type as uby, content as value, media_ids
    222             FROM {$wpdb->prefix}hippoo_ticket
    223             WHERE pid = %d
    224             ORDER BY id DESC
    225             LIMIT %d, %d",
    226             $ticket->ID,
    227             $page,
    228             $hippoo_ticket_api_page
    229         );
    230         $replies = $wpdb->get_results($query);
    231         foreach($replies as $i=>$rep){
    232             if (property_exists($rep, 'media_ids') ) {
    233                 $media_urls =  hippoo_ticket_get_media_urls($rep->media_ids);
     211
     212        // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
     213        $replies = $wpdb->get_results(
     214            $wpdb->prepare(
     215                "SELECT id, date, type as uby, content as value, media_ids
     216                FROM {$wpdb->prefix}hippoo_ticket
     217                WHERE pid = %d
     218                ORDER BY id DESC
     219                LIMIT %d, %d",
     220                $ticket->ID,
     221                $page,
     222                $hippoo_ticket_api_page
     223            )
     224        );
     225        // phpcs:enable
     226
     227        foreach ( $replies as $i=>$rep ) {
     228            if ( property_exists( $rep, 'media_ids' ) ) {
     229                $media_urls = hippoo_ticket_get_media_urls( $rep->media_ids );
    234230                $replies[$i]->media_urls = $media_urls;
    235231            }
    236232        }
     233
    237234        $out = [
    238             'ticket_id'=> $ticket->ID,
    239             'order_id' => $ticket->post_parent,
    240             'customer_name' =>get_post_meta($ticket->post_parent,'_billing_first_name',true).' '.get_post_meta($ticket->post_parent,'_billing_last_name',true),
    241             'customer_phone'=>get_post_meta($ticket->post_parent,'_billing_phone',true),
    242             'customer_email'=>get_post_meta($ticket->post_parent,'_billing_email',true),
    243             'status'  =>$ticket->post_status,
    244             'replies' =>$replies
     235            'ticket_id' => $ticket->ID,
     236            'order_id'  => $ticket->post_parent,
     237            'customer_name'  => get_post_meta( $ticket->post_parent, '_billing_first_name', true ) . ' ' . get_post_meta( $ticket->post_parent, '_billing_last_name', true ),
     238            'customer_phone' => get_post_meta( $ticket->post_parent, '_billing_phone', true ),
     239            'customer_email' => get_post_meta( $ticket->post_parent, '_billing_email', true ),
     240            'status'  => $ticket->post_status,
     241            'replies' => $replies
    245242        ];
     243
    246244        return new WP_REST_Response( $out, 200 );
    247245    }
    248246
    249     function hippoo_ticket_count($data){
    250         global $wpdb,$hippoo_ticket_api_page;
     247    function hippoo_ticket_count( $data ) {
     248        global $wpdb, $hippoo_ticket_api_page;
     249
     250        // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
    251251        $cnt = $wpdb->get_var(
    252252            $wpdb->prepare(
    253                 "SELECT COUNT(ID) FROM $wpdb->posts WHERE post_type = %s AND post_status = %s",
     253                "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_type = %s AND post_status = %s",
    254254                'hippoo_ticket',
    255255                'hippoo_waiting'
    256256            )
    257257        );
    258         return new WP_REST_Response($cnt, 200);
    259     }
    260     }
     258        // phpcs:enable
     259
     260        return new WP_REST_Response( $cnt, 200 );
     261    }
     262}
  • hippoo-ticket/trunk/assets/css/style.css

    r3007682 r3265917  
    1 /* Style the barcode button */
    2 .barcode-button {
    3     display: inline-block;
    4     border: none;
     1.hippoo-ticket-container {
     2    display: flex;
     3    flex-direction: column;
     4    gap: 20px;
     5}
     6
     7.hippoo-ticket-nav a {
     8    display: inline-flex;
     9    align-items: center;
     10    gap: 5px;
     11}
     12
     13.hippoo-ticket-nav a::before {
     14    content: "";
     15    display: inline-block;
     16    width: 8px;
     17    height: 8px;
     18    border-left: 2px solid currentColor;
     19    border-bottom: 2px solid currentColor;
     20    transform: rotate(45deg);
     21    margin-right: 4px;
     22}
     23
     24.hippoo-ticket-head {
     25    display: flex;
     26    flex-direction: row;
     27    justify-content: space-between;
     28    gap: 20px;
     29    padding: 15px 25px;
     30    margin-bottom: 20px;
     31    border: 1px solid #e7e7e7;
     32    border-radius: 8px;
     33}
     34
     35.hippoo-ticket-meta p {
     36    flex: 1;
    537    margin: 0;
    638    padding: 0;
    7     color: #0073aa;
    8     border:1px solid #0073aa;
    9     cursor: pointer;
    10     border-radius: 3px;
    11     font-size: 14px;
    12     font-weight: 600;
    13     padding: 5px 10px;
    14     text-decoration: none;
     39    box-sizing: border-box;
     40    font-weight: bold;
     41}
     42
     43.hippoo-ticket-form textarea {
     44    resize: none;
     45    outline: none;
     46    box-shadow: none;
     47    border: 1px solid #e7e7e7;
     48    border-radius: 8px;
     49    width: 100%;
     50}
     51
     52.hippoo-upload-label {
     53    cursor: pointer;
     54}
     55
     56.hippoo-upload-label::before {
     57    content: "";
     58    display: inline-block;
     59    width: 18px;
     60    height: 18px;
     61    margin-left: 8px;
     62    background-image: url("../images/attach.svg");
     63    background-size: contain;
     64    background-repeat: no-repeat;
     65    vertical-align: middle;
    1566    position: relative;
    16 }
    17 .barcode-button img {
    18     max-width: 100%;
    19     height: auto;
     67    top: -1px;
     68}
     69
     70.hippoo-form-group {
     71    margin-bottom: 20px;
     72}
     73
     74.hippoo-form-actions {
     75    display: flex;
     76    flex-direction: row;
     77    justify-content: space-between;
     78    align-items: center;
     79}
     80
     81.hippoo-file-upload {
     82    flex: 1;
     83    display: flex;
     84    align-items: center;
     85}
     86
     87.hippoo-upload-preview {
     88    display: flex;
     89    flex-direction: row;
     90    gap: 10px;
     91}
     92
     93.hippoo-upload-item {
     94    width: 60px;
     95    height: 40px;
     96    position: relative;
     97}
     98
     99.hippoo-upload-item img {
     100    width: 100%;
     101    max-height: 40px;
     102    border-radius: 5px;
     103}
     104
     105.hippoo-remove-file {
     106    content: "";
     107    display: inline-block;
     108    width: 15px;
     109    height: 15px;
     110    background-color: #ffffff;
     111    background-image: url("../images/close.svg");
     112    background-size: contain;
     113    background-repeat: no-repeat;
     114    border: 1px solid #a8a8a8;
     115    border-radius: 25px;
    20116    vertical-align: middle;
    21     width: 100px;
    22 }
    23 .hippoo-download{
    24     display: inline-block;
    25     width: 300px;
    26     height: auto;
    27 }
    28 .barcode-ico{
    29     display: block;
    30     height: 24px !important;
    31     width: 24px !important;
    32     color: #0073aa;
    33 }
    34 
    35 /* Style the tooltip */
    36 .barcode-button span {
    37     visibility: hidden;
    38117    position: absolute;
    39     top: -70px;
    40     left: 50%;
    41     transform: translateX(-50%);
    42     background-color: #333;
    43     color: #fff;
    44     text-align: center;
    45     padding: 20px;
    46     border-radius: 5px;
    47     font-size: 16px;
    48     z-index: 1;
    49 }
    50 
    51 .barcode-button:hover span {
    52     visibility: visible;
    53 }
    54 
    55 
    56 /* Style of the config page */
    57 .wh-heading{
    58     font-weight: 700 !important;
    59     font-size: 22px !important;
    60     line-height: 30px !important;
    61     color: #444444 !important;
    62 }
    63 
    64 .short-desc:after {
    65     content:"";
    66     display:block;
    67     clear:both;
    68 }
    69 
    70 .short-desc .left{
    71     width: 65%;
    72     float: left;
    73 }
    74 
    75 .short-desc .left p{
    76     font-weight: 400;
    77     font-size: 19px;
    78     line-height: 28px;
    79     color: #000000;
    80     padding-right: 80px;
    81 }
    82 
    83 .short-desc .right{
    84     width: 35%;
    85     float: right;
    86 }
    87 
    88 .short-desc .right div{
    89     background: #FFFFFF;
    90     border: 1px solid #DEDEDE;
    91     border-radius: 16px;
    92     text-align: center;
    93     padding: 32px;
    94     display: inline-block;
    95     max-width: 320px;
    96     font-weight: 600;
    97     font-size: 18px;
    98     line-height: 25px;
    99     text-align: center;
    100     color: #000000;
    101     float: right
    102 }
    103 
    104 .short-desc .right div img{
    105     display: block;
    106     margin: 0 auto;
    107     margin-bottom: 20px;
    108     width: 200px;
    109     height: auto;
    110 }
    111 
    112 .extentions{
    113     border-top: 1px solid #D6D6D6;
    114     margin-top: 35px;
    115 }
    116 
    117 .extentions > strong{
    118     font-weight: 700;
    119     font-size: 19px;
    120     line-height: 26px;
    121     color: #444444;
    122     position: relative;
    123     top: -15px;
    124     background: #f0f0f1;
    125     padding: 15px 15px 15px 0
    126 }
    127 
    128 .extentions > p{
    129     font-weight: 400;
    130     font-size: 18px;
    131     line-height: 25px;
    132     color: #000000;
    133 }
    134 
    135 .extentions .item{
    136     width: 49%;
    137     display: inline-block;
    138     float: left
    139 }
    140 
    141 .extentions .item .item-inner{
    142     background: #FFFFFF;
    143     border: 1px solid #DEDEDE;
    144     border-radius: 16px;
    145     min-height: 200px;
    146     margin: 15px 15px 15px 0;
    147     padding: 30px;
    148     position: relative
    149 }
    150 
    151 .extentions .item:nth-of-type(2n) .item-inner{
    152     margin: 15px 0 15px 15px;
    153 }
    154 
    155 .extentions .item .item-inner strong{
    156     font-weight: 700;
    157     font-size: 16px;
    158     line-height: 25px;
    159     height: 75px;
    160     color: #000000;
    161     display: block
    162 }
    163 
    164 .extentions .item .item-inner p{
    165     font-weight: 400;
     118    top: -5px;
     119    right: -5px;
     120    z-index: 10000;
     121    cursor: pointer;
     122}
     123
     124.hippoo-empty-conversation {
     125    display: flex;
     126    flex-direction: column;
     127    justify-content: center;
     128    align-items: center;
     129    padding: 15px 25px;
     130    margin-bottom: 20px;
     131    background-color: #fdfdfd;
     132    border: 1px solid #e7e7e7;
     133    border-radius: 8px;
     134    min-height: 280px;
     135}
     136
     137.hippoo-conversation-list {
     138    display: flex;
     139    flex-direction: column;
     140    margin-bottom: 20px;
     141    background-color: #fdfdfd;
     142    border: 1px solid #e7e7e7;
     143    border-radius: 8px;
     144    min-height: 280px;
     145}
     146
     147.hippoo-conversation-item {
     148    display: flex;
     149    flex-direction: column;
     150    gap: 10px;
     151    width: 100%;
     152    padding: 25px;
     153    border-bottom: 1px solid #eeeeee;
     154}
     155
     156.hippoo-conversation-item:last-child {
     157    border-bottom: none;
     158}
     159
     160.hippoo-conversation-meta {
     161    display: flex;
     162    flex-direction: row;
     163    align-items: center;
     164    gap: 10px;
     165}
     166
     167.hippoo-avatar img {
     168    border-radius: 25px;
     169}
     170
     171.hippoo-conversation-details {
     172    display: flex;
     173    flex-direction: column;
    166174    font-size: 14px;
    167     line-height: 22px;
    168     color: #000000;
    169 }
    170 
    171 .extentions .item .item-inner a{
    172     background: #5F238D;
    173     border-radius: 60px;
    174     padding: 10px 45px 12px;
    175     font-weight: 700;
    176     font-size: 14px;
    177     color: #FFFFFF;
    178     text-decoration: none;
    179     float: left
    180 }
    181 
    182 .extentions .item .item-inner span{
    183     float: right;
    184     font-weight: 700;
    185     font-size: 18px;
    186     line-height: 25px;
    187     color: #5F238D;
    188     margin: 7px 0 0 0;
    189 }
    190 
    191 .extentions .item .item-inner img{
    192     background: #CFCFCF;
    193     border-radius: 8px;
    194     position: absolute;
    195     width: 75px;
    196     height: auto;
    197     top: 30px;
    198     right: 30px;
    199 }
    200 
    201 @media only screen and (max-width: 480px) {
    202 
    203     .short-desc .left,
    204     .short-desc .right{
    205         width: 100%;
    206         float: none;
     175}
     176
     177.hippoo-conversation-media .hippoo-attachments-label::before {
     178    content: "";
     179    display: inline-block;
     180    width: 18px;
     181    height: 18px;
     182    margin-right: 8px;
     183    background-image: url("../images/attach.svg");
     184    background-size: contain;
     185    background-repeat: no-repeat;
     186    vertical-align: middle;
     187    position: relative;
     188    top: -1px;
     189}
     190
     191.hippoo-conversation-media ul {
     192    margin: 0 !important;
     193    padding: 0 !important;
     194    margin-top: 10px !important;
     195    display: flex;
     196    gap: 10px;
     197}
     198
     199.hippoo-conversation-media li {
     200    width: 60px;
     201    height: 40px;
     202    list-style-type: none !important;
     203    margin: 0 !important;
     204    padding: 0 !important;
     205}
     206
     207.hippoo-conversation-media li img {
     208    width: 100%;
     209    max-height: 40px;
     210    border-radius: 5px;
     211}
     212
     213.hippoo-ticket-container .hippoo-status {
     214    padding: 2px 10px;
     215    border-radius: 8px;
     216}
     217
     218.hippoo-ticket-container .hippoo-status.status-green {
     219    background-color: #e8fbf6;
     220    color: #1f9376;
     221}
     222
     223.hippoo-ticket-container .hippoo-status.status-red {
     224    background-color: #fbe9e8;
     225    color: #93271f;
     226}
     227
     228.hippoo-ticket-container .hippoo-status.status-blue {
     229    background-color: #e8f0fb;
     230    color: #1f5f93;
     231}
     232
     233@media (max-width: 768px) {
     234    .hippoo-ticket-head {
     235        flex-direction: column;
     236        gap: 10px;
    207237    }
    208     .short-desc .left p{
    209         padding-right: 0;
    210     }
    211 
    212     .short-desc .right div{
    213         display: block;
    214         float: none;
    215         margin: 20px auto
    216     }
    217 
    218     .extentions .item{
    219         width: 100%;
    220         display: block;
    221         float: none
    222     }
    223     .extentions .item .item-inner{
    224         margin: 15px !important;
    225     }
    226 }
     238}
  • hippoo-ticket/trunk/assets/js/script.js

    r3007682 r3265917  
    1 // Generate barcodes and show them in tooltips
    21jQuery(document).ready(function($) {
    3     $('.barcode-button').hover(
    4         function() {
    5             var orderId = $(this).data('order-id');
    6             var barcodeUrl = 'https://barcode.tec-it.com/barcode.ashx?data=' + orderId + '&code=Code128&dpi=96';
    7             $(this).append('<span><img src="' + barcodeUrl + '"/></span>');
     2    let fileCounter = 0;
    83
    9         },
    10         function() {
    11             $(this).find('span').remove();
     4    // File upload handling
     5    $('.hippoo-upload-input').on('change', function(e) {
     6        e.preventDefault();
     7        const files = this.files;
     8        const previewContainer = $(this).parents('.hippoo-file-upload').find('.hippoo-upload-preview');
     9        const form = $(this).closest('form');
     10       
     11        if (files.length > 5 || fileCounter >= 5) {
     12            alert('Maximum 5 files allowed');
     13            this.value = '';
     14            return;
    1215        }
    13     );
     16       
     17        Array.from(files).forEach(file => {
     18            if (file.size > 358400) {
     19                alert('File too large: ' + file.name + ' \nImage size should not exceed 350KB');
     20                return;
     21            }
     22           
     23            if (file.type.match('image.*')) {
     24                const reader = new FileReader();
     25                const fileId = 'file-' + fileCounter++;
     26               
     27                reader.onload = function(e) {
     28                    const previewElement = $(`
     29                        <div class="hippoo-upload-item" data-file-id="${fileId}">
     30                            <img src="${e.target.result}" alt="Preview">
     31                            <span class="hippoo-remove-file"></span>
     32                        </div>
     33                    `);
     34                   
     35                    const fileInput = $(`
     36                        <input type="file" name="file[]" id="${fileId}"
     37                               style="display: none;" data-file-name="${file.name}">
     38                    `);
     39                   
     40                    const dataTransfer = new DataTransfer();
     41                    dataTransfer.items.add(file);
     42                   
     43                    fileInput[0].files = dataTransfer.files;
     44                   
     45                    previewContainer.append(previewElement);
     46                    form.append(fileInput);
     47                };
     48               
     49                reader.readAsDataURL(file);
     50            }
     51        });
     52    });
     53   
     54    // Remove file
     55    $(document).on('click', '.hippoo-remove-file', function(e) {
     56        e.preventDefault();
     57        const item = $(this).parent();
     58        const fileId = item.data('file-id');
     59       
     60        item.remove();
     61        $('#' + fileId).remove();
     62    });
    1463});
  • hippoo-ticket/trunk/hippoo-ticket.php

    r3038770 r3265917  
    22/**
    33 * Plugin Name: Hippoo Ticket
    4  * Version: 1.0.1
     4 * Version: 1.0.7
    55 * Plugin URI: https://Hippoo.app/
    66 * Description: A Free WooCommerce Plugin for Seamless Customer Support and support ticket.
    77 * Author: Hippoo team
     8 * Author URI: https://Hippoo.app/
    89 * Text Domain: hippoo-ticket
    910 * Domain Path: /languages
     
    2728if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly     
    2829
    29 define('hippoo_ticket_path',dirname(__file__).DIRECTORY_SEPARATOR);
    30 define('hippoo_ticket_url',plugins_url('hippoo-ticket').'/assets/');
     30define( 'hippoo_ticket_version', '1.0.7' );
     31define( 'hippoo_ticket_path', plugin_dir_path( __FILE__ ) );
     32define( 'hippoo_ticket_url', plugin_dir_url( __FILE__ ) . 'assets/' );
     33
    3134global $hippoo_ticket_api_page;
    3235$hippoo_ticket_api_page = 10;
    3336
    34 require_once(ABSPATH."wp-admin/includes/image.php");
     37require_once ABSPATH . 'wp-admin/includes/image.php';
    3538
    36 include_once(hippoo_ticket_path.'app'.DIRECTORY_SEPARATOR.'utils.php');
    37 include_once(hippoo_ticket_path.'app'.DIRECTORY_SEPARATOR.'hooks.php');
    38 include_once(hippoo_ticket_path.'app'.DIRECTORY_SEPARATOR.'web_api.php');
    39 include_once(hippoo_ticket_path.'shortcode'.DIRECTORY_SEPARATOR.'ticket.php');
    40 include_once(hippoo_ticket_path.'metabox'.DIRECTORY_SEPARATOR.'ticket_box.php');
     39require_once hippoo_ticket_path . 'app/utils.php';
     40require_once hippoo_ticket_path . 'app/hooks.php';
     41require_once hippoo_ticket_path . 'app/web_api.php';
     42require_once hippoo_ticket_path . 'shortcode/ticket.php';
     43require_once hippoo_ticket_path . 'metabox/ticket_box.php';
    4144
    42 register_activation_hook(__file__,'hippoo_ticket_register_hook');
     45register_activation_hook( __file__, 'hippoo_ticket_register_hook' );
    4346
    44 function hippoo_ticket_register_hook(){
    45    
    46     require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    47    
     47function hippoo_ticket_register_hook() {
     48    require_once ABSPATH . 'wp-admin/includes/upgrade.php';
    4849    global $wpdb;
     50
    4951    $hippoo_ticket_table_name = $wpdb->prefix . 'hippoo_ticket';
    5052    $sql = "CREATE TABLE IF NOT EXISTS {$hippoo_ticket_table_name} (
     
    5961        PRIMARY KEY (id)
    6062        ) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
    61     $wpdb->query($sql);
     63    dbDelta( $sql );
    6264
     65    // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
    6366    $pg_ticket = $wpdb->get_var(
    6467        $wpdb->prepare(
    65             "SELECT ID FROM $wpdb->posts WHERE post_type = %s AND post_content LIKE %s",
     68            "SELECT ID FROM {$wpdb->posts} WHERE post_type = %s AND post_content LIKE %s",
    6669            'page',
    6770            '%[hippoo_ticket]%'
    6871        )
    6972    );
    70     if(empty($pg_ticket)){
     73    // phpcs:enable
     74
     75    if ( empty( $pg_ticket ) ) {
    7176        $args = [
    72         'post_title'  => 'Hippoo Ticket',
    73         'post_type'   => 'page',
    74         'post_content'=> '[hippoo_ticket]',
    75         'post_status' =>'publish',
    76         'post_author' => get_current_user_id(),];
    77         $pg_ticket = wp_insert_post($args);
     77            'post_title'  => 'Hippoo Ticket',
     78            'post_type'   => 'page',
     79            'post_content'=> '[hippoo_ticket]',
     80            'post_status' => 'publish',
     81            'post_author' => get_current_user_id(),
     82        ];
     83        $pg_ticket = wp_insert_post( $args );
    7884    }
     85
    7986    $args = [
    80     'sms'      => 'A message is sent to you.',
    81     'email'    => '<p>Dear User %user%</p>
    82     <p>A message is sent to you.</p>
    83     <p><a url="%url%">%ticket%</a></p>',
    84     'pg_ticket'=> $pg_ticket,
     87        'sms'      => 'A message is sent to you.',
     88        'email'    => '<p>Dear User %user%</p>
     89        <p>A message is sent to you.</p>
     90        <p><a url="%url%">%ticket%</a></p>',
     91        'pg_ticket'=> $pg_ticket,
    8592    ];
    86     update_option('hippoo_ticket',$args);
     93
     94    update_option( 'hippoo_ticket', $args );
    8795}
    8896
    89 function hippoo_ticket_admin_menu(){
     97function hippoo_ticket_admin_menu() {
     98    global $menu, $wpdb;
    9099
    91100    // add_submenu_page('edit.php?post_type=hippoo_ticket','Settings','Settings','administrator','hippoo_ticket_con_ticket','hippoo_ticket_con_ticket');
     
    94103        __( 'Hippoo Ticket', 'hippoo-ticket' ),
    95104        'manage_options',
    96         'hippoo_ticket_con_ticket',
    97         'hippoo_ticket_con_ticket',
    98         ( HIPPOO_POPUP_URL . '/images/icon.svg' )
     105        'hippoo_ticket',
     106        'hippoo_ticket_config_page',
     107        hippoo_ticket_url . 'images/icon.svg'
    99108    );
    100109
    101     global $menu,$wpdb;
     110    // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
    102111    $count = $wpdb->get_var(
    103112        $wpdb->prepare(
    104             "SELECT COUNT(ID) FROM $wpdb->posts WHERE post_type = %s AND post_status = %s",
     113            "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_type = %s AND post_status = %s",
    105114            'hippoo_ticket',
    106115            'hippoo_waiting'
    107116        )
    108117    );
    109     if(!empty($count)){
    110         foreach($menu as $i=>$men){
    111             if($men[2] == 'edit.php?post_type=hippoo_ticket'){
     118    // phpcs:enable
     119
     120    if ( ! empty( $count ) ) {
     121        foreach ( $menu as $i => $men ){
     122            if ( $men[2] == 'edit.php?post_type=hippoo_ticket' ) {
    112123                $menu[$i][0] .= " <span class='update-plugins count-$count'><span class='plugin-count'>$count</span></span>";
    113124            }
     
    115126    }
    116127}
    117 add_action('admin_menu','hippoo_ticket_admin_menu');
    118128
    119 function hippoo_ticket_con_ticket(){
    120     include_once(hippoo_ticket_path.'app'.DIRECTORY_SEPARATOR.'config.php');
     129add_action( 'admin_menu', 'hippoo_ticket_admin_menu' );
     130
     131function hippoo_ticket_config_page() {
     132    require_once hippoo_ticket_path . 'app/config.php';
    121133}
    122 
    123134
    124135function hippoo_ticket_textdomain() {
    125136    load_theme_textdomain( 'hippoo', get_template_directory() . '/languages' );
    126137}
     138
    127139add_action( 'after_setup_theme', 'hippoo_ticket_textdomain' );
    128140
    129 function hippoo_ticket_page_style( $hook ) {
    130     if ( in_array( $hook, array( 'hippoo_ticket_page_hippoo_ticket_con_ticket' ) ) ) {
    131         wp_enqueue_style( 'hippoo_ticket_page_style',
    132             hippoo_ticket_url . "css/style.css", null, 1.0);
     141function hippoo_ticket_admin_style( $hook ) {
     142    if ( strpos( $hook, 'hippoo_ticket' ) !== false ) {
     143        wp_enqueue_style( 'hippoo-ticket-style', hippoo_ticket_url . "css/admin-style.css", [], hippoo_ticket_version );
     144    }
     145
     146    if ( get_post_type() == 'hippoo_ticket' ) {
     147        wp_enqueue_script( 'hippoo-ticket-script', hippoo_ticket_url . "js/admin-script.js", [ 'jquery' ], hippoo_ticket_version, true );
    133148    }
    134149}
    135150
    136 add_action( 'admin_enqueue_scripts', 'hippoo_ticket_page_style' );
     151add_action( 'admin_enqueue_scripts', 'hippoo_ticket_admin_style' );
     152
     153function hippoo_ticket_public_style() {
     154    wp_enqueue_style( 'hippoo-ticket-style', hippoo_ticket_url . "css/style.css", [], hippoo_ticket_version );
     155    wp_enqueue_script( 'hippoo-ticket-script', hippoo_ticket_url . "js/script.js", [ 'jquery' ], hippoo_ticket_version, true );
     156}
     157
     158add_action( 'wp_enqueue_scripts', 'hippoo_ticket_public_style' );
    137159
    138160/**
     
    145167
    146168add_action( 'add_meta_boxes', 'hippoo_ticket_register_meta_boxes');
    147 ?>
  • hippoo-ticket/trunk/metabox/ticket_box.php

    r3007682 r3265917  
    11<?php
    22if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly     
    3 
    43
    54function hippoo_ticket_display_callback( $post ) {
    65    # Generate the table
    76    $ticket_id = $post->ID;
    8     $rows = hippoo_ticket_generate_tickets_table_body_html($ticket_id);
    9     include(plugin_dir_path(__FILE__) . DIRECTORY_SEPARATOR . 'ticket_box_html_template.php');
     7    $rows      = hippoo_ticket_generate_tickets_table_body_html( $ticket_id );
     8    require_once hippoo_ticket_path . 'metabox/ticket_box_html_template.php';
    109}
    1110
    1211add_action( 'save_post_hippoo_ticket', 'hippoo_ticket_save_meta_box' );
     12
    1313function hippoo_ticket_save_meta_box( $post_id ) {
    14    
    15     // Verify nonce for security
    16     if (!( isset( $_POST['hippoo_ticket_meta_box_nonce'] ) && wp_verify_nonce( $_POST['hippoo_ticket_meta_box_nonce'], 'hippoo_ticket_meta_box_nonce_action' ) )) {
     14    if ( ! ( isset( $_POST['hippoo_ticket_meta_box_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['hippoo_ticket_meta_box_nonce'] ), 'hippoo_ticket_meta_box_nonce_action' ) ) ) {
    1715        return;
    1816    }
    1917
    20     // Check it's not an auto save routine
    21     if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return;
    22     if (!is_admin()) return;
     18    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
    2319
    24     if (!empty($_POST['scontent'])) {
     20    if ( ! is_admin() ) return;
     21
     22    if ( ! empty( $_POST['scontent'] ) ) {
    2523        global $wpdb;
     24
     25        // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
    2626        $pid = $wpdb->get_var(
    27             $wpdb->prepare("SELECT post_parent FROM $wpdb->posts WHERE ID = %d", $post_id)
     27            $wpdb->prepare( "SELECT post_parent FROM {$wpdb->posts} WHERE ID = %d", $post_id )
    2828        );
     29        // phpcs:enable
    2930
    30         if ($pid) {
    31             remove_action('save_post_hippoo_ticket', 'hippoo_ticket_save_meta_box');
    32             $scontent = isset( $_POST['scontent'] ) ? sanitize_text_field( $_POST['scontent'] ) : '';
     31        if ( $pid ) {
     32            remove_action( 'save_post_hippoo_ticket', 'hippoo_ticket_save_meta_box' );
     33            $scontent = isset( $_POST['scontent'] ) ? sanitize_text_field( wp_unslash( $_POST['scontent'] ) ) : '';
    3334            hippoo_add_ticket( $pid, $scontent, [], 2 );
    3435            add_action( 'save_post_hippoo_ticket', 'hippoo_ticket_save_meta_box' );
    35             hippoo_ticket_sms($post_id);
    36             hippoo_ticket_email($post_id);
     36            hippoo_ticket_sms( $post_id );
     37            hippoo_ticket_email( $post_id );
    3738        }
    3839    }
    3940}
    40 
    41 ?>
  • hippoo-ticket/trunk/metabox/ticket_box_html_template.php

    r3038770 r3265917  
    11<?php
    22    if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
    3    
    43?>
    54<style type="text/css">
     
    1918    <tr>
    2019        <td>
    21             <?php wp_editor('','scontent',['textarea_rows'=>5]); ?>
     20            <?php wp_editor( '', 'scontent', [ 'textarea_rows' => 5 ] ); ?>
    2221        </td>
    2322    </tr>
     
    2625    wp_nonce_field( 'hippoo_ticket_meta_box_nonce_action', 'hippoo_ticket_meta_box_nonce' ); ?>
    2726    <tbody>
    28         <?php if (empty($rows)) : ?>
     27        <?php if ( empty( $rows ) ) : ?>
    2928            <tr>
    3029                <td colspan="1">
     
    3231                </td>
    3332            </tr>
    34             <?php else : foreach ($rows as $row) : ?>
     33            <?php else : foreach ( $rows as $row ) : ?>
    3534                <tr>
    3635                    <td>
    3736                        <p>
    3837                            <strong>
    39                                 <?php echo wp_kses_post($row->type); ?> :
     38                                <?php echo wp_kses_post( $row->type ); ?> :
    4039                            </strong>
    4140                            <br/>
    42                             <?php echo wp_kses_post($row->content); ?>
     41                            <?php echo wp_kses_post( $row->content ); ?>
    4342                        </p>
    44                         <ul><?php echo wp_kses_post($row->media_urls_html); ?></ul>
     43                        <ul><?php echo wp_kses_post( $row->media_urls_html ); ?></ul>
    4544                        <br/>
    4645                        <p>
    4746                            <strong>Date : </strong>
    4847                            <bdi>
    49                                 <?php echo esc_html($row->date); ?>
     48                                <?php echo esc_html( $row->date ); ?>
    5049                            </bdi>
    5150                        </p>
  • hippoo-ticket/trunk/readme.txt

    r3038770 r3265917  
    1 === Hippoo-Ticket ===
     1=== Hippoo Ticket ===
    22Contributors: Hippooo
    33Donate link: https://Hippoo.app/
    4 Tags: Hippoo ticket, ticket, support ticket, Hippoo,customer support
     4Tags: Hippoo ticket, ticket, support ticket, Hippoo, customer support
    55Requires at least: 5.3
    6 Tested up to: 6.4
    7 Stable tag: 1.0.1
    8 License: GPLv2 or later
    9 License URI: https://www.gnu.org/licenses/gpl-2.0.html
     6Tested up to: 6.7
     7Stable tag: 1.0.7
     8License: GPL3
     9License URI: https://www.gnu.org/licenses/gpl-3.0.html
    1010
    1111== Description ==
     
    9191
    9292== Changelog ==
    93 
    94 = 1.0 =
    95 * Hippos-ticket launch
     93* 1.0.7 - Minor Improvements.
     94* 1.0.1 Hippoo app auth
     95* 1.0 Hippos-ticket launch
  • hippoo-ticket/trunk/shortcode/ticket.php

    r3038770 r3265917  
    22if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly     
    33
    4 add_action('init', 'hippoo_ticket_output_buffer');
    5 add_shortcode('hippoo_ticket','hippoo_short_ticket');
     4add_action( 'init', 'hippoo_ticket_output_buffer' );
     5add_shortcode( 'hippoo_ticket', 'hippoo_short_ticket' );
    66
    77function hippoo_ticket_output_buffer() {
     
    99}
    1010
    11 function hippoo_short_ticket($atts=[]){
     11function hippoo_short_ticket( $atts = [] ){
     12    if ( defined( 'REST_REQUEST' ) )
     13        return;
    1214
    13     if(defined('REST_REQUEST'))
    14         return;
    15        
    16     if( !is_admin() && (!is_user_logged_in() or empty($_GET['oid']) or !is_numeric($_GET['oid'])) ){
    17         wp_redirect(home_url());
     15    if ( ! is_admin() && ( ! is_user_logged_in() or empty( $_GET['oid'] ) or ! is_numeric( $_GET['oid'] ) ) ) {
     16        wp_redirect( home_url() );
    1817        exit();
    1918    }
    2019
     20    global $wpdb;
    2121   
    2222    ob_start();
    23    
    24     global $wpdb;
    25     $order_id = absint($_GET['oid']); // Sanitize input
     23
     24    $order_id = absint( $_GET['oid'] );
     25    $uid      = get_current_user_id();
     26    $cid      = get_post_meta( $order_id, '_customer_user', true );
    2627    $msg      = '';
    27     $order    = $wpdb->get_row(
    28                     $wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d", $order_id)
    29                 );
    30     $uid      = get_current_user_id();
    31     $cid      = get_post_meta($order_id, '_customer_user', true);
    32    
    3328
    34     $ticket_id = $wpdb->get_var(
    35                     $wpdb->prepare("SELECT ID FROM $wpdb->posts
    36                                     WHERE post_type='hippoo_ticket' AND post_parent= %d", $order->ID)
    37                     );
    38    
    39    if(get_post_status($ticket_id) == 'trash'){
    40         wp_redirect(wc_get_page_permalink( 'myaccount' ) . '/orders');
    41         exit();
    42     }
    43    
    44 
    45     if (isset($_POST['save']) && isset($_POST['csrf_token'])) {
    46         if (wp_verify_nonce($_POST['csrf_token'], 'csrf_token_save')) {
     29    if ( isset( $_POST['save'] ) && isset( $_POST['csrf_token'] ) ) {
     30        if ( wp_verify_nonce( sanitize_key( $_POST['csrf_token'] ), 'csrf_token_save' ) ) {
    4731
    4832            // Check if file upload was successful
    49             if (
    50                 isset($_FILES['file']) &&
    51                 is_array($_FILES['file'])
    52             ) {
     33            if ( isset( $_FILES['file'] ) && is_array( $_FILES['file'] ) ) {
    5334                $media_ids = hippoo_ticket_media_upload();
    5435            } else {
     
    5637            }
    5738
    58             // Sanitize and validate content
    59             $tcontent = isset($_POST['tcontent']) ? sanitize_text_field($_POST['tcontent']) : '';
     39            $tcontent = isset( $_POST['tcontent'] ) ? sanitize_text_field( wp_unslash( $_POST['tcontent'] ) ) : '';
    6040
    61             if (!empty($tcontent)) {
    62                 hippoo_add_ticket($order_id, $tcontent, $media_ids, 1);
    63                 $msg = 'Ticket submitted.';
     41            if ( ! empty( $tcontent ) ) {
     42                hippoo_add_ticket( $order_id, $tcontent, $media_ids, 1 );
     43                wc_add_notice( 'Ticket submitted.', 'success' );
    6444            } else {
    65                 $msg = 'Error: Invalid ticket content.';
     45                wc_add_notice( 'Error: Invalid ticket content.', 'error' );
    6646            }
    6747        }
    6848    }
    6949
     50    // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
     51    $order = $wpdb->get_row(
     52                    $wpdb->prepare( "SELECT * FROM {$wpdb->posts} WHERE ID = %d", $order_id )
     53                );
     54    // phpcs:enable
    7055
     56    // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
     57    $ticket_id = $wpdb->get_var(
     58                    $wpdb->prepare( "SELECT ID FROM {$wpdb->posts}
     59                                    WHERE post_type='hippoo_ticket' AND post_parent= %d", $order_id )
     60                    );
     61    // phpcs:enable
     62
     63    if( get_post_status( $ticket_id ) == 'trash' ) {
     64        wp_redirect( wc_get_page_permalink( 'myaccount' ) . '/orders' );
     65        exit();
     66    }
    7167   
    7268    # Generate the table
    73     $rows = hippoo_ticket_generate_tickets_table_body_html($ticket_id);
    74     $ticket_name = sanitize_text_field( str_replace( "Private:", "", get_the_title( absint( $_GET['oid'] ) ) ) );
    75     $ticket_number = empty($ticket_id) ? '' : $ticket_id;
    76     $ticket_status = empty($ticket_id) ? 'New Ticket' : wp_kses_post(hippoo_ticket_status($ticket_id));
    77     include(plugin_dir_path(__FILE__) . DIRECTORY_SEPARATOR . 'ticket_html_template.php');
     69    $conversations = hippoo_ticket_generate_tickets_table_body_html( $ticket_id );
     70    $ticket_name   = sanitize_text_field( str_replace( "Private:", "", get_the_title( absint( $_GET['oid'] ) ) ) );
     71    $ticket_number = empty( $ticket_id ) ? '' : $ticket_id;
     72    $ticket_status = empty( $ticket_id ) ? 'New Ticket' : wp_kses_post( hippoo_ticket_status( $ticket_id ) );
     73   
     74    require_once wc_locate_template( 'form-ticket.php', 'hippoo-ticket', hippoo_ticket_path . 'shortcode/' );
    7875
    7976    return ob_get_clean();
    8077}
    81 ?>
Note: See TracChangeset for help on using the changeset viewer.