Exemplo n.º 1
0
QString tidyHtml(QString str, bool& ok) {
#ifdef NO_TIDY
  ok = true;
  return str;
#else
  QString res = str;
  ok = false;

  static bool isTidyWithIntBodyOnly = isTidyWithIntBodyOnlyCheck();
  
  TidyDoc tdoc = tidyCreate();
  TidyBuffer output;
  TidyBuffer errbuf;

  tidyBufInit(&output);
  tidyBufInit(&errbuf);

  bool configOk = 
    tidyOptSetBool(tdoc, TidyXhtmlOut, yes) && 
    tidyOptSetBool(tdoc, TidyForceOutput, yes) &&
    tidyOptSetBool(tdoc, TidyMark, no) &&
    (isTidyWithIntBodyOnly
     ? tidyOptSetInt(tdoc, TidyBodyOnly, 1)
     : tidyOptSetBool(tdoc, TidyBodyOnly, yes)) &&
    tidyOptSetInt(tdoc, TidyWrapLen, 0) &&
    tidyOptSetInt(tdoc, TidyDoctypeMode, TidyDoctypeOmit);
    
  if (configOk &&
      (tidySetCharEncoding(tdoc, "utf8") >= 0) &&
      (tidySetErrorBuffer(tdoc, &errbuf) >= 0) &&
      (tidyParseString(tdoc, str.toUtf8().data()) >= 0) &&
      (tidyCleanAndRepair(tdoc) >= 0) &&
      (tidyRunDiagnostics(tdoc) >= 0) &&
      (tidySaveBuffer(tdoc, &output) >= 0) &&
      (output.bp != 0 && output.size > 0)) {
    res = QString::fromUtf8((char*)output.bp, output.size);

    ok = true;
  }

#ifdef DEBUG_MARKUP
  if (errbuf.size > 0) {
    QString errStr =  QString::fromUtf8((char*)errbuf.bp, errbuf.size);
    qDebug() << "\n[DEBUG] MARKUP, libtidy errors and warnings:\n" << errStr;
  }
#endif

  if (output.bp != 0)
    tidyBufFree(&output);
  if (errbuf.bp != 0)
    tidyBufFree(&errbuf);
  tidyRelease(tdoc);

  return res.trimmed();
#endif
}
Exemplo n.º 2
0
QVector<QString> UCHome_Main_SiteConst::find_sys_notice(TidyDoc doc)
{
    QVector<QString> sys_notes;
    QString note;
    char *notes_ids[] = { "mtag_invite", "f_request", NULL  };
    char *nid = NULL;
    TidyNode node = NULL;
    TidyNode node2 = NULL;
    TidyBuffer tbuf;

    for(int i = 0; i < 16 ; i++) {
        nid = notes_ids[i];
        if(nid == NULL) {
            break;
        }

        node = this->searchNode(doc, NULL, nid, TidyTag_DIV);
        if(node != NULL) {
            tidyBufInit(&tbuf);

            tidyNodeGetText(doc, node, &tbuf);
            note = this->u8codec->toUnicode(QByteArray((char*)tbuf.bp));
            sys_notes.append(note);

            tidyBufFree(&tbuf);

            q_debug()<<note;
        }else{
            q_debug()<<"Warning: "<<nid<<" not found";
        }
    }

    return sys_notes;
}
Exemplo n.º 3
0
void CCaHtmlParse::__GetPriceAndRamainTicket(UINT *pPrice, UINT *pRemainTicket, const TidyDoc & tdoc, const TidyNode & tdNode)
{
	CStringA straRet;
	*pPrice = 0;
	*pRemainTicket = 0;

	TidyBuffer text = {0};
	tidyBufInit(&text);
	TidyNodeType type = tidyNodeGetType(tdNode);
	tidyNodeGetText(tdoc, tdNode, &text);
	straRet.Format("%s",text.bp);
	straRet.TrimLeft();

	CStringA straKey("</font>");
	int iPos = straRet.Find(straKey);
	int iEndPos = straRet.Find("</strong>");
	int iStartPos = iPos+straKey.GetLength();
	CStringA straPrice = straRet.Mid(iStartPos, iEndPos-iStartPos);
	straPrice.Remove(0x0d);//去掉回车
	straPrice.Remove(0x0a);//去掉换行
	*pPrice = atoi(straPrice.GetBuffer(0));
	straPrice.ReleaseBuffer();

	//剩余座位
	straKey = ":";
	iPos = straRet.Find(straKey);
	iEndPos = straRet.Find("</td>");
	iStartPos = iPos+straKey.GetLength();
	CStringA straRemainSeat = straRet.Mid(iStartPos, iEndPos-iStartPos);
	*pRemainTicket = atoi(straRemainSeat.GetBuffer(0));
	straRemainSeat.ReleaseBuffer();

	tidyBufFree(&text);
}
Exemplo n.º 4
0
static int tidy_doc_cast_handler(zval *in, zval *out, int type)
{
	TidyBuffer output;
	PHPTidyObj *obj;

	switch (type) {
		case IS_LONG:
			ZVAL_LONG(out, 0);
			break;

		case IS_DOUBLE:
			ZVAL_DOUBLE(out, 0);
			break;

		case _IS_BOOL:
			ZVAL_TRUE(out);
			break;

		case IS_STRING:
			obj = Z_TIDY_P(in);
			tidyBufInit(&output);
			tidySaveBuffer (obj->ptdoc->doc, &output);
			ZVAL_STRINGL(out, (char *) output.bp, output.size ? output.size-1 : 0);
			tidyBufFree(&output);
			break;

		default:
			return FAILURE;
	}

	return SUCCESS;
}
Exemplo n.º 5
0
static void tidy_doc_update_properties(PHPTidyObj *obj)
{

	TidyBuffer output;
	zval temp;

	tidyBufInit(&output);
	tidySaveBuffer (obj->ptdoc->doc, &output);

	if (output.size) {
		if (!obj->std.properties) {
			rebuild_object_properties(&obj->std);
		}
		ZVAL_STRINGL(&temp, (char*)output.bp, output.size-1);
		zend_hash_str_update(obj->std.properties, "value", sizeof("value") - 1, &temp);
	}

	tidyBufFree(&output);

	if (obj->ptdoc->errbuf->size) {
		if (!obj->std.properties) {
			rebuild_object_properties(&obj->std);
		}
		ZVAL_STRINGL(&temp, (char*)obj->ptdoc->errbuf->bp, obj->ptdoc->errbuf->size-1);
		zend_hash_str_update(obj->std.properties, "errorBuffer", sizeof("errorBuffer") - 1, &temp);
	}
}
Exemplo n.º 6
0
/* Traverse the document tree */
void dumpNode(TidyDoc doc, TidyNode tnod, int indent )
{
  TidyNode child;
  for ( child = tidyGetChild(tnod); child; child = tidyGetNext(child) )
  {
    ctmbstr name = tidyNodeGetName( child );
    if ( name )
    {
      /* if it has a name, then it's an HTML tag ... */
      TidyAttr attr;
      printf( "%*.*s%s ", indent, indent, "<", name);
      /* walk the attribute list */
      for ( attr=tidyAttrFirst(child); attr; attr=tidyAttrNext(attr) ) {
        printf(tidyAttrName(attr));
        tidyAttrValue(attr)?printf("=\"%s\" ",
                                   tidyAttrValue(attr)):printf(" ");
      }
      printf( ">\n");
    }
    else {
      /* if it doesn't have a name, then it's probably text, cdata, etc... */
      TidyBuffer buf;
      tidyBufInit(&buf);
      tidyNodeGetText(doc, child, &buf);
      printf("%*.*s\n", indent, indent, buf.bp?(char *)buf.bp:"");
      tidyBufFree(&buf);
    }
    dumpNode( doc, child, indent + 4 ); /* recursive */
  }
}
Exemplo n.º 7
0
QString UCHome_Main_SiteConst::find_sys_notice_by_type(TidyDoc doc, char *type_class)
{
    QString note;

    char *nid = type_class;
    TidyNode node = NULL;
    TidyNode node2 = NULL;
    TidyBuffer tbuf;

    if(nid == NULL) {
        q_debug()<<"";
        return note;
    }

    node = this->searchNode(doc, NULL, nid, TidyTag_DIV);
    if(node != NULL) {
        tidyBufInit(&tbuf);

        tidyNodeGetText(doc, node, &tbuf);
        note = this->u8codec->toUnicode(QByteArray((char*)tbuf.bp));

        tidyBufFree(&tbuf);

        q_debug()<<note;
    }else{
        q_debug()<<"Warning: "<<nid<<" not found";
    }

    
    return note;
}
Exemplo n.º 8
0
bool CCFHtmlTidy::TidyMain(const char* pSourceIn, const char* pOptions, std::string &strOut, std::string &strErr)
{
	TidyBuffer output;
	TidyBuffer errbuf;
	int rc = -1;
	Bool ok = yes;

	TidyDoc tdoc = tidyCreate();                     // Initialize "document"
	tidyBufInit(&output);
	tidyBufInit(&errbuf);

	TidyOptionsSet(tidyDocToImpl(tdoc), pOptions);

	if (ok)
		rc = tidySetErrorBuffer(tdoc, &errbuf);      // Capture diagnostics
	if (rc >= 0)
		rc = tidyParseString(tdoc, pSourceIn);           // Parse the input
	if (rc >= 0)
		rc = tidyCleanAndRepair(tdoc);               // Tidy it up!
	if (rc >= 0)
		rc = tidyRunDiagnostics(tdoc);               // Kvetch
	//if ( rc > 1 )                                    // If error, force output.
	//	rc = ( tidyOptSetBool(tdoc, TidyForceOutput, yes) ? rc : -1 );
	if (rc >= 0)
		rc = tidySaveBuffer(tdoc, &output);          // Pretty Print

	if (rc >= 0)
	{
		if (output.bp)
		{
			strOut = reinterpret_cast<char const*>(output.bp);
		}
	}

	strErr = reinterpret_cast<char const*>(errbuf.bp);
	std::string strEmpty = "No warnings or errors were found.\n\n";
	if (0 == strEmpty.compare(strErr))
	{
		strErr.clear();
	}
	tidyBufFree(&output);
	tidyBufFree(&errbuf);
	tidyRelease(tdoc);
	return true;
}
Exemplo n.º 9
0
Arquivo: tdoc.c Projeto: nuxlli/wax
// formats the 'dom' tree into HTML output.
int lua_tidy_saveString(lua_State *L)
{
    pTidy t = toTidy(L,1);
    TidyBuffer output;
    tidyBufInit(&output);
    lua_pushnumber(L, tidySaveBuffer(t->tdoc, &output));
    lua_pushlstring(L, (char*)output.bp, output.size);
    tidyBufFree( &output );
    return 1;        
}
Exemplo n.º 10
0
bool HTidyInterface::formatSource( const char* textIn, CString &strTidy, CString &strMsg )
{
	TidyBuffer output;
	TidyBuffer errbuf;	
	int rc = -1;
	Bool ok = yes;

	TidyDoc tdoc = tidyCreate();                     // Initialize "document"
	tidyBufInit(&output);
	tidyBufInit(&errbuf);

	InitTidyDefault(tdoc);
	SetTidyConfig(tdoc);

	if ( ok )
		rc = tidySetErrorBuffer(tdoc, &errbuf);      // Capture diagnostics
	if ( rc >= 0 )
		rc = tidyParseString(tdoc, textIn);           // Parse the input
	if ( rc >= 0 )
		rc = tidyCleanAndRepair(tdoc);               // Tidy it up!
	if ( rc >= 0 )
		rc = tidyRunDiagnostics(tdoc);               // Kvetch
	//if ( rc > 1 )                                    // If error, force output.
	//	rc = ( tidyOptSetBool(tdoc, TidyForceOutput, yes) ? rc : -1 );
	if ( rc >= 0 )
		rc = tidySaveBuffer(tdoc, &output);          // Pretty Print

	if ( rc >= 0 )
	{		
		strTidy = reinterpret_cast< char const* >(output.bp);
	}

	strMsg = reinterpret_cast< char const* >(errbuf.bp);
	CString strEmpty = _T("No warnings or errors were found.\r\n\r\n");
	if (0 == strEmpty.Compare(strMsg))
	{
		strMsg.Empty();
	}
	tidyBufFree(&output);
	tidyBufFree(&errbuf);
	tidyRelease(tdoc);
	return true;
}
Exemplo n.º 11
0
void CCaHtmlParse::__GetAirPortCode(CStringA & straDCode, CStringA & straACode, const TidyDoc & tdoc, const TidyNode & tdNode)
{
	CStringA straRet;
	CStringA straSha("上海虹桥");
	CStringA straPvg("上海浦东");
	CStringA straPek("北京首都");
	CStringA straNay("北京南苑");

	straDCode = "";
	straACode = "";

	TidyBuffer text = {0};
	tidyBufInit(&text);
	TidyNodeType type = tidyNodeGetType(tdNode);
	tidyNodeGetText(tdoc, tdNode, &text);
	straRet.Format("%s",text.bp);
	straRet.TrimLeft();

	CStringA straKey("<br />");//<br />后有回车换行符
	int iPos = straRet.Find(straKey);
	CStringA straDCity = straRet.Mid(4, iPos-4);
	if (-1 != straDCity.Find(straSha))
		straDCode = "SHA";
	else if (-1 != straDCity.Find(straPvg))
		straDCode = "PVG";
	else if (-1 != straDCity.Find(straPek))
		straDCode = "PEK";
	else if(-1 != straDCity.Find(straNay))
		straDCode = "NAY";
	else
	{

	}

	//取到达机场,<br />后有回车换行符
	straRet = straRet.Mid(iPos+straKey.GetLength());
	straRet.Remove(0x0d);//去掉回车
	straRet.Remove(0x0a);//去掉换行
	int iEndPos = straRet.Find("</td>");
	CStringA straACity = straRet.Left(iEndPos);
	if (-1 != straACity.Find(straSha))
		straACode = "SHA";
	else if (-1 != straACity.Find(straPvg))
		straACode = "PVG";
	else if (-1 != straACity.Find(straPek))
		straACode = "PEK";
	else if(-1 != straACity.Find(straNay))
		straACode = "NAY";
	else
	{

	}

	tidyBufFree(&text);
}
Exemplo n.º 12
0
/* {{{ proto string tidy_get_output()
   Return a string representing the parsed tidy markup */
