00001 #include "page_control.hpp"
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 typedef vector<int> slide_selector;
00037
00038 class show_page : public page
00039 {
00040 slide_selector slides;
00041 public:
00042 show_page(cgiScript & in):page(in)
00043 {
00044 ;
00045 }
00046 virtual ~show_page()
00047 {
00048 ;
00049 }
00050
00051
00052 bool loadSlides( ocString tags )
00053 {
00054 bool bret = true;
00055 page_paragraphs & pg_paras = get_page_paragraphs();
00056 for( page_paragraphs::size_type szt=0; szt < pg_paragraphs.size(); ++szt )
00057 {
00058 page_paragraph & para = pg_paragraphs.at(szt);
00059 if( tags.regExMatch( para.template_tag().c_str() ) )
00060 {
00061 slides.push_back(szt);
00062 }
00063 }
00064 return bret;
00065 }
00066
00067
00068 virtual bool emitDetail( const string & for_slide_items, string contentTags, string replaceTag )
00069 {
00070 bool bRet = true;
00071 paragraphMap & paras = pg_template.getParagraphs();
00072 int slideNo = 0;
00073 string qryString = script.QueryString().c_str();
00074 cgiInput & args = script.ClientArguments();
00075 if( args.count("s") )
00076 {
00077 slideNo = atoi( args["s"].c_str() );
00078 }
00079 paras_emitDetail(get_page_paragraphs(),paras,contentTags,for_slide_items,replaceTag,slideNo);
00080 return bRet;
00081 }
00082 void paras_emitDetail( page_paragraphs & pg_paragraphs,
00083 paragraphMap & paras,
00084 ocString templateTags,
00085 ocString for_slide_items,
00086 string replace_tag,
00087 int slideNo )
00088 {
00089 templateTags.parseInit();
00090 do
00091 {
00092 string tag = templateTags.parse(",");
00093 if( tag.length() )
00094 {
00095 for( slide_selector::size_type szt=0; szt < slides.size(); ++szt )
00096 {
00097 page_paragraph & para = pg_paragraphs.at(slides.at(szt));
00098
00099 if( for_slide_items.length() )
00100 {
00101 if( for_slide_items.regExMatch(para.template_tag().c_str()) &&
00102 szt==slideNo)
00103 {
00104 para_emitDetail(para, paras,replace_tag,
00105 tag, slideNo,szt,slides.size());
00106 }
00107 }
00108 else
00109 {
00110 if( para.template_tag() == tag &&
00111 szt==slideNo )
00112 {
00113 para_emitDetail(para, paras,replace_tag,
00114 para.template_tag(), slideNo,szt,slides.size());
00115 }
00116 }
00117 }
00118 }
00119 } while( !templateTags.endOfParse() );
00120 }
00121 void para_emitDetail( page_paragraph & para,
00122 paragraphMap & paras,
00123 const string & replace_tag,
00124 const string & template_key,
00125 int selSlide,
00126 int sztPos,
00127 int arrySize )
00128 {
00129 paragraphMap::iterator pos = paras.find(template_key);
00130
00131 int iLast = arrySize?arrySize-1:0;
00132 int iPrev = selSlide?sztPos-1:iLast;
00133 int iNext = arrySize?(sztPos+1)%arrySize:0;
00134 ocString First, Previous, Next, Last;
00135 First.append(0);
00136 Previous.append(iPrev);
00137 Next.append(iNext);
00138 Last.append(iLast);
00139
00140 if( pos != paras.end() )
00141 {
00142 ocString output = pos->second;
00143
00144 script <<
00145 output.replace( replace_tag.c_str(),
00146 para.content().c_str() )
00147 .replaceAll("$Idf", First.c_str())
00148 .replaceAll("$Idp", Previous.c_str())
00149 .replaceAll("$Idn", Next.c_str())
00150 .replaceAll("$Idl", Last.c_str());
00151 }
00152 }
00153 virtual bool emitSlides( string contentTags, string replaceTag )
00154 {
00155 bool bRet = true;
00156 paragraphMap & paras = pg_template.getParagraphs();
00157 int slideNo = 0;
00158 cgiInput & args = script.ClientArguments();
00159 if( args.count("s") )
00160 {
00161 slideNo = atoi( args["s"].c_str());
00162 }
00163 paras_emitSlides(get_page_paragraphs(),paras,contentTags,replaceTag,slideNo);
00164 return bRet;
00165 }
00166 void paras_emitSlides( page_paragraphs & pg_paragraphs,
00167 paragraphMap & paras,
00168 ocString templateTags,
00169 string replace_tag,
00170 int SlideNo )
00171 {
00172 for( slide_selector::size_type szt=0; szt < slides.size(); ++szt )
00173 {
00174 page_paragraph & para = pg_paragraphs.at(slides.at(szt));
00175 para_emitSlide(para,paras,templateTags,replace_tag,SlideNo,szt);
00176 }
00177 }
00178 void para_emitSlide( page_paragraph & para,
00179 paragraphMap & paras,
00180 ocString templateTags,
00181 const string replace_tag,
00182 int SlideNo,
00183 int sztPos )
00184 {
00185 templateTags.parseInit();
00186
00187
00188
00189
00190
00191 bool isMatchFound=false;
00192 bool isSelected = SlideNo==sztPos;
00193 string firstTag,tag;
00194 do {
00195 tag = templateTags.parse(",");
00196 if(firstTag.length()==0) firstTag=tag;
00197
00198 if( tag.length() && para.template_tag() == tag )
00199 { isMatchFound = true;
00200 paragraphMap::iterator pos = paras.find(tag);
00201 if( pos != paras.end() )
00202 {
00203 slideEmission(para,replace_tag,SlideNo,sztPos,pos->second,isSelected);
00204 }
00205 }
00206 } while( !templateTags.endOfParse() );
00207 if( isMatchFound == false )
00208 {
00209
00210 paragraphMap::iterator pos = paras.find(firstTag);
00211 if( pos != paras.end() )
00212 {
00213 slideEmission(para,replace_tag,SlideNo,sztPos,pos->second,isSelected);
00214 }
00215 }
00216 }
00217 void slideEmission( page_paragraph ¶,
00218 const string replace_tag,
00219 int SlideNo,
00220 int sztPos,
00221 ocString output, bool isSelected )
00222 {
00223 ocString parseContent = para.content();
00224 string selectIndicator;
00225 if( isSelected )
00226 {
00227 selectIndicator = " id='user_selected_slide' ";
00228 }
00229
00230 if( parseContent.find("<img") != string::npos ) parseContent.parse("<img");
00231 else parseContent.parse("<IMG");
00232 if( !parseContent.endOfParse() )
00233 {
00234 ocString uniqueId;
00235 ocString image = "<img";
00236 image += parseContent.parse(">");
00237 if( image.find("small_images") == string::npos &&
00238 image.find("images") != string::npos )
00239 {
00240 image = image.replace("images","small_images");
00241 }
00242 image += " alt='";
00243 image += para.name();
00244 image += "'>";
00245 uniqueId.append(sztPos);
00246
00247 script <<
00248 output.replace("$selectIndicator",selectIndicator)
00249 .replaceAll( "$Id",uniqueId.c_str() )
00250 .replaceAll( replace_tag.c_str(),
00251 image.c_str() )
00252 .replaceAll( "$label", para.name().c_str() );
00253 }
00254 }
00255
00256
00257
00258
00259 };
00260
00261
00262
00263 bool isMutex( xmlNode & node )
00264 {
00265
00266 node_attr::iterator x = node.attr.find("mutex");
00267
00268 return (x!=node.attr.end());
00269 }
00270
00271 class detail_functor: public base_functor
00272 {
00273 cgiScript & script;
00274 public:
00275
00276 detail_functor(page & ipg,cgiScript & script):base_functor(ipg),script(script){;}
00277
00278 virtual ~detail_functor(){;}
00279
00280 show_page & showpg(void) { return dynamic_cast<show_page &>(this->pg); }
00281
00282 bool shouldShow(xmlNode & node )
00283 {
00284 bool ret=true;
00285 if( isMutex(node) )
00286 {
00287 if( script.ClientArguments().count("s") == 0 )
00288 ret=false;
00289 }
00290 return ret;
00291 }
00292
00293 virtual bool operator()( xmlNode & node )
00294 {
00295 bool bRet = false;
00296
00297 if( shouldShow( node ) )
00298 {
00299 string for_slide_items, items, replace_tag;
00300 node_attr::iterator x = node.attr.find("for_slide_items");
00301 if( x!=node.attr.end() ) for_slide_items = x->second;
00302 x = node.attr.find("item");
00303 if( x==node.attr.end() ) x = node.attr.find("items");
00304 if( x!=node.attr.end() )
00305 {
00306 items=x->second;
00307 x = node.attr.find("replace_tag");
00308 if( x==node.attr.end() ) x = node.attr.find("replace-tag");
00309
00310 if( x!=node.attr.end())
00311 {
00312 replace_tag=x->second;
00313 bRet = showpg().emitDetail( for_slide_items, items, replace_tag );
00314 }
00315 else
00316 {
00317 script << "no content replace tag" << endl;
00318 }
00319 }
00320 else
00321 {
00322 script << "no content items" << endl;
00323 }
00324 }
00325 return bRet;
00326 }
00327 };
00328
00329
00330 class slides_functor: public base_functor
00331 {
00332 cgiScript & script;
00333 public:
00334 slides_functor(page & ipg,cgiScript & script):base_functor(ipg),script(script){;}
00335 virtual ~slides_functor(){;}
00336
00337 show_page & showpg(void) { return dynamic_cast<show_page &>(this->pg); }
00338
00339 bool shouldShow(xmlNode & node )
00340 {
00341 bool ret=true;
00342 if( isMutex(node) )
00343 {
00344 if( script.ClientArguments().count("s") )
00345 ret=false;
00346 }
00347 return ret;
00348 }
00349
00350 virtual bool operator()( xmlNode & node )
00351 {
00352 bool bRet = false;
00353
00354 if( shouldShow( node ) )
00355 {
00356
00357 string items, replace_tag;
00358 node_attr::iterator x = node.attr.find("items");
00359 if( x!=node.attr.end() )
00360 {
00361
00362 items=x->second;
00363 x = node.attr.find("replace_tag");
00364 if( x==node.attr.end() ) x = node.attr.find("replace-tag");
00365 if( x!=node.attr.end())
00366 {
00367 replace_tag=x->second;
00368 bRet = showpg().emitSlides( items, replace_tag );
00369 }
00370 else
00371 {
00372 cout << "no content replace tag" << endl;
00373 }
00374 }
00375 else
00376 {
00377 cout << "no content items" << endl;
00378 }
00379 }
00380 return bRet;
00381 }
00382 };