[mapserver-commits] r10902 - trunk/mapserver

svn at osgeo.org svn at osgeo.org
Mon Jan 24 11:41:49 EST 2011


Author: sdlime
Date: 2011-01-24 08:41:49 -0800 (Mon, 24 Jan 2011)
New Revision: 10902

Modified:
   trunk/mapserver/maptemplate.c
   trunk/mapserver/maptemplate.h
Log:
Applied chodgson's [date ...] tag patch.

Modified: trunk/mapserver/maptemplate.c
===================================================================
--- trunk/mapserver/maptemplate.c	2011-01-24 16:15:47 UTC (rev 10901)
+++ trunk/mapserver/maptemplate.c	2011-01-24 16:41:49 UTC (rev 10902)
@@ -1832,7 +1832,92 @@
     return(MS_SUCCESS);
 }
 
+
 /*
+** Function to process a [date ...] tag
+*/
+
+static int processDateTag(char **line)
+{
+  struct tm *datetime;
+  time_t t;
+  int result;
+  char *tag, *tagStart, *tagEnd;
+  hashTableObj *tagArgs=NULL;
+  int tagOffset, tagLength;
+#define DATE_BUFLEN 1024
+  char datestr[DATE_BUFLEN]; 
+  char *argValue=NULL;
+  char *format, *tz; // tag parameters 
+
+  if(!*line) {
+    msSetError(MS_WEBERR, "Invalid line pointer.", "processDateTag()");
+    return(MS_FAILURE);
+  }
+
+  tagStart = findTag(*line, "date");
+
+  /* It is OK to have no date tags, just return. */
+  if( !tagStart )
+    return MS_SUCCESS;
+
+  while (tagStart) {
+    // set tag params to defaults
+    format = DEFAULT_DATE_FORMAT;
+    tz = "";
+    
+    tagOffset = tagStart - *line;
+
+    /* check for any tag arguments */
+    if(getTagArgs("date", tagStart, &tagArgs) != MS_SUCCESS) return(MS_FAILURE);
+
+    if(tagArgs) {
+      argValue = msLookupHashTable(tagArgs, "format");
+      if(argValue) format = argValue;
+      argValue = msLookupHashTable(tagArgs, "tz");
+      if(argValue) tz = argValue;
+    }
+
+    t = time(NULL);
+    if( strncasecmp( tz, "gmt", 4 ) == 0 )
+    {
+      datetime = gmtime(&t);
+    } else {
+      datetime = localtime(&t);
+    }
+    result = strftime(datestr, DATE_BUFLEN, format, datetime); 
+  
+    /* Only do the replacement if the date was successfully written */ 
+    if( result > 0 ) 
+    { 
+      /* find the end of the tag */
+      tagEnd = findTagEnd(tagStart);
+      tagEnd++;
+
+      /* build the complete tag so we can do substitution */
+      tagLength = tagEnd - tagStart;
+      tag = (char *) msSmallMalloc(tagLength + 1);
+      strlcpy(tag, tagStart, tagLength+1);
+
+      /* do the replacement */
+      *line = msReplaceSubstring(*line, tag, datestr);
+    }
+
+    /* clean up */
+    free(tag); tag = NULL;
+    msFreeHashTable(tagArgs); tagArgs=NULL;
+
+    if((*line)[tagOffset] != '\0')
+      tagStart = findTag(*line+tagOffset+1, "shpxy");
+    else
+      tagStart = NULL;  
+  }
+  
+  return(MS_SUCCESS);
+  
+}
+
+/*
 ** Function to process a [shpxy ...] tag: line contains the tag, shape holds the coordinates. 
 **
 ** TODO's: 
@@ -3683,6 +3768,9 @@
   snprintf(repstr, sizeof(repstr), "%f", mapserv->map->extent.maxy);
   outstr = msReplaceSubstring(outstr, "[maxy]", repstr);
 
+  if(processDateTag( &outstr ) != MS_SUCCESS)
+    return(NULL);
+
   if(processExtentTag(mapserv, &outstr, "mapext", &(mapserv->map->extent), &(mapserv->map->projection)) != MS_SUCCESS)
     return(NULL);
   if(processExtentTag(mapserv, &outstr, "mapext_esc", &(mapserv->map->extent), &(mapserv->map->projection)) != MS_SUCCESS) /* depricated */

Modified: trunk/mapserver/maptemplate.h
===================================================================
--- trunk/mapserver/maptemplate.h	2011-01-24 16:15:47 UTC (rev 10901)
+++ trunk/mapserver/maptemplate.h	2011-01-24 16:41:49 UTC (rev 10902)
@@ -38,6 +38,7 @@
 #define TEMPLATE_TYPE(s)  (((strncmp("http://", s, 7) == 0) || (strncmp("https://", s, 8) == 0) || (strncmp("ftp://", s, 6)) == 0)  ? MS_URL : MS_FILE)
 #define MAXZOOM 25
 #define MINZOOM -25
+#define DEFAULT_DATE_FORMAT "%d/%b/%Y:%H:%M:%S %z"
 
 enum coordSources {NONE, FROMIMGPNT, FROMIMGBOX, FROMIMGSHAPE, FROMREFPNT, FROMUSERPNT, FROMUSERBOX, FROMUSERSHAPE, FROMBUF, FROMSCALE, FROMTILE};
 



More information about the mapserver-commits mailing list