summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan José González <juanjosegzl@libreoffice.org>2024-01-14 11:12:01 -0600
committerOlivier Hallot <olivier.hallot@libreoffice.org>2024-01-16 06:24:34 +0100
commitb347baf1eaefc0c5538ec6a4ea6b4a5ba2f8a895 (patch)
tree3f26eabae0424412aa5085d2c168e71e089c9ce6
parent3d3cff05f9da95f870fd3c5b1336716cdaec7fc9 (diff)
Add check xhp async endpoint.
I am adding the endpoint first before the client using it, to prevent what happend with the render endpoint returning 404. Change-Id: I118b4adacf026ef85781f9e8d91d9cfdd00719f5 Reviewed-on: https://gerrit.libreoffice.org/c/dev-tools/+/162050 Reviewed-by: Olivier Hallot <olivier.hallot@libreoffice.org> Tested-by: Olivier Hallot <olivier.hallot@libreoffice.org>
-rw-r--r--help3/xhpeditor/api/check_xhp.php61
1 files changed, 61 insertions, 0 deletions
diff --git a/help3/xhpeditor/api/check_xhp.php b/help3/xhpeditor/api/check_xhp.php
new file mode 100644
index 00000000..7c0ca865
--- /dev/null
+++ b/help3/xhpeditor/api/check_xhp.php
@@ -0,0 +1,61 @@
+<?php
+require_once './helpers.php';
+
+try {
+ $method = get_method();
+ $data = get_data();
+
+ if (!isset($data['xhpdoc'])) {
+ respond(['message' => 'XHP is required'], 400);
+ }
+
+ $xhp = $data['xhpdoc'];
+
+ $all_errors = [
+ 'xhp_errors' => [],
+ 'duplicated_ids' => [],
+ ];
+
+ libxml_use_internal_errors(true);
+ libxml_clear_errors();
+
+ $root = 'helpdocument';
+ $old = new DOMDocument;
+
+ if (!$old->loadXML($xhp)) {
+ $all_errors['xhp_errors'] = libxml_get_errors();
+ libxml_clear_errors();
+ } else {
+ $creator = new DOMImplementation;
+ $doctype = $creator->createDocumentType($root, null, '../xmlhelp.dtd');
+ $new = $creator->createDocument(null, null, $doctype);
+ $new->encoding = "utf-8";
+
+ $oldNode = $old->getElementsByTagName($root)->item(0);
+ $newNode = $new->importNode($oldNode, true);
+ $new->appendChild($newNode);
+ libxml_clear_errors();
+
+ if(!$new->validate()) {
+ $all_errors['xhp_errors'] = libxml_get_errors();
+ libxml_clear_errors();
+ }
+
+ $tags_id_uniq = array('paragraph','note','warning','tip','h1','h2','h3','h4','h5','h6');
+ $xmlarray = simplexml_load_string($xhp);
+ $i = 0;
+ foreach($tags_id_uniq as $tag_uniq) {
+ foreach ($xmlarray->xpath("//$tag_uniq") as $tag){
+ $idarray[$i] = $tag['id'];
+ ++$i;
+ }
+ }
+ $dupped_array = array_values(array_unique(array_diff_key($idarray, array_unique($idarray))));
+ $all_errors['duplicated_ids'] = $dupped_array;
+ }
+
+ respond(['errors' => $all_errors]);
+}
+catch (Exception $e) {
+ respond(['message' => 'Unexpected error'], 500);
+}