Google
Web alhem.net
Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

BaseForm.cpp

Go to the documentation of this file.
00001 00006 /* 00007 Copyright (C) 2004 Anders Hedstrom 00008 00009 This program is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU General Public License 00011 as published by the Free Software Foundation; either version 2 00012 of the License, or (at your option) any later version. 00013 00014 This program is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU General Public License for more details. 00018 00019 You should have received a copy of the GNU General Public License 00020 along with this program; if not, write to the Free Software 00021 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00022 */ 00023 //#include <stdio.h> 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 #define DEB(x) { \ 00033 FILE *fil = fopen("/tmp/debug","at"); \ 00034 x; \ 00035 fclose(fil); \ 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); // file=>file 00073 { 00074 pa.getword(); // type 00075 pa.getword(cmd); // geometry XxY 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>&nbsp;(<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("&lt;"); 00154 } 00155 else 00156 if (str[i] == '&') 00157 { 00158 printf("&amp;"); 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>&nbsp;-&nbsp;",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 = "&lt;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 = "&lt;new message>"; 00207 nbprintf("<b>%s</b>",message.title.c_str()); 00208 } 00209 } 00210 00211 00212 void BaseForm::viewtn(long num) 00213 { 00214 // IWeb *pWeb = static_cast<IWeb *>(GetWeb()); 00215 // Database& db = pWeb -> GetDatabase(); 00216 // db::Image image(db, num); 00217 00218 /* 00219 printf("<img"); 00220 printf(" onmouseout=\"return nd();\""); 00221 printf(" onmouseover=\"return overlib('<img src=%s?img=%ld>');\"", 00222 GetCgiName().c_str(), num); 00223 printf(" border=\"0\" src=\"%s?imgtn=%ld\" alt=\"Thumbnail\">", GetCgiName().c_str(), num); 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 printf("<img"); 00229 printf(" onmouseout=\"return nd();\""); 00230 printf(" onmouseover=\"return overlib('<img src=%s?img=%ld>', WRAP, ABOVE, FOLLOWMOUSE, 0, OFFSETX, 50);\"", 00231 GetCgiName().c_str(), num); 00232 printf(" border=\"0\" src=\"%s?imgtn=%ld\" alt=\"Thumbnail\">", GetCgiName().c_str(), num); 00233 */ 00234 printf("</a>"); 00235 } 00236 00237

Generated on Sat Feb 12 00:14:56 2005 for IBank by doxygen 1.3.7