12 #include <boost/algorithm/string/replace.hpp>
13 #include <boost/filesystem.hpp>
22 #include <gdcore/gdCore.h>
36 void* hndl = dlopen(
"libwt.so", RTLD_NOW | RTLD_GLOBAL);
38 fprintf(stderr,
"cannot load libwt.so shared library! %s\n", dlerror());
49 : WContainerWidget(parent)
51 addStyleClass(
"WsLinksList");
60 Wt::WContainerWidget::load();
61 std::string sClass = asString(
option(
"class")).toUTF8();
62 if ( sClass.size() > 0 )
63 addStyleClass(sClass);
64 std::string title = asString(
option(
"title")).toUTF8();
65 if ( title.size() > 0 ) {
66 WText* pText =
new WText(title);
67 pText->addStyleClass(
"WsTitle");
70 std::string linkType = asString(
option(
"linkType")).toUTF8();
71 std::string link = asString(
option(
"link")).toUTF8();
72 std::string text = asString(
option(
"text")).toUTF8();
73 std::string icon = asString(
option(
"icon")).toUTF8();
74 std::string iconText = asString(
option(
"iconText")).toUTF8();
75 std::string target = asString(
option(
"target")).toUTF8();
76 if ( linkType.size() < 1 ) linkType =
"InternalPath";
79 std::string rootUrl = fullRootPath;
80 boost::replace_all(rootUrl, wApp->docRoot(),
"");
82 std::string sWithoutPrefix =
WsApp->WsModules().pathWithoutPrefix(path);
83 std::string rootPath = asString(
option(
"rootPath")).narrow();
84 boost::algorithm::replace_all(rootPath,
"&",
"&");
85 if ( rootPath.size() < 1 ) rootPath = path;
88 LOG(
ERROR) <<
"WsLinksList::load() cannot get root !";
91 NodePtr startNode = root->eatPath(rootPath);
92 if (startNode.get() == 0) {
93 LOG(
ERROR) <<
"WsLinksList::load() cannot eatPath !" << rootPath;
96 std::vector<NodePtr> dirNode = startNode.get()->getFiles();
97 for (std::vector<NodePtr>::iterator it = dirNode.begin(); it != dirNode.end(); ++it) {
99 boost::filesystem::path path(curNode.get()->getPath());
100 if ( ! ( path.extension() ==
".jpeg"
101 || path.extension() ==
".jpg"
102 || path.extension() ==
".png"
104 if ( curNode.get()->isDirectory() )
continue;
105 std::string pngPath = curNode.get()->getPath().string();
106 boost::filesystem::path pdfFile = pngPath;
107 pdfFile.replace_extension(
".pdf");
108 std::string sFileObject = pdfFile.string();
109 if ( sFileObject.size() < 1 )
continue;
110 std::string linkType =
"InternalPath";
112 NodePtr pNode = root->eatPath(sFileObject);
113 if ( !pNode.get() ) {
114 pdfFile.replace_extension(
".zip");
115 sFileObject = pdfFile.string();
116 pNode = root->eatPath(sFileObject);
117 if ( !pNode.get() ) {
118 pdfFile.replace_extension(
".url");
119 sFileObject = pdfFile.string();
120 pNode = root->eatPath(sFileObject);
123 std::string conct = fullRootPath + sFileObject;
124 std::ifstream f(conct.c_str());
125 std::getline(f, sUrl);
126 boost::algorithm::replace_all(sUrl,
"link=",
"");
131 std::string sShortDesc = pNode.get()->getProperties().get()->get(
"global",
"short_description",
"");
132 WsAnchor* pAnchor =
dynamic_cast<WsAnchor*
>(
WsApp->WsModules().module(
"WsModAnchor")->createContents());
134 pAnchor->
setOption(
"linkType", linkType);
136 bool bUseExt =
false;
137 if ( asString(
option(
"useExt")) ==
"true" ) bUseExt =
true;
138 if ( asString(
option(
"useText")) ==
"false" )
139 pAnchor->
setOption(
"text", std::string());
141 pAnchor->
setOption(
"text", pNode.get()->getDisplayName(bUseExt));
142 pAnchor->
setOption(
"icon", std::string(rootUrl + pngPath));
143 if ( asString(
option(
"useText")) ==
"false" )
144 pAnchor->
setOption(
"iconText", std::string());
146 pAnchor->
setOption(
"iconText", pNode.get()->getDisplayName(bUseExt));
147 pAnchor->
setOption(
"target", std::string(
"TargetNewWindow"));
148 if ( asString(
option(
"useShortDesc")) ==
"false" )
149 pAnchor->
setOption(
"title", std::string());
199 return "WsModLinksList wittyShare module";
boost::shared_ptr< WsAbstractNode > NodePtr
static WsApplication * wsInstance()
Facility function to access the application object.
Wt::WWidget * createContentsMenuBar(Wt::WContainerWidget *parent=0) const
Create the functionalities.
WsEditorWidget * createEditor(Wt::WContainerWidget *parent=0) const
Create the contents for an editor (create a view of options).
const std::vector< WsOption > & options() const
Get all options.
Interface that provides differents methods for accessing the FsTree as well as other features...
WsLinksList(Wt::WContainerWidget *parent=0)
CTor.
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.
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.
void WsModLinksListInit(void)
void setOptions(const std::vector< WsOption > &vOptions)
Set all options.
Wt::WWidget * createContents(Wt::WContainerWidget *parent=0) const
Create the contents.
std::string description() const
Return the description of the module.
NodePtr getAccessRoot()
return the root node of the access tree starting from the root
Wt::WWidget * createAdmin(Wt::WContainerWidget *parent=0) const
Create the contents for an administrator.