Changeset 3265917
- Timestamp:
- 04/02/2025 09:49:44 PM (10 months ago)
- Location:
- hippoo-ticket/trunk
- Files:
-
- 6 added
- 12 edited
-
app/config.php (modified) (8 diffs)
-
app/hooks.php (modified) (11 diffs)
-
app/utils.php (modified) (1 diff)
-
app/web_api.php (modified) (1 diff)
-
app/web_api_auth.php (modified) (6 diffs)
-
assets/css/admin-style.css (added)
-
assets/css/style.css (modified) (1 diff)
-
assets/images/attach.svg (added)
-
assets/images/chat.svg (added)
-
assets/images/close.svg (added)
-
assets/js/admin-script.js (added)
-
assets/js/script.js (modified) (1 diff)
-
hippoo-ticket.php (modified) (6 diffs)
-
metabox/ticket_box.php (modified) (1 diff)
-
metabox/ticket_box_html_template.php (modified) (4 diffs)
-
readme.txt (modified) (2 diffs)
-
shortcode/form-ticket.php (added)
-
shortcode/ticket.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
hippoo-ticket/trunk/app/config.php
r3007682 r3265917 1 <?php 1 <?php // phpcs:disable PluginCheck.CodeAnalysis.ImageFunctions.NonEnqueuedImage 2 2 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly 3 3 ?> 4 4 <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> 6 6 7 7 <div class="settings"> … … 9 9 if ( isset( $_POST['save'] ) ) { 10 10 // 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' ) ) { 12 12 // Check user permissions here (if needed) 13 13 if ( current_user_can( 'manage_options' ) ) { 14 14 $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'] ) ) : '', 18 18 ]; 19 19 20 20 // Update options only if the user has the required permissions 21 21 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>'); 23 23 } else { 24 24 // 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>'); 26 26 } 27 27 } else { 28 28 // 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>'); 30 30 } 31 31 } 32 33 34 32 35 33 $opt = get_option( 'hippoo_ticket', [] ); … … 40 38 <thead> 41 39 <tr> 42 <th colspan="2"><?php esc_html_e( 'Settings', 'hippoo ' ); ?></th>40 <th colspan="2"><?php esc_html_e( 'Settings', 'hippoo-ticket' ); ?></th> 43 41 </tr> 44 42 </thead> … … 52 50 <?php wp_editor( ( isset( $opt['email'] ) ? $opt['email'] : '' ), 'email', [ 'media_buttons' => false, 'textarea_rows' => 5 ] ); ?> 53 51 <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> 55 55 </p> 56 56 </td> 57 57 </tr> 58 58 <tr> 59 <th colspan="2"><?php esc_html_e( 'Pages', 'hippoo ' ); ?></th>59 <th colspan="2"><?php esc_html_e( 'Pages', 'hippoo-ticket' ); ?></th> 60 60 </tr> 61 61 <tr> 62 62 <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> 64 64 </tr> 65 65 <tfoot> … … 74 74 <thead> 75 75 <tr> 76 <th><?php esc_html_e( 'Shortcode List', 'hippoo ' ); ?></th>76 <th><?php esc_html_e( 'Shortcode List', 'hippoo-ticket' ); ?></th> 77 77 </tr> 78 78 </thead> … … 83 83 </div> 84 84 85 86 85 <div class="short-desc"> 87 86 <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> 89 88 <a href="https://hippoo.app"> 90 89 <img class="hippoo-download" src="<?php echo wp_kses_post( hippoo_ticket_url . 'images/play-store.png' ); ?>" alt="Play Store"> … … 94 93 95 94 <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> 98 97 99 98 <?php … … 133 132 '; 134 133 135 // echo wp_kses_post( $html ); 136 echo ( $html ); 134 echo wp_kses_post( $html ); 137 135 } 138 136 } -
hippoo-ticket/trunk/app/hooks.php
r3007682 r3265917 6 6 * 7 7 */ 8 8 9 function hippoo_ticket_wc_add_my_account_orders_column( $columns ) { 9 10 10 $columns['ticket'] = 'Support'; 11 11 $columns['ticket_status'] = 'Status'; 12 13 12 return $columns; 14 13 } 14 15 15 add_filter( 'woocommerce_account_orders_columns', 'hippoo_ticket_wc_add_my_account_orders_column' ); 16 17 16 18 17 function hippoo_ticket_wc_custom_column_display( $order ) { 19 18 global $wpdb; 20 19 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( '-' ); 23 22 return; 24 23 } 25 24 26 $opt = get_option( 'hippoo_ticket', []);25 $opt = get_option( 'hippoo_ticket', [] ); 27 26 $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 28 29 $tid = absint( $wpdb->get_var( $wpdb->prepare( 29 "SELECT ID FROM $wpdb->postsWHERE 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", 30 31 absint( $order->get_id() ) 31 32 ) ) ); 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 36 38 add_action( 'woocommerce_my_account_my_orders_column_ticket', 'hippoo_ticket_wc_custom_column_display' ); 37 39 … … 39 41 global $wpdb; 40 42 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( '-' ); 43 45 return; 44 46 } 45 47 48 // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 46 49 $tid = absint( $wpdb->get_var( $wpdb->prepare( 47 "SELECT ID FROM $wpdb->postsWHERE 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", 48 51 absint( $order->get_id() ) 49 52 ) ) ); 53 // phpcs:enable 50 54 51 55 echo wp_kses_post( hippoo_ticket_status( $tid ) ); 52 56 } 57 53 58 add_action( 'woocommerce_my_account_my_orders_column_ticket_status', 'hippoo_ticket_wc_custom_column_display_status' ); 54 59 … … 56 61 * add column to ticket post type 57 62 * 58 **/ 59 60 add_filter('manage_hippoo_ticket_posts_columns','hippoo_ticket_columns'); 63 */ 64 61 65 function hippoo_ticket_columns( $columns ) { 62 66 // this will add the column to the end of the array … … 67 71 } 68 72 69 add_ action( 'manage_hippoo_ticket_posts_custom_column','hippoo_ticket_action_custom_columns_content', 10, 2);73 add_filter( 'manage_hippoo_ticket_posts_columns', 'hippoo_ticket_columns' ); 70 74 71 75 function hippoo_ticket_action_custom_columns_content( $column_id, $post_id ) { … … 73 77 $pid = absint( get_post_field( 'post_parent', $post_id ) ); 74 78 $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>" ); 76 80 } 77 81 78 if ( $column_id == 'ticket_id' ) 82 if ( $column_id == 'ticket_id' ) { 79 83 echo wp_kses_post( $post_id ); 80 81 if ( $column_id == 'ticket_status' ) 84 } 85 86 if ( $column_id == 'ticket_status' ) { 82 87 echo wp_kses_post( hippoo_ticket_status( $post_id ) ); 83 } 84 88 } 89 } 90 91 add_action( 'manage_hippoo_ticket_posts_custom_column','hippoo_ticket_action_custom_columns_content', 10, 2 ); 85 92 86 93 /** 87 94 * init 88 */ 89 add_action( 'init', 'hippoo_ticket_hook_init' ); 95 * 96 */ 97 90 98 function hippoo_ticket_hook_init() { 91 99 $labels = array( … … 126 134 'show_in_admin_all_list' => true, 127 135 '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' ), 129 138 ) ); 139 130 140 register_post_status( 'hippoo_answered', array( 131 141 'label' => 'Answered', … … 134 144 'show_in_admin_all_list' => true, 135 145 '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' ), 137 148 ) ); 149 138 150 register_post_status( 'hippoo_close', array( 139 151 'label' => 'Closed', … … 142 154 'show_in_admin_all_list' => true, 143 155 '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' ), 145 158 ) ); 146 159 } 147 160 148 149 add_action('admin_footer-post.php', 'hippoo_ticket_append_post_status_list'); 150 151 function hippoo_ticket_append_post_status_list(){ 161 add_action( 'init', 'hippoo_ticket_hook_init' ); 162 163 function hippoo_ticket_append_post_status_list() { 152 164 global $post; 153 165 154 if ($post->post_type == 'hippoo_ticket'){166 if ( $post->post_type == 'hippoo_ticket' ) { 155 167 $statuses = [ 156 'hippoo_waiting' => 'Waiting for reply',168 'hippoo_waiting' => 'Waiting for reply', 157 169 'hippoo_answered' => 'Answered', 158 'hippoo_close' => 'Closed'170 'hippoo_close' => 'Closed' 159 171 ]; 160 172 … … 162 174 $label = ''; 163 175 164 foreach ($statuses as $state => $text){176 foreach ( $statuses as $state => $text ) { 165 177 $selected = selected( $post->post_status, $state, false ); 166 178 $status_options .= "<option value='" . esc_attr($state) . "' $selected>" . esc_html($text) . "</option>"; 167 179 168 if ($post->post_status == $state){180 if ( $post->post_status == $state ) { 169 181 $label = $text; 170 182 } … … 175 187 var statusSelect = document.querySelector("select#post_status"); 176 188 if (statusSelect) { 177 statusSelect.innerHTML = "<?php echo esc_html( $status_options); ?>";189 statusSelect.innerHTML = "<?php echo esc_html( $status_options ); ?>"; 178 190 } 179 191 180 192 var statusDisplay = document.querySelector("#post-status-display"); 181 193 if (statusDisplay) { 182 statusDisplay.innerHTML += "<?php echo esc_html( $label); ?>";194 statusDisplay.innerHTML += "<?php echo esc_html( $label ); ?>"; 183 195 } 184 196 … … 193 205 } 194 206 207 add_action( 'admin_footer-post.php', 'hippoo_ticket_append_post_status_list' ); 195 208 196 209 /** 197 210 * 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 214 function 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 222 add_filter( 'post_row_actions', 'hippoo_ticket_remove_quick_edit', 10, 2 ); 223 224 225 function hippoo_ticket_custom_bulk_actions( $actions ) { 226 $actions['status_close'] = 'Close Ticket'; 227 return $actions; 228 } 229 230 add_filter( 'bulk_actions-edit-hippoo_ticket', 'hippoo_ticket_custom_bulk_actions' ); 231 232 function 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 ] ); 202 239 } 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 245 add_filter( 'handle_bulk_actions-edit-hippoo_ticket', 'hippoo_ticket_handle_bulk_actions', 10, 3 ); 246 247 function 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 257 add_action( 'after_delete_post', 'hippoo_ticket_delete_ticket_hook', 10, 2 ); 258 259 function 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'; 249 265 } 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; 266 270 } 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 276 add_filter( 'the_author', 'hippoo_ticket_change_the_author', 10, 1 ); -
hippoo-ticket/trunk/app/utils.php
r3007682 r3265917 1 1 <?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 3 function 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 100 function 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 120 function hippoo_ticket_sms( $ticket_id ){ 121 $opt = get_option( 'hippoo_ticket',[] ); 122 } 123 124 function 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 145 function 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 158 function 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 171 function 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 184 function 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 200 function 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 221 function 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' 14 260 ); 15 261 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 ); 236 267 $attachment_ids[] = $attachment_id; 237 268 } 238 269 } 239 270 } 240 $attachment_ids = implode( ',', $attachment_ids);271 $attachment_ids = implode( ',', $attachment_ids ); 241 272 return $attachment_ids; 242 } 243 244 ?> 273 } -
hippoo-ticket/trunk/app/web_api.php
r3007682 r3265917 2 2 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly 3 3 4 add_action( 'rest_api_init', function () {5 require_once __DIR__ . DIRECTORY_SEPARATOR .'web_api_auth.php';4 add_action( 'rest_api_init', function () { 5 require_once hippoo_ticket_path . 'app/web_api_auth.php'; 6 6 $controller = new HippooTicketControllerWithAuth(); 7 7 $controller->register_routes(); 8 }); 9 ?> 8 } ); -
hippoo-ticket/trunk/app/web_api_auth.php
r3038770 r3265917 3 3 class HippooTicketControllerWithAuth extends WC_REST_Customers_Controller { 4 4 5 public function register_routes() 6 { 5 public function register_routes() { 7 6 # 8 7 $args_hippoo_ticket_insert = array( … … 17 16 $args_hippoo_ticket_list = array( 18 17 'methods' => 'GET', 19 'callback' => array( $this, 'hippoo_ticket_list' ),18 'callback' => array( $this, 'hippoo_ticket_list' ), 20 19 'permission_callback' => array( $this, 'hippo_edit_other_post_permissions_check' ), 21 20 'args' => array( … … 31 30 $args_hippoo_ticket_get_ticket_info_by_ticket_id = array( 32 31 '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' ), 34 33 'permission_callback' => array( $this, 'hippo_edit_other_post_permissions_check' ), 35 34 'args' => array( 36 35 'id' => array( 37 36 '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 ); 40 39 } 41 40 ), … … 46 45 ); 47 46 register_rest_route( 'wc-hippoo/v1', 'wp/tickets/(?P<id>\d+)', $args_hippoo_ticket_get_ticket_info_by_ticket_id ); 48 49 47 50 48 # 51 49 $args_hippoo_ticket_get_ticket_info_by_order = array( 52 50 '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' ), 54 52 'permission_callback' => array( $this, 'hippo_edit_other_post_permissions_check' ) 55 53 … … 60 58 $args_hippoo_ticket_delete = array( 61 59 '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 ); 67 65 68 66 # 69 67 $args_hippoo_ticket_update_status = array( 70 68 '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 ); 77 74 78 75 # 79 76 $args_hippoo_ticket_count = array( 80 77 '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() { 89 86 return current_user_can( 'edit_posts' ); 90 87 } 91 88 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 ) ) { 97 92 $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 ); 104 98 $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 ) { 111 105 $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 ] ); 114 108 $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'] ); 140 131 } else { 141 132 $page = "1"; 142 133 } 134 143 135 $page = --$page * $hippoo_ticket_api_page; 144 136 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 163 158 $out = []; 164 foreach($rows as $ticket){ 165 159 foreach ( $rows as $ticket ) { 166 160 $out[] = [ 167 161 'ticket_id'=> $ticket->ID, 168 162 '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 ), 172 166 'date' => $ticket->post_date, 173 167 'latest_reply' => $ticket->latest, … … 175 169 ]; 176 170 } 171 177 172 return new WP_REST_Response( $out, 200 ); 178 173 } 179 174 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', 198 189 ); 199 return new WP_REST_Response( $response, 200);190 return new WP_REST_Response( $response, 200 ); 200 191 } 201 192 $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'] ); 216 206 } else { 217 207 $page = "1"; 218 208 } 209 219 210 $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 ); 234 230 $replies[$i]->media_urls = $media_urls; 235 231 } 236 232 } 233 237 234 $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' => $replies235 '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 245 242 ]; 243 246 244 return new WP_REST_Response( $out, 200 ); 247 245 } 248 246 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 251 251 $cnt = $wpdb->get_var( 252 252 $wpdb->prepare( 253 "SELECT COUNT(ID) FROM $wpdb->postsWHERE post_type = %s AND post_status = %s",253 "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_type = %s AND post_status = %s", 254 254 'hippoo_ticket', 255 255 'hippoo_waiting' 256 256 ) 257 257 ); 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; 5 37 margin: 0; 6 38 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; 15 66 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; 20 116 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;38 117 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; 166 174 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; 207 237 } 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 tooltips2 1 jQuery(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; 8 3 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; 12 15 } 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 }); 14 63 }); -
hippoo-ticket/trunk/hippoo-ticket.php
r3038770 r3265917 2 2 /** 3 3 * Plugin Name: Hippoo Ticket 4 * Version: 1.0. 14 * Version: 1.0.7 5 5 * Plugin URI: https://Hippoo.app/ 6 6 * Description: A Free WooCommerce Plugin for Seamless Customer Support and support ticket. 7 7 * Author: Hippoo team 8 * Author URI: https://Hippoo.app/ 8 9 * Text Domain: hippoo-ticket 9 10 * Domain Path: /languages … … 27 28 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly 28 29 29 define('hippoo_ticket_path',dirname(__file__).DIRECTORY_SEPARATOR); 30 define('hippoo_ticket_url',plugins_url('hippoo-ticket').'/assets/'); 30 define( 'hippoo_ticket_version', '1.0.7' ); 31 define( 'hippoo_ticket_path', plugin_dir_path( __FILE__ ) ); 32 define( 'hippoo_ticket_url', plugin_dir_url( __FILE__ ) . 'assets/' ); 33 31 34 global $hippoo_ticket_api_page; 32 35 $hippoo_ticket_api_page = 10; 33 36 34 require_once (ABSPATH."wp-admin/includes/image.php");37 require_once ABSPATH . 'wp-admin/includes/image.php'; 35 38 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');39 require_once hippoo_ticket_path . 'app/utils.php'; 40 require_once hippoo_ticket_path . 'app/hooks.php'; 41 require_once hippoo_ticket_path . 'app/web_api.php'; 42 require_once hippoo_ticket_path . 'shortcode/ticket.php'; 43 require_once hippoo_ticket_path . 'metabox/ticket_box.php'; 41 44 42 register_activation_hook( __file__,'hippoo_ticket_register_hook');45 register_activation_hook( __file__, 'hippoo_ticket_register_hook' ); 43 46 44 function hippoo_ticket_register_hook(){ 45 46 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); 47 47 function hippoo_ticket_register_hook() { 48 require_once ABSPATH . 'wp-admin/includes/upgrade.php'; 48 49 global $wpdb; 50 49 51 $hippoo_ticket_table_name = $wpdb->prefix . 'hippoo_ticket'; 50 52 $sql = "CREATE TABLE IF NOT EXISTS {$hippoo_ticket_table_name} ( … … 59 61 PRIMARY KEY (id) 60 62 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"; 61 $wpdb->query($sql);63 dbDelta( $sql ); 62 64 65 // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 63 66 $pg_ticket = $wpdb->get_var( 64 67 $wpdb->prepare( 65 "SELECT ID FROM $wpdb->postsWHERE post_type = %s AND post_content LIKE %s",68 "SELECT ID FROM {$wpdb->posts} WHERE post_type = %s AND post_content LIKE %s", 66 69 'page', 67 70 '%[hippoo_ticket]%' 68 71 ) 69 72 ); 70 if(empty($pg_ticket)){ 73 // phpcs:enable 74 75 if ( empty( $pg_ticket ) ) { 71 76 $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 ); 78 84 } 85 79 86 $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, 85 92 ]; 86 update_option('hippoo_ticket',$args); 93 94 update_option( 'hippoo_ticket', $args ); 87 95 } 88 96 89 function hippoo_ticket_admin_menu(){ 97 function hippoo_ticket_admin_menu() { 98 global $menu, $wpdb; 90 99 91 100 // add_submenu_page('edit.php?post_type=hippoo_ticket','Settings','Settings','administrator','hippoo_ticket_con_ticket','hippoo_ticket_con_ticket'); … … 94 103 __( 'Hippoo Ticket', 'hippoo-ticket' ), 95 104 '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' 99 108 ); 100 109 101 global $menu,$wpdb;110 // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 102 111 $count = $wpdb->get_var( 103 112 $wpdb->prepare( 104 "SELECT COUNT(ID) FROM $wpdb->postsWHERE post_type = %s AND post_status = %s",113 "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_type = %s AND post_status = %s", 105 114 'hippoo_ticket', 106 115 'hippoo_waiting' 107 116 ) 108 117 ); 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' ) { 112 123 $menu[$i][0] .= " <span class='update-plugins count-$count'><span class='plugin-count'>$count</span></span>"; 113 124 } … … 115 126 } 116 127 } 117 add_action('admin_menu','hippoo_ticket_admin_menu');118 128 119 function hippoo_ticket_con_ticket(){ 120 include_once(hippoo_ticket_path.'app'.DIRECTORY_SEPARATOR.'config.php'); 129 add_action( 'admin_menu', 'hippoo_ticket_admin_menu' ); 130 131 function hippoo_ticket_config_page() { 132 require_once hippoo_ticket_path . 'app/config.php'; 121 133 } 122 123 134 124 135 function hippoo_ticket_textdomain() { 125 136 load_theme_textdomain( 'hippoo', get_template_directory() . '/languages' ); 126 137 } 138 127 139 add_action( 'after_setup_theme', 'hippoo_ticket_textdomain' ); 128 140 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); 141 function 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 ); 133 148 } 134 149 } 135 150 136 add_action( 'admin_enqueue_scripts', 'hippoo_ticket_page_style' ); 151 add_action( 'admin_enqueue_scripts', 'hippoo_ticket_admin_style' ); 152 153 function 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 158 add_action( 'wp_enqueue_scripts', 'hippoo_ticket_public_style' ); 137 159 138 160 /** … … 145 167 146 168 add_action( 'add_meta_boxes', 'hippoo_ticket_register_meta_boxes'); 147 ?> -
hippoo-ticket/trunk/metabox/ticket_box.php
r3007682 r3265917 1 1 <?php 2 2 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly 3 4 3 5 4 function hippoo_ticket_display_callback( $post ) { 6 5 # Generate the table 7 6 $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'; 10 9 } 11 10 12 11 add_action( 'save_post_hippoo_ticket', 'hippoo_ticket_save_meta_box' ); 12 13 13 function 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' ) ) ) { 17 15 return; 18 16 } 19 17 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; 23 19 24 if (!empty($_POST['scontent'])) { 20 if ( ! is_admin() ) return; 21 22 if ( ! empty( $_POST['scontent'] ) ) { 25 23 global $wpdb; 24 25 // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 26 26 $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 ) 28 28 ); 29 // phpcs:enable 29 30 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'] ) ) : ''; 33 34 hippoo_add_ticket( $pid, $scontent, [], 2 ); 34 35 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 ); 37 38 } 38 39 } 39 40 } 40 41 ?> -
hippoo-ticket/trunk/metabox/ticket_box_html_template.php
r3038770 r3265917 1 1 <?php 2 2 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly 3 4 3 ?> 5 4 <style type="text/css"> … … 19 18 <tr> 20 19 <td> 21 <?php wp_editor( '','scontent',['textarea_rows'=>5]); ?>20 <?php wp_editor( '', 'scontent', [ 'textarea_rows' => 5 ] ); ?> 22 21 </td> 23 22 </tr> … … 26 25 wp_nonce_field( 'hippoo_ticket_meta_box_nonce_action', 'hippoo_ticket_meta_box_nonce' ); ?> 27 26 <tbody> 28 <?php if ( empty($rows)) : ?>27 <?php if ( empty( $rows ) ) : ?> 29 28 <tr> 30 29 <td colspan="1"> … … 32 31 </td> 33 32 </tr> 34 <?php else : foreach ( $rows as $row) : ?>33 <?php else : foreach ( $rows as $row ) : ?> 35 34 <tr> 36 35 <td> 37 36 <p> 38 37 <strong> 39 <?php echo wp_kses_post( $row->type); ?> :38 <?php echo wp_kses_post( $row->type ); ?> : 40 39 </strong> 41 40 <br/> 42 <?php echo wp_kses_post( $row->content); ?>41 <?php echo wp_kses_post( $row->content ); ?> 43 42 </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> 45 44 <br/> 46 45 <p> 47 46 <strong>Date : </strong> 48 47 <bdi> 49 <?php echo esc_html( $row->date); ?>48 <?php echo esc_html( $row->date ); ?> 50 49 </bdi> 51 50 </p> -
hippoo-ticket/trunk/readme.txt
r3038770 r3265917 1 === Hippoo -Ticket ===1 === Hippoo Ticket === 2 2 Contributors: Hippooo 3 3 Donate link: https://Hippoo.app/ 4 Tags: Hippoo ticket, ticket, support ticket, Hippoo, customer support4 Tags: Hippoo ticket, ticket, support ticket, Hippoo, customer support 5 5 Requires at least: 5.3 6 Tested up to: 6. 47 Stable tag: 1.0. 18 License: GPL v2 or later9 License URI: https://www.gnu.org/licenses/gpl- 2.0.html6 Tested up to: 6.7 7 Stable tag: 1.0.7 8 License: GPL3 9 License URI: https://www.gnu.org/licenses/gpl-3.0.html 10 10 11 11 == Description == … … 91 91 92 92 == Changelog == 93 94 = 1.0 = 95 * Hippos-ticket launch93 * 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 2 2 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly 3 3 4 add_action( 'init', 'hippoo_ticket_output_buffer');5 add_shortcode( 'hippoo_ticket','hippoo_short_ticket');4 add_action( 'init', 'hippoo_ticket_output_buffer' ); 5 add_shortcode( 'hippoo_ticket', 'hippoo_short_ticket' ); 6 6 7 7 function hippoo_ticket_output_buffer() { … … 9 9 } 10 10 11 function hippoo_short_ticket($atts=[]){ 11 function hippoo_short_ticket( $atts = [] ){ 12 if ( defined( 'REST_REQUEST' ) ) 13 return; 12 14 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() ); 18 17 exit(); 19 18 } 20 19 20 global $wpdb; 21 21 22 22 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 ); 26 27 $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 33 28 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' ) ) { 47 31 48 32 // 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'] ) ) { 53 34 $media_ids = hippoo_ticket_media_upload(); 54 35 } else { … … 56 37 } 57 38 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'] ) ) : ''; 60 40 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' ); 64 44 } else { 65 $msg = 'Error: Invalid ticket content.';45 wc_add_notice( 'Error: Invalid ticket content.', 'error' ); 66 46 } 67 47 } 68 48 } 69 49 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 70 55 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 } 71 67 72 68 # 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/' ); 78 75 79 76 return ob_get_clean(); 80 77 } 81 ?>
Note: See TracChangeset
for help on using the changeset viewer.