Resources


Source

File: classes/Resources.php

class Resources {

	public function __construct() {
		add_action( 'init', [ $this, 'add_theme_support' ] );

		add_action( 'admin_enqueue_scripts', [ $this, 'load_resources' ] );
		add_action( 'wp_enqueue_scripts', [ $this, 'load_resources' ] );

		add_filter( 'dozent_load_chart_js', [ $this, 'load_chart_js' ], 10, 2 );
		add_filter( 'dozent_load_datepicker', [ $this, 'load_datepicker' ], 10, 2 );
	}

	public function add_theme_support() {
		//Register Nav menu for the Dashboard
		register_nav_menus( [ 'dozent-dashboard-nav' => __( 'Dozent - Dashboard Nav', 'dozent' ) ] );

	}

	public function load_resources( $page ) {
		$script_debug = dozent_script_debug();
		$suffix       = $script_debug ? '' : '.min';
		$rtl_dir      = is_rtl() ? '-rtl' : '';
		$load_select2 = false;

		if ( is_admin() ) {

			if ( $page === 'dozent-lms_page_dozent-options' ) {
				wp_enqueue_media();
			}

			wp_enqueue_style( 'dozent-noUiSlider', DOZENT_URL . "assets/plugins/noUiSlider/nouislider{$suffix}.css", [],
				DOZENT_VERSION );

			wp_enqueue_script( 'dozent-noUiSlider', DOZENT_URL . "assets/plugins/noUiSlider/nouislider{$suffix}.js", [],
				DOZENT_VERSION, true );

			$load_select2 = true;

		}

		$load_select2 = apply_filters( 'dozent_load_select2', $load_select2 );
		if ( $load_select2 ){
			$this->load_select2();
		}

		/**
		 * Tell DozentLMS if Chart.JS should load
		 *
		 * @since DozentLMS 1.0.0
		 *
		 * @param bool
		 * @param string $current_page
		 */

		$load_chart_js = apply_filters( 'dozent_load_chart_js', false, $page );
		if ( $load_chart_js ) {
			wp_enqueue_script( 'dozent-chart.js', DOZENT_URL . "assets/plugins/Chart.js/Chart.bundle.min.js",
				array(), DOZENT_VERSION );
		}

		//Load Datepicker
		$load_datepicker = apply_filters( 'dozent_load_datepicker', false, $page );
		if ( $load_datepicker ) {
			wp_enqueue_script( 'jquery-ui-datepicker' );
		}

		$this->load_videojs();

		wp_enqueue_style( 'dozent', DOZENT_URL . "assets/css{$rtl_dir}/dozent{$suffix}.css", [], DOZENT_VERSION );
		wp_enqueue_script( 'dozent', DOZENT_URL . "assets/js/dozent{$suffix}.js", [ 'jquery' ], DOZENT_VERSION, true );
	}

	public function load_select2(){

		wp_enqueue_style( 'dozent-select2', DOZENT_URL . "assets/plugins/select2/css/select2.min.css", [],
			DOZENT_VERSION );
		wp_enqueue_script( 'dozent-select2', DOZENT_URL . "assets/plugins/select2/js/select2.min.js", [],
			DOZENT_VERSION, true );
	}

	public function load_chart_js( $bool, $page ){

		if ( is_dozent_dashboard() ){
			$current_page = dozent_get_dashboard_url_segment();

			if ( $current_page === 'earning' ){
				$bool = true;
			}
		}

		return $bool;
	}

	public function load_datepicker( $bool, $page ){

		if ( is_dozent_dashboard() ){
			$current_page = dozent_get_dashboard_url_segment();

			if ( $current_page === 'earning' ){
				$bool = true;
			}
		}

		return $bool;
	}

	public function load_videojs(){

		if ( is_dozent_course() || is_dozent_single_lecture() ) {

			if ( ! apply_filters( 'load_dozent_videojs', true ) ){
				return;
			}

			$video_type = dozent_has_video( null, 'source' );
			if ( ! $video_type || $video_type === 'embedded' ){
				return;
			}

			wp_enqueue_style( 'dozent-videojs', DOZENT_URL . "assets/plugins/video-js/video-js.min.css", [], DOZENT_VERSION );
			wp_enqueue_script( 'dozent-videojs', DOZENT_URL . "assets/plugins/video-js/video.min.js", [], DOZENT_VERSION, true );

			if ( $video_type === 'youtube' ){
				wp_enqueue_script( 'dozent-videojs-youtube', DOZENT_URL . "assets/plugins/video-js/Youtube.min.js", [ 'dozent-videojs' ], DOZENT_VERSION, true );
			}

			if ( $video_type === 'vimeo' ){
				wp_enqueue_script( 'dozent-videojs-vimeo', DOZENT_URL ."assets/plugins/video-js/Vimeo.min.js", [ 'dozent-videojs' ], DOZENT_VERSION, true );
			}

			add_filter( 'dozent_body_class' , [ $this, 'add_body_class_video' ] );

		}
	}

	public function add_body_class_video( $classes ){
		$classes[] = 'dozent-has-video';
		return $classes;
	}

}

Methods