PluginProbe
Tutor LMS – eLearning and online course solution / 2.0.7
Tutor LMS – eLearning and online course solution v2.0.7
4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 4.0.0 3.9.15 3.9.14 3.9.13 3.9.12 3.9.11 trunk 1.0.0 1.0.0-alpha 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 All 191 releases
← All changes | classes/Shortcode.php +351 -19 1.0.02.0.7 View file →
@@ -1,7 +1,8 @@
1 1 <?php
2 2 /**
3 3 * Class Shortcode
4 + *
4 5 * @package TUTOR
5 6 *
6 7 * @since v.1.0.0
7 8 */
@@ -7,17 +8,40 @@
7 8 */
8 9
9 10 namespace TUTOR;
10 11
11 -if ( ! defined( 'ABSPATH' ) )
12 +if ( ! defined( 'ABSPATH' ) ) {
12 13 exit;
14 +}
13 15
14 16 class Shortcode {
15 17
18 + private $instructor_layout = array(
19 + 'default',
20 + 'cover',
21 + 'minimal',
22 + 'portrait-horizontal',
23 + 'minimal-horizontal',
24 + );
25 +
16 26 public function __construct() {
17 - add_shortcode('tutor_student_registration_form', array($this, 'student_registration_form'));
18 - add_shortcode('tutor_student_dashboard', array($this, 'tutor_student_dashboard'));
19 - add_shortcode('tutor_instructor_registration_form', array($this, 'instructor_registration_form'));
27 + add_shortcode( 'tutor_student_registration_form', array( $this, 'student_registration_form' ) );
28 + add_shortcode( 'tutor_dashboard', array( $this, 'tutor_dashboard' ) );
29 + add_shortcode( 'tutor_instructor_registration_form', array( $this, 'instructor_registration_form' ) );
30 + add_shortcode( 'tutor_course', array( $this, 'tutor_course' ) );
31 +
32 + add_shortcode( 'tutor_instructor_list', array( $this, 'tutor_instructor_list' ) );
33 + add_action( 'tutor_options_after_instructors', array( $this, 'tutor_instructor_layout' ) );
34 + add_action( 'wp_ajax_load_filtered_instructor', array( $this, 'load_filtered_instructor' ) );
35 + add_action( 'wp_ajax_nopriv_load_filtered_instructor', array( $this, 'load_filtered_instructor' ) );
36 +
37 + /**
38 + * Load more categories
39 + *
40 + * @since 2.0.0
41 + */
42 + add_action( 'wp_ajax_show_more', array( $this, 'show_more' ) );
43 + add_action( 'wp_ajax_nopriv_show_more', array( $this, 'show_more' ) );
20 44 }
21 45
22 46 /**
23 47 * @return mixed
@@ -25,14 +49,14 @@
25 49 * Instructor Registration Shortcode
26 50 *
27 51 * @since v.1.0.0
28 52 */
29 - public function student_registration_form(){
53 + public function student_registration_form() {
30 54 ob_start();
31 - if (is_user_logged_in()){
32 - tutor_load_template( 'dashboard.student.logged-in' );
33 - }else{
34 - tutor_load_template( 'dashboard.student.registration' );
55 + if ( is_user_logged_in() ) {
56 + tutor_load_template( 'dashboard.logged-in' );
57 + } else {
58 + tutor_load_template( 'dashboard.registration' );
35 59 }
36 60 return apply_filters( 'tutor/student/register', ob_get_clean() );
37 61 }
38 62
@@ -42,16 +66,26 @@
42 66 * Tutor Dashboard for students
43 67 *
44 68 * @since v.1.0.0
45 69 */
46 - public function tutor_student_dashboard(){
70 + public function tutor_dashboard() {
71 + global $wp_query;
72 +
47 73 ob_start();
48 - if (is_user_logged_in()){
49 - tutor_load_template( 'dashboard.student.index' );
50 - }else{
51 - tutor_load_template( 'global.login' );
74 + if ( is_user_logged_in() ) {
75 + /**
76 + * Added isset() Condition to avoid infinite loop since v.1.5.4
77 + * This has cause error by others plugin, Such AS SEO
78 + */
79 +
80 + if ( ! isset( $wp_query->query_vars['tutor_dashboard_page'] ) ) {
81 + tutor_load_template( 'dashboard', array( 'is_shortcode' => true ) );
82 + }
83 + } else {
84 + $login_url = tutor_utils()->get_option('enable_tutor_native_login', null, true, true) ? '' : wp_login_url(tutor()->current_url);
85 + echo sprintf( __('Please %sSign-In%s to view this page', 'tutor'), '<a data-login_url="'.$login_url.'" href="#" class="tutor-open-login-modal">', '</a>');
52 86 }
53 - return apply_filters( 'tutor_dashboard/student/index', ob_get_clean() );
87 + return apply_filters( 'tutor_dashboard/index', ob_get_clean() );
54 88 }
55 89
56 90 /**
57 91 * @return mixed
@@ -59,15 +93,313 @@
59 93 * Instructor Registration Shortcode
60 94 *
61 95 * @since v.1.0.0
62 96 */
63 - public function instructor_registration_form(){
97 + public function instructor_registration_form() {
64 98 ob_start();
65 - if (is_user_logged_in()){
99 + if ( is_user_logged_in() ) {
66 100 tutor_load_template( 'dashboard.instructor.logged-in' );
67 - }else{
101 + } else {
68 102 tutor_load_template( 'dashboard.instructor.registration' );
69 103 }
70 104 return apply_filters( 'tutor_dashboard/student/index', ob_get_clean() );
71 105 }
72 106
73 -}
107 + /**
108 + * @param $atts
109 + *
110 + * @return string
111 + *
112 + * Shortcode for getting course
113 + */
114 + public function tutor_course( $atts ) {
115 + $course_post_type = tutor()->course_post_type;
116 +
117 + $a = shortcode_atts(
118 + array(
119 + 'post_type' => $course_post_type,
120 + 'post_status' => 'publish',
121 +
122 + 'id' => '',
123 + 'exclude_ids' => '',
124 + 'category' => '',
125 +
126 + 'orderby' => 'ID',
127 + 'order' => 'DESC',
128 + 'count' => 6,
129 + 'paged' => get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1,
130 + ),
131 + $atts
132 + );
133 +
134 + if ( ! empty( $a['id'] ) ) {
135 + $ids = (array) explode( ',', $a['id'] );
136 + $a['post__in'] = $ids;
137 + }
138 +
139 + if ( ! empty( $a['exclude_ids'] ) ) {
140 + $exclude_ids = (array) explode( ',', $a['exclude_ids'] );
141 + $a['post__not_in'] = $exclude_ids;
142 + }
143 + if ( ! empty( $a['category'] ) ) {
144 + $category = (array) explode( ',', $a['category'] );
145 +
146 + $a['tax_query'] = array();
147 +
148 + $category_ids = array_filter($category, function($id){
149 + return is_numeric($id);
150 + });
151 +
152 + $category_names = array_filter($category, function($id){
153 + return !is_numeric($id);
154 + });
155 +
156 + if(!empty($category_ids)) {
157 + $a['tax_query'] = array(
158 + array(
159 + 'taxonomy' => 'course-category',
160 + 'field' => 'term_id',
161 + 'terms' => $category_ids,
162 + 'operator' => 'IN',
163 + ),
164 + );
165 + }
166 +
167 + if(!empty($category_names)) {
168 + $a['tax_query'] = array(
169 + array(
170 + 'taxonomy' => 'course-category',
171 + 'field' => 'name',
172 + 'terms' => $category_names,
173 + 'operator' => 'IN',
174 + ),
175 + );
176 + }
177 +
178 + }
179 + $a['posts_per_page'] = (int) $a['count'];
180 +
181 + wp_reset_query();
182 + $the_query = new \WP_Query( $a );
183 +
184 +
185 + // Load the renderer now
186 + ob_start();
187 +
188 + if ( $the_query->have_posts() ) {
189 + tutor_load_template('archive-course-init', array(
190 + 'course_filter' => isset( $atts['course_filter'] ) && $atts['course_filter'] == 'on',
191 + 'supported_filters' => tutor_utils()->get_option( 'supported_course_filters', array() ),
192 + 'loop_content_only' => false,
193 + 'column_per_row' => isset( $atts['column_per_row'] ) ? $atts['column_per_row'] : null,
194 + 'course_per_page' => $a['posts_per_page'],
195 + 'show_pagination' => isset( $atts['show_pagination'] ) && $atts['show_pagination']=='on',
196 + 'the_query' => $the_query
197 + ));
198 + } else {
199 + tutor_utils()->tutor_empty_state( tutor_utils()->not_found_text() );
200 + }
201 +
202 + $output = ob_get_clean();
203 +
204 + wp_reset_postdata();
205 +
206 + return $output;
207 + }
208 +
209 + private function prepare_instructor_list( $current_page, $atts, $cat_ids = array(), $keyword = '' ) {
210 +
211 + $default_pagination = tutor_utils()->get_option('pagination_per_page', 9);
212 + $limit = (int) sanitize_text_field( tutor_utils()->array_get( 'count', $atts, $default_pagination ) );
213 + $page = $current_page - 1;
214 + $rating_filter = isset( $_POST['rating_filter'] ) ? $_POST['rating_filter'] : '';
215 +
216 + /**
217 + * Sort by Relevant | New | Popular
218 + *
219 + * @since v2.0.0
220 + */
221 + $short_by = '';
222 + if ( isset( $_POST['short_by'] ) && $_POST['short_by'] === 'new' ) {
223 + $short_by = 'new';
224 + } elseif ( isset( $_POST['short_by'] ) && $_POST['short_by'] === 'popular' ) {
225 + $short_by = 'popular';
226 + } else {
227 + $short_by = 'ASC';
228 + }
229 + $instructors = tutor_utils()->get_instructors( $limit * $page, $limit, $keyword, '', '', $short_by, 'approved', $cat_ids, $rating_filter );
230 + $instructors_count = tutor_utils()->get_instructors( $limit * $page, $limit, $keyword, '', '', $short_by, 'approved', $cat_ids, $rating_filter, true );
231 +
232 + $layout = sanitize_text_field( tutor_utils()->array_get( 'layout', $atts, '' ) );
233 + $layout = in_array( $layout, $this->instructor_layout ) ? $layout : tutor_utils()->get_option( 'instructor_list_layout', $this->instructor_layout[0] );
234 + $default_col = tutor_utils()->get_option( 'courses_col_per_row', 3 );
235 +
236 + $payload = array(
237 + 'instructors' => is_array( $instructors ) ? $instructors : array(),
238 + 'instructors_count' => $instructors_count,
239 + 'column_count' => sanitize_text_field( tutor_utils()->array_get( 'column_per_row', $atts, $default_col ) ),
240 + 'layout' => $layout,
241 + 'limit' => $limit,
242 + 'current_page' => $current_page,
243 + 'filter' => $atts
244 + );
245 +
246 + return $payload;
247 + }
248 +
249 + /**
250 + * @param $atts
251 + *
252 + * @return string
253 + *
254 + * Shortcode for getting instructors
255 + */
256 + public function tutor_instructor_list( $atts ) {
257 + global $wpdb;
258 + ! is_array( $atts ) ? $atts = array() : 0;
259 +
260 + $current_page = (int) tutor_utils()->array_get( 'instructor-page', $_GET, 1 );
261 + $current_page = $current_page >= 1 ? $current_page : 1;
262 +
263 + $show_filter = isset( $atts['filter'] ) ? $atts['filter'] == 'on' : tutor_utils()->get_option( 'instructor_list_show_filter', false );
264 + $atts['show_filter'] = $show_filter;
265 +
266 + // Get instructor list to sow
267 + $payload = $this->prepare_instructor_list( $current_page, $atts );
268 + $payload['show_filter'] = $show_filter;
269 +
270 + ob_start();
271 + tutor_load_template( 'shortcode.tutor-instructor', $payload );
272 + $content = ob_get_clean();
273 +
274 + if ( $show_filter ) {
275 + $limit = 8;
276 + $course_taxonomy = 'course-category';
277 + $course_cats = $wpdb->get_results($wpdb->prepare(
278 + "SELECT * FROM {$wpdb->terms} AS term
279 + INNER JOIN {$wpdb->term_taxonomy} AS taxonomy
280 + ON taxonomy.term_id = term.term_id AND taxonomy.taxonomy = %s
281 + ORDER BY term.term_id DESC
282 + LIMIT %d",
283 + $course_taxonomy,
284 + $limit
285 + ));
286 +
287 + $all_cats = $wpdb->get_var(
288 + $wpdb->prepare(
289 + "SELECT COUNT(*) as total FROM {$wpdb->terms} AS term
290 + INNER JOIN {$wpdb->term_taxonomy} AS taxonomy
291 + ON taxonomy.term_id = term.term_id AND taxonomy.taxonomy = %s
292 + ORDER BY term.term_id DESC",
293 + $course_taxonomy
294 + )
295 + );
296 +
297 + $attributes = $payload;
298 + unset( $attributes['instructors'] );
299 +
300 + $payload = array(
301 + 'show_filter' => $show_filter,
302 + 'content' => $content,
303 + 'categories' => $course_cats,
304 + 'all_cats' => $all_cats,
305 + 'attributes' => array_merge( $atts, $attributes ),
306 + );
307 +
308 + ob_start();
309 +
310 + tutor_load_template( 'shortcode.instructor-filter', $payload );
311 +
312 + $content = ob_get_clean();
313 + }
314 +
315 + return $content;
316 + }
317 +
318 + /**
319 + * Load more categories
320 + * handle ajax request
321 + *
322 + * @package Instructor List
323 + * @return string
324 + * @since v2.0.0
325 + */
326 + public function show_more() {
327 + global $wpdb;
328 + tutor_utils()->checking_nonce();
329 + $term_id = isset( $_POST['term_id'] ) ? sanitize_text_field( $_POST['term_id'] ) : 0;
330 + $limit = 8;
331 + $course_taxonomy = 'course-category';
332 +
333 + $remaining_categories = $wpdb->get_var(
334 + $wpdb->prepare(
335 + " SElECT COUNT(*) AS total FROM {$wpdb->terms} AS term
336 + INNER JOIN {$wpdb->term_taxonomy} AS taxonomy
337 + ON taxonomy.term_id = term.term_id AND taxonomy.taxonomy = %s
338 + WHERE term.term_id < %d
339 + ORDER BY term.term_id DESC
340 + ",
341 + $course_taxonomy,
342 + $term_id
343 + )
344 + );
345 +
346 + $add_categories = $wpdb->get_results(
347 + $wpdb->prepare(
348 + " SElECT * FROM {$wpdb->terms} term
349 + INNER JOIN {$wpdb->term_taxonomy} as taxonomy
350 + ON taxonomy.term_id = term.term_id AND taxonomy.taxonomy = %s
351 + WHERE term.term_id < %d
352 + ORDER BY term.term_id DESC
353 + LIMIT %d
354 + ",
355 + $course_taxonomy,
356 + $term_id,
357 + $limit
358 + )
359 + );
360 + $show_more = false;
361 + if ( $remaining_categories > $limit ) {
362 + $show_more = true;
363 + }
364 + $response = array(
365 + 'categories' => $add_categories,
366 + 'show_more' => $show_more,
367 + 'remaining' => $remaining_categories,
368 + );
369 + wp_send_json_success( $response );
370 + exit;
371 + }
372 +
373 + /**
374 + * Filter instructor
375 + */
376 + public function load_filtered_instructor() {
377 + tutor_utils()->checking_nonce();
378 +
379 + $_post = tutor_sanitize_data($_POST);
380 + $current_page = (int) sanitize_text_field( tutor_utils()->array_get( 'current_page', $_post, 1 ) );
381 + $keyword = (string) sanitize_text_field( tutor_utils()->array_get( 'keyword', $_post, '' ) );
382 +
383 + $category = (array) tutor_utils()->array_get( 'category', $_post, array() );
384 + $category = array_filter(
385 + $category,
386 + function( $cat ) {
387 + return is_numeric( $cat );
388 + }
389 + );
390 +
391 + $data = $this->prepare_instructor_list( $current_page, $_post, $category, $keyword );
392 +
393 + ob_start();
394 + tutor_load_template( 'shortcode.tutor-instructor', $data );
395 + wp_send_json_success( array('html' => ob_get_clean() ) );
396 + exit;
397 + }
398 +
399 + /**
400 + * Show layout selection dashboard in instructor setting
401 + */
402 + public function tutor_instructor_layout() {
403 + tutor_load_template( 'instructor-setting', array( 'templates' => $this->instructor_layout ) );
404 + }
405 +}