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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 4 years ago Course_Filter.php 4 years ago Course_List.php 4 years ago Course_Settings_Tabs.php 4 years ago Course_Widget.php 4 years ago Custom_Validation.php 4 years ago Dashboard.php 4 years ago FormHandler.php 4 years ago Frontend.php 4 years ago Gutenberg.php 4 years ago Input.php 4 years ago Instructor.php 4 years ago Instructors_List.php 4 years ago Lesson.php 4 years ago Options_V2.php 4 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 4 years ago Theme_Compatibility.php 5 years ago Tools.php 4 years ago Tools_V2.php 4 years ago Tutor.php 4 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 4 years ago Video_Stream.php 4 years ago Withdraw.php 4 years ago Withdraw_Requests_List.php 4 years ago WooCommerce.php 4 years ago
Shortcode.php
376 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 array(
148 'taxonomy' => 'course-category',
149 'field' => 'term_id',
150 'terms' => $category,
151 'operator' => 'IN',
152 ),
153 );
154 }
155 $a['posts_per_page'] = (int) $a['count'];
156
157 wp_reset_query();
158 $the_query = new \WP_Query( $a );
159
160
161 // Load the renderer now
162 ob_start();
163 tutor_load_template('archive-course-init', array(
164 'course_filter' => isset( $atts['course_filter'] ) && $atts['course_filter'] == 'on',
165 'supported_filters' => tutor_utils()->get_option( 'supported_course_filters', array() ),
166 'loop_content_only' => false,
167 'column_per_row' => isset( $atts['column_per_row'] ) ? $atts['column_per_row'] : null,
168 'course_per_page' => $a['posts_per_page'],
169 'show_pagination' => isset( $atts['show_pagination'] ) && $atts['show_pagination']=='on',
170 'the_query' => $the_query
171 ));
172 $output = ob_get_clean();
173
174 wp_reset_postdata();
175
176 return $output;
177 }
178
179 private function prepare_instructor_list( $current_page, $atts, $cat_ids = array(), $keyword = '' ) {
180
181 $default_pagination = tutor_utils()->get_option('pagination_per_page', 9);
182 $limit = (int) sanitize_text_field( tutor_utils()->array_get( 'count', $atts, $default_pagination ) );
183 $page = $current_page - 1;
184 $rating_filter = isset( $_POST['rating_filter'] ) ? $_POST['rating_filter'] : '';
185
186 /**
187 * Short by Relevant | New | Popular
188 *
189 * @since v2.0.0
190 */
191 $short_by = '';
192 if ( isset( $_POST['short_by'] ) && $_POST['short_by'] === 'new' ) {
193 $short_by = 'new';
194 } elseif ( isset( $_POST['short_by'] ) && $_POST['short_by'] === 'popular' ) {
195 $short_by = 'popular';
196 } else {
197 $short_by = 'ASC';
198 }
199 $instructors = tutor_utils()->get_instructors( $limit * $page, $limit, $keyword, '', '', $short_by, 'approved', $cat_ids, $rating_filter );
200 $instructors_count = tutor_utils()->get_instructors( $limit * $page, $limit, $keyword, '', '', $short_by, 'approved', $cat_ids, $rating_filter, true );
201
202 $layout = sanitize_text_field( tutor_utils()->array_get( 'layout', $atts, '' ) );
203 $layout = in_array( $layout, $this->instructor_layout ) ? $layout : tutor_utils()->get_option( 'instructor_list_layout', $this->instructor_layout[0] );
204 $default_col = tutor_utils()->get_option( 'courses_col_per_row', 3 );
205
206 $payload = array(
207 'instructors' => is_array( $instructors ) ? $instructors : array(),
208 'instructors_count' => $instructors_count,
209 'column_count' => sanitize_text_field( tutor_utils()->array_get( 'column_per_row', $atts, $default_col ) ),
210 'layout' => $layout,
211 'limit' => $limit,
212 'current_page' => $current_page,
213 'filter' => $atts
214 );
215
216 return $payload;
217 }
218
219 /**
220 * @param $atts
221 *
222 * @return string
223 *
224 * Shortcode for getting instructors
225 */
226 public function tutor_instructor_list( $atts ) {
227 global $wpdb;
228 ! is_array( $atts ) ? $atts = array() : 0;
229
230 $current_page = (int) tutor_utils()->array_get( 'instructor-page', $_GET, 1 );
231 $current_page = $current_page >= 1 ? $current_page : 1;
232
233 $show_filter = isset( $atts['filter'] ) ? $atts['filter'] == 'on' : tutor_utils()->get_option( 'instructor_list_show_filter', false );
234 $atts['show_filter'] = $show_filter;
235
236 // Get instructor list to sow
237 $payload = $this->prepare_instructor_list( $current_page, $atts );
238 $payload['show_filter'] = $show_filter;
239
240 ob_start();
241 tutor_load_template( 'shortcode.tutor-instructor', $payload );
242 $content = ob_get_clean();
243
244 if ( $show_filter ) {
245 $limit = 8;
246 $course_taxonomy = 'course-category';
247 $course_cats = $wpdb->get_results($wpdb->prepare(
248 "SELECT * FROM {$wpdb->terms} AS term
249 INNER JOIN {$wpdb->term_taxonomy} AS taxonomy
250 ON taxonomy.term_id = term.term_id AND taxonomy.taxonomy = %s
251 ORDER BY term.term_id DESC
252 LIMIT %d",
253 $course_taxonomy,
254 $limit
255 ));
256
257 $all_cats = $wpdb->get_var(
258 $wpdb->prepare(
259 "SELECT COUNT(*) as total FROM {$wpdb->terms} AS term
260 INNER JOIN {$wpdb->term_taxonomy} AS taxonomy
261 ON taxonomy.term_id = term.term_id AND taxonomy.taxonomy = %s
262 ORDER BY term.term_id DESC",
263 $course_taxonomy
264 )
265 );
266
267 $attributes = $payload;
268 unset( $attributes['instructors'] );
269
270 $payload = array(
271 'show_filter' => $show_filter,
272 'content' => $content,
273 'categories' => $course_cats,
274 'all_cats' => $all_cats,
275 'attributes' => array_merge( $atts, $attributes ),
276 );
277
278 ob_start();
279
280 tutor_load_template( 'shortcode.instructor-filter', $payload );
281
282 $content = ob_get_clean();
283 }
284
285 return $content;
286 }
287
288 /**
289 * Load more categories
290 * handle ajax request
291 *
292 * @package Instructor List
293 * @return string
294 * @since v2.0.0
295 */
296 public function show_more() {
297 global $wpdb;
298 tutor_utils()->checking_nonce();
299 $term_id = isset( $_POST['term_id'] ) ? sanitize_text_field( $_POST['term_id'] ) : 0;
300 $limit = 8;
301 $course_taxonomy = 'course-category';
302
303 $remaining_categories = $wpdb->get_var(
304 $wpdb->prepare(
305 " SElECT COUNT(*) AS total FROM {$wpdb->terms} AS term
306 INNER JOIN {$wpdb->term_taxonomy} AS taxonomy
307 ON taxonomy.term_id = term.term_id AND taxonomy.taxonomy = %s
308 WHERE term.term_id < %d
309 ORDER BY term.term_id DESC
310 ",
311 $course_taxonomy,
312 $term_id
313 )
314 );
315
316 $add_categories = $wpdb->get_results(
317 $wpdb->prepare(
318 " SElECT * FROM {$wpdb->terms} term
319 INNER JOIN {$wpdb->term_taxonomy} as taxonomy
320 ON taxonomy.term_id = term.term_id AND taxonomy.taxonomy = %s
321 WHERE term.term_id < %d
322 ORDER BY term.term_id DESC
323 LIMIT %d
324 ",
325 $course_taxonomy,
326 $term_id,
327 $limit
328 )
329 );
330 $show_more = false;
331 if ( $remaining_categories > $limit ) {
332 $show_more = true;
333 }
334 $response = array(
335 'categories' => $add_categories,
336 'show_more' => $show_more,
337 'remaining' => $remaining_categories,
338 );
339 wp_send_json_success( $response );
340 exit;
341 }
342
343 /**
344 * Filter instructor
345 */
346 public function load_filtered_instructor() {
347 tutor_utils()->checking_nonce();
348
349 $_post = tutor_sanitize_data($_POST);
350 $current_page = (int) sanitize_text_field( tutor_utils()->array_get( 'current_page', $_post, 1 ) );
351 $keyword = (string) sanitize_text_field( tutor_utils()->array_get( 'keyword', $_post, '' ) );
352
353 $category = (array) tutor_utils()->array_get( 'category', $_post, array() );
354 $category = array_filter(
355 $category,
356 function( $cat ) {
357 return is_numeric( $cat );
358 }
359 );
360
361 $data = $this->prepare_instructor_list( $current_page, $_post, $category, $keyword );
362
363 ob_start();
364 tutor_load_template( 'shortcode.tutor-instructor', $data );
365 wp_send_json_success( array('html' => ob_get_clean() ) );
366 exit;
367 }
368
369 /**
370 * Show layout selection dashboard in instructor setting
371 */
372 public function tutor_instructor_layout() {
373 tutor_load_template( 'instructor-setting', array( 'templates' => $this->instructor_layout ) );
374 }
375 }
376