PageRenderTime 69ms CodeModel.GetById 24ms app.highlight 34ms RepoModel.GetById 0ms app.codeStats 1ms

/PageRoot.cpp

https://github.com/gigablast/open-source-search-engine
C++ | 3434 lines | 1560 code | 341 blank | 1533 comment | 205 complexity | c7c3cacbb1af6425871752ada1930fa5 MD5 | raw file
Possible License(s): Apache-2.0

Large files files are truncated, but you can click here to view the full file

   1#include "gb-include.h"
   2
   3#include "Indexdb.h"     // makeKey(int64_t docId)
   4#include "Titledb.h"
   5#include "Spider.h"
   6#include "Tagdb.h"
   7#include "Dns.h"
   8//#include "PageResults.h" // for query buf, g_qbuf
   9#include "Collectiondb.h"
  10//#include "CollectionRec.h"
  11#include "Clusterdb.h"    // for getting # of docs indexed
  12//#include "Checksumdb.h"   // should migrate to this one, though
  13#include "Pages.h"
  14#include "Query.h"        // MAX_QUERY_LEN
  15#include "SafeBuf.h"
  16#include "LanguageIdentifier.h"
  17#include "LanguagePages.h"
  18#include "Users.h"
  19#include "Address.h" // getIPLocation
  20#include "Proxy.h"
  21
  22//char *printNumResultsDropDown ( char *p, int32_t n, bool *printedDropDown);
  23bool printNumResultsDropDown ( SafeBuf& sb, int32_t n, bool *printedDropDown);
  24//static char *printTopDirectory ( char *p, char *pend );
  25static bool printTopDirectory ( SafeBuf& sb , char format );
  26
  27// this prints the last five queries
  28//static int32_t printLastQueries ( char *p , char *pend ) ;
  29
  30//static char *expandRootHtml ( char *p    , int32_t plen    ,
  31/*
  32static bool expandRootHtml  ( SafeBuf& sb,
  33			      uint8_t *html , int32_t htmlLen ,
  34			      char *q    , int32_t qlen    ,
  35			      HttpRequest *r ,
  36			      TcpSocket   *s ,
  37			      int64_t docsInColl ,
  38			      CollectionRec *cr ) ;
  39*/
  40
  41bool sendPageRoot ( TcpSocket *s, HttpRequest *r ){
  42	return sendPageRoot ( s, r, NULL );
  43}
  44
  45bool printNav ( SafeBuf &sb , HttpRequest *r ) {
  46
  47	/*
  48	char *root       = "";
  49	char *rootSecure = "";
  50	if ( g_conf.m_isMattWells ) {
  51		root       = "http://www.gigablast.com";
  52		rootSecure = "https://www.gigablast.com";
  53	}
  54
  55	sb.safePrintf("<center><b><p class=nav>"
  56		      "<a href=%s/about.html>About</a>"
  57		      " &nbsp; &nbsp; "
  58		      "<a href=%s/contact.html>Contact</a>"
  59		      " &nbsp; &nbsp; "
  60		      "<a href=%s/help.html>Help</a>"
  61		      " &nbsp; &nbsp; "
  62		      "<a href=%s/privacy.html>Privacy Policy</a>"
  63		      " &nbsp; &nbsp; "
  64
  65		      // TODO: API page must also provide a description
  66		      // of the output... like searchfeed.html does already.
  67		      // put that in the api page as well.
  68		      "<a href=%s/api>API</a>"
  69		      , root
  70		      , root
  71		      , root
  72		      , root
  73		      , root
  74		      );
  75
  76	if ( g_conf.m_isMattWells )
  77		sb.safePrintf(" &nbsp; &nbsp; "
  78			      "<a href=%s/seoapi.html>SEO API</a>"
  79			      " &nbsp; &nbsp; "
  80			      "<a href=%s/account>My Account</a> "
  81			      , root
  82			      , rootSecure
  83			      //" &nbsp; &nbsp; <a href=/logout>Logout</a>"
  84			      );
  85
  86	//if ( r->isLocal() )
  87	    sb.safePrintf("&nbsp; &nbsp; &nbsp; [<a style=color:green; "
  88			  "href=\"/admin/settings\">"
  89			  "Admin</a>]");
  90	    sb.safePrintf("</p></b></center>");
  91	*/
  92
  93	sb.safePrintf("</TD></TR></TABLE>"
  94		      "</body></html>");
  95	return true;
  96}
  97
  98//////////////
  99//
 100// BEGIN expandHtml() helper functions
 101//
 102//////////////
 103
 104bool printFamilyFilter ( SafeBuf& sb , bool familyFilterOn ) {
 105	char *s1 = "";
 106	char *s2 = "";
 107	if ( familyFilterOn ) s1 = " checked";
 108	else                  s2 = " checked";
 109	//p += sprintf ( p ,
 110	return sb.safePrintf (
 111		       "Family filter: "
 112		       "<input type=radio name=ff value=1%s>On &nbsp; "
 113		       "<input type=radio name=ff value=0%s>Off &nbsp; " ,
 114		       s1 , s2 );
 115	//return p;
 116}
 117
 118//char *printNumResultsDropDown ( char *p , int32_t n , bool *printedDropDown ) {
 119bool printNumResultsDropDown ( SafeBuf& sb , int32_t n , bool *printedDropDown ) {
 120	if ( n!=10 && n!=20 && n!=30 && n!=50 && n!=100 )
 121		//return p;
 122		return true;
 123	*printedDropDown = true;
 124	char *d1 = "";
 125	char *d2 = "";
 126	char *d3 = "";
 127	char *d4 = "";
 128	char *d5 = "";
 129	if ( n == 10 ) d1 = " selected";
 130	if ( n == 20 ) d2 = " selected";
 131	if ( n == 30 ) d3 = " selected";
 132	if ( n == 50 ) d4 = " selected";
 133	if ( n ==100 ) d5 = " selected";
 134	//p += sprintf ( p , 
 135	return sb.safePrintf (
 136		       "<select name=n>\n"
 137		       "<option value=10%s>10\n"
 138		       "<option value=20%s>20\n"
 139		       "<option value=30%s>30\n"
 140		       "<option value=50%s>50\n"
 141		       "<option value=100%s>100\n"
 142		       "</select>",
 143		       d1,d2,d3,d4,d5);
 144	//return p;
 145}
 146
 147//char *printDirectorySearchType ( char *p, int32_t sdirt ) {
 148bool printDirectorySearchType ( SafeBuf& sb, int32_t sdirt ) {
 149	// default to entire directory
 150	if (sdirt < 1 || sdirt > 4)
 151		sdirt = 3;
 152
 153	// by default search the whole thing
 154	sb.safePrintf("<input type=\"radio\" name=\"sdirt\" value=\"3\"");
 155	if (sdirt == 3) sb.safePrintf(" checked>");
 156	else            sb.safePrintf(">");
 157	sb.safePrintf("Entire Directory<br>\n");
 158	// entire category
 159	sb.safePrintf("<input type=\"radio\" name=\"sdirt\" value=\"1\"");
 160	if (sdirt == 1) sb.safePrintf(" checked>");
 161	else            sb.safePrintf(">");
 162	sb.safePrintf("Entire Category<br>\n");
 163	// base category only
 164	sb.safePrintf("<nobr><input type=\"radio\" name=\"sdirt\" value=\"2\"");
 165	if (sdirt == 2) sb.safePrintf(" checked>");
 166	else            sb.safePrintf(">"); 
 167	sb.safePrintf("Pages in Base Category</nobr><br>\n");
 168	// sites in base category
 169	sb.safePrintf("<input type=\"radio\" name=\"sdirt\" value=\"7\"");
 170	if (sdirt == 7) sb.safePrintf(" checked>");
 171	else            sb.safePrintf(">");
 172	sb.safePrintf("Sites in Base Category<br>\n");
 173	// sites in entire category
 174	sb.safePrintf("<input type=\"radio\" name=\"sdirt\" value=\"6\"");
 175	if (sdirt == 6) sb.safePrintf(" checked>");
 176	else            sb.safePrintf(">");
 177	sb.safePrintf("Sites in Entire Category<br>\n");
 178	// end it
 179	return true;
 180}
 181
 182
 183#include "SearchInput.h"
 184
 185bool printRadioButtons ( SafeBuf& sb , SearchInput *si ) {
 186	// don't display this for directory search
 187	// look it up. returns catId <= 0 if dmoz not setup yet.
 188	// From PageDirectory.cpp
 189	//int32_t catId= g_categories->getIdFromPath(decodedPath, decodedPathLen);
 190	// if /Top print the directory homepage
 191	//if ( catId == 1 || catId <= 0 ) 
 192	//	return true;
 193
 194	// site
 195	/*
 196	if ( si->m_siteLen > 0 ) {
 197		// . print rest of search box etc.
 198		// . print cobranding radio buttons
 199		//if ( p + si->m_siteLen + 1 >= pend ) return p;
 200		//p += sprintf ( p , 
 201		return sb.safePrintf (
 202			  //" &nbsp; "
 203			  //"<font size=-1>"
 204			  //"<b><a href=\"/\"><font color=red>"
 205			  //"Powered by Gigablast</font></a></b>"
 206			  //"<br>"
 207			  //"<tr align=center><td></td><td>"
 208			  "<input type=radio name=site value=\"\">"
 209			  "Search the Web "
 210			  "<input type=radio name=site "
 211			  "value=\"%s\"  checked>Search %s" ,
 212			  //"</td></tr></table><br>"
 213			  //"</td></tr>"
 214			  //"<font size=-1>" ,
 215			  si->m_site , si->m_site );
 216	}
 217	else if ( si->m_sitesLen > 0 ) {
 218	*/
 219	if ( si->m_sites && si->m_sites[0] ) {
 220		// . print rest of search box etc.
 221		// . print cobranding radio buttons
 222		//if ( p + si->m_sitesLen + 1 >= pend ) return p;
 223		// if not explicitly instructed to print all sites
 224		// and they are a int32_t list, do not print all
 225		/*
 226		char tmp[1000];
 227		char *x = si->m_sites;
 228		if ( si->m_sitesLen > 255){//&&!st->m_printAllSites){
 229			// copy what's there
 230			strncpy ( tmp , si->m_sites , 255 );
 231			x = tmp + 254 ;
 232			// do not hack off in the middle of a site
 233			while ( is_alnum(*x) && x > tmp ) x--;
 234			// overwrite it with [more] link
 235			//x += sprintf ( x , "<a href=\"/search?" );
 236			// our current query parameters
 237			//if ( x + uclen + 10 >= xend ) goto skipit;
 238			sprintf ( x , " ..." );
 239			x = tmp;
 240		}
 241		*/
 242		//p += sprintf ( p , 
 243		sb.safePrintf (
 244			  //" &nbsp; "
 245			  //"<font size=-1>"
 246			  //"<b><a href=\"/\"><font color=red>"
 247			  //"Powered by Gigablast</font></a></b>"
 248			  //"<br>"
 249			  //"<tr align=center><td></td><td>"
 250			  "<input type=radio name=sites value=\"\">"
 251			  "Search the Web "
 252			  "<input type=radio name=sites "
 253			  "value=\"%s\"  checked>Search ",
 254			  //"</td></tr></table><br>"
 255			  //"</td></tr>"
 256			  //"<font size=-1>" ,
 257			  si->m_sites );
 258		sb.safeTruncateEllipsis ( si->m_sites, 255 );
 259	}
 260	return true;
 261}
 262
 263bool printLogo ( SafeBuf& sb , SearchInput *si ) {
 264	// if an image was provided...
 265	if ( ! si->m_imgUrl || ! si->m_imgUrl[0] ) {
 266		// no, now we default to our logo
 267		//return true;
 268		//p += sprintf ( p ,
 269		return sb.safePrintf (
 270			  "<a href=\"/\">"
 271			  "<img valign=top width=250 height=61 border=0 "
 272			  // avoid https for this, so make it absolute
 273			  "src=\"/logo-med.jpg\"></a>" );
 274		//return p;
 275	}
 276	// do we have a link?
 277	if ( si->m_imgLink && si->m_imgLink[0])
 278		//p += sprintf ( p , "<a href=\"%s\">",si->m_imgLink);
 279		sb.safePrintf ( "<a href=\"%s\">", si->m_imgLink );
 280	// print image width and length
 281	if ( si->m_imgWidth >= 0 && si->m_imgHeight >= 0 ) 
 282		//p += sprintf ( p , "<img width=%"INT32" height=%"INT32" ",
 283		sb.safePrintf( "<img width=%"INT32" height=%"INT32" ",
 284			       si->m_imgWidth , si->m_imgHeight );
 285	else
 286		//p += sprintf ( p , "<img " );
 287		sb.safePrintf ( "<img " );
 288
 289	//p += sprintf ( p , "border=0 src=\"%s\">",
 290	sb.safePrintf( "border=0 src=\"%s\">",
 291		       si->m_imgUrl );
 292	// end the link if we had one
 293	if ( si->m_imgLink && si->m_imgLink[0] ) 
 294		//p += sprintf ( p , "</a>");
 295		sb.safePrintf ( "</a>");
 296
 297	return true;
 298}
 299
 300/////////////
 301//
 302// END expandHtml() helper functions
 303//
 304/////////////
 305
 306
 307bool expandHtml (  SafeBuf& sb,
 308		   char *head , 
 309		   int32_t hlen ,
 310		   char *q    , 
 311		   int32_t qlen ,
 312		   HttpRequest *r ,
 313		   SearchInput *si,
 314		   char *method ,
 315		   CollectionRec *cr ) {
 316	//char *pend = p + plen;
 317	// store custom header into buf now
 318	//for ( int32_t i = 0 ; i < hlen && p+10 < pend ; i++ ) {
 319	for ( int32_t i = 0 ; i < hlen; i++ ) {
 320		if ( head[i] != '%'   ) {
 321			// *p++ = head[i];
 322			sb.safeMemcpy((char*)&head[i], 1);
 323			continue;
 324		}
 325		if ( i + 1 >= hlen    ) {
 326			// *p++ = head[i];
 327			sb.safeMemcpy((char*)&head[i], 1);
 328			continue;
 329		}
 330		if ( head[i+1] == 'S' ) { 
 331			// now we got the %S, insert "spiders are [on/off]"
 332			bool spidersOn = true;
 333			if ( ! g_conf.m_spideringEnabled ) spidersOn = false;
 334			if ( ! cr->m_spideringEnabled ) spidersOn = false;
 335			if ( spidersOn ) 
 336				sb.safePrintf("Spiders are on");
 337			else
 338				sb.safePrintf("Spiders are off");
 339			// skip over %S
 340			i += 1;
 341			continue;
 342		}
 343
 344		if ( head[i+1] == 'q' ) { 
 345			// now we got the %q, insert the query
 346			char *p    = (char*) sb.getBuf();
 347			char *pend = (char*) sb.getBufEnd();
 348			int32_t eqlen = dequote ( p , pend , q , qlen );
 349			//p += eqlen;
 350			sb.incrementLength(eqlen);
 351			// skip over %q
 352			i += 1;
 353			continue;
 354		}
 355
 356		if ( head[i+1] == 'c' ) { 
 357			// now we got the %q, insert the query
 358			if ( cr ) sb.safeStrcpy(cr->m_coll);
 359			// skip over %c
 360			i += 1;
 361			continue;
 362		}
 363
 364		if ( head[i+1] == 'w' &&
 365		     head[i+2] == 'h' &&
 366		     head[i+3] == 'e' &&
 367		     head[i+4] == 'r' &&
 368		     head[i+5] == 'e' ) {
 369			// insert the location
 370			int32_t whereLen;
 371			char *where = r->getString("where",&whereLen);
 372			// get it from cookie as well!
 373			if ( ! where ) 
 374				where = r->getStringFromCookie("where",
 375							       &whereLen);
 376			// fix for getStringFromCookie
 377			if ( where && ! where[0] ) where = NULL;
 378			// skip over the %where
 379			i += 5;
 380			// if empty, base it on IP
 381			if ( ! where ) {
 382				double lat;
 383				double lon;
 384				double radius;
 385				char *city,*state,*ctry;
 386				// use this by default
 387				int32_t ip = r->m_userIP;
 388				// ip for testing?
 389				int32_t iplen;
 390				char *ips = r->getString("uip",&iplen);
 391				if ( ips ) ip = atoip(ips);
 392				// returns true if found in db
 393				char buf[128];
 394				getIPLocation ( ip ,
 395						&lat , 
 396						&lon , 
 397						&radius,
 398						&city ,
 399						&state ,
 400						&ctry  ,
 401						buf    ,
 402						128    ) ;
 403				if ( city && state )
 404					sb.safePrintf("%s, %s",city,state);
 405			}
 406			else
 407				sb.dequote (where,whereLen);
 408			continue;
 409		}
 410		if ( head[i+1] == 'w' &&
 411		     head[i+2] == 'h' &&
 412		     head[i+3] == 'e' &&
 413		     head[i+4] == 'n' ) {
 414			// insert the location
 415			int32_t whenLen;
 416			char *when = r->getString("when",&whenLen);
 417			// skip over the %when
 418			i += 4;
 419			if ( ! when ) continue;
 420			sb.dequote (when,whenLen);
 421			continue;
 422		}
 423		// %sortby
 424		if ( head[i+1] == 's' &&
 425		     head[i+2] == 'o' &&
 426		     head[i+3] == 'r' &&
 427		     head[i+4] == 't' &&
 428		     head[i+5] == 'b' &&
 429		     head[i+6] == 'y' ) {
 430			// insert the location
 431			int32_t sortBy = r->getLong("sortby",1);
 432			// print the radio buttons
 433			char *cs[5];
 434			cs[0]="";
 435			cs[1]="";
 436			cs[2]="";
 437			cs[3]="";
 438			cs[4]="";
 439			if ( sortBy >=1 && sortBy <=4 )
 440				cs[sortBy] = " checked";
 441			sb.safePrintf(
 442			 "<input type=radio name=sortby value=1%s>date "
 443			 "<input type=radio name=sortby value=2%s>distance "
 444			 "<input type=radio name=sortby value=3%s>relevancy "
 445			 "<input type=radio name=sortby value=4%s>popularity",
 446			 cs[1],cs[2],cs[3],cs[4]);
 447			// skip over the %sortby
 448			i += 6;
 449			continue;
 450		}
 451		if ( head[i+1] == 'e' ) { 
 452			// now we got the %e, insert the query
 453			char *p    = (char*) sb.getBuf();
 454			int32_t  plen = sb.getAvail();
 455			int32_t eqlen = urlEncode ( p , plen , q , qlen );
 456			//p += eqlen;
 457			sb.incrementLength(eqlen);
 458			// skip over %e
 459			i += 1;
 460			continue;
 461		}
 462		if ( head[i+1] == 'N' ) { 
 463			// now we got the %N, insert the global doc count
 464			//int64_t c=g_checksumdb.getRdb()->getNumGlobalRecs();
 465			//now each host tells us how many docs it has in itsping
 466			int64_t c = g_hostdb.getNumGlobalRecs();
 467			c += g_conf.m_docCountAdjustment;
 468			// never allow to go negative
 469			if ( c < 0 ) c = 0;
 470			//p+=ulltoa(p,c);
 471			char *p = (char*) sb.getBuf();
 472			sb.reserve2x(16);
 473			int32_t len = ulltoa(p, c);
 474			sb.incrementLength(len);
 475			// skip over %N
 476			i += 1;
 477			continue;
 478		}
 479		/*
 480		if ( head[i+1] == 'E' ) { 
 481			// now each host tells us how many docs it has in its
 482			// ping request
 483			int64_t c = g_hostdb.getNumGlobalEvents();
 484			char *p = (char*) sb.getBuf();
 485			sb.reserve2x(16);
 486			int32_t len = ulltoa(p, c);
 487			sb.incrementLength(len);
 488			// skip over %E
 489			i += 1;
 490			continue;
 491		}
 492		*/
 493		if ( head[i+1] == 'n' ) { 
 494			// now we got the %n, insert the collection doc count
 495			//p+=ulltoa(p,docsInColl);
 496			char *p = (char*) sb.getBuf();
 497			sb.reserve2x(16);
 498			int64_t docsInColl = 0;
 499			if ( cr ) docsInColl = cr->getNumDocsIndexed();
 500			int32_t len = ulltoa(p, docsInColl);
 501			sb.incrementLength(len);
 502			// skip over %n
 503			i += 1;
 504			continue;
 505		}
 506		/*
 507		if ( head[i+1] == 'T' ) { 
 508			// . print the final tail
 509			// . only print admin link if we're local
 510			//int32_t  user = g_pages.getUserType ( s , r );
 511			//char *username = g_users.getUsername(r);
 512			//char *pwd  = r->getString ( "pwd" );
 513			char *p    = (char*) sb.getBuf();
 514			int32_t  plen = sb.getAvail();
 515			//p = g_pages.printTail ( p , p + plen , user , pwd );
 516			char *n = g_pages.printTail(p , p + plen ,
 517						    r->isLocal());
 518			sb.incrementLength(n - p);
 519			// skip over %T
 520			i += 1;
 521			continue;
 522		}
 523		*/
 524		// print the drop down menu for selecting the # of reslts
 525		if ( head[i+1] == 'D' ) {
 526			// skip over %D
 527			i += 1;
 528			// skip if not enough buffer
 529			//if ( p + 1000 >= pend ) continue; 
 530			// # results
 531			//int32_t n = r->getLong("n",10);
 532			//bool printedDropDown;
 533			//p = printNumResultsDropDown(p,n,&printedDropDown);
 534			//printNumResultsDropDown(sb,n,&printedDropDown);
 535			continue;
 536		}
 537		if ( head[i+1] == 'H' ) { 
 538			// . insert the secret key here, to stop seo bots
 539			// . TODO: randomize its position to make parsing more 
 540			//         difficult
 541			// . this secret key is for submitting a new query
 542			// int32_t key;
 543			// char kname[4];
 544			// g_httpServer.getKey (&key,kname,NULL,0,time(NULL),0,
 545			// 		     10);
 546			//sprintf (p , "<input type=hidden name=%s value=%"INT32">",
 547			//	  kname,key);
 548			//p += gbstrlen ( p );
 549			// sb.safePrintf( "<input type=hidden name=%s "
 550			//"value=%"INT32">",
 551			// 	       kname,key);
 552
 553			//adds param for default screen size
 554			//if(cr)
 555			//	sb.safePrintf("<input type=hidden "
 556			//"id='screenWidth' name='ws' value=%"INT32">", 
 557			//cr->m_screenWidth);
 558
 559			// insert collection name too
 560			int32_t collLen;
 561			char *coll = r->getString ( "c" , &collLen );
 562			if ( collLen > 0 && collLen < MAX_COLL_LEN ) {
 563			        //sprintf (p,"<input type=hidden name=c "
 564				//	 "value=\"");
 565				//p += gbstrlen ( p );	
 566				sb.safePrintf("<input type=hidden name=c "
 567					      "value=\"");
 568				//gbmemcpy ( p , coll , collLen );
 569				//p += collLen;
 570				sb.safeMemcpy(coll, collLen);
 571				//sprintf ( p , "\">\n");
 572				//p += gbstrlen ( p );	
 573				sb.safePrintf("\">\n");
 574			}
 575
 576			// pass this crap on so zak can do searches
 577			//char *username = g_users.getUsername(r);
 578			// this is null because not in the cookie and we are
 579			// logged in
 580			//char *pwd  = r->getString ( "pwd" );
 581			//sb.safePrintf("<input type=hidden name=pwd "
 582			//"value=\"%s\">\n",
 583			//pwd);
 584			//sb.safePrintf("<input type=hidden name=username "
 585			//	      "value=\"%s\">\n",username);
 586
 587			// skip over %H
 588			i += 1;
 589			continue;
 590		}
 591		// %t, print Top Directory section
 592		if ( head[i+1] == 't' ) {
 593			i += 1;
 594			//p = printTopDirectory ( p, pend );
 595			printTopDirectory ( sb , FORMAT_HTML );
 596			continue;
 597		}
 598
 599		// MDW
 600
 601		if ( head[i+1] == 'F' ) {
 602			i += 1;
 603			//p = printTopDirectory ( p, pend );
 604			if ( ! method ) method = "GET";
 605			sb.safePrintf("<form method=%s action=\"/search\" "
 606				      "name=\"f\">\n",method);
 607			continue;
 608		}
 609
 610		if ( head[i+1] == 'L' ) {
 611			i += 1;
 612			//p = printTopDirectory ( p, pend );
 613			printLogo ( sb , si );
 614			continue;
 615		}
 616
 617		if ( head[i+1] == 'f' ) {
 618			i += 1;
 619			//p = printTopDirectory ( p, pend );
 620			printFamilyFilter ( sb , si->m_familyFilter );
 621			continue;
 622		}
 623
 624		if ( head[i+1] == 'R' ) {
 625			i += 1;
 626			//p = printTopDirectory ( p, pend );
 627			printRadioButtons ( sb , si );
 628			continue;
 629		}
 630
 631		// MDW
 632
 633		// *p++ = head[i];
 634		sb.safeMemcpy((char*)&head[i], 1);
 635		continue;
 636	}
 637	//return p;
 638	return true;
 639}
 640
 641
 642bool printLeftColumnRocketAndTabs ( SafeBuf *sb , 
 643				    bool isSearchResultsPage ,
 644				    CollectionRec *cr ,
 645				    char *tabName ) {
 646
 647	class MenuItem {
 648	public:
 649		char *m_text;
 650		char *m_url;
 651	};
 652
 653	static MenuItem mi[] = {
 654
 655		{"SEARCH","/"},
 656
 657 		// {"DISCUSSIONS","/?searchtype=discussions"},
 658 		// {"PRODUCTS","/?searchtype=products"},
 659 		// {"ARTICLES","/?searchtype=articles"},
 660 		// {"IMAGES","/?searchtype=images"},
 661
 662		{"DIRECTORY","/Top"},
 663		{"ADVANCED","/adv.html"},
 664		{"ADD URL","/addurl"},
 665		{"WIDGETS","/widgets.html"},
 666		{"SYNTAX","/syntax.html"},
 667		{"USERS","/users.html"},
 668		{"ABOUT","/about.html"},
 669		{"BLOG","/blog.html"},
 670		// take this out for now
 671		//{"FEED","/searchfeed.html"},
 672		{"FAQ","/faq.html"},
 673		{"API","/api.html"}
 674	};
 675
 676	char *coll = "";
 677	if ( cr ) coll = cr->m_coll;
 678
 679	//
 680	// first the nav column
 681	//
 682	sb->safePrintf(
 683		       "<TD bgcolor=#%s " // f3c714 " // yellow/gold
 684		      "valign=top "
 685		      "style=\"width:210px;"
 686		      "border-right:3px solid blue;"
 687		      "\">"
 688
 689		      "<br>"
 690
 691		      "<center>"
 692		      "<a href=/?c=%s>"
 693		      "<div style=\""
 694		      "background-color:white;"
 695		      "padding:10px;"
 696		      "border-radius:100px;"
 697		      "border-color:blue;"
 698		      "border-width:3px;"
 699		      "border-style:solid;"
 700		      "width:100px;"
 701		      "height:100px;"
 702		      "\">"
 703		       , GOLD
 704		       , coll
 705		       );
 706
 707	if ( strcmp(tabName,"appliance") == 0 )
 708		sb->safePrintf("<img style=margin-top:21px; width=90 "
 709			       "height=57 src=/computer2.png>");
 710	else
 711		sb->safePrintf("<br style=line-height:10px;>"
 712			       "<img border=0 "
 713			       "width=54 height=79 src=/rocket.jpg>"
 714			       );
 715
 716	sb->safePrintf ( "</div>"
 717			 "</a>"
 718			 "</center>"
 719
 720			 "<br>"
 721			 "<br>"
 722		      );
 723
 724	int32_t n = sizeof(mi) / sizeof(MenuItem);
 725
 726
 727	for ( int32_t i = 0 ; i < n ; i++ ) {
 728
 729		// just show search, directory and advanced tab in serps
 730		if ( isSearchResultsPage && i >= 3 ) break;
 731
 732		// what was this for?
 733		// if ( i >= 1 && i <= 4 &&
 734		//      cr->m_diffbotApiUrl.length() >= 0 )
 735		// 	continue;
 736
 737		char delim = '?';
 738		if ( strstr ( mi[i].m_url,"?") ) delim = '&';
 739
 740		sb->safePrintf(
 741			      "<a href=%s%cc=%s>"
 742			      "<div style=\""
 743			      "padding:5px;"
 744			      "position:relative;"
 745			      "text-align:right;"
 746			      "border-width:3px;"
 747			      "border-right-width:0px;"
 748			      "border-style:solid;"
 749			      "margin-left:10px;"
 750			      "border-top-left-radius:10px;"
 751			      "border-bottom-left-radius:10px;"
 752			      "font-size:14px;"
 753			      "x-overflow:;"
 754			      , mi[i].m_url
 755			      , delim
 756			      , coll
 757			      );
 758		//if ( i == pageNum )
 759		bool matched = false;
 760		if ( strcasecmp(mi[i].m_text,tabName) == 0 )
 761			matched = true;
 762
 763		if ( matched )
 764			sb->safePrintf(
 765				      "border-color:blue;"
 766				      "color:black;"
 767				      "background-color:white;\" ");
 768		else
 769			sb->safePrintf("border-color:white;"
 770				      "color:white;"
 771				      "background-color:blue;\" "
 772				      " onmouseover=\""
 773				      "this.style.backgroundColor='lightblue';"
 774				      "this.style.color='black';\""
 775				      " onmouseout=\""
 776				      "this.style.backgroundColor='blue';"
 777				      "this.style.color='white';\""
 778				      );
 779
 780		sb->safePrintf(">"
 781			      // make button wider
 782			      "<nobr>"
 783			      "&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "
 784			      "<b>%s</b> &nbsp; &nbsp;</nobr>"
 785			      , mi[i].m_text
 786			      );
 787		//
 788		// begin hack: white out the blue border line!!
 789		//
 790		if ( matched )
 791			sb->safePrintf(
 792				      "<div style=padding:5px;top:0;"
 793				      "background-color:white;"
 794				      "display:inline-block;"
 795				      "position:absolute;>"
 796				      "&nbsp;"
 797				      "</div>"
 798				      );
 799		// end hack
 800		sb->safePrintf(
 801			      "</div>"
 802			      "</a>"
 803			      "<br>"
 804			      );
 805	}
 806
 807
 808
 809	// admin link
 810	if ( isSearchResultsPage ) return true;
 811
 812	sb->safePrintf(
 813		      "<a href=/admin/settings?c=%s>"
 814		      "<div style=\"background-color:green;"
 815		      // for try it out bubble:
 816		      //"position:relative;"
 817		      "padding:5px;"
 818		      "text-align:right;"
 819		      "border-width:3px;"
 820		      "border-right-width:0px;"
 821		      "border-style:solid;"
 822		      "margin-left:10px;"
 823		      "border-color:white;"
 824		      "border-top-left-radius:10px;"
 825		      "border-bottom-left-radius:10px;"
 826		      "font-size:14px;"
 827		      "color:white;"
 828		      "cursor:hand;"
 829		      "cursor:pointer;\" "
 830		      " onmouseover=\""
 831		      "this.style.backgroundColor='lightgreen';"
 832		      "this.style.color='black';\""
 833		      " onmouseout=\""
 834		      "this.style.backgroundColor='green';"
 835		      "this.style.color='white';\""
 836		      ">"
 837
 838		      /*
 839		      // try it out bubble div
 840		      "<div "
 841
 842		      " onmouseover=\""
 843		      "this.style.box-shadow='10px 10px 5px #888888';"
 844		      "\""
 845		      " onmouseout=\""
 846		      "this.style.box-shadow='';"
 847		      "\""
 848
 849		      "style=\""
 850		      "vertical-align:middle;"
 851		      "text-align:left;"
 852		      "cursor:pointer;"
 853		      "cursor:hand;"
 854		      //"border-color:black;"
 855		      //"border-style:solid;"
 856		      //"border-width:2px;"
 857		      "padding:3px;"
 858		      //"width:30px;"
 859		      //"height:20px;"
 860		      //"margin-top:-20px;"
 861		      "margin-left:-120px;"
 862		      "position:absolute;"
 863		      //"top:-20px;"
 864		      //"left:10px;"
 865		      "display:inline-block;"
 866		      "\""
 867		      ">"
 868		      "<b style=font-size:11px;>"
 869		      "Click for demo"
 870		      "</b>"
 871		      "</div>"
 872		      */
 873		      // end try it out bubble div
 874
 875
 876
 877
 878		      "<b>ADMIN</b> &nbsp; &nbsp;"
 879		      "</div>"
 880		      "</a>"
 881		      "<br>"
 882
 883		      "</TD>"
 884		      , coll
 885		      );
 886
 887	return true;
 888}
 889
 890bool printFrontPageShell ( SafeBuf *sb , char *tabName , CollectionRec *cr ,
 891			   bool printGigablast ) {
 892
 893	sb->safePrintf("<html>\n");
 894	sb->safePrintf("<head>\n");
 895	//sb->safePrintf("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf8\">");
 896	sb->safePrintf("<meta name=\"description\" content=\"A powerful, new search engine that does real-time indexing!\">\n");
 897	sb->safePrintf("<meta name=\"keywords\" content=\"search, search engine, search engines, search the web, fresh index, green search engine, green search, clean search engine, clean search\">\n");
 898	//char *title = "An Alternative Open Source Search Engine";
 899	char *title = "An Alternative Open Source Search Engine";
 900	if ( strcasecmp(tabName,"search") ) title = tabName;
 901	// if ( pageNum == 1 ) title = "Directory";
 902	// if ( pageNum == 2 ) title = "Advanced";
 903	// if ( pageNum == 3 ) title = "Add Url";
 904	// if ( pageNum == 4 ) title = "About";
 905	// if ( pageNum == 5 ) title = "Help";
 906	// if ( pageNum == 6 ) title = "API";
 907	sb->safePrintf("<title>Gigablast - %s</title>\n",title);
 908	sb->safePrintf("<style><!--\n");
 909	sb->safePrintf("body {\n");
 910	sb->safePrintf("font-family:Arial, Helvetica, sans-serif;\n");
 911	sb->safePrintf("color: #000000;\n");
 912	sb->safePrintf("font-size: 12px;\n");
 913	sb->safePrintf("margin: 0px 0px;\n");
 914	sb->safePrintf("letter-spacing: 0.04em;\n");
 915	sb->safePrintf("}\n");
 916	sb->safePrintf("a {text-decoration:none;}\n");
 917	//sb->safePrintf("a:link {color:#00c}\n");
 918	//sb->safePrintf("a:visited {color:#551a8b}\n");
 919	//sb->safePrintf("a:active {color:#f00}\n");
 920	sb->safePrintf(".bold {font-weight: bold;}\n");
 921	sb->safePrintf(".bluetable {background:#d1e1ff;margin-bottom:15px;font-size:12px;}\n");
 922	sb->safePrintf(".url {color:#008000;}\n");
 923	sb->safePrintf(".cached, .cached a {font-size: 10px;color: #666666;\n");
 924	sb->safePrintf("}\n");
 925	sb->safePrintf("table {\n");
 926	sb->safePrintf("font-family:Arial, Helvetica, sans-serif;\n");
 927	sb->safePrintf("color: #000000;\n");
 928	sb->safePrintf("font-size: 12px;\n");
 929	sb->safePrintf("}\n");
 930	sb->safePrintf(".directory {font-size: 16px;}\n"
 931		      ".nav {font-size:20px;align:right;}\n"
 932		      );
 933	sb->safePrintf("-->\n");
 934	sb->safePrintf("</style>\n");
 935	sb->safePrintf("\n");
 936	sb->safePrintf("</head>\n");
 937	sb->safePrintf("<script>\n");
 938	sb->safePrintf("<!--\n");
 939	sb->safePrintf("function x(){document.f.q.focus();}\n");
 940	sb->safePrintf("// --></script>\n");
 941	sb->safePrintf("<body onload=\"x()\">\n");
 942	//sb->safePrintf("<body>\n");
 943	//g_proxy.insertLoginBarDirective ( &sb );
 944
 945	//
 946	// DIVIDE INTO TWO PANES, LEFT COLUMN and MAIN COLUMN
 947	//
 948
 949
 950	sb->safePrintf("<TABLE border=0 height=100%% cellspacing=0 "
 951		      "cellpadding=0>"
 952		      "\n<TR>\n");
 953
 954
 955	// . also prints <TD>...</TD>
 956	// . false = isSearchResultsPage?
 957	printLeftColumnRocketAndTabs ( sb , false , cr , tabName );
 958
 959
 960	//
 961	// now the MAIN column
 962	//
 963	sb->safePrintf("\n<TD valign=top style=padding-left:30px;>\n");
 964
 965	sb->safePrintf("<br><br>");
 966
 967	if ( ! printGigablast )
 968		return true;
 969
 970	sb->safePrintf("<a href=/><img border=0 width=470 "
 971		      "height=44 src=/gigablast.jpg></a>\n");
 972
 973	// sb->safePrintf("<br>"
 974	// 	      "<img border=0 width=470 "
 975	// 	      "height=15 src=/bar.jpg>\n");
 976
 977	return true;
 978}
 979
 980bool printWebHomePage ( SafeBuf &sb , HttpRequest *r , TcpSocket *sock ) {
 981
 982	SearchInput si;
 983	si.set ( sock , r );
 984
 985	// if there's a ton of sites use the post method otherwise
 986	// they won't fit into the http request, the browser will reject
 987	// sending such a large request with "GET"
 988	char *method = "GET";
 989	if ( si.m_sites && gbstrlen(si.m_sites)>800 ) method = "POST";
 990
 991	// if the provided their own
 992	CollectionRec *cr = g_collectiondb.getRec ( r );
 993	if ( cr && cr->m_htmlRoot.length() ) {
 994		return expandHtml (  sb ,
 995				     cr->m_htmlRoot.getBufStart(),
 996				     cr->m_htmlRoot.length(),
 997				     NULL,
 998				     0,
 999				     r ,
1000				     &si,
1001				     //TcpSocket   *s ,
1002				     method , // "GET" or "POST"
1003				     cr );//CollectionRec *cr ) {
1004	}
1005
1006	// . search special types
1007	// . defaults to web which is "search"
1008	// . can be like "images" "products" "articles"
1009	char *searchType = r->getString("searchtype",NULL,"search",NULL);
1010	log("searchtype=%s",searchType);
1011
1012	// pass searchType in as tabName
1013	printFrontPageShell ( &sb , searchType , cr , true );
1014
1015
1016	//sb.safePrintf("<br><br>\n");
1017	// try to avoid using https for images. it is like 10ms slower.
1018
1019	// if ( g_conf.m_isMattWells )
1020	// 	sb.safePrintf("<center><a href=/><img border=0 width=500 "
1021	// 		      "height=122 src=http://www.gigablast.com/logo-"
1022	// 		      "med.jpg></a>\n");
1023	// else
1024
1025
1026	sb.safePrintf("<br><br>\n");
1027	sb.safePrintf("<br><br><br>\n");
1028	/*
1029	sb.safePrintf("<b>web</b> &nbsp;&nbsp;&nbsp;&nbsp; ");
1030	if ( g_conf.m_isMattWells )
1031		sb.safePrintf("<a href=http://www.gigablast.com/seo>seo</a> "
1032			      "&nbsp;&nbsp;&nbsp;&nbsp; "
1033			      );
1034	sb.safePrintf( "<a href=\"/Top\">directory</a> "
1035		      "&nbsp;&nbsp;&nbsp;&nbsp; \n");
1036	sb.safePrintf("<a href=/adv.html>advanced search</a>");
1037	sb.safePrintf(" &nbsp;&nbsp;&nbsp;&nbsp; ");
1038	sb.safePrintf("<a href=/addurl title=\"Instantly add your url to "
1039		      "Gigablast's index\">add url</a>");
1040	sb.safePrintf("\n");
1041	sb.safePrintf("<br><br>\n");
1042	*/
1043	// submit to https now
1044	sb.safePrintf("<form method=%s "
1045		      "action=/search name=f>\n", method);
1046
1047	if ( cr )
1048		sb.safePrintf("<input type=hidden name=c value=\"%s\">",
1049			      cr->m_coll);
1050
1051
1052	// put search box in a box
1053	sb.safePrintf("<div style="
1054		      "background-color:#%s;"//fcc714;"
1055		      "border-style:solid;"
1056		      "border-width:3px;"
1057		      "border-color:blue;"
1058		      //"background-color:blue;"
1059		      "padding:20px;"
1060		      "border-radius:20px;"
1061		      ">"
1062		      ,GOLD
1063		      );
1064
1065
1066	sb.safePrintf("<input name=q type=text "
1067		      "style=\""
1068		      //"width:%"INT32"px;"
1069		      "height:26px;"
1070		      "padding:0px;"
1071		      "font-weight:bold;"
1072		      "padding-left:5px;"
1073		      //"border-radius:10px;"
1074		      "margin:0px;"
1075		      "border:1px inset lightgray;"
1076		      "background-color:#ffffff;"
1077		      "font-size:18px;"
1078		      "\" "
1079
1080		      "size=40 value=\"\">&nbsp; &nbsp;"
1081
1082		      //"<input type=\"submit\" value=\"Search\">"
1083
1084		      "<div onclick=document.f.submit(); "
1085
1086		      " onmouseover=\""
1087		      "this.style.backgroundColor='lightgreen';"
1088		      "this.style.color='black';\""
1089		      " onmouseout=\""
1090		      "this.style.backgroundColor='green';"
1091		      "this.style.color='white';\" "
1092
1093		      "style=border-radius:28px;"
1094		      "cursor:pointer;"
1095		      "cursor:hand;"
1096		      "border-color:white;"
1097		      "border-style:solid;"
1098		      "border-width:3px;"
1099		      "padding:12px;"
1100		      "width:20px;"
1101		      "height:20px;"
1102		      "display:inline-block;"
1103		      "background-color:green;color:white;>"
1104		      "<b style=margin-left:-5px;font-size:18px;"
1105		      ">GO</b>"
1106		      "</div>"
1107		      "\n"
1108		      );
1109
1110	sb.safePrintf("</div>\n");
1111
1112	sb.safePrintf("\n");
1113	sb.safePrintf("</form>\n");
1114	sb.safePrintf("<br>\n");
1115	sb.safePrintf("\n");
1116
1117
1118	if ( cr && cr->m_coll ) { // && strcmp(cr->m_coll,"main") ) {
1119		sb.safePrintf("<center>"
1120			      "Searching the <b>%s</b> collection."
1121			      "</center>",
1122			      cr->m_coll);
1123		sb.safePrintf("<br>\n");
1124		sb.safePrintf("\n");
1125	}
1126
1127
1128	// take this out for now
1129	/*
1130	// always the option to add event guru to their list of
1131	// search engine in their browser
1132	sb.safePrintf("<br>"
1133		      //"<br>"
1134
1135		      "<script>\n"
1136		      "function addEngine() {\n"
1137		      "if (window.external && "
1138		      "('AddSearchProvider' in window.external)) {\n"
1139		      // Firefox 2 and IE 7, OpenSearch
1140		      "window.external.AddSearchProvider('http://"
1141		      "www.gigablast.com/searchbar.xml');\n"
1142		      "}\n"
1143		      "else if (window.sidebar && ('addSearchEngine' "
1144		      "in window.sidebar)) {\n"
1145		      // Firefox <= 1.5, Sherlock
1146		      "window.sidebar.addSearchEngine('http://"
1147		      "www.gigablast.com/searchbar.xml',"
1148		      //"example.com/search-plugin.src',"
1149		      "'http://www.gigablast.com/rocket.jpg'," //guru.png
1150		      "'Search Plugin', '');\n"
1151		      "}\n"
1152		      "else {"
1153		      // No search engine support (IE 6, Opera, etc).
1154		      "alert('No search engine support');\n"
1155		      "}\n"
1156		      // do not ask again if they tried to add it
1157		      // meta cookie should store this
1158		      //"document.getElementById('addedse').value='1';\n"
1159		      // NEVER ask again! permanent cookie
1160		      "document.cookie = 'didse=3';"
1161		      // make it invisible again
1162		      //"var e = document.getElementById('addse');\n"
1163		      //"e.style.display = 'none';\n"
1164		      "}\n"
1165
1166
1167		      "</script>\n"
1168
1169
1170		      "<center>"
1171		      "<a onclick='addEngine();' style="
1172		      "cursor:pointer;"
1173		      "cursor:hand;"
1174		      "color:blue;"
1175		      ">"
1176
1177		      "<img height=16 width=16 border=0 src=/rocket16.png>"
1178
1179		      "<font color=#505050>"
1180		      "%c%c%c "
1181		      "</font>"
1182
1183		      "&nbsp; "
1184
1185		      "Add Gigablast to your browser's "
1186		      "search engines"
1187		      "</a>"
1188		      "</center>"
1189		      "<br>"
1190		      "<br>"
1191
1192		       // print triangle
1193		       ,0xe2
1194		       ,0x96
1195		       ,0xbc
1196
1197		      );
1198	*/
1199
1200
1201	// print any red boxes we might need to
1202	if ( printRedBox2 ( &sb , sock , r ) ) // true ) )
1203		sb.safePrintf("<br>\n");
1204
1205	sb.safePrintf("<br><center><table cellpadding=3>\n");
1206	sb.safePrintf("\n");
1207
1208	char *root = "";
1209	if ( g_conf.m_isMattWells )
1210		root = "http://www.gigablast.com";
1211
1212	sb.safePrintf("<tr valign=top>\n");
1213
1214	//sb.safePrintf("<td align=center><div style=width:50px;height:50px;display:inline-block;background-color:red;></div></td>\n");
1215	sb.safePrintf("<td width=10%% "
1216		      "align=center><img style=padding-right:10px; "
1217		      "height=71px width=50px "
1218		      "src=%s/opensource.png></td>\n"
1219		      , root );
1220
1221	sb.safePrintf("<td width=45%%><font size=+1><b>Open Source!</b>"
1222	"</font><br><br>\n");
1223	sb.brify2("Gigablast is now available as an <a href=https://github.com/gigablast/open-source-search-engine>open source search engine</a> on github.com. Download it today. Finally a robust, scalable search solution in C/C++ that has been in development and used commercially since 2000. <a href=http://www.gigablast.com/faq.html#features>Features</a>."
1224		  ,40);
1225	//sb.safePrintf("<br><br>");
1226	sb.safePrintf("</td>");
1227
1228	sb.safePrintf("<td><font size=+1><b>ScreenShots</b>"
1229	"</font><br><br>\n");
1230
1231	sb.safePrintf("<a href=/ss_settings.png><img width=150 height=81 src=ss_settings_thumb.png></a>");
1232
1233	sb.safePrintf("<br><br>");
1234
1235	sb.safePrintf("<a href=/ss_hosts.png><img width=150 height=81 src=ss_hosts_thumb.png></a>");
1236
1237	sb.safePrintf("<br><br>");
1238
1239	sb.safePrintf("<a href=/ss_filters.png><img width=150 height=81 src=ss_filters_thumb.png></a>");
1240
1241	sb.safePrintf("</td>");
1242
1243
1244	sb.safePrintf("</tr>\n");
1245
1246	sb.safePrintf("</table></center>\n");
1247
1248	/*
1249
1250	  do not show table for open source installs
1251
1252
1253	// donate with paypal
1254	sb.safePrintf("<tr valign=top>\n");
1255	sb.safePrintf("<td align=center style=padding-right:20px;><center>"
1256
1257		      // BEGIN PAYPAL DONATE BUTTON
1258		      "<form action=\"https://www.paypal.com/cgi-bin/webscr\" method=\"post\" target=\"_top\">"
1259		      "<input type=\"hidden\" name=\"cmd\" value=\"_donations\">"
1260		      "<input type=\"hidden\" name=\"business\" value=\"2SFSFLUY3KS9Y\">"
1261		      "<input type=\"hidden\" name=\"lc\" value=\"US\">"
1262		      "<input type=\"hidden\" name=\"item_name\" value=\"Gigablast, Inc.\">"
1263		      "<input type=\"hidden\" name=\"currency_code\" value=\"USD\">"
1264		      "<input type=\"hidden\" name=\"bn\" value=\"PP-DonationsBF:btn_donateCC_LG.gif:NonHosted\">"
1265		      "<input type=\"image\" src=\"https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif\" border=\"0\" name=\"submit\" alt=\"PayPal - The safer, easier way to pay online!\" height=47 width=147>"
1266		      "<img alt=\"\" border=\"0\" src=\"https://www.paypalobjects.com/en_US/i/scr/pixel.gif\" width=\"1\" height=\"1\">"
1267		      "</form>"
1268		      // END PAYPAY BUTTON
1269		      "</center></div></center></td>\n"
1270		      );
1271	sb.safePrintf("<td><font size=+1><b>"
1272		      "Support Gigablast"
1273		      "</b></font><br>\n"
1274		      );
1275	sb.brify2(
1276		  "Donations of $100 or more receive a black "
1277		  "Gigablast T-shirt "
1278		  "with embroidered logo while quantities last. "
1279		  "State your address and size "
1280		  "in an <a href=/contact.html>email</a>. "
1281		  "PayPal accepted. "
1282		  "Help Gigablast continue "
1283		  "to grow and add new features."
1284		  , 80
1285		  );
1286	sb.safePrintf("</td></tr>\n");
1287
1288	*/
1289
1290	/*
1291	sb.safePrintf("<tr valign=top>\n");
1292	// 204x143
1293	sb.safePrintf("<td><img height=52px width=75px "
1294		      "src=%s/eventguru.png></td>\n"
1295		      , root );
1296	sb.safePrintf("<td><font size=+1><b>Event Guru Returns</b></font><br>\n");
1297	sb.brify2("<a href=http://www.eventguru.com/>Event Guru</a> datamines events from the web. It identifies events on a web page, or even plain text, using the same rules of deduction used by the human mind. It also has Facebook integration and lots of other cool things.",80);
1298	sb.safePrintf("<br><br></td></tr>\n");
1299	sb.safePrintf("\n");
1300	sb.safePrintf("\n");
1301	*/
1302
1303
1304	/*
1305	sb.safePrintf("<tr valign=top>\n");
1306	sb.safePrintf("<td align=center><div style=width:50px;height:50px;display:inline-block;background-color:green;></div></td>\n");
1307	sb.safePrintf("<td><font size=+1><b>The Green Search Engine</b></font><br>\n");
1308	sb.brify2("Gigablast is the only clean-powered web search engine. 90% of its power usage comes from wind energy. Astoundingly, Gigablast is one of ONLY four search engines in the United States indexing over a billion pages.",80);
1309	sb.safePrintf("<br><br></td></tr>\n");
1310	sb.safePrintf("\n");
1311	sb.safePrintf("\n");
1312	*/
1313
1314
1315	/*
1316	sb.safePrintf("<tr valign=top>\n");
1317	sb.safePrintf("<td align=center><img src=%s/gears.png "
1318		      "height=50 width=50></div></td>\n"
1319		      , root );
1320	sb.safePrintf("<td><font size=+1><b>The Transparent Search Engine</b></font><br>\n");
1321	sb.brify2("Gigablast is the first truly transparent search engine. It tells you exactly why the search results are ranked the way they are. There is nothing left to the imagination.",85);
1322	sb.safePrintf("<br><br>");
1323	sb.safePrintf("</td></tr>\n");
1324	sb.safePrintf("\n");
1325	sb.safePrintf("\n");
1326	*/
1327
1328	/*
1329	if ( g_conf.m_isMattWells ) {
1330		sb.safePrintf("<tr valign=top>\n");
1331		sb.safePrintf("<td align=center><center><img src=%s/dollargear.png "
1332			      "height=50 width=50></center></div></center></td>\n"
1333			      , root );
1334		sb.safePrintf("<td><font size=+1><b>The SEO Search Engine</b></font><br>\n");
1335		sb.brify2("When it comes to search-engine based SEO, Gigablast is the place to be. With a frothy set of unique and effective <a href=http://www.gigablast.com/seo>SEO tools</a>, you will find all you need to execute a simple yet effective SEO strategy. Stop the guesswork, and let a search engine tell you how to SEO it.",85);
1336		sb.safePrintf("</td></tr>\n");
1337	}
1338	*/
1339
1340	/*
1341	sb.safePrintf("<tr valign=top>\n");
1342	sb.safePrintf("<td><div style=width:50px;height:50px;display:inline-block;background-color:ff3030;></td>\n");
1343	sb.safePrintf("<td><font size=+1><b>Xml Search Feed</b></font><br>\n");
1344	sb.brify2("Utilize Gigablast's results on your own site or product by connecting with Gigablast's <a href=/searchfeed.html>XML search feed</a>. It's now simpler than ever to setup and use. You can also add the web pages you want into the index in near real-time.",85);
1345	sb.safePrintf("</td></tr>\n");
1346	*/
1347
1348	/*
1349	sb.safePrintf("<tr valign=top>\n");
1350	sb.safePrintf("<td><div style=width:50px;height:50px;display:inline-block;background-color:black;></td>\n");
1351	sb.safePrintf("<td><font size=+1><b>The Private Search Engine</b>"
1352	"</font><br>\n");
1353	sb.brify2("Gigablast does not allow the NSA or any third party "
1354		  "to spy on the queries your IP address is doing, "
1355		  "unlike "
1356		  "<a href=http://www.guardian.co.uk/world/2013/jun/"
1357		  "06/us-tech-giants-nsa-data>"
1358		  "other large search engines</a>. "
1359		  "Gigablast is the only "
1360		  "<a href=/privacy.html>truly private search engine</a> "
1361		  "in the United States."
1362		  //" Everyone else has fundamental "
1363		  //"gaps in their "
1364		  //"security as explained by the above link."
1365		  //"Tell Congress "
1366		  //"to <a href=https://optin.stopwatching.us/>stop spying "
1367		  //"on you</a>."
1368		  ,85);
1369	sb.safePrintf("</td></tr>\n");
1370	*/
1371
1372	/*
1373	sb.safePrintf("<tr valign=top>\n");
1374	sb.safePrintf("<td><div style=width:50px;height:50px;display:inline-block;background-color:black;></td>\n");
1375	sb.safePrintf("<td><font size=+1><b>No Tax Dodging</b></font><br>\n");
1376	sb.brify2("Gigablast pays its taxes when it makes a profit. "
1377		  "Google and Bing <a href=http://www.bloomberg.com/news/"
1378		  "2010-10-21/google-2-4-rate-shows-how-60-billion-u-s-"
1379		  "revenue-lost-to-tax-loopholes.html>do not</a>. They "
1380		  "stash their profits in "
1381		  "offshore tax havens to avoid paying taxes. "
1382		  //"The end result is that taxes are higher for you. "
1383		  "You may think Google and Bing are free to use, but in "
1384		  "reality, <u>you</u> pay for it in increased taxes."
1385		  ,85);
1386	sb.safePrintf("</td></tr>\n");
1387	*/
1388
1389
1390	//
1391	// begin new stuff
1392	//
1393	/*
1394	// gradients
1395	sb.safePrintf("<style><!--\n");
1396	
1397	sb.safePrintf(".grad {");
1398	sb.safePrintf("background: rgb(190,201,247);");
1399	sb.safePrintf("background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIxMDAlIiB5Mj0iMTAwJSI+CiAgICA8c3RvcCBvZmZzZXQ9IjAlIiBzdG9wLWNvbG9yPSIjYmVjOWY3IiBzdG9wLW9wYWNpdHk9IjEiLz4KICAgIDxzdG9wIG9mZnNldD0iMTAwJSIgc3RvcC1jb2xvcj0iIzBiM2NlZCIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgPC9saW5lYXJHcmFkaWVudD4KICA8cmVjdCB4PSIwIiB5PSIwIiB3aWR0aD0iMSIgaGVpZ2h0PSIxIiBmaWxsPSJ1cmwoI2dyYWQtdWNnZy1nZW5lcmF0ZWQpIiAvPgo8L3N2Zz4=);");
1400	sb.safePrintf("background: -moz-linear-gradient(-45deg, rgba(190,201,247,1) 0%%, rgba(11,60,237,1) 100%%);");
1401	sb.safePrintf("background: -webkit-gradient(linear, left top, right bottom, color-stop(0%%,rgba(190,201,247,1)), color-stop(100%%,rgba(11,60,237,1)));");
1402	sb.safePrintf("background: -webkit-linear-gradient(-45deg, rgba(190,201,247,1) 0%%,rgba(11,60,237,1) 100%%);");
1403	sb.safePrintf("background: -o-linear-gradient(-45deg, rgba(190,201,247,1) 0%%,rgba(11,60,237,1) 100%%);");
1404	sb.safePrintf("background: -ms-linear-gradient(-45deg, rgba(190,201,247,1) 0%%,rgba(11,60,237,1) 100%%);");
1405	sb.safePrintf("background: linear-gradient(135deg, rgba(190,201,247,1) 0%%,rgba(11,60,237,1) 100%%);");
1406	sb.safePrintf("filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#bec9f7', endColorstr='#0b3ced',GradientType=1 );");
1407	sb.safePrintf("}");
1408	sb.safePrintf("-->");
1409	sb.safePrintf("</style>\n");
1410
1411	sb.safePrintf("<br>");
1412
1413
1414	sb.safePrintf("<div class=grad style=\"border-radius:200px;border-color:blue;border-style:solid;border-width:3px;padding:12px;width:320px;height:320px;display:inline-block;z-index:100;color:black;position:relative;background-color:lightgray;\">");
1415
1416	sb.safePrintf("<br>");
1417	sb.safePrintf("<b>");
1418
1419	sb.safePrintf("<font style=font-size:18px;margin-left:80px;>");
1420	sb.safePrintf("Build Your Own");
1421	sb.safePrintf("</font>");
1422	sb.safePrintf("<br>");
1423	sb.safePrintf("<font style=font-size:18px;margin-left:80px;>");
1424	sb.safePrintf("Search Engine in the");
1425	sb.safePrintf("</font>");
1426	sb.safePrintf("<br>");
1427	sb.safePrintf("<font style=font-size:18px;margin-left:80px;>");
1428	sb.safePrintf("Cloud");
1429	sb.safePrintf("</font>");
1430	sb.safePrintf("</b>");
1431
1432	sb.safePrintf("<br>");
1433	sb.safePrintf("<br>");
1434
1435	sb.safePrintf("<div style=margin-left:20px;width:270px;>");
1436	sb.safePrintf("<a href=/admin/addcoll><img style=float:left;padding-right:15px; height=188px width=101px src=/robot3.png></a>");
1437	//sb.safePrintf("<br>");
1438	sb.safePrintf("<b>STEP 1.</b> <a href=/admin/addcoll?guide=1>"
1439		      "Click here to");
1440	sb.safePrintf("<br>");
1441	sb.safePrintf("<b>name your engine</b></a>.");
1442	sb.safePrintf("<br>");
1443	sb.safePrintf("<br>");
1444	sb.safePrintf("<b>STEP 2.</b> <a href=/admin/settings?guide=1>"
1445		      "Click here to ");
1446	sb.safePrintf("<br>");
1447	sb.safePrintf("<b>add websites to index</b></a>.");
1448	sb.safePrintf("<br>");
1449	sb.safePrintf("<br>");
1450	sb.safePrintf("<b>STEP 3.</b> <a href=/widgets.html?guide=1>"
1451		      "Click here to");
1452	sb.safePrintf("<br>");
1453	sb.safePrintf("<b>insert search box</b></a>.");
1454
1455	sb.safePrintf("</div>");
1456
1457	sb.safePrintf("</div>");
1458	*/
1459
1460	/*
1461
1462	sb.safePrintf("<div class=grad style=\"border-radius:200px;border-color:blue;border-style:solid;border-width:3px;padding:12px;width:280px;height:280px;display:inline-block;z-index:105;color:black;margin-left:-50px;position:absolute;margin-top:50px;background-color:lightgray;\">");
1463
1464	sb.safePrintf("<br>");
1465	sb.safePrintf("<br style=line-height:25px;>");
1466	sb.safePrintf("<b>");
1467	sb.safePrintf("<font style=font-size:18px;margin-left:40px;>");
1468	sb.safePrintf("Web Search Appliance");
1469	sb.safePrintf("</font>");
1470	sb.safePrintf("<br>");
1471	sb.safePrintf("<br>");
1472	sb.safePrintf("<br>");
1473	sb.safePrintf("</b>");
1474
1475
1476	sb.safePrintf("<div style=margin-left:20px;width:270px;>");
1477	sb.safePrintf("<a href=http://www.gigablast.com/appliance.html><img style=float:left;padding-bottom:20px;padding-right:10px; height=81px width=121px src=/computer2.png></a>");
1478
1479
1480	sb.safePrintf("Put the web in your closet. ");
1481	sb.safePrintf("Jump start your efforts with four 1U supermicro servers loaded with the top 2 billion pages from the web. <a href=http://www.gigablast.com/appliance.html>[learn more]</a>");
1482	sb.safePrintf("</font>");
1483
1484	sb.safePrintf("</div>");
1485
1486	sb.safePrintf("</div>");
1487	*/
1488	/*
1489
1490	sb.safePrintf("<div class=grad style=\"border-radius:300px;border-color:blue;border-style:solid;border-width:3px;padding:12px;width:240px;height:240px;display:inline-block;z-index:110;color:black;margin-left:-240px;position:absolute;margin-top:230px;background-color:lightgray;\">");
1491
1492	sb.safePrintf("<br>");
1493	sb.safePrintf("<b>");
1494	sb.safePrintf("<font style=font-size:18px;margin-left:60px;>");
1495	sb.safePrintf("Open Source");
1496	sb.safePrintf("</font>");
1497	sb.safePrintf("<br>");
1498	sb.safePrintf("<br>");
1499	sb.safePrintf("</b>");
1500
1501	sb.safePrintf("<div style=margin-left:30px;margin-right:5px;>");
1502	sb.safePrintf("<a href=http://www.gigablast.com/faq.html#features><img style=float:left;padding-right:10px height=71px width=71px src=/unlocked2.png></a>");
1503
1504	sb.safePrintf("Gigablast is now available as an <a href=https://github.com/gigablast/open-source-search-engine>open source search engine</a> on github.com. Download it today. Finally a robust, scalable search solution in C/C++ that has been in development and used commercially since 2000. <a href=http://www.gigablast.com/faq.html#features>Features</a>.");
1505	sb.safePrintf("</div>");
1506
1507	sb.safePrintf("</div>");
1508
1509	//
1510	// donate with paypal bubble
1511	//
1512
1513	sb.safePrintf("<div class=grad style=\"border-radius:300px;border-color:blue;border-style:solid;border-width:3px;padding:12px;width:180px;height:180px;display:inline-block;z-index:120;color:black;margin-left:10px;position:absolute;margin-top:270px;background-color:lightgray;\">");
1514
1515	sb.safePrintf("<br>");
1516	sb.safePrintf("<b>");
1517	sb.safePrintf("<font style=font-size:18px;margin-left:40px;>");
1518	sb.safePrintf("Contribute");
1519	sb.safePrintf("</font>");
1520	sb.safePrintf("<br>");
1521	sb.safePrintf("<br>");
1522	sb.safePrintf("</b>");
1523
1524	sb.safePrintf("<div style=margin-left:15px;margin-right:5px;>");
1525
1526
1527	sb.safePrintf(
1528
1529		      "Help Gigablast development with PayPal."
1530		      "<br>"
1531		      "<br>"
1532		      // BEGIN PAYPAL DONATE BUTTON
1533		      "<form action=\"https://www.paypal.com/cgi-bin/webscr\" method=\"post\" target=\"_top\">"
1534		      "<input type=\"hidden\" name=\"cmd\" value=\"_donations\">"
1535		      "<input type=\"hidden\" name=\"business\" value=\"2SFSFLUY3KS9Y\">"
1536		      "<input type=\"hidden\" name=\"lc\" value=\"US\">"
1537		      "<input type=\"hidden\" name=\"item_name\" value=\"Gigablast, Inc.\">"
1538		      "<input type=\"hidden\" name=\"currency_code\" value=\"USD\">"
1539		      "<input type=\"hidden\" name=\"bn\" value=\"PP-DonationsBF:btn_donateCC_LG.gif:NonHosted\">"
1540		      "<input type=\"image\" src=\"https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif\" border=\"0\" name=\"submit\" alt=\"PayPal - The safer, easier way to pay online!\" height=47 width=147>"
1541		      "<img alt=\"\" border=\"0\" src=\"https://www.paypalobjects.com/en_US/i/scr/pixel.gif\" width=\"1\" height=\"1\">"
1542		      "</form>"
1543		      // END PAYPAY BUTTON
1544		      "</center></div></center>"
1545		      //"</td>\n"
1546		      );
1547	*/
1548	//
1549	// end new stuff
1550	//
1551
1552
1553	sb.safePrintf("\n");
1554	sb.safePrintf("\n");
1555	//sb.safePrintf("</table>\n");
1556	sb.safePrintf("<br><br>\n");
1557	printNav ( sb , r );
1558	return true;
1559}
1560
1561bool printAddUrlHomePage ( SafeBuf &sb , char *url , HttpRequest *r ) {
1562
1563	CollectionRec *cr = g_collectiondb.getRec ( r );
1564
1565	printFrontPageShell ( &sb , "add url" , cr , true );
1566
1567
1568	sb.safePrintf("<script type=\"text/javascript\">\n"
1569		      "function handler() {\n" 
1570		      "if(this.readyState == 4 ) {\n"
1571		      "document.getElementById('msgbox').innerHTML="
1572		      "this.responseText;\n"
1573		      //"alert(this.status+this.statusText+"
1574		      //"this.responseXML+this.responseText);\n"
1575		      "}}\n"
1576		      "</script>\n");
1577
1578
1579	sb.safePrintf("<br><br>\n");
1580	sb.safePrintf("<br><br><br>\n");
1581	/*
1582	sb.safePrintf("<b>web</b> &nbsp;&nbsp;&nbsp;&nbsp; ");
1583	if ( g_conf.m_isMattWells )
1584		sb.safePrintf("<a href=http://www.gigablast.com/seo>seo</a> "
1585			      "&nbsp;&nbsp;&nbsp;&nbsp; "
1586			      );
1587	sb.safePrintf( "<a href=\"/Top\">directory</a> "
1588		      "&nbsp;&nbsp;&nbsp;&nbsp; \n");
1589	sb.safePrintf("<a href=/adv.html>advanced search</a>");
1590	sb.safePrintf(" &nbsp;&nbsp;&nbsp;&nbsp; ");
1591	sb.safePrintf("<a href=/addurl title=\"Instantly add your url to "
1592		      "Gigablast's index\">add url</a>");
1593	sb.safePrintf("\n");
1594	sb.safePrintf("<br><br>\n");
1595	*/
1596	// submit to https now
1597	sb.safePrintf("<form method=GET "
1598		      "action=/addurl name=f>\n" );
1599
1600	char *coll = "";
1601	if ( cr ) coll = cr->m_coll;
1602	if ( cr )
1603		sb.safePrintf("<input type=hidden name=c value=\"%s\">",
1604			      cr->m_coll);
1605
1606
1607	// put search box in a box
1608	sb.safePrintf("<div style="
1609		      "background-color:#%s;" // fcc714;"
1610		      "border-style:solid;"
1611		      "border-width:3px;"
1612		      "border-color:blue;"
1613		      //"background-color:blue;"
1614		      "padding:20px;"
1615		      "border-radius:20px;"
1616		      ">"
1617		      , GOLD
1618		      );
1619
1620
1621	sb.safePrintf("<input name=urls type=text "
1622		      "style=\""
1623		      //"width:%"INT32"px;"
1624		      "height:26px;"
1625		      "padding:0px;"
1626		      "

Large files files are truncated, but you can click here to view the full file