Beispiel #1
0
bool CzAds::ExtractLinkAndImageFromtHTML(CzAd& ad, CzString& html)
{
	int pos, offset;

	// Check to see if the html has a clickable link
	html.FindReset();
	pos = html.FindNext("href=");
	if (pos > 0)
	{
		// Get the click link
		int idx = html.getFindIndex();
		int len = html.GetNextMarkedString('"', '"', offset);
		if (len < 0)
		{
			html.setFindIndex(idx);
			len = html.GetNextMarkedString('\'', '\'', offset);
		}
		if (len > 0)
		{
			ad.LinkURI.setString(html.getString() + offset, len);
#if defined(_DEBUG)
			CzDebug::Log(CZ_DEBUG_CHANNEL_INFO, "Ad Link URL: ", ad.LinkURI.c_str());
#endif	// _DEBUG
		
			// Check to see if the html has an image available
			pos = html.FindNext("img ");
			if (pos > 0)
			{
				// Grab the image url
				pos = html.FindNext("src=");
				if (pos > 0)
				{
					idx = html.getFindIndex();
					len = html.GetNextMarkedString('"', '"', offset);
					if (len < 0)
					{
						html.setFindIndex(idx);
						len = html.GetNextMarkedString('\'', '\'', offset);
					}
					if (len > 0)
					{
						ad.ImageURI.setString(html.getString() + offset, len);
#if defined(_DEBUG)
						CzDebug::Log(CZ_DEBUG_CHANNEL_INFO, "Ad Image URL: ", ad.ImageURI.c_str());
#endif	// _DEBUG
						return true;
					}
				}
			}
		}
	}

	return false;
}