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