PluginProbe
WP Courses LMS – Online Courses Builder, eLearning Courses, Courses Solution, Education Courses / trunk
WP Courses LMS – Online Courses Builder, eLearning Courses, Courses Solution, Education Courses vtrunk
3.2.30 trunk 3.1.40 3.1.41 3.1.42 3.1.43 3.2.0 3.2.1 3.2.10 3.2.11 3.2.12 3.2.13 3.2.14 3.2.15 3.2.16 3.2.17 3.2.18 3.2.19 3.2.2 3.2.20 3.2.21 3.2.22 3.2.23 3.2.24 3.2.25 All 36 releases
wp-courses / classes / WPC_Shortcodes.php

WPC_Shortcodes.php in WP Courses LMS – Online Courses Builder, eLearning Courses, Courses Solution, Education Courses trunk, at classes/WPC_Shortcodes.php

145 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class WPC_Shortcodes {
4
5 public $user_id;
6
7 public function __construct() {
8 $this->user_id = get_current_user_id();
9
10 add_shortcode('wpc_courses', array($this, 'renderAjaxView'));
11 add_shortcode( 'courses', array($this, 'renderAjaxView') ); // legacy shortcode
12 add_shortcode('wpc_profile', array($this, 'profilePage'));
13 add_shortcode('lesson_count', array($this, 'lessonCount'));
14 add_shortcode('course_count', array($this, 'courseCount'));
15
16 }
17
18 function lessonCount(){
19 $args = array(
20 'post_type' => 'lesson',
21 'post_status' => 'publish',
22 'posts_per_page' => -1
23 );
24 $query = new WP_Query($args);
25 return $query->post_count;
26 }
27
28 function courseCount(){
29 $args = array(
30 'post_type' => 'course',
31 'post_status' => 'publish',
32 'posts_per_page' => -1
33 );
34 $query = new WP_Query($args);
35 return $query->post_count;
36 }
37
38 function renderAjaxView() {
39 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
40
41 if( is_plugin_active( 'wp-courses-woocommerce/wp-courses-woocommerce.php') !== false ) {
42 return 'Courses have moved.' . '<br><a class="wpc-btn" href="' . get_post_type_archive_link( 'course' ) . '">' . __('View Courses', 'wp-courses') . '</a>';
43 }
44
45 $logged_in = is_user_logged_in() === true ? 'true' : 'false'; ?>
46
47 <?php ob_start(); ?>
48
49 <div id="wpc-course-app" class="wpc-main"></div>
50
51 <script type="text/javascript">
52 jQuery(document).ready(function(){
53 new WPC_UI({
54 'initView' : 'course-archive',
55 'loggedIn' : <?php echo $logged_in; ?>,
56 'userID' : <?php echo get_current_user_id(); ?>,
57 ajaxLinks : true,
58 fixedToolbar : <?php echo get_option('wpc_fix_toolbar_top') == 'true' ? 'true' : 'false'; ?>,
59 fixedToolbarOffset : <?php echo get_option('wpc_fixed_toolbar_offset') == 'true' ? 'true' : 'false'; ?>,
60 adminBar : <?php echo is_admin_bar_showing() === true ? 'true' : 'false'; ?>,
61 });
62 });
63 </script>
64
65 <?php if(current_user_can('administrator')) {
66 $post_id = get_the_ID();
67 wpc_front_end_editor($post_id); // FEE injected via [wpc_courses] and [courses] shortcode
68 } ?>
69
70 <?php return ob_get_clean();
71
72 }
73
74 function profilePage($atts){
75
76 ob_start();
77
78 $args = shortcode_atts( array(
79 'user_id' => get_current_user_id(),
80 ), $atts );
81
82 if(!is_user_logged_in() && !isset($args['user_id'])){
83 return '<div class="wpc-msg">' . esc_html__('You must be logged in to view your profile', 'wp-courses') . '.</div>';
84 } ?>
85
86 <div id="wpc-profile-page"></div>
87
88 <script>
89 jQuery(document).ready(function($){
90 var userID = <?php echo (int) $args['user_id']; ?>;
91
92 // Used to overwrite window.wpcd.user.ID etc. in ui.js
93 // And to load the profile window
94 new WPC_UI({
95 loggedIn : true,
96 userID : userID,
97 onLoad : false,
98 ajaxLinks : false,
99 });
100 });
101 </script>
102
103 <?php return ob_get_clean(); ?>
104
105 <?php }
106
107 }
108
109 add_action('init', 'wpc_shortcodes_init');
110
111 function wpc_shortcodes_init(){
112 new WPC_Shortcodes();
113 }
114
115
116 function wpc_get_main_shortcode_page_url()
117 {
118 $pages = get_pages();
119 $pattern = get_shortcode_regex(array('wpc_courses'));
120
121 foreach ($pages as $page) {
122 if (
123 preg_match_all('/' . $pattern . '/s', $page->post_content, $matches)
124 && array_key_exists(2, $matches)
125 && in_array('wpc_courses', $matches[2])
126 ) {
127 return get_permalink( $page->ID );
128 }
129 }
130 }
131
132 function wpc_get_courses_hash($params)
133 {
134 $paramStr = '?';
135 $index = 0;
136
137 foreach ($params as $key => $value) {
138 $paramStr .= ($index + 1) <= count($params) && $index !== 0 ? '&' : '';
139 $paramStr .= $key . '=' . $value;
140
141 $index++;
142 }
143
144 return '#' . base64_encode($paramStr);
145 }