static PHP_FUNCTION(tidy_get_output)
{
	TidyBuffer output;
	TIDY_FETCH_OBJECT;

	tidyBufInit(&output);
	tidySaveBuffer(obj->ptdoc->doc, &output);
	FIX_BUFFER(&output);
	RETVAL_STRINGL((char *) output.bp, output.size ? output.size-1 : 0);
	tidyBufFree(&output);
}
Exemplo n.º 13
0
static int php_tidy_output_handler(void **nothing, php_output_context *output_context)
{
	int status = FAILURE;
	TidyDoc doc;
	TidyBuffer inbuf, outbuf, errbuf;

	if (TG(clean_output) && (output_context->op & PHP_OUTPUT_HANDLER_START) && (output_context->op & PHP_OUTPUT_HANDLER_FINAL)) {
		doc = tidyCreate();
		tidyBufInit(&errbuf);

		if (0 == tidySetErrorBuffer(doc, &errbuf)) {
			tidyOptSetBool(doc, TidyForceOutput, yes);
			tidyOptSetBool(doc, TidyMark, no);

			if (ZEND_SIZE_T_UINT_OVFL(output_context->in.used)) {
				php_error_docref(NULL, E_WARNING, "Input string is too long");
				return status;
			}

			TIDY_SET_DEFAULT_CONFIG(doc);

			tidyBufInit(&inbuf);
			tidyBufAttach(&inbuf, (byte *) output_context->in.data, (uint)output_context->in.used);

			if (0 <= tidyParseBuffer(doc, &inbuf) && 0 <= tidyCleanAndRepair(doc)) {
				tidyBufInit(&outbuf);
				tidySaveBuffer(doc, &outbuf);
				FIX_BUFFER(&outbuf);
				output_context->out.data = (char *) outbuf.bp;
				output_context->out.used = outbuf.size ? outbuf.size-1 : 0;
				output_context->out.free = 1;
				status = SUCCESS;
			}
		}

		tidyRelease(doc);
		tidyBufFree(&errbuf);
	}

	return status;
}
Exemplo n.º 14
0
int main(int argc, char **argv )
{
  CURL *curl;
  char curl_errbuf[CURL_ERROR_SIZE];
  TidyDoc tdoc;
  TidyBuffer docbuf = {0};
  TidyBuffer tidy_errbuf = {0};
  int err;
  if ( argc == 2) {
    curl = curl_easy_init();
    curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
    curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_errbuf);
    curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_cb);

    tdoc = tidyCreate();
    tidyOptSetBool(tdoc, TidyForceOutput, yes); /* try harder */
    tidyOptSetInt(tdoc, TidyWrapLen, 4096);
    tidySetErrorBuffer( tdoc, &tidy_errbuf );
    tidyBufInit(&docbuf);

    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &docbuf);
    err=curl_easy_perform(curl);
    if ( !err ) {
      err = tidyParseBuffer(tdoc, &docbuf); /* parse the input */
      if ( err >= 0 ) {
        err = tidyCleanAndRepair(tdoc); /* fix any problems */
        if ( err >= 0 ) {
          err = tidyRunDiagnostics(tdoc); /* load tidy error buffer */
          if ( err >= 0 ) {
            dumpNode( tdoc, tidyGetRoot(tdoc), 0 ); /* walk the tree */
            fprintf(stderr, "%s\n", tidy_errbuf.bp); /* show errors */
          }
        }
      }
    }
    else
      fprintf(stderr, "%s\n", curl_errbuf);

    /* clean-up */
    curl_easy_cleanup(curl);
    tidyBufFree(&docbuf);
    tidyBufFree(&tidy_errbuf);
    tidyRelease(tdoc);
    return(err);

  }
  else
    printf( "usage: %s <url>\n", argv[0] );

  return(0);
}
Exemplo n.º 15
0
Arquivo: tdoc.c Projeto: nuxlli/wax
// quick and dirty shortcut function.
int lua_tidy_easyClean ( lua_State *L )
{
    TidyBuffer output;
    TidyBuffer errbuf;
    int rc;
	pTidy t;
	const char * input;

    tidyBufInit(&output);
    tidyBufInit(&errbuf);
    
    rc = -1;
    
    t = toTidy(L,1);
    input = lua_tostring(L,2);
    
    rc = tidySetErrorBuffer( t->tdoc, &errbuf );
    if ( rc >= 0 )
        rc = tidyParseString( t->tdoc, input );
    if ( rc >= 0 )
        rc = tidyCleanAndRepair( t->tdoc );
    if ( rc >= 0 )
        rc = tidyRunDiagnostics( t->tdoc );
    if ( rc >= 0 )
        rc = tidySaveBuffer( t->tdoc, &output );    
    
    lua_pushlstring(L, (char*)output.bp,output.size);
    if ( rc != 0  )
        lua_pushlstring(L, (char*)errbuf.bp,errbuf.size);
    else
        lua_pushnil(L);
    
    lua_pushnumber(L, rc);
    
    tidyBufFree( &output );
    tidyBufFree( &errbuf );
    
    
    return 3;
}
Exemplo n.º 16
0
char *copyTidyNodeValue(TidyNode tnode, TidyDoc tdoc)
{
    TidyBuffer buf;
    tidyBufInit(&buf);
    tidyNodeGetValue(tdoc,tnode,&buf);

    char *str = (char *)xmalloc(buf.size+1);
    memcpy(str,buf.bp,buf.size);
    str[buf.size] = '\0';

    tidyBufFree(&buf);
    return str;
}
Exemplo n.º 17
0
FeedRecord* UCHome_Main_SiteConst::parse_note(void *state_data, TidyDoc doc, TidyNode node)
{
    FeedRecord * rec = NULL;
    QString note;
    TidyBuffer tbuf;
    
    tidyBufInit(&tbuf);

    tidyNodeGetText(doc, node, &tbuf);
    note = this->u8codec->toUnicode(QByteArray((char*)tbuf.bp));    
    rec = new FeedRecord();
    rec->content = this->rewrite_relative_link(note);
    md5CheckSum((char*)tbuf.bp, tbuf.size, rec->md5sum);
    tidyBufFree(&tbuf);    
    //q_debug()<<"Orig:"<<note;
    
    return rec;
}
Exemplo n.º 18
0
void CCaHtmlParse::__GetFlightStartTime(CStringA & strFlightStartTime, const TidyDoc & tdoc, const TidyNode & tdNode)
{
	CStringA straRet;
	strFlightStartTime = "";

	TidyBuffer text = {0};
	tidyBufInit(&text);
	TidyNodeType type = tidyNodeGetType(tdNode);
	tidyNodeGetText(tdoc, tdNode, &text);
	straRet.Format("%s",text.bp);

	CStringA straKey("\">");
	int iStartPos = straRet.Find(straKey);
	int iEndPos = straRet.Find("</strong>");
	iStartPos = iStartPos+straKey.GetLength();
	strFlightStartTime = straRet.Mid(iStartPos, iEndPos-iStartPos);

	tidyBufFree(&text);
}
Exemplo n.º 19
0
FeedRecord* UCHome_Main_SiteConst::parse_friend(void *state_data, TidyDoc doc, TidyNode node) 
{
    FeedRecord * rec = NULL;
    QString note;
    TidyBuffer tbuf;
    TidyNode node2 = NULL;
    TidyNode node3 = NULL;
    TidyNode node4 = NULL;
    TidyNode node5 = NULL;
    TidyAttr attr = NULL;
    ctmbstr fuid = NULL;
    ctmbstr fusername = NULL;

    tidyBufInit(&tbuf);

    tidyNodeGetText(doc, node, &tbuf);
    note = this->u8codec->toUnicode(QByteArray((char*)tbuf.bp));    
    rec = new FeedRecord();
    rec->content = this->rewrite_relative_link(note);
    rec->content = "<table>" + rec->content + "</table>";
    md5CheckSum((char*)tbuf.bp, tbuf.size, rec->md5sum);
    tidyBufFree(&tbuf);    
    //q_debug()<<"Orig:"<<note;

    node2 = tidyGetChild(node);
    node3 = tidyGetChild(node2);
    attr = tidyAttrGetById(node3, TidyAttr_VALUE);
    fuid = tidyAttrValue(attr);
    
    node4 = tidyGetNext(node2);
    node3 = tidyGetChild(node4); // A
    node5 = tidyGetChild(node3); //IMG
    attr = tidyAttrGetById(node5, TidyAttr_ALT);
    fusername = tidyAttrValue(attr);

    rec->fuid = fuid;
    rec->fusername = this->u8codec->toUnicode(QByteArray(fusername));
    q_debug()<<"USER:"<<fuid<<rec->fusername;
    md5CheckSum(fuid, strlen(fuid), rec->md5sum);//使用uid的md5值肯定不会出现冲突
    
    return rec;
}
Exemplo n.º 20
0
static zend_object *tidy_object_new(zend_class_entry *class_type, zend_object_handlers *handlers, tidy_obj_type objtype)
{
	PHPTidyObj *intern;

	intern = ecalloc(1, sizeof(PHPTidyObj) + zend_object_properties_size(class_type));
	zend_object_std_init(&intern->std, class_type);
	object_properties_init(&intern->std, class_type);

	switch(objtype) {
		case is_node:
			break;

		case is_doc:
			intern->ptdoc = emalloc(sizeof(PHPTidyDoc));
			intern->ptdoc->doc = tidyCreate();
			intern->ptdoc->ref_count = 1;
			intern->ptdoc->initialized = 0;
			intern->ptdoc->errbuf = emalloc(sizeof(TidyBuffer));
			tidyBufInit(intern->ptdoc->errbuf);

			if (tidySetErrorBuffer(intern->ptdoc->doc, intern->ptdoc->errbuf) != 0) {
				tidyBufFree(intern->ptdoc->errbuf);
				efree(intern->ptdoc->errbuf);
				tidyRelease(intern->ptdoc->doc);
				efree(intern->ptdoc);
				efree(intern);
				php_error_docref(NULL, E_ERROR, "Could not set Tidy error buffer");
			}

			tidyOptSetBool(intern->ptdoc->doc, TidyForceOutput, yes);
			tidyOptSetBool(intern->ptdoc->doc, TidyMark, no);

			TIDY_SET_DEFAULT_CONFIG(intern->ptdoc->doc);

			tidy_add_default_properties(intern, is_doc);
			break;
	}

	intern->std.handlers = handlers;

	return &intern->std;
}
Exemplo n.º 21
0
void CCaHtmlParse::__GetSaleEndDate(CStringA & straEndDate, CStringA & straEndTime, const TidyDoc & tdoc, const TidyNode & tdNode)
{
	CStringA straRet;
	straEndDate = "";
	straEndTime = "";

	TidyBuffer text = {0};
	tidyBufInit(&text);
	TidyNodeType type = tidyNodeGetType(tdNode);
	tidyNodeGetText(tdoc, tdNode, &text);
	straRet.Format("%s",text.bp);
	straRet.TrimLeft();

	int iPos = straRet.Find("<br");
	straRet = straRet.Mid(4, iPos-4);
	straEndDate = straRet.Left(10);
	straEndTime = straRet.Mid(11);
	straEndTime.Trim();

	tidyBufFree(&text);
}
Exemplo n.º 22
0
FeedRecord* UCHome_Main_SiteConst::parse_feed(void *state_data, TidyDoc doc, TidyNode node)
{
    FeedRecord *rec = NULL;
    QString feed_text ;
    QByteArray feed_bytes;
    int nid = 0;
    ctmbstr  fid = NULL;
    TidyAttr attr = NULL;
    TidyBuffer tbuf = {0};
    tidyBufInit(&tbuf);
    
    nid = tidyNodeGetId(node);    
    this->get_node_text(doc, node, &tbuf);
    feed_bytes = QByteArray((char*)tbuf.bp);
    feed_text = this->u8codec->toUnicode(feed_bytes);

    tidyBufFree(&tbuf);

    rec = new FeedRecord();
    rec->content = feed_text;

    //<li class="type_1006780" id="feed_685697_li">
    //这个id是唯一的,用这个做标识
    attr = tidyAttrGetById(node, TidyAttr_ID);
    fid = tidyAttrValue(attr);
    //q_debug()<<attr<<fid;
    if(fid == NULL) {
        q_debug()<<"Warning: invalid fid"<<fid<<feed_text;
        return NULL;
    }else if(strstr(fid, " 1000 ") != NULL) {
        feed_bytes = fid;
        feed_bytes = feed_bytes.replace(" 1000 ", "");
        fid = feed_bytes.data();
        q_debug()<<"Warning: invalid fid"<<tidyAttrValue(attr);
        md5CheckSum(fid, strlen(fid), rec->md5sum);
    }else{
        md5CheckSum(fid, strlen(fid), rec->md5sum);
    }
    return rec;
}
Exemplo n.º 23
0
void nuiHTMLNode::SetFromNode(const void* _tdoc, const void* _tnod, nglTextEncoding encoding, bool ComputeStyle)
{
  Clear();
  
  TidyDoc tdoc = (TidyDoc)_tdoc;
  TidyNode tnod = (TidyNode)_tnod;

  mName = nglString(tidyNodeGetName(tnod), encoding);
  mType = (NodeType)tidyNodeGetType(tnod);
  mTagType = (TagType)tidyNodeGetId(tnod);
  
  nglString text;
  TidyBuffer buf;
  tidyBufInit(&buf);
  if (tidyNodeGetValue(tdoc, tnod, &buf))
  {
    mText.Import((const char*)buf.bp, (int32)buf.size, encoding);
    //NGL_OUT(_T("<%s> %s\n"), mName.GetChars(), mText.GetChars());
  }
  tidyBufFree(&buf);
  
  // Fill the attributes:
  TidyAttr tattr;
  for (tattr = tidyAttrFirst(tnod); tattr; tattr = tidyAttrNext(tattr))
  {
    nuiHTMLAttrib* pAttrib = new nuiHTMLAttrib(tattr, encoding);
    mAttributes.push_back(pAttrib);
  }
  
  if (ComputeStyle)
  {
    mpStyle = new nuiCSSStyle(this);
    nuiHTMLAttrib* pStyle = GetAttribute(nuiHTMLAttrib::eAttrib_STYLE);
    if (pStyle)
    {
      AddStyleSheet(GetSourceURL(), pStyle->GetValue(), true);
    }
  }
}
Exemplo n.º 24
0
void CCaHtmlParse::__GetFlightNoAndFlightStartDate(CStringA & strFlightNo, CStringA & strFlightStartDate, const TidyDoc & tdoc, const TidyNode & tdNode)
{
	CStringA straRet;
	strFlightNo = "";
	strFlightStartDate = "";

	TidyBuffer text = {0};
	tidyBufInit(&text);
	TidyNodeType type = tidyNodeGetType(tdNode);
	tidyNodeGetText(tdoc, tdNode, &text);
	straRet.Format("%s",text.bp);
	straRet.TrimLeft();
	strFlightStartDate = straRet.Mid(4, 10);
	int iStartPos = straRet.Find('C');//匹配CA,ca,Ca,cA,<br />后会插入回车换行符,
	if(-1 == iStartPos)//没找到大写C,匹配小写c
		iStartPos = straRet.Find('c');
	int iEndPos = straRet.Find("</");
	strFlightNo = straRet.Mid(iStartPos, iEndPos-iStartPos);//国航航班号有3位的,还有4位的
	strFlightNo = strFlightNo.MakeUpper();
	strFlightNo = strFlightNo.Mid(2);//去掉CA

	tidyBufFree(&text);
}
Exemplo n.º 25
0
static int php_tidy_parse_string(PHPTidyObj *obj, char *string, uint len, char *enc)
{
	TidyBuffer buf;

	if(enc) {
		if (tidySetCharEncoding(obj->ptdoc->doc, enc) < 0) {
			php_error_docref(NULL, E_WARNING, "Could not set encoding '%s'", enc);
			return FAILURE;
		}
	}

	obj->ptdoc->initialized = 1;

	tidyBufInit(&buf);
	tidyBufAttach(&buf, (byte *) string, len);
	if (tidyParseBuffer(obj->ptdoc->doc, &buf) < 0) {
		php_error_docref(NULL, E_WARNING, "%s", obj->ptdoc->errbuf->bp);
		return FAILURE;
	}
	tidy_doc_update_properties(obj);

	return SUCCESS;
}
Exemplo n.º 26
0
QString UCHome_Main_SiteConst::get_time_string(TidyDoc doc, TidyNode tnode)
{
    QString time_string ;

    TidyBuffer tbuf = {0};
    tidyBufInit(&tbuf);
    tidyNodeGetText(doc, tnode, &tbuf);
    if(strstr((char*)tbuf.bp, "2008-") != NULL) {                
        QDate onlyDate = QDate::fromString(QString((char*)tbuf.bp).trimmed(), "yyyy-MM-dd");
        QDateTime currDate = QDateTime::currentDateTime();
        currDate.setDate(onlyDate);
        //q_debug()<<currDate<<onlyDate<<((char*)tbuf.bp);
        time_string = onlyDate.toString();
    }else{
        //must yesterday
        QDateTime currDate = QDateTime::currentDateTime().addDays(-1);
        time_string = currDate.date().toString();
    }
    tidyBufFree(&tbuf);


    return time_string;
}
Exemplo n.º 27
0
static int tidy_node_cast_handler(zval *in, zval *out, int type)
{
	TidyBuffer buf;
	PHPTidyObj *obj;

	switch(type) {
		case IS_LONG:
			ZVAL_LONG(out, 0);
			break;

		case IS_DOUBLE:
			ZVAL_DOUBLE(out, 0);
			break;

		case _IS_BOOL:
			ZVAL_TRUE(out);
			break;

		case IS_STRING:
			obj = Z_TIDY_P(in);
			tidyBufInit(&buf);
			if (obj->ptdoc) {
				tidyNodeGetText(obj->ptdoc->doc, obj->node, &buf);
				ZVAL_STRINGL(out, (char *) buf.bp, buf.size-1);
			} else {
				ZVAL_EMPTY_STRING(out);
			}
			tidyBufFree(&buf);
			break;

		default:
			return FAILURE;
	}

	return SUCCESS;
}
Exemplo n.º 28
0
QString UCHome_Main_SiteConst::find_sign_text(TidyDoc doc)
{
    QString sign_text;
    TidyNode node;
    TidyNode node2;
    TidyBuffer tbuf;
    
    node = this->searchNode(doc, NULL, "state", TidyTag_DIV);
    if(node != NULL) {
        node2 = tidyGetChild(node);
        Q_ASSERT(tidyNodeGetId(node2) == TidyTag_A);
        tidyBufInit(&tbuf);
        if(tidyNodeGetText(doc, tidyGetChild(node2), &tbuf)) {
            sign_text = this->u8codec->toUnicode(QByteArray((char*)tbuf.bp));
            sign_text = sign_text.trimmed();
            q_debug()<<"Sign text:"<<sign_text;
        }
        tidyBufFree(&tbuf);
    }else{
        q_debug()<<"Warning: no state sign text found";
    }

    return sign_text;
}
Exemplo n.º 29
0
static void tidy_add_default_properties(PHPTidyObj *obj, tidy_obj_type type)
{

	TidyBuffer buf;
	TidyAttr	tempattr;
	TidyNode	tempnode;
	zval attribute, children, temp;
	PHPTidyObj *newobj;

	switch(type) {

		case is_node:
			if (!obj->std.properties) {
				rebuild_object_properties(&obj->std);
			}
			tidyBufInit(&buf);
			tidyNodeGetText(obj->ptdoc->doc, obj->node, &buf);
			ADD_PROPERTY_STRINGL(obj->std.properties, value, buf.bp, buf.size ? buf.size-1 : 0);
			tidyBufFree(&buf);

			ADD_PROPERTY_STRING(obj->std.properties, name, tidyNodeGetName(obj->node));
			ADD_PROPERTY_LONG(obj->std.properties, type, tidyNodeGetType(obj->node));
			ADD_PROPERTY_LONG(obj->std.properties, line, tidyNodeLine(obj->node));
			ADD_PROPERTY_LONG(obj->std.properties, column, tidyNodeColumn(obj->node));
			ADD_PROPERTY_BOOL(obj->std.properties, proprietary, tidyNodeIsProp(obj->ptdoc->doc, obj->node));

			switch(tidyNodeGetType(obj->node)) {
				case TidyNode_Root:
				case TidyNode_DocType:
				case TidyNode_Text:
				case TidyNode_Comment:
					break;

				default:
					ADD_PROPERTY_LONG(obj->std.properties, id, tidyNodeGetId(obj->node));
			}

			tempattr = tidyAttrFirst(obj->node);

			if (tempattr) {
				char *name, *val;
				array_init(&attribute);

				do {
					name = (char *)tidyAttrName(tempattr);
					val = (char *)tidyAttrValue(tempattr);
					if (name && val) {
						add_assoc_string(&attribute, name, val);
					}
				} while((tempattr = tidyAttrNext(tempattr)));
			} else {
				ZVAL_NULL(&attribute);
			}
			zend_hash_str_update(obj->std.properties, "attribute", sizeof("attribute") - 1, &attribute);

			tempnode = tidyGetChild(obj->node);

			if (tempnode) {
				array_init(&children);
				do {
					tidy_instanciate(tidy_ce_node, &temp);
					newobj = Z_TIDY_P(&temp);
					newobj->node = tempnode;
					newobj->type = is_node;
					newobj->ptdoc = obj->ptdoc;
					newobj->ptdoc->ref_count++;

					tidy_add_default_properties(newobj, is_node);
					add_next_index_zval(&children, &temp);

				} while((tempnode = tidyGetNext(tempnode)));

			} else {
				ZVAL_NULL(&children);
			}

			zend_hash_str_update(obj->std.properties, "child", sizeof("child") - 1, &children);

			break;

		case is_doc:
			if (!obj->std.properties) {
				rebuild_object_properties(&obj->std);
			}
			ADD_PROPERTY_NULL(obj->std.properties, errorBuffer);
			ADD_PROPERTY_NULL(obj->std.properties, value);
			break;
	}
}
Exemplo n.º 30
0
static void php_tidy_quick_repair(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_file)
{
	char *enc = NULL;
	size_t enc_len = 0;
	zend_bool use_include_path = 0;
	TidyDoc doc;
	TidyBuffer *errbuf;
	zend_string *data, *arg1;
	zval *config = NULL;

	if (is_file) {
		if (zend_parse_parameters(ZEND_NUM_ARGS(), "P|zsb", &arg1, &config, &enc, &enc_len, &use_include_path) == FAILURE) {
			RETURN_FALSE;
		}
		if (!(data = php_tidy_file_to_mem(ZSTR_VAL(arg1), use_include_path))) {
			RETURN_FALSE;
		}
	} else {
		if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|zsb", &arg1, &config, &enc, &enc_len, &use_include_path) == FAILURE) {
			RETURN_FALSE;
		}
		data = arg1;
	}

	if (ZEND_SIZE_T_UINT_OVFL(ZSTR_LEN(data))) {
		php_error_docref(NULL, E_WARNING, "Input string is too long");
		RETURN_FALSE;
	}

	doc = tidyCreate();
	errbuf = emalloc(sizeof(TidyBuffer));
	tidyBufInit(errbuf);

	if (tidySetErrorBuffer(doc, errbuf) != 0) {
		tidyBufFree(errbuf);
		efree(errbuf);
		tidyRelease(doc);
		php_error_docref(NULL, E_ERROR, "Could not set Tidy error buffer");
	}

	tidyOptSetBool(doc, TidyForceOutput, yes);
	tidyOptSetBool(doc, TidyMark, no);

	TIDY_SET_DEFAULT_CONFIG(doc);

	if (config) {
		TIDY_APPLY_CONFIG_ZVAL(doc, config);
	}

	if(enc_len) {
		if (tidySetCharEncoding(doc, enc) < 0) {
			php_error_docref(NULL, E_WARNING, "Could not set encoding '%s'", enc);
			RETVAL_FALSE;
		}
	}

	if (data) {
		TidyBuffer buf;

		tidyBufInit(&buf);
		tidyBufAttach(&buf, (byte *) ZSTR_VAL(data), (uint)ZSTR_LEN(data));

		if (tidyParseBuffer(doc, &buf) < 0) {
			php_error_docref(NULL, E_WARNING, "%s", errbuf->bp);
			RETVAL_FALSE;
		} else {
			if (tidyCleanAndRepair(doc) >= 0) {
				TidyBuffer output;
				tidyBufInit(&output);

				tidySaveBuffer (doc, &output);
				FIX_BUFFER(&output);
				RETVAL_STRINGL((char *) output.bp, output.size ? output.size-1 : 0);
				tidyBufFree(&output);
			} else {
				RETVAL_FALSE;
			}
		}
	}

	if (is_file) {
		zend_string_release(data);
	}

	tidyBufFree(errbuf);
	efree(errbuf);
	tidyRelease(doc);
}