void PlainHtmlExport::WriteMessage(bool isMe, const std::wstring &longDate, const std::wstring &shortDate, const std::wstring &user, const std::wstring &message, const DBEVENTINFO& dbei) { TCHAR *id = isMe ? _T("out") : _T("inc"); TCHAR* ev = (isMe ? _T("1") : _T("0")); bool isUrl = false; std::wstring& mes = UrlHighlightHtml(MakeTextHtmled(message), isUrl); if(isUrl) ev = _T("2"); EXP_FILE << _T("<div class=mes id=event") << ev << _T(">\n"); EXP_FILE << _T("<div class=nick id=") << id << _T(">") << MakeTextHtmled(user) << _T(":</div>\n"); EXP_FILE << _T("<div class=date id=") << id << _T(">") << (Options::instance->exportHtml1ShowDate ? longDate : shortDate) << _T("</div>\n"); EXP_FILE << _T("<div class=text>\n"); EXP_FILE << mes; EXP_FILE << _T("\n</div>\n"); EXP_FILE << _T("</div>\n"); }
std::wstring RichHtmlExport::ReplaceSmileys(bool isMe, const std::wstring &msg, bool &isUrl) { if (!Options::instance->exportHtml2UseSmileys || !g_SmileyAddAvail) return UrlHighlightHtml(MakeTextHtmled(msg), isUrl); wchar_t* msgbuf = new wchar_t[msg.length() + 1]; memcpy_s(msgbuf, (msg.length() + 1) * sizeof(wchar_t), msg.c_str(), (msg.length() + 1) * sizeof(wchar_t)); SMADD_BATCHPARSE2 sp = { 0 }; SMADD_BATCHPARSERES *spr; sp.cbSize = sizeof(sp); sp.Protocolname = baseProto.length() == 0 ? nullptr : baseProto.c_str(); sp.str = msgbuf; sp.flag = SAFL_TCHAR | SAFL_PATH | (isMe ? SAFL_OUTGOING : 0); spr = (SMADD_BATCHPARSERES*)CallService(MS_SMILEYADD_BATCHPARSE, 0, (LPARAM)&sp); delete[] msgbuf; // Did not find a simley if (spr == nullptr || (INT_PTR)spr == CALLSERVICE_NOTFOUND) return UrlHighlightHtml(MakeTextHtmled(msg), isUrl); std::queue<std::pair<size_t, size_t> > positionMap; std::wstring newMsg = MakeTextHtmled(msg, &positionMap); std::wstring smileyMsg; size_t last_pos = 0; std::pair<size_t, size_t> pos(0, 0); size_t currentAdd = 0; if (!positionMap.empty()) { pos = positionMap.front(); positionMap.pop(); } for (unsigned i = 0; i < sp.numSmileys; ++i) { size_t startChar = spr[i].startChar + currentAdd; while (startChar >= pos.first && pos.second) { startChar += pos.second; currentAdd += pos.second; if (!positionMap.empty()) { pos = positionMap.front(); positionMap.pop(); } else pos = std::pair<size_t, size_t>(0, 0); } size_t endChar = spr[i].startChar + spr[i].size + currentAdd; while (endChar >= pos.first && pos.second) { endChar += pos.second; currentAdd += pos.second; if (!positionMap.empty()) { pos = positionMap.front(); positionMap.pop(); } else pos = std::pair<size_t, size_t>(0, 0); } size_t size = endChar - startChar; if (spr[i].filepath != nullptr) { // For deffective smileypacks // Add text if (startChar - last_pos > 0) { smileyMsg += newMsg.substr(last_pos, startChar - last_pos); } std::wstring smileyName = GetName(spr[i].filepath); if (smileys.find(smileyName) == smileys.end()) { smileys.insert(smileyName); CopyFile(spr[i].filepath, (folder + L"\\" + smileyName).c_str(), FALSE); } std::wstring smileyText = newMsg.substr(startChar, size); smileyMsg += L"<img class=smiley src=\""; smileyMsg += folderName; smileyMsg += L"\\"; smileyMsg += smileyName; smileyMsg += L"\" alt=\""; smileyMsg += smileyText; smileyMsg += L"\"/>"; } // Get next last_pos = endChar; } // Add rest of text if (last_pos < newMsg.length()) smileyMsg += newMsg.substr(last_pos); CallService(MS_SMILEYADD_BATCHFREE, 0, (LPARAM)spr); return UrlHighlightHtml(smileyMsg, isUrl); }