12 #include <boost/filesystem/operations.hpp>
20 #include <Wt/WResource>
32 : WContainerWidget(parent), m_bDebug(false)
38 : WContainerWidget(parent), m_bDebug(false), m_sCurPath(path)
48 WContainerWidget::load();
49 addStyleClass(
"WsMenu");
56 std::string rootPath = asString(
option(
"rootPath")).toUTF8();
57 boost::algorithm::replace_all(rootPath,
"&",
"&");
59 if ( rootPath.size() < 1 )
63 std::string sWithoutPrefix =
WsApp->WsModules().pathWithoutPrefix(
m_sCurPath);
66 if ( !tmpNode.get() ) {
67 wApp->log(
"notice") <<
"WsMenu::doLoadCurPath - eatPath return NULL ";
70 if ( tmpNode.get()->isRegularFile() ) {
71 tmpNode = pUser->
getAccessRoot().get()->eatPath(boost::filesystem::path(sWithoutPrefix).parent_path().
string());
72 if ( !tmpNode.get() ) {
73 wApp->log(
"notice") <<
"WsMenu::doLoadCurPath - eatPath on parent return NULL ";
78 if ( !startNode.get() ) {
79 wApp->log(
"notice") <<
"WsMenu::doLoadCurPath - startNode = " << startNode;
82 NodePtr pNode = startNode.get()->eatPath(tmpNode.get()->getPath().string());
83 if ( !pNode.get() )
return;
84 if ( asString(
option(
"useTitle")) ==
"true" ) {
85 std::string sTitle(pNode.get()->getDisplayName());
86 boost::algorithm::replace_all(sTitle,
"&",
"&");
87 WText* title =
new WText(sTitle);
88 title->addStyleClass(
"WsMenuTitle");
91 WMenu* menuParent = 0;
92 if ( asString(
option(
"useButtons")) !=
"true" )
93 menuParent =
new WMenu(
this);
94 if ( asString(
option(
"showRoot")) ==
"true" )
95 if ( pNode.get()->getPath() ==
"/" ) {
99 if ( asString(
option(
"useImages")) ==
"true" )
105 std::vector<NodePtr> dirNode = pNodeParent.get()->getAll();
106 for (std::vector<NodePtr>::iterator it = dirNode.begin(); it != dirNode.end(); ++it) {
108 if(curNode.get()->getDisplayInMenu())
115 std::string path2Icon;
117 std::string sIcon = curNode.get()->getProperties().get()->get(
"global",
"icon",
"");
118 if ( sIcon.size() > 1 ) {
120 if ( tmpNode.get()->isRegularFile() )
121 tmpNode = curNode.get()->getParent();
122 if ( tmpNode.get() ) {
123 path2Icon = tmpNode.get()->getFullPath().string() +
"/ws.res/icones/" + sIcon;
124 if ( !boost::filesystem::exists(path2Icon) )
127 boost::algorithm::replace_first(path2Icon,
WsApp->docRoot(),
"");
131 if ( asString(
option(
"useButtons")) ==
"true" ) {
132 if ( curNode.get()->getPath().string() !=
"/" )
133 if ( asString(
option(
"useSeparator")) ==
"true" ) {
134 WText* pText =
new WText(
"|",
this);
135 pText->addStyleClass(
"WsMenuSep");
137 WPushButton* button =
new WPushButton(curNode.get()->getDisplayName(
true),
this);
139 if ( path2Icon.size() > 1 ) {
140 button->setIcon(WLink(WLink::Url, path2Icon));
141 if ( curNode.get()->getProperties().get()->get(
"global",
"button_text",
"true") ==
"false" )
145 if ( (curNode.get()->isDirectory() && asString(
option(
"directorySelectable")) ==
"true") ||
147 (asString(
option(
"showRoot")) ==
"true" && curNode.get()->getPath() ==
"/")
149 button->setLink(WLink(WLink::InternalPath, curNode.get()->getPath().string()));
151 if ( curNode.get()->isRegularFile() ) {
152 button->setLink(
makeLink(curNode.get()->getPath().string(),
false));
153 if ( button->link().type() == WLink::Url )
154 button->setLinkTarget(TargetNewWindow);
156 bool popupAllowed = (curNode.get()->getProperties().get()->get(
"global",
"allow_popup",
"true") ==
"true" ?
true :
false);
157 if ( curNode.get()->isDirectory() && popupAllowed && asString(
option(
"usePopupMenu")) ==
"true" ) {
158 if ( !(asString(
option(
"noRootPopup")) ==
"true" && curNode.get()->getPath() ==
"/") ) {
159 WPopupMenu* pPopup =
new WPopupMenu();
160 pPopup->addStyleClass(
"wt-no-reparent");
167 button->setMenu(pPopup);
168 pPopup->setAutoHide(
true);
170 button->setMouseOverDelay(50);
174 if ( curNode.get()->getPath().string() !=
"/" )
175 menuParent->addSeparator();
176 WMenuItem* pItem = menuParent->addItem(curNode.get()->getDisplayName(
true));
177 pItem->setLink(WLink(WLink::InternalPath, curNode.get()->getPath().string()));
178 if ( path2Icon.size() > 1 )
179 pItem->setIcon(path2Icon);
180 if ( curNode.get()->isDirectory() && asString(
option(
"usePopupMenu")) ==
"true" )
181 if ( curNode.get()->getDirectories().size() ) {
182 WPopupMenu* pPopup =
new WPopupMenu();
183 pPopup->addStyleClass(
"wt-no-reparent");
185 pItem->setMenu(pPopup);
192 if ( !pButton )
return;
193 if ( !pButton->menu() )
return;
194 WPopupMenu* pPopup =
dynamic_cast<WPopupMenu*
>(pButton->menu());
195 if ( asString(
option(
"align")) ==
"right" )
196 pPopup->popup(pButton, Wt::Horizontal);
198 pPopup->popup(pButton, Wt::Vertical);
203 std::vector<NodePtr> dirNode = pNodeParent->getAll();
204 for (std::vector<NodePtr>::iterator it = dirNode.begin(); it != dirNode.end(); ++it) {
206 if(!curNode.get()->getDisplayInMenu())
208 bool popupAllowed = (curNode.get()->getProperties().get()->get(
"global",
"allow_popup",
"true") ==
"true" ?
true :
false);
209 if ( curNode.get()->isDirectory() && popupAllowed ) {
210 WPopupMenu* pSubPopupMenu =
new WPopupMenu();
212 WMenuItem* pMenuItem = menuParent->addMenu(curNode.get()->getDisplayName(
true), pSubPopupMenu);
213 if ( asString(
option(
"directorySelectable")) ==
"true" )
214 pMenuItem->setLink(WLink(WLink::InternalPath, curNode.get()->getPath().string()));;
216 WPopupMenuItem* pPopupItem = menuParent->addItem(curNode.get()->getDisplayName(
true));
217 pPopupItem->setLink(
makeLink(curNode.get()->getPath().string(),
true));
218 if ( pPopupItem->link().type() == WLink::Url )
219 pPopupItem->setLinkTarget(TargetNewWindow);
227 std::string m_sDocumentRoot = pUser->
getRootPath();
228 std::string m_httpDocumentRoot = gdWApp->getParameter(
"DOCUMENT_ROOT",
"/var/www");
229 std::string m_sRelativeDocumentRoot = m_sDocumentRoot;
230 boost::algorithm::replace_first(m_sRelativeDocumentRoot, m_httpDocumentRoot,
"");
232 std::string strExt(boost::filesystem::extension(path));
233 if ( strExt ==
"" || strExt ==
".fhtml" || strExt ==
".rpg" || strExt ==
".itpl" || strExt ==
".form" || strExt ==
".youtube" )
234 lnk.setInternalPath(path);
236 if ( strExt ==
".url" ) {
237 boost::filesystem::path urlFile(m_sDocumentRoot + path);
239 std::ifstream f(urlFile.string().c_str());
240 std::getline(f, sUrl);
241 boost::algorithm::replace_all(sUrl,
"link=",
"");
244 lnk.setUrl(m_sRelativeDocumentRoot + path);
252 std::string curDir = pNodeParent->getFullPath().string() + endPath;
253 if ( !boost::filesystem::exists(curDir) )
return;
256 long delay = asNumber(
option(
"image_delay"));
259 pImg->
setOption(
"imageInBackground",
true);
260 pImg->
setOption(
"reactWhenPathChange",
false);
263 std::string curPathUrl = curDir;
264 boost::algorithm::replace_first(curPathUrl, wApp->docRoot(),
"");
265 pImg->
setOption(
"imagesPath", std::string(curPathUrl));
267 if ( !pImg->
count() ) {
269 WApplication::instance()->log(
"notice") <<
"WsMenu::load : has no images path = " << pNodeParent->getPath().string();
277 if ( asString(
option(
"useInternalPath")) ==
"true" ) {
291 if ( lnk.type() == Wt::WLink::InternalPath ) curPath = lnk.internalPath().toUTF8();
294 if ( curPath.compare(0, curPath.size(), newPath) != 0 )
continue;
const std::string PathToImages
boost::shared_ptr< WsAbstractNode > NodePtr
void build()
Build the vector.
const std::vector< WsOption > & options() const
Get all options.
Interface that provides differents methods for accessing the FsTree as well as other features...
int count()
Return the number of images.
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 setOptions(const std::vector< WsOption > &vOptions)
Set all options.
NodePtr getAccessRoot()
return the root node of the access tree starting from the root
a wittyShare class that render images randomly