[Mapbender-commits] r8836 - in trunk/mapbender/http: classes javascripts php
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Mon May 12 01:36:17 PDT 2014
Author: armin11
Date: 2014-05-12 01:36:17 -0700 (Mon, 12 May 2014)
New Revision: 8836
Modified:
trunk/mapbender/http/classes/class_metadata_new.php
trunk/mapbender/http/javascripts/initWmcObj.php
trunk/mapbender/http/php/mod_callMetadata.php
trunk/mapbender/http/php/mod_savewmc_server.php
Log:
Bugfix for CORS proxy and possibility to store temporal wmc at other storage e.g. memcached server.
Modified: trunk/mapbender/http/classes/class_metadata_new.php
===================================================================
--- trunk/mapbender/http/classes/class_metadata_new.php 2014-05-12 07:41:02 UTC (rev 8835)
+++ trunk/mapbender/http/classes/class_metadata_new.php 2014-05-12 08:36:17 UTC (rev 8836)
@@ -58,9 +58,10 @@
var $orderBy;
var $hostName;
var $resourceIds;
- var $restrictToOpenData;
+ var $restrictToOpenData;
+ var $originFromHeader;
- function __construct($userId, $searchId, $searchText, $registratingDepartments, $isoCategories, $inspireThemes, $timeBegin, $timeEnd, $regTimeBegin, $regTimeEnd, $maxResults, $searchBbox, $searchTypeBbox, $accessRestrictions, $languageCode, $searchEPSG, $searchResources, $searchPages, $outputFormat, $resultTarget, $searchURL, $customCategories, $hostName, $orderBy, $resourceIds, $restrictToOpenData){
+ function __construct($userId, $searchId, $searchText, $registratingDepartments, $isoCategories, $inspireThemes, $timeBegin, $timeEnd, $regTimeBegin, $regTimeEnd, $maxResults, $searchBbox, $searchTypeBbox, $accessRestrictions, $languageCode, $searchEPSG, $searchResources, $searchPages, $outputFormat, $resultTarget, $searchURL, $customCategories, $hostName, $orderBy, $resourceIds, $restrictToOpenData, $originFromHeader){
$this->userId = (integer)$userId;
$this->searchId = $searchId;
$this->searchText = $searchText;
@@ -92,6 +93,7 @@
} else {
$this->restrictToOpenData = false;
}
+ $this->originFromHeader = $originFromHeader;
//definitions for generating tagClouds
$this->maxObjects = 15;
$this->maxFontSize = 30;
@@ -828,9 +830,13 @@
$this->allJSON->filter = $filterJSON;
}
$this->allJSON->wms = $this->json->decode($this->wmsJSON);
- if (defined("CORS_WHITELIST") && CORS_WHITELIST != "") {
- header('Access-Control-Allow-Origin: '.CORS_WHITELIST);
+ //$e = new mb_exception("originFromHeader: ".$this->originFromHeader);
+ if ($this->originFromHeader != false) {
+ header('Access-Control-Allow-Origin: '.$this->originFromHeader);
}
+ //if (defined("CORS_WHITELIST") && CORS_WHITELIST != "") {
+ // header('Access-Control-Allow-Origin: '.CORS_WHITELIST);
+ //}
echo $this->json->encode($this->allJSON);
//echo "test";
}
Modified: trunk/mapbender/http/javascripts/initWmcObj.php
===================================================================
--- trunk/mapbender/http/javascripts/initWmcObj.php 2014-05-12 07:41:02 UTC (rev 8835)
+++ trunk/mapbender/http/javascripts/initWmcObj.php 2014-05-12 08:36:17 UTC (rev 8836)
@@ -34,6 +34,45 @@
}
}
+function getWmcFromStorage($filename) {
+ switch (TMP_WMC_SAVE_STORAGE) {
+ case "memcache":
+ $memcache_obj = new Memcache;
+ if (defined("MEMCACHED_IP") && MEMCACHED_IP != "" && defined("MEMCACHED_PORT") && MEMCACHED_PORT != "") {
+ $memcache_obj->connect(MEMCACHED_IP, MEMCACHED_PORT);
+ } else {
+ //use standard options
+ $memcache_obj->connect('localhost', 11211);
+ }
+ new mb_notice("wmc sessions stored via memcache");
+ $wmc = $memcache_obj->get($filename);
+ $memcache_obj->close();
+ return $wmc;
+ break;
+ case "memcached":
+ $memcached_obj = new Memcached;
+ if (defined("MEMCACHED_IP") && MEMCACHED_IP != "" && defined("MEMCACHED_PORT") && MEMCACHED_PORT != "") {
+ $memcached_obj->addServer(MEMCACHED_IP, MEMCACHED_PORT);
+ } else {
+ //use standard options
+ $memcached_obj->addServer('localhost', 11211);
+ }
+ new mb_notice("wmc stored via memcacheD");
+ $wmc = $memcached_obj->get($filename);
+ //$memcached_obj->quit();
+ return $wmc;
+ break;
+ case "file":
+ $wmc = file_get_contents($filename);
+ return $wmc;
+ break;
+ default:
+ $wmc = file_get_contents($filename);
+ return $wmc;
+ break;
+ }
+}
+
$admin = new administration();
$resultObj = array(
"noPermission" => array(
@@ -69,7 +108,12 @@
//check if wmc filename is in session - TODO only if should be loaded from session not else! (Module loadWMC)
if(Mapbender::session()->get("mb_wmc")) {
$wmc_filename = Mapbender::session()->get("mb_wmc");
- $wmcDocSession = file_get_contents($wmc_filename);
+ $time_start = microtime();
+ //load it from whereever it has been stored
+ $wmcDocSession = getWmcFromStorage($wmc_filename);
+ $time_end = microtime();
+ $timediff = $time_end - $time_start;
+ $e = new mb_exception('initWmcObj.php: time to load wmc from storage: '.$timediff. '('.TMP_WMC_SAVE_STORAGE.')');
}
try {
$loadFromSession = new ElementVar($app, "loadwmc", "loadFromSession");
Modified: trunk/mapbender/http/php/mod_callMetadata.php
===================================================================
--- trunk/mapbender/http/php/mod_callMetadata.php 2014-05-12 07:41:02 UTC (rev 8835)
+++ trunk/mapbender/http/php/mod_callMetadata.php 2014-05-12 08:36:17 UTC (rev 8836)
@@ -52,7 +52,14 @@
$tempFolder = TMPDIR;
$orderBy = "rank"; //rank or title or id or date
$hostName = $_SERVER['HTTP_HOST'];
-
+$headers = apache_request_headers();
+$originFromHeader = false;
+foreach ($headers as $header => $value) {
+ if ($header === "Origin") {
+ //$e = new mb_exception("Origin: ".$value);
+ $originFromHeader = $value;
+ }
+}
//read the whole query string:
$searchURL = $_SERVER['QUERY_STRING'];
//decode it !
@@ -1004,7 +1011,8 @@
}
if ($resultTarget == 'web' or $resultTarget == 'debug' or $resultTarget == 'webclient') {
if (count($searchResources) == 1) {
- $metadata = new searchMetadata($userId, $searchId, $searchText, $registratingDepartments, $isoCategories, $inspireThemes, $timeBegin, $timeEnd, $regTimeBegin, $regTimeEnd, $maxResults, $searchBbox, $searchTypeBbox, $accessRestrictions, $languageCode, $searchEPSG, $searchResources[0], $searchPages[0], $outputFormat, $resultTarget, $searchURL, $customCategories, $hostName, $orderBy, $resourceIds, $restrictToOpenData);
+ //$e = new mb_exception("originFromHeader: ".$originFromHeader);
+ $metadata = new searchMetadata($userId, $searchId, $searchText, $registratingDepartments, $isoCategories, $inspireThemes, $timeBegin, $timeEnd, $regTimeBegin, $regTimeEnd, $maxResults, $searchBbox, $searchTypeBbox, $accessRestrictions, $languageCode, $searchEPSG, $searchResources[0], $searchPages[0], $outputFormat, $resultTarget, $searchURL, $customCategories, $hostName, $orderBy, $resourceIds, $restrictToOpenData, $originFromHeader);
#if ($outputFormat == 'xml') {
# header("Content-type: application/xhtml+xml; charset=UTF-8");
#}
Modified: trunk/mapbender/http/php/mod_savewmc_server.php
===================================================================
--- trunk/mapbender/http/php/mod_savewmc_server.php 2014-05-12 07:41:02 UTC (rev 8835)
+++ trunk/mapbender/http/php/mod_savewmc_server.php 2014-05-12 08:36:17 UTC (rev 8836)
@@ -13,6 +13,47 @@
require_once(dirname(__FILE__)."/../classes/class_json.php");
require_once(dirname(__FILE__)."/../classes/class_lzw_decompress.php");
+function putWmcToStorage($filename, $xml) {
+ switch (TMP_WMC_SAVE_STORAGE) {
+ case "memcache":
+ $memcache_obj = new Memcache;
+ if (defined("MEMCACHED_IP") && MEMCACHED_IP != "" && defined("MEMCACHED_PORT") && MEMCACHED_PORT != "") {
+ $memcache_obj->connect(MEMCACHED_IP, MEMCACHED_PORT);
+ } else {
+ //use standard options
+ $memcache_obj->connect('localhost', 11211);
+ }
+ new mb_notice("wmc sessions stored via memcache");
+ $memcache_obj->set($filename, $xml, 0, TMP_WMC_MAX_AGE);
+ $memcache_obj->close();
+ return true;
+ break;
+ case "memcached":
+ $memcached_obj = new Memcached;
+ if (defined("MEMCACHED_IP") && MEMCACHED_IP != "" && defined("MEMCACHED_PORT") && MEMCACHED_PORT != "") {
+ $memcached_obj->addServer(MEMCACHED_IP, MEMCACHED_PORT);
+ } else {
+ //use standard options
+ $memcached_obj->addServer('localhost', 11211);
+ }
+ new mb_notice("wmc stored via memcacheD");
+ return $memcached_obj->set($filename, $xml, TMP_WMC_MAX_AGE);
+ //$memcached_obj->quit();
+ return true;
+ break;
+ case "file":
+ file_put_contents($filename, $xml);
+ break;
+ default:
+ file_put_contents($filename, $xml);
+ break;
+ }
+}
+
+
+
+
+
$ajaxResponse = new AjaxResponse($_POST);
if($ajaxResponse->getMethod() != "saveWMC") {
$ajaxResponse->setSuccess(false);
@@ -61,30 +102,25 @@
}
if ($saveInSession === 1) {
- // CLEAN SESSION WMC FILES
- //do this by cronjob!
- //$tmp = scandir(TMPDIR);
- // get all files from tmp folder
- /*for($p = 0; $p < count($tmp); $p++) {
- // match timestamp on begin of the filename
- if(preg_match("/^([\d]+).*$/i", $tmp[$p],$timestamp)) {
- // if file older than 24h, remove it.
- if((time() - $timestamp[1]) >= 86400) { // 86400 = 24h
- unlink(TMPDIR."/wmc/".$tmp[$p]);
- }
- }
- }*/
- // store XML in tmp folder
+ //CLEAN SESSION WMC FILES
+ //do this by cronjob or handled by memcached itself!
+ //store XML location, that is defined in mapbender.conf (memcached server, session or file)
+ //look for existing referenced wmc in session
if(Mapbender::session()->get("mb_wmc")) {
$filename = Mapbender::session()->get("mb_wmc");
} else {
$filename = TMPDIR."/wmc/".time()."_".uniqid();//will be set to new one cause ?
}
- file_put_contents($filename, $wmc->xml);
+ //
+ $time_start = microtime();
+ putWmcToStorage($filename, $wmc->xml);
+ $time_end = microtime();
+ $timediff = $time_end - $time_start;
+ $e = new mb_exception('mod_savewmc_server.php: time to save wmc to storage: '.$timediff. '('.TMP_WMC_SAVE_STORAGE.')');
+
+ //file_put_contents($filename, $wmc->xml);
+ //put filename into session
Mapbender::session()->set("mb_wmc",$filename);
- // store XML in session
- //Mapbender::session()->set("mb_wmc",$wmc->xml);
- //$epsgTest=$wmc->mainMap->extent->toJavaScript();
$epsgString = $wmc->mainMap->extentToJavascript();
// get epsg code from jquery string
preg_match('/EPSG:\d{4,5}/',$epsgString, $matches);
@@ -96,14 +132,12 @@
Mapbender::session()->set("epsg",$epsg);
}
Mapbender::session()->set("previous_gui", Mapbender::session()->get("mb_user_gui"));
-
- $e = new mb_notice("mod_insertWMCIntoDB: save WMC in session succeeded.");
+ $e = new mb_notice("mod_savewmc_server: save WMC into storage succeeded.");
$ajaxResponse->setSuccess(true);
- $ajaxResponse->setResult(_mb("saved wmc document to session"));
+ $ajaxResponse->setResult(_mb("saved wmc document to temporal storage"));
}
else {
// insert WMC into database
-
if(isset($attributes->title)) {
$attributes->title = trim($attributes->title);
if($attributes->title == "") {
More information about the Mapbender_commits
mailing list