Wittyshare  0.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
WsBanners.cpp
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2006-Today Guy Deleeuw
3 *
4 * See the LICENSE file for terms of use.
5 */
6 
7 #include <dlfcn.h>
8 #include <stdio.h>
9 
10 #include <iostream>
11 
12 #include <boost/filesystem/operations.hpp>
13 
14 #include <Include/WsGlobalConfig.h>
15 
16 #include <Wt/WLogger>
17 #include <Wt/WTheme>
18 #include <Wt/WText>
19 
20 #include <Main/WsApplication.h>
21 
22 // TODO : pas top je sais
24 
25 #include "WsBanners.h"
26 
27 WsBanners::WsBanners(WContainerWidget* parent)
28  : WContainerWidget(parent)
29 {
30  addStyleClass("WsBanners");
31 }
32 
34 {
35  WContainerWidget::load();
36  if ( Wt::asString(option("useInternalPath")) == "true" ) {
37  wApp->internalPathChanged().connect(SLOT(this, WsBanners::doPathChanged));
38  }
39  doPathChanged(wApp->internalPath());
40 }
41 
42 void WsBanners::doPathChanged(std::string newPath)
43 {
44  clear();
45  std::string sPathWithoutPrefix = WsApp->WsModules().pathWithoutPrefix(newPath); // ex. /SiteMap
46  WsUser* pUser = WsApp->wsUser();
47  boost::filesystem::path root = pUser->getRootPath();
48  std::string sCurrent = root.string() + sPathWithoutPrefix; // root.string() retourne un / a la fin ?
49  NodePtr startNode = pUser->getAccessRoot();
50  std::string imgPath = Wt::asString(option("imagesPath")).toUTF8();
51  boost::algorithm::replace_all(imgPath, "&amp;", "&");
52  if ( imgPath.size() > 0 ) {
53  WsImages2* pImg = new WsImages2(this);
54  pImg->setOptions(options());
55  std::string s = root.string() + imgPath;
56  boost::replace_all(s, wApp->docRoot(), "");
57  pImg->setOption("imagesPath", s); // TODO : move this to WsImages2
58  pImg->build();
59  pImg->load();
60  addWidget(pImg);
61  return;
62  }
63  boost::replace_all(sCurrent, "//", "/");
64  boost::filesystem::path current(sCurrent);
65  // Check that the path is a directory, if not take the parent
66  if ( !boost::filesystem::is_directory(current) )
67  current = current.parent_path();
68  while (1) {
69  sCurrent = current.string() + "/ws.res/images/WsBanners";
70  boost::replace_all(sCurrent, "//", "/");
71  boost::filesystem::path banners(sCurrent);
72  // Check if the current directory has a sub directory ws.res/images/WsBanners
73  if ( boost::filesystem::is_directory(banners) ) {
74  boost::filesystem::directory_iterator end_itr;
75  for (boost::filesystem::directory_iterator itr_dir(banners); itr_dir != end_itr; ++itr_dir) {
76  if ( ( itr_dir->path().extension() == ".jpeg"
77  || itr_dir->path().extension() == ".jpg"
78  || itr_dir->path().extension() == ".png"
79  ) ) {
80  string str_bann = banners.string();
81  boost::replace_all(str_bann, "//", "/");
82  boost::replace_all(str_bann, WsApp->docRoot(), "");
83  WsImages2* pImg = new WsImages2(this);
84  pImg->setOptions(options());
85  pImg->setOption("imagesPath", str_bann);
86  pImg->build();
87  pImg->load();
88  addWidget(pImg);
89  return;
90  }
91  }
92  }
93  if (current == root) break;
94  //
95  // Check if the current directory allow up to parrent on the banners
96  std::string noRoot = current.string();
97  boost::replace_all(noRoot, root.string(), "");
98  NodePtr currentNode = startNode.get()->eatPath(noRoot);
99  if ( currentNode )
100  if ( currentNode.get()->getProperties().get()->get("global", "banners_up", "true") == "false" ) break;
101  current = current.parent_path();
102  }
103  wApp->log("notice") << "WsBanners::doPathChanged() NO Image(s) found";
104 }
105 
boost::shared_ptr< WsAbstractNode > NodePtr
void build()
Build the vector.
Definition: WsImages2.cpp:96
virtual void load()
Load the widget (traditional wt virtual function).
Definition: WsImages2.cpp:78
void load()
Definition: WsBanners.cpp:33
const std::vector< WsOption > & options() const
Get all options.
Definition: WsOption.cpp:70
Interface that provides differents methods for accessing the FsTree as well as other features...
Definition: WsUser.h:33
WsBanners(Wt::WContainerWidget *parent=0)
Definition: WsBanners.cpp:27
void setOption(const std::string &attribute, boost::any value)
Set an options if previously set, update the value.
Definition: WsOption.cpp:47
const boost::any & option(const std::string &attribute) const
Get an options value.
Definition: WsOption.cpp:62
const std::string getRootPath()
return the root path of the filesystem tree, example : /var/www/demo_site
Definition: WsUser.cpp:55
#define WsApp
Define a shortcut to the application instance.
Definition: WsApplication.h:62
void setOptions(const std::vector< WsOption > &vOptions)
Set all options.
Definition: WsOption.cpp:57
A class that render a menu.
NodePtr getAccessRoot()
return the root node of the access tree starting from the root
Definition: WsUser.cpp:50
void doPathChanged(std::string newPath)
Definition: WsBanners.cpp:42
a wittyShare class that render images randomly