changed: upload function

select file type by the extension
         param: multi
fixed:   uptime function
         it showed incorrect uptime time (minuts were badly calculated)


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@575 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2010-02-12 23:16:13 +00:00
parent 796985472a
commit 3c5a7cd664
16 changed files with 275 additions and 81 deletions

View File

@@ -50,6 +50,9 @@ return false;
}
// this function checks how many dots there are in the url
// if there are more than one (last) dot then the first dots will be changed into '_'
void CorrectUrlDots(std::string & url)
{
size_t i = url.size();
@@ -73,7 +76,7 @@ void CorrectUrlChars(std::string & url)
{
std::string::iterator i;
for(i = url.begin(); i!=url.end() ; ++i)
for(i=url.begin(); i != url.end() ; ++i)
{
if( !CorrectUrlChar(*i) )
{
@@ -215,6 +218,9 @@ void HtmlEscapeFormTxt(std::ostringstream & out, const std::string & in)
std::string::const_iterator i;
int was_enter = 0; // how many enteres there were before
if( in.empty() )
return;
out << "<p>";
// skipping first new line characters
@@ -485,15 +491,15 @@ return false;
}
bool EqualNoCase(const char * short_str, const char * long_str)
bool EqualNoCase(const char * str1, const char * str2)
{
while( *short_str && *long_str && ToSmall(*short_str) == ToSmall(*long_str) )
while( *str1 && *str2 && ToSmall(*str1) == ToSmall(*str2) )
{
++short_str;
++long_str;
++str1;
++str2;
}
if( *short_str == 0 && *long_str == 0 )
if( *str1 == 0 && *str2 == 0 )
return true;
return false;
@@ -555,3 +561,54 @@ bool IsFile(const std::string & file)
{
return IsFile(file.c_str());
}
// if there is not an extension it returns a pointer to the last '\0' character
const char * GetFileExt(const char * name)
{
size_t i, ilast;
// looking for the end of the name
for(i=0 ; name[i] != 0 ; ++i);
if( i == 0 )
return name; // ops, the name is empty
// remember the end of the string
ilast = i;
// looking for the last dot
for(--i ; i>0 && name[i] != '.' ; --i);
if( name[i] != '.' )
return name + ilast; // ops, there is not a dot
// the extensions starts from i+1
// and can be empty (if the last character is a dot)
return name + i + 1;
}
Item::StaticAuth SelectFileType(const char * file_name)
{
const char * ext = GetFileExt(file_name);
// as an image we're using only those types which can be rendered
// by a web browser
if( EqualNoCase(ext, "jpg") ||
EqualNoCase(ext, "gif") ||
EqualNoCase(ext, "png") )
return Item::static_image;
if( EqualNoCase(ext, "pdf") ||
EqualNoCase(ext, "doc") ||
EqualNoCase(ext, "xls") ||
EqualNoCase(ext, "txt") ||
EqualNoCase(ext, "ods") ||
EqualNoCase(ext, "odt") )
return Item::static_document;
return Item::static_other;
}