static void getIsSpecialHost(struct cartJson *cj, struct hash *paramHash) /* Tell whether we're on a development host, preview, gsid etc. */ { jsonWriteBoolean(cj->jw, "isPrivateHost", hIsPrivateHost()); jsonWriteBoolean(cj->jw, "isBetaHost", hIsBetaHost()); jsonWriteBoolean(cj->jw, "isBrowserbox", hIsBrowserbox()); jsonWriteBoolean(cj->jw, "isPreviewHost", hIsPreviewHost()); }
static void doMainPage() /* Send HTML with javascript to bootstrap the user interface. */ { // Start web page with new banner char *db = NULL, *genome = NULL, *clade = NULL; getDbGenomeClade(cart, &db, &genome, &clade, oldVars); // If CGI has &lastDbPos=..., handle that here and save position to cart so it's in place for // future cartJson calls. char *position = cartGetPosition(cart, db, NULL); cartSetString(cart, "position", position); webStartJWest(cart, db, "Genome Browser Gateway"); if (cgiIsOnWeb()) checkForGeoMirrorRedirect(cart); #define WARNING_BOX_START "<div id=\"previewWarningRow\" class=\"jwRow\">" \ "<div id=\"previewWarningBox\" class=\"jwWarningBox\">" #define UNDER_DEV "Data and tools on this site are under development, have not been reviewed " \ "for quality, and are subject to change at any time. " #define MAIN_SITE "The high-quality, reviewed public site of the UCSC Genome Browser is " \ "available for use at <a href=\"http://genome.ucsc.edu/\">http://genome.ucsc.edu/</a>." #define WARNING_BOX_END "</div></div>" if (hIsPreviewHost()) { puts(WARNING_BOX_START "WARNING: This is the UCSC Genome Browser preview site. " "This website is a weekly mirror of our internal development server for public access. " UNDER_DEV "We provide this site for early access, with the warning that it is less available " "and stable than our public site. " MAIN_SITE WARNING_BOX_END); } if (hIsPrivateHost() && !hHostHasPrefix("hgwdev-demo6")) { puts(WARNING_BOX_START "WARNING: This is the UCSC Genome Browser development site. " "This website is used for testing purposes only and is not intended for general public " "use. " UNDER_DEV MAIN_SITE WARNING_BOX_END); } // The visible page elements are all in ./hgGateway.html, which is transformed into a quoted .h // file containing a string constant that we #include and print here (see makefile). puts( #include "hgGateway.html.h" ); // Set global JS variables hgsid, activeGenomes, and survey* at page load time // We can't just use "var hgsid = " or the other scripts won't see it -- it has to be // "window.hgsid = ". puts("<script>"); printf("window.%s = '%s';\n", cartSessionVarName(), cartSessionId(cart)); puts("window.activeGenomes ="); printActiveGenomes(); puts(";"); char *surveyLink = cfgOption("survey"); if (isNotEmpty(surveyLink) && !sameWord(surveyLink, "off")) { printf("window.surveyLink=\"%s\";\n", jsonStringEscape(surveyLink)); char *surveyLabel = cfgOptionDefault("surveyLabel", "Please take our survey"); printf("window.surveyLabel=\"%s\";\n", jsonStringEscape(surveyLabel)); char *surveyLabelImage = cfgOption("surveyLabelImage"); if (isNotEmpty(surveyLabelImage)) printf("window.surveyLabelImage=\"%s\";\n", jsonStringEscape(surveyLabelImage)); else puts("window.surveyLabelImage=null;"); } else { puts("window.surveyLink=null;"); puts("window.surveyLabel=null;"); puts("window.surveyLabelImage=null;"); } puts("</script>"); puts("<script src=\"../js/es5-shim.4.0.3.min.js\"></script>"); puts("<script src=\"../js/es5-sham.4.0.3.min.js\"></script>"); puts("<script src=\"../js/lodash.3.10.0.compat.min.js\"></script>"); puts("<script src=\"../js/cart.js\"></script>"); webIncludeResourceFile("jquery-ui.css"); jsIncludeFile("jquery-ui.js", NULL); jsIncludeFile("jquery.watermarkinput.js", NULL); jsIncludeFile("utils.js",NULL); // Phylogenetic tree .js file, produced by dbDbTaxonomy.pl: char *dbDbTree = cfgOptionDefault("hgGateway.dbDbTaxonomy", "../js/dbDbTaxonomy.js"); if (isNotEmpty(dbDbTree)) printf("<script src=\"%s\"></script>\n", dbDbTree); // Main JS for hgGateway: puts("<script src=\"../js/hgGateway.js\"></script>"); webIncludeFile("inc/jWestFooter.html"); cartFlushHubWarnings(); webEndJWest(); }
char *webTimeStampedLinkToResource(char *fileName, boolean wrapInHtml) // If wrapInHtml // returns versioned link embedded in style or script html (free after use). // else // returns full path of a versioned path to the requested resource file (js, or css). // NOTE: png, jpg and gif should also be supported but are untested. // // In production sites we use a versioned softlink that includes the CGI version. This has the following benefits: // a) flushes user's web browser cache when the user visits a GB site whose version has changed since their last visit; // b) enforces the requirement that static files are the same version as the CGIs (something that often fails to happen in mirrors). // (see notes in redmine #3170). // // In dev trees we use mtime to create a pseudo-version; this forces web browsers to reload css/js file when it changes, // so we don't get odd behavior that can be caused by caching of mis-matched javascript and style files in dev trees. // // In either case, the actual file has to have been previously created by running make in the appropriate directory (kent/src/hg/js // or kent/src/hg/htdocs/style). { char baseName[PATH_LEN]; char extension[FILEEXT_LEN]; splitPath(fileName, NULL, baseName, extension); boolean js = sameString(".js",extension); boolean style = !js && sameString(".css",extension); boolean image = !js && !style && ( sameString(".png",extension) || sameString(".jpg",extension) || sameString(".gif",extension)); if (!js && !style) // && !image) NOTE: This code has not been tested on images but should work. errAbort("webTimeStampedLinkToResource: unknown resource type for %s.\n", fileName); // Build and verify directory char *dirName = ""; if (js) dirName = cfgOptionDefault("browser.javaScriptDir", "js"); else if (style) dirName = cfgOptionDefault("browser.styleDir","style"); else if (image) dirName = cfgOptionDefault("browser.styleImagesDir","style/images"); struct dyString *fullDirName = NULL; char *docRoot = hDocumentRoot(); if (docRoot != NULL) fullDirName = dyStringCreate("%s/%s", docRoot, dirName); else // tolerate missing docRoot (i.e. when running from command line) fullDirName = dyStringCreate("%s", dirName); if (!fileExists(dyStringContents(fullDirName))) errAbort("webTimeStampedLinkToResource: dir: %s doesn't exist.\n", dyStringContents(fullDirName)); // build and verify real path to file struct dyString *realFileName = dyStringCreate("%s/%s", dyStringContents(fullDirName), fileName); if (!fileExists(dyStringContents(realFileName))) errAbort("webTimeStampedLinkToResource: file: %s doesn't exist.\n", dyStringContents(realFileName)); // build and verify link path including timestamp in the form of dir/baseName + timeStamp or CGI Version + ext long mtime = fileModTime(dyStringContents(realFileName)); struct dyString *linkWithTimestamp; char *scriptName = cgiScriptName(); if (scriptName == NULL) scriptName = cloneString(""); boolean nonVersionedLinks = FALSE; if (endsWith(scriptName, "qaPushQ")) nonVersionedLinks = TRUE; if (nonVersionedLinks) linkWithTimestamp = dyStringCreate("%s/%s%s", dyStringContents(fullDirName), baseName, extension); else if ((cfgOption("versionStamped") == NULL) && (hIsPreviewHost() || hIsPrivateHost())) linkWithTimestamp = dyStringCreate("%s/%s-%ld%s", dyStringContents(fullDirName), baseName, mtime, extension); else linkWithTimestamp = dyStringCreate("%s/%s-v%s%s", dyStringContents(fullDirName), baseName, CGI_VERSION, extension); if (!fileExists(dyStringContents(linkWithTimestamp))) errAbort("Cannot find correct version of file '%s'; this is due to an installation error\n\nError details: %s does not exist", fileName, dyStringContents(linkWithTimestamp)); // Free up all that extra memory dyStringFree(&realFileName); dyStringFree(&fullDirName); char *linkFull = dyStringCannibalize(&linkWithTimestamp); char *link = linkFull; if (docRoot != NULL) { link = cloneString(linkFull + strlen(docRoot) + 1); freeMem(linkFull); } if (wrapInHtml) // wrapped for christmas { struct dyString *wrapped = dyStringNew(0); if (js) dyStringPrintf(wrapped,"<script type='text/javascript' SRC='/%s'></script>\n", link); else if (style) dyStringPrintf(wrapped,"<LINK rel='STYLESHEET' href='/%s' TYPE='text/css' />\n", link); else // Will be image, since these are the only three choices allowed dyStringPrintf(wrapped,"<IMG src='/%s' />\n", link); freeMem(link); link = dyStringCannibalize(&wrapped); } return link; }