10 #include <boost/algorithm/string/replace.hpp>
11 #include <boost/filesystem/operations.hpp>
12 #include <boost/filesystem/exception.hpp>
13 #include <boost/filesystem/convenience.hpp>
14 #include <boost/thread.hpp>
19 #include <Wt/WOverlayLoadingIndicator>
20 #include <Wt/WVBoxLayout>
21 #include <Wt/WProgressBar>
26 #include <gdcore/gdCore.h>
28 #include <gdwtcore/gdFHtmlEditor.h>
41 : WContainerWidget(parent), m_bLogContent(false), m_bAllowHtmlRendering(false), m_pSiteMapView(0), m_curWForm(0)
44 if ( WString::tr(
"byObjectStyleSheet").narrow() ==
"true" )
45 wApp->useStyleSheet(wApp->theme()->resourcesUrl() +
"wittyshare/Css/WsContent.css");
46 addStyleClass(
"WsContent");
58 wApp->log(
"notice") <<
"WsContent::WsContent wittyshare Document Root = " <<
m_sDocumentRoot
65 WContainerWidget::clear();
72 WContainerWidget::load();
81 addWidget(
WsApp->WsModules().module(
"WsModFileUpload")->createContents());
86 std::string newPath = path;
87 boost::algorithm::replace_first(newPath,
"/Edit",
"");
88 boost::algorithm::replace_first(newPath,
"/SiteMap",
"");
89 std::string sPathWithoutPrefix =
WsApp->WsModules().pathWithoutPrefix(newPath);
98 setOverflow(WContainerWidget::OverflowAuto);
99 WVBoxLayout* vbox =
new WVBoxLayout();
102 vbox->addWidget(m_formConfig, 0);
103 vbox->addWidget(
WsApp->WsModules().module(
"WsModEditorUploader")->createContents());
104 std::string strExt(boost::filesystem::extension(sPathWithoutPrefix));
105 if ( strExt ==
".fhtml" ) {
106 if ( !gdcore_isPathFile(sysPath) )
return;
107 gdFHtmlEditor* pEditor =
new gdFHtmlEditor(
"",
false);
108 pEditor->setCurrentPath(sysPath);
111 pEditor->resize(WLength(100, WLength::Percentage), WLength(400));
112 vbox->addWidget(pEditor, 1);
119 setOverflow(WContainerWidget::OverflowHidden);
121 nTmp |= gdWFileView::tbUseLeftTree;
124 resize(WLength(100, WLength::Percentage), WLength(100, WLength::Percentage));
140 resize(WLength(100, WLength::Percentage), WLength(100, WLength::Percentage));
158 wApp->log(
"notice") <<
"WsContent::viewDirectory() : Path = " << path <<
", getAccessRoot() is null";
161 NodePtr pNode = pRootNode.get()->eatPath(path);
162 if ( !pNode.get() ) {
163 wApp->log(
"notice") <<
"WsContent::viewDirectory() : Path = " << path <<
", getAccessRoot() eatPath is null";
166 std::string sInitPage = pNode.get()->getProperties().get()->get(
"global",
"initial_page",
"");
167 if ( sInitPage.size() > 0 ) {
168 std::string newPage = pNode.get()->getPath().string() +
"/" + sInitPage;
169 wApp->log(
"notice") <<
"WsContent::viewDirectory() : set initial page to " << newPage;
170 return wApp->setInternalPath(newPage,
true);
175 WsApp->hideImages(
false);
176 WWidget* w =
WsApp->WsModules().module(
"WsModDirectoryView2")->createContents();
180 WVBoxLayout* vBox =
new WVBoxLayout();
181 vBox->addWidget(w, 1);
183 setOverflow(WContainerWidget::OverflowHidden);
187 setOverflow(WContainerWidget::OverflowAuto);
193 std::string sPathWithoutPrefix =
WsApp->WsModules().pathWithoutPrefix(newPath);
194 boost::algorithm::replace_all(sPathWithoutPrefix,
"&",
"&");
195 if ( newPath ==
"/" ) newPath =
WsApp->homePage();
197 boost::filesystem::path p(newPath);
198 std::string strExt (p.extension().string());
200 if ( strExt ==
".itpl" ) {
201 sPathWithoutPrefix = p.parent_path().string();
218 if ( newPath ==
"/Logo" ) {
225 }
catch (
string serr) {
226 wApp->log(
"notice") <<
"WsContent::setPath : assign crash : " << newPath <<
" error " << serr;
231 boost::algorithm::replace_first(query,
"/",
"");
234 if ( newPath.compare(0, 8,
"/SiteMap") == 0)
237 if ( newPath.compare(0, 5,
"/Edit") == 0)
244 if ( newPath.compare(0, 11,
"/FileUpload") == 0 )
258 boost::filesystem::path p(path);
259 std::string strExt (p.extension().string());
260 std::string strName(p.stem().string());
261 std::string strFileName(strName + strExt);
262 std::string fileContent;
264 wApp->log(
"notice") <<
"WsContent::selectWidget : path = " << path <<
" name = " << strName <<
" extension = " << strExt <<
" system path = " << sysPath;
266 if ( strExt ==
".nolink" ) {
271 if ( strExt ==
".fhtml" ) {
272 if ( !gdcore_file_content2string(sysPath.c_str(), fileContent) ) {
275 wApp->log(
"notice") <<
"WsContent::selectWidget : cannot open : " << sysPath;
279 wApp->log(
"notice") <<
"WsContent::selectWidget : file " << sysPath <<
" size = " << fileContent.size();
282 if ( strExt ==
".html" ) {
284 wApp->log(
"notice") <<
"WsContent::selectWidget : render a html file : " << sysPath;
290 WsApp->hideImages(
false);
291 WText* pIFrame =
new WText();
292 pIFrame->setTextFormat(XHTMLUnsafeText);
293 pIFrame->setText(
"<iframe src='" +
m_sRelativeDocumentRoot + path +
"' height='98%' width='100%' frameborder='0'></iframe>");
298 if ( strExt ==
".fhtml" ) {
300 WsApp->hideImages(
false);
301 WText* wtext =
new WText();
303 wtext->setTextFormat(Wt::XHTMLUnsafeText);
304 wtext->setText(fileContent);
305 bool bUseLayout =
false;
310 setOverflow(WContainerWidget::OverflowHidden);
311 WContainerWidget* cw =
new WContainerWidget();
312 cw->setOverflow(WContainerWidget::OverflowAuto);
313 cw->addWidget(wtext);
314 WVBoxLayout* vBox =
new WVBoxLayout();
315 vBox->addWidget(cw, 1);
321 if ( strExt ==
".form" ) {
323 wApp->log(
"notice") <<
"WsContent::selectWidget : render a form : " << sysPath;
330 if ( strExt ==
".itpl" ) {
332 wApp->log(
"notice") <<
"WsContent::selectWidget : render an inside template : " << sysPath;
335 addWidget(pTemplate);
339 if ( gdcore_isPathDirectory(sysPath) ) {
341 wApp->log(
"notice") <<
"WsContent::selectWidget : render a directory : " << sysPath;
355 if ( strExt ==
".pdf" ) {
357 wApp->log(
"notice") <<
"WsContent::selectWidget : render a " << strExt <<
" file : " << sysPath;
360 WsApp->hideImages(
false);
361 addWidget(
new WText(
"Download file : " + path +
" ..."));
371 if ( strExt ==
".rss" ) {
373 wApp->log(
"notice") <<
"WsContent::selectWidget : render a " << strExt <<
" file : " << sysPath;
375 WsApp->hideImages(
false);
376 addWidget(
new WText(
"Download file : " + path +
" ..."));
379 for (
int iModule = 0; iModule <
WsApp->WsModules().modules().size(); iModule++) {
380 WsModule* curModule =
WsApp->WsModules().modules()[iModule]->module;
381 if ( curModule->
isLoaded() )
continue;
382 if ( (strExt.size() == 0 && strName == curModule->
fileName()) || (strExt.size() > 0 && strExt == curModule->
extension(strExt)) ) {
384 if ( strExt == curModule->
extension(strExt) )
385 wApp->log(
"notice") <<
"WsContent::selectWidget : module, render a " << strExt <<
" file extension : " << sysPath;
387 wApp->log(
"notice") <<
"WsContent::selectWidget : module, render " << strName <<
" file name: " << sysPath;
394 if ( asString(curModule->
option(
"useLayout")) ==
"true" ) {
395 WVBoxLayout* vbox =
new WVBoxLayout();
396 vbox->addWidget(w, 1);
402 wApp->log(
"notice") <<
"WsContent::selectWidget : module, render " << curModule->
moduleName() <<
" CANNOT call create content: ";
413 std::string str = selectedPath;
414 if ( sigType == gdWFileView::selected )
415 boost::algorithm::replace_first(str,
"/SiteMap",
"");
416 wApp->setInternalPath(str,
true);
void doSiteMapItemSelected(gdWFileView::signalType sigType, std::string selectedPath)
boost::shared_ptr< WsAbstractNode > NodePtr
void setRelativePath(const std::string &relativePath)
int getPermissions(const std::string &p)
return the permissions on specific node
Wt::Signal< gdWFileView::signalType, std::string > & fileSelected()
void siteMapChanged(std::string newPath)
void setPath(std::string newPath)
std::string m_sDocumentRoot
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...
void viewDirectory(const std::string &path)
void doSearch(Wt::WString sSearch)
virtual Wt::WWidget * createContents(Wt::WContainerWidget *parent=0) const =0
Create the contents.
void selectWidget(std::string path)
std::string m_sRelativeDocumentRoot
const std::string & moduleName() const
void setOption(const std::string &attribute, boost::any value)
Set an options if previously set, update the value.
const boost::any & option(const std::string &attribute) const
Get an options value.
std::string m_httpDocumentRoot
const std::string getRootPath()
return the root path of the filesystem tree, example : /var/www/demo_site
const std::string & fileName() const
std::string get(const std::string §ion, const std::string &id, const std::string &def)
#define WsApp
Define a shortcut to the application instance.
static WsLayoutProperties * instance()
Get the singleton instance.
const std::string & extension(const std::string &extension="") const
void setSysPath(const std::string &sysPath)
Set/Get the system path (example the selected file /var/www/mysite/about/me.fhtml).
void doEditPage(std::string path)
NodePtr getAccessRoot()
return the root node of the access tree starting from the root
void buildFileUpload(const std::string &path)
bool m_bAllowHtmlRendering
WsContent(Wt::WContainerWidget *parent=0)
WsSiteMapView * m_pSiteMapView