2bcf5f8cf0cab0650f31b77873d8785f08709fcc larrym Wed Jun 6 15:40:20 2012 -0700 start of new menu code diff --git src/hg/lib/web.c src/hg/lib/web.c index 4622e13..b01d11c 100644 --- src/hg/lib/web.c +++ src/hg/lib/web.c @@ -15,30 +15,31 @@ #include "hgColors.h" #include "hubConnect.h" #include "search.h" #ifndef GBROWSE #include "axtInfo.h" #include "wikiLink.h" #include "googleAnalytics.h" #include "jsHelper.h" #endif /* GBROWSE */ #include "errabort.h" // FIXME tmp hack to try to find source of popWarnHandler underflows in browse /* phoneHome business */ #include #include #include #include "geoMirror.h" +#include /* phoneHome business */ /* flag that tell if the CGI header has already been outputed */ boolean webHeadAlreadyOutputed = FALSE; /* flag that tell if text CGI header hsa been outputed */ boolean webInTextMode = FALSE; static char *dbCgiName = "db"; static char *orgCgiName = "org"; static char *cladeCgiName = "clade"; static char *extraStyle = NULL; /* global: a cart for use in error handlers. */ static struct cart *errCart = NULL; @@ -83,47 +84,39 @@ /* set a style to add to the header */ { extraStyle = style; } void webStartText() /* output the head for a text page */ { /*printf("Content-Type: text/plain\n\n");*/ webHeadAlreadyOutputed = TRUE; webInTextMode = TRUE; webPushErrHandlers(); } -// NEW_MENUS is used to experiment with using jabico derived menus (see redmine #5245) -// curently only used in larrym's tree -// #define NEW_MENUS - static void webStartWrapperDetailedInternal(struct cart *theCart, char *db, char *headerText, char *textOutBuf, boolean withHttpHeader, boolean withLogo, boolean skipSectionHeader, boolean withHtmlHeader) /* output a CGI and HTML header with the given title in printf format */ { char uiState[256]; char *scriptName = cgiScriptName(); boolean isEncode = FALSE; -#ifndef NEW_MENUS -boolean isGsid = hIsGsidServer(); -boolean isGisaid = hIsGisaidServer(); -#endif if (theCart) { char *theGenome = NULL; char *genomeEnc = NULL; getDbAndGenome(theCart, &db, &theGenome, NULL); genomeEnc = cgiEncode(theGenome); safef(uiState, sizeof(uiState), "?%s=%s&%s=%s&%s=%u", orgCgiName, genomeEnc, dbCgiName, db, cartSessionVarName(), cartSessionId(theCart)); } else { @@ -216,188 +209,36 @@ puts("" "\"ENCODE" ""); puts("\"ENCODE"); } else { puts(""); } puts("" "\n" "" "\n" ); } /* Put up the hot links bar. */ -#ifdef NEW_MENUS - - char *docRoot = hDocumentRoot(); - jsIncludeFile("jquery.js", NULL); - if(docRoot != NULL) - { - struct dyString *file = dyStringCreate("%s/%s", docRoot, "NavBar.html"); - FILE *fd = fopen(dyStringContents(file), "r"); - if(fd == NULL) - // fail some other way (e.g. HTTP 500)? - errAbort("Couldn't open header file '%s' for reading", dyStringContents(file)); - else - { - char buf[4096]; - while(TRUE) - { - size_t n = fread(buf, 1, sizeof(buf), fd); - if(n) - fwrite(buf, 1, n, stdout); - else - break; - } - fclose(fd); - printf("\n"); - } - } - else - { - // tolerate missing docRoot (i.e. when running from command line) - // XXXX ???? - } - -#else - -if (isGisaid) - { - printf("\n"); - printf("\n"); // Home - if (haveBlat) - printf("\n"); // Blat - printf("\n"); // Subject View - printf("\n",uiState); // Sequence View - printf("\n"); // Table View - printf("
HomeBlatSample ViewSequence ViewTable View 
\n"); // last column squeezes other columns left - } -else if (isGsid) - { - printf("\n"); - printf("\n"); // Home - if (haveBlat) - printf("\n"); // Blat - printf("\n"); // Subject View - printf("\n",uiState); // Sequence View - printf("\n"); // Table View - if (endsWith(scriptName, "hgBlat")) - printf("\n"); // Help - else - printf("\n"); // Help - printf("
HomeBlatSubject ViewSequence ViewTable ViewHelpHelp 
\n"); // last column squeezes other columns left - } -else if (dbIsFound) - { - puts("\n"); - puts(""); - - if (isEncode) - printf("\n"); - else - { - printf("\n", uiState); - if (isGsid) - printf("\n",uiState); - else - printf("\n",uiState); - - if (endsWith(scriptName, "hgTracks") || endsWith(scriptName, "hgGene") || - endsWith(scriptName, "hgTables") || endsWith(scriptName, "hgTrackUi") || - endsWith(scriptName, "hgSession") || endsWith(scriptName, "hgCustom") || - endsWith(scriptName, "hgHubConnect") || - endsWith(scriptName, "hgc") || endsWith(scriptName, "hgPal")) - printf("\n",uiState,TRACK_SEARCH); - - if (haveBlat && !endsWith(scriptName, "hgBlat")) - printf("\n",theCart ? "&" : "", uiState+1 ); - } - - if (!isGsid && !hIsCgbServer()) // disable TB for both GSID and CGB servers - { - char *table = (theCart == NULL ? NULL : - (endsWith(scriptName, "hgGene") ? - cartOptionalString(theCart, "hgg_type") : - cartOptionalString(theCart, "g"))); - if (table && theCart && - (endsWith(scriptName, "hgc") || endsWith(scriptName, "hgTrackUi") || - endsWith(scriptName, "hgGene"))) - { - struct trackDb *tdb = hTrackDbForTrack(db, table); - if (tdb != NULL) - printf("\n"); - } - - if (!endsWith(scriptName, "hgNear") && db != NULL && hgNearOk(db)) // possible to make this conditional: if (db != NULL && hgNearOk(db)) +char *menuStr = menuBar(theCart); +if(menuStr) { - if (isGsid) - printf("\n",uiState); - else - printf("\n",uiState); - } - if ((!endsWith(scriptName, "hgPcr")) && (db == NULL || hgPcrOk(db))) - printf("\n",uiState); - if (endsWith(scriptName, "hgGenome")) - printf("\n",uiState); - if (endsWith(scriptName, "hgHeatmap")) - printf("\n",uiState); -#ifndef GBROWSE - if (wikiLinkEnabled() && !endsWith(scriptName, "hgSession")) - printf("\n",uiState, theCart ? "&" : "?" ); -#endif /* GBROWSE */ - if (!isGsid) - printf(""); - if (!isGsid) - { - if (endsWith(scriptName, "hgBlat")) - printf("\n"); - } + jsIncludeFile("jquery.js", NULL); + puts(menuStr); } - printf("
HomeHomeSubject ViewGenomesGenome BrowserBlat", - uiState, tdb->grp, tdb->track, tdb->table); - else - printf("", uiState); - trackDbFree(&tdb); - } - else - printf("", - uiState, theCart ? "&" : "?" ); - printf("TablesTable ViewGene SorterPCRPDF/PSPDF/PSSessionFAQHelp 
\n"); // last column squeezes other columns left - puts("\n"); - -#endif if (endsWith(scriptName, "hgGateway") && geoMirrorEnabled()) { // Show an opt-out alert if user is on a host to which user has been automatically redirected (just once, right after they have been redirected) char *source = cgiOptionalString("source"); char *redirect = cgiOptionalString("redirect"); if (source != NULL && redirect != NULL && sameString(redirect, "auto")) { char *domain = cgiServerName(); char *port = cgiServerPort(); // We don't bother maintaining stuff in request URI, because it may contain items like hgsid and other host specific values int newUriSize = 2048; char *newUri = needMem(newUriSize); // TODO what about https? safef(newUri, newUriSize, "http://%s:%s/cgi-bin/hgGateway?redirect=manual&source=%s", source, port, domain); @@ -516,30 +357,31 @@ webStartWrapper(theCart, db, format, args, TRUE, TRUE); va_end(args); } void webStartHeader(struct cart *theCart, char *db, char *headerText, char *format, ...) /* Print out pretty wrapper around things when not from cart. * Include headerText in the html header. */ { va_list args; va_start(args, format); webStartWrapperGatewayHeader(theCart, db, headerText, format, args, TRUE, TRUE, FALSE); va_end(args); } + static void webEndSection() /* Close down a section */ { puts( "" "\n" " " "\n" // "
" " " "\n" " " "\n" " " ); puts(""); } void webNewSection(char* format, ...) /* create a new section on the web page */ @@ -1440,15 +1282,67 @@ // The reference will be to a link with timestamp. { char *link = webTimeStampedLinkToResourceOnFirstCall(fileName,TRUE); if (link) { if (toFile == NULL) hPrintf("%s",link); else fprintf(toFile,"%s",link); freeMem(link); return TRUE; } return FALSE; } +char *menuBar(struct cart *cart) +// Return HTML for the menu bar (read from a configuration file); +// we fixup internal CGI's to add hgsid's and include the appropriate js and css files. +{ +char *docRoot = hDocumentRoot(); +char *menuStr, buf[4096], uiVars[128]; +FILE *fd; +int len, offset, err; +char *navBarFile = "inc/globalNavBar.inc"; +struct stat statBuf; +regex_t re; +regmatch_t match[2]; +safef(uiVars, sizeof(uiVars), "%s=%u", cartSessionVarName(), cartSessionId(cart)); + +if(docRoot == NULL) + // tolerate missing docRoot (i.e. don't bother with menu when running from command line) + return NULL; + +jsIncludeFile("jquery.js", NULL); +jsIncludeFile("jquery.plugins.js", NULL); +webIncludeResourceFile("nice_menu.css"); + +// Read in menu bar html +safef(buf, sizeof(buf), "%s/%s", docRoot, navBarFile); +fd = mustOpen(buf, "r"); +fstat(fileno(fd), &statBuf); +len = statBuf.st_size; +menuStr = needMem(len + 1); +mustRead(fd, menuStr, statBuf.st_size); +menuStr[len] = 0; +carefulClose(&fd); + +// fixup internal CGIs to have hgsid +safef(buf, sizeof(buf), "/cgi-bin/hg[A-Za-z]+(%c%c?)", '\\', '?'); +err = regcomp(&re, buf, REG_EXTENDED); +if(err) + errAbort("regcomp failed; err: %d", err); +struct dyString *dy = newDyString(0); +for(offset = 0; offset < len && !regexec(&re, menuStr + offset, ArraySize(match), match, 0); offset += match[0].rm_eo) + { + dyStringAppendN(dy, menuStr + offset, match[0].rm_eo); + if(match[1].rm_so == match[1].rm_eo) + dyStringAppend(dy, "?"); + dyStringAppend(dy, uiVars); + if(match[1].rm_so != match[1].rm_eo) + dyStringAppend(dy, "&"); + } +if(offset < len) + dyStringAppend(dy, menuStr + offset); + +return dyStringCannibalize(&dy); +}