changed: plugin 'export'
rewritten changing of strings in html output (added support for https:// prefix) git-svn-id: svn://ttmath.org/publicrep/winix/trunk@779 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
parent
93273bd470
commit
dce68221ad
|
@ -42,6 +42,9 @@ void ExportThread::SetUTF8(bool use_utf8)
|
|||
|
||||
void ExportThread::SetBaseUrl(const std::wstring & url)
|
||||
{
|
||||
// SetBaseUrl() is called before the this thread
|
||||
// is started so we can use 'base_url' later without locking
|
||||
// the same is for 'utf8'
|
||||
base_url = url;
|
||||
}
|
||||
|
||||
|
@ -259,6 +262,7 @@ bool ExportThread::Put()
|
|||
{
|
||||
FILE * file = 0;
|
||||
|
||||
|
||||
if( message_work.type == WINIX_PL_EXPORT_TYPE_CREATE_FILE_STATIC )
|
||||
{
|
||||
Convert(message_work.url, local_path);
|
||||
|
@ -372,101 +376,8 @@ return i;
|
|||
}
|
||||
|
||||
|
||||
void ExportThread::CreateBaseUrl(std::string & buf)
|
||||
{
|
||||
buf = "http://";
|
||||
Convert(base_url, buf, false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ExportThread::ChangeAdresses(std::string & buf)
|
||||
{
|
||||
// !! mozna lock skasowac jesli loger nie bedzie uzywany
|
||||
Lock();
|
||||
|
||||
ChangeAdressesThumb(buf);
|
||||
|
||||
CreateBaseUrl(look_for_url);
|
||||
look_for_url += "/static";
|
||||
Convert(message_work.src_dir, look_for_url, false);
|
||||
Convert(message_work.http_server, repl_url);
|
||||
repl_url += "/static/";
|
||||
log << log1 << "zamiana: |" << look_for_url << "|, na: |" << repl_url << "|" << logend << logsave;
|
||||
ReplaceString(buf, look_for_url, repl_url);
|
||||
|
||||
/*
|
||||
CreateBaseUrl(look_for_url);
|
||||
look_for_url += "/common/";
|
||||
Convert(message_work.http_server, repl_url);
|
||||
repl_url += "/common/";
|
||||
log << log1 << "zamiana: |" << look_for_url << "|, na: |" << repl_url << "|" << logend << logsave;
|
||||
ReplaceString(buf, look_for_url, repl_url);
|
||||
*/
|
||||
|
||||
CreateBaseUrl(look_for_url);
|
||||
Convert(message_work.src_dir, look_for_url, false);
|
||||
Convert(message_work.http_server, repl_url);
|
||||
repl_url += "/";
|
||||
log << log1 << "zamiana: |" << look_for_url << "|, na: |" << repl_url << "|" << logend << logsave;
|
||||
ReplaceString(buf, look_for_url, repl_url);
|
||||
|
||||
NoLastSlash(look_for_url);
|
||||
Convert(message_work.http_server, repl_url);
|
||||
look_for_url += '\"';
|
||||
repl_url += '\"';
|
||||
log << log1 << "zamiana: |" << look_for_url << "|, na: |" << repl_url << "|" << logend << logsave;
|
||||
ReplaceString(buf, look_for_url, repl_url);
|
||||
|
||||
|
||||
Convert(message_work.src_dir, look_for_url);
|
||||
repl_url = '/';
|
||||
log << log1 << "zamiana: |" << look_for_url << "|, na: |" << repl_url << "|" << logend << logsave;
|
||||
ReplaceString(buf, look_for_url, repl_url);
|
||||
|
||||
NoLastSlash(look_for_url);
|
||||
look_for_url += '\"';
|
||||
repl_url = "/\"";
|
||||
log << log1 << "zamiana: |" << look_for_url << "|, na: |" << repl_url << "|" << logend << logsave;
|
||||
ReplaceString(buf, look_for_url, repl_url);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Unlock();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void ExportThread::ChangeAdressesThumb(std::string & buf)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
CreateBaseUrl(look_for_url);
|
||||
Convert(message_work.src_dir, look_for_url, false);
|
||||
|
||||
for(i=0 ; i<buf.size() ; ++i)
|
||||
{
|
||||
if( IsSubStringp(look_for_url.c_str(), &buf[i]) )
|
||||
{
|
||||
i += look_for_url.size() - 1; // without skipping the last slash
|
||||
|
||||
if( HasThumbInAdress(buf, i) )
|
||||
{
|
||||
if( i <= buf.size() )
|
||||
buf.insert(i, "/download"); //!! do konfiga
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// second thread
|
||||
// objects locked
|
||||
bool ExportThread::HasThumbInAdress(std::string & buf, size_t i)
|
||||
{
|
||||
const char * thumb1 = "/-/thumb";
|
||||
|
@ -489,7 +400,7 @@ bool ExportThread::HasThumbInAdress(std::string & buf, size_t i)
|
|||
return true;
|
||||
}
|
||||
|
||||
if( buf[i] == 10 || buf[i] == '"' || buf[i] == ' ' || buf[i] == '\t' ||
|
||||
if( buf[i] == 10 || buf[i] == '"' || buf[i] == ' ' || buf[i] == '\t' ||
|
||||
buf[i] == '>' ||buf[i] == '<' )
|
||||
{
|
||||
return false;
|
||||
|
@ -501,5 +412,151 @@ return false;
|
|||
|
||||
|
||||
|
||||
// second thread
|
||||
// objects locked
|
||||
void ExportThread::ChangeAdressesThumb(std::string & buf, const char * http_prefix)
|
||||
{
|
||||
look_for_url = http_prefix;
|
||||
Convert(base_url, look_for_url, false);
|
||||
Convert(message_work.src_dir, look_for_url, false);
|
||||
|
||||
for(size_t i=0 ; i<buf.size() ; ++i)
|
||||
{
|
||||
if( IsSubStringp(look_for_url.c_str(), &buf[i]) )
|
||||
{
|
||||
i += look_for_url.size() - 1; // without skipping the last slash
|
||||
|
||||
if( HasThumbInAdress(buf, i) )
|
||||
{
|
||||
if( i <= buf.size() )
|
||||
buf.insert(i, "/download"); //!! do konfiga (prefiks katalogu z miniaturami na serwerze docelowym)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// second thread
|
||||
// objects not locked
|
||||
void ExportThread::ChangeAdressesThumb(std::string & buf)
|
||||
{
|
||||
Lock();
|
||||
ChangeAdressesThumb(buf, "http://");
|
||||
ChangeAdressesThumb(buf, "https://");
|
||||
Unlock();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// second thread
|
||||
// objects locked
|
||||
void ExportThread::ChangeLogStrings()
|
||||
{
|
||||
log << log3 << "Export: changing string: |" << look_for_url << "|, to: |" << repl_url << "|" << logend;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// second thread
|
||||
// objects locked
|
||||
void ExportThread::ChangeBaseAdress(std::string & buf,
|
||||
const char * http_prefix, const char * dir_prefix, const char * dir_postfix,
|
||||
const char * repl_dir_postfix, bool skip_dir_last_slash)
|
||||
{
|
||||
look_for_url = http_prefix;
|
||||
Convert(base_url, look_for_url, false);
|
||||
look_for_url += dir_prefix;
|
||||
Convert(message_work.src_dir, look_for_url, false);
|
||||
|
||||
if( skip_dir_last_slash )
|
||||
NoLastSlash(look_for_url);
|
||||
|
||||
look_for_url += dir_postfix;
|
||||
|
||||
Convert(message_work.http_server, repl_url);
|
||||
repl_url += repl_dir_postfix;
|
||||
|
||||
ChangeLogStrings();
|
||||
ReplaceString(buf, look_for_url, repl_url);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// second thread
|
||||
// objects not locked
|
||||
void ExportThread::ChangeBaseAdress(std::string & buf,
|
||||
const char * dir_prefix, const char * dir_postfix,
|
||||
const char * repl_dir_postfix, bool skip_dir_last_slash)
|
||||
{
|
||||
Lock();
|
||||
ChangeBaseAdress(buf, "http://", dir_prefix, dir_postfix, repl_dir_postfix, skip_dir_last_slash);
|
||||
ChangeBaseAdress(buf, "https://", dir_prefix, dir_postfix, repl_dir_postfix, skip_dir_last_slash);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
|
||||
// second thread
|
||||
// objects not locked
|
||||
void ExportThread::ChangeSiteNames(std::string & buf)
|
||||
{
|
||||
Lock();
|
||||
|
||||
// changing:
|
||||
// /sitename/ -> /
|
||||
Convert(message_work.src_dir, look_for_url);
|
||||
repl_url = '/';
|
||||
ChangeLogStrings();
|
||||
ReplaceString(buf, look_for_url, repl_url);
|
||||
|
||||
// changing:
|
||||
// /sitename" -> /"
|
||||
NoLastSlash(look_for_url);
|
||||
look_for_url += '\"';
|
||||
repl_url = "/\"";
|
||||
ChangeLogStrings();
|
||||
ReplaceString(buf, look_for_url, repl_url);
|
||||
|
||||
Unlock();
|
||||
}
|
||||
|
||||
|
||||
// second thread
|
||||
// objects not locked
|
||||
void ExportThread::ChangeAdresses(std::string & buf)
|
||||
{
|
||||
// changing: (http or https)
|
||||
// http://domain.tld/sitename/[...]/file.jpg/-/thumb -> http://otherdomain.tld/download/[...]/file.jpg
|
||||
// http://domain.tld/sitename/[...]/file.jpg/download/thumb -> http://otherdomain.tld/download/[...]/file.jpg
|
||||
ChangeAdressesThumb(buf);
|
||||
|
||||
// changing: (http or https)
|
||||
// http://domain.tld/static/sitename/ -> http://otherdomain.tld/static/
|
||||
ChangeBaseAdress(buf, "/static", "", "/static/");
|
||||
|
||||
// changing: (http or https)
|
||||
// http://domain.tld/common/sitename/ -> http://otherdomain.tld/common/
|
||||
//ChangeAdresss(buf, "/common", "", "/common/");
|
||||
|
||||
// changing: (http or https)
|
||||
// http://domain.tld/sitename/ -> http://otherdomain.tld/
|
||||
ChangeBaseAdress(buf, "", "", "/");
|
||||
|
||||
// changing:
|
||||
// http://domain.tld/sitename" -> http://otherdomain.tld"
|
||||
// !! dodac no last slash na zrodle
|
||||
ChangeBaseAdress(buf, "", "\"", "\"", true);
|
||||
|
||||
// changing:
|
||||
// /sitename/ -> /
|
||||
// /sitename" -> /"
|
||||
ChangeSiteNames(buf);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -72,10 +72,21 @@ private:
|
|||
size_t ReadFunction(char * ptr, size_t size, size_t nmemb, void *userdata);
|
||||
void Convert(const std::wstring & in, std::string & out, bool clear = true);
|
||||
void ChangeAdresses(std::string & buf);
|
||||
void ChangeAdressesThumb(std::string & buf);
|
||||
bool HasThumbInAdress(std::string & buf, size_t i);
|
||||
void CreateBaseUrl(std::string & buf);
|
||||
void ChangeAdressesThumb(std::string & buf, const char * http_prefix);
|
||||
void ChangeAdressesThumb(std::string & buf);
|
||||
|
||||
void ChangeLogStrings();
|
||||
|
||||
void ChangeBaseAdress(std::string & buf,
|
||||
const char * http_prefix, const char * dir_prefix, const char * dir_postfix,
|
||||
const char * repl_dir_postfix, bool skip_dir_last_slash = false);
|
||||
void ChangeBaseAdress(std::string & buf,
|
||||
const char * dir_prefix, const char * dir_postfix,
|
||||
const char * repl_dir_postfix, bool skip_dir_last_slash = false);
|
||||
|
||||
void ChangeSiteNames(std::string & buf);
|
||||
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
|
Loading…
Reference in New Issue