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.1 3.6.2 3.6.3 3.6.4 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 3.9.1 3.9.10 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9
tutor / classes / Shortcode.php
tutor / classes Last commit date
Addons.php 4 years ago Admin.php 4 years ago Ajax.php 4 years ago Announcements.php 4 years ago Assets.php 4 years ago Backend_Page_Trait.php 4 years ago Course.php 3 years ago Course_Filter.php 4 years ago Course_List.php 3 years ago Course_Settings_Tabs.php 4 years ago Course_Widget.php 4 years ago Custom_Validation.php 4 years ago Dashboard.php 3 years ago FormHandler.php 4 years ago Frontend.php 3 years ago Gutenberg.php 4 years ago Input.php 3 years ago Instructor.php 4 years ago Instructors_List.php 3 years ago Lesson.php 4 years ago Options_V2.php 3 years ago Post_types.php 4 years ago Private_Course_Access.php 4 years ago Q_and_A.php 4 years ago Question_Answers_List.php 4 years ago Quiz.php 4 years ago Quiz_Attempts_List.php 4 years ago RestAPI.php 4 years ago Reviews.php 4 years ago Rewrite_Rules.php 4 years ago Shortcode.php 4 years ago Student.php 4 years ago Students_List.php 4 years ago Taxonomies.php 4 years ago Template.php 3 years ago Theme_Compatibility.php 5 years ago Tools.php 3 years ago Tools_V2.php 4 years ago Tutor.php 3 years ago TutorEDD.php 4 years ago Tutor_Base.php 5 years ago Tutor_List_Table.php 4 years ago Tutor_Setup.php 4 years ago Upgrader.php 4 years ago User.php 4 years ago Utils.php 3 years ago Video_Stream.php 4 years ago Withdraw.php 3 years ago Withdraw_Requests_List.php 4 years ago WooCommerce.php 3 years ago
Shortcode.php
406 lines
1 <?php
2 /**
3 * Class Shortcode
4 *
5 * @package TUTOR
6 *
7 * @since v.1.0.0
8 */
9
10 namespace TUTOR;
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit;
14 }
15
16 class Shortcode {
17
18 private $instructor_layout = array(
19 'default',
20 'cover',
21 'minimal',
22 'portrait-horizontal',
23 'minimal-horizontal',
24 );
25
26 public function __construct() {
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' ) );
44 }
45
46 /**
47 * @return mixed
48 *
49 * Instructor Registration Shortcode
50 *
51 * @since v.1.0.0
52 */
53 public function student_registration_form() {
54 ob_start();
55 if ( is_user_logged_in() ) {
56 tutor_load_template( 'dashboard.logged-in' );
57 } else {
58 tutor_load_template( 'dashboard.registration' );
59 }
60 return apply_filters( 'tutor/student/register', ob_get_clean() );
61 }
62
63 /**
64 * @return mixed
65 *
66 * Tutor Dashboard for students
67 *
68 * @since v.1.0.0
69 */
70 public function tutor_dashboard() {
71 global $wp_query;
72
73 ob_start();
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>');
86 }
87 return apply_filters( 'tutor_dashboard/index', ob_get_clean() );
88 }
89
90 /**
91 * @return mixed
92 *
93 * Instructor Registration Shortcode
94 *
95 * @since v.1.0.0
96 */
97 public function instructor_registration_form() {
98 ob_start();
99 if ( is_user_logged_in() ) {
100 tutor_load_template( 'dashboard.instructor.logged-in' );
101 } else {
102 tutor_load_template( 'dashboard.instructor.registration' );
103 }
104 return apply_filters( 'tutor_dashboard/student/index', ob_get_clean() );
105 }
106
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 }
406