7 #include <boost/algorithm/string/replace.hpp>
14 #include <gdcore/gdCore.h>
33 : WTemplate(parent), m_sInitialPath(initialPath)
35 propagateSetEnabled(
true);
36 if ( WString::tr(
"byObjectStyleSheet").narrow() ==
"true" )
37 wApp->useStyleSheet(wApp->theme()->resourcesUrl() +
"wittyshare/Css/WsTemplate.css");
38 addStyleClass(
"WsTemplate");
40 std::string fileContent;
41 if ( !gdcore_file_content2string(tFile.c_str(), fileContent) ) {
42 wApp->log(
"ERROR") <<
"WsTemplate::WsTemplate - cannot load " << tFile;
45 setTemplateText(fileContent);
54 std::string curPath = wApp->internalPath();
55 boost::algorithm::replace_all(curPath,
"&",
"&");
57 boost::filesystem::path current(tFile);
58 if ( !boost::filesystem::is_directory(current) )
59 current = current.parent_path();
63 if ( boost::filesystem::exists(sCurrent) )
return sCurrent;
64 if ( pUser->
getRootPath() == current.string() )
return templateFile;
65 current = current.parent_path();
72 if ( varName ==
"WsLogo" ) {
75 bindWidget(varName, pLogo);
78 if ( varName ==
"WsSiteMap" ) {
81 bindWidget(varName, pSiteMap);
84 if ( varName ==
"WsSearchObject" ) {
87 bindWidget(varName, pSearch);
90 if ( varName ==
"WsTopBanner" ) {
93 bindWidget(varName, pTB);
96 if ( varName ==
"WsContentButtonsBar" ) {
99 bindWidget(varName, pCBB);
102 if ( varName ==
"WsFunctionnalities" ) {
105 bindWidget(varName, pFunc);
108 if ( varName ==
"WsBottomBanner" ) {
111 bindWidget(varName, pBB);
114 return WTemplate::resolveWidget(varName);
121 if ( varName ==
"WsContent" ) {
123 WsApp->setContent(pContent);
124 std::string overflow;
125 std::string sHomePage;
126 bool bUseLayout =
false;
127 for (
int count = 0; count < args.size(); ++count) {
130 gdcore_string_split(args[count].toUTF8(), attr, val,
'=');
131 if ( attr ==
"useLayout" && val ==
"true" )
133 if ( attr ==
"homePage" )
135 if ( attr ==
"overflow" )
139 if ( overflow ==
"auto" )
140 pContent->setOverflow(WContainerWidget::OverflowAuto);
143 bindWidget(varName, pContent);
144 if ( sHomePage.size() > 0 )
146 return WTemplate::resolveString(varName, args, result);
149 std::string moduleName =
"WsTemplate";
150 if ( varName.compare(0, moduleName.size(), moduleName) == 0 ) {
151 std::string templateFile;
152 std::string templateClass;
153 for (
int count = 0; count < args.size(); ++count) {
156 gdcore_string_split(args[count].toUTF8(), attr, val,
'=');
157 if ( attr ==
"templateFile" )
159 if ( attr ==
"templateClass" )
162 if ( templateFile.size() > 0 ) {
164 if ( templateClass.size() > 0 )
165 pTemplate->addStyleClass(templateClass);
167 bindWidget(varName, pTemplate);
169 return WTemplate::resolveString(varName, args, result);
172 std::string m_sDocumentRoot = pUser->
getRootPath();
173 std::string m_httpDocumentRoot = gdWApp->getParameter(
"DOCUMENT_ROOT",
"/var/www");
174 std::string m_sRelativeDocumentRoot = m_sDocumentRoot;
175 boost::algorithm::replace_first(m_sRelativeDocumentRoot, m_httpDocumentRoot,
"");
176 std::string sysPath(m_sDocumentRoot + wApp->internalPath());
177 for (
int iModule = 0; iModule <
WsApp->WsModules().modules().size(); ++iModule) {
178 WsModule* curModule =
WsApp->WsModules().modules()[iModule]->module;
182 gdcore_string_split(varName, moduleName, right,
'_');
183 if ( curModule->
moduleName() != moduleName )
continue;
188 for (
int count = 0; count < args.size(); ++count) {
191 gdcore_string_split(args[count].toUTF8(), attr, val,
'=');
196 bindWidget(varName, w);
199 return WTemplate::resolveString(varName, args, result);
WsTemplate(const std::string &templateFile, const std::string &initialPath=std::string(), Wt::WContainerWidget *parent=0)
Wt::WWidget * resolveWidget(const std::string &varName)
std::string m_sInitialPath
void setPath(std::string newPath)
void setDiffPath(const std::string &diffPath)
Set/Get the difference between the web server (example Apache /var/www) root path and the wittishare ...
Interface that provides differents methods for accessing the FsTree as well as other features...
const std::string PathToTemplates
virtual Wt::WWidget * createContents(Wt::WContainerWidget *parent=0) const =0
Create the contents.
const std::string & moduleName() const
void setOption(const std::string &attribute, boost::any value)
Set an options if previously set, update the value.
const std::string getRootPath()
return the root path of the filesystem tree, example : /var/www/demo_site
#define WsApp
Define a shortcut to the application instance.
static WsLayoutProperties * instance()
Get the singleton instance.
void resolveString(const std::string &varName, const std::vector< Wt::WString > &args, std::ostream &result)
void setSysPath(const std::string &sysPath)
Set/Get the system path (example the selected file /var/www/mysite/about/me.fhtml).
std::string matchTemplate(const std::string &templateFile)