2008-12-10 05:42:49 +01:00
|
|
|
/*
|
|
|
|
* This file is a part of CMSLU -- Content Management System like Unix
|
|
|
|
* and is not publicly distributed
|
|
|
|
*
|
|
|
|
* Copyright (c) 2008, Tomasz Sowa
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "misc.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ToString(std::string & s, int value)
|
|
|
|
{
|
|
|
|
static char buffer[50];
|
|
|
|
|
|
|
|
sprintf(buffer, "%d", value);
|
|
|
|
s = buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ToString(std::string & s, long value)
|
|
|
|
{
|
|
|
|
static char buffer[50];
|
|
|
|
|
|
|
|
sprintf(buffer, "%ld", value);
|
|
|
|
s = buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SetUrlSubjectFromSubject(Item & item)
|
|
|
|
{
|
|
|
|
std::string::iterator i;
|
|
|
|
|
2008-12-14 06:28:28 +01:00
|
|
|
item.url.clear();
|
2008-12-10 05:42:49 +01:00
|
|
|
|
|
|
|
for(i = item.subject.begin(); i!=item.subject.end() ; ++i)
|
|
|
|
{
|
|
|
|
int c = ChangeLocalChar(*i);
|
|
|
|
|
|
|
|
if( (c >= 'a' && c <='z') ||
|
|
|
|
(c >= 'A' && c <='Z') ||
|
|
|
|
(c >= '0' && c <='9') ||
|
|
|
|
(c == '(' || c == ')' || c == '.' || c == ',' || c == '_' )
|
|
|
|
)
|
|
|
|
{
|
2008-12-14 06:28:28 +01:00
|
|
|
item.url += c;
|
2008-12-10 05:42:49 +01:00
|
|
|
}
|
|
|
|
else
|
2008-12-14 06:28:28 +01:00
|
|
|
item.url += '_';
|
2008-12-10 05:42:49 +01:00
|
|
|
}
|
|
|
|
|
2008-12-14 06:28:28 +01:00
|
|
|
if( item.url.empty() )
|
|
|
|
item.url = "bez_nazwy"; // !! wrzucic do pliku konfiguracyjnego
|
2008-12-10 05:42:49 +01:00
|
|
|
else
|
2008-12-14 06:28:28 +01:00
|
|
|
if( item.url[0] >= '0' && item.url[0] <= '9' )
|
|
|
|
// url must begin with a letter
|
|
|
|
item.url.insert(item.url.begin(), '_');
|
2008-12-10 05:42:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int polish_letters_simple[] =
|
|
|
|
{ 'a', 'A',
|
|
|
|
'c', 'C',
|
|
|
|
's', 'S',
|
|
|
|
'e', 'E',
|
|
|
|
'l', 'L',
|
|
|
|
'o', 'O',
|
|
|
|
'z', 'Z',
|
|
|
|
'z', 'Z',
|
|
|
|
'n', 'N', 0 }; // 0 - terminating
|
|
|
|
|
|
|
|
|
|
|
|
int polish_letters_iso88592[] =
|
|
|
|
{ 0xb1, 0xa1,
|
|
|
|
0xe6, 0xc6,
|
|
|
|
0xb6, 0xa6,
|
|
|
|
0xea, 0xca,
|
|
|
|
0xb3, 0xa3,
|
|
|
|
0xf3, 0xd3,
|
|
|
|
0xbf, 0xaf,
|
|
|
|
0xbc, 0xac,
|
|
|
|
0xf1, 0xd1, 0 };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int ChangeLocalChar(unsigned char c)
|
|
|
|
{
|
|
|
|
// if( language == polish_iso88592 )
|
|
|
|
|
|
|
|
for(int i = 0 ; polish_letters_iso88592[i] ; ++i)
|
|
|
|
{
|
|
|
|
if( polish_letters_simple[i] == 0 )
|
|
|
|
{
|
|
|
|
log << log1 << "localization tables don't have the same size" << logend;
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( polish_letters_iso88592[i] == c )
|
|
|
|
return polish_letters_simple[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HtmlSpecial(std::ostringstream & out, const std::string & in)
|
|
|
|
{
|
|
|
|
std::string::const_iterator i;
|
|
|
|
|
|
|
|
for(i = in.begin() ; i != in.end() ; ++i)
|
|
|
|
{
|
|
|
|
if( *i == '<' )
|
|
|
|
out << "<";
|
|
|
|
else
|
|
|
|
if( *i == '>' )
|
|
|
|
out << ">";
|
2008-12-21 22:17:09 +01:00
|
|
|
else
|
|
|
|
if( *i == '&' )
|
|
|
|
out << "&";
|
2008-12-10 05:42:49 +01:00
|
|
|
else
|
|
|
|
out << *i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string HtmlSpecial(const std::string & in)
|
|
|
|
{
|
|
|
|
std::ostringstream out;
|
|
|
|
|
|
|
|
HtmlSpecial(out, in);
|
|
|
|
|
|
|
|
return out.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-12-21 22:17:09 +01:00
|
|
|
|