put thumbnail in proper proportion.

other formatting fixes.
This commit is contained in:
Matt Wells
2014-04-28 14:14:18 -07:00
parent e21e0a404c
commit a2c6527ada
3 changed files with 158 additions and 94 deletions

@ -771,6 +771,110 @@ bool sendPageBasicStatus ( TcpSocket *socket , HttpRequest *hr ) {
// this prints the <form tag as well
g_pages.printAdminTop ( &sb , socket , hr );
// table to split between widget and stats in left and right panes
if ( fmt == FORMAT_HTML ) {
sb.safePrintf("<TABLE>"
"<TR><TD valign=top>");
}
//
// widget
//
// put the widget in here, just sort results by spidered date
//
if ( fmt == FORMAT_HTML ) {
sb.safePrintf(
"<script type=\"text/javascript\">"
"function diffbot_handler() {"
"if(this.readyState != 4 )return;"
"if(!this.responseText)return;"
"document.getElementById(\"diffbot_widget\")."
"innerHTML=this.responseText;"
"diffbot_scroll();}"
"</script>"
"<script type=text/javascript>function "
"diffbot_scroll() {var hd = document."
"getElementById('diffbot_invisible');"
"if ( ! hd ) {setTimeout('diffbot_scroll()',"
"3);return;} var b=parseInt(hd.style.top);"
"var step=4;b=b+step;hd.style.top=b+\"px\";"
"var vd=document.getElementById"
"('diffbot_visible');"
"var c=parseInt(vd.style.top);"
"c=c+step;"
"vd.style.top=c+\"px\";"
"if(b>=0)return;"
"setTimeout('diffbot_scroll()',3);}"
"</script>"
);
long widgetWidth = 300;
long widgetHeight = 500;
// make the ajax url that gets the search results
SafeBuf ub;
ub.safePrintf("/search"
"?format=ajax"
"&c=%s"
"&q=gbrevsortbyint%%3Agbspiderdate"
"&widgetheight=%li"
"&widgetwidth=%li"
"&topdocid="
, cr->m_coll
, widgetHeight
, widgetWidth
);
// then the containing div. set the "id" so that the
// style tag the user sets can control its appearance.
// when the browser loads this the ajax sets the contents
// to the reply from neo.
sb.safePrintf("<div id=diffbot_widget "
"style=\"border:2px solid black;"
"position:relative;border-radius:10px;"
"width:%lipx;height:%lipx;\">"
, widgetWidth
, widgetHeight
);
//sb.safePrintf("<style>"
// "a{color:white;}"
// "</style>");
// get the search results from neo as soon as this div is
// being rendered, and set its contents to them
sb.safePrintf("<script type=text/javascript>function "
"diffbot_reload() {var client="
"new XMLHttpRequest();"
"client.onreadystatechange=diffbot_handler;"
"var u='%s';"
"var td=document.getElementById('topdocid');"
"if ( td ) u=u+td.value;"
"client.open('GET',u);"
"client.send();"
"setTimeout('diffbot_reload()',15000);}"
"diffbot_reload();</script>"
, ub.getBufStart()
);
sb.safePrintf("Waiting for Server...");
// end the containing div
sb.safePrintf("</div>");
}
// the right table pane is the crawl stats
if ( fmt == FORMAT_HTML ) {
sb.safePrintf("</TD><TD valign=top>");
}
//
// show stats
//
@ -862,100 +966,24 @@ bool sendPageBasicStatus ( TcpSocket *socket , HttpRequest *hr ) {
, cr->m_globalCrawlInfo.m_pageDownloadSuccesses
);
char tmp3[64];
struct tm *timeStruct;
timeStruct = localtime((time_t *)&cr->m_diffbotCrawlStartTime);
// Jan 01 1970 at 10:30:00
strftime ( tmp3,64 , "%b %d %Y at %H:%M:%S",timeStruct);
sb.safePrintf("<tr><td><b>Collection Created</b></td>"
"<td>%s</td></tr>",tmp3);
sb.safePrintf("</table>\n\n");
}
// put the widget in here, just sort results by spidered date
// end the right table pane
if ( fmt == FORMAT_HTML ) {
sb.safePrintf("<br>"
"<script type=\"text/javascript\">"
"function diffbot_handler() {"
"if(this.readyState != 4 )return;"
"if(!this.responseText)return;"
"document.getElementById(\"diffbot_widget\")."
"innerHTML=this.responseText;"
"diffbot_scroll();}"
"</script>"
"<script type=text/javascript>function "
"diffbot_scroll() {var hd = document."
"getElementById('diffbot_invisible');"
"if ( ! hd ) {setTimeout('diffbot_scroll()',"
"3);return;} var b=parseInt(hd.style.top);"
"var step=4;b=b+step;hd.style.top=b+\"px\";"
"var vd=document.getElementById"
"('diffbot_visible');"
"var c=parseInt(vd.style.top);"
"c=c+step;"
"vd.style.top=c+\"px\";"
"if(b>=0)return;"
"setTimeout('diffbot_scroll()',3);}"
"</script>"
);
long widgetWidth = 300;
long widgetHeight = 500;
// make the ajax url that gets the search results
SafeBuf ub;
ub.safePrintf("/search"
"?format=ajax"
"&c=%s"
"&q=gbrevsortbyint%%3Agbspiderdate"
"&widgetheight=%li"
"&widgetwidth=%li"
"&topdocid="
, cr->m_coll
, widgetHeight
, widgetWidth
);
// then the containing div. set the "id" so that the
// style tag the user sets can control its appearance.
// when the browser loads this the ajax sets the contents
// to the reply from neo.
sb.safePrintf("<div id=diffbot_widget "
"style=\"border:2px solid black;"
"position:relative;border-radius:10px;"
"width:%lipx;height:%lipx;\">"
, widgetWidth
, widgetHeight
);
//sb.safePrintf("<style>"
// "a{color:white;}"
// "</style>");
// get the search results from neo as soon as this div is
// being rendered, and set its contents to them
sb.safePrintf("<script type=text/javascript>function "
"diffbot_reload() {var client="
"new XMLHttpRequest();"
"client.onreadystatechange=diffbot_handler;"
"var u='%s';"
"var td=document.getElementById('topdocid');"
"if ( td ) u=u+td.value;"
"client.open('GET',u);"
"client.send();"
"setTimeout('diffbot_reload()',15000);}"
"diffbot_reload();</script>"
, ub.getBufStart()
);
sb.safePrintf("Waiting for Server...");
// end the containing div
sb.safePrintf("</div>");
sb.safePrintf("</TD></TR</TABLE>");
}
//if ( fmt != FORMAT_JSON )
// // wrap up the form, print a submit button
// g_pages.printAdminBottom ( &sb );

