PluginProbe
Tutor LMS – eLearning and online course solution / 3.9.2
Tutor LMS – eLearning and online course solution v3.9.2
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
tutor / classes / Course_Embed.php

Course_Embed.php in Tutor LMS – eLearning and online course solution 3.9.2, at classes/Course_Embed.php

107 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Manage course embed
4 *
5 * @package Tutor
6 * @author Themeum <support@themeum.com>
7 * @link https://themeum.com
8 * @since 2.1.0
9 */
10
11 namespace TUTOR;
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 /**
18 * Course embed class
19 *
20 * @since 2.1.0
21 */
22 class Course_Embed {
23
24 /**
25 * Register hooks
26 *
27 * @since 2.1.0
28 * @return void
29 */
30 public function __construct() {
31 add_filter( 'tutor_get_template_path', __CLASS__ . '::filter_template_path', 100, 2 );
32 add_filter( 'embed_oembed_html', __CLASS__ . '::oembed_iframe_overrides', 10, 3 );
33 }
34
35 /**
36 * Filter oembed data
37 *
38 * @since 2.1.0
39 *
40 * @param string $html html content to filter.
41 * @param string $url post embed url.
42 * @param array $attr attrs.
43 *
44 * @return string customized html content
45 */
46 public static function oembed_iframe_overrides( $html, $url, $attr ) {
47
48 $post_id = url_to_postid( $url );
49 if ( ! $post_id || tutor()->course_post_type !== get_post_type( $post_id ) ) {
50 return $html;
51 }
52
53 if ( strpos( $html, '<iframe' ) !== false ) {
54 $html = str_replace(
55 '<iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted" style="position: absolute; clip: rect(1px, 1px, 1px, 1px);"',
56 '<iframe class="wp-embedded-content" sandbox="allow-forms allow-popups allow-scripts allow-same-origin allow-top-navigation" security="restricted" ',
57 $html
58 );
59
60 $html = preg_replace( '/( height=".*")/i', ' height="620" marginwidth="0" marginheight="0" frameborder="0" scrolling="no" ', $html );
61
62 $html = str_replace(
63 '<blockquote class="wp-embedded-content"',
64 '<blockquote class="wp-embedded-content" style="display:none" ',
65 $html
66 );
67 return $html;
68 } else {
69 return $html;
70 }
71 }
72
73 /**
74 * Filter template
75 *
76 * @since 2.1.0
77 *
78 * @param string $template_location default template location.
79 * @param string $template template name.
80 *
81 * @return string
82 */
83 public static function filter_template_path( $template_location, $template ) {
84 $post_id = get_the_ID();
85 if ( get_post_type( $post_id ) === tutor()->course_post_type && function_exists( 'is_embed' ) && is_embed() ) {
86 if ( 'single-course' === $template ) {
87 $template_location = tutor()->path . 'templates/course-embed.php';
88 }
89 }
90 return $template_location;
91 }
92
93 /**
94 * Check if current course is embedded
95 *
96 * @since 2.1.0
97 * @return boolean
98 */
99 public static function is_embed_course() {
100 $post_id = get_the_ID();
101 if ( get_post_type( $post_id ) === tutor()->course_post_type && function_exists( 'is_embed' ) && is_embed() ) {
102 return true;
103 }
104 return false;
105 }
106 }
107