From 4fed77c1a8ea585d02ce54abb270f95da7c7ee79 Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 6 Nov 2019 23:27:51 -0600 Subject: [PATCH 01/14] rm angular-resource --- src/view/header.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/view/header.php b/src/view/header.php index 5038ea9..d385bc3 100644 --- a/src/view/header.php +++ b/src/view/header.php @@ -27,7 +27,6 @@ - From 3a6b27030728be07f597c2bc39acd1f47f4f8de5 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 7 Nov 2019 16:27:11 -0600 Subject: [PATCH 02/14] Fix some opengraph tags --- src/view/header.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/view/header.php b/src/view/header.php index d385bc3..fe206b0 100644 --- a/src/view/header.php +++ b/src/view/header.php @@ -8,11 +8,12 @@ + - + - + From 895a3c9b548f557bcab623d615b13bb51897b418 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 7 Nov 2019 16:53:38 -0600 Subject: [PATCH 03/14] Fix uploading in FF 71 --- src/upload.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/upload.php b/src/upload.php index 0eb3f24..e79758d 100644 --- a/src/upload.php +++ b/src/upload.php @@ -68,7 +68,7 @@ function checkUploads($files) //Get and check mime types (ignoring provided ones) $finfo = new finfo(FILEINFO_MIME_TYPE); $mimeType = $finfo->file($file['tmp_name']); - if ($mimeType != "application/xml" && $mimeType != "text/xml") + if (!acceptableMimeType($mimeType)) { if (DEBUG) warn('File: ' . $file['tmp_name'] . ': Invalid MIME type ' . $mimeType); unset($files[$index]); @@ -79,6 +79,22 @@ function checkUploads($files) return $files; } +/** + * @brief Check that a mime type matches ones we think are OK. + * @param $mimeType {string} MIME type + * @returns true or false + */ +function acceptableMimeType($mimeType) { + switch ($mimeType) { + case "application/xml": + case "text/xml": + case "text/plain": + return true; + default: + return FALSE; + } +} + //var_export($_POST); //var_export($_FILES); From f661437fa904d6a59ee9cc3b3591d39488073fdc Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 7 Nov 2019 16:53:52 -0600 Subject: [PATCH 04/14] Cleanup downloads --- src/db.php | 5 +---- src/msqur.php | 1 - 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/db.php b/src/db.php index 33fa264..697e554 100644 --- a/src/db.php +++ b/src/db.php @@ -297,7 +297,6 @@ public function getCachedMSQ($id) public function getMSQForDownload($id) { - if (!$this->connect()) return null; $xml = FALSE; @@ -312,12 +311,10 @@ public function getMSQForDownload($id) $result = $st->fetch(PDO::FETCH_ASSOC); $st->closeCursor(); $xml = $result['xml']; - if (DEBUG) debug('Cached, returning HTML.'); } else { - echo "
No result for $id
"; - echo '
Invalid MSQ err 2
'; + echo "404 no such MSQ"; return null; } } diff --git a/src/msqur.php b/src/msqur.php index 2d2c8fb..277d7bd 100644 --- a/src/msqur.php +++ b/src/msqur.php @@ -45,7 +45,6 @@ public function getCachedMSQ($id) public function getMSQForDownload($id) { - return $this->db->getMSQForDownload($id); } From 66c8243d49debd8231e3b44747a4f2b0ff3a7037 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 7 Nov 2019 17:52:56 -0600 Subject: [PATCH 05/14] Fix debug messages --- src/db.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/db.php b/src/db.php index 697e554..35b4b7c 100644 --- a/src/db.php +++ b/src/db.php @@ -217,7 +217,7 @@ public function resetReingest($id) try { - if (DEBUG) debug('Updating HTML cache...'); + if (DEBUG) debug('Resetting reingest flag...'); $st = $this->db->prepare("UPDATE metadata m SET m.reingest=FALSE WHERE m.id = :id"); DB::tryBind($st, ":id", $id); if ($st->execute()) @@ -314,7 +314,7 @@ public function getMSQForDownload($id) } else { - echo "404 no such MSQ"; + error("No such XML for $id"); return null; } } @@ -645,7 +645,7 @@ public function updateMetadata($id, $metadata) try { - if (DEBUG) debug('Updating HTML cache...'); + if (DEBUG) debug('Updating MSQ metadata...'); $st = $this->db->prepare("UPDATE metadata md SET md.fileFormat = :fileFormat, md.signature = :signature, md.firmware = :firmware, md.author = :author WHERE md.id = :id"); //$xml = mb_convert_encoding($html, "UTF-8"); DB::tryBind($st, ":id", $id); From 14347206d1fc3f8fda72eabf4e5b3a8032d822d2 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 7 Nov 2019 17:53:32 -0600 Subject: [PATCH 06/14] Fix download link --- src/msq.php | 3 +-- src/view/header.php | 1 + src/view/msqur.css | 12 ++++++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/msq.php b/src/msq.php index 3b2b97d..2c8a7d6 100644 --- a/src/msq.php +++ b/src/msq.php @@ -60,10 +60,9 @@ public function parseMSQ($xml, &$engine, &$metadata) error($error->message); } - $html['header'] = '
Unable to parse MSQ.
'; + throw new MSQ_ParseException("Error parsing XML", '
Unable to parse MSQ.
'); } else if ($msq) { $msqHeader = '
'; - $msqHeader .= ''; $msqHeader .= "
Format Version: " . $msq->versionInfo['fileFormat'] . "
"; $msqHeader .= "
MS Signature: " . $msq->versionInfo['signature'] . "
"; $msqHeader .= "
Tuning SW: " . $msq->bibliography['author'] . "
"; diff --git a/src/view/header.php b/src/view/header.php index fe206b0..7512b7c 100644 --- a/src/view/header.php +++ b/src/view/header.php @@ -96,6 +96,7 @@
+ \ No newline at end of file diff --git a/src/view/msqur.css b/src/view/msqur.css index 523df5c..dff957a 100644 --- a/src/view/msqur.css +++ b/src/view/msqur.css @@ -82,9 +82,17 @@ div#splash img.tutorial { div#settings { z-index: 999; background: rgba(224, 224, 224, 32); - position: absolute; + float: right; margin-top: 4px; - right: 8px; +} + +img#settingsIcon { + cursor: pointer; +} + +div#downloadLink { + margin: 5px; + float: right; } #fileDropZone { From 9de6c6e2b79ff078cbe706e169c88e745f51f4c7 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 7 Nov 2019 20:32:07 -0600 Subject: [PATCH 07/14] Move sections to jQuery tabs --- src/msq.php | 29 ++++++++++++++++++++--------- src/msqur.php | 4 ++-- src/view/msqur.css | 10 ---------- src/view/msqur.js | 8 +++++--- 4 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/msq.php b/src/msq.php index 2c8a7d6..a3ab209 100644 --- a/src/msq.php +++ b/src/msq.php @@ -100,8 +100,16 @@ public function parseMSQ($xml, &$engine, &$metadata) $engineSchema = getEngineSchema(); - $html["precurves"] = '
2D Tables (Curves)
'; - $html["curves"] = ""; + $html["tabList"] = << + + EOT; + + $html["tabList"] .= '
'; foreach ($curves as $curve) { if (in_array($curve['id'], $this->msq_curve_blacklist)) @@ -128,13 +136,13 @@ public function parseMSQ($xml, &$engine, &$metadata) $yBins = $this->findConstant($msq, $curve['yBinConstant']); $xAxis = preg_split("/\s+/", trim($xBins)); $yAxis = preg_split("/\s+/", trim($yBins)); - $html["curves"] .= $this->msqTable2D($curve, $curve['xMin'], $curve['xMax'], $xAxis, $curve['yMin'], $curve['yMax'], $yAxis, $help); + $html["tabList"] .= $this->msqTable2D($curve, $curve['xMin'], $curve['xMax'], $xAxis, $curve['yMin'], $curve['yMax'], $yAxis, $help); } else if (DEBUG) debug('Missing/unsupported curve information: ' . $curve['id']); } + $html["tabList"] .= '
'; - $html["pretables"] = '
3D Tables
';; - $html["tables"] = ""; + $html["tabList"] .= '
'; foreach ($tables as $table) { if (DEBUG) debug('Table: ' . $table['id']); @@ -153,13 +161,13 @@ public function parseMSQ($xml, &$engine, &$metadata) $xAxis = preg_split("/\s+/", trim($xBins)); $yAxis = preg_split("/\s+/", trim($yBins)); $zData = preg_split("/\s+/", trim($zBins));//, PREG_SPLIT_NO_EMPTY); //, $limit); - $html["tables"] .= $this->msqTable3D($table, $xAxis, $yAxis, $zData, $help); + $html["tabList"] .= $this->msqTable3D($table, $xAxis, $yAxis, $zData, $help); } else if (DEBUG) debug('Missing/unsupported table information: ' . $table['id']); } + $html["tabList"] .= '
'; - $html["preconstants"] = '
Constants
'; - $html["constants"] = ""; + $html["tabList"] .= '
'; foreach ($constants as $key => $config) { if ($config[0] == "array") continue; //TODO Skip arrays until blacklist is done @@ -179,9 +187,12 @@ public function parseMSQ($xml, &$engine, &$metadata) if (array_key_exists($key, $helpTexts)) $help = $helpTexts[$key]; - $html["constants"] .= $this->msqConstant($key, $value, $help); + $html["tabList"] .= $this->msqConstant($key, $value, $help); } } + $html["tabList"] .= '
'; + $html["tabList"] .= ''; + } return $html; diff --git a/src/msqur.php b/src/msqur.php index 277d7bd..bc5cbd3 100644 --- a/src/msqur.php +++ b/src/msqur.php @@ -164,9 +164,9 @@ public function view($id) foreach($groupedHtml as $group => $v) { //TODO Group name as fieldset legend or sth - $html .= "
"; + //$html .= "
"; $html .= $v; - $html .= '
'; + //$html .= '
'; } $this->db->updateCache($id, $html); diff --git a/src/view/msqur.css b/src/view/msqur.css index dff957a..abb197d 100644 --- a/src/view/msqur.css +++ b/src/view/msqur.css @@ -118,16 +118,6 @@ table caption { padding: 0.2em; } -div[class^="group-"] { - border: 4px solid #F0F0F0; -} - -div.group-header { - font-size: 3em; - text-align: center; - font-style: bold; -} - table.msq td:hover { background-color: magenta !important; } diff --git a/src/view/msqur.js b/src/view/msqur.js index cdab480..b006cde 100644 --- a/src/view/msqur.js +++ b/src/view/msqur.js @@ -70,10 +70,12 @@ $(function() { heightStyle: "content", activate: doChart }; + + $('div#tabList').tabs(); - $('div.group-curves').accordion(accordionOptions); - $('div.group-tables').accordion(accordionOptions); - $('div.constant').tooltip(); + $('div#tab_tables').accordion(accordionOptions); + $('div#tab_curves').accordion(accordionOptions); + $('div#tab_constants').tooltip(); Chart.defaults.global.animation = false; //Chart.defaults.global.responsive = true; From cd65a10284c20209222ad24aa1b6371df5d73ab9 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 7 Nov 2019 20:56:10 -0600 Subject: [PATCH 08/14] Style constants slightly better --- src/msq.php | 4 ++-- src/view/msqur.css | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/msq.php b/src/msq.php index a3ab209..89d465b 100644 --- a/src/msq.php +++ b/src/msq.php @@ -27,7 +27,7 @@ class MSQ /** * @brief Format a constant to HTML * @param $constant The constant name - * @param $value It's value + * @param $value Its value * @returns String HTML \ */ private function msqConstant($constant, $value, $help) @@ -35,7 +35,7 @@ private function msqConstant($constant, $value, $help) //var_export($constant); //var_export($value); //var_export($help); - return "
$constant: $value
"; + return "$constant:$value"; } /** diff --git a/src/view/msqur.css b/src/view/msqur.css index abb197d..5de327f 100644 --- a/src/view/msqur.css +++ b/src/view/msqur.css @@ -155,6 +155,28 @@ div.chart { display: inline; } +/* msqur.css | http://localhost:5050/view/msqur.css */ + +div#tab_constants { + display: flex; + flex-flow: column wrap; + max-height: 900px; + overflow: auto; + max-width: 100%; +} + +span.constant:nth-child(even) { + background-color: #e4e4e4; +} + +span.constant { + margin: 0px 10px; +} + +span.constant span.value { + float: right; +} + #engineForm { display: table; } From ba237ad98d1d5b7308b5b7c491d3a50d15766509 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 7 Nov 2019 21:08:37 -0600 Subject: [PATCH 09/14] Fix header download link --- src/view/header.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/view/header.php b/src/view/header.php index 7512b7c..0717f71 100644 --- a/src/view/header.php +++ b/src/view/header.php @@ -96,7 +96,7 @@ - + \ No newline at end of file From 86166cda7c776b442f805a7d0559621d2b2a6c27 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 7 Nov 2019 21:28:44 -0600 Subject: [PATCH 10/14] Add real 404 --- src/db.php | 45 +++++---------------------------------------- src/download.php | 19 +++++++++++++++---- src/msqur.php | 17 ++++++++--------- src/view.php | 17 +++++++++++++++-- 4 files changed, 43 insertions(+), 55 deletions(-) diff --git a/src/db.php b/src/db.php index 35b4b7c..0cc3112 100644 --- a/src/db.php +++ b/src/db.php @@ -249,19 +249,19 @@ public function getCachedMSQ($id) if (DISABLE_MSQ_CACHE) { if (DEBUG) debug('Cache disabled.'); - return FALSE; + return null; } if ($this->needReingest($id)) { if (DEBUG) debug('Flagged for reingest.'); $this->resetReingest($id); - return FALSE; + return null; } if (!$this->connect()) return null; - $html = FALSE; + $html = null; try { @@ -276,15 +276,14 @@ public function getCachedMSQ($id) if ($html === NULL) { if (DEBUG) debug('No HTML cache found.'); - return FALSE; + return null; } else if (DEBUG) debug('Cached, returning HTML.'); } else { if (DEBUG) debug("No result for $id"); - echo '
Invalid MSQ
'; - return null; + return FALSE; } } catch (PDOException $e) @@ -295,37 +294,6 @@ public function getCachedMSQ($id) return $html; } - public function getMSQForDownload($id) - { - if (!$this->connect()) return null; - - $xml = FALSE; - - try - { - $st = $this->db->prepare("SELECT xml FROM msqs INNER JOIN metadata ON metadata.msq = msqs.id WHERE metadata.id = :id LIMIT 1"); - DB::tryBind($st, ":id", $id); - $st->execute(); - if ($st->rowCount() > 0) - { - $result = $st->fetch(PDO::FETCH_ASSOC); - $st->closeCursor(); - $xml = $result['xml']; - } - else - { - error("No such XML for $id"); - return null; - } - } - catch (PDOException $e) - { - $this->dbError($e); - } - - return $xml; - } - /** * @brief Get a list of MSQs * @param $bq The BrowseQuery to filter results @@ -752,9 +720,6 @@ public function getXML($id) $result = $st->fetch(PDO::FETCH_ASSOC); $st->closeCursor(); $xml = $result['xml']; - } else { - //TODO Send real 404 - echo '
404 MSQ not found.
'; } } catch (PDOException $e) diff --git a/src/download.php b/src/download.php index 6a034e6..47a7fc7 100644 --- a/src/download.php +++ b/src/download.php @@ -18,11 +18,22 @@ require "msqur.php"; if (isset($_GET['msq'])) { - header('Content-Type: application/xml'); - header('Content-Disposition: attachment; filename="' . $_GET['msq'] . '.msq"'); - header('Pragma: no-cache'); + $id = $_GET['msq']; //TODO Sanitize - echo $msqur->getMSQForDownload($_GET['msq']); + $xml = $msqur->getMSQForDownload($id); + + if ($xml) { + header('Content-Type: application/xml'); + header('Content-Disposition: attachment; filename="' . $id . '.msq"'); + header('Pragma: no-cache'); + echo trim($xml); //`trim` is a workaround for #30 + } else { + http_response_code(404); + unset($_GET['msq']); + include "view/header.php"; + echo '
404 MSQ file not found.
'; + include "view/footer.php"; + } } else { include "index.php"; } diff --git a/src/msqur.php b/src/msqur.php index bc5cbd3..7632678 100644 --- a/src/msqur.php +++ b/src/msqur.php @@ -45,7 +45,7 @@ public function getCachedMSQ($id) public function getMSQForDownload($id) { - return $this->db->getMSQForDownload($id); + return $this->db->getXML($id); } public function addMSQs($files, $engineid) @@ -140,16 +140,15 @@ public function getEngineCodeList($make = null) */ public function view($id) { - $this->header(); if (DEBUG) debug('Load MSQ: ' . $id); //Get cached HTML and display it, or reparse and display (in order) $html = $this->getCachedMSQ($id); - if ($html !== null) + if ($html !== FALSE) { $this->db->updateViews($id); $msq = new MSQ(); //ugh - if ($html == FALSE) + if ($html == null) { $engine = array(); $metadata = array(); @@ -172,14 +171,14 @@ public function view($id) $this->db->updateCache($id, $html); } catch (MSQ_ParseException $e) { $html = $e->getHTMLMessage(); - } + } finally { + return $html; + } } } } - //TODO else show 404 - - echo $html; - $this->footer(); + + return null; } public function addEngine($make, $code, $displacement, $compression, $turbo) diff --git a/src/view.php b/src/view.php index 58561a9..997c275 100644 --- a/src/view.php +++ b/src/view.php @@ -18,7 +18,20 @@ require "msqur.php"; if (isset($_GET['msq'])) { - echo $msqur->view($_GET['msq']); + $id = $_GET['msq']; //TODO Sanitize + $html = $msqur->view($_GET['msq']); + if ($html !== null) { + include "view/header.php"; + echo $html; + include "view/footer.php"; + } else { + http_response_code(404); + unset($_GET['msq']); + include "view/header.php"; + echo '
404 MSQ file not found.
'; + include "view/footer.php"; + } +} else { + include "index.php"; } -else include "index.php"; ?> From db16a21eaef7b130b02f2ccd40a5f9a3413324fe Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 7 Nov 2019 23:06:58 -0600 Subject: [PATCH 11/14] Downgrade travis php 7.2->7.1 --- .travis.yml | 2 +- src/download.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 884cf67..425d1ab 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: php php: -- '7.2' +- '7.1' branches: only: diff --git a/src/download.php b/src/download.php index 47a7fc7..6247c93 100644 --- a/src/download.php +++ b/src/download.php @@ -31,7 +31,7 @@ http_response_code(404); unset($_GET['msq']); include "view/header.php"; - echo '
404 MSQ file not found.
'; + echo '
404 MSQ file not found.
'; include "view/footer.php"; } } else { From b84bdfdf908d108703a614ec031b9c3f9e0b05fd Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 7 Nov 2019 23:09:05 -0600 Subject: [PATCH 12/14] Fix heredoc --- src/msq.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/msq.php b/src/msq.php index 89d465b..fc4c200 100644 --- a/src/msq.php +++ b/src/msq.php @@ -107,7 +107,7 @@ public function parseMSQ($xml, &$engine, &$metadata)
  • 2D Tables (Curves)
  • Constants
  • - EOT; +EOT; $html["tabList"] .= '
    '; foreach ($curves as $curve) From f67c72f58282f0f5f2214b89bc9abe1689368a65 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 7 Nov 2019 23:11:10 -0600 Subject: [PATCH 13/14] Ok, have to upgrade for phpunit. Sigh. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 425d1ab..884cf67 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: php php: -- '7.1' +- '7.2' branches: only: From 2243d8e8e717bf42e01417f470ecabd398eba5bc Mon Sep 17 00:00:00 2001 From: Nick Date: Fri, 8 Nov 2019 09:19:05 -0600 Subject: [PATCH 14/14] Fix viewing cached msq --- src/msqur.php | 6 +++++- src/view.php | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/msqur.php b/src/msqur.php index 7632678..1f9dfa3 100644 --- a/src/msqur.php +++ b/src/msqur.php @@ -173,8 +173,12 @@ public function view($id) $html = $e->getHTMLMessage(); } finally { return $html; - } + } + } else { + error("Null xml"); } + } else { + return $html; } } diff --git a/src/view.php b/src/view.php index 997c275..eef1d90 100644 --- a/src/view.php +++ b/src/view.php @@ -19,7 +19,7 @@ if (isset($_GET['msq'])) { $id = $_GET['msq']; //TODO Sanitize - $html = $msqur->view($_GET['msq']); + $html = $msqur->view($id); if ($html !== null) { include "view/header.php"; echo $html;