From 3a76acd7fcb073088d5de6b3c75b07ef5a66632d Mon Sep 17 00:00:00 2001 From: NicolasGraph Date: Mon, 16 Oct 2017 09:35:16 +0200 Subject: [PATCH] Fixes the play attribute value inheritence in the conditional tag --- src/player/Public.php | 8 ++++-- src/tags.php | 64 ++++++++++++++++--------------------------- 2 files changed, 29 insertions(+), 43 deletions(-) diff --git a/src/player/Public.php b/src/player/Public.php index 146b706..1e29ff9 100644 --- a/src/player/Public.php +++ b/src/player/Public.php @@ -199,7 +199,9 @@ public function getInfos($fallback = true) if ($this->infos && array_key_exists($this->getPlay(), $this->infos) || $this->setInfos()) { return $this->infos; } elseif ($fallback) { - return $this->setFallbackInfos(); + $this->setFallbackInfos(); + + return $this->infos; } return false; @@ -231,7 +233,9 @@ public function getProvider($fallback = true) if ($this->provider && array_key_exists($this->getPlay(), $this->infos) || $this->setInfos()) { return $this->provider; } elseif ($fallback) { - return $this->setFallbackInfos(); + $this->setFallbackInfos(); + + return $this->provider; } return false; diff --git a/src/tags.php b/src/tags.php index f369179..836bd57 100644 --- a/src/tags.php +++ b/src/tags.php @@ -35,37 +35,29 @@ function oui_player($atts) { global $thisarticle, $oui_player_item; - // Set tag attributes - $get_atts = Oui\Player\Main::getAtts(__FUNCTION__); - $latts = lAtts($get_atts, $atts); + $namespace = 'Oui\Player'; // Plugin namespace. + $main_class = $namespace . '\Main'; // Main plugin class. + $lAtts = lAtts($main_class::getAtts(__FUNCTION__), $atts); // Gets used attributes. - extract($latts); + extract($lAtts); // Extracts used attributes. if (!$play) { - if ($oui_player_item) { - $provider = $oui_player_item['provider']; - $play = $oui_player_item['url']; + if (isset($oui_player_item['play'])) { + $play = $oui_player_item['play']; } else { - $play = strtolower(get_pref('oui_player_custom_field')); + $play = $thisarticle[get_pref('oui_player_custom_field')]; } } - $play = isset($thisarticle[$play]) ? $thisarticle[$play] : $play; - - if ($provider) { - $player = 'Oui\Player\\' . $provider; - - if (!class_exists($player)) { - trigger_error('Unknown or unset provider: "' . $provider . '".'); - return; - } - } else { - $player = 'Oui\Player\Main'; + if (!$provider && isset($oui_player_item['provider'])) { + $provider = $oui_player_item['provider']; } - $out = $player::getInstance($play, $latts)->getPlayer(); + $class_in_use = $provider ? $namespace . '\\' . ucfirst($provider) : $main_class; - return doLabel($label, $labeltag).(($wraptag) ? doTag($out, $wraptag, $class) : $out); + $player = $class_in_use::getInstance($play, $lAtts)->getPlayer(); + + return doLabel($label, $labeltag).(($wraptag) ? doTag($player, $wraptag, $class) : $player); } /** @@ -83,31 +75,21 @@ function oui_if_player($atts, $thing) { global $thisarticle, $oui_player_item; - // Sets tag attributes - $get_atts = Oui\Player\Main::getAtts(__FUNCTION__); - $latts = lAtts($get_atts, $atts); + $namespace = 'Oui\Player'; // Plugin namespace. + $main_class = $namespace . '\Main'; // Main plugin class. - extract($latts); + extract(lAtts($main_class::getAtts(__FUNCTION__), $atts)); // Extracts used attributes. - // Checks if the play attribute value is recognised. - if ($provider) { - $player = 'Oui\Player\\' . $provider; + $play ?: $play = $thisarticle[get_pref('oui_player_custom_field')]; - if (!class_exists($player)) { - trigger_error('Unknown or unset provider: "' . $provider . '".'); - return; - } - } else { - $player = 'Oui\Player\Main'; - } - - $play ?: $play = strtolower(get_pref('oui_player_custom_field')); + $class_in_use = $provider ? $namespace . '\\' . ucfirst($provider) : $main_class; - $obj = $player::getInstance(isset($thisarticle[$play]) ? $thisarticle[$play] : $play); - - $oui_player_item = $obj->isValid(); + if ($is_valid = $class_in_use::getInstance($play)->isValid()) { + $oui_player_item = array('play' => $play); + $provider ? $oui_player_item['provider'] = $provider : ''; + } - $out = parse($thing, $oui_player_item); + $out = parse($thing, $is_valid); unset($GLOBALS['oui_player_item']);