Advertisement
cipher87

Audio Player

May 29th, 2019
448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 32.33 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Audio File Playlist Element
  4.  *
  5.  * Shortcode that allows to add an audio playlist
  6.  *
  7.  * @since 4.1.3
  8.  */
  9. if ( ! defined( 'ABSPATH' ) ) {  exit;  }    // Exit if accessed directly
  10.  
  11. if ( ! class_exists( 'avia_sc_audio_player' ) )
  12. {
  13.    
  14.     class avia_sc_audio_player extends aviaShortcodeTemplate
  15.     {
  16.         /**
  17.          *
  18.          * @since 4.1.3
  19.          * @var int
  20.          */
  21.         static protected $instance = 0;
  22.        
  23.         /**
  24.          *
  25.          * @since 4.1.3
  26.          * @var string
  27.          */
  28.         protected $extra_style;
  29.        
  30.         /**
  31.          *
  32.          * @since 4.1.3
  33.          * @var string
  34.          */
  35.         static protected $non_ajax_style = '';
  36.        
  37.        
  38.         /**
  39.          *
  40.          * @since 4.1.3
  41.          * @var array
  42.          */
  43.         protected $atts;
  44.  
  45.         /**
  46.          *
  47.          * @since 4.1.3
  48.          * @param AviaBuilder $builder
  49.          */
  50.         public function __construct( $builder )
  51.         {
  52.             parent::__construct( $builder );
  53.            
  54.             $this->extra_style = '';
  55.             $this->atts = array();
  56.         }
  57.        
  58.         /**
  59.          *
  60.          * @since 4.1.3
  61.          */
  62.         public function __destruct()
  63.         {
  64.             parent::__destruct();
  65.            
  66.             unset( $this->atts );
  67.         }
  68.        
  69.         /**
  70.          * Create the config array for the shortcode button
  71.          *
  72.          * @since 4.1.3
  73.          */
  74.         public function shortcode_insert_button()
  75.         {
  76.             $this->config['self_closing']   =   'no';
  77.            
  78.             $this->config['name']           = __( 'Audio Player', 'avia_framework' );
  79.             $this->config['tab']            = __( 'Media Elements', 'avia_framework' );
  80.             $this->config['icon']           = AviaBuilder::$path['imagesURL'] . "sc-audio-player.png";
  81.             $this->config['order']          = 60;
  82.             $this->config['target']         = 'avia-target-insert';
  83.             $this->config['shortcode']      = 'av_player';
  84.             $this->config['shortcode_nested'] = array( 'av_playlist_element' );
  85.             $this->config['tooltip']        = __( 'Add an audio player element', 'avia_framework' );
  86.             $this->config['tinyMCE']        = array( 'disable' => "true" );
  87.             $this->config['drag-level']     = 3;
  88.             $this->config['preview']        = false;
  89.             $this->config['disabling_allowed'] = true;
  90.             $this->config['disabled']       = array(
  91.             'condition' =>( avia_get_option('disable_mediaelement') == 'disable_mediaelement' ),
  92.             'text'   => __( 'This element is disabled in your theme options. You can enable it in Enfold &raquo; Performance', 'avia_framework' ));
  93.                                                    
  94.                                                    
  95.            
  96.         }
  97.        
  98.         function extra_assets()
  99.         {
  100.             //load css
  101.             wp_enqueue_style( 'avia-module-audioplayer' , AviaBuilder::$path['pluginUrlRoot'].'avia-shortcodes/audio-player/audio-player.css' , array('avia-layout'), false );
  102.            
  103.                 //load js
  104.             wp_enqueue_script( 'avia-module-audioplayer' , AviaBuilder::$path['pluginUrlRoot'].'avia-shortcodes/audio-player/audio-player.js' , array('avia-shortcodes'), false, TRUE );
  105.  
  106.         }
  107.        
  108.        
  109.         /**
  110.         * Popup Elements
  111.         *
  112.         * If this function is defined in a child class the element automatically gets an edit button, that, when pressed
  113.         * opens a modal window that allows to edit the element properties
  114.         *
  115.         * @since 4.1.3
  116.         * @return void
  117.         */
  118.         public function popup_elements()
  119.         {
  120.             //if the element is disabled
  121.             if($this->config['disabled']['condition'] == true)
  122.             {
  123.                 $this->elements = array(
  124.                    
  125.                     array(
  126.                             "name"  => __("Element disabled",'avia_framework' ),
  127.                             "desc"  => $this->config['disabled']['text'].
  128.                             '<br/><br/><a target="_blank" href="'.admin_url('admin.php?page=avia#goto_performance').'">'.__("Enable it here",'avia_framework' )."</a>",
  129.                             "type"  => "heading",
  130.                             "description_class" => "av-builder-note av-error",
  131.                             )
  132.                         );
  133.                
  134.                 return;
  135.             }
  136.            
  137.            
  138.             $this->elements = array(
  139.  
  140.                     array(
  141.                         "type"          => "tab_container",
  142.                         'nodescription' => true
  143.                     ),
  144.  
  145.                     array(
  146.                         "type"          => "tab",
  147.                         "name"          => __( "Playlist" , 'avia_framework' ),
  148.                         'nodescription' => true
  149.                     ),
  150.                
  151.                         array( 
  152.                             "name"          => __( "Autoplay", 'avia_framework' ),
  153.                             "desc"          => __( "Choose if the player starts on pageload or has to be started manually", 'avia_framework' ),
  154.                             "id"            => "autoplay",
  155.                             "type"          => "select",
  156.                             "std"           => '',
  157.                             "subtype"       => array(
  158.                                                     __( 'Start manually','avia_framework' )     => 'manual',
  159.                                                     __( 'Start on pageload','avia_framework' )  => 'autoplay'
  160.                                                 )
  161.                         ),
  162.                
  163.                         array( 
  164.                             "name"          => __( "Loop playlist", 'avia_framework' ),
  165.                             "desc"          => __( "Choose if you want to stop after playing the list once or if you want to continue from beginning again", 'avia_framework' ),
  166.                             "id"            => "loop",
  167.                             "type"          => "select",
  168.                             "std"           => '',
  169.                             "subtype"       => array(
  170.                                                     __( 'Start from beginning again','avia_framework' )     => '',
  171.                                                     __( 'Stop after playing last song','avia_framework' )   => 'avia-playlist-no-loop'
  172.                                                 )
  173.                         ),
  174.                
  175.                         array( 
  176.                             "name"          => __( "Playlist Order", 'avia_framework' ),
  177.                             "desc"          => __( "Here you can select how to sort the playlist when rendering to the player on each pageload.", 'avia_framework' ),
  178.                             "id"            => "playorder",
  179.                             "type"          => "select",
  180.                             "std"           => '',
  181.                             "subtype"       => array(
  182.                                                     __( 'Use order of playlist as selected','avia_framework' )  => 'normal',
  183.                                                     __( 'Shuffle the playlist randomly','avia_framework' )      => 'shuffle',
  184.                                                     /*__( 'Reverse the playlist','avia_framework' )             => 'reverse'*/
  185.                                                 )
  186.                         ),
  187.                
  188.                         array( 
  189.                             "type"          => "modal_group",
  190.                             "id"            => "content",
  191.                             'container_class' =>"avia-element-fullwidth avia-multi-img",
  192.                             "modal_title"   => __("Edit Form Element", 'avia_framework' ),
  193.                             'modal_open'    => 'no',
  194.                             'trigger_button' => 'avia-builder-audio-edit',
  195.                             "add_label"     => __("Add single audio", 'avia_framework' ),
  196.                             'disable_manual'    =>  'yes',
  197.                             "std"           => array(),
  198.  
  199.                             'creator'       => array(
  200.                                         "name"      => __( "Create and Edit Audio Playlist", 'avia_framework' ),
  201.                                         "desc"      => __( "Here you can add new audio files to the playlist, remove files or reorder them.", 'avia_framework' ),
  202.                                         "id"        => "id",
  203.                                         "type"      => "audio_player",
  204.                                         'state'     => 'avia_insert_multi_audio',
  205.                                         "title"     => __( "Add/Edit Audio Files", 'avia_framework' ),
  206.                                         "button"    => __( "Insert Audio Files", 'avia_framework' ),
  207.                                         "std"       => ""
  208.                                             ),
  209.                                
  210.                             'subelements'   => array(
  211.                                    
  212.                                         array(
  213.                                             "type"  => "tab_container", 'nodescription' => true
  214.                                         ),
  215.  
  216.                                         array(
  217.                                             "type"      => "tab",
  218.                                             "name"      => __( "Content Audio" , 'avia_framework' ),
  219.                                             'nodescription' => true
  220.                                         ),
  221.                                    
  222.                                         //  Dummy element only to avoid notices
  223.                                         array( 
  224.                                             "name"      => __("Which type of media is this?",'avia_framework' ),
  225.                                             "id"        => "audio_type",
  226.                                             "type"      => "select",
  227.                                             "std"       => "audio",
  228.                                             "subtype"   => array(  
  229.                                                                 __( 'Audio File', 'avia_framework' )    => 'audio',
  230.                                                                 __( 'Video File', 'avia_framework' )    => 'video',
  231.                                                             )
  232.                                         ),
  233.                                    
  234.                                         array(
  235.                                             "type"          => "close_div",
  236.                                             'nodescription' => true
  237.                                         ), 
  238.                                
  239.                                
  240.                                         array(
  241.                                             "type"          => "close_div",
  242.                                             'nodescription' => true
  243.                                         ), 
  244.  
  245.                                     ),      //  subelements
  246.                                                            
  247.                         ),          //  modal_group
  248.                
  249.                         array( 
  250.                             "name"  => __("For Developers: Section ID", 'avia_framework' ),
  251.                             "desc"  => __("Apply a custom ID Attribute to the section, so you can apply a unique style via CSS. This option is also helpful if you want to use anchor links to scroll to a sections when a link is clicked", 'avia_framework' )."<br/><br/>".
  252.                                        __("Use with caution and make sure to only use allowed characters. No special characters can be used.", 'avia_framework' ),
  253.                             "id"    => "id",
  254.                             "type"  => "input",
  255.                             "std"   => ""
  256.                         ),
  257.                
  258.                     array(
  259.                         "type"          => "close_div",
  260.                         'nodescription' => true
  261.                     ), 
  262.  
  263.                     array(
  264.                         "type"          => "tab",
  265.                         "name"          => __( "Layout" , 'avia_framework' ),
  266.                         'nodescription' => true
  267.                     ),
  268.                
  269.                         array( 
  270.                             "name"          => __( "Player styling", 'avia_framework' ),
  271.                             "desc"          => __( "Here you can select the general appearance of the player", 'avia_framework' ),
  272.                             "id"            => "player_style",
  273.                             "type"          => "select",
  274.                             "std"           => '',
  275.                             "subtype"       => array(
  276.                                                     __( 'Classic (boxed)', 'avia_framework' )   => 'classic',
  277.                                                     __( 'Minimal (borderless, no background)', 'avia_framework' )   => 'minimal',
  278.                                                 )
  279.                             ), 
  280.                
  281.                         array( 
  282.                             "name"          => __( "Choose a Cover Image", 'avia_framework' ),
  283.                             "desc"          => __("Either upload a new or choose an existing image from your media library", 'avia_framework' ),
  284.                             "id"            => "cover_id",
  285.                             "fetch"         => "id",
  286.                             "type"          => "image",
  287.                             "title"         => __("Choose a Cover Image", 'avia_framework' ),
  288.                             "button"        => __("Choose a Cover Image", 'avia_framework' ),
  289.                             "std"           => ''
  290.                         ),
  291.                
  292. /*
  293.                         array( 
  294.                             "name"          => __( "Cover Image Location", 'avia_framework' ),
  295.                             "desc"          => __( "Here you can select where to show the cover for larger screens. On mobile devices the image will be centered above the player by default.", 'avia_framework' ),
  296.                             "id"            => "cover_location",
  297.                             "type"          => "select",
  298.                             "std"           => 'top left',
  299.                             "subtype"       => array(
  300.                                                     __( 'Hide the cover image', 'avia_framework' )              => 'hide',
  301.                                                     __( 'Show above player left aligned', 'avia_framework' )    => 'top left',
  302.                                                     __( 'Show above player centered', 'avia_framework' )        => 'top center',
  303.                                                     __( 'Show above player right aligned', 'avia_framework' )   => 'top right',
  304.                                                     __( 'Show left of player', 'avia_framework' )               => 'aside left',
  305.                                                     __( 'Show right of player', 'avia_framework' )              => 'aside right'
  306.                                                 )
  307.                         ), 
  308.                        
  309.                         array( 
  310.                             "name"          => __( "Cover Image Size", 'avia_framework' ),
  311.                             "desc"          => __( "Choose image size for your cover.", 'avia_framework' ),
  312.                             "id"            => "cover_size",
  313.                             "type"          => "select",
  314.                             "std"           => "thumbnail",
  315.                             "required"      => array( 'cover_location', 'not', 'hide' ),
  316.                             "subtype"       =>  AviaHelper::get_registered_image_sizes( array(), false, true )     
  317.                         ),
  318.  
  319.                
  320.                        
  321.                        
  322.                         array( 
  323.                             "name"          => __( "Playlist styling", 'avia_framework' ),
  324.                             "desc"          => __( "Here you can select the styling of the playlist", 'avia_framework' ),
  325.                             "id"            => "playlist_style",
  326.                             "type"          => "select",
  327.                             "std"           => 'light',
  328.                             "subtype"       => array(
  329.                                                     __( 'Light', 'avia_framework' ) => 'light',
  330.                                                     __( 'Dark', 'avia_framework' )  => 'dark'
  331.                                                 )
  332.                         ), 
  333.                        
  334.                         */
  335.                
  336.                         array( 
  337.                             "name"          => __( "Tracklist", 'avia_framework' ),
  338.                             "desc"          => __( "Here you can select to show or hide the tracklist", 'avia_framework' ),
  339.                             "id"            => "tracklist",
  340.                             "type"          => "select",
  341.                             "std"           => 'show',
  342.                             "subtype"       => array(
  343.                                                     __( 'Show tracklist', 'avia_framework' )    => 'show',
  344.                                                     __( 'Hide tracklist', 'avia_framework' )    => 'hide'
  345.                                                 )
  346.                         ), 
  347.                
  348.                         array( 
  349.                             "name"          => __( "Tracknumbers", 'avia_framework' ),
  350.                             "desc"          => __( "Here you can select to show or hide the tracknumbers next to entries in the playlist", 'avia_framework' ),
  351.                             "id"            => "tracknumbers",
  352.                             "type"          => "select",
  353.                             "std"           => 'show',
  354.                             "required"      => array( 'tracklist', 'equals', 'show' ),
  355.                             "subtype"       => array(
  356.                                                     __( 'Show tracknumbers', 'avia_framework' ) => 'show',
  357.                                                     __( 'Hide tracknumbers', 'avia_framework' ) => 'hide'
  358.                                                 )
  359.                         ), 
  360.                
  361.                         array( 
  362.                             "name"          => __( "Artists Name", 'avia_framework' ),
  363.                             "desc"          => __( "Here you can select to show or hide the artists name in the playlist", 'avia_framework' ),
  364.                             "id"            => "artists",
  365.                             "type"          => "select",
  366.                             "std"           => 'show',
  367.                             "required"      => array( 'tracklist', 'equals', 'show' ),
  368.                             "subtype"       => array(
  369.                                                     __( 'Show artists name', 'avia_framework' ) => 'show',
  370.                                                     __( 'Hide artists name', 'avia_framework' ) => 'hide'
  371.                                                 )
  372.                         ), 
  373.                
  374.                         array( 
  375.                             "name"          => __( "Media Icon/Album Cover", 'avia_framework' ),
  376.                             "desc"          => __( "Here you can select to show or hide the media icon in the playlist. This icon can be set in the media gallery for each element as the featured image. WP will use a default icon on upload, if none is set.", 'avia_framework' ),
  377.                             "id"            => "media_icon",
  378.                             "type"          => "select",
  379.                             "std"           => 'show',
  380.                             "subtype"       => array(
  381.                                                     __( 'Show media icon/album cover', 'avia_framework' )       => 'show',
  382.                                                     __( 'Hide', 'avia_framework' ) => 'hide'
  383.                                                 )
  384.                         ), 
  385.                
  386.                     array(
  387.                         "type"          => "close_div",
  388.                         'nodescription' => true
  389.                     ), 
  390.  
  391.                     array(
  392.                         "type"          => "tab",
  393.                         "name"          => __( "Colors" , 'avia_framework' ),
  394.                         'nodescription' => true
  395.                     ),
  396.                
  397.                         array( 
  398.                             "name"          => __( "Font Color", 'avia_framework' ),
  399.                             "desc"          => __( "Select a font color", 'avia_framework' ),
  400.                             "id"            => "font_color",
  401.                             "type"          => "select",
  402.                             "std"           => "",
  403.                             "subtype"       => array(
  404.                                                     __( "Default Color", 'avia_framework' ) => '',
  405.                                                     __( "Custom Color", 'avia_framework' )  => 'custom-font-color'
  406.                                                 )
  407.                         ),
  408.                    
  409.                         array( 
  410.                             "name"          => __( "Custom Font Color", 'avia_framework' ),
  411.                             "desc"          => __( "Select a custom font color for your Player here", 'avia_framework' ),
  412.                             "id"            => "custom_font_color",
  413.                             "type"          => "colorpicker",
  414.                             "std"           => "",
  415.                             "rgba"          => true,
  416.                             "required"      => array( 'font_color', 'equals', 'custom-font-color' )
  417.                         ),
  418.                
  419.                         array( 
  420.                             "name"          => __( "Background Color", 'avia_framework' ),
  421.                             "desc"          => __( "Select a background color", 'avia_framework' ),
  422.                             "id"            => "background_color",
  423.                             "type"          => "select",
  424.                             "std"           => "",
  425.                             "subtype"       => array(
  426.                                                     __( "Default Color", 'avia_framework' ) => '',
  427.                                                     __( "Custom Color", 'avia_framework' )  => 'custom-background-color'
  428.                                                 )
  429.                         ),
  430.                
  431.                         array( 
  432.                             "name"          => __( "Custom Background Color", 'avia_framework' ),
  433.                             "desc"          => __( "Select a custom background color for your Player here", 'avia_framework' ),
  434.                             "id"            => "custom_background_color",
  435.                             "type"          => "colorpicker",
  436.                             "std"           => "",
  437.                             "rgba"          => true,
  438.                             "required"      => array( 'background_color', 'equals', 'custom-background-color' )
  439.                         ),
  440.                        
  441.                         array( 
  442.                             "name"          => __( "Border Color", 'avia_framework' ),
  443.                             "desc"          => __( "Select a border color", 'avia_framework' ),
  444.                             "id"            => "border_color",
  445.                             "type"          => "select",
  446.                             "std"           => "",
  447.                             "subtype"       => array(
  448.                                                     __( "Default Color", 'avia_framework' ) => '',
  449.                                                     __( "Custom Color", 'avia_framework' )  => 'custom-border-color'
  450.                                                 )
  451.                         ),
  452.                
  453.                         array( 
  454.                             "name"          => __( "Custom Border Color", 'avia_framework' ),
  455.                             "desc"          => __( "Select a custom background color for your Player here", 'avia_framework' ),
  456.                             "id"            => "custom_border_color",
  457.                             "type"          => "colorpicker",
  458.                             "rgba"          => true,
  459.                             "std"           => "",
  460.                             "required"      => array( 'border_color', 'equals', 'custom-border-color' )
  461.                         ),
  462.                
  463.                     array(
  464.                         "type"          => "close_div",
  465.                         'nodescription' => true
  466.                     ), 
  467.  
  468.                     array(
  469.                         "type"  => "tab",
  470.                         "name"  => __("Screen Options",'avia_framework' ),
  471.                         'nodescription' => true
  472.                     ),
  473.                
  474.                
  475.                         array(
  476.                             "name"          => __( "Element Visibility",'avia_framework' ),
  477.                             "desc"          => __( "Set the visibility for this element, based on the device screensize.", 'avia_framework' ),
  478.                             "type"          => "heading",
  479.                             "description_class" => "av-builder-note av-neutral",
  480.                         ),
  481.  
  482.                         array( 
  483.                                 "desc"      => __( "Hide on large screens (wider than 990px - eg: Desktop)", 'avia_framework' ),
  484.                                 "id"        => "av-desktop-hide",
  485.                                 "std"       => "",
  486.                                 "container_class" => 'av-multi-checkbox',
  487.                                 "type"      => "checkbox"
  488.                         ),
  489.                
  490.                         array( 
  491.  
  492.                                 "desc"      => __( "Hide on medium sized screens (between 768px and 989px - eg: Tablet Landscape)", 'avia_framework' ),
  493.                                 "id"        => "av-medium-hide",
  494.                                 "std"       => "",
  495.                                 "container_class" => 'av-multi-checkbox',
  496.                                 "type"      => "checkbox"
  497.                         ),
  498.  
  499.                         array( 
  500.                                 "desc"      => __( "Hide on small screens (between 480px and 767px - eg: Tablet Portrait)", 'avia_framework' ),
  501.                                 "id"        => "av-small-hide",
  502.                                 "std"       => "",
  503.                                 "container_class" => 'av-multi-checkbox',
  504.                                 "type"      => "checkbox"
  505.                         ),
  506.  
  507.                         array( 
  508.                                 "desc"      => __( "Hide on very small screens (smaller than 479px - eg: Smartphone Portrait)", 'avia_framework' ),
  509.                                 "id"        => "av-mini-hide",
  510.                                 "std"       => "",
  511.                                 "container_class" => 'av-multi-checkbox',
  512.                                 "type"      => "checkbox"
  513.                         ),
  514.    
  515.                                            
  516.                     array(
  517.                         "type"          => "close_div",
  518.                         'nodescription' => true
  519.                     ), 
  520.                                
  521.                                
  522.                     array(
  523.                         "type"          => "close_div",
  524.                         'nodescription' => true
  525.                     ), 
  526.                
  527.                 );
  528.         }
  529.        
  530.         /**
  531.          * Editor Element - this function defines the visual appearance of an element on the AviaBuilder Canvas
  532.          * Most common usage is to define some markup in the $params['innerHtml'] which is then inserted into the drag and drop container
  533.          * Less often used: $params['data'] to add data attributes, $params['class'] to modify the className
  534.          *
  535.          *
  536.          * @since 4.1.3
  537.          * @param array $params         this array holds the default values for $content and $args.
  538.          * @return $params              the return array usually holds an innerHtml key that holds item specific markup.
  539.          */
  540.         public function editor_element( $params )
  541.         {  
  542.             $element = $this->get_popup_element_by_id( 'autoplay' );
  543.            
  544.             /**
  545.              * Element has been disabled with option "Disable self hosted video and audio features"
  546.              */
  547.             if( false === $element )
  548.             {
  549.                 return $params;
  550.             }
  551.            
  552.             $playmodes = $element['subtype'];
  553.            
  554.             $update_template =  '<span class="av-player-{{autoplay}}">';
  555.            
  556.             foreach( $playmodes as $info => $playmode )
  557.             {
  558.                 $update_template .=     '<span class="av-play-' . $playmode . '">' . $info . '</span>';
  559.             }
  560.            
  561.             $update_template .= '</span>';
  562.            
  563.            
  564.             $update = $this->update_template( 'autoplay', $update_template );
  565.            
  566.             $selected = empty( $params['args']['autoplay'] ) ? 'manual' : $params['args']['autoplay'];
  567.             $template = str_replace('{{autoplay}}', $selected, $update_template );
  568.                                                
  569.             $params['innerHtml'] = "<img src='".$this->config['icon'] . "' title='".$this->config['name'] . "' />";
  570.             $params['innerHtml'].= "<div class='av-player'>" . $this->config['name'] . ' -  <span ' . $update . '">' . $template . "</span></div>";
  571.             return $params;
  572.         }
  573.        
  574.         /**
  575.          * Editor Sub Element - this function defines the visual appearance of an element that is displayed within a modal window and on click opens its own modal window
  576.          * Works in the same way as Editor Element
  577.          *
  578.          * @since 4.1.3
  579.          * @param array $params     this array holds the default values for $content and $args.
  580.          * @return array            the return array usually holds an innerHtml key that holds item specific markup.
  581.          */
  582.         public function editor_sub_element( $params )
  583.         {  
  584.  
  585.             $img_template       = $this->update_template( "img_fakeArg", "{{img_fakeArg}}" );
  586.             $title              = $this->update_template( "title_info", "{{title_info}}" );
  587.             $artist             = $this->update_template( "artist", "{{artist}}" );
  588.             $album              = $this->update_template( "album", "{{album}}" );
  589.             $description        = $this->update_template( "description", "{{description}}" );
  590.             $filename           = $this->update_template( "filename", "{{filename}}" );
  591.             $id                 = $this->update_template( "id", "{{id}}" );
  592.             $filelength         = $this->update_template( "filelength", "{{filelength}}" );
  593.            
  594.             $title_info     = isset( $params['args']['title'] ) ? $params['args']['title'] : '';
  595.             $thumbnail      = isset( $params['args']['icon'] ) ? '<img src="' . $params['args']['icon'] .  '" title="' . esc_attr(  $title_info ) . '" alt="" />' : "";
  596.             $album_info     = isset( $params['args']['album'] ) && 'undefined' != $params['args']['album'] ?  $params['args']['album'] : '';
  597.             $desc_info      = isset( $params['args']['description'] ) && 'undefined' != $params['args']['description'] ?  $params['args']['description'] : '';
  598.             $file_info      = isset( $params['args']['filename'] ) && 'undefined' != $params['args']['filename'] ?  $params['args']['filename'] : '';
  599.             $id_info        = isset( $params['args']['id'] ) && 'undefined' != $params['args']['id'] ? $params['args']['id'] : '0';
  600.            
  601.             $main = '<span class="avia-audiolist-title" '. $title . '>';
  602.            
  603.             if( isset( $params['args']['title'] ) && 'undefined' != $params['args']['title'] )
  604.             {
  605.                 $main .=    '<span class="avia-known-title">' . $params['args']['title'];
  606.             }
  607.             else
  608.             {
  609.                 $main .=    '<span class="avia-unknown-title">' . __( ' Unknown ' , 'avia_framework' );
  610.             }
  611.             $main .=        '</span></span>';  
  612.            
  613.             /**
  614.              * Currently WP does not return artist when editing an existing playlist in popup playlist editor.
  615.              *
  616.              * This might change in future -> then uncomment the following lines to show the artist
  617.              */
  618. //          $main .=        '<span class="avia_audiolist-by">' . __( ' by ' , 'avia_framework' ) . '</span>';
  619. //         
  620. //          if( isset( $params['args']['artist'] ) && 'undefined' != $params['args']['artist'] )
  621. //          {
  622. //              $main .=    '<span class="avia-audiolist-artist" ' . $artist . '>' . $params['args']['artist'];
  623. //          }
  624. //          else
  625. //          {
  626. //              $main .=    '<span class="avia-audiolist-artist avia-unknown" ' . $artist . '>' . __( ' unknown ' , 'avia_framework' );
  627. //          }
  628. //          $main .= '</span>';
  629.            
  630.             if( isset( $params['args']['filelength'] ) )
  631.             {
  632.                 $main .=    ' (<span class="avia-audiolist-length" ' . $filelength . '>' . $params['args']['filelength'];
  633.             }
  634.             else
  635.             {
  636.                 $main .=    ' (<span class="avia-audiolist-length avia-unknown" ' . $filelength . '>' . __( ' ??? ' , 'avia_framework' );
  637.             }
  638.             $main .= '</span>)';
  639.            
  640.  
  641.             $params['innerHtml']  = '';
  642.             $params['innerHtml'] .= "<div class='avia_title_container'>";
  643.             $params['innerHtml'] .= "   <div " . $this->class_by_arguments( 'audio_type' ,$params['args'] ) . ">";
  644.             $params['innerHtml'] .= "       <span class='avia_audiolist_image' {$img_template} >{$thumbnail}</span>";
  645.             $params['innerHtml'] .= "       <div class='avia_audiolist_content'>";
  646.             $params['innerHtml'] .= "           <h4 class='avia_title_container_inner'>" . $main . "</h4>";
  647.             $params['innerHtml'] .= "           <p class='avia_content_album' {$album}>" . stripslashes( $album_info ) . "</p>";
  648.             $params['innerHtml'] .= "           <p class='avia_content_description' {$description}>" . stripslashes( $desc_info ) . "</p>";
  649.             $params['innerHtml'] .= "           <small class='avia_audio_url' {$filename}>" . stripslashes( $file_info ) . "</small>";
  650.             $params['innerHtml'] .= "       </div>";
  651.             $params['innerHtml'] .= "       <div class='hidden-attachment-id' style='display: none;' {$id}>" . $id_info . '</div>';
  652.             $params['innerHtml'] .= "   </div>";
  653.             $params['innerHtml'] .= "</div>";
  654.  
  655.             return $params;
  656.         }
  657.            
  658.         /**
  659.          * Frontend Shortcode Handler
  660.          *
  661.          * @since 4.1.3
  662.          * @param array $atts array of attributes
  663.          * @param string $content text within enclosing form of shortcode element
  664.          * @param string $shortcodename the shortcode found, when == callback name
  665.          * @return string $output returns the modified html string
  666.          */
  667.         public function shortcode_handler( $atts, $content = "", $shortcodename = "", $meta = "" )
  668.         {
  669.             extract( AviaHelper::av_mobile_sizes( $atts ) ); //return $av_font_classes, $av_title_font_classes and $av_display_classes
  670.            
  671.             $this->extra_style = '';
  672.             $this->atts = shortcode_atts( array(
  673.                                 'handle'            => $shortcodename,
  674.                                 'id'                => '',
  675.                                 'autoplay'          => 'manual',
  676.                                 'loop'              => '',
  677.                                 'playorder'         => 'normal',
  678.                                 'player_style'      => 'classic',
  679.                                 'cover_id'          => '',
  680.                                 'cover_size'        => 'thumbnail',
  681.                                 'cover_location'    => 'hide',
  682.                                 'playlist_style'    => 'light',
  683.                                 'tracklist'         => 'show',
  684.                                 'tracknumbers'      => 'show',
  685.                                 'artists'           => 'show',
  686.                                 'media_icon'        => 'show',
  687.                                 'font_color'        => '',
  688.                                 'custom_font_color' => '',
  689.                                 'background_color'  => '',
  690.                                 'custom_background_color'   =>'',
  691.                                 'border_color'      => '',
  692.                                 'custom_border_color'       => '',
  693.                                
  694.                                 'content'           => ShortcodeHelper::shortcode2array( $content, 1 )
  695.  
  696.                         ), $atts, $this->config['shortcode'] );
  697.        
  698.             //replace some values that are removed for simplicity with defaults. can be later changed if user request those features
  699.             $this->atts['cover_location'] = "hide";
  700.             $this->atts['playlist_style'] = "light";
  701.            
  702.             if( $this->atts['media_icon'] == "cover")
  703.             {
  704.                 $this->atts['media_icon'] = "show";
  705.             }
  706.        
  707.             /**
  708.              * Replace empty default values so we can later use them to add classes
  709.              */
  710.             if( empty( $this->atts['id'] ) )
  711.             {
  712.                 $this->atts['id'] = $this->config['shortcode'] . '-' . avia_sc_audio_player::$instance;
  713.             }
  714.            
  715.             avia_sc_audio_player::$instance++;
  716.            
  717.             if( empty( $this->atts['player_style'] ) )
  718.             {
  719.                 $this->atts['player_style'] = 'classic';
  720.             }
  721.  
  722.             extract( $this->atts );
  723.            
  724.             /**
  725.              * Return if no playlist defined
  726.              */
  727.             if( empty( $content ) )
  728.             {
  729.                 return '';
  730.             }
  731.            
  732.             $ids = array();
  733.             foreach( $content as $key => $audio )
  734.             {
  735.                 $ids[] = $audio['attr']['id'];
  736.             }
  737.            
  738.             if( 'shuffle' == $playorder )
  739.             {
  740.                 shuffle( $ids );
  741.             }
  742.             else if( 'reverse' == $playorder )
  743.             {
  744.                 $ids = array_reverse( $ids );
  745.             }
  746.            
  747.             /**
  748.              * With WP 5.2 we need to show tracklist and hide with CSS to allow stop of loop
  749.              */
  750.             $args = array(
  751.                     'type'          => 'audio',
  752.                     'ids'           => $ids,
  753.                     'style'         => empty( $playlist_style ) ? 'classic' : $playlist_style,
  754.                     'tracklist'     => true,           
  755.                     'tracknumbers'  => empty( $tracknumbers ) || ( 'hide' != $tracknumbers )  ? true : false,
  756.                     'images'        => empty( $media_icon) || ( 'hide' != $media_icon )  ? true : false,
  757.                     'artists'       => empty( $artists ) || ( 'hide' != $artists )  ? true : false
  758.                 );
  759.            
  760.            
  761.             if( ( $media_icon == 'show' ) && ( is_numeric( $cover_id  ) ) )
  762.             {
  763.                 add_filter( 'wp_get_attachment_image_src', array( $this, 'handler_wp_get_attachment_image_src' ), 10, 4 );
  764.                 add_filter( 'wp_mime_type_icon', array( $this, 'handler_wp_mime_type_icon' ), 10, 3 );
  765.             }
  766.            
  767.             $player = wp_playlist_shortcode( $args );
  768.            
  769.             if( ( $media_icon == 'show' ) && ( is_numeric( $cover_id  ) ) )
  770.             {
  771.                 remove_filter( 'wp_get_attachment_image_src', array( $this, 'handler_wp_get_attachment_image_src' ), 10 );
  772.                 remove_filter( 'wp_mime_type_icon', array( $this, 'handler_wp_mime_type_icon' ), 10 );
  773.             }
  774.            
  775.             $output  = '';
  776.            
  777.             $outer_cls = array(
  778.                                 'av-player',
  779.                                 'av-player-container',
  780.                                 $av_display_classes
  781.                             );
  782.            
  783.             if( 'hide' == $tracklist )
  784.             {
  785.                 $outer_cls[] = 'av-player-hide-playlist';
  786.             }
  787.            
  788.             if( 1 == avia_sc_audio_player::$instance )
  789.             {
  790.                 $outer_cls[] = 'first';
  791.             }
  792.            
  793.             if( ! empty( $loop ) )
  794.             {
  795.                 $outer_cls[] = $loop;
  796.             }
  797.            
  798.             $outer_styles = array();
  799.            
  800.             $outer_cls[] = 'avia-playerstyle-' . $player_style;
  801.            
  802.             if( $autoplay == 'autoplay' )
  803.             {
  804.                 $outer_cls[] = 'avia-playlist-autoplay';
  805.             }
  806.            
  807.             if( ( $font_color == 'custom-font-color') && ( ! empty( $custom_font_color ) ) )
  808.             {
  809.                 $outer_cls[] = 'avia-playlist-' . $font_color;
  810.                 $outer_styles[] = 'color:' . $custom_font_color . ';';
  811.             }
  812.            
  813.             if( ( $background_color == 'custom-background-color') && ( ! empty( $custom_background_color ) ) )
  814.             {
  815.                 $outer_cls[] = 'avia-playlist-' . $background_color;
  816.                 $outer_styles[] = 'background-color:' . $custom_background_color . ';';
  817.             }
  818.            
  819.             if( ( $border_color == 'custom-border-color') && ( ! empty( $custom_border_color ) ) )
  820.             {
  821.                 $outer_cls[] = 'avia-playlist-' . $border_color;
  822.                 $outer_styles[] = 'border-color:' . $custom_border_color . ';';
  823.                
  824.                 //generate thumb width based on columns
  825.                 $this->extra_style .= "<style type='text/css'>";
  826.                 $this->extra_style .= "#top #wrap_all #{$id} .wp-playlist-item {border-color:{$custom_border_color};}";
  827.                 $this->extra_style .= "</style>";
  828.                
  829.                 if(!empty($this->extra_style))
  830.                 {
  831.                     if(!empty($atts['ajax_request']) || !empty($_POST['avia_request']))
  832.                     {
  833.                         $output .= $this->extra_style;
  834.                         $this->extra_style = "";
  835.                     }
  836.                     else
  837.                     {
  838.                         avia_sc_audio_player::$non_ajax_style .= $this->extra_style;
  839.                         if( false === has_action( 'wp_footer', array( $this, 'print_extra_style' ) ) )
  840.                         {
  841.                             add_action( 'wp_footer', array( $this, 'print_extra_style' ) );
  842.                         }
  843.                     }
  844.                 }
  845.                
  846.             }
  847.            
  848.             $cover = '';
  849.             if( ( $cover_location != 'hide' ) && ( ! empty( $cover_id ) ) )
  850.             {
  851.                 $outer_cls[] = 'avia-playlist-show-cover';
  852.                 $outer_cls[] = $cover_location;
  853.                 $cover = wp_get_attachment_link( $cover_id, $cover_size );
  854.             }
  855.             else
  856.             {
  857.                 $outer_cls[] = 'avia-playlist-hide-cover';
  858.             }
  859.            
  860.             if( ! empty( $outer_styles ) )
  861.             {
  862.                 $outer_styles = ' style="' . implode( '', $outer_styles ) . '" ';
  863.             }
  864.             else
  865.             {
  866.                 $outer_styles = '';
  867.             }
  868.            
  869.             $output .= '<div id="' . $id . '" class="' . implode( ' ', $outer_cls ) . '" ' . $outer_styles . '>';
  870.            
  871.             if( ! empty( $cover ) )
  872.             {
  873.                 $output .=  '<div class="av-player-cover-container">';
  874.                 $output .=      '<div class="av-player-cover">' . $cover . '</div>';
  875.                 $output .=  '</div>';
  876.             }
  877.            
  878.             $output .=      '<div class="av-player-player-container">';
  879.             $output .=          $player;
  880.             $output .=      '</div>';
  881.            
  882.             $output .= '</div>';
  883.            
  884.        
  885.             return $output;
  886.         }
  887.        
  888.        
  889.         /**
  890.          * If user uploads an image for tbe player this image will overwrite any preset featured image.
  891.          * To speed up the code the filter should only be activated when images should be exchanged
  892.          *
  893.          * @since 4.1.3
  894.          * @param array|false  $image         Either array with src, width & height, icon src, or false.
  895.          * @param int          $attachment_id Image attachment ID.
  896.          * @param string|array $size          Size of image. Image size or array of width and height values
  897.          *                                    (in that order). Default 'thumbnail'.
  898.          * @param bool         $icon          Whether the image should be treated as an icon. Default false.
  899.          * @return array|false
  900.          */
  901.         public function handler_wp_get_attachment_image_src( $image, $attachment_id, $size, $icon )
  902.         {
  903.             static $recursive = 0;
  904.            
  905.             /**
  906.              * To avoid duplicating code we call the original function. Avoid endless recursions.
  907.              */
  908.             if( $recursive > 0 )
  909.             {
  910.                 return $image;
  911.             }
  912.            
  913.             $new_id = $this->atts['cover_id'];
  914.            
  915.             if( empty( $new_id ) || ( ! is_numeric( $new_id ) ) || ( (int) $new_id == $attachment_id ) )
  916.             {
  917.                 return $image;
  918.             }
  919.            
  920.             $recursive++;
  921.            
  922.             $image = wp_get_attachment_image_src( $new_id, $size, $icon );
  923.            
  924.             $recursive--;
  925.            
  926.             return $image;
  927.         }
  928.        
  929.         /**
  930.          * If user uploads an image for tbe player this image will overwrite the default mime icon from WP if no featured image was assigned
  931.          * to the media file.
  932.          * To speed up the code the filter should only be activated when images should be exchanged
  933.          *
  934.          * @since 4.1.3
  935.          * @param string    $icon
  936.          * @param string    $mime
  937.          * @param int       $post_id
  938.          * @return string
  939.          */
  940.         public function handler_wp_mime_type_icon( $icon, $mime, $post_id )
  941.         {
  942.             $new_id = $this->atts['cover_id'];
  943.            
  944.             if( empty( $new_id ) || ! is_numeric( $new_id ) )
  945.             {
  946.                 return $icon;
  947.             }
  948.            
  949.             $image = wp_get_attachment_image_src( $new_id, 'thumbnail', false );
  950.             return $image[0];
  951.         }
  952.        
  953.         /**
  954.          * @since 4.1.3
  955.          */
  956.         public function print_extra_style()
  957.         {
  958.             echo avia_sc_audio_player::$non_ajax_style;
  959.         }
  960.  
  961.     }       //  end class definition
  962.    
  963. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement