|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Shopping Cart widget class |
|
5
|
|
|
* |
|
6
|
|
|
* @since 3.8 |
|
7
|
|
|
* |
|
8
|
|
|
* @todo Check if widget_wp_shopping_cart_init function is still required? |
|
9
|
|
|
*/ |
|
10
|
|
|
class WP_Widget_Shopping_Cart extends WP_Widget { |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Widget Constuctor |
|
14
|
|
|
*/ |
|
15
|
|
|
public function __construct() { |
|
16
|
|
|
|
|
17
|
|
|
$widget_ops = array( |
|
18
|
|
|
'classname' => 'widget_wpsc_shopping_cart', |
|
19
|
|
|
'description' => __( 'Shopping Cart Widget', 'wp-e-commerce' ) |
|
20
|
|
|
); |
|
21
|
|
|
|
|
22
|
|
|
parent::__construct( 'wpsc_shopping_cart', __( '(WPEC) Shopping Cart', 'wp-e-commerce' ), $widget_ops ); |
|
23
|
|
|
|
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Widget Output |
|
28
|
|
|
* |
|
29
|
|
|
* @param $args (array) |
|
30
|
|
|
* @param $instance (array) Widget values. |
|
31
|
|
|
* |
|
32
|
|
|
*/ |
|
33
|
|
|
public function widget( $args, $instance ) { |
|
34
|
|
|
|
|
35
|
|
|
extract( $args ); |
|
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
// Create fancy collapser |
|
38
|
|
|
$fancy_collapser = ''; |
|
39
|
|
|
if ( $instance['show_sliding_cart'] == 1 ) { |
|
40
|
|
|
if ( isset($_SESSION['slider_state']) && is_numeric( $_SESSION['slider_state'] ) ) { |
|
|
|
|
|
|
41
|
|
|
if ( $_SESSION['slider_state'] == 0 ) { |
|
|
|
|
|
|
42
|
|
|
$collapser_image = 'plus.png'; |
|
43
|
|
|
} else { |
|
44
|
|
|
$collapser_image = 'minus.png'; |
|
45
|
|
|
} |
|
46
|
|
|
$fancy_collapser = ' <a href="#" onclick="return shopping_cart_collapser()" id="fancy_collapser_link"><img src="' . WPSC_CORE_IMAGES_URL . '/' . $collapser_image . '" title="" alt="" id="fancy_collapser" /></a>'; |
|
47
|
|
|
} else { |
|
48
|
|
|
if ( ! wpsc_get_customer_meta( 'nzshpcart' ) ) { |
|
49
|
|
|
$collapser_image = 'plus.png'; |
|
50
|
|
|
} else { |
|
51
|
|
|
$collapser_image = 'minus.png'; |
|
52
|
|
|
} |
|
53
|
|
|
$fancy_collapser = ' <a href="#" onclick="return shopping_cart_collapser()" id="fancy_collapser_link"><img src="' . WPSC_CORE_IMAGES_URL . '/' . $collapser_image . '" title="" alt="" id="fancy_collapser" /></a>'; |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
// Start widget output |
|
58
|
|
|
$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Shopping Cart', 'wp-e-commerce' ) : $instance['title'] ); |
|
59
|
|
|
echo $before_widget; |
|
60
|
|
|
|
|
61
|
|
|
if ( $title ) |
|
62
|
|
|
echo $before_title . $title . $fancy_collapser . $after_title; |
|
63
|
|
|
|
|
64
|
|
|
// Set display state |
|
65
|
|
|
$display_state = ''; |
|
66
|
|
|
if ( ( ( isset( $_SESSION['slider_state'] ) && ( $_SESSION['slider_state'] == 0 ) ) || ( wpsc_cart_item_count() < 1 ) ) && ( get_option( 'show_sliding_cart' ) == 1 ) ) |
|
|
|
|
|
|
67
|
|
|
$display_state = 'style="display: none;"'; |
|
68
|
|
|
|
|
69
|
|
|
// Output start, if we are not allowed to save results ( WPSC_DONT_CACHE ) load the cart using ajax |
|
70
|
|
|
$use_object_frame = false; |
|
71
|
|
|
if ( WPSC_PAGE_CACHE_IN_USE ) { |
|
72
|
|
|
echo '<div id="sliding_cart" class="shopping-cart-wrapper">'; |
|
73
|
|
|
if ( ( strstr( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) == false ) && ( $use_object_frame == true ) ) { |
|
|
|
|
|
|
74
|
|
|
?> |
|
75
|
|
|
<object codetype="text/html" type="text/html" data="index.php?wpsc_action=cart_html_page" border="0"> |
|
76
|
|
|
<p><?php _e( 'Loading...', 'wp-e-commerce' ); ?></p> |
|
77
|
|
|
</object> |
|
78
|
|
|
<?php |
|
79
|
|
|
} else { |
|
80
|
|
|
?> |
|
81
|
|
|
<div class="wpsc_cart_loading"><p><?php _e( 'Loading...', 'wp-e-commerce' ); ?></p></div> |
|
82
|
|
|
<?php |
|
83
|
|
|
} |
|
84
|
|
|
echo '</div>'; |
|
85
|
|
|
} else { |
|
86
|
|
|
echo '<div id="sliding_cart" class="shopping-cart-wrapper" ' . $display_state . '>'; |
|
87
|
|
|
include( wpsc_get_template_file_path( 'wpsc-cart_widget.php' ) ); |
|
88
|
|
|
echo '</div>'; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
// End widget output |
|
92
|
|
|
echo $after_widget; |
|
93
|
|
|
|
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Update Widget |
|
98
|
|
|
* |
|
99
|
|
|
* @param $new_instance (array) New widget values. |
|
100
|
|
|
* @param $old_instance (array) Old widget values. |
|
101
|
|
|
* |
|
102
|
|
|
* @return (array) New values. |
|
|
|
|
|
|
103
|
|
|
*/ |
|
104
|
|
|
public function update( $new_instance, $old_instance ) { |
|
105
|
|
|
|
|
106
|
|
|
$instance = $old_instance; |
|
107
|
|
|
$instance['title'] = strip_tags( $new_instance['title'] ); |
|
108
|
|
|
$instance['show_sliding_cart'] = strip_tags( $new_instance['show_sliding_cart'] ); |
|
109
|
|
|
return $instance; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Widget Options Form |
|
114
|
|
|
* |
|
115
|
|
|
* @param $instance (array) Widget values. |
|
116
|
|
|
*/ |
|
117
|
|
|
public function form( $instance ) { |
|
118
|
|
|
global $wpdb; |
|
119
|
|
|
|
|
120
|
|
|
// Defaults |
|
121
|
|
|
$instance = wp_parse_args( (array)$instance, array( |
|
122
|
|
|
'title' => __( 'Shopping Cart', 'wp-e-commerce' ), |
|
123
|
|
|
'show_sliding_cart' => 0 |
|
124
|
|
|
) ); |
|
125
|
|
|
|
|
126
|
|
|
// Values |
|
127
|
|
|
$title = esc_attr( $instance['title'] ); |
|
128
|
|
|
$show_sliding_cart = esc_attr( $instance['show_sliding_cart'] ); |
|
129
|
|
|
if( 1 == $show_sliding_cart) |
|
130
|
|
|
$show_sliding_cart = 'checked="checked"'; |
|
131
|
|
|
else |
|
132
|
|
|
$show_sliding_cart = ''; |
|
133
|
|
|
?> |
|
134
|
|
|
<p> |
|
135
|
|
|
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:', 'wp-e-commerce' ); ?></label> |
|
136
|
|
|
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" /> |
|
137
|
|
|
</p> |
|
138
|
|
|
<input type='hidden' name="<?php echo $this->get_field_name( 'show_sliding_cart' ); ?>" value='0' /> |
|
139
|
|
|
<p> |
|
140
|
|
|
|
|
141
|
|
|
<label for="<?php echo $this->get_field_id('show_sliding_cart'); ?>"><?php _e( 'Use Sliding Cart:', 'wp-e-commerce' ); ?></label> |
|
142
|
|
|
<input id="<?php echo $this->get_field_id( 'show_sliding_cart' ); ?>" name="<?php echo $this->get_field_name( 'show_sliding_cart' ); ?>" type="checkbox" value="1" <?php echo $show_sliding_cart; ?> /> |
|
143
|
|
|
</p> |
|
144
|
|
|
|
|
145
|
|
|
<?php |
|
146
|
|
|
} |
|
147
|
|
|
} |
|
148
|
|
|
add_action( 'widgets_init', create_function( '', 'return register_widget("WP_Widget_Shopping_Cart");' ) ); |
|
|
|
|
|
|
149
|
|
|
|
|
150
|
|
|
?> |
|
151
|
|
|
|