PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.5
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.5
4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 All 139 releases
learnpress / inc / admin / lp-admin-functions.php

lp-admin-functions.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.4.5, at inc/admin/lp-admin-functions.php

2,243 lines 56.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Common functions used for admin
4 *
5 * @package LearnPress
6 * @author ThimPress
7 * @version 1.0
8 */
9
10 /**
11 * Prevent loading this file directly
12 */
13 defined( 'ABSPATH' ) || exit();
14
15 /**
16 * Check whether MCP capabilities are available in current WordPress runtime.
17 *
18 * @return bool
19 */
20 function learn_press_is_mcp_available(): bool {
21 $wp_version = (string) get_bloginfo( 'version' );
22
23 if ( version_compare( $wp_version, '6.9', '<' ) ) {
24 return false;
25 }
26
27 require_once ABSPATH . 'wp-admin/includes/plugin.php';
28
29 return is_plugin_active( 'mcp-adapter/mcp-adapter.php' );
30 }
31
32 if ( ! function_exists( 'learn_press_add_row_action_link' ) ) {
33 /**
34 * Setup action links to the admin course, lesson, quiz, question. e.g: Add Duplicate link, hide View link for lesson, quiz so on.
35 *
36 * @param $actions
37 *
38 * @return mixed
39 */
40 function learn_press_add_row_action_link( $actions ) {
41
42 global $post;
43
44 if ( LP_COURSE_CPT == $post->post_type ) {
45 $duplicate_link = '#';
46 $duplicate_link = array(
47 array(
48 'link' => $duplicate_link,
49 'title' => _x( 'Duplicate', 'copy course', 'learnpress' ),
50 'class' => 'lp-duplicate-post lp-duplicate-course',
51 'data' => $post->ID,
52 ),
53 );
54
55 $links = apply_filters( 'learn_press_row_action_links', $duplicate_link );
56
57 if ( count( $links ) > 1 ) {
58 $drop_down = array( '<ul class="lpr-row-action-dropdown">' );
59
60 foreach ( $links as $link ) {
61 $drop_down[] = '<li>' . sprintf(
62 '<a href="%s" class="%s" data-post-id="%s">%s</a>',
63 $link['link'],
64 $link['class'],
65 $link['data'],
66 $link['title']
67 ) . '</li>';
68 }
69
70 $drop_down[] = '</ul>';
71 $link = sprintf(
72 '<div class="lpr-row-actions"><a href="%s">%s</a>%s</div>',
73 'javascript: void(0);',
74 __( 'Course', 'learnpress' ),
75 join( "\n", $drop_down )
76 );
77
78 } else {
79 $link = array_shift( $links );
80 $link = sprintf(
81 '<a href="%s" class="%s" data-post-id="%s">%s</a>',
82 $link['link'],
83 $link['class'],
84 $link['data'],
85 $link['title']
86 );
87 }
88
89 $actions['lp-duplicate-row-action'] = $link;
90
91 } elseif ( LP_QUIZ_CPT === $post->post_type ) {
92 unset( $actions['view'] );
93 $link = sprintf(
94 '<a href="#" class="lp-duplicate-post lp-duplicate-quiz" data-post-id="%s">%s</a>',
95 $post->ID,
96 _x( 'Duplicate', 'copy quiz', 'learnpress' )
97 );
98 $actions['lp-duplicate-row-action'] = $link;
99
100 } elseif ( LP_QUESTION_CPT === $post->post_type ) {
101 unset( $actions['view'] );
102 $link = sprintf(
103 '<a href="#" class="lp-duplicate-post lp-duplicate-question" data-post-id="%s">%s</a>',
104 $post->ID,
105 _x( 'Duplicate', 'copy question', 'learnpress' )
106 );
107 $actions['lp-duplicate-row-action'] = $link;
108
109 } elseif ( LP_LESSON_CPT === $post->post_type ) {
110 unset( $actions['view'] );
111 $link = sprintf(
112 '<a href="#" class="lp-duplicate-post lp-duplicate-lesson" data-post-id="%s">%s</a>',
113 $post->ID,
114 _x( 'Duplicate', 'copy lesson', 'learnpress' )
115 );
116 $actions['lp-duplicate-row-action'] = $link;
117 }
118
119 return apply_filters( 'learn-press/row-action-links', $actions );
120 }
121
122 add_filter( 'post_row_actions', 'learn_press_add_row_action_link' );
123 add_filter( 'page_row_actions', 'learn_press_add_row_action_link' );
124 }
125
126 /*function learn_press_is_hidden_post_box( $id, $user_id = 0 ) {
127 if ( ! $user_id ) {
128 $user_id = get_current_user_id();
129 }
130
131 $data = learn_press_get_user_option( 'post-closed-box' );
132 if ( ! $data ) {
133 $data = array();
134 }
135
136 return false !== array_search( $id, $data );
137 }*/
138
139 /**
140 * List all pages as a dropdown with "Add New Page" option
141 *
142 * @param $name
143 * @param bool|false $selected
144 * @param array $args
145 *
146 * @return mixed|string
147 */
148 function learn_press_pages_dropdown( $name, $selected = false, $args = array() ) {
149 $id = null;
150 $class = null;
151 $css = null;
152 $before = [];
153 $after = null;
154 $echo = true;
155 $allow_create = true;
156
157 if ( func_num_args() == 1 && is_array( $name ) ) {
158 $args = $name;
159 }
160
161 is_array( $args ) && extract( $args );
162
163 if ( empty( $id ) ) {
164 $id = $name;
165 }
166
167 $class .= 'list-pages lp-list-pages lp-tom-select';
168
169 $args = array(
170 'name' => $name,
171 'id' => $id,
172 'sort_column' => 'menu_order',
173 'sort_order' => 'ASC',
174 'show_option_none' => __( 'Select Page', 'learnpress' ),
175 'class' => $class,
176 'echo' => false,
177 'selected' => $selected,
178 'allow_create' => true,
179 );
180 $output = wp_dropdown_pages( $args );
181 $replace = '';
182
183 if ( $class ) {
184 $replace .= ' class="' . $class . '"';
185 }
186
187 if ( $css ) {
188 $replace .= ' style="' . $css . '"';
189 }
190
191 $replace .= ' data-selected="' . $selected . '"';
192 $replace .= " data-placeholder='" . __( 'Select a page&hellip;', 'learnpress' ) . "' id=";
193 $output = '<div class="list-pages-wrapper">' . str_replace( ' id=', $replace, $output );
194
195 if ( $before ) {
196 $before_output = array();
197
198 foreach ( $before as $v => $l ) {
199 $before_output[] = sprintf( '<option value="%s">%s</option>', $v, $l );
200 }
201
202 $before_output = join( "\n", $before_output );
203 $output = preg_replace(
204 '!(<option class=".*" value="[0-9]+".*>.*</option>)!',
205 $before_output . "\n$1",
206 $output,
207 1
208 );
209 }
210
211 $output = str_replace( '<option class="level-0" value="00000">#0 (no title)</option>', '', $output );
212
213 if ( $selected && get_post_status( $selected ) !== 'publish' ) {
214 $selected = 0;
215 }
216
217 if ( $allow_create ) {
218 ob_start(); ?>
219
220 <?php echo esc_html( _x( 'or', 'dropdown pages', 'learnpress' ) ); ?>
221
222 <button class="button button-quick-add-page" data-id="<?php echo esc_attr( $id ); ?>" type="button">
223 <?php esc_html_e( 'Create new', 'learnpress' ); ?>
224 </button>
225 <?php echo '</div>'; ?>
226
227 <p class="quick-add-page-inline <?php echo esc_attr( $id ); ?> hide-if-js">
228 <input type="text" placeholder="<?php esc_attr_e( 'New page title', 'learnpress' ); ?>"/>
229 <button class="button" type="button">
230 <?php esc_html_e( 'Ok [Enter]', 'learnpress' ); ?>
231 </button>
232 <a href=""><?php esc_html_e( 'Cancel [ESC]', 'learnpress' ); ?></a>
233 </p>
234
235 <p class="quick-add-page-actions <?php echo esc_attr( $id ); ?><?php echo esc_attr( $selected ? '' : ' hide-if-js' ); ?>">
236 <a class="edit-page" href="<?php echo get_edit_post_link( $selected ); ?>"
237 target="_blank"><?php esc_html_e( 'Edit page', 'learnpress' ); ?></a>
238 &#124;
239 <a class="view-page" href="<?php echo get_permalink( $selected ); ?>"
240 target="_blank"><?php esc_html_e( 'View page', 'learnpress' ); ?></a>
241 </p>
242 <!-- Not use input on here, will be not save value -->
243 <div class="field_name" name="<?php echo esc_attr( $id ); ?>"></div>
244
245 <?php
246 $output .= ob_get_clean();
247 } else {
248 $output .= '</div>';
249 }
250
251 $output = sprintf( '<div class="learn-press-dropdown-pages">%s</div>', $output );
252
253 if ( $echo ) {
254 $allowed_html = wp_kses_allowed_html( 'post' );
255 $allowed_html['select'] = [
256 'name' => [],
257 'class' => [],
258 ];
259 $allowed_html['option'] = [
260 'value' => [],
261 'selected' => [],
262 'class' => [],
263 ];
264 $allowed_html['input'] = [
265 'type' => [],
266 'placeholder' => [],
267 'name' => [],
268 'class' => [],
269 ];
270 $allowed_html['div'] = [
271 'name' => [],
272 'class' => [],
273 ];
274
275 echo wp_kses( $output, $allowed_html );
276 }
277
278 return $output;
279 }
280
281 /**
282 * List all registered question types into dropdown
283 *
284 * @param array
285 *
286 * @return string
287 */
288 function learn_press_dropdown_question_types( $args = array() ) {
289 $args = wp_parse_args(
290 $args,
291 array(
292 'name' => 'learn-press-dropdown-question-types',
293 'id' => '',
294 'class' => '',
295 'selected' => '',
296 'echo' => true,
297 )
298 );
299
300 if ( ! $args['id'] ) {
301 $args['id'] = $args['name'];
302 }
303
304 $args['class'] = 'lp-dropdown-question-types' . ( $args['class'] ? ' ' . $args['class'] : '' );
305 $types = learn_press_question_types();
306 $output = sprintf(
307 '<select name="%s" id="%s" class="%s"%s>',
308 $args['name'],
309 $args['id'],
310 $args['class'],
311 $args['selected'] ? 'data-selected="' . $args['selected'] . '"' : ''
312 );
313
314 foreach ( $types as $slug => $name ) {
315 $output .= sprintf(
316 '<option value="%s"%s>%s</option>',
317 $slug,
318 selected( $slug == $args['selected'], true, false ),
319 $name
320 );
321 }
322
323 $output .= '</select>';
324
325 if ( $args['echo'] ) {
326 echo wp_kses_post( $output );
327 }
328
329 return $output;
330 }
331
332 /**
333 * List all registered question types into dropdown
334 *
335 * @param array $args
336 * @param LP_Question $question
337 *
338 * @return string
339 */
340 function learn_press_field_question_duration( $args = array(), $question = null ) {
341 global $post;
342
343 $duration_type = get_post_meta( $post->ID, '_lp_duration_type', true );
344 $value = get_post_meta( $question->id, '_question_duration', true );
345
346 $wrap_class = 'learn-press-question-duration';
347
348 if ( 'questions_duration' !== $duration_type ) {
349 $wrap_class .= ' hide';
350 }
351
352 $args = wp_parse_args(
353 $args,
354 array(
355 'name' => 'learn_press_question[' . $question->id . '][duration]',
356 'id' => 'learn-press-question-duration-' . $question->id,
357 'class' => 'learn-press-question-duration',
358 'selected' => '',
359 'echo' => true,
360 'value' => 0,
361 'step' => 1,
362 'min' => 0,
363 'placeholder' => __( 'Minutes', 'learnpress' ),
364 )
365 );
366
367 $args['value'] = $value;
368
369 if ( ! $args['id'] ) {
370 $args['id'] = $args['name'];
371 }
372
373 return '<span class="' . esc_attr( $wrap_class ) . '">' . sprintf(
374 '<input type="number" class="%s" name="%s" id="%s" value="%s" step="%s" min="%s" max="%s" placeholder="%s"/>',
375 $args['class'],
376 $args['name'],
377 empty( $args['clone'] ) ? $args['id'] : '',
378 $args['value'],
379 $args['step'],
380 $args['min'],
381 ! empty( $args['max'] ) ? $args['max'] : '',
382 $args['placeholder']
383 ) . $args['placeholder'] . '</span>';
384 }
385
386 /**
387 * Displays email formats support into a dropdown
388 *
389 * @param array $args
390 *
391 * @return string
392 * @deprecated 4.2.6.9.3
393 */
394 /*function learn_press_email_formats_dropdown( $args = array() ) {
395 $args = wp_parse_args(
396 $args,
397 array(
398 'name' => 'learn-press-dropdown-email-formats',
399 'id' => '',
400 'class' => '',
401 'selected' => '',
402 'option_none' => '',
403 'echo' => true,
404 )
405 );
406
407 $formats = array(
408 'plain_text' => __( 'Plain Text', 'learnpress' ),
409 'html' => __( 'HTML', 'learnpress' ),
410 );
411
412 if ( empty( $args['id'] ) ) {
413 $args['id'] = sanitize_file_name( $args['name'] );
414 }
415
416 $output = sprintf( '<select name="%s" id="%s" class="%s" %s>', $args['name'], $args['id'], $args['class'], '' );
417
418 if ( $args['option_none'] ) {
419 if ( is_array( $args['option_none'] ) ) {
420 $text = reset( $args['option_none'] );
421 $value = key( $args['option_none'] );
422 } else {
423 $text = $args['option_none'];
424 $value = '';
425 }
426
427 $output .= sprintf( '<option value="%s">%s</option>', $value, $text );
428 }
429
430 foreach ( $formats as $name => $text ) {
431 $output .= sprintf(
432 '<option value="%s" %s>%s</option>',
433 $name,
434 selected( $args['selected'] == $name, true, false ),
435 $text
436 ) . "\n";
437 }
438 $output .= '</select>';
439
440 if ( $args['echo'] ) {
441 echo wp_kses_post( $output );
442 }
443
444 return $output;
445 }*/
446
447 /**
448 * Return array of email formats.
449 *
450 * @return mixed
451 */
452 function learn_press_email_formats() {
453 $formats = array(
454 'plain' => esc_html__( 'Plain Text', 'learnpress' ),
455 'html' => esc_html__( 'HTML', 'learnpress' ),
456 );
457
458 return apply_filters( 'learn-press/email-formats', $formats );
459 }
460
461 function learn_press_trim_content( $content, $count = 0 ) {
462 $content = preg_replace( '/(?<=\S,)(?=\S)/', ' ', $content );
463 $content = str_replace( "\n", ' ', $content );
464 $content = explode( ' ', $content );
465
466 $count = $count > 0 ? $count : sizeof( $content ) - 1;
467 $full = $count >= sizeof( $content ) - 1;
468
469 $content = array_slice( $content, 0, $count );
470 $content = implode( ' ', $content );
471
472 if ( ! $full ) {
473 $content .= '...';
474 }
475
476 return $content;
477 }
478
479 /**
480 * Get list of themes that support LearnPress.
481 *
482 * @return mixed
483 */
484 function learn_press_get_education_themes() {
485
486 // New theme can be added here
487 return apply_filters(
488 'learn-press/education-themes',
489 array(
490 '23451388' => 'kindergarten',
491 '22773871' => 'ivy-school',
492 '20370918' => 'wordpress-lms',
493 '14058034' => 'eduma',
494 '17097658' => 'coach',
495 '11797847' => 'lms',
496 )
497 );
498 }
499
500 if ( ! function_exists( 'learn_press_get_item_referral' ) ) {
501 /**
502 * Set item link referral.
503 *
504 * @param int|string $item_id
505 *
506 * @return string
507 */
508 function learn_press_get_item_referral( $item_id ) {
509 $affiliate_links = array(
510 14058034 => 'https://1.envato.market/G5Ook', // Eduma
511 22773871 => 'https://1.envato.market/akrzZ', // Ivy-school
512 20370918 => 'https://1.envato.market/13Zkd', // Course Builder LMS
513 17097658 => 'https://1.envato.market/Xq2Ra', // Coach
514 23451388 => 'https://1.envato.market/oWov9', // StarKid
515 11797847 => 'https://1.envato.market/zknvM', // Epsilon
516 13321455 => 'https://1.envato.market/G5Rkk', // Sailing
517 19029758 => 'https://1.envato.market/mAYdZ', // Travel Tour Booking
518 12124219 => 'https://1.envato.market/qJYdO', // Resca
519 18828322 => 'https://1.envato.market/VW2K3', // LuxStay
520 8254575 => 'https://1.envato.market/xWYdO', // Squareroot
521 13782850 => 'https://1.envato.market/Qo71z',
522 14025178 => 'https://1.envato.market/9R0oQ',
523 17739078 => 'https://1.envato.market/jkYda',
524 16210005 => 'https://1.envato.market/56oJD',
525 11733602 => 'https://1.envato.market/keYdv',
526 13513609 => 'https://1.envato.market/aq7dQ',
527 19693761 => 'https://1.envato.market/A976D',
528 12532973 => 'https://1.envato.market/Ge79B',
529 19305239 => 'https://1.envato.market/10JAB',
530 23716060 => 'https://1.envato.market/ZO7WW',
531 20466233 => 'https://1.envato.market/gjYd0',
532 21070438 => 'https://1.envato.market/xPz65',
533 20794183 => 'https://1.envato.market/o1YdY',
534 20979215 => 'https://1.envato.market/03R5V',
535 11151269 => 'https://1.envato.market/Br7L4',
536 8905392 => 'https://1.envato.market/zEYd7',
537 23168294 => 'https://1.envato.market/Wn7on',
538 17719422 => 'https://1.envato.market/0WVaL',
539 21680592 => 'https://1.envato.market/qqO6y',
540 );
541
542 return $affiliate_links[ $item_id ] ?? 'https://themeforest.net/user/thimpress/portfolio/';
543 }
544 }
545
546 /**
547 * Count number of orders between to dates
548 *
549 * @param string
550 * @param int
551 *
552 * @return int
553 */
554 function learn_press_get_order_by_time( $by, $time ) {
555 global $wpdb;
556
557 $user_id = get_current_user_id();
558
559 $y = gmdate( 'Y', $time );
560 $m = gmdate( 'm', $time );
561 $d = gmdate( 'd', $time );
562
563 switch ( $by ) {
564 case 'days':
565 $orders = $wpdb->get_var(
566 $wpdb->prepare(
567 "SELECT COUNT(*)
568 FROM $wpdb->posts AS p
569 INNER JOIN $wpdb->postmeta AS m ON p.ID = m.post_id
570 WHERE p.post_author = %d
571 AND p.post_type = %s
572 AND p.post_status = %s
573 AND m.meta_key = %s
574 AND m.meta_value = %s
575 AND YEAR(p.post_date) = %s AND MONTH(p.post_date) = %s AND DAY(p.post_date) = %s",
576 $user_id,
577 LP_ORDER_CPT,
578 'publish',
579 '_learn_press_transaction_status',
580 'completed',
581 $y,
582 $m,
583 $d
584 )
585 );
586 break;
587 case 'months':
588 $orders = $wpdb->get_var(
589 $wpdb->prepare(
590 "SELECT COUNT(*)
591 FROM $wpdb->posts AS p
592 INNER JOIN $wpdb->postmeta AS m ON p.ID = m.post_id
593 WHERE p.post_author = %d
594 AND p.post_type = %s
595 AND p.post_status = %s
596 AND m.meta_key = %s
597 AND m.meta_value = %s
598 AND YEAR(p.post_date) = %s AND MONTH(p.post_date) = %s",
599 $user_id,
600 LP_ORDER_CPT,
601 'publish',
602 '_learn_press_transaction_status',
603 'completed',
604 $y,
605 $m
606 )
607 );
608 break;
609 }
610
611 return $orders;
612 }
613
614 /**
615 * Count number of orders by status
616 *
617 * @param string Status of the orders
618 *
619 * @return int
620 */
621 function learn_press_get_courses_by_status( $status ) {
622 global $wpdb;
623
624 $user_id = get_current_user_id();
625
626 $courses = $wpdb->get_var(
627 $wpdb->prepare(
628 "SELECT COUNT(*)
629 FROM $wpdb->posts
630 WHERE post_author = %d
631 AND post_type = %s
632 AND post_status = %s",
633 $user_id,
634 LP_COURSE_CPT,
635 $status
636 )
637 );
638
639 return $courses;
640 }
641
642 /**
643 * Count number of orders by price
644 *
645 * @param string
646 *
647 * @return int
648 * @deprecated 4.2.6.9.3
649 */
650 /*function learn_press_get_courses_by_price( $fee ) {
651 global $wpdb;
652
653 $user_id = get_current_user_id();
654
655 $courses = $wpdb->get_var(
656 $wpdb->prepare(
657 "SELECT COUNT(*)
658 FROM $wpdb->posts AS p
659 INNER JOIN $wpdb->postmeta AS m ON p.ID = m.post_id
660 WHERE p.post_author = %d
661 AND p.post_type = %s
662 AND p.post_status IN (%s, %s)
663 AND m.meta_key = %s
664 AND m.meta_value = %s",
665 $user_id,
666 LP_COURSE_CPT,
667 'publish',
668 'pending',
669 '_lpr_course_payment',
670 $fee
671 )
672 );
673
674 return $courses;
675 }*/
676
677 /**
678 * Get data about students to render in chart
679 *
680 * @param null $from
681 * @param null $by
682 * @param float $time_ago
683 *
684 * @return array
685 * @deprecated 4.2.6.9.3
686 */
687 /*function learn_press_get_chart_students( $from = null, $by = null, $time_ago = 0 ) {
688 $labels = array();
689 $datasets = array();
690
691 if ( is_null( $from ) ) {
692 $from = current_time( 'mysql', 1 );
693 }
694
695 if ( is_null( $by ) ) {
696 $by = 'days';
697 }
698
699 switch ( $by ) {
700 case 'days':
701 $date_format = 'M d';
702 break;
703 case 'months':
704 $date_format = 'M Y';
705 break;
706 case 'years':
707 $date_format = 'Y';
708 break;
709 }
710
711 for ( $i = - $time_ago + 1; $i <= 0; $i ++ ) {
712 $labels[] = gmdate( $date_format, strtotime( "$i $by", strtotime( $from ) ) );
713 $datasets[0]['data'][] = learn_press_get_order_by_time( $by, strtotime( "$i $by", strtotime( $from ) ) );
714 }
715
716 $colors = learn_press_get_admin_colors();
717 $datasets[0]['fillColor'] = 'rgba(255,255,255,0.1)';
718 $datasets[0]['strokeColor'] = $colors[0];
719 $datasets[0]['pointColor'] = $colors[0];
720 $datasets[0]['pointStrokeColor'] = $colors[2];
721 $datasets[0]['pointHighlightFill'] = $colors[2];
722 $datasets[0]['pointHighlightStroke'] = $colors[0];
723
724 return array(
725 'labels' => $labels,
726 'datasets' => $datasets,
727 );
728 }*/
729
730 /**
731 * Get data about students to render in chart
732 *
733 * @param null $from
734 * @param null $by
735 * @param float $time_ago
736 *
737 * @return array
738 * @deprecated 4.2.6.9.3
739 */
740 /*function learn_press_get_chart_users( $from = null, $by = null, $time_ago = 0 ) {
741 global $wpdb;
742
743 $labels = array();
744 $datasets = array();
745
746 if ( is_null( $from ) ) {
747 $from = current_time( 'mysql', 1 );
748 }
749
750 if ( is_null( $by ) ) {
751 $by = 'days';
752 }
753
754 $results = array(
755 'all' => array(),
756 'instructors' => array(),
757 );
758
759 $from_time = is_numeric( $from ) ? $from : strtotime( $from );
760
761 switch ( $by ) {
762 case 'days':
763 $date_format = 'M d Y';
764 $_from = - $time_ago + 1;
765 $_from = gmdate( 'Y-m-d', strtotime( "{$_from} {$by}", $from_time ) );
766 $_to = date( 'Y-m-d', $from_time );
767 $_sql_format = '%Y-%m-%d';
768 $_key_format = 'Y-m-d';
769 break;
770 case 'months':
771 $date_format = 'M Y';
772 $_from = - $time_ago + 1;
773 $_from = date( 'Y-m-01', strtotime( "{$_from} {$by}", $from_time ) );
774 $days = date( 't', mktime( 0, 0, 0, date( 'm', $from_time ), 1, date( 'Y', $from_time ) ) );
775 $_to = date( 'Y-m-' . $days, $from_time );
776 $_sql_format = '%Y-%m';
777 $_key_format = 'Y-m';
778 break;
779 case 'years':
780 $date_format = 'Y';
781 $_from = - $time_ago + 1;
782 $_from = date( 'Y-01-01', strtotime( "{$_from} {$by}", $from_time ) );
783 $days = date( 't', mktime( 0, 0, 0, date( 'm', $from_time ), 1, date( 'Y', $from_time ) ) );
784 $_to = date( 'Y-12-' . $days, $from_time );
785 $_sql_format = '%Y';
786 $_key_format = 'Y';
787
788 break;
789 }
790 $query = $wpdb->prepare(
791 "
792 SELECT count(u.ID) as c, DATE_FORMAT( u.user_registered, %s) as d
793 FROM {$wpdb->users} u
794 WHERE 1
795 GROUP BY d
796 HAVING d BETWEEN %s AND %s
797 ORDER BY d ASC
798 ",
799 $_sql_format,
800 $_from,
801 $_to
802 );
803
804 if ( $_results = $wpdb->get_results( $query ) ) {
805 foreach ( $_results as $k => $v ) {
806 $results['all'][ $v->d ] = $v;
807 }
808 }
809
810 $query = $wpdb->prepare(
811 "
812 SELECT count(u.ID) as c, DATE_FORMAT( u.user_registered, %s) as d
813 FROM {$wpdb->users} u
814 INNER JOIN {$wpdb->usermeta} um ON um.user_id = u.ID AND um.meta_key = %s AND ( um.meta_value LIKE %s OR um.meta_value LIKE %s )
815 WHERE 1
816 GROUP BY d
817 HAVING d BETWEEN %s AND %s
818 ORDER BY d ASC
819 ",
820 $_sql_format,
821 'wp_capabilities',
822 '%' . $wpdb->esc_like( 's:13:"administrator"' ) . '%',
823 '%' . $wpdb->esc_like( 's:10:"lp_teacher"' ) . '%',
824 $_from,
825 $_to
826 );
827
828 if ( $_results = $wpdb->get_results( $query ) ) {
829 foreach ( $_results as $k => $v ) {
830 $results['instructors'][ $v->d ] = $v;
831 }
832 }
833
834 for ( $i = - $time_ago + 1; $i <= 0; $i ++ ) {
835 $date = strtotime( "$i $by", $from_time );
836 $labels[] = date( $date_format, $date );
837 $key = date( $_key_format, $date );
838
839 $all = ! empty( $results['all'][ $key ] ) ? $results['all'][ $key ]->c : 0;
840 $instructors = ! empty( $results['instructors'][ $key ] ) ? $results['instructors'][ $key ]->c : 0;
841
842 $datasets[0]['data'][] = $all;
843 $datasets[1]['data'][] = $instructors;
844 $datasets[2]['data'][] = $all - $instructors;
845 }
846
847 $dataset_params = array(
848 array(
849 'color1' => 'rgba(47, 167, 255, %s)',
850 'color2' => '#FFF',
851 'label' => __( 'All', 'learnpress' ),
852 ),
853 array(
854 'color1' => 'rgba(212, 208, 203, %s)',
855 'color2' => '#FFF',
856 'label' => __( 'Instructors', 'learnpress' ),
857 ),
858 array(
859 'color1' => 'rgba(234, 199, 155, %s)',
860 'color2' => '#FFF',
861 'label' => __( 'Students', 'learnpress' ),
862 ),
863 );
864
865 foreach ( $dataset_params as $k => $v ) {
866 $datasets[ $k ]['fillColor'] = sprintf( $v['color1'], '0.2' );
867 $datasets[ $k ]['strokeColor'] = sprintf( $v['color1'], '1' );
868 $datasets[ $k ]['pointColor'] = sprintf( $v['color1'], '1' );
869 $datasets[ $k ]['pointStrokeColor'] = $v['color2'];
870 $datasets[ $k ]['pointHighlightFill'] = $v['color2'];
871 $datasets[ $k ]['pointHighlightStroke'] = sprintf( $v['color1'], '1' );
872 $datasets[ $k ]['label'] = $v['label'];
873 }
874
875 return array(
876 'labels' => $labels,
877 'datasets' => $datasets,
878 'sql' => $query,
879 );
880 }*/
881
882
883 /**
884 * Get data about students to render in chart
885 *
886 * @param null $from
887 * @param null $by
888 * @param float $time_ago
889 *
890 * @return array
891 * @deprecated 4.2.6.9.3
892 */
893 /*function learn_press_get_chart_courses( $from = null, $by = null, $time_ago = 0 ) {
894 global $wpdb;
895
896 $labels = array();
897 $datasets = array();
898
899 if ( is_null( $from ) ) {
900 $from = current_time( 'mysql', 1 );
901 }
902
903 if ( is_null( $by ) ) {
904 $by = 'days';
905 }
906
907 $results = array(
908 'all' => array(),
909 'public' => array(),
910 'pending' => array(),
911 'free' => array(),
912 'paid' => array(),
913 );
914
915 $from_time = is_numeric( $from ) ? $from : strtotime( $from );
916
917 switch ( $by ) {
918 case 'days':
919 $date_format = 'M d Y';
920 $_from = - $time_ago + 1;
921 $_from = date( 'Y-m-d', strtotime( "{$_from} {$by}", $from_time ) );
922 $_to = date( 'Y-m-d', $from_time );
923 $_sql_format = '%Y-%m-%d';
924 $_key_format = 'Y-m-d';
925 break;
926 case 'months':
927 $date_format = 'M Y';
928 $_from = - $time_ago + 1;
929 $_from = date( 'Y-m-01', strtotime( "{$_from} {$by}", $from_time ) );
930 $days = date( 't', mktime( 0, 0, 0, date( 'm', $from_time ), 1, date( 'Y', $from_time ) ) );
931 $_to = date( 'Y-m-' . $days, $from_time );
932 $_sql_format = '%Y-%m';
933 $_key_format = 'Y-m';
934 break;
935 case 'years':
936 $date_format = 'Y';
937 $_from = - $time_ago + 1;
938 $_from = date( 'Y-01-01', strtotime( "{$_from} {$by}", $from_time ) );
939 $days = date( 't', mktime( 0, 0, 0, date( 'm', $from_time ), 1, date( 'Y', $from_time ) ) );
940 $_to = date( 'Y-12-' . $days, $from_time );
941 $_sql_format = '%Y';
942 $_key_format = 'Y';
943
944 break;
945 }
946
947 $query_where = '';
948
949 if ( current_user_can( LP_TEACHER_ROLE ) ) {
950 $user_id = learn_press_get_current_user_id();
951 $query_where .= $wpdb->prepare( ' AND c.post_author=%d ', $user_id );
952 }
953
954 $query = $wpdb->prepare(
955 "
956 SELECT count(c.ID) as c, DATE_FORMAT( c.post_date, %s) as d
957 FROM {$wpdb->posts} c
958 WHERE 1
959 {$query_where}
960 AND c.post_status IN('publish', 'pending') AND c.post_type = %s
961 GROUP BY d
962 HAVING d BETWEEN %s AND %s
963 ORDER BY d ASC
964 ",
965 $_sql_format,
966 'lp_course',
967 $_from,
968 $_to
969 );
970 if ( $_results = $wpdb->get_results( $query ) ) {
971 foreach ( $_results as $k => $v ) {
972 $results['all'][ $v->d ] = $v;
973 }
974 }
975 $query = $wpdb->prepare(
976 "
977 SELECT count(c.ID) as c, DATE_FORMAT( c.post_date, %s) as d
978 FROM {$wpdb->posts} c
979 WHERE 1
980 {$query_where}
981 AND c.post_status = %s AND c.post_type = %s
982 GROUP BY d
983 HAVING d BETWEEN %s AND %s
984 ORDER BY d ASC
985 ",
986 $_sql_format,
987 'publish',
988 'lp_course',
989 $_from,
990 $_to
991 );
992
993 $_results = $wpdb->get_results( $query );
994 if ( $_results ) {
995 foreach ( $_results as $k => $v ) {
996 $results['publish'][ $v->d ] = $v;
997 }
998 }
999
1000 $query = $wpdb->prepare(
1001 "
1002 SELECT count(c.ID) as c, DATE_FORMAT( c.post_date, %s) as d
1003 FROM {$wpdb->posts} c
1004 INNER JOIN {$wpdb->postmeta} cm ON cm.post_id = c.ID
1005 WHERE 1
1006 {$query_where}
1007 AND c.post_status = %s AND c.post_type = %s
1008 GROUP BY d
1009 HAVING d BETWEEN %s AND %s
1010 ORDER BY d ASC
1011 ",
1012 $_sql_format,
1013 'publish',
1014 'lp_course',
1015 $_from,
1016 $_to
1017 );
1018
1019 $_results = $wpdb->get_results( $query );
1020 if ( $_results ) {
1021 foreach ( $_results as $k => $v ) {
1022 $results['paid'][ $v->d ] = $v;
1023 }
1024 }
1025
1026 for ( $i = - $time_ago + 1; $i <= 0; $i ++ ) {
1027 $date = strtotime( "$i $by", $from_time );
1028 $labels[] = date( $date_format, $date );
1029 $key = date( $_key_format, $date );
1030
1031 $all = ! empty( $results['all'][ $key ] ) ? $results['all'][ $key ]->c : 0;
1032 $publish = ! empty( $results['publish'][ $key ] ) ? $results['publish'][ $key ]->c : 0;
1033 $paid = ! empty( $results['paid'][ $key ] ) ? $results['paid'][ $key ]->c : 0;
1034
1035 $datasets[0]['data'][] = $all;
1036 $datasets[1]['data'][] = $publish;
1037 $datasets[2]['data'][] = $all - $publish;
1038 $datasets[3]['data'][] = $paid;
1039 $datasets[4]['data'][] = $all - $paid;
1040 }
1041
1042 $dataset_params = array(
1043 array(
1044 'color1' => 'rgba(47, 167, 255, %s)',
1045 'color2' => '#FFF',
1046 'label' => __( 'All', 'learnpress' ),
1047 ),
1048 array(
1049 'color1' => 'rgba(212, 208, 203, %s)',
1050 'color2' => '#FFF',
1051 'label' => __( 'Publish', 'learnpress' ),
1052 ),
1053 array(
1054 'color1' => 'rgba(234, 199, 155, %s)',
1055 'color2' => '#FFF',
1056 'label' => __( 'Pending', 'learnpress' ),
1057 ),
1058 array(
1059 'color1' => 'rgba(234, 199, 155, %s)',
1060 'color2' => '#FFF',
1061 'label' => __( 'Paid', 'learnpress' ),
1062 ),
1063 array(
1064 'color1' => 'rgba(234, 199, 155, %s)',
1065 'color2' => '#FFF',
1066 'label' => __( 'Free', 'learnpress' ),
1067 ),
1068 );
1069
1070 foreach ( $dataset_params as $k => $v ) {
1071 $datasets[ $k ]['fillColor'] = sprintf( $v['color1'], '0.2' );
1072 $datasets[ $k ]['strokeColor'] = sprintf( $v['color1'], '1' );
1073 $datasets[ $k ]['pointColor'] = sprintf( $v['color1'], '1' );
1074 $datasets[ $k ]['pointStrokeColor'] = $v['color2'];
1075 $datasets[ $k ]['pointHighlightFill'] = $v['color2'];
1076 $datasets[ $k ]['pointHighlightStroke'] = sprintf( $v['color1'], '1' );
1077 $datasets[ $k ]['label'] = $v['label'];
1078 }
1079
1080 return array(
1081 'labels' => $labels,
1082 'datasets' => $datasets,
1083 'sql' => $query,
1084 );
1085 }*/
1086
1087
1088 /**
1089 * Get data about students to render in chart
1090 *
1091 * @param null $from
1092 * @param null $by
1093 * @param float $time_ago
1094 *
1095 * @return array
1096 * @deprecated 4.2.6.9.3
1097 */
1098 /*function learn_press_get_chart_orders( $from = null, $by = null, $time_ago = 0 ) {
1099 global $wpdb;
1100 $sql_join = '';
1101
1102 $report_sales_by = learn_press_get_request( 'report_sales_by' );
1103 $course_id = learn_press_get_request( 'course_id' );
1104 $cat_id = learn_press_get_request( 'cat_id' );
1105
1106 $labels = array();
1107 $datasets = array();
1108 if ( is_null( $from ) ) {
1109 $from = current_time( 'mysql', 1 );
1110 }
1111 if ( is_null( $by ) ) {
1112 $by = 'days';
1113 }
1114 $results = array(
1115 'all' => array(),
1116 'completed' => array(),
1117 'pending' => array(),
1118 );
1119 $from_time = is_numeric( $from ) ? $from : strtotime( $from );
1120
1121 switch ( $by ) {
1122 case 'days':
1123 $date_format = 'M d Y';
1124 $_from = - $time_ago + 1;
1125 $_from = date( 'Y-m-d', strtotime( "{$_from} {$by}", $from_time ) );
1126 $_to = date( 'Y-m-d', $from_time );
1127 $_sql_format = '%Y-%m-%d';
1128 $_key_format = 'Y-m-d';
1129 break;
1130 case 'months':
1131 $date_format = 'M Y';
1132 $_from = - $time_ago + 1;
1133 $_from = date( 'Y-m-01', strtotime( "{$_from} {$by}", $from_time ) );
1134 $days = date( 't', mktime( 0, 0, 0, date( 'm', $from_time ), 1, date( 'Y', $from_time ) ) );
1135 $_to = date( 'Y-m-' . $days, $from_time );
1136 $_sql_format = '%Y-%m';
1137 $_key_format = 'Y-m';
1138 break;
1139 case 'years':
1140 $date_format = 'Y';
1141 $_from = - $time_ago + 1;
1142 $_from = date( 'Y-01-01', strtotime( "{$_from} {$by}", $from_time ) );
1143 $days = date( 't', mktime( 0, 0, 0, date( 'm', $from_time ), 1, date( 'Y', $from_time ) ) );
1144 $_to = date( 'Y-12-' . $days, $from_time );
1145 $_sql_format = '%Y';
1146 $_key_format = 'Y';
1147
1148 break;
1149 }
1150
1151 $query_join = '';
1152 $query_where = '';
1153 $sql_join = '';
1154 if ( 'course' === $report_sales_by ) {
1155 $sql_join .= " INNER JOIN `{$wpdb->prefix}learnpress_order_items` `lpoi` "
1156 . ' ON o.ID=lpoi.order_id '
1157 . " INNER JOIN {$wpdb->prefix}learnpress_order_itemmeta loim "
1158 . ' ON lpoi.order_item_id=loim.learnpress_order_item_id '
1159 . " AND loim.meta_key='_course_id' "
1160 . ' AND CAST(loim.meta_value AS SIGNED)=%d ';
1161 if ( current_user_can( LP_TEACHER_ROLE ) ) {
1162 $user_id = learn_press_get_current_user_id();
1163 $sql_join .= $wpdb->prepare(
1164 ' AND CAST(loim.meta_value AS SIGNED) IN '
1165 . ' ( '
1166 . " SELECT ID FROM {$wpdb->posts} p WHERE p.ID = CAST(loim.meta_value AS SIGNED) AND `post_author`=" . intval( $user_id )
1167 . ' ) '
1168 );
1169 }
1170 $query_join .= $wpdb->prepare( $sql_join, $course_id );
1171
1172 } elseif ( 'category' === $report_sales_by ) {
1173 $sql_join .= " INNER JOIN `{$wpdb->prefix}learnpress_order_items` `lpoi` "
1174 . ' ON o.ID=lpoi.order_id '
1175 . " INNER JOIN {$wpdb->prefix}learnpress_order_itemmeta loim "
1176 . ' ON lpoi.order_item_id=loim.learnpress_order_item_id '
1177 . " AND loim.meta_key='_course_id' "
1178 . ' AND CAST(loim.meta_value AS SIGNED) IN('
1179 // sub query
1180 . ' SELECT tr.object_id '
1181 . " FROM {$wpdb->prefix}term_taxonomy tt INNER JOIN {$wpdb->prefix}term_relationships tr "
1182 . " ON tt.term_taxonomy_id = tr.term_taxonomy_id AND tt.taxonomy='course_category' "
1183 . ' WHERE tt.term_id=%d)';
1184 $query_join .= $wpdb->prepare( $sql_join, $cat_id );
1185 }
1186 if ( current_user_can( LP_TEACHER_ROLE ) ) {
1187 $user_id = learn_press_get_current_user_id();
1188 $query_where .= $wpdb->prepare(
1189 " AND o.ID IN( SELECT oi.order_id
1190 FROM lptest.{$wpdb->prefix}learnpress_order_items oi
1191 inner join {$wpdb->prefix}learnpress_order_itemmeta oim
1192 on oi.order_item_id = oim.learnpress_order_item_id
1193 and oim.meta_key='_course_id'
1194 and cast(oim.meta_value as SIGNED) IN (
1195 SELECT sp.ID FROM {$wpdb->prefix}posts sp WHERE sp.post_author=%d and sp.ID=cast(oim.meta_value as SIGNED)
1196 )
1197 ) ",
1198 $user_id
1199 );
1200 }
1201
1202 $query = $wpdb->prepare(
1203 "
1204 SELECT count(o.ID) as c, DATE_FORMAT( o.post_date, %s) as d
1205 FROM {$wpdb->posts} o {$query_join}
1206 WHERE 1 {$query_where}
1207 AND o.post_status IN('lp-completed') AND o.post_type = %s
1208 GROUP BY d
1209 HAVING d BETWEEN %s AND %s
1210 ORDER BY d ASC
1211 ",
1212 $_sql_format,
1213 'lp_order',
1214 $_from,
1215 $_to
1216 );
1217
1218 if ( $_results = $wpdb->get_results( $query ) ) {
1219 foreach ( $_results as $k => $v ) {
1220 $results['completed'][ $v->d ] = $v;
1221 }
1222 }
1223
1224 $query = $wpdb->prepare(
1225 "
1226 SELECT count(o.ID) as c, DATE_FORMAT( o.post_date, %s) as d
1227 FROM {$wpdb->posts} o {$query_join}
1228 WHERE 1 {$query_where}
1229 AND o.post_status IN('lp-pending', 'lp-processing') AND o.post_type = %s
1230 GROUP BY d
1231 HAVING d BETWEEN %s AND %s
1232 ORDER BY d ASC
1233 ",
1234 $_sql_format,
1235 'lp_order',
1236 $_from,
1237 $_to
1238 );
1239
1240 if ( $_results = $wpdb->get_results( $query ) ) {
1241 foreach ( $_results as $k => $v ) {
1242 $results['pending'][ $v->d ] = $v;
1243 }
1244 }
1245
1246 for ( $i = - $time_ago + 1; $i <= 0; $i ++ ) {
1247 $date = strtotime( "$i $by", $from_time );
1248 $labels[] = date( $date_format, $date );
1249 $key = date( $_key_format, $date );
1250
1251 $completed = ! empty( $results['completed'][ $key ] ) ? $results['completed'][ $key ]->c : 0;
1252 $pending = ! empty( $results['pending'][ $key ] ) ? $results['pending'][ $key ]->c : 0;
1253 $all = $completed + $pending;
1254
1255 $datasets[0]['data'][] = $all;
1256 $datasets[1]['data'][] = $completed;
1257 $datasets[2]['data'][] = $pending;
1258 }
1259
1260 $dataset_params = array(
1261 array(
1262 'color1' => 'rgba(47, 167, 255, %s)',
1263 'color2' => '#FFF',
1264 'label' => __( 'All', 'learnpress' ),
1265 ),
1266 array(
1267 'color1' => 'rgba(212, 208, 203, %s)',
1268 'color2' => '#FFF',
1269 'label' => __( 'Completed', 'learnpress' ),
1270 ),
1271 array(
1272 'color1' => 'rgba(234, 199, 155, %s)',
1273 'color2' => '#FFF',
1274 'label' => __( 'Pending', 'learnpress' ),
1275 ),
1276 );
1277
1278 foreach ( $dataset_params as $k => $v ) {
1279 $datasets[ $k ]['fillColor'] = sprintf( $v['color1'], '0.2' );
1280 $datasets[ $k ]['strokeColor'] = sprintf( $v['color1'], '1' );
1281 $datasets[ $k ]['pointColor'] = sprintf( $v['color1'], '1' );
1282 $datasets[ $k ]['pointStrokeColor'] = $v['color2'];
1283 $datasets[ $k ]['pointHighlightFill'] = $v['color2'];
1284 $datasets[ $k ]['pointHighlightStroke'] = sprintf( $v['color1'], '1' );
1285 $datasets[ $k ]['label'] = $v['label'];
1286 }
1287
1288 return array(
1289 'labels' => $labels,
1290 'datasets' => $datasets,
1291 'sql' => $query,
1292 );
1293 }*/
1294
1295 /**
1296 * Get data about courses to render in the chart
1297 *
1298 * @return array
1299 * @deprecated 4.2.6.9.3
1300 */
1301 /*function learn_press_get_chart_courses2() {
1302 $labels = array(
1303 __( 'Pending Courses/Publish Courses', 'learnpress' ),
1304 __( 'Free Courses/Paid Courses', 'learnpress' ),
1305 );
1306
1307 $datasets = array();
1308 $datasets[0]['data'] = array(
1309 learn_press_get_courses_by_status( 'pending' ),
1310 learn_press_get_courses_by_price( 'free' ),
1311 );
1312
1313 $datasets[1]['data'] = array(
1314 learn_press_get_courses_by_status( 'publish' ),
1315 learn_press_get_courses_by_price( 'not_free' ),
1316 );
1317
1318 $colors = learn_press_get_admin_colors();
1319 $datasets[0]['fillColor'] = $colors[1];
1320 $datasets[0]['strokeColor'] = $colors[1];
1321 $datasets[1]['fillColor'] = $colors[3];
1322 $datasets[1]['strokeColor'] = $colors[3];
1323
1324 return array(
1325 'labels' => $labels,
1326 'datasets' => $datasets,
1327 );
1328 }*/
1329
1330 /**
1331 * Get colors setting up by admin user
1332 *
1333 * @return array
1334 */
1335 function learn_press_get_admin_colors() {
1336 $admin_color = get_user_meta( get_current_user_id(), 'admin_color', true );
1337 global $_wp_admin_css_colors;
1338 $colors = array();
1339
1340 if ( ! empty( $_wp_admin_css_colors[ $admin_color ]->colors ) ) {
1341 $colors = $_wp_admin_css_colors[ $admin_color ]->colors;
1342 }
1343
1344 if ( empty( $colors[0] ) ) {
1345 $colors[0] = '#000000';
1346 }
1347
1348 if ( empty( $colors[2] ) ) {
1349 $colors[2] = '#00FF00';
1350 }
1351
1352 return $colors;
1353 }
1354
1355 /**
1356 * Convert an array to json format and print out to browser
1357 *
1358 * @param array $chart
1359 */
1360 function learn_press_process_chart( $chart = array() ) {
1361 $data = json_encode(
1362 array(
1363 'labels' => $chart['labels'],
1364 'datasets' => $chart['datasets'],
1365 )
1366 );
1367 echo wp_kses_post( $data );
1368 }
1369
1370 /**
1371 * Print out the configuration for admin chart
1372 */
1373 function learn_press_config_chart() {
1374 $colors = learn_press_get_admin_colors();
1375
1376 $config = array(
1377 'scaleShowGridLines' => true,
1378 'scaleGridLineColor' => '#777',
1379 'scaleGridLineWidth' => 0.3,
1380 'scaleFontColor' => '#444',
1381 'scaleLineColor' => $colors[0],
1382 'bezierCurve' => true,
1383 'bezierCurveTension' => 0.2,
1384 'pointDotRadius' => 5,
1385 'pointDotStrokeWidth' => 5,
1386 'pointHitDetectionRadius' => 20,
1387 'datasetStroke' => true,
1388 'responsive' => true,
1389 'tooltipFillColor' => $colors[2],
1390 'tooltipFontColor' => '#eee',
1391 'tooltipCornerRadius' => 0,
1392 'tooltipYPadding' => 10,
1393 'tooltipXPadding' => 10,
1394 'barDatasetSpacing' => 10,
1395 'barValueSpacing' => 200,
1396
1397 );
1398
1399 echo json_encode( $config );
1400 }
1401
1402 function set_post_order_in_admin( $wp_query ) {
1403 global $pagenow;
1404
1405 if ( isset( $_GET['post_type'] ) ) {
1406 $post_type = LP_Helper::sanitize_params_submitted( $_GET['post_type'] );
1407 } else {
1408 $post_type = '';
1409 }
1410
1411 if ( is_admin() && 'edit.php' == $pagenow && $post_type == LP_COURSE_CPT && ! isset( $_GET['orderby'] ) ) {
1412 $wp_query->set( 'orderby', 'date' );
1413 $wp_query->set( 'order', 'DSC' );
1414 }
1415 }
1416
1417 // add_filter( 'pre_get_posts', 'set_post_order_in_admin' );
1418
1419 function learn_press_copy_post_meta( $from_id, $to_id ) {
1420 global $wpdb;
1421
1422 $course_meta = $wpdb->get_results(
1423 $wpdb->prepare( "SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id = %d", $from_id )
1424 );
1425
1426 if ( count( $course_meta ) != 0 ) {
1427 $sql_query = "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) ";
1428 $sql_query_sel = array();
1429
1430 foreach ( $course_meta as $meta ) {
1431 $meta_key = $meta->meta_key;
1432 $meta_value = addslashes( $meta->meta_value );
1433
1434 $sql_query_sel[] = "SELECT {$to_id}, '$meta_key', '$meta_value'";
1435 }
1436
1437 $sql_query .= implode( ' UNION ALL ', $sql_query_sel );
1438 $wpdb->query( $sql_query );
1439 }
1440 }
1441
1442 /**
1443 * Check to see if a plugin is already installed or not
1444 *
1445 * @param $plugin
1446 *
1447 * @return bool
1448 */
1449 function learn_press_is_plugin_install( $plugin ) {
1450 $installed_plugins = get_plugins();
1451
1452 return isset( $installed_plugins[ $plugin ] );
1453 }
1454
1455 /**
1456 * Get plugin file that contains the information from slug
1457 *
1458 * @param $slug
1459 *
1460 * @return mixed
1461 */
1462 function learn_press_plugin_basename_from_slug( $slug ) {
1463 $keys = array_keys( get_plugins() );
1464
1465 foreach ( $keys as $key ) {
1466 if ( preg_match( '|^' . $slug . '/|', $key ) ) {
1467 return $key;
1468 }
1469 }
1470
1471 return $slug;
1472 }
1473
1474 function _learn_press_reset_course_data() {
1475 if ( empty( $_REQUEST['reset-course-data'] ) ) {
1476 return false;
1477 }
1478
1479 learn_press_reset_course_data( intval( $_REQUEST['reset-course-data'] ) );
1480
1481 wp_redirect( esc_url_raw( remove_query_arg( 'reset-course-data' ) ) );
1482 }
1483
1484 add_action( 'init', '_learn_press_reset_course_data' );
1485
1486 function learn_press_admin_section_loop_item_class( $item, $section ) {
1487 $classes = array(
1488 'lp-section-item',
1489 );
1490
1491 $classes[] = 'lp-item-' . $item->post_type;
1492
1493 if ( ! absint( $item->ID ) ) {
1494 $classes[] = 'lp-item-empty lp-item-new focus';
1495 }
1496
1497 $classes = apply_filters( 'learn_press_section_loop_item_class', $classes, $item, $section );
1498
1499 if ( $classes ) {
1500 echo 'class="' . join( ' ', $classes ) . '"';
1501 }
1502
1503 return $classes;
1504 }
1505
1506 function learn_press_disable_checked_ontop( $args ) {
1507
1508 if ( 'course_category' == $args['taxonomy'] ) {
1509 $args['checked_ontop'] = false;
1510 }
1511
1512 return $args;
1513 }
1514
1515 add_filter( 'wp_terms_checklist_args', 'learn_press_disable_checked_ontop' );
1516
1517 function learn_press_get_screens() {
1518 $screen_id = sanitize_title( __( 'LearnPress', 'learnpress' ) );
1519
1520 $screens = array(
1521 'toplevel_page_' . $screen_id,
1522 $screen_id . '_page_learn-press-statistics',
1523 $screen_id . '_page_learn-press-addons',
1524 $screen_id . '_page_learn-press-settings',
1525 $screen_id . '_page_learn-press-tools',
1526 );
1527
1528 foreach ( array( LP_COURSE_CPT, LP_LESSON_CPT, LP_QUIZ_CPT, LP_QUESTION_CPT, LP_ORDER_CPT ) as $post_type ) {
1529 $screens[] = 'edit-' . $post_type;
1530 $screens[] = $post_type;
1531 }
1532
1533 return apply_filters( 'learn_press_screen_ids', $screens );
1534 }
1535
1536 function learn_press_is_post_type_screen( $post_type, $union = 'OR' ) {
1537 if ( is_array( $post_type ) ) {
1538 $return = null;
1539
1540 foreach ( $post_type as $_post_type ) {
1541 $check = learn_press_is_post_type_screen( $_post_type );
1542
1543 if ( $union == 'OR' && $check ) {
1544 return true;
1545 }
1546
1547 if ( $return == null ) {
1548 $return = $check;
1549 } else {
1550 $return = $return && $check;
1551 }
1552
1553 if ( $union !== 'OR' ) {
1554 return $return;
1555 }
1556 }
1557
1558 return $return;
1559 }
1560
1561 $screen = get_current_screen();
1562
1563 if ( ! $screen ) {
1564 return;
1565 }
1566
1567 $screen_id = $screen->id;
1568
1569 return in_array( $screen_id, array( $post_type, "edit-{$post_type}" ) );
1570 }
1571
1572 function learn_press_get_notice_dismiss( $context, $type = 'transient' ) {
1573 if ( $type == 'transient' ) {
1574 return get_transient( 'learn_press_dismiss_notice_' . $context );
1575 }
1576
1577 return get_option( 'learn_press_dismiss_notice_' . $context );
1578 }
1579
1580 if ( ! function_exists( 'learn_press_course_insert_section' ) ) {
1581 function learn_press_course_insert_section( $section = array() ) {
1582 global $wpdb;
1583
1584 $section = wp_parse_args(
1585 $section,
1586 array(
1587 'section_name' => '',
1588 'section_course_id' => 0,
1589 'section_order' => 0,
1590 'section_description' => '',
1591 )
1592 );
1593
1594 $section = stripslashes_deep( $section );
1595
1596 extract( $section );
1597
1598 $insert_data = compact( 'section_name', 'section_course_id', 'section_order', 'section_description' );
1599
1600 $wpdb->insert(
1601 $wpdb->learnpress_sections,
1602 $insert_data,
1603 array( '%s', '%d', '%d' )
1604 );
1605
1606 return $wpdb->insert_id;
1607 }
1608 }
1609
1610 if ( ! function_exists( 'learn_press_course_insert_section_item' ) ) {
1611 function learn_press_course_insert_section_item( $item_data = array() ) {
1612 global $wpdb;
1613
1614 $wpdb->insert(
1615 $wpdb->learnpress_section_items,
1616 array(
1617 'section_id' => $item_data['section_id'],
1618 'item_id' => $item_data['item_id'],
1619 'item_order' => $item_data['item_order'],
1620 'item_type' => $item_data['item_type'],
1621 ),
1622 array(
1623 '%d',
1624 '%d',
1625 '%d',
1626 '%s',
1627 )
1628 );
1629
1630 return $wpdb->insert_id;
1631 }
1632 }
1633
1634 if ( ! function_exists( 'learn_press_duplicate_post' ) ) {
1635 /**
1636 * Duplicate post.
1637 *
1638 * @param null $post_id
1639 * @param array $args
1640 * @param bool $meta
1641 *
1642 * @return bool|mixed
1643 * @since 3.0.0
1644 */
1645 function learn_press_duplicate_post( $post_id = null, $args = array(), $meta = true ) {
1646 $post = get_post( $post_id );
1647
1648 if ( ! $post ) {
1649 return false;
1650 }
1651
1652 $default = array(
1653 'comment_status' => $post->comment_status,
1654 'ping_status' => $post->ping_status,
1655 'post_author' => get_current_user_id(),
1656 'post_content' => $post->post_content,
1657 'post_excerpt' => $post->post_excerpt,
1658 'post_parent' => $post->post_parent,
1659 'post_password' => $post->post_password,
1660 'post_status' => 'draft',
1661 'post_title' => sprintf(
1662 '%1$s (%2$s)',
1663 $post->post_title,
1664 _x( 'Copy', 'Duplicate item title suffix', 'learnpress' )
1665 ),
1666 'post_type' => $post->post_type,
1667 'to_ping' => $post->to_ping,
1668 'menu_order' => $post->menu_order,
1669 'exclude_meta' => array(),
1670 );
1671
1672 $args = wp_parse_args( $args, $default );
1673 $exclude_meta = array();
1674
1675 if ( ! empty( $args['exclude_meta'] ) ) {
1676 $exclude_meta = $args['exclude_meta'];
1677 unset( $args['exclude_meta'] );
1678 }
1679
1680 $new_post_id = wp_insert_post( $args );
1681
1682 if ( ! is_wp_error( $new_post_id ) && $meta ) {
1683 learn_press_duplicate_post_meta( $post_id, $new_post_id, $exclude_meta );
1684
1685 $taxonomies = get_object_taxonomies( $post->post_type );
1686
1687 foreach ( $taxonomies as $taxonomy ) {
1688 $post_terms = wp_get_object_terms( $post_id, $taxonomy, array( 'fields' => 'slugs' ) );
1689 wp_set_object_terms( $new_post_id, $post_terms, $taxonomy, false );
1690 }
1691 }
1692
1693 return apply_filters( 'learn_press_duplicate_post', $new_post_id, $post_id );
1694 }
1695 }
1696
1697 /**
1698 * Duplicate post meta.
1699 *
1700 * @editor tungnx
1701 * @sicne 3.0.0
1702 * @version 4.0.1
1703 */
1704 if ( ! function_exists( 'learn_press_duplicate_post_meta' ) ) {
1705 function learn_press_duplicate_post_meta( $old_post_id, $new_post_id, $excerpt = array() ) {
1706 $lp_db = LP_Database::getInstance();
1707
1708 try {
1709 $excerpt = array_merge( array( '_edit_lock', '_edit_last' ), $excerpt );
1710 $excerpt_name_keys = implode( "','", $excerpt );
1711 $sql_query = $lp_db->wpdb->prepare(
1712 "INSERT INTO $lp_db->tb_postmeta (post_id, meta_key, meta_value)
1713 SELECT %d, pmc.meta_key, pmc.meta_value
1714 FROM $lp_db->tb_postmeta AS pmc
1715 WHERE post_id = %d
1716 AND meta_key not in ('{$excerpt_name_keys}')
1717 ",
1718 $new_post_id,
1719 $old_post_id
1720 );
1721
1722 $lp_db->check_execute_has_error();
1723
1724 $lp_db->wpdb->query( $sql_query );
1725 } catch ( Throwable $e ) {
1726 error_log( $e->getMessage() );
1727 }
1728 }
1729 }
1730
1731 if ( ! function_exists( 'learn_press_sort_questions' ) ) {
1732 function learn_press_sort_questions( $types ) {
1733 $user_id = get_current_user_id();
1734 $question_types = get_user_meta( $user_id, '_learn_press_memorize_question_types', true );
1735
1736 if ( ! empty( $question_types ) ) {
1737 $sort = array();
1738 arsort( $types );
1739 $new_types = array();
1740 $ktypes = array_keys( $types );
1741
1742 for ( $i = 0; $i < count( $ktypes ) - 1; $i ++ ) {
1743 $max = $i;
1744
1745 if ( ! isset( $question_types[ $ktypes[ $i ] ] ) ) {
1746 $question_types[ $ktypes[ $i ] ] = 0;
1747 }
1748
1749 for ( $j = $i + 1; $j < count( $ktypes ); $j ++ ) {
1750 if ( isset( $question_types[ $ktypes[ $j ] ], $question_types[ $ktypes[ $max ] ] )
1751 && $question_types[ $ktypes[ $j ] ] > $question_types[ $ktypes[ $max ] ]
1752 ) {
1753 $max = $j;
1754 }
1755 }
1756
1757 $tmp = $ktypes[ $i ];
1758 $ktypes[ $i ] = $ktypes[ $max ];
1759 $ktypes[ $max ] = $tmp;
1760 }
1761
1762 $ktypes = array_flip( $ktypes );
1763 $types = array_merge( $ktypes, $types );
1764 }
1765
1766 return $types;
1767 }
1768 }
1769
1770 if ( ! function_exists( 'learn_press_duplicate_question' ) ) {
1771 function learn_press_duplicate_question( $question_id = null, $quiz_id = null, $args = array() ) {
1772 if ( ! $question_id || ! get_post( $question_id ) ) {
1773 return new WP_Error( sprintf( __( 'Question id %s does not exist.', 'learnpress' ), $question_id ) );
1774 }
1775
1776 if ( $quiz_id && ! get_post( $quiz_id ) ) {
1777 return new WP_Error( sprintf( __( 'Quiz id %s does not exist.', 'learnpress' ), $quiz_id ) );
1778 }
1779
1780 global $wpdb;
1781 $new_question_id = learn_press_duplicate_post( $question_id, $args );
1782
1783 if ( $quiz_id ) {
1784 $sql = $wpdb->prepare(
1785 "
1786 SELECT * FROM $wpdb->learnpress_quiz_questions WHERE quiz_id = %d AND question_id = %d
1787 ",
1788 $quiz_id,
1789 $question_id
1790 );
1791
1792 $quiz_question_data = $wpdb->get_row( $sql );
1793 $max_order = $wpdb->get_var(
1794 $wpdb->prepare(
1795 "SELECT max(question_order) FROM {$wpdb->prefix}learnpress_quiz_questions WHERE quiz_id = %d",
1796 $quiz_id
1797 )
1798 );
1799
1800 if ( $quiz_question_data ) {
1801 $wpdb->insert(
1802 $wpdb->learnpress_quiz_questions,
1803 array(
1804 'quiz_id' => $quiz_id,
1805 'question_id' => $new_question_id,
1806 'question_order' => $max_order + 1,
1807 'params' => $quiz_question_data->params,
1808 ),
1809 array(
1810 '%d',
1811 '%d',
1812 '%d',
1813 '%s',
1814 )
1815 );
1816 }
1817 }
1818
1819 $sql = $wpdb->prepare(
1820 "
1821 SELECT * FROM $wpdb->learnpress_question_answers WHERE question_id = %d
1822 ",
1823 $question_id
1824 );
1825
1826 $question_answers = $wpdb->get_results( $sql );
1827
1828 if ( $question_answers ) {
1829 foreach ( $question_answers as $q_a ) {
1830 $wpdb->insert(
1831 $wpdb->learnpress_question_answers,
1832 array(
1833 'question_id' => $new_question_id,
1834 'title' => $q_a->title,
1835 'value' => $q_a->value,
1836 'is_true' => $q_a->is_true,
1837 'order' => $q_a->order,
1838 ),
1839 array(
1840 '%d',
1841 '%s',
1842 '%s',
1843 )
1844 );
1845 }
1846 }
1847
1848 return $new_question_id;
1849 }
1850 }
1851
1852 if ( ! function_exists( 'learn_press_duplicate_quiz' ) ) {
1853
1854 function learn_press_duplicate_quiz( $quiz_id = null, $args = array() ) {
1855 global $wpdb;
1856
1857 $new_quiz_id = learn_press_duplicate_post( $quiz_id, $args, true );
1858 $quiz = LP_Quiz::get_quiz( $quiz_id );
1859 if ( ! $quiz ) {
1860 return 0;
1861 }
1862
1863 $questions = $quiz->get_question_ids();
1864
1865 if ( $questions ) {
1866 foreach ( $questions as $question_id ) {
1867 $new_question_id = learn_press_duplicate_post( $question_id );
1868
1869 $sql = $wpdb->prepare(
1870 "
1871 SELECT * FROM $wpdb->learnpress_quiz_questions WHERE quiz_id = %d AND question_id = %d
1872 ",
1873 $quiz_id,
1874 $question_id
1875 );
1876
1877 $quiz_question_data = $wpdb->get_row( $sql );
1878
1879 if ( $quiz_question_data ) {
1880 $wpdb->insert(
1881 $wpdb->learnpress_quiz_questions,
1882 array(
1883 'quiz_id' => $new_quiz_id,
1884 'question_id' => $new_question_id,
1885 'question_order' => $quiz_question_data->question_order,
1886 'params' => $quiz_question_data->params,
1887 ),
1888 array(
1889 '%d',
1890 '%d',
1891 '%d',
1892 '%s',
1893 )
1894 );
1895 }
1896
1897 $sql = $wpdb->prepare(
1898 "
1899 SELECT * FROM $wpdb->learnpress_question_answers WHERE question_id = %d
1900 ",
1901 $question_id
1902 );
1903
1904 $question_answers = $wpdb->get_results( $sql );
1905 if ( $question_answers ) {
1906 foreach ( $question_answers as $q_a ) {
1907 $wpdb->insert(
1908 $wpdb->learnpress_question_answers,
1909 array(
1910 'question_id' => $new_question_id,
1911 'title' => $q_a->title,
1912 'value' => $q_a->value,
1913 'is_true' => $q_a->is_true,
1914 'order' => $q_a->order,
1915 ),
1916 array(
1917 '%d',
1918 '%s',
1919 '%s',
1920 )
1921 );
1922 }
1923 }
1924 }
1925 }
1926
1927 return $new_quiz_id;
1928 }
1929 }
1930
1931 /**
1932 * Get general data to render in chart
1933 *
1934 * @param null $from
1935 * @param null $by
1936 * @param float $time_ago
1937 *
1938 * @return array
1939 */
1940 function learn_press_get_chart_general( $from = null, $by = null, $time_ago = 0 ) {
1941 global $wpdb;
1942
1943 $labels = array();
1944 $datasets = array();
1945
1946 if ( is_null( $from ) ) {
1947 $from = current_time( 'mysql', 1 );
1948 }
1949
1950 if ( is_null( $by ) ) {
1951 $by = 'days';
1952 }
1953
1954 $results = array(
1955 'all' => array(),
1956 'public' => array(),
1957 'pending' => array(),
1958 'free' => array(),
1959 'paid' => array(),
1960 );
1961
1962 $results = array(
1963 'course' => array(),
1964 'lesson' => array(),
1965 'quiz' => array(),
1966 'student' => array(),
1967 'teacher' => array(),
1968 'revenue' => array(),
1969 );
1970
1971 $from_time = is_numeric( $from ) ? $from : strtotime( $from );
1972 $_from = '';
1973 $_to = '';
1974 $_sql_format = '';
1975 $date_format = '';
1976
1977 switch ( $by ) {
1978 case 'days':
1979 $date_format = 'M d Y';
1980 $_from = - $time_ago + 1;
1981 $_from = date( 'Y-m-d', strtotime( "{$_from} {$by}", $from_time ) );
1982 $_to = date( 'Y-m-d', $from_time );
1983 $_sql_format = '%Y-%m-%d';
1984 $_key_format = 'Y-m-d';
1985 break;
1986
1987 case 'months':
1988 $date_format = 'M Y';
1989 $_from = - $time_ago + 1;
1990 $_from = date( 'Y-m-01', strtotime( "{$_from} {$by}", $from_time ) );
1991 $days = date( 't', mktime( 0, 0, 0, date( 'm', $from_time ), 1, date( 'Y', $from_time ) ) );
1992 $_to = date( 'Y-m-' . $days, $from_time );
1993 $_sql_format = '%Y-%m';
1994 $_key_format = 'Y-m';
1995 break;
1996
1997 case 'years':
1998 $date_format = 'Y';
1999 $_from = - $time_ago + 1;
2000 $_from = date( 'Y-01-01', strtotime( "{$_from} {$by}", $from_time ) );
2001 $days = date( 't', mktime( 0, 0, 0, date( 'm', $from_time ), 1, date( 'Y', $from_time ) ) );
2002 $_to = date( 'Y-12-' . $days, $from_time );
2003 $_sql_format = '%Y';
2004 $_key_format = 'Y';
2005 break;
2006
2007 }
2008
2009 $query_where = '';
2010 if ( current_user_can( LP_TEACHER_ROLE ) ) {
2011 $user_id = learn_press_get_current_user_id();
2012 $query_where .= $wpdb->prepare( ' AND c.post_author=%d ', $user_id );
2013 }
2014
2015 $query = $wpdb->prepare(
2016 "
2017 SELECT count(c.ID) as c, DATE_FORMAT( c.post_date, %s) as d
2018 FROM {$wpdb->posts} c
2019 WHERE 1
2020 {$query_where}
2021 AND c.post_status IN('publish', 'pending') AND c.post_type = %s
2022 GROUP BY d
2023 HAVING d BETWEEN %s AND %s
2024 ORDER BY d ASC
2025 ",
2026 $_sql_format,
2027 'lp_course',
2028 $_from,
2029 $_to
2030 );
2031
2032 if ( $_results = $wpdb->get_results( $query ) ) {
2033 foreach ( $_results as $k => $v ) {
2034 $results['all'][ $v->d ] = $v;
2035 }
2036 }
2037
2038 $query = $wpdb->prepare(
2039 "
2040 SELECT count(c.ID) as c, DATE_FORMAT( c.post_date, %s) as d
2041 FROM {$wpdb->posts} c
2042 WHERE 1
2043 {$query_where}
2044 AND c.post_status = %s AND c.post_type = %s
2045 GROUP BY d
2046 HAVING d BETWEEN %s AND %s
2047 ORDER BY d ASC
2048 ",
2049 $_sql_format,
2050 'publish',
2051 'lp_course',
2052 $_from,
2053 $_to
2054 );
2055
2056 if ( $_results = $wpdb->get_results( $query ) ) {
2057 foreach ( $_results as $k => $v ) {
2058 $results['publish'][ $v->d ] = $v;
2059 }
2060 }
2061
2062 $query = $wpdb->prepare(
2063 "
2064 SELECT count(c.ID) as c, DATE_FORMAT( c.post_date, %s) as d
2065 FROM {$wpdb->posts} c
2066 INNER JOIN {$wpdb->postmeta} cm ON cm.post_id = c.ID
2067 WHERE 1
2068 {$query_where}
2069 AND c.post_status = %s AND c.post_type = %s
2070 GROUP BY d
2071 HAVING d BETWEEN %s AND %s
2072 ORDER BY d ASC
2073 ",
2074 $_sql_format,
2075 'publish',
2076 'lp_course',
2077 $_from,
2078 $_to
2079 );
2080
2081 if ( $_results = $wpdb->get_results( $query ) ) {
2082 foreach ( $_results as $k => $v ) {
2083 $results['paid'][ $v->d ] = $v;
2084 }
2085 }
2086
2087 for ( $i = - $time_ago + 1; $i <= 0; $i ++ ) {
2088 $date = strtotime( "$i $by", $from_time );
2089 $labels[] = date( $date_format, $date );
2090 $key = date( $_key_format, $date );
2091
2092 $all = ! empty( $results['all'][ $key ] ) ? $results['all'][ $key ]->c : 0;
2093 $publish = ! empty( $results['publish'][ $key ] ) ? $results['publish'][ $key ]->c : 0;
2094 $paid = ! empty( $results['paid'][ $key ] ) ? $results['paid'][ $key ]->c : 0;
2095
2096 $datasets[0]['data'][] = $all;
2097 $datasets[1]['data'][] = $publish;
2098 $datasets[2]['data'][] = $all - $publish;
2099 $datasets[3]['data'][] = $paid;
2100 $datasets[4]['data'][] = $all - $paid;
2101 }
2102
2103 $dataset_params = array(
2104 array(
2105 'color1' => 'rgba(47, 167, 255, %s)',
2106 'color2' => '#FFF',
2107 'label' => __( 'All', 'learnpress' ),
2108 ),
2109 array(
2110 'color1' => 'rgba(212, 208, 203, %s)',
2111 'color2' => '#FFF',
2112 'label' => __( 'Publish', 'learnpress' ),
2113 ),
2114 array(
2115 'color1' => 'rgba(234, 199, 155, %s)',
2116 'color2' => '#FFF',
2117 'label' => __( 'Pending', 'learnpress' ),
2118 ),
2119 array(
2120 'color1' => 'rgba(234, 199, 155, %s)',
2121 'color2' => '#FFF',
2122 'label' => __( 'Paid', 'learnpress' ),
2123 ),
2124 array(
2125 'color1' => 'rgba(234, 199, 155, %s)',
2126 'color2' => '#FFF',
2127 'label' => __( 'Free', 'learnpress' ),
2128 ),
2129 );
2130
2131 foreach ( $dataset_params as $k => $v ) {
2132 $datasets[ $k ]['fillColor'] = sprintf( $v['color1'], '0.2' );
2133 $datasets[ $k ]['strokeColor'] = sprintf( $v['color1'], '1' );
2134 $datasets[ $k ]['pointColor'] = sprintf( $v['color1'], '1' );
2135 $datasets[ $k ]['pointStrokeColor'] = $v['color2'];
2136 $datasets[ $k ]['pointHighlightFill'] = $v['color2'];
2137 $datasets[ $k ]['pointHighlightStroke'] = sprintf( $v['color1'], '1' );
2138 $datasets[ $k ]['label'] = $v['label'];
2139 }
2140
2141 return array(
2142 'labels' => $labels,
2143 'datasets' => $datasets,
2144 'sql' => $query,
2145 );
2146 }
2147
2148 function learn_press_get_default_section( $section = null ) {
2149 if ( ! $section ) {
2150 $section = new stdClass();
2151 }
2152 foreach (
2153 array(
2154 'section_id' => null,
2155 'section_name' => '',
2156 'section_course_id' => null,
2157 'section_order' => null,
2158 'section_description' => '',
2159 ) as $k => $v
2160 ) {
2161 if ( ! property_exists( $section, $k ) ) {
2162 $section->{$k} = $v;
2163 }
2164 }
2165
2166 return $section;
2167 }
2168
2169 /**
2170 * Display time fields for a post in editing mode.
2171 *
2172 * @param int $edit
2173 * @param int $for_post
2174 * @param int $tab_index
2175 * @param int $multi
2176 */
2177 function learn_press_touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) {
2178 global $wp_locale;
2179 $post = get_post();
2180
2181 if ( $for_post ) {
2182 $edit = ! ( in_array(
2183 $post->post_status,
2184 array(
2185 'draft',
2186 'pending',
2187 )
2188 ) && ( ! $post->post_date_gmt || '0000-00-00 00:00:00' == $post->post_date_gmt ) );
2189 }
2190
2191 $tab_index_attribute = '';
2192 if ( (int) $tab_index > 0 ) {
2193 $tab_index_attribute = " tabindex=\"$tab_index\"";
2194 }
2195
2196 $time_adj = current_time( 'timestamp' );
2197 $post_date = ( $for_post ) ? $post->post_date : get_comment()->comment_date;
2198 $jj = ( $edit ) ? mysql2date( 'd', $post_date, false ) : gmdate( 'd', $time_adj );
2199 $mm = ( $edit ) ? mysql2date( 'm', $post_date, false ) : gmdate( 'm', $time_adj );
2200 $aa = ( $edit ) ? mysql2date( 'Y', $post_date, false ) : gmdate( 'Y', $time_adj );
2201 $hh = ( $edit ) ? mysql2date( 'H', $post_date, false ) : gmdate( 'H', $time_adj );
2202 $mn = ( $edit ) ? mysql2date( 'i', $post_date, false ) : gmdate( 'i', $time_adj );
2203 $ss = ( $edit ) ? mysql2date( 's', $post_date, false ) : gmdate( 's', $time_adj );
2204
2205 $cur_jj = gmdate( 'd', $time_adj );
2206 $cur_mm = gmdate( 'm', $time_adj );
2207 $cur_aa = gmdate( 'Y', $time_adj );
2208 $cur_hh = gmdate( 'H', $time_adj );
2209 $cur_mn = gmdate( 'i', $time_adj );
2210
2211 $map = array(
2212 'mm' => array( $mm, $cur_mm ),
2213 'jj' => array( $jj, $cur_jj ),
2214 'aa' => array( $aa, $cur_aa ),
2215 'hh' => array( $hh, $cur_hh ),
2216 'mn' => array( $mn, $cur_mn ),
2217 );
2218
2219 foreach ( $map as $timeunit => $value ) {
2220 list( $unit, $curr ) = $value;
2221
2222 echo '<input type="hidden" id="hidden_' . $timeunit . '" name="hidden_' . $timeunit . '" value="' . $unit . '" />' . "\n";
2223 $cur_timeunit = 'cur_' . $timeunit;
2224 echo '<input type="hidden" id="' . $cur_timeunit . '" name="' . $cur_timeunit . '" value="' . $curr . '" />' . "\n";
2225 }
2226 }
2227
2228 /**
2229 * Return id of current screen.
2230 *
2231 * @return bool|string
2232 * @since 3.2.6
2233 */
2234 function learn_press_get_screen_id() {
2235 _deprecated_function( __METHOD__, '4.2.3.6' );
2236 $screen = get_current_screen();
2237 $screen_id = $screen ? $screen->id : false;
2238
2239 return $screen_id;
2240 }
2241
2242 require_once 'class-lp-post-type-actions.php';
2243