| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * WP eCommerce Fancy Notifications | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | add_action( 'wp_enqueue_scripts', array( 'WPSC_Fancy_Notifications', 'enqueue_styles' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | add_action( 'wp_enqueue_scripts', array( 'WPSC_Fancy_Notifications', 'enqueue_scripts' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | add_action( 'wpsc_add_to_cart_button_form_begin', array( 'WPSC_Fancy_Notifications', 'add_fancy_notifications' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | add_action( 'wpsc_theme_footer', array( 'WPSC_Fancy_Notifications', 'fancy_notifications' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | add_filter( 'wpsc_add_to_cart_json_response', array( 'WPSC_Fancy_Notifications', 'wpsc_add_to_cart_json_response' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * WP eCommerce Fancy Notifications Class | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | class WPSC_Fancy_Notifications { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | 	 * Fancy Notifications | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | 	 * Container HTML for fancy notifications. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | 	 * @param   boolean  $return  Return output. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | 	 * @return  string            Output. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 	public static function fancy_notifications( $return = false ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 		static $already_output = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 		if ( $already_output ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 			return ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 		$output = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 		if ( 1 == get_option( 'fancy_notifications' ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 			$output .= '<div id="fancy_notification">'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 			$output .= '   <div id="loading_animation">'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | 			$output .= '      <img id="fancy_notificationimage" title="' . esc_attr__( 'Loading', 'wpsc' ) . '" alt="' . esc_attr__( 'Loading', 'wpsc' ) . '" src="' . esc_url( wpsc_loading_animation_url() ) . '" />' . esc_html__( 'Updating', 'wpsc' ) . '...'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 			$output .= '   </div>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 			$output .= '   <div id="fancy_notification_content"></div>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 			$output .= '</div>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 		$already_output = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 		if ( $return ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 			return $output; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 		echo $output; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 	 * Fancy Notification Content | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 	 * @param   array   $cart_messages  Cart message. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 	 * @return  string                  Fancy notification content. | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 58 |  |  | 	 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  | 	public static function fancy_notification_content( $cart_messages ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  | 		$output = ''; | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  | 		foreach ( (array)$cart_messages as $cart_message ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  | 			$output .= '<span>' . $cart_message . '</span><br />'; | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  | 		} | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  | 		$output .= sprintf( '<a href="%s" class="go_to_checkout">%s</a>', esc_url( get_option( 'shopping_cart_url' ) ), esc_html__( 'Go to Checkout', 'wpsc' ) ); | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  | 		$output .= sprintf( '<a href="#" onclick="jQuery( \'#fancy_notification\' ).css( \'display\', \'none\' ); return false;" class="continue_shopping">%s</a>', esc_html__( 'Continue Shopping', 'wpsc' ) ); | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  | 		return $output; | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 	 * Add To Cart JSON Response | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 	 * Adds 'fancy_notification' content to JSON response. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 	 * @param   array  $json_response  JSON response. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 	 * @return  array                  Updated JSON response. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 	public static function wpsc_add_to_cart_json_response( $json_response ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 		if ( is_numeric( $json_response['product_id'] ) && 1 == get_option( 'fancy_notifications' ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 			$json_response['fancy_notification'] = str_replace( array( "\n", "\r" ), array( '\n', '\r' ), self::fancy_notification_content( $json_response['cart_messages'] ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 		return $json_response; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 	 * Add Fancy Notifications | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 	public static function add_fancy_notifications() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | 		add_action( 'wp_footer', array( 'WPSC_Fancy_Notifications', 'fancy_notifications' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  | 	 * Enqueue Styles | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  | 	public static function enqueue_styles() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | 		wp_enqueue_style( 'wpsc-fancy-notifications', self::plugin_url() . '/css/fancy-notifications.css', false, '1.0' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  | 	 * Enqueue Scripts | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  | 	public static function enqueue_scripts() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  | 		wp_enqueue_script( 'wpsc-fancy-notifications', self::plugin_url() . '/js/fancy-notifications.js', array( 'jquery' ), '1.0' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  | 	 * Plugin URL | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  | 	 * @return  string  URL for fancy notifications directory. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  | 	public static function plugin_url() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  | 		return plugins_url( '', __FILE__ ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 128 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 129 |  |  |  |