Skip to content

Commit

Permalink
Fix for xml that doesn't have targetFolder set #1120
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnSmith-LT committed Jun 23, 2022
1 parent 189bdd9 commit 2b5db95
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions website_code/php/xmlInspector.php
Expand Up @@ -142,6 +142,31 @@ private function isValidXml($string)
return $ok;
}

private function recognise_template($check) {
$probably = "decision";
$probably_weight = $this->test_unrecognised_template(["name", "displayMode", "newBtnLabel", "backBtn", "fwdBtn", "emailBtn", "printBtn", "viewThisBtn", "closeBtn", "moreInfoString", "lessInfoString", "helpString", "resultString", "overviewString", "posAnswerString", "fromRangeString", "viewAllString", "errorString", "sliderError", "noQ", "noA", "resultEndString", "theme"], $check);

$new_weight = $this->test_unrecognised_template(["name", "language", "navigation", "textSize", "theme", "displayMode", "responsive"], $check);
if ($new_weight > $probably_weight) {
$probably = "Nottingham";
$probably_weight = $new_weight;
}

$new_weight = $this->test_unrecognised_template(["language", "name", "theme"], $check);
if ($new_weight > $probably_weight) {
$probably = "site";
}

return $probably;
}

private function test_unrecognised_template($test_array, $check) {
$count = 0;
foreach($test_array as $t)
if ( $check[$t] ) $count++;
return ($count / count($test_array)) * 100;
}

public function loadTemplateXML($name)
{
_debug("Trying to simplexml_load_file : $name");
Expand Down Expand Up @@ -230,14 +255,20 @@ public function loadTemplateXML($name)
$this->theme = "default";
}

$this->target = (string) $this->xml['targetFolder'];
if ($this->xml['targetFolder']) {
$this->target = (string) $this->xml['targetFolder'];
}
else { // Sniff the XML to figure out if Bootstrap or XOT
$this->target = $this->recognise_template($this->xml);
}

if ($this->target == 'site') { // Bootstrap
$this->logoL = (string) $this->xml['logoL'];
$this->logoR = (string) $this->xml['logoR'];
$this->logoLHide = filter_var($this->xml['logoLHide'], FILTER_VALIDATE_BOOLEAN);
$this->logoRHide = filter_var($this->xml['logoRHide'], FILTER_VALIDATE_BOOLEAN);
}
else { // XOT
else { // Assume XOT
$this->ic = (string) $this->xml['ic'];
$this->icHide = filter_var($this->xml['icHide'], FILTER_VALIDATE_BOOLEAN);
}
Expand Down

0 comments on commit 2b5db95

Please sign in to comment.