From 799a7c93bda7f13804f365039a0f092c21e4eb4a Mon Sep 17 00:00:00 2001 From: Clemens Tolboom Date: Thu, 15 Mar 2018 14:42:03 +0100 Subject: [PATCH] Use the amara interface instead of universal subtitles. --- wp_amara_shortcode.php | 55 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/wp_amara_shortcode.php b/wp_amara_shortcode.php index e7fdb03..acb073d 100644 --- a/wp_amara_shortcode.php +++ b/wp_amara_shortcode.php @@ -36,11 +36,56 @@ class WP_Amara_Shortcode public function __construct() { add_shortcode( 'amara' , array(&$this, 'amara') ); } // __construct - + /** * Main plugin function */ public function amara( $atts ) { + // TODO: make a UI for this option + if (get_option('wp_amara_use_legacy', true) ) { + return $this->unisub($atts); + } + else { + wp_enqueue_script('amara-embed-js'); + //
+ // These will be prefixed by 'data-' + $data = array( + 'width' => 640, + 'height' => 480, + // TODO: replace by tutorial video + 'url' => 'http://www.youtube.com/watch?v=5CKwCfLUwj4', + ); + + $attributes = array(); + $attributes['class'] = 'amara-embed'; + foreach($data as $key => $default) { + if (isset($atts[$key])) { + $attributes['data-' . $key] = $atts[$key]; + unset($atts[$key]); + } + else { + $attributes['data-' . $key] = $default; + } + } + $result = '
$value) { + // TODO escape $value attributes + $result.= $key . '="' . $value . '" '; + } + $result.= '>
'; + if (!empty($atts)) { + $result .= '' . print_r($atts, true) . ''; + } + return $result; + } + } + + /** + * @deprecated + * + * Legacy implementation + */ + public function unisub( $atts) { if(isset($atts['content'])) { $content = $this->prepare_content($atts['content']); @@ -124,4 +169,10 @@ private function prepare_content ( $content ) { if(class_exists('WP_Amara_Shortcode')) { // instantiate the plugin class $wp_amara_shortcode = new WP_Amara_Shortcode(); -} \ No newline at end of file +} + +add_action("wp_enqueue_scripts", "WP_Amara_scripts"); + +function WP_Amara_scripts() { + wp_register_script( 'amara-embed-js', 'https://amara.org/embedder-iframe' , '', '', true ); +}