| 1 |
<?php |
| 2 |
|
| 3 |
add_action('admin_menu', 'playerjs_com_admin'); |
| 4 |
|
| 5 |
function playerjs_com_admin(){ |
| 6 |
add_options_page( 'PlayerJS', 'PlayerJS', 'manage_options', 'playerjs_com_admin', 'playerjs_com_admin_html'); |
| 7 |
if(stripos($_SERVER['REQUEST_URI'],'post.php')!==false || stripos($_SERVER['REQUEST_URI'], 'post-new.php') !==false) { |
| 8 |
add_action('media_buttons', 'playerjs_com_editor_button', 10); |
| 9 |
} |
| 10 |
} |
| 11 |
|
| 12 |
function playerjs_com_editor_button() { |
| 13 |
global $post; |
| 14 |
wp_enqueue_script('playerjs-editor-js', plugins_url('',__FILE__).'/playerjs_com_admin.js'); |
| 15 |
wp_enqueue_style('playerjs-editor-css', plugins_url('',__FILE__).'/playerjs_com_admin.css'); |
| 16 |
echo '<span id="playerjs_com_editor_button" class="button">PlayerJS</span> '; |
| 17 |
} |
| 18 |
|
| 19 |
function playerjs_com_admin_html(){ |
| 20 |
?> |
| 21 |
<div class="wrap"><a href="https://playerjs.com" target="_blank"><div style="float:right;width:33px;margin:20px 20px 0 0;height:50px;background:url('<?php echo(esc_html(plugins_url('',__FILE__)));?>/playerjs.png') no-repeat 0 0;background-size:cover;"></div></a> |
| 22 |
<h1>PlayerJS</h1> |
| 23 |
<form action="options.php" method="POST"> |
| 24 |
<?php |
| 25 |
settings_fields('settings'); |
| 26 |
do_settings_sections('page'); |
| 27 |
submit_button(); |
| 28 |
|
| 29 |
echo('<p>PlayerJS support HTML5 Video, HTML5 Audio, HLS, DASH, YouTube and Vimeo.<br>Please look our <a href="https://playerjs.com/docs/q=wordpress" target="_blank">plugin page</a> and <a href="https://playerjs.com/docs" target="_blank">docs</a> if you have any questions.</p>'); |
| 30 |
?> |
| 31 |
</form> |
| 32 |
</div> |
| 33 |
<?php |
| 34 |
} |
| 35 |
|
| 36 |
add_action('admin_init', 'playerjs_com_settings_page'); |
| 37 |
|
| 38 |
function playerjs_com_settings_page(){ |
| 39 |
|
| 40 |
register_setting('settings', 'playerjs_com_script_path', 'playerjs_com_sanitize_callback'); |
| 41 |
register_setting('settings', 'playerjs_com_width', 'playerjs_com_sanitize_callback'); |
| 42 |
register_setting('settings', 'playerjs_com_customheight', 'playerjs_com_sanitize_callback'); |
| 43 |
register_setting('settings', 'playerjs_com_height', 'playerjs_com_sanitize_callback'); |
| 44 |
register_setting('settings', 'playerjs_com_align', 'playerjs_com_sanitize_callback'); |
| 45 |
|
| 46 |
add_settings_section('section', 'Create a custom player for free → <a href="https://playerjs.com" target="_blank">playerjs.com</a>', '', 'page'); |
| 47 |
|
| 48 |
add_settings_field('path', "Path to created player", 'pjs_settings_path', 'page', 'section'); |
| 49 |
add_settings_field('size', 'Options', 'pjs_settings_size', 'page', 'section'); |
| 50 |
} |
| 51 |
|
| 52 |
function pjs_settings_path(){ |
| 53 |
$path = get_option('playerjs_com_script_path'); |
| 54 |
$path = $path ? $path['input'] : ''; |
| 55 |
if(trim($path)==''){ |
| 56 |
$path = plugins_url('').'/playerjs/playerjs_default.js'; |
| 57 |
} |
| 58 |
|
| 59 |
$check_path = ''; |
| 60 |
/*if(strpos(file_get_contents($path),'Player')===false){ |
| 61 |
$check_path = '<p style="color:#f00">File not found</p>'; |
| 62 |
}*/ |
| 63 |
echo('<input type="text" name="playerjs_com_script_path[input]" style="width:100%;font-size:90%;max-width:800px;font-family:Courier New,monotype" value="'.esc_html(esc_attr($path)).'" />'.esc_html($check_path)); |
| 64 |
} |
| 65 |
|
| 66 |
function pjs_settings_size(){ |
| 67 |
|
| 68 |
$width = playerjs_com_get_option('width',0,'100%'); |
| 69 |
|
| 70 |
$height = playerjs_com_get_option('height',0,'280px'); |
| 71 |
|
| 72 |
$customheight = playerjs_com_get_option('customheight',0,''); |
| 73 |
|
| 74 |
$align = playerjs_com_get_option('align',0,''); |
| 75 |
|
| 76 |
echo('<span style="display:inline-block;width:70px">Width</span> <input type="text" name="playerjs_com_width[input]" style="width:60px" value="'.esc_attr($width).'" />'); |
| 77 |
|
| 78 |
echo('<p><span style="display:inline-block;width:70px">Height</span> <select name="playerjs_com_customheight[input]"><option value="">auto</option><option value="custom" '.($customheight=="custom"?"selected":"").'>custom</option></select> '.($customheight=="custom"?'<input type="text" name="playerjs_com_height[input]" style="width:60px" value="'.esc_attr($height).'"/>':'').'</p>'); |
| 79 |
|
| 80 |
echo('<p><span style="display:inline-block;width:70px">Align</span> <select name="playerjs_com_align[input]"><option value="">left</option><option value="center" '.($align=="center"?"selected":"").'>center</option></select></p>'); |
| 81 |
|
| 82 |
//<input type="checkbox" name="playerjs_com_customheight[checkbox]" value="1" '.($customheight==1?"":"checked").'/> custom |
| 83 |
} |
| 84 |
|
| 85 |
function playerjs_com_sanitize_callback( $options ){ |
| 86 |
if (is_array($options) || is_object($options)){ |
| 87 |
foreach( $options as $name => & $val ){ |
| 88 |
if( $name == 'input' ) |
| 89 |
$val = wp_strip_all_tags( $val ); |
| 90 |
|
| 91 |
if( $name == 'checkbox' ) |
| 92 |
$val = intval( $val ); |
| 93 |
} |
| 94 |
} |
| 95 |
return $options; |
| 96 |
} |