@ -2585,8 +2585,11 @@ bool printResult ( State0 *st, long ix ) {
( si->m_format == FORMAT_WIDGET_IFRAME ||
si->m_format == FORMAT_WIDGET_AJAX) ) {
long widgetwidth = hr->getLong("widgetwidth",200);
long widgetWidth = hr->getLong("widgetwidth",200);
// prevent coring
if ( widgetWidth < 1 ) widgetWidth = 1;
// make a div around this for widget so we can print text
// on top
sb->safePrintf("<div "
@ -2597,7 +2600,7 @@ bool printResult ( State0 *st, long ix ) {
"padding:%lipx;"
"display:table-cell;"
"vertical-align:bottom;"
, widgetwidth - 2*8 // padding is 8px
, widgetWidth - 2*8 // padding is 8px
, (long)RESULT_HEIGHT
, (long)RESULT_HEIGHT
, (long)PADDING
@ -2611,11 +2614,28 @@ bool printResult ( State0 *st, long ix ) {
if ( mr->ptr_imgData ) {
ThumbnailArray *ta = (ThumbnailArray *)mr->ptr_imgData;
ThumbnailInfo *ti = ta->getThumbnailInfo(0);
// avoid distortion.
// if image is wide, use that to scale
long newdx = 0;
long newdy = 0;
if ( ti->m_dx >= ti->m_dy && ti->m_dx > 0 ) {
newdx=widgetWidth;
newdy=(ti->m_dy * widgetWidth) / ti->m_dx;
}
else if ( ti->m_dy > 0 ) {
newdy=(long)RESULT_HEIGHT;
newdx=(ti->m_dx*(long)RESULT_HEIGHT)/ti->m_dy;
}
sb->safePrintf("background-repeat:no-repeat;"
"background-size:%lipx 140px;"
"background-size:%lipx %lipx;"
"background-image:url('data:image/"
"jpg;base64,"
, widgetwidth - 2*8); // padding is 8px
//, widgetWidth - 2*8);// padding is 8px
, newdx
, newdy
);
// encode image in base 64
if ( ti )
sb->base64Encode (ti->getData(),

@ -116,12 +116,28 @@ bool Title::setTitle ( XmlDoc *xd ,
SafeBuf jsonTitle;
long vlen = 0;
if ( xd->m_contentType == CT_JSON ) {
// shortcut
char *s = xd->ptr_utf8Content;
char *jt;
jt = getJSONFieldValue(xd->ptr_utf8Content,"title",&vlen);
jt = getJSONFieldValue(s,"title",&vlen);
if ( jt && vlen > 0 ) {
jsonTitle.safeDecodeJSONToUtf8 (jt, vlen, m_niceness);
//true ); // decodeAll?
jsonTitle.nullTerm();
}
// if we got a product, try getting price
long oplen;
char *op = getJSONFieldValue(s,"offerPrice",&oplen);
if ( op && oplen ) {
if ( ! is_digit(op[0]) ) { op++; oplen--; }
float price = atof2(op,oplen);
// print without decimal point if ends in .00
if ( (float)(long)price == price )
jsonTitle.safePrintf(", &nbsp; $%li",
(long)price);
else
jsonTitle.safePrintf(", &nbsp; $%.02f",price);
}
if ( jsonTitle.length() ) {
val = jsonTitle.getBufStart();
vlen = jsonTitle.length();
}