00001 /* 00002 page.hpp 00003 00004 page object abstraction 00005 00006 Copyright (late) 2004 - 2004 by D.K. McCombs. 00007 ====================================== 00008 00009 */ 00010 #ifndef page_hpp 00011 #define page_hpp 00012 00013 #include "connectstring" 00014 #include "ocTypes.h" 00015 #include "ocString.h" 00016 #include "read_write_base.hpp" 00017 #include "openLogger.h" 00018 #ifndef SUPPRESS_LINK_CREATION 00019 00020 #include "link.hpp" 00021 #include "site.hpp" 00022 #include "templates.hpp" 00023 #include "menu.hpp" 00024 #include "sys_page_menus.h" 00025 00026 #include "cgiTemplates.h" 00027 #include "ocXML.h" 00028 00029 #endif 00030 using namespace std; 00031 00032 /* 00033 00034 CREATE TABLE pages ( 00035 id bigint not null primary key auto_increment, 00036 site_id bigint NOT NULL, -- the id to the containing web site 00037 template_id bigint NOT NULL, -- the id to the page template 00038 name text NOT NULL, -- name 00039 url text, -- location 00040 meta_description text -- description for robots. 00041 ); 00042 00043 */ 00044 00045 class page: public read_write_base 00046 { 00047 public: 00048 identifier id; 00049 long long site_id; 00050 long long template_id; 00051 string name; 00052 string url; 00053 string meta_description; 00054 00055 page():read_write_base(),id(0LL),site_id(0LL),template_id(0LL) 00056 { 00057 // set name 00058 data_name("metasite.pages"); 00059 00060 // add fields 00061 addDXMap( new llongXfer("id", &id )); 00062 addDXMap( new llongXfer("site_id", &site_id )); 00063 addDXMap( new llongXfer("template_id", & template_id)); 00064 addDXMap( new stringXfer("name", &name )); 00065 addDXMap( new stringXfer("url", &url )); 00066 addDXMap( new stringXfer("meta_description", &meta_description )); 00067 } 00068 00069 virtual bool uvalidate( changeMap & changes ) 00070 { 00071 // find out if changes hold url 00072 if( changes.find("url") != changes.end() ) 00073 { 00074 // if so, find out what this url was before change 00075 ocString sql = "select url from metasite.pages where id = "; 00076 sql.append(id); 00077 if(rs.open(sql)) 00078 { 00079 // update links with that url to have the new url 00080 sql = "update metasite.links set url = '" + url + "' where site_id = "; 00081 sql.append(site_id); 00082 sql += " and url = '"; 00083 sql += rs.getField(0).format(); 00084 sql += "'"; 00085 cmd.execute(sql); 00086 rs.close(); 00087 } 00088 } 00089 return true; 00090 } 00091 #ifndef SUPPRESS_LINK_CREATION 00092 bool usupplemental( changeMap & changes ) 00093 { 00094 if( changes.find("template_id") != changes.end() ) 00095 { 00096 deletePageMenus(); 00097 createPageMenus(); 00098 } 00099 return true; 00100 } 00101 bool isupplemental( void ) 00102 { 00103 // automatically generate a link item with this url 00104 class link ln; 00105 ln.site_id=site_id; 00106 ln.name = name; 00107 ln.url = url; 00108 ln.db_insert(); 00109 // automatically create page menus; 00110 createPageMenus(); 00111 return true; 00112 } 00113 void deletePageMenus( void ) 00114 { 00115 ocString sql = "delete from metasite.page_menus where page_id = "; 00116 sql.append(id); 00117 cmd.execute(sql); 00118 } 00119 void deletePageParagraphs( void ) 00120 { 00121 ocString sql = "delete from metasite.paragraphs where page_id = "; 00122 sql.append(id); 00123 cmd.execute(sql); 00124 } 00125 void createPageMenus( void ) 00126 { 00127 // find the menus associated with this page 00128 siteObject thisSite; 00129 thisSite.id - site_id; 00130 thisSite.key(site_id); 00131 if( thisSite.get_data() ) 00132 { 00133 Template tmplt; 00134 tmplt.id = template_id; 00135 tmplt.key(template_id); 00136 if( tmplt.get_data() ) 00137 { 00138 // build a path to the Template 00139 string fullPath = thisSite.path; 00140 fullPath += "/Templates/"; 00141 fullPath += tmplt.path; 00142 00143 cgiTemplates cTemp; 00144 if( cTemp.load(fullPath.c_str()) ) 00145 { 00146 // get the control section 00147 xmlParser parser( cTemp.getParagraph("control") ); 00148 parser.parse(); 00149 node_vector::iterator & it = parser.findFirstNodeByName( "menu" ); 00150 int order=0; 00151 while( it != parser.states.nodes.end() ) 00152 { 00153 xmlNode & node = *it; 00154 string open_tag = node.attr["open"]; 00155 string close_tag = node.attr["close"]; 00156 00157 class menu mnu; 00158 string clause = "reference_template = '"; 00159 clause += tmplt.path; 00160 clause += "' and template_open_tag = '"; 00161 clause += open_tag; 00162 clause += "' and template_close_tag = '"; 00163 clause += close_tag; 00164 clause += "'"; 00165 00166 if( mnu.get_data(clause) ) 00167 { 00168 page_menus_Obj pg_mnu; 00169 pg_mnu.site_id = site_id; 00170 pg_mnu.menu_id = mnu.id; 00171 pg_mnu.page_id = id; 00172 pg_mnu.place_order = order++; 00173 pg_mnu.collapsible = false; 00174 pg_mnu.db_insert(); 00175 } 00176 it = parser.findNextNodeByName( "menu" ); 00177 } 00178 } 00179 } 00180 } 00181 } 00182 00183 virtual bool dsupplemental( void ) 00184 { 00185 // delete all associated content 00186 deletePageParagraphs(); 00187 deletePageMenus(); 00188 return true; 00189 } 00190 #endif 00191 }; 00192 00193 #endif
1.5.5