1
|
|
|
<?php if ( !defined( 'ABSPATH' ) ) exit; |
2
|
|
|
/** |
3
|
|
|
* File for installer control class definition |
4
|
|
|
* |
5
|
|
|
* @author Development team <[email protected]> |
6
|
|
|
* @version 1.0 |
7
|
|
|
* |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class for installer control |
12
|
|
|
* |
13
|
|
|
* @author Development team <[email protected]> |
14
|
|
|
* @version 1.0 |
15
|
|
|
* |
16
|
|
|
*/ |
17
|
|
|
class wps_dashboard_ctr { |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Instanciate the module controller |
21
|
|
|
*/ |
22
|
|
|
function __construct() { |
|
|
|
|
23
|
|
|
// add_action( 'admin_enqueue_scripts', array( $this, 'add_scripts'), '', '', true ); |
|
|
|
|
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
function add_scripts() { |
|
|
|
|
27
|
|
|
add_action( 'admin_print_scripts', array($this, 'admin_print_script') ); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
function admin_print_script() { |
|
|
|
|
31
|
|
|
echo "<div id=\"fb-root\"></div> |
32
|
|
|
<script type=\"text/javascript\">(function(d, s, id) { |
33
|
|
|
var js, fjs = d.getElementsByTagName(s)[0]; |
34
|
|
|
if (d.getElementById(id)) return; |
35
|
|
|
js = d.createElement(s); js.id = id; |
36
|
|
|
js.src = \"//connect.facebook.net/fr_FR/sdk.js#xfbml=1&version=v2.0\"; |
37
|
|
|
fjs.parentNode.insertBefore(js, fjs); |
38
|
|
|
}(document, 'script', 'facebook-jssdk'));</script>'"; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* DISPLAY - Display wpshop dashboard |
43
|
|
|
*/ |
44
|
|
|
function display_dashboard() { |
|
|
|
|
45
|
|
|
global $order_status, $wpdb; |
46
|
|
|
|
47
|
|
|
$this->add_dashboard_metaboxes(); |
48
|
|
|
require_once( wpshop_tools::get_template_part( WPS_DASHBOARD_DIR, WPSDASHBOARD_TPL_DIR, "backend", "dashboard" ) ); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
function wpshop_dashboard_orders() { |
|
|
|
|
52
|
|
|
$output = ''; |
|
|
|
|
53
|
|
|
$orders = get_posts( array( 'posts_per_page' => 10, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'post_status' => 'publish', 'orderby' => 'post_date', 'order' => 'DESC') ); |
|
|
|
|
54
|
|
|
// Display orders |
55
|
|
|
ob_start(); |
56
|
|
|
require_once( wpshop_tools::get_template_part( WPS_DASHBOARD_DIR, WPSDASHBOARD_TPL_DIR, "backend", "wps_orders_on_dashboard" ) ); |
57
|
|
|
$output = ob_get_contents(); |
58
|
|
|
ob_end_clean(); |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
return $output; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
View Code Duplication |
function wpshop_rss_feed() { |
|
|
|
|
65
|
|
|
$output = ''; |
66
|
|
|
include_once( ABSPATH . WPINC . '/feed.php' ); |
67
|
|
|
|
68
|
|
|
$rss = fetch_feed( 'http://www.wpshop.fr/feed/' ); |
69
|
|
|
if( ! is_wp_error( $rss ) ){ |
70
|
|
|
$maxitems = $rss->get_item_quantity( 4 ); |
71
|
|
|
$rss_items = $rss->get_items( 0, $maxitems ); |
72
|
|
|
} |
73
|
|
|
else { |
74
|
|
|
$output .= '<p>' . __('WPShop News cannot be loaded', 'wpshop') . '</p>'; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
if ( $maxitems == 0 ) { |
|
|
|
|
78
|
|
|
$output .= '<p>' . __('No WPShop new has been found', 'wpshop') . '</p>'; |
79
|
|
|
} |
80
|
|
|
else { |
81
|
|
|
$output .= '<ul class="recent-orders">'; |
82
|
|
|
foreach ( $rss_items as $item ) { |
|
|
|
|
83
|
|
|
$output .= '<li><a href="' .$item->get_permalink() . '" title="' .$item->get_title(). '" target="_blank">' .$item->get_title(). '</a><br/>'; |
84
|
|
|
$output .= $item->get_content(); |
85
|
|
|
$output .= '</li>'; |
86
|
|
|
} |
87
|
|
|
$output .= '</ul>'; |
88
|
|
|
} |
89
|
|
|
echo $output; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
function wpshop_rss_tutorial_videos() { |
|
|
|
|
93
|
|
|
$ini_get_checking = ini_get( 'allow_url_fopen' ); |
94
|
|
|
|
95
|
|
|
if ( $ini_get_checking != 0 ) { |
96
|
|
|
$content = @file_get_contents( 'http://www.wpshop.fr/rss_video.xml' ); |
97
|
|
|
$videos_rss = ( $content !== false ) ? new SimpleXmlElement( $content ) : null; |
98
|
|
|
if ( !empty($videos_rss) && !empty($videos_rss->channel) ) { |
99
|
|
|
$videos_items = array(); |
100
|
|
|
foreach( $videos_rss->channel->item as $i => $item ) { |
101
|
|
|
$videos_items[] = $item; |
102
|
|
|
} |
103
|
|
|
$rand_element = array_rand( $videos_items ); |
|
|
|
|
104
|
|
|
|
105
|
|
|
ob_start(); |
106
|
|
|
require_once( wpshop_tools::get_template_part( WPS_DASHBOARD_DIR, WPSDASHBOARD_TPL_DIR, "backend", "dashboard", "videos" ) ); |
107
|
|
|
$output = ob_get_contents(); |
108
|
|
|
ob_end_clean(); |
109
|
|
|
} |
110
|
|
|
else { |
111
|
|
|
$output = __('No tutorial videos can be loaded', 'wpshop' ); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
else { |
115
|
|
|
$output = __( 'Your servor doesn\'t allow to open external files', 'wpshop'); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
echo $output; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
View Code Duplication |
function wpshop_dashboard_get_changelog() { |
|
|
|
|
122
|
|
|
$readme_file = fopen( WPSHOP_DIR.'/readme.txt', 'r' ); |
123
|
|
|
if ( $readme_file ) { |
124
|
|
|
$txt = file_get_contents( WPSHOP_DIR.'/readme.txt' ); |
125
|
|
|
$pre_change_log = explode( '== Changelog ==', $txt ); |
126
|
|
|
$versions = explode( '= Version', $pre_change_log[1] ); |
127
|
|
|
|
128
|
|
|
echo $versions[1]; |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Add custom metaboxes to WPShop dashboard |
134
|
|
|
*/ |
135
|
|
|
function add_dashboard_metaboxes() { |
|
|
|
|
136
|
|
|
add_meta_box( 'wps-right-now', '<i class="dashicons dashicons-info"></i>' . esc_html( 'Right Now', 'wpshop' ), array( $this, 'wps_dashboard_right_now' ), 'wpshop_dashboard', 'left_column' ); |
137
|
|
|
add_meta_box( 'wps-dashboard-quick-links', '<i class="dashicons dashicons-performance"></i>' . esc_html( 'Quick Links', 'wpshop' ), array( $this, 'wps_dashboard_quick_links' ), 'wpshop_dashboard', 'left_column' ); |
138
|
|
|
// add_meta_box( 'wps-dashboard-customer-stats', '<i class="dashicons dashicons-chart-pie"></i>' . esc_html( 'Customers stats', 'wpshop' ), array( $this, 'wps_dashboard_customer_stats' ), 'wpshop_dashboard', 'left_column' ); |
|
|
|
|
139
|
|
|
add_meta_box( 'wps-dashboard-export', '<i class="dashicons dashicons-download"></i>' . esc_html( 'CSV export', 'wpshop' ), array( $this, 'wps_dashboard_export' ), 'wpshop_dashboard', 'left_column' ); |
140
|
|
|
add_meta_box( 'wps-dashboard-orders', '<i class="dashicons dashicons-cart"></i>' . esc_html( 'Recent Orders', 'wpshop' ), array( $this, 'wps_dashboard_orders' ), 'wpshop_dashboard', 'left_column' ); |
141
|
|
|
|
142
|
|
|
add_meta_box( 'wps-dashboard-statistics', '<i class="dashicons dashicons-chart-area"></i>' . esc_html( 'Statistics', 'wpshop' ), array( $this, 'wps_dashboard_statistics' ), 'wpshop_dashboard', 'right_column' ); |
143
|
|
|
|
144
|
|
|
add_meta_box( 'wps-dashboard-infos', '<i class="dashicons dashicons-heart"></i>' . esc_html( 'WPShop : WordPress e-commerce', 'wpshop' ), array( $this, 'wps_dashboard_infos' ), 'wpshop_dashboard', 'right_column' ); |
145
|
|
|
add_meta_box( 'wps-dashboard-feed', '<i class="dashicons dashicons-format-status"></i>' . esc_html( 'WPShop News', 'wpshop' ), array( $this, 'wps_dashboard_feed' ), 'wpshop_dashboard', 'right_column' ); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Display metabox with main shop summary |
150
|
|
|
*/ |
151
|
|
|
function wps_dashboard_right_now() { |
|
|
|
|
152
|
|
|
global $wpdb; |
153
|
|
|
require_once( wpshop_tools::get_template_part( WPS_DASHBOARD_DIR, WPSDASHBOARD_TPL_DIR, 'backend', 'metabox', 'right_now' ) ); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Display metabox with quick links |
158
|
|
|
*/ |
159
|
|
|
function wps_dashboard_quick_links() { |
|
|
|
|
160
|
|
|
require_once( wpshop_tools::get_template_part( WPS_DASHBOARD_DIR, WPSDASHBOARD_TPL_DIR, 'backend', 'metabox', 'quicklinks' ) ); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* Display metabox with quick links |
165
|
|
|
*/ |
166
|
|
|
function wps_dashboard_customer_stats() { |
|
|
|
|
167
|
|
|
global $wpdb; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Display metabox with shop main statistics |
172
|
|
|
*/ |
173
|
|
|
function wps_dashboard_statistics() { |
|
|
|
|
174
|
|
|
global $wpdb, $current_month_offset; |
175
|
|
|
|
176
|
|
|
$current_month_offset = (int) current_time( 'm' ); |
177
|
|
|
$current_month_offset = isset( $_GET['month'] ) ? (int) $_GET['month'] : $current_month_offset; |
178
|
|
|
|
179
|
|
|
$current_month_start = date( 'Y-m-d 00:00:00', strtotime( 'first day of this month', time() ) ); |
180
|
|
|
$current_month_end = date( 'Y-m-d 23:59:59', strtotime( 'last day of this month', time() ) ); |
181
|
|
|
|
182
|
|
|
$last_month_start = date( 'Y-m-d 00:00:00', strtotime( 'first day of last month', time() ) ); |
183
|
|
|
$last_month_end = date( 'Y-m-d 23:59:59', strtotime( 'last day of last month', time() ) ); |
184
|
|
|
$one_month_ago = date( 'Y-m-d 23:59:59', strtotime( '-1 month', time() ) ); |
185
|
|
|
|
186
|
|
|
$dates = array( |
|
|
|
|
187
|
|
|
__( 'Current month', 'wpshop' ) => array( |
188
|
|
|
'after' => $current_month_start, |
189
|
|
|
'before' => $current_month_end, |
190
|
|
|
'inclusive' => true, |
191
|
|
|
), |
192
|
|
|
sprintf( __( 'One month ago (%s)', 'wpshop' ), mysql2date( get_option( 'date_format' ), $one_month_ago, true ) ) => array( |
193
|
|
|
'after' => $last_month_start, |
194
|
|
|
'before' => $one_month_ago, |
195
|
|
|
'inclusive' => true, |
196
|
|
|
), |
197
|
|
|
__( 'Last month', 'wpshop' ) => array( |
198
|
|
|
'after' => $last_month_start, |
199
|
|
|
'before' => $last_month_end, |
200
|
|
|
'inclusive' => true, |
201
|
|
|
), |
202
|
|
|
); |
203
|
|
|
|
204
|
|
|
$orders_default_args = array( |
|
|
|
|
205
|
|
|
'posts_per_page' => -1, |
206
|
|
|
'orderby' => 'post_date', |
207
|
|
|
'order' => 'DESC', |
208
|
|
|
'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, |
209
|
|
|
'post_status' => 'publish', |
210
|
|
|
'meta_query' => array( |
211
|
|
|
'relation' => 'OR', |
212
|
|
|
array( |
213
|
|
|
'key' => '_order_postmeta', |
214
|
|
|
'value' => 's:12:"order_status";s:9:"completed";', |
215
|
|
|
'compare' => 'LIKE', |
216
|
|
|
), |
217
|
|
|
array( |
218
|
|
|
'key' => '_order_postmeta', |
219
|
|
|
'value' => 's:12:"order_status";s:7:"shipped";', |
220
|
|
|
'compare' => 'LIKE', |
221
|
|
|
), |
222
|
|
|
), |
223
|
|
|
); |
224
|
|
|
|
225
|
|
|
require_once( wpshop_tools::get_template_part( WPS_DASHBOARD_DIR, WPSDASHBOARD_TPL_DIR, 'backend', 'metabox', 'statistics' ) ); |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* Display metabox with shop main statistics |
230
|
|
|
*/ |
231
|
|
|
function wps_dashboard_infos() { |
|
|
|
|
232
|
|
|
global $wpdb; |
233
|
|
|
require_once( wpshop_tools::get_template_part( WPS_DASHBOARD_DIR, WPSDASHBOARD_TPL_DIR, 'backend', 'metabox', 'infos' ) ); |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* Display metabox with shop main statistics |
238
|
|
|
*/ |
239
|
|
|
function wps_dashboard_feed() { |
|
|
|
|
240
|
|
|
require_once( wpshop_tools::get_template_part( WPS_DASHBOARD_DIR, WPSDASHBOARD_TPL_DIR, 'backend', 'metabox', 'feed' ) ); |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* Display metabox with recent orders list |
245
|
|
|
*/ |
246
|
|
|
function wps_dashboard_orders() { |
|
|
|
|
247
|
|
|
require_once( wpshop_tools::get_template_part( WPS_DASHBOARD_DIR, WPSDASHBOARD_TPL_DIR, 'backend', 'metabox', 'orders' ) ); |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* Display metabox for export |
252
|
|
|
*/ |
253
|
|
|
function wps_dashboard_export() { |
|
|
|
|
254
|
|
|
if ( class_exists( 'wps_export_ctr' ) ) { |
255
|
|
|
$wps_export = new wps_export_ctr(); |
256
|
|
|
$wps_export->wps_export_tpl(); |
257
|
|
|
} |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
} |
261
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.