Skip to content

Commit

Permalink
Fixes the play attribute value inheritence in the conditional tag
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasGraph committed Oct 16, 2017
1 parent 9c18c2c commit 3a76acd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 43 deletions.
8 changes: 6 additions & 2 deletions src/player/Public.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
64 changes: 23 additions & 41 deletions src/tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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']);

Expand Down

0 comments on commit 3a76acd

Please sign in to comment.