golden hour
/home/godaofbq/hyperbarichelp.com/wp-content/plugins/support_ticket/lib/front-form
⬆️ Go Up
Upload
File/Folder
Size
Actions
.htaccess
420 B
Del
OK
Front_Form.php
115.73 KB
Del
OK
front-form.php
553 B
Del
OK
lib
-
Del
OK
Edit: Front_Form.php
<?php class Front_Form { public $allowed_mime_types; public $html; public $settings; public $settings_slug = 'tps_all_settings'; public $is_debug = false; public $lang = 'en_US'; public $lang_short = 'en'; public $form_fields = array(); protected $manage_permissions = array(); function __construct() { // Init add_action( 'init', array( $this, 'tps_init' ) ); // HTML helper to render HTML elements $this->html = new Html_Helper; // Either use default settings if no setting set, or try to merge defaults with existing settings // Needed if new options were added in upgraded version of the plugin //print_r($this->settings); $this->settings = $this->tps_get_all_options(); //echo "<pre>"; print_r($this->settings); echo "</pre>"; //die; //register_activation_hook( __FILE__, array( $this, 'activate_plugin' ) ); } function tps_settings_defaults($section_name = "") { $defaults = array(); $setting_fields = Front_Form_Settings::tps_get_settings_fields(); if($section_name == "" || $section_name == "all"){ foreach ($setting_fields as $section => $fields_arr) { foreach ($setting_fields[$section] as $setting) { $defaults[ $setting['name'] ] = $setting['default']; } } } else if(isset($setting_fields[$section_name])){ foreach ($setting_fields[$section_name] as $setting) { $defaults[ $setting['name'] ] = $setting['default']; } } /*$settings = Front_Form_Settings::tps_get_settings_fields(); foreach ( $settings[$this->settings_slug] as $setting ) { $defaults[ $setting['name'] ] = $setting['default']; }*/ return $defaults; } function tps_get_all_options(){ //echo "<pre>------------------------<br>"; $get = array(); $setting_fields = Front_Form_Settings::tps_get_settings_fields(); foreach ($setting_fields as $section => $fields_arr) { //echo $section."<br>"; $get_section = get_option( $section, $this->tps_settings_defaults($section)); //print_r($get_section); if($section == "email_settings"){ foreach ($get_section as $key => $value) { $value = str_replace("!@#$#%new#$#@!","\n", $value); $value = str_replace("!@#$#%tab#$#@!","\t", $value); $value = str_replace("!@#$#%lt#$#@!","<", $value); $value = str_replace("!@#$#%gt#$#@!",">", $value); $get_section[$key] = $value; } //echo "<pre>"; print_r($get_section); echo "</pre>"; } if($get_section){ $get = array_merge($get,$get_section); //$get = $get + $get_section; } } //echo "<pre>"; print_r($get); echo "</pre>"; //print_r($get); //echo "------------------------<br></pre>"; return $get; } /** * Load languages and a bit of paranoia */ function tps_init() { //echo get_locale(); // echo dirname(plugin_basename( __FILE__ )) . '/../../languages/'; load_plugin_textdomain( 'tpsupport', false, dirname( plugin_basename( __FILE__ ) ) . '/../../languages/' ); // Hooking to wp_ajax add_action( 'wp_ajax_approve_ugc', array( $this, 'tps_approve_media' ) ); add_action( 'wp_ajax_approve_ugc_post', array( $this, 'tps_approve_post' ) ); add_action( 'wp_ajax_delete_ugc', array( $this, 'tps_delete_post' ) ); add_action( 'wp_ajax_upload_ugc', array( $this, 'tps_upload_content' ) ); add_action( 'wp_ajax_nopriv_upload_ugc', array( $this, 'tps_upload_content' ) ); // Adding media submenu add_action( 'admin_menu', array( $this, 'tps_add_menu_items' ) ); // Currently supported shortcodes add_shortcode( 'tps-new-ticket-form', array( $this, 'tps_ticket_new_form' ) ); add_shortcode( 'tps-ticket-comment-form', array( $this, 'tps_ticket_new_form' ) ); add_shortcode( 'tps-ticket-feedback-form', array( $this, 'tps_ticket_new_form' ) ); add_shortcode( 'tps-upload-response', array( $this, 'tps_form_response_shortcode' ) ); // Since 4.01 we need to explicitly disable texturizing of shortcode's inner content add_filter( 'no_texturize_shortcodes', array( $this, 'tps_filter_no_texturize_shortcodes' ) ); // Static assets add_action( 'admin_enqueue_scripts', array( $this, 'tps_admin_enqueue_scripts' ) ); // Unautop the shortcode add_filter( 'the_content', 'shortcode_unautop', 100 ); // Hiding not approved attachments from Media Gallery // @since core 3.5-beta-1 add_filter( 'posts_where', array( $this, 'tps_filter_posts_where' ) ); $this->allowed_mime_types = $this->tps_get_mime_types(); // Configuration filter to change manage permissions $this->manage_permissions = apply_filters( 'tps_manage_permissions', 'edit_posts' ); // Debug mode filter $this->is_debug = (bool) apply_filters( 'tps_is_debug', defined( 'WP_DEBUG' ) && WP_DEBUG ); add_action( 'tps_after_upload', array( $this, 'tps_maybe_insert_images_into_post' ), 10, 4 ); $this->tps_set_language(); /* // Maybe enable Akismet protection $this->tps_enable_akismet_protection(); */ // Maybe enable Recaptcha protection $this->tps_enable_recaptcha_protection(); } /** * Set current language (used for captcha and jquery validate l18n ) */ function tps_set_language() { // Filter is needed for wordpress.com $this->lang = apply_filters( 'tps_wplang', get_bloginfo( 'language' ) ); $this->lang_short = substr( $this->lang, 0, 2 ); } /** * Add extra mime-types * * This is mostly legacy, and really should be deprecated or refactored due to unneccessary complexity * * @return [type] [description] */ function tps_get_mime_types() { $mime_types = wp_get_mime_types(); $tps_mime_types = tpstps_get_mime_types(); $enabled = isset( $this->settings['enabled_files'] ) && is_array( $this->settings['enabled_files'] ) ? $this->settings['enabled_files'] : array(); // $tps_mime_types holds extra mimes that are not allowed by WP foreach ( $tps_mime_types as $extension => $details ) { // Skip if it's not in the settings if ( !in_array( $extension, $enabled ) ) continue; // Files have multiple mimes sometimes, we need to cover all of them foreach ( $details['mimes'] as $ext_mime ) { $mime_types[ $extension . '|' . $extension . sanitize_title_with_dashes( $ext_mime ) ] = $ext_mime; } } // Configuration filter: tps_allowed_mime_types should return array of allowed mime types (see readme) $mime_types = apply_filters( 'tps_allowed_mime_types', $mime_types ); foreach ( $mime_types as $ext_key => $mime ) { // Check for php just in case if ( false !== strpos( $mime, 'php' ) ) unset( $mime_types[$ext_key] ); } return $mime_types; } function tps_filter_no_texturize_shortcodes( $shortcodes ) { $shortcodes[] = 'tps-new-ticket-form'; return $shortcodes; } function tps_filter_posts_where( $where ) { if ( !is_admin() || !function_exists( 'get_current_screen' ) ) return $where; $screen = get_current_screen(); if ( ! defined( 'DOING_AJAX' ) && $screen && isset( $screen->base ) && $screen->base == 'upload' && ( !isset( $_GET['page'] ) || $_GET['page'] != 'manage_front_form' ) ) { $where = str_replace( "post_status = 'private'", "post_status = 'inherit'", $where ); } return $where; } function tps_is_public() { return ( current_user_can( 'read' ) /*&& 'on' == $this->settings['auto_approve_user_files'] ) || ( 'on' == $this->settings['auto_approve_any_files']*/ ); } function tps_upload_files( $post_id = 0, $retarr = array() ) { $upload_type = ""; if(isset($retarr['upload_type']) && $retarr['upload_type'] == 'ticket_comment'){ $upload_type = 'ticket_comment'; } // Only filter mimes just before the upload add_filter( 'upload_mimes', array( $this, 'tps_get_mime_types' ), 999 ); //print_r($retarr); die; $media_ids = $media_names = $errors = array(); // Bail if there are no files if ( empty( $_FILES ) ) return array(); // File field name could be user defined, so we just get the first file $files = current( $_FILES ); //echo "<pre>"; print_r($files); echo "</pre>"; //die; // There can be multiple files // So we need to iterate over each of the files to process for ( $i = 0; $i < count( $files['name'] ); $i++ ) { $fields = array( 'name', 'type', 'tmp_name', 'error', 'size' ); foreach ( $fields as $field ) { $k[$field] = $files[$field][$i]; } $k['name'] = sanitize_file_name( $k['name'] ); // if ( $k['error'] === 4 ) { continue; } // Skip to the next file if upload went wrong if ( $k['error'] !== 0 ) { $errors['tps-error-media'][] = array( 'name' => $k['name'], 'code' => $k['error'] ); continue; } $typecheck = wp_check_filetype_and_ext( $k['tmp_name'], $k['name'], false ); // Add an error message if MIME-type is not allowed if ( ! in_array( $typecheck['type'], (array) $this->allowed_mime_types ) ) { $errors['tps-disallowed-mime-type'][] = array( 'name' => $k['name'], 'mime' => $k['type'] ); continue; } /* // Now let's try to catch eval( base64() ) et al if ( 0 !== $this->tps_invoke_paranoia_on_file_contents( file_get_contents( $k['tmp_name'] ) ) ) { $errors['tps-suspicious-file'][] = array( 'name' => $k['name'] ); continue; }*/ // Setup some default values // However, you can make additional changes on 'tps_after_upload' action $caption = ''; // Try to set post caption if the field is set on request // Fallback to post_content if the field is not set if ( isset( $_POST['caption'] ) ) { $caption = sanitize_text_field( $_POST['caption'] ); } elseif ( isset( $_POST['post_content'] ) ) { $caption = sanitize_text_field( $_POST['post_content'] ); } $filename = pathinfo( $k['name'], PATHINFO_FILENAME ); if($upload_type == "ticket_comment"){ $post_overrides = array( 'post_status' => 'publish', //$this->tps_is_public() ? 'publish' : 'private', 'post_title' => __( 'Attached to Comment on Ticket ID:', 'tpsupport' )." ".$post_id." [".__('Comment ID:','tpsupport'). " ".$retarr['commentid']."] ".sanitize_text_field( $filename ), 'post_content' => "", //empty( $caption ) ? __( 'Unnamed', 'tpsupport' ) : $caption, 'post_excerpt' => "", //empty( $caption ) ? __( 'Unnamed', 'tpsupport' ) : $caption, ); } else { $post_overrides = array( 'post_status' => 'publish', //$this->tps_is_public() ? 'publish' : 'private', 'post_title' => __( 'Attached to Ticket ID:', 'tpsupport' )." ".$post_id."", //isset( $_POST['post_title'] ) && ! empty( $_POST['post_title'] ) ? sanitize_text_field( $_POST['post_title'] ) : sanitize_text_field( $filename ), 'post_content' => isset( $_POST['post_title'] ) && ! empty( $_POST['post_title'] ) ? sanitize_text_field( $_POST['post_title'] ) : "", //empty( $caption ) ? __( 'Unnamed', 'tpsupport' ) : $caption, 'post_excerpt' => isset( $_POST['post_title'] ) && ! empty( $_POST['post_title'] ) ? sanitize_text_field( $_POST['post_title'] ) : "", //empty( $caption ) ? __( 'Unnamed', 'tpsupport' ) : $caption, ); } $m = $k; // Obfuscate filename if setting is present if ( isset( $this->settings['obfuscate_file_name'] ) && 'on' == $this->settings['obfuscate_file_name'] ){ $fn = explode( '.', $k['name'] ); $m['name'] = uniqid( mt_rand( 1, 1000 ) , true ) . '.' . end( $fn ); } //echo "<pre>"; //print_r($m); //print_r( $post_overrides); //echo "</pre>"; //die; // Trying to upload the file $upload_id = media_handle_sideload( $m, (int) $post_id, $post_overrides['post_title'], $post_overrides ); if ( !is_wp_error( $upload_id ) ) { $media_ids[] = $upload_id; $media_names[$upload_id] = $m['name']; //$upload_id; } else { $errors['tps-error-media'][] = $k['name']; } } /** * $success determines the rest of upload flow * Setting this to true if no errors were produced even if there's was no files to upload */ $success = empty( $errors ) ? true : false; if ( $success ) { foreach ( $media_ids as $media_id ) { $this->tps_save_post_meta_fields( $media_id ); } } //echo "<pre>"; print_r($retarr); print_r($post_overrides); print_r($media_ids); print_r($success); echo "<br>"; print_r($post_id); echo "</pre>"; //die; // Allow additional setup // Pass array of attachment ids if($upload_type == "ticket_comment"){ //echo "hihi"; //print_r($retarr); //die; do_action( 'tps_after_upload', $media_ids, $success, $post_id, $retarr ); } else { do_action( 'tps_after_upload', $media_ids, $success, $post_id, array()); } //die; return array( 'success' => $success, 'media_ids' => $media_ids, 'media_names' => $media_names, 'errors' => $errors ); } /** * A callback to append uploaded images html to post * * @param array $media_ids [description] * @param bool $success [description] * @param int $post_id [description] * @return mixed [description] */ function tps_maybe_insert_images_into_post( $media_ids, $success, $post_id , $retarr ) { //echo "media_ids"; //print_r($media_ids); // Bail if request is failed, $post = get_post( $post_id ); $attachments_html = "\n"; $attachments_arr = array(); foreach( (array) $media_ids as $media_id ) { $attachments_html .= wp_get_attachment_image( $media_id, 'full' ); //$src = wp_get_attachment_image_src( $media_id, 'full'); $attachments_arr[] = $media_id; //$src[0]; } //echo "hi11"; //print_r($attachments_arr); //die; if(isset($retarr['upload_type']) && $retarr['upload_type'] == "ticket_comment"){ //echo "h1i: " .$retarr['upload_type'] . $retarr['commentid']; $get_comments = get_post_meta( $post_id, 'tps_comments', true ); //print_r($get_comments);echo "<br>"; //echo "<pre>0 < comments found|"; echo "|hi"; print_r($get_comments); echo "hi|"; $key = $retarr['commentid']; //echo "[".$newkey."]"; $comments_arr = $get_comments; //$comments_arr[$key]['attachments'] = $attachments_arr; $comments_arr[$key]['attachments'] = $attachments_arr; //echo "|hi:"; print_r($comments_arr); echo "hi|</pre>"; update_post_meta( $post_id, 'tps_comments', $comments_arr ); //die; return; } //die; add_post_meta( $post_id, 'tps_attachments', $attachments_arr, false ); // add wp_kses_allowed_html filter just in time before we save post add_filter( 'wp_kses_allowed_html', array( $this, 'tps_wp_kses_add_srcset' ), 10, 2 ); /*if ( ! $success || !isset( $_POST[ 'append_to_post' ] ) || !$_POST['append_to_post'] ){ return; } else { $post->post_content .= $attachments_html; return wp_update_post( $post, true ); }*/ } /** * Force adding srcset as allowed attr for repsonsive images * @param [type] $tags [description] * @param [type] $context [description] * @return [type] [description] */ function tps_wp_kses_add_srcset( $tags, $context ) { if ( $context == 'post' ) $tags['img']['srcset'] = true; return $tags; } function tps_upload_post() { $errors = array(); $success = true; // Sanitize category if present in request // Allow to supply comma-separated category ids $category = array(); if ( isset( $_POST['post_category'] ) ) { //echo $_POST['post_category']; if(is_numeric($_POST['post_category'])){ $category = $_POST['post_category']; } else { foreach ( explode( ',', $_POST['post_category'] ) as $cat_id ) { $category[] = (int) $cat_id; } } } //print_r($category); //die; $post_title = isset( $_POST['caption'] ) ? sanitize_text_field( $_POST['caption'] ) : sanitize_text_field( $_POST['post_title'] ); $post_type = isset( $_POST['post_type'] ) && $this->tps_is_allowed_post_type( $_POST['post_type'] ) ? sanitize_key( $_POST['post_type'] ) : 'tickets'; $post_taxnomy = ""; if($post_type == "tickets"){ $post_taxnomy = "topic"; } // Construct post array; $post_array = array( 'post_type' => $post_type, 'post_title' => $post_title ? $post_title : __( 'Untitled Ticket', 'tpsupport' ), 'post_content' => wp_filter_post_kses( $_POST['post_content'] ), 'post_status' => 'publish', //$this->tps_is_public() ? 'publish' : 'private', //'post_category' => $category, /*'tax_input' => array( $post_taxnomy => array($category), ),*/ ); // get current user id if logged in $post_array['post_author'] = ""; if(is_user_logged_in()){ $current_user = wp_get_current_user(); $post_array['post_author'] = $current_user->ID; } $post_array = apply_filters( 'tps_before_create_post', $post_array ); //echo "<pre>"; print_r($_POST); print_r($post_array); echo "</pre>"; //die; $post_id = wp_insert_post( $post_array, true ); //This is typical issue. While wp_insert_post() won't check for user capabilities to insert post, the tax_input part actually will check if user has permission to manipulate those specific taxonomies. //The solution is to insert post first, then assign terms via separate function calls which won't check capabilities (yeah, it's not consistent). //if(!is_user_logged_in()){ wp_set_object_terms( $post_id, array((int)$category), $post_taxnomy ); //die; //} // Something went wrong if ( is_wp_error( $post_id ) ) { $errors = array( 'tps-error-post' => 1 ); $success = false; } else { do_action( 'tps_after_create_post', $post_id ); $this->tps_save_post_meta_fields( $post_id ); // If the author name is not in registered users // Save the author name if it was filled and post was created successfully //if ( $author ) //add_post_meta( $post_id, 'author_name', $author ); $post_dispname = isset( $_POST['post_dispname'] ) ? sanitize_text_field( $_POST['post_dispname'] ) : ''; $post_email = isset( $_POST['post_email'] ) ? sanitize_text_field( $_POST['post_email'] ) : ''; $post_url = isset( $_POST['post_url'] ) ? sanitize_text_field( $_POST['post_url'] ) : ''; $post_followup = isset( $_POST['followup'] ) ? sanitize_text_field( $_POST['followup'] ) : ''; add_post_meta( $post_id, 'tps_dispname', $post_dispname, false ); add_post_meta( $post_id, 'tps_email', $post_email, false ); add_post_meta( $post_id, 'tps_url', $post_url, false ); add_post_meta( $post_id, 'tps_followup', $post_followup, false ); add_post_meta( $post_id, 'tps_feedback_status', 'na', false ); //add_post_meta( $post_id, 'tps_last_activity', $post_time, false ); add_post_meta( $post_id, 'tps_assign', "", false ); $ticket_status = $this->tps_ticket_status($post_id,'new'); $ticket_agent = $this->tps_ticket_auto_assign_agent($post_id,$category); } $return_data = array(); $return_data['post_array'] = $post_array; $return_data['post_taxnomy'] = $post_taxnomy; $return_data['post_category'] = $category; $return_data['post_id'] = $post_id; $return_data['post_dispname'] = $post_dispname; $return_data['post_email'] = $post_email; $return_data['post_url'] = $post_url; $return_data['post_status'] = $post_status; $return_data['post_followup'] = $post_followup; return array( 'success' => $success, 'post_id' => $post_id, 'errors' => $errors , 'data' => $return_data, 'upload_type' => 'new_ticket' ); } function tps_ticket_status($post_id,$status,$details = array()){ // Change Status $post_status = $status; if($post_status != "no_change_from_email"){ update_post_meta( $post_id, 'tps_status', $post_status, false ); } $post_time = $this->tps_get_current_time('ts'); update_post_meta( $post_id, 'tps_last_activity', $post_time, false ); //print_r($post_id); die; $data = array(); $data['type'] = "status"; $data['value'] = $post_status; if(isset($details['submit_type'])){ $data['submit_type'] = $details['submit_type']; } if(isset($details['userId'])){ $data['userId'] = $details['userId']; } if(isset($details['user_type'])){ $data['user_type'] = $details['user_type']; } if(isset($details['user_name'])){ $data['user_name'] = $details['user_name']; } if(isset($details['status_type'])){ $data['status_type'] = $details['status_type']; } if(isset($details['udate'])){ $data['email']['udate'] = $details['udate']; } if(isset($details['date'])){ $data['email']['date'] = $details['date']; } if(isset($details['uid'])){ $data['email']['uid'] = $details['uid']; } if(isset($details['msgno'])){ $data['email']['msgno'] = $details['msgno']; } //print_r($data); //print_r($details); die; $this->tps_manage_ticket_history($post_id,$data); return true; } function tps_assign_to_anyone($getval,$method){ //echo $getval; $assign_entity_id = $getval; $assign_entity_name = ""; if(is_numeric($getval)){ $get_userdata = get_userdata($assign_entity_id); $assign_entity_name = $get_userdata->display_name; $get_agent_role = $get_userdata->roles; $data['assigntype'] = ""; //print_r($get_agent_role); // get role //echo "|".$get_agent_role."|"; if(is_array($get_agent_role)){ if(in_array("agentadmin",$get_agent_role)){ $data['assigntype'] = "agentadmin"; } else if(in_array("agent",$get_agent_role)){ $data['assigntype'] = "agent"; } } } else { $exp = explode("-", $getval); $assigntype = $exp[0]; $agid = $exp[1]; if($agid != ""){ $assign_entity_name = get_post_field( 'post_title', $agid); if($assigntype == "GA"){ $data['assigntype'] = "groupadmin"; $assign_entity_name = __("Group Admin: ","tpsupport")." ".$assign_entity_name; } else if($assigntype == "G"){ $data['assigntype'] = "group"; $assign_entity_name = __("Group: ","tpsupport")." ".$assign_entity_name; } } } if($method == "assign_to_one_from_multiple"){ $data['value'] = 'assign_by_topic'; } else { $data['value'] = 'assign_to_anyone'; } $ret = array(); $ret['assign_entity_id'] = $assign_entity_id; $ret['assign_entity_name'] = $assign_entity_name; $ret['data_value'] = $data['value']; $ret['data_assigntype'] = $data['assigntype']; return $ret; } function tps_get_assign_type_all_ids($post_topic){ $ret = array(); $gto = ""; $gid = ""; $all_ids = array(); $get_assign_type = $this->settings['assign_to_one_from_multiple']; $data['entitytype'] = $get_assign_type; if($get_assign_type != ""){ $allowed_ids = $this->settings[$get_assign_type]; //echo $get_assign_type; print_r($allowed_ids)."<br>"; // agents if($get_assign_type == "assign_to_agents"){ if(is_array($allowed_ids) && in_array("all",$allowed_ids)){ //echo "all agents"; $all_ids = tps_get_all_entities_arr("agents","","","id"); } else { $all_ids = $allowed_ids; } } // agent admins else if($get_assign_type == "assign_to_agentadmins"){ if(is_array($allowed_ids) && in_array("all",$allowed_ids)){ //echo "all agent admins"; $all_ids = tps_get_all_entities_arr("agentadmin","","","id"); } else { //echo "agent admins with id:"; print_r($allowed_ids); $all_ids = $allowed_ids; } } // groups else if($get_assign_type == "assign_to_groups"){ if(is_array($allowed_ids) && in_array("all",$allowed_ids)){ //echo "all agent admins"; $all_ids = tps_get_all_entities_arr("groups","","","id"); } else { //echo "agent admins with id:"; print_r($allowed_ids); $all_ids = $allowed_ids; } } // group admins else if($get_assign_type == "assign_to_group_admins"){ if(is_array($allowed_ids) && in_array("all",$allowed_ids)){ //echo "all agent admins"; $all_ids = tps_get_all_entities_arr("groupsadmin","","","id"); } else { //echo "agent admins with id:"; print_r($allowed_ids); $all_ids = $allowed_ids; } } // group agents else if($get_assign_type == "assign_to_group_agents"){ if($allowed_ids != ""){ $exp = explode("-", $allowed_ids); $assigntype = $exp[0]; $agid = $exp[1]; if($agid != "0" && $agid != "" && is_numeric($agid)){ // get all group members $ag_allagents = get_post_meta($agid,"tpsag_allagents",true); if(isset($ag_allagents['agents'])){ $all_ids = $ag_allagents['agents']; } } //echo "all agent in group: ".$allowed_ids; } } // topic based else if($get_assign_type == "assign_by_topic"){ //echo $post_topic; if($post_topic != "" && $post_topic !="0" && is_numeric($post_topic)){ $get_map = $this->settings['assign_by_topic']; //print_r($get_map); if(is_array($get_map) && isset($get_map['map_topic_'.$post_topic.'_group'])){ $gid = $get_map['map_topic_'.$post_topic.'_group']; $gto = "group"; if(isset($get_map['map_topic_'.$post_topic.'_to'])){ $gto = $get_map['map_topic_'.$post_topic.'_to']; } if($gto == "group"){ $all_ids[] = $gid; } else if($gto == "group_admin"){ $gid = str_replace("G-", "GA-", $gid); $all_ids[] = $gid; } else if($gto == "group_member"){ $all_ids = $this->tps_get_group_members($gid); } } } } // end else if assign_by_topic } $ret['all_ids'] = $all_ids; $ret['get_assign_type'] = $get_assign_type; $ret['allowed_ids'] = $allowed_ids; $ret['data_entitytype'] = $data['entitytype']; $ret['gid'] = $gid; $ret['gto'] = $gto; return $ret; } function tps_assign_by_order($all_ids,$get_assign_type,$allowed_ids,$gid,$gto){ if ( isset($this->settings['assign_ticket_order']) && $this->settings['assign_ticket_order'] == 'loop'){ // assign agent and status = open $assign_entity_id = ""; $assign_entity_name = ""; /*$agents_arr = get_users(array( 'role' => 'agent', 'fields'=> array('ID','display_name'), )); echo "<pre>"; print_r($agents_arr); echo "</pre>";*/ $option_name = $get_assign_type.'_in_loop'; if($get_assign_type == "assign_to_group_agents"){ $option_name .= '_'.$allowed_ids; } else if($get_assign_type == "assign_by_topic" && $gto == "group_member"){ $option_name .= '_'.$gto.'_'.$gid; } // fetch last assigned agent in loop $last_assigned_agent_in_loop = trim(get_option( $option_name, '')); //echo $option_name." : "; echo "|".$last_assigned_agent_in_loop."|<br>"; // get last agent assigned and select next agent in loop if($last_assigned_agent_in_loop != "" && $last_assigned_agent_in_loop != "0"){ //echo "||".$last_assigned_agent_in_loop."||<br>"; //echo "<pre>"; print_r($agents_arr); echo "</pre>"; if(sizeof($all_ids) > 0){ $found = false; foreach ($all_ids as $entityID) { if($found){ $assign_entity_id = $entityID; $assign_entity_name = $this->tps_get_entity_name($entityID,$get_assign_type); break; } else if($entityID == $last_assigned_agent_in_loop){ $found = true; } } } //echo "|||".$assign_entity_id.": ".$assign_entity_name."|||"; } // if empty get option: no agent in loop assigned yet // or // assigned agent is last in loop, then restart loop if($last_assigned_agent_in_loop == "" || $assign_entity_id == ""){ //echo "no entity last assigned"; //die; //echo "<pre>"; print_r($agents_arr); echo "</pre>"; if(sizeof($all_ids) > 0){ foreach ($all_ids as $entityID) { $assign_entity_id = $entityID; $assign_entity_name = $this->tps_get_entity_name($entityID,$get_assign_type); break; } } //echo "|".$assign_entity_id.": ".$assign_entity_name."|"; } // update option last assigned update_option( $option_name, $assign_entity_id); // assign agent to ticket // change status to open // manage status history //die; $data['value'] = 'assign_in_loop'; } // end loop else if ( isset($this->settings['assign_ticket_order']) && $this->settings['assign_ticket_order'] == 'lowest'){ $assign_entity_id = ""; $assign_entity_name = ""; $args = array( 'posts_per_page' => -1, 'post_type' => 'tickets', 'fields' => 'id=>tps_assign', 'meta_query' => array( array( 'key' => 'tps_status', 'value' => 'open', ), array( 'key' => 'tps_assign', 'value' => $all_ids, 'compare' => 'IN', ) ) ); $count = array(); $the_query = new WP_Query( $args ); if ( $the_query->have_posts() ) { // set basic array keys for all agent user ids /*$agents_arr = get_users(array( 'role' => 'agent', 'fields'=> array('ID','display_name'), ));*/ if(sizeof($all_ids) > 0){ foreach ($all_ids as $entityID) { $count[$entityID] = 0; } } //echo "post found"; //echo '<ul>'; while ( $the_query->have_posts() ) { $the_query->the_post(); //print_r($the_query); //$status = get_post_meta( get_the_ID(), 'tps_status', true ); $agent = get_post_meta( get_the_ID(), 'tps_assign', true ); //echo '<li>'.get_the_ID().': ' . get_the_title() .": ".$status.$agent. '</li>'; if($agent != ""){ if(isset($count[$agent])){ $count[$agent] = $count[$agent]+1; } else { $count[$agent] = 1; } } } //echo '</ul>'; //echo "<pre>"; print_r($count); echo "</pre>"; // sort array by key with lowest value asort($count); //echo "<pre>"; print_r($count); echo "</pre>"; $assign_entity_id = current(array_keys($count)); $assign_entity_name = $this->tps_get_entity_name($entityID,$get_assign_type); wp_reset_postdata(); } else { //echo "no post found"; // no posts found // assign agent and status = open /*$agents_arr = get_users(array( 'role' => 'agent', 'fields'=> array('ID','display_name'), ));*/ //echo "<pre>"; print_r($agents_arr); echo "</pre>"; if(sizeof($all_ids) > 0){ foreach ($all_ids as $entityID) { $assign_entity_id = $entityID; $assign_entity_name = $this->tps_get_entity_name($entityID,$get_assign_type); break; } } } //echo "assign: |".$assign_entity_id."|"; $data['value'] = 'assign_by_lowest'; //die; } // end lowest $ret = array(); $ret['assign_entity_id'] = $assign_entity_id; $ret['assign_entity_name'] = $assign_entity_name; $ret['data_value'] = $data['value']; return $ret; } function tps_ticket_auto_assign_agent($post_id,$post_topic){ if ( 'on' == $this->settings['assign_ticket_agent'] ){ $method = $this->settings['assign_ticket_method']; $data = array(); $data['type'] = "agent"; // method 1 if($method == "assign_to_anyone"){ $assign_entity_id = ""; $assign_entity_name = ""; $getval = $this->settings['assign_to_anyone']; if(isset($getval) && $getval != "" && $getval != "0"){ $retval = $this->tps_assign_to_anyone($getval,$method); //echo "<pre>"; print_r($retval); echo "</pre>"; $assign_entity_id = $retval['assign_entity_id']; $assign_entity_name = $retval['assign_entity_name']; $data['value'] = $retval['data_value']; $data['assigntype'] = $retval['data_assigntype']; } else { //echo "notfound"; } } // method 2 else if($method == "assign_to_one_from_multiple"){ // end if get_assign_type $retval = $this->tps_get_assign_type_all_ids($post_topic); $all_ids = $retval['all_ids']; $get_assign_type = $retval['get_assign_type']; $allowed_ids = $retval['allowed_ids']; $data['entitytype'] = $retval['data_entitytype']; $gid = $retval['gid']; $gto = $retval['gto']; //echo $gid; echo $gto; //echo $get_assign_type; //echo "<pre>"; print_r($all_ids); echo "</pre>"; //die; if($get_assign_type == "assign_by_topic" && in_array($gto,array("group","group_admin"))){ //echo "select any one from method 1"; $retval = $this->tps_assign_to_anyone($gid,$method); //echo "<pre>"; print_r($retval); echo "</pre>"; $assign_entity_id = $retval['assign_entity_id']; $assign_entity_name = $retval['assign_entity_name']; $data['value'] = $retval['data_value']; $data['assigntype'] = $retval['data_assigntype']; } else { $retval = $this->tps_assign_by_order($all_ids,$get_assign_type,$allowed_ids,$gid,$gto); } $assign_entity_id = $retval['assign_entity_id']; $assign_entity_name = $retval['assign_entity_name']; $data['value'] = $retval['data_value']; $data['gid'] = $gid; $data['gto'] = $gto; } // end method 2 //die; /******** common actions *********/ // assign agent to ticket // change status to open // manage status history /*********************************/ $data['agentid'] = $assign_entity_id; $data['agentname'] = $assign_entity_name; //echo "<pre>"; print_r($data); echo "</pre>"; //die; if(isset($data['agentid']) && $data['agentid'] != ""){ // Change Status $post_status = 'open'; update_post_meta( $post_id, 'tps_status', $post_status, false ); // assign to agent with id below $post_assign = $data['agentid']; update_post_meta( $post_id, 'tps_assign', $post_assign, false ); $this->tps_all_agents_assigned($post_id,$post_assign); } $this->tps_manage_ticket_history($post_id,$data); //echo $post_id; //die; /***********************/ } return true; } function tps_get_group_members($gid){ $all_ids = array(); $exp = explode("-", $gid); $assigntype = $exp[0]; $agid = $exp[1]; if($agid != "0" && $agid != "" && is_numeric($agid)){ // get all group members $ag_allagents = get_post_meta($agid,"tpsag_allagents",true); if(isset($ag_allagents['agents'])){ $all_ids = $ag_allagents['agents']; } } return $all_ids; } function tps_get_entity_name($entityID,$get_assign_type){ $assign_entity_name = ""; if($get_assign_type == "assign_to_group_admins" || $get_assign_type == "assign_to_groups"){ // is group or group admin //echo "Group: ".$entityID; $assign_entity_name = $this->tps_get_group_name($entityID); } else { // is user id //echo "User: ".$entityID; $assign_entity_name = get_userdata($entityID)->display_name; } return $assign_entity_name; } function tps_get_group_name($entityID){ $assign_entity_name = ""; $exp = explode("-", $entityID); $assigntype = $exp[0]; $agid = $exp[1]; if($agid != ""){ $assign_entity_name = get_post_field( 'post_title', $agid); if($assigntype == "GA"){ $assign_entity_name = __("Group Admin: ","tpsupport")." ".$assign_entity_name; } else if($assigntype == "G"){ $assign_entity_name = __("Group: ","tpsupport")." ".$assign_entity_name; } } return $assign_entity_name; } function tps_all_agents_assigned($post_id,$post_assign){ $get_allagents = trim(get_post_meta( $post_id, 'tps_allagents',true)); //echo "|"; echo $get_allagents; echo "|"; $str = ""; if($get_allagents == ""){ $str = "|".$post_assign."|"; } else { $str = $get_allagents."|".$post_assign."|"; } update_post_meta( $post_id, 'tps_allagents', $str, false ); //die; } // this function manages status and agent history function tps_manage_ticket_history($post_id,$data = array()){ $time = $this->tps_get_current_time('ts'); $timestr = $this->tps_get_current_time("YmdHisfromts",$time); //$time = $this->tps_get_current_time('ts'); $str = ""; //echo "hi111"; die; // manage status history if(isset($data['type']) && $data['type'] == 'status'){ $status = $data['value']; if($status == "new"){ $userId = $data['userId']; $user_name = $data['user_name']; if(isset($data['submit_type']) && $data['submit_type'] == "comment"){ $str = __('New comment posted on', 'tpsupport' )." ".$timestr." [submit_type:comment|||userId:".$userId."|||user_name:".$user_name."|||status:".$status."|||time:".$time."]"; } else { $str = __('New ticket created on', 'tpsupport' )." ".$timestr." [submit_type:ticket|||userId:".$userId."|||user_name:".$user_name."|||status:".$status."|||time:".$time."]"; } } else if($status == "open" || $status == "no_change_from_email"){ $userId = $data['userId']; $user_name = $data['user_name']; $user_type = $data['user_type']; $str = ""; $status_type = ""; if($user_type == "client_emailreply"){ $email_udate = $data['email']['udate']; $email_uid = $data['email']['uid']; $email_msgno = $data['email']['msgno']; $email_date = $data['email']['date']; $status_type = '|||comment_type:email|||email_udate:'.$email_udate.'|||email_uid:'.$email_uid.'|||email_msgno:'.$email_msgno.'|||email_date:'.$email_date; } if(isset($data['status_type']) && $data['status_type'] == "re-open"){ $str .= __('Ticket Re-opened', 'tpsupport' )." "; $status_type = '|||status_type:re-open'; } $startstr = __('Owner Replied and Ticket Status: Open', 'tpsupport' ); if($status == "no_change_from_email"){ $startstr = __('Owner Replied and Ticket Status: Not Changed', 'tpsupport' ); } $str .= $startstr." ".__('On:', 'tpsupport' )." ".$timestr." [userId:".$userId."|||user_name:".$user_name."|||user_type:".$user_type."|||status:".$status.$status_type."|||time:".$time."]"; } else if($status == "pending"){ $userId = $data['userId']; $user_name = $data['user_name']; $user_type = $data['user_type']; $str = ""; $status_type = ""; if(isset($data['status_type']) && $data['status_type'] == "re-pending"){ $str .= __('Ticket Re-opened as Pending', 'tpsupport' )." "; $status_type = '|||status_type:re-pending'; } $str .= __('Agent Replied and Ticket Status: Pending ', 'tpsupport' ).$agentname." ".__('On:', 'tpsupport' )." ".$timestr." [userId:".$userId."|||user_name:".$user_name."|||user_type:".$user_type."|||status:".$status.$status_type."|||time:".$time."]"; } else if($status == "solved"){ $userId = $data['userId']; $user_name = $data['user_name']; $user_type = $data['user_type']; $str = __('Ticket Marked as Solved by '.$user_type.' Status: Solved', 'tpsupport' ).$agentname." ".__('On:', 'tpsupport' )." ".$timestr." [userId:".$userId."|||user_name:".$user_name."|||user_type:".$user_type."|||status:".$status."|||time:".$time."]"; } } // manage agent history if(isset($data['type']) && $data['type'] == 'agent'){ //echo "<pre>"; print_r($data); echo "</pre>"; //die; $status = $data['value']; $agentid = $data['agentid']; $agentname = $data['agentname']; $entitytype = $data['entitytype']; $gid = $data['gid']; $gto = $data['gto']; $assign_by_topic_details = ""; //echo $entitytype; $user_id = $data['userId']; $user_name = $data['user_name']; if($gid != ""){ $assign_by_topic_details .= "|||groupid:".$gid; } if($gto != ""){ $assign_by_topic_details .= "|||assignto:".$gto; } $strinfo = "[agentid:".$agentid."|||agentname:".$agentname."|||entitytype:".$entitytype."|||type:".$data['type'].$assign_by_topic_details."|||auto_assign:".$status."|||time:".$time."]"; if($entitytype == "assign_to_groups" || $entitytype == "assign_to_group_admins"){ $strinfo = "[groupid:".$agentid."|||groupname:".$agentname."|||entitytype:".$entitytype."|||type:".$data['type'].$assign_by_topic_details."|||auto_assign:".$status."|||time:".$time."]"; } $entity_assigned = __('Agent Assigned: ', 'tpsupport' ); if($entitytype == "assign_to_groups"){ $entity_assigned = __('Group Assigned: ', 'tpsupport' ); } else if($entitytype == "assign_to_group_admins"){ $entity_assigned = __('Group Admin Assigned: ', 'tpsupport' ); } //die; if($status == "assign_in_loop"){ $str = __('Ticekt Status: Open ', 'tpsupport' ).$entity_assigned." ".$agentname." ".__('On:', 'tpsupport' )." ".$timestr." ".$strinfo; } else if($status == "assign_by_lowest"){ $str = __('Ticekt Status: Open ', 'tpsupport' ).$entity_assigned." ".$agentname." ".__('On:', 'tpsupport' )." ".$timestr." ".$strinfo; } else if ( $status == "assign_to_anyone" || ($status == "assign_by_topic" && isset($data['assigntype']) && ($data['assigntype'] == "group" || $data['assigntype'] == "groupadmin") )) { $assigntype = $data['assigntype']; //echo "|".$assigntype."|"; $str = ""; $assign_str = ""; if($assigntype == "agent"){ $assign_str = __('Assigned Agent: ', 'tpsupport' ); } else if($assigntype == "agentadmin"){ $assign_str = __('Assigned Agent Admin: ', 'tpsupport' ); } else if($assigntype == "group"){ $assign_str = __('Assigned to: ', 'tpsupport' ); } else if($assigntype == "groupadmin"){ $assign_str = __('Assigned to: ', 'tpsupport' ); } $str = __('Ticekt Status: Open ', 'tpsupport' ).$assign_str.$agentname." ".__('On:', 'tpsupport' )." ".$timestr." [".$assigntype."id:".$agentid.$assign_by_topic_details."|||".$assigntype."name:".$agentname."|||assigntype:".$assigntype."|||auto_assign:".$status."|||time:".$time."]"; } else if($status == "frontend_reassign"){ $strinfo = "[agentid:".$agentid."|||agentname:".$agentname."|||userid:".$user_id."|||username:".$user_name."|||status:".$status."|||type:".$data['type']."|||usertype:".$data['user_type']."|||time:".$time."]"; $str = __('Ticket Assigned to ', 'tpsupport' )." ".$agentname." ".__('On:', 'tpsupport' )." ".$timestr." ".__('By:', 'tpsupport' )." ".$user_name." ".$strinfo; //echo $str; } //echo $str; die; } //echo "hi"; if(isset($data['type']) && $data['type'] == 'feedback'){ $strinfo = "[userid:".$data['userId']."|||user_name:".$data['user_name']."|||rating:".$data['feedback_rate']."|||time:".$time."]"; $str = __('Ticekt Feedback: Rated as ', 'tpsupport' )." ".$data['feedback_rate']." ".__('On:', 'tpsupport' )." ".$timestr." ".__('By:', 'tpsupport' )." ".$data['user_name']." ".$strinfo; //echo $str; } //echo "hihi222"; die; $this->tps_update_ticket_history($post_id,$str); return true; } function tps_update_ticket_history($post_id,$str){ //echo "hihi333"; die; // add/update history value $get_history = get_post_meta( $post_id, 'tps_ticket_history',true ); //print_r($get_history);echo "<br>"; // update history, if already present if(is_array($get_history) && sizeof($get_history) > 0){ //echo "history > 0<br>"; $newkey = sizeof($get_history); $new_status = $str; $new_history = $get_history; $new_history[$newkey] = $new_status; update_post_meta( $post_id, 'tps_ticket_history', $new_history ); } else { // add history //echo "history == 0<br>"; $status_history = array($str); add_post_meta( $post_id, 'tps_ticket_history', $status_history, false ); } // echo "<pre>"; print_r(get_post_meta( $post_id, 'tps_ticket_history',true )); echo "</pre>"; // die; return true; } function tps_upload_post_comment() { //echo "hi"; //echo "<pre>"; print_r($_POST); echo "</pre>"; //die; $errors = array(); $success = true; $user_type = ""; $userId = ""; $user_name = ""; if(is_user_logged_in()){ $current_user = wp_get_current_user(); $userId = $current_user->ID; $user_name = $current_user->data->display_name; //echo "<pre>"; print_r($current_user); echo "</pre>"; //die; if(isset($current_user->roles) && is_array($current_user->roles)){ if(in_array("client",$current_user->roles)){ $user_type = "client"; } if(in_array("agent",$current_user->roles)){ $user_type = "agent"; } } //echo $user_type; //die; } /* $post_dispname = isset( $_POST['post_dispname'] ) ? sanitize_text_field( $_POST['post_dispname'] ) : ''; $post_email = isset( $_POST['post_email'] ) ? sanitize_text_field( $_POST['post_email'] ) : ''; $post_url = isset( $_POST['post_url'] ) ? sanitize_text_field( $_POST['post_url'] ) : ''; */ /* add_post_meta( $post_id, 'tps_dispname', $post_dispname, false ); add_post_meta( $post_id, 'tps_email', $post_email, false ); add_post_meta( $post_id, 'tps_url', $post_url, false ); */ $comments_arr = array(); $ticketid = $_POST['ticketid']; $post_comments = array(); $comment_text = wp_filter_post_kses( $_POST['post_content'] ); $post_comments['content'] = $comment_text; $post_comments['attachments'] = array(); $post_comments['userId'] = $userId; $details = array(); $details = $post_comments; $details['user_type'] = $user_type; $details['user_name'] = $user_name; $details['submit_type'] = "comment"; $newkey = $this->tps_update_ticket_comments($ticketid,$post_comments); //echo "hihi"; die; if(isset($_POST['mark_as_solved']) && $_POST['mark_as_solved'] == "on"){ $details['status'] = 'solved'; $ticket_status = $this->tps_ticket_status($ticketid,'solved',$details); $time = $this->tps_get_current_time('ts'); update_post_meta( $ticketid, 'tps_ticket_solved_time', $time, false ); //echo "hi". $user_type; die; } else if($user_type == "agent" || (isset($_POST['mark_as_pending']) && $_POST['mark_as_pending'] == "on")){ $details['status'] = 'pending'; $details['status_type'] = ""; if(isset($_POST['mark_as_pending']) && $_POST['mark_as_pending'] == "on"){ $details['status_type'] = "re-pending"; } //echo "hi1". $user_type; die; $ticket_status = $this->tps_ticket_status($ticketid,'pending',$details); // add the agent in conversation list $this->tps_all_agents_assigned($ticketid,$userId); //echo "hi". $user_type; } else if($user_type == "client" || (isset($_POST['mark_as_open']) && $_POST['mark_as_open'] == "on")){ // if assigned to none and status is new, than status is new // if assigned then status is open $get_status = get_post_meta( $ticketid, 'tps_status',true ); $get_assign = get_post_meta( $ticketid, 'tps_assign',true ); if($get_status == "new" && $get_assign == ""){ $details['status'] = 'new'; } else { $details['status'] = 'open'; } $details['status_type'] = ""; if(isset($_POST['mark_as_open']) && $_POST['mark_as_open'] == "on"){ $details['status'] = 'open'; $details['status_type'] = "re-open"; } $ticket_status = $this->tps_ticket_status($ticketid,$details['status'],$details); //echo "hi". $user_type; die; } else { // in case of admin or any other user role is submitting the form // if current user is same as ticket owner, then status is open $post_author_id = get_post_field( 'post_author', $ticketid ); //echo "author: " . $post_author_id."<br>"; if($post_author_id == $userId){ $details['status'] = 'open'; $details['user_type'] = "client"; $details['status_type'] = ""; } else { $details['status'] = 'pending'; $details['user_type'] = "agent"; $details['status_type'] = ""; } // else status is pending $ticket_status = $this->tps_ticket_status($ticketid,$details['status'],$details); // add the current user in conversation list $this->tps_all_agents_assigned($ticketid,$userId); } // assign agent, if(isset($_POST['assign_agent']) && $_POST['assign_agent'] != "0" && $_POST['assign_agent'] != ""){ // add the new agent/group in conversation list $this->tps_all_agents_assigned($ticketid,$_POST['assign_agent']); // assign new agent update_post_meta( $ticketid, 'tps_assign', $_POST['assign_agent']); // update history $data = array(); $data['type'] = "agent"; $data['agentid'] = $_POST['assign_agent']; $data['agentname'] = tps_get_assigned_agent_name_for_frontend($_POST['assign_agent'],"comment_history"); $data['value'] = "frontend_reassign"; $data['assigntype'] = ""; $data['entitytype'] = ""; $data['userId'] = $userId; $data['user_name'] = $user_name; $data['user_type'] = $_POST['comment_user_type']; $data['user_role'] = $_POST['user_role']; $data['gid'] = ""; $data['gto'] = ""; $this->tps_manage_ticket_history($ticketid,$data); } //echo "hi". $details['user_type']; //die; return array( 'success' => $success, 'post_id' => $ticketid, 'errors' => $errors, 'upload_type' => 'ticket_comment', 'commentid' => $newkey, 'data' => $post_comments ); } public function tps_update_ticket_comments($ticketid,$post_comments){ $comment_time = $this->tps_get_current_time('ts'); if($post_comments['userId'] == ""){ $post_comments['userId'] .= "|||".$post_comments['from']."|||"; } $post_comments['userId'] .= "-".$comment_time; $str = $post_comments['content']; /*$str = str_replace("\n", "!@#$#%new#$#@!", $str); $str = str_replace("\t", "!@#$#%tab#$#@!", $str); $str = str_replace("<", "!@#$#%lt#$#@!", $str); $str = str_replace(">", "!@#$#%gt#$#@!", $str);*/ $post_comments['content'] = $str; //echo "hi<pre>"; print_r($post_comments); echo "</pre>"; die; $get_comments = get_post_meta( $ticketid, 'tps_comments',true ); //print_r($get_comments);echo "<br>"; $newkey = "na"; if(is_array($get_comments) && sizeof($get_comments) > 0){ //echo "<pre>0 < comments found|"; //echo "|hi"; print_r($get_comments); echo "hi|"; // check for duplicate comment $duplicate = false; foreach ($get_comments as $kc => $kv) { //echo md5(trim(stripslashes($kv['content'])))."<br>".trim(stripslashes($kv['content']))."<hr>"; //echo md5(trim(stripslashes($post_comments['content'])))."<br>".trim(stripslashes($post_comments['content']))."<hr>"; if(trim(stripslashes($kv['content'])) == trim(stripslashes($post_comments['content']))){ $duplicate = true; break; } } if(!$duplicate){ $newkey = sizeof($get_comments); //echo "[".$newkey."]"; $comments_arr = $get_comments; $comments_arr[$newkey] = $post_comments; //echo "|hi:"; print_r($comments_arr); echo "hi|</pre>"; update_post_meta( $ticketid, 'tps_comments', $comments_arr ); } else { //echo "duplicate comment"; } //die; } else { $newkey = 0; //echo "|0 comments|"; echo "[".$post_comments."]"; $comments_arr[$newkey] = $post_comments; //echo "|hi:"; print_r($comments_arr); echo "hi|"; add_post_meta( $ticketid, 'tps_comments', $comments_arr ); } return $newkey; //die; } function tps_upload_post_feedback() { //echo "hi"; echo "<pre>"; print_r($_POST); echo "</pre>"; //die; $errors = array(); $success = true; $user_type = ""; $userId = ""; $user_name = ""; $ticketid = $_POST['ticketid']; $authorized = false; if(is_user_logged_in()){ $current_user = wp_get_current_user(); $userId = $current_user->ID; $user_name = $current_user->data->display_name; $post_author = get_post_field( 'post_author', $ticketid); $post_status = get_post_meta($ticketid,'tps_status',true); //echo $post_status; //die; //echo "post_author".$post_author; if($post_author == $userId && $post_status == "solved"){ $authorized = true; } } $data = array(); $details = array(); if($authorized){ $comment_text = wp_filter_post_kses( $_POST['post_content'] ); $comment_time = $this->tps_get_current_time('ts'); $details[0]['content'] = $comment_text; $details[0]['userId'] = $userId."-".$comment_time; //$details['feedback_rate'] = $_POST['feedback_rate']; //$details['user_name'] = $user_name; //$details['time'] = $comment_time; //$details['user_type'] = $user_type; echo "<pre>"; print_r($details); echo "</pre>"; update_post_meta( $ticketid, 'tps_feedback_status', $_POST['feedback_rate'] ); update_post_meta( $ticketid, 'tps_feedback_comment', $details ); update_post_meta( $ticketid, 'tps_last_activity', $comment_time ); $data['type'] = "feedback"; $data['content'] = $comment_text; $data['userId'] = $userId; $data['feedback_rate'] = $_POST['feedback_rate']; $data['user_name'] = $user_name; $data['time'] = $comment_time; echo "<pre>"; print_r($data); echo "</pre>"; $this->tps_manage_ticket_history($ticketid,$data); } //die; return array( 'success' => $success, 'post_id' => $ticketid, 'errors' => $errors, 'upload_type' => 'feedback', 'data' => $data ); } function tps_upload_post_comment_backup() { $errors = array(); $success = true; //echo "<pre>"; print_r($_POST); echo "</pre>"; die; global $post; global $current_user; //for this example only :) $ticketid = $_POST['ticketid']; $commentdata = array( 'comment_post_ID' => $ticketid, //$post->ID, // to which post the comment will show up 'comment_author' => '', //fixed value - can be dynamic 'comment_author_email' => '', //fixed value - can be dynamic 'comment_author_url' => '', //fixed value - can be dynamic 'comment_content' => wp_filter_post_kses( $_POST['post_content'] ), //fixed value - can be dynamic 'comment_type' => '', //empty for regular comments, 'pingback' for pingbacks, 'trackback' for trackbacks 'comment_parent' => 0, //0 if it's not a reply to another comment; if it's a reply, mention the parent comment ID here 'user_id' => $current_user->ID, //passing current user ID or any predefined as per the demand ); //Insert new comment and get the comment ID $comment_id = wp_new_comment( $commentdata ); //echo "comment_id: ".$comment_id." : <pre>"; print_r($_POST); echo "</pre>"; //die; $post_status = "open"; add_post_meta( $ticketid, 'tps_status', $post_status, false ); return array( 'success' => $success, 'post_id' => $ticketid, 'errors' => $errors ); } private function tps_save_post_meta_fields( $post_id = 0 ) { // Post ID not set, bailing if ( ! $post_id = (int) $post_id ) return false; // No meta fields in field mapping, bailing if ( !isset( $this->form_fields['meta'] ) || empty( $this->form_fields['meta'] ) ) return false; foreach ( $this->form_fields['meta'] as $meta_field ) { if ( !isset( $_POST[$meta_field] ) ) continue; $value = $_POST[$meta_field]; // Sanitize array if ( is_array( $value ) ) { $value = array_map( array( $this, 'tps_sanitize_array_element_callback' ), $value ); // Sanitize everything else } else { $value = sanitize_text_field( $value ); } add_post_meta( $post_id, $meta_field, $value, true ); } } /** * Handle post, post+media, or just media files * * @since 0.4 */ function tps_upload_content() { //echo "<pre>"; print_r($_POST); echo "</pre>"; die; $fields = $result = array(); // Bail if something fishy is going on if ( !wp_verify_nonce( $_POST['tps_nonce'], TPS_NONCE ) ) { wp_safe_redirect( add_query_arg( array( 'response' => 'tps-error', 'errors' => array( 'tps-nonce-failure' => 1 ) ), wp_get_referer() ) ); exit; } // Bail if supplied post type is not allowed if ( isset( $_POST['post_type'] ) && ! $this->tps_is_allowed_post_type( sanitize_key( $_POST['post_type'] ) ) ) { wp_safe_redirect( add_query_arg( array( 'response' => 'tps-error', 'errors' => array( 'tps-disallowed-post-type' => sanitize_key( $_POST['post_type'] ) ) ), wp_get_referer() ) ); exit; } //echo "<pre>"; print_r($_POST); echo "</pre>"; die; $form_post_id = isset( $_POST['form_post_id'] ) ? (int) $_POST['form_post_id'] : 0; $hash = sanitize_text_field( $_POST['ff'] ); $this->form_fields = !empty( $this->form_fields ) ? $this->form_fields : $this->tps_get_fields_for_form( $form_post_id, $hash ); $layout = isset( $_POST['form_layout'] ) && !empty( $_POST['form_layout'] ) ? $_POST['form_layout'] : 'post_media'; /** * Utility hook 'tps_should_process_content_upload': maybe terminate upload early (useful for Akismet integration, etc) * Defaults to true, upload will be terminated if set to false. * * Parameters: * boolean - whether should process * string $layout - which form layout is used */ if ( false === apply_filters( 'tps_should_process_content_upload', true, $layout ) ) { wp_safe_redirect( add_query_arg( array( 'response' => 'tps-spam' ), wp_get_referer() ) ); exit; } //switch ( $layout ) { //case 'post_media'; $content_submitted = ""; if(isset($_POST['form_type']) && $_POST['form_type'] == "comment" ){ $result = $this->tps_upload_post_comment(); } else if(isset($_POST['form_type']) && $_POST['form_type'] == "feedback" ){ $result = $this->tps_upload_post_feedback(); $content_submitted = "feedback"; } else { $result = $this->tps_upload_post(); } if ( ! is_wp_error( $result['post_id'] ) && $content_submitted != "feedback") { $media_result = $this->tps_upload_files( $result['post_id'], $result ); // Make sure we don't merge a non-array (tps_upload_files might return null, false or WP_Error) if(isset($_POST['form_type']) && $_POST['form_type'] == "comment"){ if ( is_array( $media_result ) ){ $result = array_merge( $result, $media_result ); } } else { if ( is_array( $media_result ) ){ $result = array_merge( $result, $media_result ); } } } //print_r($result); //die; if($content_submitted != "feedback"){ do_action( 'tps_upload_result', $layout, $result ); // Notify the admin via email $this->tps_notify_admin( $result ); } // Handle error and success messages, and redirect $this->tps_handle_result( $result ); exit; } /** * Notify site administrator by email */ function tps_notify_admin( $result = array() ) { // echo "||".$this->tps_generate_html_email_template_ticket_generated_to_user( $result )."||"; //die; //echo "<pre>"; print_r($result); echo "</pre>"; if (($result['success'] ) ){ add_filter( 'wp_mail_content_type', 'tps_email_content_type' ); //echo "notify_admin: ".$this->settings['notify_admin']."<br>"; //echo "notify_ticket_creator: ".$this->settings['notify_ticket_creator']; //die; $blogname = get_option('blogname'); $post_author_username = ""; if(isset($result['data']['post_array']['post_author']) && $result['data']['post_array']['post_author'] != ""){ $post_author_user = get_user_by("id",$result['data']['post_array']['post_author']); $post_author_username = $post_author_user->user_login; } $topic_name = ""; if(isset($result['data']['post_category']) && $result['data']['post_category'] != ""){ $topic_obj = get_term_by( "id", $result['data']['post_category'], "topic", "", ""); $topic_name = $topic_obj->name; } $attachments_str = ""; if(is_array($result['media_names']) && isset($result['media_names']) && sizeof($result['media_names'])){ foreach ($result['media_names'] as $a_id => $a_name) { $attachments_str .= "<a href='".wp_get_attachment_url( $a_id )."' target='_blank'>".$a_name."</a>, "; } $attachments_str = substr($attachments_str, 0, -2); } $ticketid = $result['post_id']; $author_display_name = ""; if(isset($result['data']['post_dispname']) && $result['data']['post_dispname'] != ""){ $author_display_name = $result['data']['post_dispname']; } $author_email = ""; if(isset($result['data']['post_email']) && $result['data']['post_email'] != ""){ $author_email = $result['data']['post_email']; } $ticket_post_title = ""; if(isset($result['data']['post_array']['post_title']) && $result['data']['post_array']['post_title'] != ""){ $ticket_post_title = $result['data']['post_array']['post_title']; } $ticket_content = ""; if(isset($result['data']['post_array']['post_content']) && $result['data']['post_array']['post_content'] != ""){ $ticket_content = $result['data']['post_array']['post_content']; } $ticket_relevanturl = ""; if(isset($result['data']['post_url']) && $result['data']['post_url'] != ""){ $ticket_relevanturl = $result['data']['post_url']; } $ticket_details_pageid = $this->settings['tps_page_ticket_view']; //329; $ticket_url = esc_url( add_query_arg( 'ticketid', $ticketid, get_page_link($ticket_details_pageid)) ); $site_admin_email = !empty( $this->settings['notification_email'] ) && filter_var( $this->settings['notification_email'], FILTER_VALIDATE_EMAIL ) ? $this->settings['notification_email'] : get_option( 'admin_email' ); $replyto_email = !empty( $this->settings['replyto_email'] ) && filter_var( $this->settings['replyto_email'], FILTER_VALIDATE_EMAIL ) ? $this->settings['replyto_email'] : $site_admin_email; $headers = array(); $headers[] = 'Content-Type: text/html; charset=UTF-8'; $headers[] = 'From: '.$blogname.' <'.$site_admin_email.'>' . ""; $headers[] = 'Reply-To: '.$blogname.' <'.$replyto_email.'>' . ""; $placeholders = array( '%BLOGNAME%' => $blogname, '%TICKETID%' => $ticketid, '%NAME%' => $author_display_name, '%USERNAME%' => $post_author_username, '%USEREMAIL%' => $author_email, '%TOPIC%' => $topic_name, '%TITLE%' => $ticket_post_title, '%CONTENT%' => $ticket_content, '%RELEVANTURL%' => $ticket_relevanturl, '%ATTACHMENTS%' => $attachments_str, '%BLOGURL%' => "<a href='" . site_url() . "'>" . site_url() . "</a>", '%TICKETURL%' => "<a href='" . $ticket_url . "'>" . $ticket_url . "</a>", ); // print_r($placeholders); // die; // notify site admin user if ( 'on' == $this->settings['notify_admin'] && isset($result['upload_type']) && $result['upload_type'] == "new_ticket"){ //echo "admin email"; echo "<pre>"; print_r($result); echo "</pre>"; die; $subj = $this->settings['tps_new_ticket_generated_admin_notification_subject']; $subj = html_entity_decode(tps_generic_placeholder_replacer($subj, $placeholders)); $msg = $this->settings['tps_new_ticket_generated_admin_notification_message']; $msg = html_entity_decode(tps_generic_placeholder_replacer($msg, $placeholders)); // $msg = str_replace("<br>", "\n", $msg); // $msg = str_replace("<br\>", "\n", $msg); $to = $site_admin_email; //echo $to."<hr>"; //echo $subj."<hr>"; //echo $msg."<hr>"; //die; wp_mail( $to, $subj, $msg ); } // notify email to ticket user if ( isset($this->settings['notify_ticket_creator']) && 'on' == $this->settings['notify_ticket_creator'] ){ //echo "user"; echo "<pre>"; print_r($result); echo "</pre>";die; $replyabove = '<div style="font-size:13px;color:#aaaaaa;clear:both;">'; $replyabove .= $this->settings['tps_new_ticket_generated_user_notification_replyabove']. $replyabove .= '</div><div style="width:100%;height:1px;background:#eeeeee;display:block;"></div><br>'; $subj = $this->settings['tps_new_ticket_generated_user_notification_subject']; $subj = html_entity_decode(tps_generic_placeholder_replacer($subj, $placeholders))." [".$ticketid."]"; //$headers[] = //$headers = 'From: My Name <myname@example.com>' . "\r\n"; if ( isset($result['data']['post_email']) && is_email(trim($result['data']['post_email'])) && isset($result['upload_type']) && $result['upload_type'] == "new_ticket"){ // TODO: It'd be nice to add the list of upload files $to = trim($result['data']['post_email']); //$subj = __( 'Your New support request was generated', 'tpsupport' ); $msg = $this->settings['tps_new_ticket_generated_user_notification_message']; $msg = html_entity_decode(tps_generic_placeholder_replacer($msg, $placeholders)); $msg = $replyabove."<br>".$msg; //$msg = str_replace("<br>", "\n", $msg); // $msg = str_replace("<br\>", "\n", $msg); //echo $to."<hr>"; //echo $subj."<hr>"; //echo $msg."<hr>"; //die; wp_mail( $to, $subj, $msg, $headers ); //echo "user email: ".$to.$subj; die; //die; } if ( isset($result['upload_type']) && $result['upload_type'] == "ticket_comment" ){ //echo "comment notify to ticket owner"; $post_email = get_post_meta($result['post_id'],'tps_email',true); if(is_email(trim($post_email))){ // TODO: It'd be nice to add the list of upload files $to = trim($post_email); $comment_author_user = get_user_by("id",$result['data']['userId']); $comment_author_dispname = $comment_author_user->display_name; $placeholders['%NAME%'] = $comment_author_dispname; $placeholders['%CONTENT%'] = $result['data']['content']; $msg = $this->settings['tps_new_comment_generated_user_notification_message']; $msg = html_entity_decode(tps_generic_placeholder_replacer($msg, $placeholders)); $msg = $replyabove."<br>".$msg; // $msg = str_replace("<br>", "\n", $msg); // $msg = str_replace("<br\>", "\n", $msg); //$subj = __( 'A New Reply is posted on your support ticket', 'tpsupport' ); //echo $to."<hr>"; //echo $subj."<hr>"; //echo $msg."<hr>"; //die; wp_mail($to, $subj, $msg, $headers ); //echo "user email: ".$to.$subj; die; } } } remove_filter( 'wp_mail_content_type', 'tps_email_content_type' ); //echo "success"; die; } } /** * Get html template * * @since 1.2 * * @param array $result [description] * @return [type] [description] */ function tps_generate_html_email_template( $result = array() ) { global $tps_result; $tps_result = $result; //print_r($result); return $this->tps_email_template($result); /* ob_start(); include_once TPS_ROOT . "/lib/views/html-email.tpl.php"; return ob_get_clean();*/ } /*function tps_generate_html_email_template_ticket_generated_to_user( $result = array() ) { global $tps_result; $tps_result = $result; //return "111 hihi"; //ob_start(); return $this->tps_email_template($result); //echo $email_template; //return ob_get_clean(); //print_r($result); }*/ /** * Process response from upload logic * * @since 0.4 */ function tps_handle_result( $result = array() ) { // Redirect to referrer if repsonse is malformed if ( empty( $result ) || !is_array( $result ) ) { wp_safe_redirect( wp_get_referer() ); return; } // Either redirect to success page if it's set and valid // Or to referrer $url = isset( $_POST['success_page'] ) && filter_var( $_POST['success_page'], FILTER_VALIDATE_URL ) ? $_POST['success_page'] : wp_get_referer(); // $query_args will hold everything that's needed for displaying notices to user $query_args = array(); // Account for successful uploads if ( isset( $result['success'] ) && $result['success'] ) { // If it's a post if ( isset( $result['post_id'] ) ) $query_args['response'] = 'tps-sent'; //'tps-post-sent'; // If it's media uploads if ( isset( $result['media_ids'] ) && !isset( $result['post_id'] ) ) $query_args['response'] = 'tps-sent'; } if($result['upload_type'] == "ticket_comment"){ $query_args['response'] .= "-comment"; } else if($result['upload_type'] == "feedback"){ $query_args['response'] .= "-feedback"; } // Something went wrong, let's indicate it if ( !empty( $result['errors'] ) ) { $query_args['response'] = 'tps-error'; $query_args['errors'] = $result['errors']; } /** * Allow to filter query args before doing the redirect after upload */ $query_args = apply_filters( 'tps_upload_result_query_args', $query_args, $result ); // Perform a safe redirect and exit wp_safe_redirect( add_query_arg( $query_args, $url ) ); exit; } /** * Render various admin template files * * @param string $view file slug * @since 0.4 */ /*function tps_render( $view = '' ) { if ( empty( $view ) ) return; $this->tps_set_global_query_for_tables( $view ); require_once ABSPATH . '/wp-admin/includes/class-wp-list-table.php'; require_once ABSPATH . '/wp-admin/includes/class-wp-posts-list-table.php'; require_once ABSPATH . '/wp-admin/includes/class-wp-media-list-table.php'; require_once TPS_ROOT . '/lib/php/class-front-form-wp-media-list-table.php'; require_once TPS_ROOT . '/lib/php/class-front-form-wp-posts-list-table.php'; $file = "lib/views/manage-ugc-{$view}.tpl.php"; // Supply relative path to validate_file as it fails to validate absolute paths on Windows (due to colon) if ( 0 === validate_file( $file ) && file_exists( TPS_ROOT . '/' . $file ) ) { include_once TPS_ROOT . '/' . $file; } else { wp_die( __( "Couldn't find template file", 'tpsupport' ) ); } }*/ /** * We need to set global $wp_query in order for list tables to work properly * @param string $type (media|posts) */ private function tps_set_global_query_for_tables( $type = 'posts' ) { if ( ! in_array( $type, array( 'posts', 'media' ) ) ) return false; $args = array( 'post_status' => array( 'private' ), 'posts_per_page' => 20, 'paged' => isset( $_GET['paged'] ) ? (int) $_GET['paged'] : 1, ); // Tweak query arguments (set proper post type and post status) switch( $type ) { case 'posts': $args['post_type'] = isset( $_GET['post_type'] ) && $this->tps_is_allowed_post_type( $_GET['post_type'] ) ? sanitize_key( $_GET['post_type'] ) : 'post'; break; case 'media': $args['post_type'] = 'attachment'; break; } query_posts( $args ); } /** * Is post type allowed UGC post type? * @param string $post_type to check * @return boolean */ function tps_is_allowed_post_type( $post_type = 'post' ) { $enabled_post_types = array('tickets'); return in_array( $post_type, $enabled_post_types, true ); //return in_array( $post_type, $this->settings['enabled_post_types'], true ); } /** * Display media list table * * @return [type] [description] */ /* function tps_admin_list() { $this->tps_render( 'media' ); }*/ /** * Display posts/custom post types table * * @return [type] [description] */ /*function tps_admin_posts_list() { $this->tps_render( 'posts' ); }*/ /** * Add submenu items */ function tps_add_menu_items() { // add_media_page( __( 'Manage UGC', 'tpsupport' ), __( 'Manage UGC', 'tpsupport' ), $this->manage_permissions, 'manage_front_form', array( $this, 'tps_admin_list' ) ); $enabled_post_types = array('tickets'); foreach ( (array) $enabled_post_types as $cpt ) { if ( $cpt == 'post' ) { // add_posts_page( __( 'Manage UGC Posts', 'tpsupport' ), __( 'Manage UGC', 'tpsupport' ), $this->manage_permissions, 'manage_front_form_posts', array( $this, 'tps_admin_posts_list' ) ); continue; } //add_submenu_page( "edit.php?post_type={$cpt}", __( 'Manage UGC Posts', 'tpsupport' ), __( 'Manage UGC', 'tpsupport' ), $this->manage_permissions, "manage_front_form_{$cpt}s", array( $this, 'tps_admin_posts_list' ) ); } } /** * Approve a media file * * @return [type] [description] */ function tps_approve_media() { // Check permissions, attachment ID, and nonce if ( false === $this->tps_check_perms_and_nonce() || 0 === (int) $_GET['id'] ) { wp_safe_redirect( get_admin_url( null, 'upload.php?page=manage_front_form&error=id_or_perm' ) ); exit; } $post = get_post( $_GET['id'] ); if ( is_object( $post ) && $post->post_status == 'private' ) { $post->post_status = 'inherit'; wp_update_post( $post ); do_action( 'tps_media_approved', $post ); $this->tps_update_gallery_shortcode( $post->post_parent, $post->ID ); wp_safe_redirect( get_admin_url( null, 'upload.php?page=manage_front_form&approved=1' ) ); exit; } wp_safe_redirect( get_admin_url( null, 'upload.php?page=manage_front_form' ) ); exit; } /** * TODO: refactor in 0.6 * * @return [type] [description] */ function tps_approve_post() { // check for permissions and id $url = get_admin_url( null, 'edit.php?page=manage_front_form_posts&error=id_or_perm' ); if ( !current_user_can( $this->manage_permissions ) || intval( $_GET['id'] ) === 0 ) { wp_safe_redirect( $url ); exit; } $post = get_post( $_GET['id'] ); if ( is_object( $post ) ) { $post->post_status = 'publish'; wp_update_post( $post ); do_action( 'tps_post_approved', $post ); // Check if there's any UGC attachments $attachments = get_children( 'post_type=attachment&post_parent=' . $post->ID ); foreach ( (array) $attachments as $image_id => $attachment ) { $attachment->post_status = "inherit"; wp_update_post( $attachment ); } // Override query args $qa = array( 'page' => "manage_front_form_{$post->post_type}s", 'approved' => 1, 'post_type' => $post->post_type != 'post' ? $post->post_type : '', ); $url = add_query_arg( $qa, get_admin_url( null, "edit.php" ) ); } wp_safe_redirect( $url ); exit; } /** * Delete post and redirect to referrer * * @return [type] [description] */ function tps_delete_post() { if ( $this->tps_check_perms_and_nonce() && 0 !== (int) $_GET['id'] ) { if ( wp_delete_post( (int) $_GET['id'], true ) ) $args['deleted'] = 1; } wp_safe_redirect( add_query_arg( $args, wp_get_referer() ) ); exit; } /** * Handles security checks * * @return bool */ function tps_check_perms_and_nonce() { return current_user_can( $this->manage_permissions ) && wp_verify_nonce( $_REQUEST['tps_nonce'], TPS_NONCE ); } /** * Shortcode callback for inner content of [tps-new-ticket-form] shortcode * * @param array $atts shortcode attributes * @param unknown $content not used * @param string $tag */ function tps_shortcode_content_parser( $atts, $content = null, $tag ) { $atts = shortcode_atts( array( 'id' => isset( $atts['name'] ) ? 'ugc-input-' . sanitize_key( $atts['name'] ) : '' , 'name' => '', 'description' => '', 'help' => '', 'value' => '', 'type' => '', 'class' => '', 'multiple' => false, 'required' => false, 'aria-required' => false, 'values' => '', 'wysiwyg_enabled' => false, 'role' => 'meta', 'minlength' => '', 'maxlength' => '', ), $atts ); extract( $atts ); $role = in_array( $role, array( 'meta', 'title', 'description', 'author', 'internal', 'content' ) ) ? $role : 'meta'; $name = sanitize_text_field( $name ); // Add the field to fields map $this->form_fields[$role][] = $name; // Render the element if render callback is available $callback = array( $this, "_tps_render_{$tag}" ); if ( is_callable( $callback ) ) return call_user_func( $callback, $atts ); } /** * Input element callback * * @param array shortcode attributes * @return string formatted html element */ function _tps_render_input( $atts ) { extract( $atts ); // Workaround for HTML5 multiple attribute if ( (bool) $multiple === false ) unset( $atts['multiple'] ); // Allow multiple file upload by default. // To do so, we need to add array notation to name field: [] if ( !strpos( $name, '[]' ) && $type == 'file' ) $name = 'files' . '[]'; $input = $this->html->input( $type, $name, $value, $atts ); // No need for wrappers or labels for hidden input if ( $type == 'hidden' ) return $input; $label = $this->html->element( 'label', $description , array( 'for' => $id ), false ); $help = isset( $help ) && $help ? $this->html->element( 'p', sanitize_text_field( $help ), array( 'class' => 'ugc-help' ) ) : ''; return $this->html->element( 'div', $label . $input . $help, array( 'class' => 'ugc-input-wrapper' ), false ); } /** * Textarea element callback * * @param array shortcode attributes * @return string formatted html elemen */ function _tps_render_textarea( $atts ) { extract( $atts ); $help = isset( $help ) && $help ? $this->html->element( 'p', sanitize_text_field( $help ), array( 'class' => 'ugc-help' ) ) : ''; $label = $this->html->element( 'label', $description , array( 'for' => $id ), false ); // Render WYSIWYG textarea if ( ( isset( $this->settings['wysiwyg_enabled'] ) && 'on' == $this->settings['wysiwyg_enabled'] ) || $wysiwyg_enabled == true ) { ob_start(); wp_editor( '', $id, array( 'textarea_name' => $name, 'media_buttons' => false, 'teeny' => true, 'quicktags' => false ) ); $tiny = ob_get_clean(); return $this->html->element( 'div', $label . $tiny . $help, array( 'class' => 'ugc-input-wrapper' ), false ) ; } $element = $this->html->element( 'textarea', '', array( 'name' => $name, 'id' => $id, 'class' => $class, 'minlength' => $minlength, 'maxlength' => $maxlength, 'required' => $required ) ); // Render plain textarea $label = $this->html->element( 'label', $description, array( 'for' => $id ), false ); return $this->html->element( 'div', $label . $element . $help, array( 'class' => 'ugc-input-wrapper' ), false ); } /** * Checkboxes element callback * * @param array shortcode attributes * @return [type] [description] */ function _tps_render_checkboxes( $atts ) { extract( $atts ); $values = explode( ',', $values ); $options = ''; $help = isset( $help ) && $help ? $this->html->element( 'p', sanitize_text_field( $help ), array( 'class' => 'ugc-help' ) ) : ''; // Making sure we're having array of values for checkboxes if ( false === stristr( '[]', $name ) ) $name = $name . '[]'; //Build options for the list foreach ( $values as $option ) { $kv = explode( ":", $option ); $options .= $this->html->_checkbox( $name, isset( $kv[1] ) ? $kv[1] : $kv[0], $kv[0], $atts, array() ); } $description = $label = $this->html->element( 'label', $description, array(), false ); // Render select field $element = $this->html->element( 'div', $description . $help . $options, array( 'class' => 'checkbox-wrapper ' . $class ), false ); return $this->html->element( 'div', $element, array( 'class' => 'ugc-input-wrapper' ), false ); } /** * Radio buttons callback * * @param array shortcode attributes * @return [type] [description] */ function _tps_render_radio( $atts ) { extract( $atts ); $values = explode( ',', $values ); $options = ''; $help = isset( $help ) && $help ? $this->html->element( 'p', sanitize_text_field( $help ), array( 'class' => 'ugc-help' ) ) : ''; //Build options for the list foreach ( $values as $option ) { $kv = explode( ":", $option ); $caption = isset( $kv[1] ) ? $kv[1] : $kv[0]; $options .= $this->html->_radio( $name, isset( $kv[1] ) ? $kv[1] : $kv[0], $kv[0], $atts, array() ); } //Render $label = $this->html->element( 'label', $description , array( 'for' => $id ), false ); return $this->html->element( 'div', $label . $help . $options, array( 'class' => 'ugc-input-wrapper ' . $class ), false ); } /** * Select element callback * * @param array shortcode attributes * @return [type] [description] */ function _tps_render_select( $atts ) { extract( $atts ); $help = isset( $help ) && $help ? $this->html->element( 'p', sanitize_text_field( $help ), array( 'class' => 'ugc-help' ) ) : ''; $options = ''; // for string of values if(isset($values) && !is_array($values)){ $values = explode( ',', $values ); //Build options for the list foreach ( $values as $option ) { $kv = explode( ":", $option ); $caption = isset( $kv[1] ) ? $kv[1] : $kv[0]; $options .= $this->html->element( 'option', $caption, array( 'value' => $kv[0] ), false ); } } else { // for array of option values foreach ( $values as $caption => $option ) { $options .= $this->html->element( 'option', $option, array( 'value' => $caption ), false ); } } //Render select field $label = $this->html->element( 'label', $description , array( 'for' => $id ), false ); $element =$this->html->element( 'select', $options, array( 'name' => $name, 'id' => $id, 'class' => $class ), false ); return $this->html->element( 'div', $label . $help . $element, array( 'class' => 'ugc-input-wrapper' ), false ); } /** * Display the upload post form * * @param array $atts shortcode attributes * @param string $content content that is enclosed in [tps-new-ticket-form][/tps-new-ticket-form] */ function tps_ticket_new_form( $atts, $content = null ) { //echo "<pre>"; print_r($this->settings); echo "</pre>"; //echo "<pre>"; print_r($this->tps_settings_defaults()); echo "</pre>"; //$msg = $this->settings['tps_new_ticket_generated_admin_notification_message']; //echo $msg; static $inst = 0; add_shortcode( 'input', array( $this, 'tps_shortcode_content_parser' ) ); add_shortcode( 'textarea', array( $this, 'tps_shortcode_content_parser' ) ); add_shortcode( 'select', array( $this, 'tps_shortcode_content_parser' ) ); add_shortcode( 'checkboxes', array( $this, 'tps_shortcode_content_parser' ) ); add_shortcode( 'radio', array( $this, 'tps_shortcode_content_parser' ) ); add_shortcode( 'recaptcha', 'tps_get_recaptcha_markup' ); // Reset postdata in case it got polluted somewhere wp_reset_postdata(); $form_post_id = get_the_id(); $followup_id = ""; if(isset($_GET['followup']) && $_GET['followup'] != ""){ $followup_id = $_GET['followup']; } //echo "form_post_id: ". $form_post_id; extract( shortcode_atts( array( 'description' => '', 'title' => __( 'New Ticket', 'tpsupport' ), 'type' => '', 'class' => 'validate', 'success_page' => '', 'form_layout' => 'post_media', 'post_id' => get_the_ID(), 'post_type' => 'tickets', // custom post type slug 'category' => '', 'ticketid' => '', 'status' => '', 'rating' => '', 'followup' => $followup_id, /*'suppress_default_fields' => false,*/ 'append_to_post' => false, ), $atts ) ); if($type == ""){ $type = "newticket"; } if($type == "comment"){ $title = __( 'Add a Reply', 'tpsupport' ); } if($type == "feedback"){ $title = __( 'How would you rate the support you have received?', 'tpsupport' ). " <sup>*</sup>"; } $post_id = (int) $post_id; //echo ": ".$post_id; $this->tps_enqueue_scripts(); $form_layout = 'post_media'; ob_start(); //echo $class; ?> <form action="<?php echo admin_url( 'admin-ajax.php' ) ?>" method="post" class="<?php echo esc_attr( $class )?> tps-form tps-new-ticket-form" enctype="multipart/form-data" id="tps-form-<?php echo $type; ?>"> <div class="ugc-inner-wrapper"> <h3 class='ticket-inner-title'><?php echo $title; ?></h3> <?php if ( !empty( $_GET ) ) $this->tps_display_response_notices( $_GET ); $textarea_desc = __( 'Description for attachment', 'tpsupport' ); $file_desc = __( 'Attachments', 'tpsupport' ); $submit_button = __( 'Submit', 'tpsupport' ); // Set post type for layouts that include uploading of posts // Put it in front of the main form to allow to override it if ( in_array( $form_layout, array( "post_media") ) ) { echo $this->tps_shortcode_content_parser( array( 'type' => 'hidden', 'role' => 'internal', 'name' => 'post_type', 'value' => $post_type ), null, 'input' ); } echo $this->tps_shortcode_content_parser( array( 'type' => 'hidden', 'role' => 'internal', 'name' => 'post_ID', 'value' => $post_id ), null, 'input' ); echo $this->tps_shortcode_content_parser( array( 'type' => 'hidden', 'role' => 'internal', 'name' => 'form_type', 'value' => $type ), null, 'input' ); echo $this->tps_shortcode_content_parser( array( 'type' => 'hidden', 'role' => 'internal', 'name' => 'followup', 'value' => $followup ), null, 'input' ); if ( isset( $category ) && 0 !== (int) $category ) { echo $this->tps_shortcode_content_parser( array( 'type' => 'hidden', 'role' => 'internal', 'name' => 'post_category', 'value' => $category ), null, 'input' ); } if(isset($type) && ($type == "comment" || $type == "feedback")) { echo $this->tps_shortcode_content_parser( array( 'type' => 'hidden', 'role' => 'internal', 'name' => 'ticketid', 'value' => $ticketid ), null, 'input' ); } /*if ( !( isset( $this->settings['suppress_default_fields'] ) && 'on' == $this->settings['suppress_default_fields'] ) && ( $suppress_default_fields === false ) ) {*/ if(isset($type) && $type != "comment" && $type != "feedback"){ // Display topic field echo '<div class="ugc-input-wrapper"><label for="ug_post_category">'.__( 'Select Topic', 'tpsupport' ).' <sup>*</sup></label>'; wp_dropdown_categories(array( 'taxonomy' => 'topic', 'hide_empty' => 0, 'hierarchical' => 1, 'name' => 'post_category', 'id' => 'post_category', 'class' => 'required', 'show_option_all' => 'Pick a Topic', )); echo '</div>'; /*$args = array( 'taxonomy' => 'topic', 'hide_empty' => 0, 'orderby' => 'name', 'order' => 'ASC', 'show_count' => 0, 'use_desc_for_title' => 0, 'title_li' => 0 ); wp_list_categories($args);*/ /*echo $this->tps_shortcode_content_parser( array( 'type' => 'select', 'role' => 'topic', 'name' => 'post_category', 'id' => 'ug_post_category', 'class' => 'required', 'values' => $topics_arr, 'description' => __( 'Select Topic', 'tpsupport' ), ), null, 'select' );*/ } $current_user = wp_get_current_user(); //echo "<pre>"; print_r($current_user); echo "</pre>"; $user_userid = $current_user->ID; $user_login = $current_user->user_login; $user_dispname = $current_user->display_name; $user_email = $current_user->user_email; if(isset($type) && $type != "comment" && $type != "feedback"){ // Display Name field echo $this->tps_shortcode_content_parser( array( 'type' => 'text', 'role' => 'name', 'name' => 'post_dispname', 'id' => 'ug_post_dispname', 'class' => 'required', 'value' => $user_dispname, 'description' => __( 'Your Name', 'tpsupport' )." <sup>*</sup>", ), null, 'input' ); // Display Email field echo $this->tps_shortcode_content_parser( array( 'type' => 'text', 'role' => 'email', 'name' => 'post_email', 'id' => 'ug_post_email', 'class' => 'required email', 'value' => $user_email, 'description' => __( 'Your Email', 'tpsupport' )." <sup>*</sup>", ), null, 'input' ); // Display title field echo $this->tps_shortcode_content_parser( array( 'type' => 'text', 'role' => 'title', 'name' => 'post_title', 'id' => 'ug_post_title', 'class' => 'required', 'description' => __( 'Your Support Ticket Title', 'tpsupport' )."<sup>*</sup>", ), null, 'input' ); } if(isset($type) && $type == "feedback"){ $check = array('good' => '', 'bad' => ''); if(isset($_GET['rate']) && $_GET['rate'] == "good"){ $check['good'] = "checked"; } if(isset($_GET['rate']) && $_GET['rate'] == "bad"){ $check['bad'] = "checked"; } echo "<label for='feedback_rate_good'><input type='radio' name='feedback_rate' value='good' id='feedback_rate_good' ".$check['good'].">Good. I am Satisfied.</label>"; echo "<label for='feedback_rate_bad'><input type='radio' name='feedback_rate' value='bad' id='feedback_rate_bad' ".$check['bad'].">Bad. I am Unsatisfied.</label>"; echo '<label for="feedback_rate" class="error" style="display:none;"></label>'; echo '<br>'; } $desc_star = " <sup>*</sup>"; if($type == "feedback"){ $desc_star = ""; } // post_content echo $this->tps_shortcode_content_parser( array( 'role' => 'content', 'name' => 'post_content', 'id' => 'ug_content', 'class' => 'required', 'description' => __( 'Add Description', 'tpsupport' ).$desc_star, ), null, 'textarea' ); echo '<input type="text" value="post_content_hidden_area_field" style="margin:0px;overflow:hidden;display:inline;visibility:hidden;width:1px;height:1px;" id="post_content_field" name="post_content_field" value="" class="required">'; if(isset($type) && $type != "comment" && $type != "feedback"){ // Display URL field echo $this->tps_shortcode_content_parser( array( 'type' => 'text', 'role' => 'url', 'name' => 'post_url', 'id' => 'ug_post_url', 'class' => '', 'description' => __( 'Relevant URL (if any)', 'tpsupport' ), ), null, 'input' ); } // Parse nested shortcodes if ( $content ){ echo do_shortcode( $content ); } /*if ( !( isset( $this->settings['suppress_default_fields'] ) && 'on' == $this->settings['suppress_default_fields'] ) && ( $suppress_default_fields === false ) ) {*/ if ( in_array( $form_layout, array( 'post_media' ) ) && $type != "feedback") { // Default upload field echo $this->tps_shortcode_content_parser( array( 'type' => 'file', 'role' => 'file', 'name' => 'files', 'id' => 'ug_photo', 'multiple' => 'multiple', 'description' => $file_desc, 'help' => '' ), null, 'input' ); } // if type == comment start if(isset($type) && $type == "comment"){ $user_type = ""; if(is_user_logged_in()){ $current_user = wp_get_current_user(); $userId = $current_user->ID; //print_r($current_user->roles); //agentadmin or administrator or group admin if(isset($current_user->roles) && is_array($current_user->roles)){ if(in_array("client",$current_user->roles)){ $user_type = "client"; } if(in_array("agent",$current_user->roles)){ $user_type = "agent"; $UserProfile = new TPS_User_Profile(); $agent_groups = $UserProfile->tps_get_agent_groups($userId); //print_r($agent_groups); //find if group admin of any group } if(in_array("agentadmin",$current_user->roles)){ $user_type = "agentadmin"; } if(in_array("administrator",$current_user->roles)){ $user_type = "administrator"; } } } // can assign ticket to any other agent, group, groupadmin or agentadmin if(isset($this->settings['allow_agent_frontend_reassign']) && $this->settings['allow_agent_frontend_reassign'] == "on"){ echo $this->tps_shortcode_content_parser( array( 'type' => 'hidden', 'role' => 'internal', 'name' => 'comment_user_type', 'value' => $user_type ), null, 'input' ); //echo "yes"; if($user_type == "administrator" || $user_type == "agentadmin" || is_network_admin()){ // can assign ticket to any other agent, group, groupadmin or agentadmin echo '<div class="ugc-input-wrapper"><label for="ug_post_category">'.__( 'Assign Agent', 'tpsupport' ).'</label>'; tps_select_users_dropdown("","","frontend"); echo '</div>'; } if($user_type == "agent" && isset($agent_groups['admin_of_groups']) && sizeof($agent_groups['admin_of_groups'])){ echo '<div class="ugc-input-wrapper"><label for="ug_post_category">'.__( 'Assign Agent', 'tpsupport' ).'</label>'; //echo "all agents of these groups"; //print_r($agent_groups['admin_of_groups']); $opt_str = ""; foreach ($agent_groups['admin_of_groups'] as $groupadmin_id) { $exp = explode("-", $groupadmin_id); $agid = $exp[1]; $agusers = get_post_meta($agid,"tpsag_allagents",true); //echo "<pre>"; print_r($agusers); echo "</pre>"; if(isset($agusers['agents']) && is_array($agusers['agents'])){ $agentsargs = array( 'role' => 'agent', 'fields' => array('ID','display_name'), 'include' => $agusers['agents'], ); //$agents_arr = array(); $opt_str .= "<optgroup label='".get_the_title( $agid )."'>"; $agents_obj = get_users( $agentsargs ); foreach ($agents_obj as $userobj) { $opt_str .= "<option value='".$userobj->ID."'>".$userobj->display_name."</option>"; //$agents_arr[$userobj->ID] = $userobj->display_name; } $opt_str .= "</optgroup>"; //echo "<pre>"; echo "G agents".$agid; print_r($agents_arr); echo "</pre>"; //$opt_str .= "<option></option>"; } } echo "<select name='assign_agent' id='assign_agent'><option value='0'>".__("Select anyone","tpsupport")."</option>"; echo $opt_str; echo "</select>"; //tps_select_users_dropdown("","","frontend"); echo '</div>'; } } //if($user_type == "client"){ // add mark as solved option if(isset($status) && in_array($status,array("new","open","pending"))){ $mark_solved = ""; echo "<input type='checkbox' value='on' name='mark_as_solved' class='ticket_status'> Mark as Solved"; } else if(isset($status) && $user_type == "client" && in_array($status,array("solved"))){ $mark_solved = ""; echo "<input type='checkbox' value = 'on' name='mark_as_open' class='ticket_status'> Re-Open Ticket"; } else if(isset($status) && $user_type == "agent" && in_array($status,array("solved"))){ $mark_solved = ""; echo "<input type='checkbox' value = 'on' name='mark_as_pending' class='ticket_status'> Re-Open ticket as Pending Status"; } //} } // if type == comment end if(isset($type) && $type != "comment" && $type != "feedback"){ if ( isset($this->settings['enable_recaptcha_protection' ]) && $this->settings['enable_recaptcha_protection' ] == 'on' ){ echo tps_get_recaptcha_markup(); } do_action( 'tps_additional_html', $this ); } if(isset($type) && ( ($type == "comment" && $this->settings['tps_enable_captcha_comment'] == 'on') || ($type == "feedback" && $this->settings['tps_enable_captcha_feedback'] == 'on') || ($type == "newticket" && $this->settings['tps_enable_captcha_ticket'] == 'on') )){ $no1 = mt_rand(10,100); $no2 = mt_rand(10,100); $captcha_title = "".$no1." + ".$no2." = ?"; $captcha_ans = $no1+$no2; ?> <div class="ugc-input-wrapper"> <label class="control-label" id="captchaOperation"><?php echo $captcha_title?> <sup>*</sup></label> <input type="text" placeholder="Answer" class="form-control required" id="tps_captcha" name="tps_captcha" data-ans="<?php echo $captcha_ans; ?>"/> </div> <?php } echo $this->tps_shortcode_content_parser( array( 'type' => 'submit', 'role' => 'internal', 'id' => 'ug_submit_button', 'class' => 'btn', 'value' => $submit_button, ), null, 'input' ); /*} else { do_action( 'tps_additional_html', $this ); }*/ // wp_ajax_ hook echo $this->tps_shortcode_content_parser( array( 'type' => 'hidden', 'role' => 'internal', 'name' => 'action', 'value' => 'upload_ugc' ), null, 'input' ); // Redirect to specified url if valid if ( !empty( $success_page ) && filter_var( $success_page, FILTER_VALIDATE_URL ) ) { echo $this->tps_shortcode_content_parser( array( 'type' => 'hidden', 'role' => 'internal', 'name' => 'success_page', 'value' => $success_page ), null, 'input' ); } // One of supported form layouts echo $this->tps_shortcode_content_parser( array( 'type' => 'hidden', 'role' => 'internal', 'name' => 'form_layout', 'value' => $form_layout ), null, 'input' ); if ( in_array( $form_layout, array( 'post_media' ) ) ) { // One of supported form layouts echo $this->tps_shortcode_content_parser( array( 'type' => 'hidden', 'role' => 'internal', 'name' => 'append_to_post', 'value' => (bool) $append_to_post ), null, 'input' ); } ?> <?php wp_nonce_field( TPS_NONCE, 'tps_nonce' ); ?> <input type="hidden" name="ff" value="<?php echo esc_attr( $this->tps_get_fields_hash() ) ?>" /> <input type="hidden" name="form_post_id" value="<?php echo (int) $form_post_id ?>" /> <div class="clear"></div> </div> </form> <?php $this->tps_maybe_update_fields_map( $form_post_id ); return ob_get_clean(); } /** * Save field map * * @param integer $form_post_id [description] * @return [type] [description] */ private function tps_maybe_update_fields_map( $form_post_id = 0 ) { $form_post_id = (int) $form_post_id ? (int) $form_post_id : get_the_id(); $key = 'tps_form:' . $this->tps_get_fields_hash(); // See if we already have field map saved as meta $fields = get_post_meta( $form_post_id, $key, true ); // If not, update it if ( ! $fields ) { update_post_meta( $form_post_id, $key, $this->form_fields ); } } /** * Get a key for a form (supposed to be unique to not conflict with multiple forms) * * @return string hash */ function tps_get_fields_hash() { $hash = md5( serialize( $this->form_fields ) ); return $hash; } function tps_get_fields_for_form( $post_id, $hash ) { $fields = get_post_meta( $post_id, "tps_form:{$hash}", true ); if ( $fields ) return $fields; return false; } /** * [tps-upload-response] shortcode callback to render upload results notice * * @param [type] $atts [description] * @return [type] [description] */ function tps_form_response_shortcode( $atts ) { $this->tps_enqueue_scripts(); ob_start(); $this->tps_display_response_notices( $_GET ); return ob_get_clean(); } /** * Returns html chunk of single notice * * @since 0.4 * * @param string $message Text of the message * @param string $class Class of container * @return string [description] */ function tps_notice_html( $message, $class ) { if ( empty( $message ) || empty( $class ) ) return; return sprintf( '<div class="ugc-notice alert alert-%1$s %1$s">%2$s</div>', esc_attr( $class ), esc_html( $message ) ); } /** * Handle response notices * * @since 0.4 * * @param array $res [description] * @return [type] [description] */ function tps_display_response_notices( $res = array() ) { if ( empty( $res ) || !is_array( $res ) ) return; array_walk_recursive( $res, 'sanitize_text_field' ); $output = ''; $map = apply_filters( 'tps_response_notices', array( 'tps-sent' => array( 'text' => $this->settings['tps_response_sent'], 'class' => 'success', ), 'tps-sent-comment' => array( 'text' => $this->settings['tps_response_sent_comment'], 'class' => 'success', ), 'tps-sent-feedback' => array( 'text' => $this->settings['tps_response_sent_feedback'], 'class' => 'success', ), 'tps-post-sent' => array( 'text' => $this->settings['tps_response_sent'], 'class' => 'success', ), 'tps-error' => array( 'text' => $this->settings['tps_response_error'], 'class' => 'failure', ), 'tps-spam' => array( 'text' => $this->settings['tps_response_spam'], 'class' => 'failure', ), ) ); if ( isset( $res['response'] ) && isset( $map[ $res['response'] ] ) ) $output .= $this->tps_notice_html( $map[ $res['response'] ]['text'] , $map[ $res['response'] ]['class'] ); if ( !empty( $res['errors' ] ) && 'tps-error' === $res['response'] ) $output .= $this->tps_display_errors( $res['errors' ] ); echo $output; } /** * Handle errors * * @since 0.4 * @param mixed $errors either a comma separated string of error codes or * @return string HTML */ function tps_display_errors( $errors ) { if ( ! $errors ) return; $output = ''; $map = array( 'tps-nonce-failure' => array( 'text' => __( 'Security check failed!', 'tpsupport' ), ), 'tps-disallowed-mime-type' => array( 'text' => __( 'This kind of file is not allowed. Please, try again selecting other file.', 'tpsupport' ), 'format' => $this->is_debug ? '%1$s File name: %2$s MIME-TYPE: %3$s' : '%1$s: %2$s', ), 'tps-disallowed-post-type' => array( 'text' =>__( 'This post type is not allowed.', 'tpsupport' ), ), 'tps-error-media' => array( 'text' =>__( "Couldn't upload the file due to server error", 'tpsupport' ), 'format' => '%1$s - %2$s' ), 'tps-error-post' => array( 'text' =>__( "Couldn't create the post due to server error", 'tpsupport' ), ), 'tps-suspicious-file' => array( 'text' =>__( "The file you tried to upload looks suspicious. This incident will be reported.", 'tpsupport' ), ), ); // Iterate over all the errors that occured for this submission // $error is the key of error, $details - additional information about the error foreach ( (array) $errors as $error => $details ) { if ( ! isset( $map[ $error] ) ) { continue; } // We might have multiple errors of the same type, let's walk through them foreach ( (array) $details as $single_error ) { if ( isset( $map[ $error ]['format'] ) ) { // Prepend the array with error message array_unshift( $single_error, $map[ $error ]['text'] ); $message = vsprintf( $map[ $error ]['format'], $single_error ); } else { $message = $map[ $error ]['text']; } // Append the error to html to display $output .= $this->tps_notice_html( $message, 'failure' ); } } return $output; } /** * Enqueue our assets */ function tps_enqueue_scripts() { $url = plugins_url('/', __FILE__).'../../css/style.min.css'; wp_deregister_style('tps-style-front'); wp_register_style('tps-style-front', $url); wp_enqueue_style('tps-style-front'); /* wp_enqueue_script( 'jquery-validate', TPS_URL . 'js/validate/jquery.validate.min.js', array( 'jquery',) ); wp_enqueue_script( 'jquery-validate-additional', TPS_URL . 'js/validate/additional-methods.min.js', array( 'jquery',) ); */ /*wp_enqueue_style( 'tpsupport', TPS_URL . 'lib/css/front-form.css' );*/ /*wp_enqueue_script( 'jquery-validate', TPS_URL . 'lib/js/validate/jquery.validate.min.js', array( 'jquery', 'underscore' ) ); wp_enqueue_script( 'jquery-validate-additional', TPS_URL . 'lib/js/validate/additional-methods.min.js', array( 'jquery', 'underscore' ) ); wp_enqueue_script( 'tps-underscore-string', TPS_URL . 'lib/js/underscore.string.min.js', array( 'jquery', 'underscore' ) );*/ /*wp_enqueue_script( 'front-form-js', TPS_URL . 'lib/js/front-form.js', array( 'jquery', 'jquery-validate' ) );*/ // Include localization strings for default messages of validation plugin /*if ( $this->lang ) { $relative_path = "lib/js/validate/localization/messages_{$this->lang_short}.js"; $url = TPS_URL . $relative_path; if ( file_exists( TPS_ROOT . "/{$relative_path}" ) ) wp_enqueue_script( 'jquery-validate-messages', $url, array( 'jquery' ) ); }*/ } /** * Enqueue scripts for admin */ function tps_admin_enqueue_scripts() { $screen = get_current_screen(); /** * Don't try to include media script anywhere except "Manage UGC" screen * Otherwise it produces JS errors, potentially breaking some post edit screen features */ if ( $screen && 'media_page_manage_front_form' == $screen->base ) wp_enqueue_script( 'media', array( 'jquery' ) ); } /** * We have to specify ids of approved attachments explicitly in shortcode, * Otherwise, editors have to pick photos after they have already approved them in "Manage UGC" * * This method will search a parent post with a regular expression, and update gallery shortcode with freshly approved attachment ID * * @return post id/wp_error */ function tps_update_gallery_shortcode( $post_id, $attachment_id ) { global $wp_version; // Bail of wp is older than 3.5 if ( version_compare( $wp_version, '3.5', '<' ) ) return; $parent = get_post( $post_id ); /** * Parse the post content: * Before the shortcode, * Before ids, * Ids, * After ids */ preg_match( '#(?<way_before>.*)(?<before>\[gallery(.*))ids=(\'|")(?<ids>[0-9,]*)(\'|")(?<after>.*)#ims', $parent->post_content, $matches ) ; // No gallery shortcode, no problem if ( !isset( $matches['ids'] ) ) return; $content = ''; $if_prepend = apply_filters( 'tps_update_gallery_shortcode_prepend', false ); // Replace ids element with actual string of ids, adding the new att id $matches['ids'] = $if_prepend ? "ids=\"{$attachment_id},{$matches['ids']}\"" : "ids=\"{$matches['ids']},{$attachment_id}\""; $deconstructed = array( 'way_before', 'before', 'ids', 'after' ); // Iterate through match elements and reconstruct the post foreach ( $deconstructed as $match_key ) { if ( isset( $matches[ $match_key ] ) ) { $content .= $matches[ $match_key ]; } } // Update the post $post_to_update = array( 'ID' => (int) $post_id, 'post_content' => $content, ); return wp_update_post( $post_to_update ); } function tps_sanitize_array_element_callback( $el ) { return sanitize_text_field( $el ); } /** * Include Akismet spam protection if enabled in plugin settings */ /*function tps_enable_akismet_protection() { // Maybe include Akismet if ( isset( $this->settings['enable_akismet_protection'] ) && 'on' == $this->settings['enable_akismet_protection'] ) { require_once TPS_ROOT . '/lib/php/akismet.php'; } }*/ /** * Include recaptcha if configured properly * @return [type] [description] */ function tps_enable_recaptcha_protection() { $to_check = array( 'recaptcha_site_key', 'recaptcha_secret_key', 'enable_recaptcha_protection' ); foreach( $to_check as $check ) { if ( !isset( $this->settings[ $check ] ) || ! $this->settings[ $check ] || 'off' === $this->settings[ $check ] ) return false; } require_once TPS_ROOT . '/lib/php/recaptcha.php'; } public function tps_get_current_time($type,$timestamp = ''){ $format = 'F d, Y H:i:s'; $offset = get_option( 'gmt_offset' ) * 60 * 60; $tz_string = get_option('timezone_string'); if($timestamp == ""){ $timestamp = 0; } // echo $timestamp; // echo "|".$offset."|"; // die; if($type == "ts"){ // utc timestamp return current_time( 'timestamp',1); } else if($type == "localts"){ // local timestamp return current_time( 'timestamp',0); } else if($type == "utcdt"){ // utc date and time return current_time( 'mysql',1); } else if($type == "localdt"){ // local date and time return current_time( 'mysql',0); } else if($type == "localdtfromts"){ // local date from timestamp return date($format, $timestamp+$offset); } else if($type == "utcdtfromts"){ // utc date from timestamp return date($format, $timestamp); } else if($type == "YmdHisfromts"){ // utc date from timestamp return date("Y-m-d H:i:s", $timestamp); } else if($type == "localYmdHisfromts"){ // utc date from timestamp return date("Y-m-d H:i:s", $timestamp+$offset); } else if($type == "tz"){ // utc date from timestamp return $tz_string."|".$offset."|".get_option( 'gmt_offset' ); } /* $time = current_time( 'mysql',0); echo $time."<br>"; $time = current_time( 'mysql',1); echo $time."<br>"; $time = current_time( 'timestamp',0); echo $time."<br>"; $time = current_time( 'timestamp',1); echo $time."<br>"; echo get_option('timezone_string')."<br>"; echo get_option('gmt_offset')."<br>----"; $format = 'F d, Y H:i:s'; $time = current_time( 'mysql',1); echo $time."<br>"; $timestamp = current_time( 'timestamp',1); echo $timestamp."<br>"; $gmt = date($format, $timestamp); echo " UTC: ". $gmt."<br>"; $offset = get_option( 'gmt_offset' ) * 60 * 60; $gmt = date($format, $timestamp+$offset); echo " Local UTC: ". $gmt; return $gmt; */ } function tps_email_template($result){ //return "222"; global $tps_result; //print_r($tps_result); $str = ''; $str .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0"/> <title>User submitted content on </title> <style type="text/css"> #outlook a {padding:0;} .ExternalClass {width:100%;} .ExternalClass, .ExternalClass p, .ExternalClass span, .ExternalClass font, .ExternalClass td, .ExternalClass div {line-height: 100%;} table td {border-collapse: collapse;} table {border-collapse: collapse; mso-table-lspace:0pt; mso-table-rspace:0pt; } img {display: block; outline: none; text-decoration: none; -ms-interpolation-mode: bicubic;} a img {border: none;} a.phone {text-decoration: none; color: #000001 !important; pointer-events: auto; cursor: default;} span {font-size: 13px; line-height: 17px; font-family: monospace; color: #000001;} </style> <!--[if gte mso 9]> <style> </style> <![endif]--> </head> <body style="width:100%; margin:0; padding:0; -webkit-text-size-adjust:100%; -ms-text-size-adjust:100%;"> <!-- body wrapper --> <table cellpadding="0" cellspacing="0" border="0" style="margin:0; padding:0; width:100%; line-height: 100% !important;"> <tr> <td valign="top"> <!-- edge wrapper --> <table cellpadding="0" cellspacing="0" border="0" align="center" width="600" style="background: #efefef;"> <tr> <td valign="top"> <!-- content wrapper --> <table cellpadding="0" cellspacing="0" border="0" align="center" width="560" style="background: #efefef;"> <tr> <td valign="top" style="vertical-align: top;"> <table cellpadding="0" cellspacing="0" border="0" align="center"> <tr> <td valign="top" style="vertical-align: top;"> <p>'; $str .= wp_kses_post( $this->settings['admin_notification_text'] ); $str .= '</p> </td> </tr> </table>'; if ( isset( $tps_result['post_id'] ) && $tps_result['post_id'] ) { $obj = get_post( $tps_result['post_id'] ); $email_content = $obj->post_content; if(isset($result['upload_type']) && $result['upload_type'] == "ticket_comment"){ $email_content = $result['data']['content']; } $str .='<table cellpadding="0" cellspacing="0" border="0" align="center"> <tr> <td valign="top" style="vertical-align: top;"> <h2>Submitted Text</h2> </td> </tr> </table> <table cellpadding="0" cellspacing="0" border="0" align="center"> <tr> <td valign="top" style="vertical-align: top;"> <h3>'.esc_html( $obj->post_title ).'</h3>'.wp_kses_post( wpautop( $email_content ) ).'</td> </tr> </table>'; } if(isset($result['upload_type']) && $result['upload_type'] == "ticket_comment"){ // comment media attachments if ( isset( $tps_result['media_ids'] ) && $tps_result['media_ids'] ){ $str .= '<table cellpadding="0" cellspacing="0" border="0" align="center"> <tr> <td valign="top" style="vertical-align: top;"> <h2>Submitted Images</h2> </td> </tr> </table>'; foreach( $result['data']['attachments'] as $media_id ){ $type = get_post_mime_type( $media_id ); if ( ! $type || ! stristr( $type, 'image' ) ) continue; $obj = get_post( $media_id ); $str .= '<table cellpadding="0" cellspacing="0" border="0" align="center"> <tr> <td valign="top" style="vertical-align: top;">'. wp_get_attachment_image( $media_id, 'large' ). '<p>'.esc_html( $obj->post_title ).'</p> '.wp_kses_post( wpautop( $obj->post_content ) ).' </td> </tr> </table>'; } } } else { // post media attachments if ( isset( $tps_result['media_ids'] ) && $tps_result['media_ids'] ){ $str .= '<table cellpadding="0" cellspacing="0" border="0" align="center"> <tr> <td valign="top" style="vertical-align: top;"> <h2>Submitted Images</h2> </td> </tr> </table>'; foreach( $tps_result['media_ids'] as $media_id ){ $type = get_post_mime_type( $media_id ); if ( ! $type || ! stristr( $type, 'image' ) ) continue; $obj = get_post( $media_id ); $str .= '<table cellpadding="0" cellspacing="0" border="0" align="center"> <tr> <td valign="top" style="vertical-align: top;">'. wp_get_attachment_image( $media_id, 'large' ). '<p>'.esc_html( $obj->post_title ).'</p> '.wp_kses_post( wpautop( $obj->post_content ) ).' </td> </tr> </table>'; } } // end if } // end else $str .='<table cellpadding="0" cellspacing="0" border="0" align="center"> <tr height="30"> <td valign="top" style="vertical-align: top; background: #efefef;" width="600" > </td> </tr> </table> <!-- --> </td> </tr> </table> <!-- content wrapper --> </td> </tr> </table> <!-- edge wrapper --> </td> </tr> </table> <!-- page wrapper --> </body> </html>'; return $str; } } $GLOBALS['front_form'] = new Front_Form; ?>
Save