| @@ -139,6 +139,9 @@ discard block | ||
| 139 | 139 | return $output; | 
| 140 | 140 | } | 
| 141 | 141 | |
| 142 | + /** | |
| 143 | + * @param string $code | |
| 144 | + */ | |
| 142 | 145 |  	public static function get_xml_messages( $code = null ) { | 
| 143 | 146 |  		if ( is_null( self::$xml_messages ) ) { | 
| 144 | 147 | $xml_default_emails = file_get_contents( WP_PLUGIN_DIR . '/' . WPSHOP_PLUGIN_DIR . '/assets/datas/default_emails.xml' ); | 
| @@ -328,7 +331,11 @@ discard block | ||
| 328 | 331 | |
| 329 | 332 | /** Store a new message | 
| 330 | 333 | * | 
| 331 | - * @return boolean | |
| 334 | + * @param string $email | |
| 335 | + * @param string $title | |
| 336 | + * @param string $message | |
| 337 | + * @param integer $model_id | |
| 338 | + * @return boolean|null | |
| 332 | 339 | */ | 
| 333 | 340 |  	function add_message( $recipient_id = 0, $email, $title, $message, $model_id, $object, $date = null ) { | 
| 334 | 341 | |
| @@ -1,4 +1,4 @@ discard block | ||
| 1 | -<?php if ( ! defined( 'ABSPATH' ) ) { exit; | |
| 1 | +<?php if (!defined('ABSPATH')) { exit; | |
| 2 | 2 | } | 
| 3 | 3 |  class wps_message_ctr { | 
| 4 | 4 | |
| @@ -18,19 +18,19 @@ discard block | ||
| 18 | 18 |  	function __construct() { | 
| 19 | 19 | |
| 20 | 20 | /** Js */ | 
| 21 | - add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); | |
| 21 | +		add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts')); | |
| 22 | 22 | // End if(). | 
| 23 | 23 | $this->template_dir = WPS_MESSAGE_PATH . WPS_MESSAGE_DIR . '/templates/'; | 
| 24 | 24 | // WP General actions | 
| 25 | - add_action( 'admin_init', array( $this, 'wps_messages_init_actions' ) ); | |
| 26 | - add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) ); | |
| 27 | - add_action( 'manage_' . WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE . '_posts_custom_column', array( $this, 'messages_custom_columns' ) ); | |
| 28 | - add_filter( 'manage_edit-' . WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE . '_columns', array( $this, 'messages_edit_columns' ) ); | |
| 25 | +		add_action('admin_init', array($this, 'wps_messages_init_actions')); | |
| 26 | +		add_action('add_meta_boxes', array($this, 'add_meta_boxes')); | |
| 27 | +		add_action('manage_' . WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE . '_posts_custom_column', array($this, 'messages_custom_columns')); | |
| 28 | +		add_filter('manage_edit-' . WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE . '_columns', array($this, 'messages_edit_columns')); | |
| 29 | 29 | // Shortcodes | 
| 30 | - add_shortcode( 'wps_message_histo', array( $this, 'display_message_histo_per_customer' ) ); | |
| 31 | - add_shortcode( 'order_customer_personnal_informations', array( $this, 'order_personnal_informations' ) ); | |
| 30 | +		add_shortcode('wps_message_histo', array($this, 'display_message_histo_per_customer')); | |
| 31 | +		add_shortcode('order_customer_personnal_informations', array($this, 'order_personnal_informations')); | |
| 32 | 32 | /** Ajax */ | 
| 33 | - add_action( 'wp_ajax_get_content_message', array( $this, 'get_content_message' ) ); | |
| 33 | +		add_action('wp_ajax_get_content_message', array($this, 'get_content_message')); | |
| 34 | 34 | } | 
| 35 | 35 | |
| 36 | 36 | /** | 
| @@ -40,10 +40,10 @@ discard block | ||
| 40 | 40 | |
| 41 | 41 | /** Css */ | 
| 42 | 42 | add_thickbox(); | 
| 43 | - wp_register_style( 'wpeo-message-css', WPS_MESSAGE_URL . WPS_MESSAGE_DIR . '/assets/css/frontend.css', '', WPS_MESSAGE_VERSION ); | |
| 44 | - wp_enqueue_style( 'wpeo-message-css' ); | |
| 43 | +		wp_register_style('wpeo-message-css', WPS_MESSAGE_URL . WPS_MESSAGE_DIR . '/assets/css/frontend.css', '', WPS_MESSAGE_VERSION); | |
| 44 | +		wp_enqueue_style('wpeo-message-css'); | |
| 45 | 45 | /** My js */ | 
| 46 | - wp_enqueue_script( 'wps-message-js', WPS_MESSAGE_URL . WPS_MESSAGE_DIR . '/assets/js/frontend.js', array( 'jquery', 'thickbox' ), WPS_MESSAGE_VERSION ); | |
| 46 | +		wp_enqueue_script('wps-message-js', WPS_MESSAGE_URL . WPS_MESSAGE_DIR . '/assets/js/frontend.js', array('jquery', 'thickbox'), WPS_MESSAGE_VERSION); | |
| 47 | 47 | } | 
| 48 | 48 | |
| 49 | 49 | /** | 
| @@ -59,23 +59,23 @@ discard block | ||
| 59 | 59 | */ | 
| 60 | 60 |  	function create_message_type() { | 
| 61 | 61 | |
| 62 | - register_post_type( WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE, array( | |
| 62 | + register_post_type(WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE, array( | |
| 63 | 63 | 'labels' => array( | 
| 64 | - 'name' => __( 'Message', 'wpshop' ), | |
| 65 | - 'singular_name' => __( 'message', 'wpshop' ), | |
| 66 | - 'add_new' => __( 'Add message', 'wpshop' ), | |
| 67 | - 'add_new_item' => __( 'Add New message', 'wpshop' ), | |
| 68 | - 'edit' => __( 'Edit', 'wpshop' ), | |
| 69 | - 'edit_item' => __( 'Edit message', 'wpshop' ), | |
| 70 | - 'new_item' => __( 'New message', 'wpshop' ), | |
| 71 | - 'view' => __( 'View message', 'wpshop' ), | |
| 72 | - 'view_item' => __( 'View message', 'wpshop' ), | |
| 73 | - 'search_items' => __( 'Search messages', 'wpshop' ), | |
| 74 | - 'not_found' => __( 'No message found', 'wpshop' ), | |
| 75 | - 'not_found_in_trash' => __( 'No message found in trash', 'wpshop' ), | |
| 64 | +				'name' => __('Message', 'wpshop'), | |
| 65 | +				'singular_name' => __('message', 'wpshop'), | |
| 66 | +				'add_new' => __('Add message', 'wpshop'), | |
| 67 | +				'add_new_item' => __('Add New message', 'wpshop'), | |
| 68 | +				'edit' => __('Edit', 'wpshop'), | |
| 69 | +				'edit_item' => __('Edit message', 'wpshop'), | |
| 70 | +				'new_item' => __('New message', 'wpshop'), | |
| 71 | +				'view' => __('View message', 'wpshop'), | |
| 72 | +				'view_item' => __('View message', 'wpshop'), | |
| 73 | +				'search_items' => __('Search messages', 'wpshop'), | |
| 74 | +				'not_found' => __('No message found', 'wpshop'), | |
| 75 | +				'not_found_in_trash' => __('No message found in trash', 'wpshop'), | |
| 76 | 76 | 'parent-item-colon' => '', | 
| 77 | 77 | ), | 
| 78 | - 'description' => __( 'This is where store messages are stored.', 'wpshop' ), | |
| 78 | +			'description' => __('This is where store messages are stored.', 'wpshop'), | |
| 79 | 79 | 'public' => true, | 
| 80 | 80 | 'show_ui' => true, | 
| 81 | 81 | 'capability_type' => 'post', | 
| @@ -86,9 +86,9 @@ discard block | ||
| 86 | 86 | 'show_in_nav_menus' => false, | 
| 87 | 87 | 'rewrite' => false, | 
| 88 | 88 | 'query_var' => true, | 
| 89 | - 'supports' => array( 'title', 'editor' ), | |
| 89 | +			'supports' => array('title', 'editor'), | |
| 90 | 90 | 'has_archive' => false, | 
| 91 | - ) ); | |
| 91 | + )); | |
| 92 | 92 | } | 
| 93 | 93 | |
| 94 | 94 | /** | 
| @@ -97,10 +97,10 @@ discard block | ||
| 97 | 97 |  	function add_meta_boxes() { | 
| 98 | 98 | |
| 99 | 99 | // Add message sending historic meta box | 
| 100 | - add_meta_box( 'wpshop_message_histo', | |
| 101 | - __( 'Message historic', 'wpshop' ), | |
| 102 | - array( $this, 'message_histo_box' ), | |
| 103 | - WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE, 'normal', 'high' ); | |
| 100 | +		add_meta_box('wpshop_message_histo', | |
| 101 | +			__('Message historic', 'wpshop'), | |
| 102 | + array($this, 'message_histo_box'), | |
| 103 | + WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE, 'normal', 'high'); | |
| 104 | 104 | } | 
| 105 | 105 | |
| 106 | 106 | /** | 
| @@ -109,10 +109,10 @@ discard block | ||
| 109 | 109 | * @param unknown_type $post | 
| 110 | 110 | * @param unknown_type $params | 
| 111 | 111 | */ | 
| 112 | -	function message_histo_box( $post, $params ) { | |
| 112 | +	function message_histo_box($post, $params) { | |
| 113 | 113 | |
| 114 | 114 | $output = '<div id="message_histo_container">'; | 
| 115 | - $output .= $this->get_historic_message_by_type( $post->ID ); | |
| 115 | + $output .= $this->get_historic_message_by_type($post->ID); | |
| 116 | 116 | $output .= '</div>'; | 
| 117 | 117 | echo $output; | 
| 118 | 118 | } | 
| @@ -123,39 +123,39 @@ discard block | ||
| 123 | 123 | * @param integer $message_type_id : Message type ID | 
| 124 | 124 | * @return string | 
| 125 | 125 | */ | 
| 126 | -	function get_historic_message_by_type( $message_type_id ) { | |
| 126 | +	function get_historic_message_by_type($message_type_id) { | |
| 127 | 127 | |
| 128 | 128 | global $wpdb; | 
| 129 | 129 | $output = ''; | 
| 130 | -		if ( ! empty( $message_type_id ) ) { | |
| 130 | +		if (!empty($message_type_id)) { | |
| 131 | 131 | // Recover all sended messages | 
| 132 | 132 | $wps_message_mdl = new wps_message_mdl(); | 
| 133 | - $messages = $wps_message_mdl->get_messages_histo( $message_type_id ); | |
| 133 | + $messages = $wps_message_mdl->get_messages_histo($message_type_id); | |
| 134 | 134 | ob_start(); | 
| 135 | - require( wpshop_tools::get_template_part( WPS_MESSAGE_DIR, $this->template_dir, 'backend', 'message_historic' ) ); | |
| 135 | + require(wpshop_tools::get_template_part(WPS_MESSAGE_DIR, $this->template_dir, 'backend', 'message_historic')); | |
| 136 | 136 | $output .= ob_get_contents(); | 
| 137 | 137 | ob_end_clean(); | 
| 138 | 138 | } | 
| 139 | 139 | return $output; | 
| 140 | 140 | } | 
| 141 | 141 | |
| 142 | -	public static function get_xml_messages( $code = null ) { | |
| 143 | -		if ( is_null( self::$xml_messages ) ) { | |
| 144 | - $xml_default_emails = file_get_contents( WP_PLUGIN_DIR . '/' . WPSHOP_PLUGIN_DIR . '/assets/datas/default_emails.xml' ); | |
| 145 | - $default_emails = new SimpleXMLElement( $xml_default_emails ); | |
| 142 | +	public static function get_xml_messages($code = null) { | |
| 143 | +		if (is_null(self::$xml_messages)) { | |
| 144 | + $xml_default_emails = file_get_contents(WP_PLUGIN_DIR . '/' . WPSHOP_PLUGIN_DIR . '/assets/datas/default_emails.xml'); | |
| 145 | + $default_emails = new SimpleXMLElement($xml_default_emails); | |
| 146 | 146 | self::$xml_messages = array(); | 
| 147 | -			foreach ( $default_emails->xpath( '//emails/email' ) as $email ) { | |
| 148 | - self::$xml_messages[ (string) $email->attributes()->code ] = array( | |
| 149 | - 'shop_type' => (string) $email->attributes()->shop_type, | |
| 150 | - 'object' => (string) $email->subject, | |
| 151 | - 'message' => (string) $email->content, | |
| 147 | +			foreach ($default_emails->xpath('//emails/email') as $email) { | |
| 148 | + self::$xml_messages[(string)$email->attributes()->code] = array( | |
| 149 | + 'shop_type' => (string)$email->attributes()->shop_type, | |
| 150 | + 'object' => (string)$email->subject, | |
| 151 | + 'message' => (string)$email->content, | |
| 152 | 152 | ); | 
| 153 | 153 | } | 
| 154 | 154 | } | 
| 155 | -		if ( is_null( $code ) ) { | |
| 155 | +		if (is_null($code)) { | |
| 156 | 156 | return self::$xml_messages; | 
| 157 | -		} elseif ( isset( self::$xml_messages[ $code ] ) ) { | |
| 158 | - return self::$xml_messages[ $code ]; | |
| 157 | +		} elseif (isset(self::$xml_messages[$code])) { | |
| 158 | + return self::$xml_messages[$code]; | |
| 159 | 159 |  		} else { | 
| 160 | 160 | return false; | 
| 161 | 161 | } | 
| @@ -165,9 +165,9 @@ discard block | ||
| 165 | 165 | */ | 
| 166 | 166 |  	public static function create_default_message() { | 
| 167 | 167 | // Read default emails for options creation | 
| 168 | -		foreach ( self::get_xml_messages() as $code => $email ) { | |
| 169 | -			if ( ( WPSHOP_DEFINED_SHOP_TYPE == $email['shop_type'] ) || ( 'sale' == WPSHOP_DEFINED_SHOP_TYPE ) ) { | |
| 170 | - self::createMessage( $code, $email['object'], $email['message'] ); | |
| 168 | +		foreach (self::get_xml_messages() as $code => $email) { | |
| 169 | +			if ((WPSHOP_DEFINED_SHOP_TYPE == $email['shop_type']) || ('sale' == WPSHOP_DEFINED_SHOP_TYPE)) { | |
| 170 | + self::createMessage($code, $email['object'], $email['message']); | |
| 171 | 171 | } | 
| 172 | 172 | } | 
| 173 | 173 | } | 
| @@ -180,25 +180,25 @@ discard block | ||
| 180 | 180 | * @param string $message : Message content | 
| 181 | 181 | * @return integer message ID | 
| 182 | 182 | */ | 
| 183 | -	public static function createMessage( $code, $object = '', $message = '' ) { | |
| 183 | +	public static function createMessage($code, $object = '', $message = '') { | |
| 184 | 184 | $id = 0; | 
| 185 | - $xml_message = self::get_xml_messages( $code ); | |
| 186 | - $object = empty( $object ) ? $xml_message['object'] : $object; | |
| 187 | - $message = empty( $message ) ? $xml_message['message'] : $message; | |
| 188 | - $message_option = get_option( $code, null ); | |
| 189 | -		if ( empty( $message_option ) || false === get_post_status( $message_option ) ) { | |
| 190 | - $id = post_exists( __( $object , 'wpshop' ), self::customize_message( __( $message, 'wpshop' ) ) ); | |
| 191 | -			if( $id == 0 ) { | |
| 185 | + $xml_message = self::get_xml_messages($code); | |
| 186 | + $object = empty($object) ? $xml_message['object'] : $object; | |
| 187 | + $message = empty($message) ? $xml_message['message'] : $message; | |
| 188 | + $message_option = get_option($code, null); | |
| 189 | +		if (empty($message_option) || false === get_post_status($message_option)) { | |
| 190 | + $id = post_exists(__($object, 'wpshop'), self::customize_message(__($message, 'wpshop'))); | |
| 191 | +			if ($id == 0) { | |
| 192 | 192 | $new_message = array( | 
| 193 | - 'post_title' => __( $object , 'wpshop' ), | |
| 194 | - 'post_content' => self::customize_message( __( $message, 'wpshop' ) ), | |
| 193 | + 'post_title' => __($object, 'wpshop'), | |
| 194 | + 'post_content' => self::customize_message(__($message, 'wpshop')), | |
| 195 | 195 | 'post_status' => 'publish', | 
| 196 | 196 | 'post_author' => 1, | 
| 197 | 197 | 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE, | 
| 198 | 198 | ); | 
| 199 | - $id = wp_insert_post( $new_message ); | |
| 199 | + $id = wp_insert_post($new_message); | |
| 200 | 200 | } | 
| 201 | - update_option( $code, $id ); | |
| 201 | + update_option($code, $id); | |
| 202 | 202 |  		} else { | 
| 203 | 203 | $id = $message_option; | 
| 204 | 204 | } | 
| @@ -211,17 +211,17 @@ discard block | ||
| 211 | 211 | * | 
| 212 | 212 | * @return array | 
| 213 | 213 | */ | 
| 214 | -	function messages_custom_columns( $column ) { | |
| 214 | +	function messages_custom_columns($column) { | |
| 215 | 215 | |
| 216 | 216 | global $post; | 
| 217 | 217 | $metadata = get_post_custom(); | 
| 218 | -		switch ( $column ) { | |
| 218 | +		switch ($column) { | |
| 219 | 219 | case 'extract': | 
| 220 | - echo wp_trim_words( $post->post_content, 55 ); | |
| 220 | + echo wp_trim_words($post->post_content, 55); | |
| 221 | 221 | break; | 
| 222 | 222 | case 'last_dispatch_date': | 
| 223 | -				if ( ! empty( $metadata['wpshop_message_last_dispatch_date'][0] ) ) { | |
| 224 | - echo mysql2date( 'd F Y, H:i:s',$metadata['wpshop_message_last_dispatch_date'][0], true ); | |
| 223 | +				if (!empty($metadata['wpshop_message_last_dispatch_date'][0])) { | |
| 224 | +					echo mysql2date('d F Y, H:i:s', $metadata['wpshop_message_last_dispatch_date'][0], true); | |
| 225 | 225 |  				} else { echo '-'; | 
| 226 | 226 | } | 
| 227 | 227 | break; | 
| @@ -233,14 +233,14 @@ discard block | ||
| 233 | 233 | * | 
| 234 | 234 | * @return array | 
| 235 | 235 | */ | 
| 236 | -	function messages_edit_columns( $columns ) { | |
| 236 | +	function messages_edit_columns($columns) { | |
| 237 | 237 | |
| 238 | 238 | $columns = array( | 
| 239 | 239 | 'cb' => '<input type="checkbox" />', | 
| 240 | - 'title' => __( 'Name', 'wpshop' ), | |
| 241 | - 'extract' => __( 'Extract from the message','wpshop' ), | |
| 242 | - 'date' => __( 'Creation date','wpshop' ), | |
| 243 | - 'last_dispatch_date' => __( 'Last dispatch date','wpshop' ), | |
| 240 | +			'title' => __('Name', 'wpshop'), | |
| 241 | +			'extract' => __('Extract from the message', 'wpshop'), | |
| 242 | +			'date' => __('Creation date', 'wpshop'), | |
| 243 | +			'last_dispatch_date' => __('Last dispatch date', 'wpshop'), | |
| 244 | 244 | ); | 
| 245 | 245 | return $columns; | 
| 246 | 246 | } | 
| @@ -251,17 +251,17 @@ discard block | ||
| 251 | 251 | * @param integer $current | 
| 252 | 252 | * @return string | 
| 253 | 253 | */ | 
| 254 | -	function getMessageListOption( $current = 0 ) { | |
| 254 | +	function getMessageListOption($current = 0) { | |
| 255 | 255 | |
| 256 | - $posts = query_posts( array( | |
| 256 | + $posts = query_posts(array( | |
| 257 | 257 | 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE, | 
| 258 | 258 | 'posts_per_page' => '-1', | 
| 259 | - ) ); | |
| 259 | + )); | |
| 260 | 260 | $options = ''; | 
| 261 | -		if ( ! empty( $posts ) ) { | |
| 262 | - $options = '<option value="0">' . __( 'Select values from list', 'wpshop' ) . '</option>'; | |
| 263 | -			foreach ( $posts as $p ) { | |
| 264 | - $selected = $p->ID == $current ? ' selected="selected"': ''; | |
| 261 | +		if (!empty($posts)) { | |
| 262 | +			$options = '<option value="0">' . __('Select values from list', 'wpshop') . '</option>'; | |
| 263 | +			foreach ($posts as $p) { | |
| 264 | + $selected = $p->ID == $current ? ' selected="selected"' : ''; | |
| 265 | 265 | $options .= '<option value="' . $p->ID . '"' . $selected . '>' . $p->post_title . '</option>'; | 
| 266 | 266 | } | 
| 267 | 267 | } | 
| @@ -276,40 +276,40 @@ discard block | ||
| 276 | 276 | * @param integer $customer_id : ID to identifiate the customer | 
| 277 | 277 | * @return string | 
| 278 | 278 | */ | 
| 279 | -	function display_message_histo_per_customer( $args, $customer_id = '' ) { | |
| 280 | - $customer_id = ( ! empty( $customer_id ) ) ? $customer_id : ( isset( $args['cid'] ) && ! empty( $args['cid'] ) ? $args['cid'] : get_current_user_id() ); | |
| 281 | - $message_id = ( ! empty( $args ) && ! empty( $args['message_id'] ) ) ? $args['message_id'] : ''; | |
| 279 | +	function display_message_histo_per_customer($args, $customer_id = '') { | |
| 280 | + $customer_id = (!empty($customer_id)) ? $customer_id : (isset($args['cid']) && !empty($args['cid']) ? $args['cid'] : get_current_user_id()); | |
| 281 | + $message_id = (!empty($args) && !empty($args['message_id'])) ? $args['message_id'] : ''; | |
| 282 | 282 | $message_elements = ''; | 
| 283 | 283 | $wps_message_mdl = new wps_message_mdl(); | 
| 284 | - $messages_data = $wps_message_mdl->get_messages_histo( $message_id, $customer_id ); | |
| 284 | + $messages_data = $wps_message_mdl->get_messages_histo($message_id, $customer_id); | |
| 285 | 285 | |
| 286 | 286 | $wps_customers_contacts = new WPS_Customers_Contacts(); | 
| 287 | - $contact_list = $wps_customers_contacts->get_customer_contact_list( get_post( $customer_id ) ); | |
| 287 | + $contact_list = $wps_customers_contacts->get_customer_contact_list(get_post($customer_id)); | |
| 288 | 288 | $customer_email_contact_list = array(); | 
| 289 | -		foreach ( $contact_list as $contact ) { | |
| 289 | +		foreach ($contact_list as $contact) { | |
| 290 | 290 | $customer_email_contact_list[] = $contact['user_email']; | 
| 291 | 291 | } | 
| 292 | 292 | |
| 293 | 293 | $messages_histo = array(); | 
| 294 | - foreach ( $messages_data as $meta_id => $messages ) : | |
| 294 | + foreach ($messages_data as $meta_id => $messages) : | |
| 295 | 295 | $i = 0; | 
| 296 | - foreach ( $messages as $message ) : | |
| 297 | - if ( in_array( $message['mess_user_email'], $customer_email_contact_list, true ) ) : | |
| 298 | - $messages_histo[ $message['mess_dispatch_date'][0] ][ $i ]['title'] = $message['mess_title']; | |
| 299 | - $messages_histo[ $message['mess_dispatch_date'][0] ][ $i ]['message'] = $message['mess_message']; | |
| 300 | - $messages_histo[ $message['mess_dispatch_date'][0] ][ $i ]['dates'] = $message['mess_dispatch_date']; | |
| 301 | -					if ( ! empty( $message['mess_object_id'] ) ) { | |
| 302 | - $messages_histo[ $message['mess_dispatch_date'][0] ][ $i ]['object'] = $message['mess_object_id']; | |
| 296 | + foreach ($messages as $message) : | |
| 297 | + if (in_array($message['mess_user_email'], $customer_email_contact_list, true)) : | |
| 298 | + $messages_histo[$message['mess_dispatch_date'][0]][$i]['title'] = $message['mess_title']; | |
| 299 | + $messages_histo[$message['mess_dispatch_date'][0]][$i]['message'] = $message['mess_message']; | |
| 300 | + $messages_histo[$message['mess_dispatch_date'][0]][$i]['dates'] = $message['mess_dispatch_date']; | |
| 301 | +					if (!empty($message['mess_object_id'])) { | |
| 302 | + $messages_histo[$message['mess_dispatch_date'][0]][$i]['object'] = $message['mess_object_id']; | |
| 303 | 303 | } | 
| 304 | 304 | $i++; | 
| 305 | 305 | endif; | 
| 306 | 306 | endforeach; | 
| 307 | 307 | endforeach; | 
| 308 | 308 | |
| 309 | - ksort( $messages_histo ); | |
| 310 | - $messages_histo = array_reverse( $messages_histo ); | |
| 309 | + ksort($messages_histo); | |
| 310 | + $messages_histo = array_reverse($messages_histo); | |
| 311 | 311 | ob_start(); | 
| 312 | - require( wpshop_tools::get_template_part( WPS_MESSAGE_DIR, $this->template_dir, 'frontend', 'customer', 'messages' ) ); | |
| 312 | + require(wpshop_tools::get_template_part(WPS_MESSAGE_DIR, $this->template_dir, 'frontend', 'customer', 'messages')); | |
| 313 | 313 | $output = ob_get_contents(); | 
| 314 | 314 | ob_end_clean(); | 
| 315 | 315 | |
| @@ -322,11 +322,11 @@ discard block | ||
| 322 | 322 | * @param string $message : message content | 
| 323 | 323 | * @return string | 
| 324 | 324 | */ | 
| 325 | -	public static function customize_message( $message ) { | |
| 325 | +	public static function customize_message($message) { | |
| 326 | 326 | |
| 327 | -		if ( ! empty( $message ) ) { | |
| 327 | +		if (!empty($message)) { | |
| 328 | 328 | ob_start(); | 
| 329 | - require( wpshop_tools::get_template_part( WPS_MESSAGE_DIR, WPS_MESSAGE_PATH . WPS_MESSAGE_DIR . '/templates/', 'backend', 'message_html_structure' ) ); | |
| 329 | + require(wpshop_tools::get_template_part(WPS_MESSAGE_DIR, WPS_MESSAGE_PATH . WPS_MESSAGE_DIR . '/templates/', 'backend', 'message_html_structure')); | |
| 330 | 330 | $message = ob_get_contents(); | 
| 331 | 331 | ob_end_clean(); | 
| 332 | 332 | } | 
| @@ -337,15 +337,15 @@ discard block | ||
| 337 | 337 | * | 
| 338 | 338 | * @return boolean | 
| 339 | 339 | */ | 
| 340 | -	function add_message( $recipient_id = 0, $email, $title, $message, $model_id, $object, $date = null ) { | |
| 340 | +	function add_message($recipient_id = 0, $email, $title, $message, $model_id, $object, $date = null) { | |
| 341 | 341 | |
| 342 | - $date = empty( $date ) ? current_time( 'mysql', 0 ) : $date; | |
| 342 | +		$date = empty($date) ? current_time('mysql', 0) : $date; | |
| 343 | 343 | $object_empty = array( | 
| 344 | 344 | 'object_type' => '', | 
| 345 | 345 | 'object_id' => 0, | 
| 346 | 346 | ); | 
| 347 | - $object = array_merge( $object_empty, $object ); | |
| 348 | - $historic = get_post_meta( $recipient_id, '_wpshop_messages_histo_' . $model_id . '_' . substr( $date, 0, 7 ), true ); | |
| 347 | + $object = array_merge($object_empty, $object); | |
| 348 | + $historic = get_post_meta($recipient_id, '_wpshop_messages_histo_' . $model_id . '_' . substr($date, 0, 7), true); | |
| 349 | 349 | $data_to_insert = array( | 
| 350 | 350 | 'mess_user_id' => $recipient_id, | 
| 351 | 351 | 'mess_user_email' => $email, | 
| @@ -353,10 +353,10 @@ discard block | ||
| 353 | 353 | 'mess_object_id' => $object['object_id'], | 
| 354 | 354 | 'mess_title' => $title, | 
| 355 | 355 | 'mess_message' => $message, | 
| 356 | - 'mess_dispatch_date' => array( $date ), | |
| 356 | + 'mess_dispatch_date' => array($date), | |
| 357 | 357 | ); | 
| 358 | 358 | $historic[] = $data_to_insert; | 
| 359 | - update_post_meta( $recipient_id, '_wpshop_messages_histo_' . $model_id . '_' . substr( $date, 0, 7 ), $historic ); | |
| 359 | + update_post_meta($recipient_id, '_wpshop_messages_histo_' . $model_id . '_' . substr($date, 0, 7), $historic); | |
| 360 | 360 | } | 
| 361 | 361 | |
| 362 | 362 | /** | 
| @@ -368,49 +368,49 @@ discard block | ||
| 368 | 368 | * @param boolean $duplicate_message : Duplicate a light message for historic storage | 
| 369 | 369 | * @return string | 
| 370 | 370 | */ | 
| 371 | -	function customMessage( $string, $data, $model_name = '', $duplicate_message = false ) { | |
| 371 | +	function customMessage($string, $data, $model_name = '', $duplicate_message = false) { | |
| 372 | 372 | |
| 373 | 373 | $avant = array(); | 
| 374 | 374 | $apres = array(); | 
| 375 | - $logo_option = get_option( 'wpshop_logo' ); | |
| 375 | +		$logo_option = get_option('wpshop_logo'); | |
| 376 | 376 | |
| 377 | - $data['your_shop_logo'] = ( ! empty( $logo_option ) ) ? '<img src="' . $logo_option . '" alt="' . get_bloginfo( 'name' ) . '" />' : ''; | |
| 377 | +		$data['your_shop_logo'] = (!empty($logo_option)) ? '<img src="' . $logo_option . '" alt="' . get_bloginfo('name') . '" />' : ''; | |
| 378 | 378 | |
| 379 | -		foreach ( $data as $key => $value ) { | |
| 379 | +		foreach ($data as $key => $value) { | |
| 380 | 380 | $avant[] = '[' . $key . ']'; | 
| 381 | -			switch ( $key ) { | |
| 381 | +			switch ($key) { | |
| 382 | 382 | case 'order_content' : | 
| 383 | - $apres[] = ( $duplicate_message ) ? '[order_content]' : $this->order_content_template_for_mail( $data['order_id'] ); | |
| 383 | + $apres[] = ($duplicate_message) ? '[order_content]' : $this->order_content_template_for_mail($data['order_id']); | |
| 384 | 384 | break; | 
| 385 | 385 | case 'order_addresses' : | 
| 386 | - $apres[] = ( $duplicate_message ) ? '[order_addresses]' : $this->order_addresses_template_for_mail( $data['order_id'] ); | |
| 386 | + $apres[] = ($duplicate_message) ? '[order_addresses]' : $this->order_addresses_template_for_mail($data['order_id']); | |
| 387 | 387 | break; | 
| 388 | 388 | |
| 389 | 389 | case 'order_billing_address' : | 
| 390 | - $apres[] = ( $duplicate_message ) ? '[order_billing_address]' : $this->order_addresses_template_for_mail( $data['order_id'], 'billing' ); | |
| 390 | + $apres[] = ($duplicate_message) ? '[order_billing_address]' : $this->order_addresses_template_for_mail($data['order_id'], 'billing'); | |
| 391 | 391 | break; | 
| 392 | 392 | |
| 393 | 393 | case 'order_shipping_address' : | 
| 394 | - $apres[] = ( $duplicate_message ) ? '[order_shipping_address]' : $this->order_addresses_template_for_mail( $data['order_id'], 'shipping' ); | |
| 394 | + $apres[] = ($duplicate_message) ? '[order_shipping_address]' : $this->order_addresses_template_for_mail($data['order_id'], 'shipping'); | |
| 395 | 395 | break; | 
| 396 | 396 | |
| 397 | 397 | case 'order_customer_comments' : | 
| 398 | - $apres[] = ( $duplicate_message ) ? '[order_customer_comments]' : $this->order_customer_comment_template_for_mail( $data['order_id'] ); | |
| 398 | + $apres[] = ($duplicate_message) ? '[order_customer_comments]' : $this->order_customer_comment_template_for_mail($data['order_id']); | |
| 399 | 399 | break; | 
| 400 | 400 | case 'order_personnal_informations' : | 
| 401 | - $apres[] = ( $duplicate_message ) ? '[order_personnal_informations]' : $this->order_personnal_informations(); | |
| 401 | + $apres[] = ($duplicate_message) ? '[order_personnal_informations]' : $this->order_personnal_informations(); | |
| 402 | 402 | break; | 
| 403 | 403 | default : | 
| 404 | 404 | $apres[] = $value; | 
| 405 | 405 | break; | 
| 406 | 406 | } | 
| 407 | 407 | } | 
| 408 | - $string = str_replace( $avant, $apres, $string ); | |
| 408 | + $string = str_replace($avant, $apres, $string); | |
| 409 | 409 | |
| 410 | - $string = apply_filters( 'wps_more_customized_message', $string, $data, $duplicate_message ); | |
| 410 | +		$string = apply_filters('wps_more_customized_message', $string, $data, $duplicate_message); | |
| 411 | 411 | |
| 412 | -		if ( ($model_name != 'WPSHOP_NEW_ORDER_ADMIN_MESSAGE') ) { | |
| 413 | - $string = preg_replace( '/\[(.*)\]/Usi', '', $string ); | |
| 412 | +		if (($model_name != 'WPSHOP_NEW_ORDER_ADMIN_MESSAGE')) { | |
| 413 | +			$string = preg_replace('/\[(.*)\]/Usi', '', $string); | |
| 414 | 414 | } | 
| 415 | 415 | |
| 416 | 416 | return $string; | 
| @@ -425,22 +425,22 @@ discard block | ||
| 425 | 425 | * @param string $object : message object | 
| 426 | 426 | * @param file $attached_file : File to attached to e-mail | 
| 427 | 427 | */ | 
| 428 | -	function wpshop_prepared_email( $email, $model_name, $data = array(), $object = array(), $attached_file = '' ) { | |
| 428 | +	function wpshop_prepared_email($email, $model_name, $data = array(), $object = array(), $attached_file = '') { | |
| 429 | 429 | global $wpdb; | 
| 430 | - $data = apply_filters( 'wps_extra_data_to_send_in_email', $data ); | |
| 431 | - $model_id = get_option( $model_name, 0 ); | |
| 432 | - $query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->posts . ' WHERE ID = %s', $model_id ); | |
| 433 | - $post_message = $wpdb->get_row( $query ); | |
| 430 | +		$data = apply_filters('wps_extra_data_to_send_in_email', $data); | |
| 431 | + $model_id = get_option($model_name, 0); | |
| 432 | +		$query = $wpdb->prepare('SELECT * FROM ' . $wpdb->posts . ' WHERE ID = %s', $model_id); | |
| 433 | + $post_message = $wpdb->get_row($query); | |
| 434 | 434 | $duplicate_message = ''; | 
| 435 | -		if ( ! empty( $post_message ) ) { | |
| 436 | - $title = $this->customMessage( $post_message->post_title, $data, $model_name ); | |
| 437 | - $message = $this->customMessage( $post_message->post_content, $data, $model_name ); | |
| 435 | +		if (!empty($post_message)) { | |
| 436 | + $title = $this->customMessage($post_message->post_title, $data, $model_name); | |
| 437 | + $message = $this->customMessage($post_message->post_content, $data, $model_name); | |
| 438 | 438 | // End if(). | 
| 439 | -			if ( array_key_exists( 'order_content', $data ) || array_key_exists( 'order_addresses', $data ) || array_key_exists( 'order_customer_comments', $data ) ) { | |
| 440 | - $duplicate_message = $this->customMessage( $post_message->post_content, $data, $model_name, true ); | |
| 439 | +			if (array_key_exists('order_content', $data) || array_key_exists('order_addresses', $data) || array_key_exists('order_customer_comments', $data)) { | |
| 440 | + $duplicate_message = $this->customMessage($post_message->post_content, $data, $model_name, true); | |
| 441 | 441 | } | 
| 442 | -			if ( ! empty( $email ) ) { | |
| 443 | - $this->wpshop_email( $email, $title, $message, true, $model_id, $object, $attached_file, $duplicate_message ); | |
| 442 | +			if (!empty($email)) { | |
| 443 | + $this->wpshop_email($email, $title, $message, true, $model_id, $object, $attached_file, $duplicate_message); | |
| 444 | 444 | } | 
| 445 | 445 | } | 
| 446 | 446 | } | 
| @@ -457,37 +457,37 @@ discard block | ||
| 457 | 457 | * @param file $attachments : File to attached to e-mail | 
| 458 | 458 | * @param string $duplicate_message : lighter message to store | 
| 459 | 459 | */ | 
| 460 | -	function wpshop_email( $email, $title, $message, $save = true, $model_id, $object = array(), $attachments = '', $duplicate_message = '' ) { | |
| 460 | +	function wpshop_email($email, $title, $message, $save = true, $model_id, $object = array(), $attachments = '', $duplicate_message = '') { | |
| 461 | 461 | global $wpdb; | 
| 462 | 462 | // Sauvegarde | 
| 463 | -		if ( $save ) { | |
| 464 | - $user = $wpdb->get_row( 'SELECT ID FROM ' . $wpdb->users . ' WHERE user_email="' . $email . '";' ); | |
| 463 | +		if ($save) { | |
| 464 | +			$user = $wpdb->get_row('SELECT ID FROM ' . $wpdb->users . ' WHERE user_email="' . $email . '";'); | |
| 465 | 465 | $user_id = $user ? $user->ID : get_current_user_id(); | 
| 466 | - $query = $wpdb->prepare( 'SELECT ID FROM ' . $wpdb->posts . ' WHERE post_author = %d AND post_type = %s ', $user_id, WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ); | |
| 467 | - $user_post_id = $wpdb->get_var( $query ); | |
| 466 | +			$query = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_author = %d AND post_type = %s ', $user_id, WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); | |
| 467 | + $user_post_id = $wpdb->get_var($query); | |
| 468 | 468 | |
| 469 | -			if ( ! empty( $duplicate_message ) ) { | |
| 470 | - $this->add_message( $user_post_id, $email, $title, $duplicate_message, $model_id, $object ); | |
| 469 | +			if (!empty($duplicate_message)) { | |
| 470 | + $this->add_message($user_post_id, $email, $title, $duplicate_message, $model_id, $object); | |
| 471 | 471 |  			} else { | 
| 472 | - $this->add_message( $user_post_id, $email, $title, $message, $model_id, $object ); | |
| 472 | + $this->add_message($user_post_id, $email, $title, $message, $model_id, $object); | |
| 473 | 473 | } | 
| 474 | 474 | } | 
| 475 | 475 | |
| 476 | - $emails = get_option( 'wpshop_emails', array() ); | |
| 476 | +		$emails = get_option('wpshop_emails', array()); | |
| 477 | 477 | $noreply_email = $emails['noreply_email']; | 
| 478 | 478 | // Split the email to get the name | 
| 479 | - $vers_nom = substr( $email, 0, strpos( $email,'@' ) ); | |
| 479 | + $vers_nom = substr($email, 0, strpos($email, '@')); | |
| 480 | 480 | |
| 481 | 481 | // Headers du mail | 
| 482 | 482 | $headers = "MIME-Version: 1.0\r\n"; | 
| 483 | 483 | $headers .= "Content-type: text/html; charset=UTF-8\r\n"; | 
| 484 | - $headers .= 'From: ' . get_bloginfo( 'name' ) . ' <' . $noreply_email . '>' . "\r\n"; | |
| 484 | +		$headers .= 'From: ' . get_bloginfo('name') . ' <' . $noreply_email . '>' . "\r\n"; | |
| 485 | 485 | |
| 486 | 486 | // Mail en HTML | 
| 487 | - @wp_mail( $email, $title, $message, $headers, $attachments ); | |
| 487 | + @wp_mail($email, $title, $message, $headers, $attachments); | |
| 488 | 488 | |
| 489 | -		if ( ! empty( $attachments ) ) { | |
| 490 | - unlink( $attachments ); | |
| 489 | +		if (!empty($attachments)) { | |
| 490 | + unlink($attachments); | |
| 491 | 491 | } | 
| 492 | 492 | } | 
| 493 | 493 | |
| @@ -497,13 +497,13 @@ discard block | ||
| 497 | 497 | * @param integer $order_id : Order ID | 
| 498 | 498 | * @return string | 
| 499 | 499 | */ | 
| 500 | -	function order_content_template_for_mail( $order_id ) { | |
| 500 | +	function order_content_template_for_mail($order_id) { | |
| 501 | 501 | $message = ''; | 
| 502 | -		if ( ! empty( $order_id ) ) { | |
| 503 | - $currency_code = wpshop_tools::wpshop_get_currency( false ); | |
| 504 | - $orders_infos = get_post_meta( $order_id, '_order_postmeta', true ); | |
| 502 | +		if (!empty($order_id)) { | |
| 503 | + $currency_code = wpshop_tools::wpshop_get_currency(false); | |
| 504 | + $orders_infos = get_post_meta($order_id, '_order_postmeta', true); | |
| 505 | 505 | ob_start(); | 
| 506 | - require( wpshop_tools::get_template_part( WPS_MESSAGE_DIR, $this->template_dir, 'backend/mails', 'order_content_mail_template' ) ); | |
| 506 | + require(wpshop_tools::get_template_part(WPS_MESSAGE_DIR, $this->template_dir, 'backend/mails', 'order_content_mail_template')); | |
| 507 | 507 | $message .= ob_get_contents(); | 
| 508 | 508 | ob_end_clean(); | 
| 509 | 509 | } | 
| @@ -517,44 +517,44 @@ discard block | ||
| 517 | 517 | * @param integer $address_type : Address type ID | 
| 518 | 518 | * @return string | 
| 519 | 519 | */ | 
| 520 | -	function order_addresses_template_for_mail( $order_id, $address_type = '' ) { | |
| 520 | +	function order_addresses_template_for_mail($order_id, $address_type = '') { | |
| 521 | 521 | global $wpdb; | 
| 522 | - $shipping_option = get_option( 'wpshop_shipping_address_choice' ); | |
| 523 | - $display_shipping = ( ! empty( $shipping_option ) && ! empty( $shipping_option['activate'] ) ) ? true : false; | |
| 522 | +		$shipping_option = get_option('wpshop_shipping_address_choice'); | |
| 523 | + $display_shipping = (!empty($shipping_option) && !empty($shipping_option['activate'])) ? true : false; | |
| 524 | 524 | $message = ''; | 
| 525 | -		if ( ! empty( $order_id ) ) { | |
| 526 | - $order_addresses = get_post_meta( $order_id, '_order_info', true ); | |
| 527 | -			if ( ! empty( $order_addresses ) ) { | |
| 528 | -				foreach ( $order_addresses as $key => $order_address ) { | |
| 529 | -					if ( ! empty( $order_address ) && ( empty( $address_type ) || $address_type == $key ) ) { | |
| 530 | - | |
| 531 | -						if ( $key != 'shipping' || ($key == 'shipping' && $display_shipping) ) { | |
| 532 | - $address_type_title = ( ! empty( $key ) && $key == 'billing' ) ? __( 'Billing address', 'wpshop' ) : __( 'Shipping address', 'wpshop' ); | |
| 525 | +		if (!empty($order_id)) { | |
| 526 | + $order_addresses = get_post_meta($order_id, '_order_info', true); | |
| 527 | +			if (!empty($order_addresses)) { | |
| 528 | +				foreach ($order_addresses as $key => $order_address) { | |
| 529 | +					if (!empty($order_address) && (empty($address_type) || $address_type == $key)) { | |
| 530 | + | |
| 531 | +						if ($key != 'shipping' || ($key == 'shipping' && $display_shipping)) { | |
| 532 | +							$address_type_title = (!empty($key) && $key == 'billing') ? __('Billing address', 'wpshop') : __('Shipping address', 'wpshop'); | |
| 533 | 533 | $civility = ''; | 
| 534 | -							if ( ! empty( $order_address['address']['civility'] ) ) { | |
| 535 | - $query = $wpdb->prepare( 'SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $order_address['address']['civility'] ); | |
| 536 | - $civility = $wpdb->get_var( $query ); | |
| 534 | +							if (!empty($order_address['address']['civility'])) { | |
| 535 | +								$query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $order_address['address']['civility']); | |
| 536 | + $civility = $wpdb->get_var($query); | |
| 537 | 537 | } | 
| 538 | 538 | |
| 539 | 539 | // Address informations | 
| 540 | - $customer_last_name = ( ! empty( $order_address['address']['address_last_name'] ) ) ? $order_address['address']['address_last_name'] : ''; | |
| 541 | - $customer_firtsname = ( ! empty( $order_address['address']['address_first_name'] ) ) ? $order_address['address']['address_first_name'] : ''; | |
| 542 | - $customer_company = ( ! empty( $order_address['address']['company'] ) ) ? $order_address['address']['company'] : ''; | |
| 543 | - $customer_address = ( ! empty( $order_address['address']['address'] ) ) ? $order_address['address']['address'] : ''; | |
| 544 | - $customer_zip_code = ( ! empty( $order_address['address']['postcode'] ) ) ? $order_address['address']['postcode'] : ''; | |
| 545 | - $customer_city = ( ! empty( $order_address['address']['city'] ) ) ? $order_address['address']['city'] : ''; | |
| 546 | - $customer_state = ( ! empty( $order_address['address']['state'] ) ) ? $order_address['address']['state'] : ''; | |
| 547 | - $customer_phone = ( ! empty( $order_address['address']['phone'] ) ) ? ' Tel. : ' . $order_address['address']['phone'] : ''; | |
| 540 | + $customer_last_name = (!empty($order_address['address']['address_last_name'])) ? $order_address['address']['address_last_name'] : ''; | |
| 541 | + $customer_firtsname = (!empty($order_address['address']['address_first_name'])) ? $order_address['address']['address_first_name'] : ''; | |
| 542 | + $customer_company = (!empty($order_address['address']['company'])) ? $order_address['address']['company'] : ''; | |
| 543 | + $customer_address = (!empty($order_address['address']['address'])) ? $order_address['address']['address'] : ''; | |
| 544 | + $customer_zip_code = (!empty($order_address['address']['postcode'])) ? $order_address['address']['postcode'] : ''; | |
| 545 | + $customer_city = (!empty($order_address['address']['city'])) ? $order_address['address']['city'] : ''; | |
| 546 | + $customer_state = (!empty($order_address['address']['state'])) ? $order_address['address']['state'] : ''; | |
| 547 | + $customer_phone = (!empty($order_address['address']['phone'])) ? ' Tel. : ' . $order_address['address']['phone'] : ''; | |
| 548 | 548 | $country = ''; | 
| 549 | -							foreach ( unserialize( WPSHOP_COUNTRY_LIST ) as $key => $value ) { | |
| 550 | -								if ( ! empty( $order_address['address']['country'] ) && $key == $order_address['address']['country'] ) { | |
| 549 | +							foreach (unserialize(WPSHOP_COUNTRY_LIST) as $key => $value) { | |
| 550 | +								if (!empty($order_address['address']['country']) && $key == $order_address['address']['country']) { | |
| 551 | 551 | $country = $value; | 
| 552 | 552 | } | 
| 553 | 553 | } | 
| 554 | 554 | $customer_country = $country; | 
| 555 | 555 | |
| 556 | 556 | ob_start(); | 
| 557 | - require( wpshop_tools::get_template_part( WPS_MESSAGE_DIR, $this->template_dir, 'backend/mails', 'order_addresses_template_for_mail' ) ); | |
| 557 | + require(wpshop_tools::get_template_part(WPS_MESSAGE_DIR, $this->template_dir, 'backend/mails', 'order_addresses_template_for_mail')); | |
| 558 | 558 | $message .= ob_get_contents(); | 
| 559 | 559 | ob_end_clean(); | 
| 560 | 560 | } | 
| @@ -571,20 +571,20 @@ discard block | ||
| 571 | 571 | * @param integer $order_id : Order ID | 
| 572 | 572 | * @return string | 
| 573 | 573 | */ | 
| 574 | -	function order_customer_comment_template_for_mail( $order_id ) { | |
| 574 | +	function order_customer_comment_template_for_mail($order_id) { | |
| 575 | 575 | global $wpdb; | 
| 576 | 576 | $message = ''; | 
| 577 | -		if ( ! empty( $order_id ) ) { | |
| 578 | - $query = $wpdb->prepare( 'SELECT post_excerpt FROM ' . $wpdb->posts . ' WHERE ID = %d', $order_id ); | |
| 579 | - $comment = $wpdb->get_var( $query ); | |
| 580 | - $order_infos = get_post_meta( $order_id, '_order_postmeta', true ); | |
| 581 | -			if ( ! empty( $order_infos['order_key'] ) ) { | |
| 582 | - $comment_title = __( 'Comments about the order', 'wpshop' ); | |
| 577 | +		if (!empty($order_id)) { | |
| 578 | +			$query = $wpdb->prepare('SELECT post_excerpt FROM ' . $wpdb->posts . ' WHERE ID = %d', $order_id); | |
| 579 | + $comment = $wpdb->get_var($query); | |
| 580 | + $order_infos = get_post_meta($order_id, '_order_postmeta', true); | |
| 581 | +			if (!empty($order_infos['order_key'])) { | |
| 582 | +				$comment_title = __('Comments about the order', 'wpshop'); | |
| 583 | 583 |  			} else { | 
| 584 | - $comment_title = __( 'Comments about the quotation', 'wpshop' ); | |
| 584 | +				$comment_title = __('Comments about the quotation', 'wpshop'); | |
| 585 | 585 | } | 
| 586 | 586 | ob_start(); | 
| 587 | - require( wpshop_tools::get_template_part( WPS_MESSAGE_DIR, $this->template_dir, 'backend/mails', 'order_email_customer_comments' ) ); | |
| 587 | + require(wpshop_tools::get_template_part(WPS_MESSAGE_DIR, $this->template_dir, 'backend/mails', 'order_email_customer_comments')); | |
| 588 | 588 | $message .= ob_get_contents(); | 
| 589 | 589 | ob_end_clean(); | 
| 590 | 590 | } | 
| @@ -600,15 +600,15 @@ discard block | ||
| 600 | 600 | global $wpdb; | 
| 601 | 601 | $user_id = get_current_user_id(); | 
| 602 | 602 | $message = ''; | 
| 603 | - $customer_entity = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ); | |
| 604 | -		if ( ! empty( $customer_entity ) ) { | |
| 603 | + $customer_entity = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); | |
| 604 | +		if (!empty($customer_entity)) { | |
| 605 | 605 | |
| 606 | - $query = $wpdb->prepare( 'SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d AND status = %s', $customer_entity, 'valid' ); | |
| 607 | - $attributes_sets = $wpdb->get_results( $query ); | |
| 606 | +			$query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d AND status = %s', $customer_entity, 'valid'); | |
| 607 | + $attributes_sets = $wpdb->get_results($query); | |
| 608 | 608 | |
| 609 | -			if ( ! empty( $attributes_sets ) ) { | |
| 609 | +			if (!empty($attributes_sets)) { | |
| 610 | 610 | ob_start(); | 
| 611 | - require( wpshop_tools::get_template_part( WPS_MESSAGE_DIR, $this->template_dir, 'backend/mails', 'order_personnal_informations_template_for_mail' ) ); | |
| 611 | + require(wpshop_tools::get_template_part(WPS_MESSAGE_DIR, $this->template_dir, 'backend/mails', 'order_personnal_informations_template_for_mail')); | |
| 612 | 612 | $message .= ob_get_contents(); | 
| 613 | 613 | ob_end_clean(); | 
| 614 | 614 | } | 
| @@ -621,17 +621,17 @@ discard block | ||
| 621 | 621 | */ | 
| 622 | 622 |  	function wpshop_messages_historic_correction() { | 
| 623 | 623 | global $wpdb; | 
| 624 | - $query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->postmeta . ' WHERE meta_key LIKE %s', '_wpshop_messages_histo_%' ); | |
| 625 | - $messages_histo = $wpdb->get_results( $query ); | |
| 624 | +		$query = $wpdb->prepare('SELECT * FROM ' . $wpdb->postmeta . ' WHERE meta_key LIKE %s', '_wpshop_messages_histo_%'); | |
| 625 | + $messages_histo = $wpdb->get_results($query); | |
| 626 | 626 | |
| 627 | -		foreach ( $messages_histo as $message ) { | |
| 628 | - $query_user = $wpdb->prepare( 'SELECT ID FROM ' . $wpdb->posts . ' WHERE post_author = %d AND post_type = %s', $message->post_id, WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ); | |
| 629 | - $user_post_id = $wpdb->get_var( $query_user ); | |
| 630 | - $wpdb->update( $wpdb->postmeta, array( | |
| 627 | +		foreach ($messages_histo as $message) { | |
| 628 | +			$query_user = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_author = %d AND post_type = %s', $message->post_id, WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); | |
| 629 | + $user_post_id = $wpdb->get_var($query_user); | |
| 630 | + $wpdb->update($wpdb->postmeta, array( | |
| 631 | 631 | 'post_id' => $user_post_id, | 
| 632 | 632 | ), array( | 
| 633 | 633 | 'meta_id' => $message->meta_id, | 
| 634 | - ) ); | |
| 634 | + )); | |
| 635 | 635 | } | 
| 636 | 636 | } | 
| 637 | 637 | |
| @@ -640,20 +640,20 @@ discard block | ||
| 640 | 640 | * Récupères le contenu du message | 
| 641 | 641 | */ | 
| 642 | 642 |  	public function get_content_message() { | 
| 643 | - $_wpnonce = ! empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; | |
| 643 | + $_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; | |
| 644 | 644 | |
| 645 | -		if ( ! wp_verify_nonce( $_wpnonce, 'get_content_message' ) ) { | |
| 645 | +		if (!wp_verify_nonce($_wpnonce, 'get_content_message')) { | |
| 646 | 646 | wp_die(); | 
| 647 | 647 | } | 
| 648 | 648 | |
| 649 | 649 | global $wpdb; | 
| 650 | - $meta_id = (int) $_GET['meta_id']; | |
| 650 | + $meta_id = (int)$_GET['meta_id']; | |
| 651 | 651 | |
| 652 | - $result = $wpdb->get_results( $wpdb->prepare( 'SELECT meta_value FROM ' . $wpdb->postmeta . ' WHERE meta_id=%d', array( ($meta_id) ) ) ); | |
| 653 | - $result = unserialize( $result[0]->meta_value ); | |
| 652 | +		$result = $wpdb->get_results($wpdb->prepare('SELECT meta_value FROM ' . $wpdb->postmeta . ' WHERE meta_id=%d', array(($meta_id)))); | |
| 653 | + $result = unserialize($result[0]->meta_value); | |
| 654 | 654 | $result = $result[0]['mess_message']; | 
| 655 | 655 | |
| 656 | - wp_die( $result ); | |
| 656 | + wp_die($result); | |
| 657 | 657 | } | 
| 658 | 658 | |
| 659 | 659 | } | 
| @@ -1,53 +1,53 @@ discard block | ||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; | |
| 1 | +<?php if (!defined('ABSPATH')) exit; | |
| 2 | 2 |  class wps_account_dashboard_ctr { | 
| 3 | 3 |  	function __construct() { | 
| 4 | -		if ( empty( $_COOKIE ) || empty( $_COOKIE['wps_current_connected_customer'] ) ) { | |
| 5 | - setcookie( 'wps_current_connected_customer', wps_customer_ctr::get_customer_id_by_author_id( get_current_user_id() ), strtotime( '+30 days' ), SITECOOKIEPATH, COOKIE_DOMAIN, is_ssl() ); | |
| 4 | +		if (empty($_COOKIE) || empty($_COOKIE['wps_current_connected_customer'])) { | |
| 5 | +			setcookie('wps_current_connected_customer', wps_customer_ctr::get_customer_id_by_author_id(get_current_user_id()), strtotime('+30 days'), SITECOOKIEPATH, COOKIE_DOMAIN, is_ssl()); | |
| 6 | 6 | } | 
| 7 | 7 | |
| 8 | - add_shortcode( 'wps_account_dashboard', array( $this, 'display_account_dashboard') ); | |
| 8 | +		add_shortcode('wps_account_dashboard', array($this, 'display_account_dashboard')); | |
| 9 | 9 | // add_shortcode( 'wps_messages', array( 'wpshop_messages', 'get_histo_messages_per_customer' ) ); | 
| 10 | - add_shortcode( 'wps_account_last_actions_resume', array($this, 'display_account_last_actions' ) ); | |
| 10 | +		add_shortcode('wps_account_last_actions_resume', array($this, 'display_account_last_actions')); | |
| 11 | 11 | } | 
| 12 | 12 | |
| 13 | -	function import_data( $part ) { | |
| 13 | +	function import_data($part) { | |
| 14 | 14 | $output = ''; | 
| 15 | - $current_customer_id = ! empty( $_COOKIE ) && ! empty( $_COOKIE['wps_current_connected_customer'] ) ? (int) $_COOKIE['wps_current_connected_customer'] : wps_customer_ctr::get_customer_id_by_author_id( get_current_user_id() ); | |
| 15 | + $current_customer_id = !empty($_COOKIE) && !empty($_COOKIE['wps_current_connected_customer']) ? (int)$_COOKIE['wps_current_connected_customer'] : wps_customer_ctr::get_customer_id_by_author_id(get_current_user_id()); | |
| 16 | 16 | |
| 17 | -		switch ( $part ) { | |
| 17 | +		switch ($part) { | |
| 18 | 18 | case 'account' : | 
| 19 | - $output = '<div id="wps_account_informations_container" data-nonce="' . esc_attr( wp_create_nonce( 'wps_account_reload_informations' ) ) . '" >'; | |
| 20 | - $output .= do_shortcode( '[wps_account_informations cid="' . $current_customer_id . '" ]' ); | |
| 19 | +				$output  = '<div id="wps_account_informations_container" data-nonce="' . esc_attr(wp_create_nonce('wps_account_reload_informations')) . '" >'; | |
| 20 | +				$output .= do_shortcode('[wps_account_informations cid="' . $current_customer_id . '" ]'); | |
| 21 | 21 | $output .= '</div>'; | 
| 22 | - $output .= do_shortcode( '[wps_orders_in_customer_account cid="' . $current_customer_id . '" ]' ); | |
| 22 | +				$output .= do_shortcode('[wps_orders_in_customer_account cid="' . $current_customer_id . '" ]'); | |
| 23 | 23 | break; | 
| 24 | 24 | case 'address' : | 
| 25 | - $output .= do_shortcode( '[wps_addresses cid="' . $current_customer_id . '" ]' ); | |
| 25 | +				$output .= do_shortcode('[wps_addresses cid="' . $current_customer_id . '" ]'); | |
| 26 | 26 | break; | 
| 27 | 27 | case 'order' : | 
| 28 | - $output = do_shortcode( '[wps_orders_in_customer_account cid="' . $current_customer_id . '" ]' ); | |
| 28 | +				$output = do_shortcode('[wps_orders_in_customer_account cid="' . $current_customer_id . '" ]'); | |
| 29 | 29 | break; | 
| 30 | 30 | case 'opinion' : | 
| 31 | - $output = do_shortcode( '[wps_opinion cid="' . $current_customer_id . '" ]' ); | |
| 31 | +				$output = do_shortcode('[wps_opinion cid="' . $current_customer_id . '" ]'); | |
| 32 | 32 | break; | 
| 33 | 33 | case 'wishlist' : | 
| 34 | - $output = '<div class="wps-alert-info">' . __( 'This functionnality will be available soon', 'wpshop' ) . '</div>'; | |
| 34 | +				$output = '<div class="wps-alert-info">' . __('This functionnality will be available soon', 'wpshop') . '</div>'; | |
| 35 | 35 | break; | 
| 36 | 36 | case 'coupon' : | 
| 37 | - $output = do_shortcode( '[wps_coupon cid="' . $current_customer_id . '" ]' ); | |
| 37 | +				$output = do_shortcode('[wps_coupon cid="' . $current_customer_id . '" ]'); | |
| 38 | 38 | break; | 
| 39 | 39 | case 'messages' : | 
| 40 | - $output = do_shortcode( '[wps_message_histo cid="' . $current_customer_id . '" ]' ); | |
| 40 | +				$output = do_shortcode('[wps_message_histo cid="' . $current_customer_id . '" ]'); | |
| 41 | 41 | break; | 
| 42 | 42 | default : | 
| 43 | - $output = do_shortcode( '[wps_account_informations cid="' . $current_customer_id . '" ]' ); | |
| 43 | +				$output = do_shortcode('[wps_account_informations cid="' . $current_customer_id . '" ]'); | |
| 44 | 44 | break; | 
| 45 | 45 | } | 
| 46 | 46 | |
| 47 | - $output = apply_filters( 'wps_my_account_extra_panel_content', $output, $part ); | |
| 47 | +		$output = apply_filters('wps_my_account_extra_panel_content', $output, $part); | |
| 48 | 48 | |
| 49 | -		if ( 0 === get_current_user_id() ) { | |
| 50 | - $output = do_shortcode( '[wpshop_login]' ); | |
| 49 | +		if (0 === get_current_user_id()) { | |
| 50 | +			$output = do_shortcode('[wpshop_login]'); | |
| 51 | 51 | } | 
| 52 | 52 | return $output; | 
| 53 | 53 | } | 
| @@ -56,11 +56,11 @@ discard block | ||
| 56 | 56 | * Display Account Dashboard | 
| 57 | 57 | */ | 
| 58 | 58 |  	function display_account_dashboard() { | 
| 59 | - $part = ( !empty($_GET['account_dashboard_part']) ) ? sanitize_title( $_GET['account_dashboard_part'] ) : 'account'; | |
| 60 | - $content = $this->import_data( $part ); | |
| 59 | + $part = (!empty($_GET['account_dashboard_part'])) ? sanitize_title($_GET['account_dashboard_part']) : 'account'; | |
| 60 | + $content = $this->import_data($part); | |
| 61 | 61 | |
| 62 | 62 | ob_start(); | 
| 63 | - require_once( wpshop_tools::get_template_part( WPS_ACCOUNT_DIR, WPS_ACCOUNT_PATH . WPS_ACCOUNT_DIR . "/templates/", "frontend", "account/account-dashboard") ); | |
| 63 | + require_once(wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, WPS_ACCOUNT_PATH . WPS_ACCOUNT_DIR . "/templates/", "frontend", "account/account-dashboard")); | |
| 64 | 64 | $output = ob_get_contents(); | 
| 65 | 65 | ob_end_clean(); | 
| 66 | 66 | |
| @@ -72,26 +72,26 @@ discard block | ||
| 72 | 72 | global $wpdb; | 
| 73 | 73 | $output = ''; | 
| 74 | 74 | $user_id = get_current_user_id(); | 
| 75 | -		if( !empty($user_id) ) { | |
| 76 | - $query = $wpdb->prepare( 'SELECT * FROM ' .$wpdb->posts. ' WHERE post_type = %s AND post_author = %d', WPSHOP_NEWTYPE_IDENTIFIER_ORDER, $user_id ); | |
| 77 | - $orders = $wpdb->get_results( $query ); | |
| 78 | -			if( !empty($orders) ) { | |
| 75 | +		if (!empty($user_id)) { | |
| 76 | +			$query = $wpdb->prepare('SELECT * FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_author = %d', WPSHOP_NEWTYPE_IDENTIFIER_ORDER, $user_id); | |
| 77 | + $orders = $wpdb->get_results($query); | |
| 78 | +			if (!empty($orders)) { | |
| 79 | 79 | $orders_list = ''; | 
| 80 | -				foreach( $orders as $order ) { | |
| 81 | - $order_meta = get_post_meta( $order->ID, '_order_postmeta', true ); | |
| 82 | - $order_number = ( !empty($order_meta) && !empty($order_meta['order_key']) ) ? $order_meta['order_key'] : ''; | |
| 83 | -					$order_date = ( !empty($order_meta) && !empty($order_meta['order_date']) ) ? mysql2date( get_option('date_format'), $order_meta['order_date'], true ) : ''; | |
| 84 | - $order_amount = ( !empty($order_meta) && !empty($order_meta['order_key']) ) ? wpshop_tools::formate_number( $order_meta['order_grand_total'] ).' '.wpshop_tools::wpshop_get_currency( false ) : ''; | |
| 85 | - $order_available_status = unserialize( WPSHOP_ORDER_STATUS ); | |
| 86 | - $order_status = ( !empty($order_meta) && !empty($order_meta['order_status']) ) ? __( $order_available_status[ $order_meta['order_status'] ], 'wpshop' ) : ''; | |
| 80 | +				foreach ($orders as $order) { | |
| 81 | + $order_meta = get_post_meta($order->ID, '_order_postmeta', true); | |
| 82 | + $order_number = (!empty($order_meta) && !empty($order_meta['order_key'])) ? $order_meta['order_key'] : ''; | |
| 83 | +					$order_date = (!empty($order_meta) && !empty($order_meta['order_date'])) ? mysql2date(get_option('date_format'), $order_meta['order_date'], true) : ''; | |
| 84 | + $order_amount = (!empty($order_meta) && !empty($order_meta['order_key'])) ? wpshop_tools::formate_number($order_meta['order_grand_total']) . ' ' . wpshop_tools::wpshop_get_currency(false) : ''; | |
| 85 | + $order_available_status = unserialize(WPSHOP_ORDER_STATUS); | |
| 86 | + $order_status = (!empty($order_meta) && !empty($order_meta['order_status'])) ? __($order_available_status[$order_meta['order_status']], 'wpshop') : ''; | |
| 87 | 87 | ob_start(); | 
| 88 | - require( wpshop_tools::get_template_part( WPS_ACCOUNT_DIR, WPS_ACCOUNT_PATH . WPS_ACCOUNT_DIR . "/templates/", "frontend", "account/account-dashboard-resume-element") ); | |
| 88 | + require(wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, WPS_ACCOUNT_PATH . WPS_ACCOUNT_DIR . "/templates/", "frontend", "account/account-dashboard-resume-element")); | |
| 89 | 89 | $orders_list .= ob_get_contents(); | 
| 90 | 90 | ob_end_clean(); | 
| 91 | 91 | } | 
| 92 | 92 | |
| 93 | 93 | ob_start(); | 
| 94 | - require_once( wpshop_tools::get_template_part( WPS_ACCOUNT_DIR, WPS_ACCOUNT_PATH . WPS_ACCOUNT_DIR . "/templates/","frontend", "account/account-dashboard-resume") ); | |
| 94 | + require_once(wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, WPS_ACCOUNT_PATH . WPS_ACCOUNT_DIR . "/templates/", "frontend", "account/account-dashboard-resume")); | |
| 95 | 95 | $output = ob_get_contents(); | 
| 96 | 96 | ob_end_clean(); | 
| 97 | 97 | } |