char *linkGetUrl(struct link *link, struct sqlConnection *conn, char *geneId) /* Return URL string if possible or NULL if not. FreeMem this when done. */ { char query[512]; struct sqlResult *sr; char **row; char *url = NULL; /* Some special case code here for things that need to * do more than check a table. */ if (sameString(link->name, "family")) { if (!hgNearOk(database)) return NULL; } if (sameString(link->name, "protBrowser")) { if (!hgPbOk(database)) return NULL; /* special processing for PB, since we need the protein ID, instead everything key off from gene ID */ /* use UniProt accession instead of displayID, because display ID sometimes changes */ if (swissProtAcc == NULL || swissProtAcc[0] == 0) return NULL; if (isRgdGene(conn)) { safef(query, sizeof(query), "../cgi-bin/pbGlobal?proteinID=%s", swissProtAcc); } else { safef(query, sizeof(query), "../cgi-bin/pbTracks?db=%s&proteinID=%s", database, swissProtAcc); } return(cloneString(query)); } if (sameString(link->name, "tbSchema")) { char *geneTable = genomeSetting("knownGene"); struct trackDb *tdb = hTrackDbForTrack(sqlGetDatabase(conn), geneTable); struct dyString *dy = NULL; if (tdb == NULL) return NULL; dy = newDyString(256); dyStringPrintf(dy, link->url, tdb->grp, geneTable, geneTable); trackDbFree(&tdb); addLinkExtras(link, dy); return dyStringCannibalize(&dy); } geneId = cloneAndCut(geneId, link->preCutAt); safef(query, sizeof(query), link->idSql, geneId); sr = sqlGetResult(conn, query); row = sqlNextRow(sr); if (row != NULL && row[0][0] != 0) /* If not null or empty */ { struct dyString *dy = newDyString(0); char *name = cloneAndCut(row[0], link->postCutAt); dyStringPrintf(dy, link->url, name, row[1], row[2], row[3]); addLinkExtras(link, dy); url = dyStringCannibalize(&dy); freez(&name); } sqlFreeResult(&sr); freeMem(geneId); return url; }
char *menuBar(struct cart *cart, char *db) // 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. // // Note this function is also called by hgTracks which extends the menu bar // with a View menu defined in hgTracks/menu.c { char *docRoot = hDocumentRoot(); char *menuStr, buf[4096], uiVars[128]; FILE *fd; char *navBarFile = "inc/globalNavBar.inc"; struct stat statBuf; char *scriptName = cgiScriptName(); if (cart) safef(uiVars, sizeof(uiVars), "%s=%s", cartSessionVarName(), cartSessionId(cart)); else uiVars[0] = 0; 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); int len = statBuf.st_size; menuStr = needMem(len + 1); mustRead(fd, menuStr, statBuf.st_size); menuStr[len] = 0; carefulClose(&fd); if (cart) { char *newMenuStr = menuBarAddUiVars(menuStr, "/cgi-bin/hg", uiVars); freez(&menuStr); menuStr = newMenuStr; } if(scriptName) { // Provide hgTables options for some CGIs. char hgTablesOptions[1024] = ""; char *track = (cart == NULL ? NULL : (endsWith(scriptName, "hgGene") ? cartOptionalString(cart, "hgg_type") : cartOptionalString(cart, "g"))); if (track && cart && db && (endsWith(scriptName, "hgc") || endsWith(scriptName, "hgTrackUi") || endsWith(scriptName, "hgGene"))) { struct trackDb *tdb = hTrackDbForTrack(db, track); if (tdb) { struct trackDb *topLevel = trackDbTopLevelSelfOrParent(tdb); safef(hgTablesOptions, sizeof hgTablesOptions, "../cgi-bin/hgTables?hgta_doMainPage=1&hgta_group=%s&hgta_track=%s&hgta_table=%s&", topLevel->grp, topLevel->track, tdb->table); menuStr = replaceChars(menuStr, "../cgi-bin/hgTables?", hgTablesOptions); trackDbFree(&tdb); } } } if(!loginSystemEnabled()) stripRegEx(menuStr, "<\\!-- LOGIN_START -->.*<\\!-- LOGIN_END -->", REG_ICASE); if(scriptName) { // Provide optional official mirror servers menu items char *geoMenu = geoMirrorMenu(); char *pattern = "<!-- OPTIONAL_MIRROR_MENU -->"; char *newMenuStr = replaceChars(menuStr, pattern, geoMenu); freez(&menuStr); menuStr = newMenuStr; } if(scriptName) { // Provide view menu for some CGIs. struct dyString *viewItems = dyStringCreate(""); boolean hasViewMenu = TRUE; if (endsWith(scriptName, "hgGenome")) { safef(buf, sizeof(buf), "../cgi-bin/hgGenome?%s&hgGenome_doPsOutput=1", uiVars); dyStringPrintf(viewItems, "<li><a href='%s' id='%s'>%s</a></li>\n", buf, "pdfLink", "PDF/PS"); } else { hasViewMenu = FALSE; } if (hasViewMenu) { struct dyString *viewMenu = dyStringCreate("<li class='menuparent' id='view'><span>View</span>\n<ul style='display: none; visibility: hidden;'>\n"); dyStringAppend(viewMenu, viewItems->string); dyStringAppend(viewMenu, "</ul>\n</li>\n"); menuStr = replaceChars(menuStr, "<!-- OPTIONAL_VIEW_MENU -->", viewMenu->string); dyStringFree(&viewMenu); } else if (!endsWith(scriptName, "hgTracks")) { replaceChars(menuStr, "<!-- OPTIONAL_VIEW_MENU -->", ""); } dyStringFree(&viewItems); } if(scriptName) { // Provide context sensitive help links for some CGIs. char *link = NULL; char *label = NULL; if (endsWith(scriptName, "hgBlat")) { link = "../goldenPath/help/hgTracksHelp.html#BLATAlign"; label = "Help on Blat"; } else if (endsWith(scriptName, "hgHubConnect")) { link = "../goldenPath/help/hgTrackHubHelp.html"; label = "Help on Track Hubs"; } else if (endsWith(scriptName, "hgNear")) { link = "../goldenPath/help/hgNearHelp.html"; label = "Help on Gene Sorter"; } else if (endsWith(scriptName, "hgTables")) { link = "../goldenPath/help/hgTablesHelp.html"; label = "Help on Table Browser"; } else if (endsWith(scriptName, "hgGenome")) { link = "../goldenPath/help/hgGenomeHelp.html"; label = "Help on Genome Graphs"; } else if (endsWith(scriptName, "hgSession")) { link = "../goldenPath/help/hgSessionHelp.html"; label = "Help on Sessions"; } else if (endsWith(scriptName, "hgVisiGene")) { link = "../goldenPath/help/hgTracksHelp.html#VisiGeneHelp"; label = "Help on VisiGene"; } else if (endsWith(scriptName, "hgCustom")) { link = "../goldenPath/help/customTrack.html"; label = "Help on Custom Tracks"; } // Don't overwrite any previously set defaults if(!contextSpecificHelpLink && link) contextSpecificHelpLink = link; if(!contextSpecificHelpLabel && label) contextSpecificHelpLabel = label; } if(contextSpecificHelpLink) { char buf[1024]; safef(buf, sizeof(buf), "<li><a href='%s'>%s</a></li>", contextSpecificHelpLink, contextSpecificHelpLabel); menuStr = replaceChars(menuStr, "<!-- CONTEXT_SPECIFIC_HELP -->", buf); } return menuStr; }