ap-cp-media-player
4 months ago
ap-html5-audio-player
4 months ago
ap-mp3-jplayer
4 months ago
dokan
4 months ago
wcfm
4 months ago
wcv
4 months ago
ap-compact-audio-player.addon.php
4 months ago
ap-cp-media-player.addon.php
4 months ago
ap-html5-audio-player.addon.php
4 months ago
ap-mp3-jplayer.addon.php
4 months ago
dokan.addon.php
4 months ago
mvx.addon.php
4 months ago
wcfm.addon.php
4 months ago
wcv.addon.php
4 months ago
ap-cp-media-player.addon.php
121 lines
| 1 | <?php |
| 2 | if ( ! class_exists( 'WCMP_CPMEDIAPLAYER_ADDON' ) ) { |
| 3 | class WCMP_CPMEDIAPLAYER_ADDON { |
| 4 | |
| 5 | private $_wcmp; |
| 6 | |
| 7 | public function __construct( $wcmp ) { |
| 8 | $this->_wcmp = $wcmp; |
| 9 | add_action( 'wcmp_addon_general_settings', array( $this, 'general_settings' ) ); |
| 10 | add_action( 'wcmp_save_setting', array( $this, 'save_general_settings' ) ); |
| 11 | add_filter( 'wcmp_audio_tag', array( $this, 'generate_player' ), 99, 4 ); |
| 12 | add_filter( 'wcmp_widget_audio_tag', array( $this, 'generate_player' ), 99, 4 ); |
| 13 | add_filter( 'wcmp_product_attr', array( $this, 'product_attr' ), 99, 3 ); |
| 14 | add_filter( 'wcmp_global_attr', array( $this, 'global_attr' ), 99, 2 ); |
| 15 | } // End __construct |
| 16 | |
| 17 | private function _player_exists() { |
| 18 | return defined( 'CPMP_VERSION' ); |
| 19 | } // End _player_exists |
| 20 | |
| 21 | private function _is_enabled() { |
| 22 | return get_option( 'wcmp_addon_player' ) == 'cpmediaplayer'; |
| 23 | } // End _is_enabled |
| 24 | |
| 25 | private function _load_skins( $selected_option ) { |
| 26 | // Skins |
| 27 | $options = ''; |
| 28 | if ( defined( 'CPMP_PLUGIN_DIR' ) ) { |
| 29 | $skins = array(); |
| 30 | $skin_dir = CPMP_PLUGIN_DIR . '/skins'; |
| 31 | if ( file_exists( $skin_dir ) ) { |
| 32 | $d = dir( $skin_dir ); |
| 33 | while ( false !== ( $entry = $d->read() ) ) { |
| 34 | if ( '.' != $entry && '..' != $entry && is_dir( $skin_dir . '/' . $entry ) ) { |
| 35 | $this_skin = $skin_dir . '/' . $entry . '/'; |
| 36 | if ( file_exists( $this_skin ) ) { |
| 37 | $skin_data = parse_ini_file( $this_skin . 'config.ini', true ); |
| 38 | $options .= '<option value="' . $skin_data['id'] . '" ' . ( $skin_data['id'] == $selected_option ? 'SELECTED' : '' ) . '>' . esc_html( $skin_data['name'] ) . '</option>'; |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | $d->close(); |
| 43 | } |
| 44 | } |
| 45 | return $options; |
| 46 | } // End _load_skins |
| 47 | |
| 48 | private function _get_skin() { |
| 49 | return get_option( 'wcmp_cpmediaplayer_addon_skin', 'classic-skin' ); |
| 50 | } // End _get_skin |
| 51 | |
| 52 | private function _set_skin( $v ) { |
| 53 | update_option( 'wcmp_cpmediaplayer_addon_skin', $v ); |
| 54 | } // End _set_skin |
| 55 | |
| 56 | public function general_settings() { |
| 57 | $enabled = ( $this->_player_exists() && $this->_is_enabled() ); |
| 58 | |
| 59 | print '<tr><td><input aria-label="' . esc_attr__( 'Use CP Media Player instead of the current plugin players', 'music-player-for-woocommerce' ) . '" type="radio" value="cpmediaplayer" name="wcmp_addon_player" ' . ( $enabled ? 'CHECKED' : '' ) . ( $this->_player_exists() ? '' : ' DISABLED' ) . ' class="wcmp_radio"></td><td width="100%"><b>' . esc_html__( 'Use "CP Media Player" instead of the current plugin players', 'music-player-for-woocommerce' ) . '</b><br> |
| 60 | ' . esc_html__( 'Select player skin', 'music-player-for-woocommerce' ) . ': <select name="wcmp_cpmediaplayer_addon_skin" ' . ( $this->_player_exists() ? '' : ' DISABLED' ) . '>' . $this->_load_skins( $this->_get_skin() ) . '</select> |
| 61 | <br><i>' . |
| 62 | ( $this->_player_exists() |
| 63 | ? __( 'The player functions configured above do not apply, except for audio protection if applicable.<br>This player <b>will take precedence</b> over the player configured in the products\' settings.', 'music-player-for-woocommerce' ) // phpcs:ignore WordPress.Security.EscapeOutput |
| 64 | : esc_html__( 'The "CP Media Player" plugin is not installed on your WordPress.', 'music-player-for-woocommerce' ) |
| 65 | ) |
| 66 | . '</i></td></tr>'; |
| 67 | } // End general_settings |
| 68 | |
| 69 | public function save_general_settings() { |
| 70 | if ( $this->_player_exists() ) { |
| 71 | if ( isset( $_POST['wcmp_addon_player'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 72 | update_option( 'wcmp_addon_player', sanitize_text_field( wp_unslash( $_POST['wcmp_addon_player'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification |
| 73 | } else { |
| 74 | delete_option( 'wcmp_addon_player' ); |
| 75 | } |
| 76 | |
| 77 | if ( isset( $_POST['wcmp_cpmediaplayer_addon_skin'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 78 | $this->_set_skin( sanitize_text_field( wp_unslash( $_POST['wcmp_cpmediaplayer_addon_skin'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification |
| 79 | } |
| 80 | } |
| 81 | } // End save_general_settings |
| 82 | |
| 83 | public function generate_player( $player, $product_id, $file_index, $url ) { |
| 84 | if ( $this->_player_exists() && $this->_is_enabled() ) { |
| 85 | wp_enqueue_style( 'wcmp-ap-cp-media-player-style', plugin_dir_url( __FILE__ ) . 'ap-cp-media-player/style.css', array(), WCMP_VERSION ); |
| 86 | return do_shortcode( '[cpm-player skin="' . esc_attr( $this->_get_skin() ) . '" playlist="false" type="audio"][cpm-item file="' . esc_attr( $url ) . '"][/cpm-player]' ); |
| 87 | } |
| 88 | return $player; |
| 89 | } // End generate_player |
| 90 | |
| 91 | public function product_attr( $value, $product_id, $attribute ) { |
| 92 | if ( |
| 93 | ! is_admin() && |
| 94 | $this->_player_exists() && |
| 95 | $this->_is_enabled() && |
| 96 | '_wcmp_player_controls' == $attribute |
| 97 | ) { |
| 98 | return 'all'; |
| 99 | } |
| 100 | |
| 101 | return $value; |
| 102 | } // End product_attr |
| 103 | |
| 104 | public function global_attr( $value, $attribute ) { |
| 105 | if ( |
| 106 | ! is_admin() && |
| 107 | $this->_player_exists() && |
| 108 | $this->_is_enabled() && |
| 109 | '_wcmp_player_controls' == $attribute |
| 110 | ) { |
| 111 | return 'all'; |
| 112 | } |
| 113 | |
| 114 | return $value; |
| 115 | } // End global_attr |
| 116 | |
| 117 | } // End WCMP_CPMEDIAPLAYER_ADDON |
| 118 | } |
| 119 | |
| 120 | new WCMP_CPMEDIAPLAYER_ADDON( $wcmp ); |
| 121 |