From c48241f78af7a5cd221b9d7f39d5dab01a01978a Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Sat, 23 Oct 2010 23:12:47 +0000 Subject: [PATCH] fixed: there were mktime() used on some dirs Items so sometimes the time of the dir was changed now for converting tm into time_t use: time_t Time(const tm & par); time_t Time(const tm * par); tm Time(time_t par); from core/misc.h now winix internally use GMT time only when printing it is converted to local user time temporarily all users use the same local time (config: time_zone_offset) (only logs are genereted with local system time) added to system: time_t LocalTime(time_t gmt_time); tm LocalTime(const tm * ptm); tm LocalTime(const tm & ptm); they convert GMT time to local user time git-svn-id: svn://ttmath.org/publicrep/winix/trunk@666 e52654a7-88a9-db11-a3e9-0013d4bc506e --- core/Makefile.dep | 9 ++-- core/Makefile.o.dep | 2 +- core/app.cpp | 18 +++----- core/config.cpp | 3 ++ core/config.h | 9 ++++ core/item.cpp | 63 ++++++++++++++++++++++++++ core/item.h | 63 +++----------------------- core/lastcontainer.cpp | 9 ++-- core/log.cpp | 2 + core/misc.cpp | 84 ++++++++++++++++++++++++++++++----- core/misc.h | 15 +++++-- core/session.cpp | 4 +- core/sessioncontainer.cpp | 4 +- core/sessionparser.cpp | 5 ++- core/system.cpp | 33 ++++++++++++++ core/system.h | 9 +++- core/thread.h | 2 +- core/user.h | 9 +++- core/users.cpp | 11 +++++ core/users.h | 1 + functions/Makefile.dep | 12 ++--- functions/funthread.cpp | 6 ++- plugins/ticket/Makefile.dep | 2 +- plugins/ticket/funticket.cpp | 7 +-- plugins/ticket/ticketinfo.cpp | 2 +- templates/Makefile.dep | 2 +- templates/dir.cpp | 16 +++---- templates/item.cpp | 32 +++++-------- templates/misc.cpp | 13 +++--- templates/misc.h | 2 +- templates/stat.cpp | 8 ++-- templates/thread.cpp | 2 +- templates/winix.cpp | 6 +-- 33 files changed, 298 insertions(+), 167 deletions(-) create mode 100755 core/item.cpp diff --git a/core/Makefile.dep b/core/Makefile.dep index a391fa1..bf54945 100755 --- a/core/Makefile.dep +++ b/core/Makefile.dep @@ -83,7 +83,8 @@ groups.o: ../db/dbitemcolumns.h ../core/user.h ../core/group.h groups.o: ../core/thread.h ../core/dircontainer.h ../core/ugcontainer.h htmlfilter.o: htmlfilter.h httpsimpleparser.o: httpsimpleparser.h -lastcontainer.o: lastcontainer.h log.h +item.o: item.h misc.h +lastcontainer.o: lastcontainer.h log.h misc.h item.h loadavg.o: loadavg.h log.h locale.o: locale.h confparser.h log.h log.o: log.h @@ -231,9 +232,9 @@ request.o: ../core/item.h ../templates/ckeditorgetparser.h request.o: ../core/httpsimpleparser.h ../core/log.h request.o: ../templates/indexpatterns.h ../templates/localefilter.h request.o: ../core/locale.h ../core/locale.h ../core/sessionmanager.h -session.o: session.h item.h error.h user.h plugindata.h rebus.h +session.o: session.h item.h error.h user.h plugindata.h rebus.h misc.h sessioncontainer.o: sessioncontainer.h session.h item.h error.h user.h -sessioncontainer.o: plugindata.h rebus.h lastcontainer.h log.h +sessioncontainer.o: plugindata.h rebus.h lastcontainer.h log.h misc.h sessionmanager.o: sessionmanager.h sessioncontainer.h session.h item.h sessionmanager.o: error.h user.h plugindata.h rebus.h lastcontainer.h sessionmanager.o: config.h confparser.h htmlfilter.h request.h requesttypes.h @@ -277,7 +278,7 @@ sessionparser.o: ../db/dbtextstream.h ../core/textstream.h ../core/error.h sessionparser.o: log.h ../db/dbitemquery.h ../core/item.h sessionparser.o: ../db/dbitemcolumns.h ../core/user.h ../core/group.h sessionparser.o: ../core/thread.h ../core/dircontainer.h -sessionparser.o: ../core/ugcontainer.h +sessionparser.o: ../core/ugcontainer.h misc.h system.o: system.h dirs.h item.h dircontainer.h ../db/db.h ../db/dbbase.h system.o: ../db/dbconn.h ../db/dbtextstream.h ../core/textstream.h system.o: ../core/error.h log.h ../db/dbitemquery.h ../core/item.h diff --git a/core/Makefile.o.dep b/core/Makefile.o.dep index 1931ac7..cb25b7b 100755 --- a/core/Makefile.o.dep +++ b/core/Makefile.o.dep @@ -1 +1 @@ -o = acceptbaseparser.o app.o bbcodeparser.o compress.o config.o confparser.o dircontainer.o dirs.o groups.o htmlfilter.o httpsimpleparser.o lastcontainer.o loadavg.o locale.o log.o misc.o mount.o mountparser.o mounts.o notify.o plugin.o plugindata.o postmultiparser.o rebus.o request.o session.o sessioncontainer.o sessionmanager.o sessionparser.o system.o textstream.o users.o +o = acceptbaseparser.o app.o bbcodeparser.o compress.o config.o confparser.o dircontainer.o dirs.o groups.o htmlfilter.o httpsimpleparser.o item.o lastcontainer.o loadavg.o locale.o log.o misc.o mount.o mountparser.o mounts.o notify.o plugin.o plugindata.o postmultiparser.o rebus.o request.o session.o sessioncontainer.o sessionmanager.o sessionparser.o system.o textstream.o users.o diff --git a/core/app.cpp b/core/app.cpp index cfdacf8..5520230 100755 --- a/core/app.cpp +++ b/core/app.cpp @@ -19,7 +19,7 @@ App::App() { stdout_is_closed = false; - last_sessions_save = time(0); + last_sessions_save = std::time(0); db.SetConn(db_conn); @@ -278,7 +278,7 @@ void App::Start() void App::SaveSessionsIfNeeded() { - time_t t = time(0); + time_t t = std::time(0); if( last_sessions_save + 86400 > t ) return; @@ -531,17 +531,9 @@ void App::PrepareSessionCookie() } else { - time_t t = time(0) + config.session_remember_max_idle; - tm * expires = localtime(&t); - - if( !expires ) - { - // oops, something wrong - request.SetCookie(config.http_session_id_name.c_str(), request.session->id); - return; - } - - request.SetCookie(config.http_session_id_name.c_str(), request.session->id, expires); + time_t t = std::time(0) + config.session_remember_max_idle; + tm expires = Time(t); + request.SetCookie(config.http_session_id_name.c_str(), request.session->id, &expires); } } diff --git a/core/config.cpp b/core/config.cpp index 7c8e22a..9c1be8b 100755 --- a/core/config.cpp +++ b/core/config.cpp @@ -165,6 +165,9 @@ void Config::AssignValues(bool stdout_is_closed) plugins_dir = Text("plugins_dir", "/usr/local/winix/plugins"); NoLastSlash(plugins_dir); parser.ListText("plugins", plugin_file); + + time_zone_offset = Int("time_zone_offset", 0); + time_zone_offset_guest = Int("time_zone_offset_guest", 0); } diff --git a/core/config.h b/core/config.h index 3a73cdc..60dbaf4 100755 --- a/core/config.h +++ b/core/config.h @@ -210,6 +210,15 @@ public: // (if true the html code for root is not filtered) bool editors_html_safe_mode_skip_root; + // temporarily we do not support time zones per user + // there is one offset for all users + // default: 0 + int time_zone_offset; + + // time zone offset for guests (not logged users) + // default: 0 + int time_zone_offset_guest; + /* */ diff --git a/core/item.cpp b/core/item.cpp new file mode 100755 index 0000000..4e98e77 --- /dev/null +++ b/core/item.cpp @@ -0,0 +1,63 @@ +/* + * This file is a part of Winix + * and is not publicly distributed + * + * Copyright (c) 2010, Tomasz Sowa + * All rights reserved. + * + */ + +#include "item.h" +#include "misc.h" + + + +Item::Item() +{ + Clear(); +} + + +void Item::SetDateToNow() +{ + date_creation = Time(std::time(0)); + date_modification = date_creation; +} + + +void Item::SetDateModifyToNow() +{ + date_modification = Time(std::time(0)); +} + + +void Item::Clear() +{ + id = -1; + + user_id = -1; + group_id = -1; + privileges = 0; + modification_user_id = -1; + + guest_name.clear(); + + subject.clear(); + content.clear(); + url.clear(); + + content_type = ct_formatted_text; + + type = none; + parent_id = -1; + default_item = -1; + + content_id = -1; + + auth = auth_none; + auth_path.clear(); + + html_template.clear(); + + SetDateToNow(); +} diff --git a/core/item.h b/core/item.h index 7bca23f..67265aa 100755 --- a/core/item.h +++ b/core/item.h @@ -14,7 +14,6 @@ - struct Item { long id; @@ -83,64 +82,12 @@ std::string auth_path; // path to a file (if auth!=auth_none) std::string html_template; -// methods - -Item() -{ - Clear(); -} - - -void SetDateToNow() -{ - time_t t = std::time(0); - date_creation = *std::localtime( &t ); - date_modification = date_creation; -} - - -void SetDateModifyToNow() -{ - time_t t = std::time(0); - date_modification = *std::localtime( &t ); -} - - -void Clear() -{ - id = -1; - - user_id = -1; - group_id = -1; - privileges = 0; - modification_user_id = -1; - - guest_name.clear(); - - subject.clear(); - content.clear(); - url.clear(); - - content_type = ct_formatted_text; - - type = none; - parent_id = -1; - default_item = -1; - - content_id = -1; - - auth = auth_none; - auth_path.clear(); - - html_template.clear(); - - SetDateToNow(); -} - - - - + // methods + Item(); + void SetDateToNow(); + void SetDateModifyToNow(); + void Clear(); }; diff --git a/core/lastcontainer.cpp b/core/lastcontainer.cpp index 2f2fbd6..4f9332d 100755 --- a/core/lastcontainer.cpp +++ b/core/lastcontainer.cpp @@ -10,7 +10,7 @@ #include "lastcontainer.h" #include "log.h" - +#include "misc.h" LastItem::LastItem() @@ -87,9 +87,7 @@ LastTab::iterator i = FindNotLoggedOut(user_id, session_id); li.name = name; li.ip = ip; li.session_id = session_id; - - time_t t = std::time(0); - li.start = *localtime(&t); + li.start = Time(std::time(0)); last_tab.insert(last_tab.end(), li); @@ -105,8 +103,7 @@ LastTab::iterator i = FindNotLoggedOut(user_id, session_id); if( i != last_tab.end() ) { - time_t t = std::time(0); - i->end = *localtime(&t); + i->end = Time(std::time(0)); } else { diff --git a/core/log.cpp b/core/log.cpp index 311108a..8276beb 100755 --- a/core/log.cpp +++ b/core/log.cpp @@ -42,6 +42,8 @@ void Log::OpenFile() void Log::PutDate(Manipulators m) { + // logs are related to localtime + time_t t = std::time(0); std::tm * loct = std::localtime(&t); diff --git a/core/misc.cpp b/core/misc.cpp index c3f3647..12e5e77 100755 --- a/core/misc.cpp +++ b/core/misc.cpp @@ -311,31 +311,43 @@ static char buffer[100]; } -const char * DateToStr(tm * ptm) +const char * DateToStr(const tm * ptm) { return DateToStr(ptm->tm_year + 1900, ptm->tm_mon+1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec); } -const char * DateToStr(time_t t) +const char * DateToStr(const tm & rtm) { - tm * ptm = std::localtime(&t); - -return DateToStr(ptm); + return DateToStr(rtm.tm_year + 1900, rtm.tm_mon+1, rtm.tm_mday, rtm.tm_hour, rtm.tm_min, rtm.tm_sec); } -const char * DateToStrWithoutHours(tm * ptm) +const char * DateToStr(time_t t) +{ + tm rtm = Time(t); + +return DateToStr(rtm); +} + + +const char * DateToStrWithoutHours(const tm * ptm) { return DateToStr(ptm->tm_year + 1900, ptm->tm_mon+1, ptm->tm_mday); } +const char * DateToStrWithoutHours(const tm & rtm) +{ + return DateToStr(rtm.tm_year + 1900, rtm.tm_mon+1, rtm.tm_mday); +} + + const char * DateToStrWithoutHours(time_t t) { - tm * ptm = std::localtime(&t); + tm rtm = Time(t); -return DateToStrWithoutHours(ptm); +return DateToStrWithoutHours(rtm); } @@ -360,17 +372,23 @@ return buffer; } -const char * DateToStrCookie(tm * ptm) +const char * DateToStrCookie(const tm * ptm) { return DateToStrCookie(ptm->tm_year + 1900, ptm->tm_mon+1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec); } +const char * DateToStrCookie(const tm & rtm) +{ + return DateToStrCookie(rtm.tm_year + 1900, rtm.tm_mon+1, rtm.tm_mday, rtm.tm_hour, rtm.tm_min, rtm.tm_sec); +} + + const char * DateToStrCookie(time_t t) { - tm * ptm = std::localtime(&t); + tm rtm = Time(t); -return DateToStrCookie(ptm); +return DateToStrCookie(rtm); } @@ -801,3 +819,47 @@ Item::Auth SelectFileType(const char * file_name) return Item::auth_other; } + + +time_t Time(const tm & par) +{ +tm t; + + memset(&t, 0, sizeof(t)); + + t.tm_year = par.tm_year; + t.tm_mon = par.tm_mon; + t.tm_mday = par.tm_mday; + t.tm_hour = par.tm_hour; + t.tm_min = par.tm_min; + t.tm_sec = par.tm_sec; + +return timegm(&t); +} + + +time_t Time(const tm * par) +{ + return Time(*par); +} + + +tm Time(time_t par) +{ + tm * ptm = gmtime(&par); + tm res; + + memset(&res, 0, sizeof(res)); + + if( ptm ) + { + res.tm_year = ptm->tm_year; + res.tm_mon = ptm->tm_mon; + res.tm_mday = ptm->tm_mday; + res.tm_hour = ptm->tm_hour; + res.tm_min = ptm->tm_min; + res.tm_sec = ptm->tm_sec; + } + +return res; +} diff --git a/core/misc.h b/core/misc.h index 05e4291..da52aac 100755 --- a/core/misc.h +++ b/core/misc.h @@ -14,8 +14,8 @@ #include #include #include -#include "item.h" #include +#include "item.h" void ToString(std::string & s, int value); @@ -34,13 +34,16 @@ std::string HtmlEscapeFormTxt(const std::string & in); const char * DateToStr(int year, int month, int day); const char * DateToStr(int year, int month, int day, int hour, int min, int sec); -const char * DateToStr(tm * ptm); +const char * DateToStr(const tm * ptm); +const char * DateToStr(const tm & rtm); const char * DateToStr(time_t t); -const char * DateToStrWithoutHours(tm * ptm); +const char * DateToStrWithoutHours(const tm * ptm); +const char * DateToStrWithoutHours(const tm & rtm); const char * DateToStrWithoutHours(time_t t); const char * DateToStrCookie(int year, int month, int day, int hour, int min, int sec); -const char * DateToStrCookie(tm * ptm); +const char * DateToStrCookie(const tm * ptm); +const char * DateToStrCookie(const tm & rtm); const char * DateToStrCookie(time_t t); const char * IpToStr(unsigned int ip_); @@ -76,4 +79,8 @@ bool CopyFile(const std::string & src, const std::string & dst); const char * GetFileExt(const char * name); Item::Auth SelectFileType(const char * file_name); +time_t Time(const tm & par); +time_t Time(const tm * par); +tm Time(time_t par); + #endif diff --git a/core/session.cpp b/core/session.cpp index 87820c8..84487b7 100755 --- a/core/session.cpp +++ b/core/session.cpp @@ -8,7 +8,7 @@ */ #include "session.h" - +#include "misc.h" @@ -18,7 +18,7 @@ Session::Session() Clear(); time = std::time(0); - tm_time = *std::localtime(&time); + tm_time = Time(time); last_time = time; tm_last_time = tm_time; diff --git a/core/sessioncontainer.cpp b/core/sessioncontainer.cpp index 20994e5..4eeecf3 100755 --- a/core/sessioncontainer.cpp +++ b/core/sessioncontainer.cpp @@ -9,7 +9,7 @@ #include "sessioncontainer.h" #include "log.h" - +#include "misc.h" @@ -147,7 +147,7 @@ void SessionContainer::UpdateLastTime(SessionContainer::Iterator iter, time_t ne index_time.insert( std::make_pair(new_time, iter) ); iter->last_time = new_time; - iter->tm_last_time = *std::localtime(&new_time); + iter->tm_last_time = Time(new_time); log << log3 << "SC: last time and the time index for session id: " << iter->id << " updated" << logend; found = true; diff --git a/core/sessionparser.cpp b/core/sessionparser.cpp index ee81986..8859fc6 100755 --- a/core/sessionparser.cpp +++ b/core/sessionparser.cpp @@ -9,6 +9,7 @@ #include "sessionparser.h" #include "log.h" +#include "misc.h" @@ -98,8 +99,8 @@ bool SessionParser::MakeSession(long user_id) session.puser = puser; session.new_session = true; - session.tm_time = *std::localtime(&session.time); - session.tm_last_time = *std::localtime(&session.last_time); + session.tm_time = Time(session.time); + session.tm_last_time = Time(session.last_time); return true; } diff --git a/core/system.cpp b/core/system.cpp index f52ee5a..a99e34c 100755 --- a/core/system.cpp +++ b/core/system.cpp @@ -51,6 +51,7 @@ void System::Init() users.SetRequest(request); users.ReadUsers(db); + users.SetTimeZoneOffset(config->time_zone_offset); groups.ReadGroups(db); // !! chwilowe przekazanie argumentu, db bedzie zmienione rebus.SetRequest(request); @@ -533,3 +534,35 @@ Error System::EditFile(Item & item, bool with_url, bool notify) return status; } + + +time_t System::LocalTime(time_t gmt_time) +{ +int time_offset; + + if( request->session && request->session->puser ) + time_offset = request->session->puser->time_zone_offset; + else + time_offset = config->time_zone_offset_guest; + +return gmt_time + (time_t)time_offset; +} + + +tm System::LocalTime(const tm * ptm) +{ +time_t t; +tm rtm; + + t = Time(ptm); + t = LocalTime(t); + rtm = Time(t); + +return rtm; +} + + +tm System::LocalTime(const tm & ptm) +{ + return LocalTime(&ptm); +} diff --git a/core/system.h b/core/system.h index 99cb049..3cfa695 100755 --- a/core/system.h +++ b/core/system.h @@ -20,7 +20,7 @@ #include "groups.h" #include "rebus.h" #include "loadavg.h" - +#include @@ -86,6 +86,13 @@ public: Error AddFile(Item & item, bool notify = true); Error EditFile(Item & item, bool with_url = true, bool notify = true); + // converting GMT time to local time (different for each user) + time_t LocalTime(time_t gmt_time); + tm LocalTime(const tm * ptm); + tm LocalTime(const tm & ptm); + + + private: Request * request; Config * config; diff --git a/core/thread.h b/core/thread.h index 809b34e..42dc823 100755 --- a/core/thread.h +++ b/core/thread.h @@ -32,7 +32,7 @@ public: Item last_item; // used when sorting - long sort; + unsigned long sort; void Clear() { diff --git a/core/user.h b/core/user.h index e75c03d..7ad3a65 100755 --- a/core/user.h +++ b/core/user.h @@ -24,9 +24,13 @@ struct User int cms_notify; int thread_notify; + + // !! currently all users have the same offset + // option in config: time_zone_offset + int time_zone_offset; - - + + User() { Clear(); @@ -42,6 +46,7 @@ struct User email.clear(); cms_notify = 0; thread_notify = 0; + time_zone_offset = 0; } diff --git a/core/users.cpp b/core/users.cpp index 94321ba..09b5bab 100755 --- a/core/users.cpp +++ b/core/users.cpp @@ -39,6 +39,17 @@ void Users::ReadUsers(Db * db) } +void Users::SetTimeZoneOffset(int offset) +{ + Table::Iterator i; + + for(i=table.Begin() ; i!=table.End() ; ++i) + { + i->time_zone_offset = offset; + } +} + + bool Users::AddUser(const User & user) { Table::Iterator i = table.PushBack(user); diff --git a/core/users.h b/core/users.h index fb18f1b..aa37e54 100755 --- a/core/users.h +++ b/core/users.h @@ -39,6 +39,7 @@ public: void Clear(); void ReadUsers(Db * db); + void SetTimeZoneOffset(int offset); // !! temporarily one time_zone for all users bool AddUser(const User & user); bool IsUser(const std::string & name); User * GetUser(long user_id); diff --git a/functions/Makefile.dep b/functions/Makefile.dep index 12ca243..1de05fc 100755 --- a/functions/Makefile.dep +++ b/functions/Makefile.dep @@ -273,12 +273,12 @@ functions.o: ../templates/patterncacher.h ../core/item.h functions.o: ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h functions.o: ../core/log.h ../templates/indexpatterns.h functions.o: ../core/sessionmanager.h -funthread.o: funthread.h functionbase.h ../core/item.h ../db/db.h -funthread.o: ../db/dbbase.h ../db/dbconn.h ../db/dbtextstream.h -funthread.o: ../core/textstream.h ../core/error.h ../core/log.h -funthread.o: ../db/dbitemquery.h ../db/dbitemcolumns.h ../core/user.h -funthread.o: ../core/group.h ../core/thread.h ../core/dircontainer.h -funthread.o: ../core/item.h ../core/ugcontainer.h ../core/request.h +funthread.o: ../core/misc.h ../core/item.h funthread.h functionbase.h +funthread.o: ../core/item.h ../db/db.h ../db/dbbase.h ../db/dbconn.h +funthread.o: ../db/dbtextstream.h ../core/textstream.h ../core/error.h +funthread.o: ../core/log.h ../db/dbitemquery.h ../db/dbitemcolumns.h +funthread.o: ../core/user.h ../core/group.h ../core/thread.h +funthread.o: ../core/dircontainer.h ../core/ugcontainer.h ../core/request.h funthread.o: ../core/requesttypes.h ../core/session.h ../core/error.h funthread.o: ../core/user.h ../core/plugindata.h ../core/rebus.h funthread.o: ../core/config.h ../core/confparser.h ../core/htmlfilter.h diff --git a/functions/funthread.cpp b/functions/funthread.cpp index eb17387..78fa2f9 100755 --- a/functions/funthread.cpp +++ b/functions/funthread.cpp @@ -8,10 +8,10 @@ */ #include +#include "core/misc.h" #include "funthread.h" - namespace Fun { @@ -46,7 +46,9 @@ size_t i; Item * pdir = system->dirs.GetDir(thread_tab[i].dir_id); if( pdir ) - thread_tab[i].sort = (long)mktime(&pdir->date_creation); + thread_tab[i].sort = (unsigned long)Time(pdir->date_creation); + else + thread_tab[i].sort = 0; } } diff --git a/plugins/ticket/Makefile.dep b/plugins/ticket/Makefile.dep index 5c3efd5..7a21be8 100755 --- a/plugins/ticket/Makefile.dep +++ b/plugins/ticket/Makefile.dep @@ -102,7 +102,7 @@ funticket.o: ../../core/plugindata.h ../../core/config.h ../../core/notify.h funticket.o: ../../templatesnotify/templatesnotify.h ../../../ezc/src/ezc.h funticket.o: ../../core/mount.h ../../core/locale.h ../../templates/misc.h funticket.o: ../../templates/localefilter.h ../../core/locale.h -funticket.o: ../../core/system.h +funticket.o: ../../core/system.h ../../core/misc.h init.o: tdb.h ticket.h ../../db/dbbase.h ../../db/dbconn.h init.o: ../../db/dbtextstream.h ../../core/textstream.h ../../core/error.h init.o: ../../core/log.h funticket.h ticketinfo.h ticketparser.h ticketconf.h diff --git a/plugins/ticket/funticket.cpp b/plugins/ticket/funticket.cpp index b469b0f..45c06e7 100755 --- a/plugins/ticket/funticket.cpp +++ b/plugins/ticket/funticket.cpp @@ -7,9 +7,10 @@ * */ -#include "funticket.h" #include #include +#include "funticket.h" +#include "core/misc.h" @@ -101,8 +102,8 @@ bool FunTicket::SortByDate::operator()(const Item * item1, const Item * item2) tm tm1 = item1->date_creation; tm tm2 = item2->date_creation; - time_t time1 = mktime(&tm1); - time_t time2 = mktime(&tm2); + time_t time1 = Time(tm1); + time_t time2 = Time(tm2); return time1 < time2; } diff --git a/plugins/ticket/ticketinfo.cpp b/plugins/ticket/ticketinfo.cpp index cf1b09c..f18694d 100755 --- a/plugins/ticket/ticketinfo.cpp +++ b/plugins/ticket/ticketinfo.cpp @@ -86,7 +86,7 @@ std::vector::iterator i; for(i=ticket_tab.begin() ; i!=ticket_tab.end() ; ++i) { Item * dir = system->dirs.GetDir(i->dir_id); - i->sort_id = ( dir ) ? (unsigned long)mktime(&dir->date_creation) : 0; + i->sort_id = ( dir ) ? (unsigned long)Time(dir->date_creation) : 0; } std::sort(ticket_tab.begin(), ticket_tab.end(), SortTicketsFun); diff --git a/templates/Makefile.dep b/templates/Makefile.dep index 0b3527e..e389aed 100755 --- a/templates/Makefile.dep +++ b/templates/Makefile.dep @@ -433,4 +433,4 @@ winix.o: ../functions/run.h ../functions/stat.h ../functions/subject.h winix.o: ../functions/funthread.h ../functions/template.h winix.o: ../functions/tinymce.h ../functions/uname.h ../functions/upload.h winix.o: ../functions/uptime.h ../functions/who.h ../core/htmlfilter.h -winix.o: ../templates/templates.h +winix.o: ../templates/templates.h ../core/misc.h diff --git a/templates/dir.cpp b/templates/dir.cpp index df54ca6..2a64a15 100755 --- a/templates/dir.cpp +++ b/templates/dir.cpp @@ -350,31 +350,27 @@ void dir_last_url_is(Info & i) void dir_last_date_creation(Info & i) { - tm * ptm = &request->dir_tab.back()->date_creation; - - i.out << DateToStr(ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec); + tm rtm = system->LocalTime(request->dir_tab.back()->date_creation); + i.out << DateToStr(rtm.tm_year + 1900, rtm.tm_mon + 1, rtm.tm_mday, rtm.tm_hour, rtm.tm_min, rtm.tm_sec); } void dir_last_date_modification(Info & i) { - tm * ptm = &request->dir_tab.back()->date_modification; - - i.out << DateToStr(ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec); + tm rtm = system->LocalTime(request->dir_tab.back()->date_modification); + i.out << DateToStr(rtm.tm_year + 1900, rtm.tm_mon + 1, rtm.tm_mday, rtm.tm_hour, rtm.tm_min, rtm.tm_sec); } void dir_last_date_creation_nice(Info & i) { - tm * ptm = &request->dir_tab.back()->date_creation; - print_date_nice(i, ptm); + print_date_nice(i, request->dir_tab.back()->date_creation); } void dir_last_date_modification_nice(Info & i) { - tm * ptm = &request->dir_tab.back()->date_modification; - print_date_nice(i, ptm); + print_date_nice(i, request->dir_tab.back()->date_modification); } diff --git a/templates/item.cpp b/templates/item.cpp index 2a2b31f..c5330ed 100755 --- a/templates/item.cpp +++ b/templates/item.cpp @@ -224,31 +224,27 @@ void item_users_different(Info & i) void item_date_creation(Info & i) { - tm * ptm = &request->item.date_creation; - - i.out << DateToStr(ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec); + tm rtm = system->LocalTime(request->item.date_creation); + i.out << DateToStr(rtm.tm_year + 1900, rtm.tm_mon + 1, rtm.tm_mday, rtm.tm_hour, rtm.tm_min, rtm.tm_sec); } void item_date_modification(Info & i) { - tm * ptm = &request->item.date_modification; - - i.out << DateToStr(ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec); + tm rtm = system->LocalTime(request->item.date_modification); + i.out << DateToStr(rtm.tm_year + 1900, rtm.tm_mon + 1, rtm.tm_mday, rtm.tm_hour, rtm.tm_min, rtm.tm_sec); } void item_date_creation_nice(Info & i) { - tm * ptm = &request->item.date_creation; - print_date_nice(i, ptm); + print_date_nice(i, request->item.date_creation); } void item_date_modification_nice(Info & i) { - tm * ptm = &request->item.date_modification; - print_date_nice(i, ptm); + print_date_nice(i, request->item.date_modification); } @@ -492,9 +488,8 @@ void item_tab_date_creation(Info & i) { if( item_index < request->item_tab.size() ) { - tm * ptm = &request->item_tab[item_index].date_creation; - - i.out << DateToStr(ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec); + tm rtm = system->LocalTime(request->item_tab[item_index].date_creation); + i.out << DateToStr(rtm.tm_year + 1900, rtm.tm_mon + 1, rtm.tm_mday, rtm.tm_hour, rtm.tm_min, rtm.tm_sec); } } @@ -503,9 +498,8 @@ void item_tab_date_modification(Info & i) { if( item_index < request->item_tab.size() ) { - tm * ptm = &request->item_tab[item_index].date_modification; - - i.out << DateToStr(ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec); + tm rtm = system->LocalTime(request->item_tab[item_index].date_modification); + i.out << DateToStr(rtm.tm_year + 1900, rtm.tm_mon + 1, rtm.tm_mday, rtm.tm_hour, rtm.tm_min, rtm.tm_sec); } } @@ -514,8 +508,7 @@ void item_tab_date_creation_nice(Info & i) { if( item_index < request->item_tab.size() ) { - tm * ptm = &request->item_tab[item_index].date_creation; - print_date_nice(i, ptm); + print_date_nice(i, request->item_tab[item_index].date_creation); } } @@ -525,8 +518,7 @@ void item_tab_date_modification_nice(Info & i) { if( item_index < request->item_tab.size() ) { - tm * ptm = &request->item_tab[item_index].date_modification; - print_date_nice(i, ptm); + print_date_nice(i, request->item_tab[item_index].date_modification); } } diff --git a/templates/misc.cpp b/templates/misc.cpp index 7c06978..6044df8 100755 --- a/templates/misc.cpp +++ b/templates/misc.cpp @@ -18,19 +18,18 @@ namespace TemplatesFunctions { -void print_date_nice(Ezc::Info & i, const tm * ptm) +void print_date_nice(Ezc::Info & i, const tm & rtm) { - tm tm_temp(*ptm); - - time_t t = mktime(&tm_temp); // mktime do something in tm_temp - time_t now = time(0); + time_t t = Time(rtm); + time_t now = std::time(0); time_t one_day = 60 * 60 * 24; + tm ltm = system->LocalTime(rtm); if( t + one_day > now ) - i.out << DateToStr(ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec); + i.out << DateToStr(ltm.tm_year + 1900, ltm.tm_mon + 1, ltm.tm_mday, ltm.tm_hour, ltm.tm_min, ltm.tm_sec); else - i.out << DateToStr(ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday); + i.out << DateToStr(ltm.tm_year + 1900, ltm.tm_mon + 1, ltm.tm_mday); } diff --git a/templates/misc.h b/templates/misc.h index 017b59a..17818c9 100755 --- a/templates/misc.h +++ b/templates/misc.h @@ -24,7 +24,7 @@ namespace TemplatesFunctions // table: [language][file] typedef std::vector > Patterns; -void print_date_nice(Ezc::Info & i, const tm * ptm); +void print_date_nice(Ezc::Info & i, const tm & rtm); void print_user_name(Ezc::Info & i, const User * puser, const std::string & guest_name); int ParseCKeditorFun(); diff --git a/templates/stat.cpp b/templates/stat.cpp index 4093783..b000aaa 100755 --- a/templates/stat.cpp +++ b/templates/stat.cpp @@ -71,15 +71,15 @@ void stat_item_privileges(Info & i) void stat_item_date_creation(Info & i) { - tm * ptm = &request->last_item->date_creation; - i.out << DateToStr(ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec); + tm rtm = system->LocalTime(request->last_item->date_creation); + i.out << DateToStr(rtm.tm_year + 1900, rtm.tm_mon + 1, rtm.tm_mday, rtm.tm_hour, rtm.tm_min, rtm.tm_sec); } void stat_item_date_modification(Info & i) { - tm * ptm = &request->last_item->date_modification; - i.out << DateToStr(ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec); + tm rtm = system->LocalTime(request->last_item->date_modification); + i.out << DateToStr(rtm.tm_year + 1900, rtm.tm_mon + 1, rtm.tm_mday, rtm.tm_hour, rtm.tm_min, rtm.tm_sec); } diff --git a/templates/thread.cpp b/templates/thread.cpp index 77e8377..c949b5d 100755 --- a/templates/thread.cpp +++ b/templates/thread.cpp @@ -143,7 +143,7 @@ void thread_tab_last_item_date_modification_nice(Info & i) { if( thread_tab_index < functions->fun_thread.thread_tab.size() ) if( functions->fun_thread.thread_tab[thread_tab_index].last_item.id != -1 ) - print_date_nice(i, &functions->fun_thread.thread_tab[thread_tab_index].last_item.date_modification); + print_date_nice(i, functions->fun_thread.thread_tab[thread_tab_index].last_item.date_modification); } diff --git a/templates/winix.cpp b/templates/winix.cpp index 43289f1..9a03beb 100755 --- a/templates/winix.cpp +++ b/templates/winix.cpp @@ -11,6 +11,7 @@ #include "templates.h" #include "core/request.h" #include "core/plugin.h" +#include "core/misc.h" #include "functions/functions.h" @@ -24,10 +25,9 @@ void winix_cur_time(Info & i) { static char buffer[100]; - time_t t = time(0); - tm * ptm = localtime(&t); + tm rtm = Time(std::time(0)); - sprintf(buffer, "%02d:%02d:%02d", ptm->tm_hour, ptm->tm_min, ptm->tm_sec); + sprintf(buffer, "%02d:%02d:%02d", rtm.tm_hour, rtm.tm_min, rtm.tm_sec); i.out << buffer; }