summaryrefslogtreecommitdiffstats
path: root/src/WebPlugin.cpp
diff options
context:
space:
mode:
authorAlexander Harkness <bearbin@gmail.com>2013-11-24 15:19:41 +0100
committerAlexander Harkness <bearbin@gmail.com>2013-11-24 15:19:41 +0100
commit675b4aa878f16291ce33fced48a2bc7425f635ae (patch)
tree409914df27a98f65adf866da669429c4de141b6f /src/WebPlugin.cpp
parentLineBlockTracer: Using the coord-based block faces. (diff)
downloadcuberite-675b4aa878f16291ce33fced48a2bc7425f635ae.tar
cuberite-675b4aa878f16291ce33fced48a2bc7425f635ae.tar.gz
cuberite-675b4aa878f16291ce33fced48a2bc7425f635ae.tar.bz2
cuberite-675b4aa878f16291ce33fced48a2bc7425f635ae.tar.lz
cuberite-675b4aa878f16291ce33fced48a2bc7425f635ae.tar.xz
cuberite-675b4aa878f16291ce33fced48a2bc7425f635ae.tar.zst
cuberite-675b4aa878f16291ce33fced48a2bc7425f635ae.zip
Diffstat (limited to 'src/WebPlugin.cpp')
-rw-r--r--src/WebPlugin.cpp113
1 files changed, 113 insertions, 0 deletions
diff --git a/src/WebPlugin.cpp b/src/WebPlugin.cpp
new file mode 100644
index 000000000..48ddb2076
--- /dev/null
+++ b/src/WebPlugin.cpp
@@ -0,0 +1,113 @@
+
+#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
+
+#include "WebPlugin.h"
+#include "WebAdmin.h"
+#include "Server.h"
+#include "Root.h"
+
+
+
+
+
+cWebPlugin::cWebPlugin()
+{
+ cWebAdmin * WebAdmin = cRoot::Get()->GetWebAdmin();
+ if (WebAdmin != NULL)
+ {
+ WebAdmin->AddPlugin(this);
+ }
+}
+
+
+
+
+
+cWebPlugin::~cWebPlugin()
+{
+ cWebAdmin * WebAdmin = cRoot::Get()->GetWebAdmin();
+ if (WebAdmin != NULL)
+ {
+ WebAdmin->RemovePlugin(this);
+ }
+
+ for (TabList::iterator itr = m_Tabs.begin(); itr != m_Tabs.end(); ++itr)
+ {
+ delete *itr;
+ }
+ m_Tabs.clear();
+}
+
+
+
+
+
+std::list<std::pair<AString, AString> > cWebPlugin::GetTabNames(void)
+{
+ std::list< std::pair< AString, AString > > NameList;
+ for( TabList::iterator itr = GetTabs().begin(); itr != GetTabs().end(); ++itr )
+ {
+ std::pair< AString, AString > StringPair;
+ StringPair.first = (*itr)->Title;
+ StringPair.second = (*itr)->SafeTitle;
+ NameList.push_back( StringPair );
+ }
+ return NameList;
+}
+
+
+
+
+
+std::pair< AString, AString > cWebPlugin::GetTabNameForRequest(const HTTPRequest * a_Request)
+{
+ std::pair< AString, AString > Names;
+ AStringVector Split = StringSplit(a_Request->Path, "/");
+
+ if( Split.size() > 1 )
+ {
+ sWebPluginTab* Tab = 0;
+ if( Split.size() > 2 ) // If we got the tab name, show that page
+ {
+ for( TabList::iterator itr = GetTabs().begin(); itr != GetTabs().end(); ++itr )
+ {
+ if( (*itr)->SafeTitle.compare( Split[2] ) == 0 ) // This is the one! Rawr
+ {
+ Tab = *itr;
+ break;
+ }
+ }
+ }
+ else // Otherwise show the first tab
+ {
+ if( GetTabs().size() > 0 )
+ Tab = *GetTabs().begin();
+ }
+
+ if( Tab )
+ {
+ Names.first = Tab->Title;
+ Names.second = Tab->SafeTitle;
+ }
+ }
+
+ return Names;
+}
+
+
+
+
+AString cWebPlugin::SafeString( const AString & a_String )
+{
+ AString RetVal;
+ for( unsigned int i = 0; i < a_String.size(); ++i )
+ {
+ char c = a_String[i];
+ if( c == ' ' )
+ {
+ c = '_';
+ }
+ RetVal.push_back( c );
+ }
+ return RetVal;
+} \ No newline at end of file