00001 #ifndef OPEN_CORE_RICHFORM_H
00002 #define OPEN_CORE_RICHFORM_H 123456
00003
00004 #include "forms_base.hpp"
00005 class ocRicharea: public ocBase
00006 {
00007
00008 public:
00009 string ctrlName;
00010 ocString ctrlTemplate;
00011
00012
00013 ocRicharea(string ctrlTemplate, string name):ctrlTemplate(ctrlTemplate),ctrlName(name)
00014 {
00015 ;
00016 }
00017 virtual string getHtml( void )
00018 {
00019 string result;
00020 if( ctrlTemplate.length() > 0 )
00021 {
00022 result = ctrlTemplate.replace("$name",ctrlName.c_str()).replace("$content",content.c_str());
00023 }
00024 return result;
00025 }
00026 ~ocRicharea(){;}
00027 };
00028
00029 ocRicharea * richEntry( string ctrlTemplate, string name = "content" )
00030 {
00031 ocRicharea * ra = new ocRicharea(ctrlTemplate,name);
00032 return ra;
00033 }
00034
00035 class richForm: public forms_base
00036 {
00037
00038 public:
00039 string tmpltPath;
00040 string ctrlName;
00041 cgiTemplates ctrlTemplate;
00042
00043 richForm( cgiScript & in, string templatePath = "Templates/FullyRichEditor.html" ):forms_base(in)
00044 {
00045 tmpltPath = templatePath;
00046 if(tmpltPath.length()) ctrlTemplate.load(tmpltPath.c_str());
00047 }
00048 string makeRichEntry( string label, string name, string value )
00049 {
00050 ocString ret = formTemplate.getParagraph("wide_group");
00051 ocRicharea * pRich = richEntry( ctrlTemplate.getParagraph("control") , name );
00052 if( pRich )
00053 {
00054 pRich->setContent(value);
00055 ret = ret.replace("$label$",label.c_str())
00056 .replace("$control$", pRich->getHtml().c_str());
00057 delete pRich;
00058 }
00059 return ret;
00060 }
00061
00062 string htmlFixup(string in)
00063 {
00064 ocString content(in);
00065 return content.replaceAll("\"","`22;")
00066 .replaceAll("'","`27;")
00067 .replaceAll("+","`29;")
00068 .replaceAll("<","`3c;")
00069 .replaceAll(">","`3e;")
00070 .replaceAll("&","`26;");
00071 }
00072
00073 string htmlDecode(string in)
00074 {
00075 ocString content(in);
00076 return content.replaceAll("`22;","\"")
00077 .replaceAll("`27;","'")
00078 .replaceAll("`29;","+")
00079 .replaceAll("`3c;","<")
00080 .replaceAll("`3e;",">")
00081 .replaceAll("`26;","&");
00082 }
00083 };
00084
00085 #endif