diff --git a/README.textile b/README.textile index dde66f8..9b6a715 100644 --- a/README.textile +++ b/README.textile @@ -1,4 +1,4 @@ -h1. oui_video (beta) +h1. oui_video Easily embed videos in articles and customise the appearance of the player. This plugin does, by its own, what "arc_youtube":http://andy-carter.com/txp/arc_youtube, "arc_vimeo":http://andy-carter.com/txp/arc_vimeo and oui_dailymotion used to do together. @@ -18,7 +18,7 @@ h2(#requirements). Plugin requirements oui_video's minimum requirements: -* "Textpattern CMS":http://textpattern.com/ 4.5+ +* "Textpattern CMS":http://textpattern.com/ 4.5+ (4.6+ is recommended). h2(#install). Installation @@ -29,6 +29,8 @@ h2(#tags). Preferences/options Plugin prefs are mainly used as default values for the oui_video @@ attributes. They can be overriden by these attributes when needed. ++Always prefer plugin "global" prefs to tag related attributes!+ + h2(#tags). Tags h3. oui_video diff --git a/src/class.php b/src/class.php index facc379..89d5b41 100644 --- a/src/class.php +++ b/src/class.php @@ -222,15 +222,15 @@ class Oui_Video 'default' => '4:3', ), 'vimeo_prefs' => array( - 'default' => 1, + 'default' => '0', 'valid' => array('0', '1'), ), 'dailymotion_prefs' => array( - 'default' => 1, + 'default' => '0', 'valid' => array('0', '1'), ), 'youtube_prefs' => array( - 'default' => 1, + 'default' => '0', 'valid' => array('0', '1'), ), ), @@ -241,6 +241,7 @@ class Oui_Video 'params' => array( 'autopause' => array( 'default' => '1', + 'valid' => array('0', '1'), ), 'autoplay' => array( 'default' => '0', @@ -451,7 +452,7 @@ public function __construct() register_callback(array($this, 'lifeCycle'), 'plugin_lifecycle.' . $this->plugin); register_callback(array($this, 'setPrefs'), 'prefs', null, 1); - register_callback(array($this, 'options'), 'plugin_prefs.' . $this->plugin, null, 1); + register_callback(array($this, 'optionsLink'), 'plugin_prefs.' . $this->plugin, null, 1); } else { if (class_exists('\Textpattern\Tag\Registry')) { // Register Textpattern tags for TXP 4.6+. @@ -484,9 +485,11 @@ public function lifeCycle($evt, $stp) /** * Jump to the prefs panel. */ - public function options() + public function optionsLink() { - $url = '?event=prefs#prefs_group_' . $this->plugin; + $url = defined('PREF_PLUGIN') + ? '?event=prefs#prefs_group_' . $this->plugin + : '?event=prefs&step=advanced_prefs'; header('Location: ' . $url); } @@ -499,11 +502,13 @@ public function prefWidget($options) { // Check what is needed as the html value of the pref $valid = isset($options['valid']) ? $options['valid'] : false; + if ($valid && is_array($valid)) { $widget = $valid === array('0', '1') ? 'yesnoradio' : $this->plugin . '_pref'; } else { $widget = 'text_input'; } + return $widget; } @@ -517,13 +522,16 @@ public function prefSelect($name, $val) { foreach ($this->providers as $provider => $infos) { $group = $provider === 'all' ? $this->plugin : $this->plugin . '_' . $provider; + foreach ($infos['params'] as $pref => $options) { if ($name === $group . '_' . $pref) { $valid = $options['valid']; $vals = array(); + foreach ($valid as $value) { $value === '' ?: $vals[$value] = gtxt($group . '_' . $pref . '_' . $value); } + return selectInput($name, $vals, $val, $valid[0] === '' ? true : false); } } @@ -539,13 +547,14 @@ public function setPrefs() foreach ($this->providers as $provider => $infos) { $group = $provider === 'all' ? $this->plugin : $this->plugin . '_' . $provider; + foreach ($infos['params'] as $pref => $options) { if (get_pref($group . '_' . $pref, null) === null) { set_pref( $group . '_' . $pref, $options['default'], $group, - PREF_PLUGIN, + defined('PREF_PLUGIN') ? PREF_PLUGIN : PREF_ADVANCED, isset($options['widget']) ? $options['widget'] : $this->prefWidget($options), $position ); @@ -568,9 +577,9 @@ public function pophelp($evt, $stp, $ui, $vars) } /** - * Get the video provider and the video id from its url + * Get a tag attribute list * - * @param string $video The video url + * @param string $tag The plugin tag */ public function getAtts($tag) { @@ -578,18 +587,21 @@ public function getAtts($tag) foreach ($this->tags[$tag] as $att => $options) { $init_atts[$att] = $options['default']; } + return $init_atts; } /** - * Get the video provider and the video id from its url + * Look for wrong attribute values * - * @param string $video The video url + * @param string $tag The plugin tag + * @param array $atts The Txp variable containing attribute values in use */ public function checkAtts($tag, $atts) { foreach ($atts as $att => $val) { $valid = isset($this->tags[$tag][$att]['valid']) ? $this->tags[$tag][$att]['valid'] : false; + if ($valid) { if (is_array($valid) && !in_array($val, $valid)) { $valid = implode(', ', $valid); @@ -605,6 +617,7 @@ public function checkAtts($tag, $atts) } } } + return; } @@ -628,6 +641,7 @@ public function videoInfos($video) } } } + return false; } @@ -639,38 +653,49 @@ public function videoInfos($video) */ public function playerInfos($provider, $no_cookie) { + if ($provider === 'youtube') { + $src = $no_cookie ? $this->providers[$provider]['src'][1] : $this->providers[$provider]['src'][0]; + } else { + $src = $this->providers[$provider]['src'][0]; + } + $player_infos = array( - 'src' => $no_cookie ? $this->providers[$provider]['src'][1] : $this->providers[$provider]['src'][0], + 'src' => $src, 'params' => $this->providers[$provider]['params'], ); + return $player_infos; } - public function videoSize($dims) + /** + * Calculate the player size + * + * @param array $dims An associative array containing provided attribute values for width, height and ratio + */ + public function playerSize($dims) { $width = $dims['width']; $height = $dims['height']; - $ratio = $dims['ratio'] ? $dims['ratio'] : $this->providers['all']['params']['ratio']['default']; if (!$width || !$height) { - $toolbarHeight = 25; + $ratio = $dims['ratio'] ? $dims['ratio'] : $this->providers['all']['params']['ratio']['default']; // Work out the aspect ratio. preg_match("/(\d+):(\d+)/", $ratio, $matches); if ($matches[0] && $matches[1]!=0 && $matches[2]!=0) { - $aspect = $matches[1]/$matches[2]; + $aspect = $matches[1] / $matches[2]; } else { $aspect = 1.333; } // Calcuate the new width/height. if ($width) { - $height = $width/$aspect + $toolbarHeight; + $height = $width / $aspect; } elseif ($height) { - $width = ($height-$toolbarHeight)*$aspect; + $width = $height * $aspect; } else { $width = $this->providers['all']['params']['width']['default']; - $height = $width/$aspect + $toolbarHeight; + $height = $width / $aspect; } } return array( diff --git a/src/tags.php b/src/tags.php index d293f81..4f9be67 100644 --- a/src/tags.php +++ b/src/tags.php @@ -35,6 +35,7 @@ function oui_video($atts, $thing) /* * Define player src and parameters. */ + $no_cookie ?: $no_cookie = get_pref('oui_video_youtube_no_cookie'); $player_infos = $oui_video->playerInfos($provider, $no_cookie); $src = $player_infos['src'] . $video_id; $params = $player_infos['params']; @@ -43,16 +44,18 @@ function oui_video($atts, $thing) $used_params = array(); foreach ($params as $param => $infos) { - $pref = get_pref('oui_video_' . $provider . '_' . $param); - $default = $infos['default']; - $att_name = str_replace('-', '_', $param); - $att = $$att_name; - - if ($att === '' && $pref !== $default) { - // if the attribute is empty, get the related pref value. - $used_params[] = $param . '=' . $pref; - } elseif ($att !== '') { - $used_params[] = $param . '=' . $att; + if ($param !== 'no_cookie') { + $pref = get_pref('oui_video_' . $provider . '_' . $param); + $default = $infos['default']; + $att_name = str_replace('-', '_', $param); + $att = $$att_name; + + if ($att === '' && $pref !== $default) { + // if the attribute is empty, get the related pref value. + $used_params[] = $param . '=' . $pref; + } elseif ($att !== '') { + $used_params[] = $param . '=' . $att; + } } } @@ -77,7 +80,7 @@ function oui_video($atts, $thing) } // Get the video size. - $video_size = $oui_video->videoSize($dims); + $video_size = $oui_video->playerSize($dims); $width = $video_size['width']; $height = $video_size['height']; @@ -123,5 +126,5 @@ function oui_if_video($atts, $thing) } // Txp 4.6+ don't need EvalElse() anymore. - return parse($thing, $result); + return defined('PREF_PLUGIN') ? parse($thing, $result) : parse(EvalElse($thing, $result)); } diff --git a/textpacks/en-gb.textpack b/textpacks/en-gb.textpack index cca0cfd..701414a 100644 --- a/textpacks/en-gb.textpack +++ b/textpacks/en-gb.textpack @@ -1,15 +1,15 @@ #@admin #Default language, en-us, en-gb oui_video => Video embeding (oui_video) -oui_video_provider => Provider +oui_video_provider => Favourite provider oui_video_provider_dailymotion => Dailymotion oui_video_provider_vimeo => Vimeo oui_video_provider_youtube => Youtube -oui_video_custom_field => Video field +oui_video_custom_field => Video field by default oui_video_vimeo => Vimeo player (oui_video) oui_video_width => Width in pixels oui_video_height => Height in pixels -oui_video_ratio => Ratio by default +oui_video_ratio => Ratio (calculate the missing size) oui_video_youtube_prefs => Display the Youtube player prefs oui_video_vimeo_prefs => Display the Vimeo player prefs oui_video_dailymotion_prefs => Display the Dailymotion player prefs @@ -49,7 +49,7 @@ oui_video_youtube_loop => Replay the video once finished oui_video_youtube_modestbranding => Modest branding oui_video_youtube_origin => Origin domain (api) oui_video_youtube_playerapiid => Player id (api) -oui_video_youtube_playsinline => playsinline +oui_video_youtube_playsinline => Avoid fullscreen playback by default on iOS oui_video_youtube_playlist => Video list (id's) to play then oui_video_youtube_rel => Display related videos at the end oui_video_youtube_showinfo => Display video informations diff --git a/textpacks/fr-fr.textpack b/textpacks/fr-fr.textpack index e994305..b214c8a 100755 --- a/textpacks/fr-fr.textpack +++ b/textpacks/fr-fr.textpack @@ -1,15 +1,15 @@ #@admin #@language fr-fr oui_video => Intégration vidéo (oui_video) -oui_video_provider => Provider +oui_video_provider => Service préféré oui_video_provider_dailymotion => Dailymotion oui_video_provider_vimeo => Vimeo oui_video_provider_youtube => Youtube -oui_video_custom_field => Champ de la vidéo +oui_video_custom_field => Champ de la vidéo par défaut oui_video_vimeo => Lecteur Vimeo (oui_video) oui_video_width => Largeur en pixels oui_video_height => Hauteur en pixels -oui_video_ratio => Ratio par défaut +oui_video_ratio => Ratio (calcule la dimension manquante) oui_video_youtube_prefs => Afficher les préférences du lecteur Youtube oui_video_vimeo_prefs => Afficher les préférences du lecteur Vimeo oui_video_dailymotion_prefs => Afficher les préférences du lecteur Dailymotion @@ -49,7 +49,7 @@ oui_video_youtube_loop => Lire en boucle oui_video_youtube_modestbranding => Logo discret oui_video_youtube_origin => Domaine d'origine (api) oui_video_youtube_playerapiid => id du lecteur (api) -oui_video_youtube_playsinline => playsinline +oui_video_youtube_playsinline => Empêcher la lecture plein écran par défaut sur iOS oui_video_youtube_playlist => Liste de vidéos (id's) à lire ensuite oui_video_youtube_rel => Afficher les vidéos associées en fin de lecture oui_video_youtube_start => Commencer la lecture à la seconde: