[fusion-commits] r3035 - in sandbox/cms_refactor: lib templates/mapguide

svn_fusion at osgeo.org svn_fusion at osgeo.org
Thu Jul 26 06:51:45 PDT 2018


Author: jng
Date: 2018-07-26 06:51:45 -0700 (Thu, 26 Jul 2018)
New Revision: 3035

Added:
   sandbox/cms_refactor/templates/mapguide/index.php
Modified:
   sandbox/cms_refactor/lib/fusion.js
Log:
Implement a new server-side template entry point. This gives us:

 1. A way to safely append script tags, as appending such tags on the client-side via document.write is flagged as unsafe. Doing it server side is a safer approach. This is only needed for Google Maps support. For other providers, it is not necessary to add script tags (OSM/Stamen can just use the XYZ layer). Bing does not require any script tags.
 2. A way to pre-load and parse out the Application Definition JSON avoiding some roundtrips.

fusion.js has been updated to support initialization from JSON payload directly.

Modified: sandbox/cms_refactor/lib/fusion.js
===================================================================
--- sandbox/cms_refactor/lib/fusion.js	2018-07-26 12:20:53 UTC (rev 3034)
+++ sandbox/cms_refactor/lib/fusion.js	2018-07-26 13:51:45 UTC (rev 3035)
@@ -344,15 +344,21 @@
             // Override the pre-created sessionId by user specified sessionId(if exist)
             this.sessionId = sessionIdParam || options.sessionId || this.sessionId;
         
-            if (options.applicationDefinitionURL) {
-                this.applicationDefinitionURL = options.applicationDefinitionURL;            
+            if (options.appDef) { //An appdef was alread loaded via the server-side entry point
+                this.newTemplatePath = true;
+                this.appDefJson = options.appDef;
+                this.applicationDefinitionURL = "ApplicationDefinition_Generated.xml";
             } else {
-                var queryAppDef = this.getQueryParam('ApplicationDefinition');
-                if (queryAppDef) {
-                    this.applicationDefinitionURL = queryAppDef.split('+').join(' ');
-                    this.appDefJson = null;   //wipe out any preloaded AppDef in a single file build
+                if (options.applicationDefinitionURL) {
+                    this.applicationDefinitionURL = options.applicationDefinitionURL;            
                 } else {
-                    this.applicationDefinitionURL = 'ApplicationDefinition.xml';
+                    var queryAppDef = this.getQueryParam('ApplicationDefinition');
+                    if (queryAppDef) {
+                        this.applicationDefinitionURL = queryAppDef.split('+').join(' ');
+                        this.appDefJson = null;   //wipe out any preloaded AppDef in a single file build
+                    } else {
+                        this.applicationDefinitionURL = 'ApplicationDefinition.xml';
+                    }
                 }
             }
             if (Fusion._singleFile) {
@@ -1655,8 +1661,6 @@
         }
 		xhr.open("POST", url, false);
 		xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
-		xhr.setRequestHeader("Content-length", params.length);
-		xhr.setRequestHeader("Connection", "close");
 		xhr.send(params);
 		
         var o = Fusion.parseJSON(xhr.responseText);

Added: sandbox/cms_refactor/templates/mapguide/index.php
===================================================================
--- sandbox/cms_refactor/templates/mapguide/index.php	                        (rev 0)
+++ sandbox/cms_refactor/templates/mapguide/index.php	2018-07-26 13:51:45 UTC (rev 3035)
@@ -0,0 +1,73 @@
+<?php
+
+require_once("../../layers/MapGuide/php/Common.php");
+require_once('../../common/php/Utilities.php');
+
+if (InitializationErrorOccurred())
+{
+    DisplayInitializationErrorHTML();
+    exit;
+}
+
+$locale = GetDefaultLocale();
+$params = $_GET;
+
+if (!array_key_exists("template", $params)) 
+{
+    echo "<p>Missing required parameter: template</p>";
+    exit;
+}
+if (!array_key_exists("ApplicationDefinition", $params)) 
+{
+    echo "<p>Missing required parameter: ApplicationDefinition</p>";
+    exit;
+}
+
+$bDebug = (array_key_exists("debug", $params) && $params["debug"] == "1");
+
+$templateName = strtolower($params["template"]);
+$appDef = $params["ApplicationDefinition"];
+$templatePath = dirname(__FILE__)."/$templateName/index.templ";
+
+if (!file_exists($templatePath)) {
+    echo "<p>Template ($templateName) not found</p>";
+    exit;
+}
+
+//Requests to this script can be made from anywhere, so disable XML entity loading to
+//guard against malicious XML
+libxml_disable_entity_loader(true);
+
+try {
+    $resourceService = $siteConnection->CreateService(MgServiceType::ResourceService);
+    $appDefId = new MgResourceIdentifier($appDef);
+    $content = $resourceService->GetResourceContent($appDefId);
+
+    $document = new DOMDocument();
+    $document->loadXML($content->ToString());
+
+    $root = $document->documentElement;
+    $json = '{"' . $root->tagName . '":' . xml2json($root) . '}';
+
+    $scriptName = "fusionSF-compressed";
+    if ($bDebug) {
+        $scriptName = "fusion";
+    }
+
+    $content = file_get_contents($templatePath);
+
+    $content = str_replace("%__LIB_BASE__%", "../../lib", $content);
+    $content = str_replace("%__TEMPLATE_BASE__%", "$templateName", $content);
+    $content = str_replace("%__FUSION_SCRIPT__%", $scriptName, $content);
+    $content = str_replace("%__SCRIPTS__%", "<!-- TODO: Inject Google Maps script if required -->", $content);
+    $content = str_replace("%__APPDEF_JSON__%", $json, $content);
+
+    header("Content-Type: text/html");
+    echo $content;
+} catch (MgException $ex) {
+    $initializationErrorMessage = $ex->GetExceptionMessage();
+    $initializationErrorDetail = $ex->GetDetails();
+    $initializationErrorStackTrace = $ex->GetStackTrace();
+    DisplayInitializationErrorHTML();
+}
+?>
\ No newline at end of file



More information about the fusion-commits mailing list