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