Files
cuberite-2a/src/Bindings/WebPlugin.cpp
T

119 lines
1.9 KiB
C++
Raw Normal View History

#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "WebPlugin.h"
#include "../WebAdmin.h"
#include "../Root.h"
2012-08-22 14:22:21 +00:00
cWebPlugin::cWebPlugin()
{
cWebAdmin * WebAdmin = cRoot::Get()->GetWebAdmin();
2014-10-20 21:55:07 +01:00
if (WebAdmin != nullptr)
{
WebAdmin->AddPlugin(this);
}
}
2012-08-22 14:22:21 +00:00
cWebPlugin::~cWebPlugin()
{
cWebAdmin * WebAdmin = cRoot::Get()->GetWebAdmin();
2014-10-20 21:55:07 +01:00
if (WebAdmin != nullptr)
{
WebAdmin->RemovePlugin(this);
}
2012-08-22 14:22:21 +00:00
for (TabList::iterator itr = m_Tabs.begin(); itr != m_Tabs.end(); ++itr)
2012-08-22 14:22:21 +00:00
{
delete *itr;
}
m_Tabs.clear();
}
std::list<std::pair<AString, AString> > cWebPlugin::GetTabNames(void)
2012-08-22 14:22:21 +00:00
{
std::list< std::pair< AString, AString > > NameList;
for (TabList::iterator itr = GetTabs().begin(); itr != GetTabs().end(); ++itr)
2012-08-22 14:22:21 +00:00
{
std::pair< AString, AString > StringPair;
2012-08-22 14:22:21 +00:00
StringPair.first = (*itr)->Title;
StringPair.second = (*itr)->SafeTitle;
NameList.push_back( StringPair);
2012-08-22 14:22:21 +00:00
}
return NameList;
}
2013-07-29 02:37:59 +02:00
std::pair< AString, AString > cWebPlugin::GetTabNameForRequest(const HTTPRequest * a_Request)
2012-08-22 14:22:21 +00:00
{
std::pair< AString, AString > Names;
2012-08-22 14:22:21 +00:00
AStringVector Split = StringSplit(a_Request->Path, "/");
2014-07-17 22:50:58 +02:00
if (Split.size() > 1)
2012-08-22 14:22:21 +00:00
{
2014-10-20 21:55:07 +01:00
sWebPluginTab * Tab = nullptr;
2014-07-17 22:50:58 +02:00
if (Split.size() > 2) // If we got the tab name, show that page
2012-08-22 14:22:21 +00:00
{
for (TabList::iterator itr = GetTabs().begin(); itr != GetTabs().end(); ++itr)
2012-08-22 14:22:21 +00:00
{
2014-07-17 22:50:58 +02:00
if ((*itr)->SafeTitle.compare(Split[2]) == 0) // This is the one!
2012-08-22 14:22:21 +00:00
{
Tab = *itr;
break;
}
}
}
2014-07-17 22:50:58 +02:00
else // Otherwise show the first tab
2012-08-22 14:22:21 +00:00
{
if (GetTabs().size() > 0)
2014-08-04 13:20:16 +02:00
{
2012-08-22 14:22:21 +00:00
Tab = *GetTabs().begin();
2014-08-04 13:20:16 +02:00
}
2012-08-22 14:22:21 +00:00
}
2014-10-20 21:55:07 +01:00
if (Tab != nullptr)
2012-08-22 14:22:21 +00:00
{
Names.first = Tab->Title;
Names.second = Tab->SafeTitle;
}
}
return Names;
}
2014-07-17 22:50:58 +02:00
AString cWebPlugin::SafeString(const AString & a_String)
2012-08-22 14:22:21 +00:00
{
AString RetVal;
for (unsigned int i = 0; i < a_String.size(); ++i)
2012-08-22 14:22:21 +00:00
{
char c = a_String[i];
if (c == ' ')
2012-08-22 14:22:21 +00:00
{
c = '_';
}
RetVal.push_back( c);
2012-08-22 14:22:21 +00:00
}
return RetVal;
}
2014-07-17 22:50:58 +02:00