00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
#include <mysql/mysql.h>
00026
#include <libmysqlwrapped.h>
00027
#include <libibank.h>
00028
#include "IWeb.h"
00029
#include "BaseForm.h"
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 BaseForm::BaseForm(Web *pWeb,
const std::string& x) : WebForm(pWeb,x)
00041 ,m_mime("/usr/local/apache/conf/mime.types")
00042 {
00043 }
00044
00045
00046 BaseForm::~BaseForm()
00047 {
00048 }
00049
00050
00051 long BaseForm::AddImage(
long num,
const std::string &filename)
00052 {
00053
IWeb *pWeb = static_cast<IWeb *>(GetWeb());
00054 Database& db = pWeb -> GetDatabase();
00055 db::Image pic(&db);
00056 cgi::Base64 bomb;
00057 size_t x = 0;
00058 size_t y = 0;
00059
00060 unlink(
"/tmp/tn.gif");
00061 unlink(
"/tmp/geometry");
00062 {
00063 FILE *fil;
00064
char cmd[1000];
00065 sprintf(cmd,
"%s -verbose -geometry 128 %s /tmp/tn.gif 2>/tmp/geometry",_CONVERT,filename.c_str());
00066 system( cmd );
00067
if ((fil = fopen(
"/tmp/geometry",
"rt")) != NULL)
00068 {
00069 fgets(cmd, 1000, fil);
00070 {
00071 cgi::Parse pa(cmd);
00072 pa.getword(cmd);
00073 {
00074 pa.getword();
00075 pa.getword(cmd);
00076 {
00077 cgi::Parse pa(cmd,
"x=");
00078 x = pa.getvalue();
00079 y = pa.getvalue();
00080 }
00081 }
00082 }
00083 fclose(fil);
00084 }
00085 }
00086 pic.owner = num;
00087 bomb.encode_from_file( (
char *)filename.c_str(), pic.image_data);
00088 bomb.encode_from_file(
"/tmp/tn.gif", pic.image_tn);
00089 pic.filename = filename;
00090 pic.xsize = x;
00091 pic.ysize = y;
00092 pic.modified = GetDate();
00093 pic.save();
00094
return pic.num;
00095 }
00096
00097
00098 std::string
BaseForm::GetMimeFromFilename(
const std::string& filename)
00099 {
00100 std::string tmp;
00101 size_t x = 0;
00102
for (size_t i = 0; i < filename.size(); i++)
00103 {
00104
if (filename[i] >=
'A' && filename[i] <=
'Z')
00105 tmp += (
char)(filename[i] + 32);
00106
else
00107 tmp += filename[i];
00108
if (filename[i] ==
'.')
00109 x = i + 1;
00110 }
00111 std::string ext = filename.substr(x);
00112
return m_mime.
GetMimeFromExtension(ext);
00113 }
00114
00115
00116 std::string
BaseForm::GetAccountName(db::Account& account)
00117 {
00118
char slask[1000];
00119
if (account.show_email &&
valid_email(account.email))
00120 {
00121 sprintf(slask,
"<b>%s</b><br> (<a href=\"mailto:%s\">%s</a>)",account.name.c_str(),account.email.c_str(),account.email.c_str());
00122
return slask;
00123 }
00124 sprintf(slask,
"<b>%s</b>",account.name.c_str());
00125
return slask;
00126 }
00127
00128
00129 bool BaseForm::valid_email(
const std::string& email)
00130 {
00131
char *s = strstr(email.c_str(),
"@");
00132
if (s && strstr(s,
"."))
00133
return true;
00134
return false;
00135 }
00136
00137
00138 void BaseForm::viewtext(
const std::string& str,
bool in_textarea)
00139 {
00140
for (size_t i = 0; i < str.size(); i++)
00141 {
00142
if (str[i] == 13 && !in_textarea)
00143 {
00144 }
00145
else
00146
if (str[i] == 10 && !in_textarea)
00147 {
00148 printf(
"<br>");
00149 }
00150
else
00151
if (str[i] ==
'<')
00152 {
00153 printf(
"<");
00154 }
00155
else
00156
if (str[i] ==
'&')
00157 {
00158 printf(
"&");
00159 }
00160
else
00161 {
00162 printf(
"%c",str[i]);
00163 }
00164 }
00165
if (!in_textarea)
00166 {
00167 printf(
"<br>");
00168 }
00169 }
00170
00171
00172 void BaseForm::Navigator(
long nforum,
long nthread,
long nmessage)
00173 {
00174
IWeb *pWeb = static_cast<IWeb *>(GetWeb());
00175 Database& db = pWeb -> GetDatabase();
00176
00177 printf(
"<div class=navigator>");
00178 printf(
"<table cellpadding=0 cellspacing=0 width=\"100%%\"><tr><td>");
00179
if (!nforum)
00180 {
00181 printf(
"<b>Forums</b>");
00182
return;
00183 }
00184 db::Forum forum(db, nforum);
00185 printf(
"<a href=\"%s?page=3\">Forums</a> - ",GetCgiName().c_str());
00186
if (!nthread)
00187 {
00188 nbprintf(
"<b>%s</b>",forum.name.c_str());
00189
return;
00190 }
00191 db::Thread thread(db, nthread);
00192 printf(
"<a href=\"%s?ForumsForm=select&forum=%ld\">",GetCgiName().c_str(),forum.num);
00193 nbprintf(
"%s</a> - ",forum.name.c_str());
00194
if (!nmessage)
00195 {
00196
if (!thread.num)
00197 thread.title =
"<new topic>";
00198 nbprintf(
"<b>%s</b>",thread.title.c_str());
00199
return;
00200 }
00201 db::Message message(db, nmessage);
00202 printf(
"<a href=\"%s?ThreadListForm=view&thread=%ld\">",GetCgiName().c_str(),thread.num);
00203 nbprintf(
"%s</a> - ",thread.title.c_str());
00204 {
00205
if (!message.num)
00206 message.title =
"<new message>";
00207 nbprintf(
"<b>%s</b>",message.title.c_str());
00208 }
00209 }
00210
00211
00212 void BaseForm::viewtn(
long num)
00213 {
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225 printf(
"<a class=tn href=\"%s?img=%ld\">",GetCgiName().c_str(),num);
00226 printf(
"<img border=\"0\" src=\"%s?imgtn=%ld\" alt=\"Thumbnail\">",GetCgiName().c_str(),num);
00227
00228
00229
00230
00231
00232
00233
00234 printf(
"</a>");
00235 }
00236
00237