2012-06-14 06:06:06 -07:00
|
|
|
|
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
2012-09-23 15:09:57 -07:00
|
|
|
#include "WebPlugin.h"
|
|
|
|
#include "WebAdmin.h"
|
|
|
|
#include "Server.h"
|
|
|
|
#include "Root.h"
|
2012-06-14 06:06:06 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-22 07:22:21 -07:00
|
|
|
cWebPlugin::cWebPlugin()
|
2012-06-14 06:06:06 -07:00
|
|
|
{
|
2013-01-11 20:46:01 -08:00
|
|
|
cWebAdmin * WebAdmin = cRoot::Get()->GetWebAdmin();
|
|
|
|
if (WebAdmin != NULL)
|
|
|
|
{
|
|
|
|
WebAdmin->AddPlugin(this);
|
|
|
|
}
|
2012-06-14 06:06:06 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 07:22:21 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-14 06:06:06 -07:00
|
|
|
cWebPlugin::~cWebPlugin()
|
|
|
|
{
|
2013-01-11 20:46:01 -08:00
|
|
|
cWebAdmin * WebAdmin = cRoot::Get()->GetWebAdmin();
|
|
|
|
if (WebAdmin != NULL)
|
|
|
|
{
|
|
|
|
WebAdmin->RemovePlugin(this);
|
|
|
|
}
|
2012-08-22 07:22:21 -07:00
|
|
|
|
2013-01-11 20:46:01 -08:00
|
|
|
for (TabList::iterator itr = m_Tabs.begin(); itr != m_Tabs.end(); ++itr)
|
2012-08-22 07:22:21 -07:00
|
|
|
{
|
|
|
|
delete *itr;
|
|
|
|
}
|
|
|
|
m_Tabs.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-01-11 20:46:01 -08:00
|
|
|
std::list<std::pair<AString, AString> > cWebPlugin::GetTabNames(void)
|
2012-08-22 07:22:21 -07:00
|
|
|
{
|
2012-08-22 16:29:15 -07:00
|
|
|
std::list< std::pair< AString, AString > > NameList;
|
2012-08-22 07:22:21 -07:00
|
|
|
for( TabList::iterator itr = GetTabs().begin(); itr != GetTabs().end(); ++itr )
|
|
|
|
{
|
2012-08-22 16:29:15 -07:00
|
|
|
std::pair< AString, AString > StringPair;
|
2012-08-22 07:22:21 -07:00
|
|
|
StringPair.first = (*itr)->Title;
|
|
|
|
StringPair.second = (*itr)->SafeTitle;
|
|
|
|
NameList.push_back( StringPair );
|
|
|
|
}
|
|
|
|
return NameList;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-01-11 20:46:01 -08:00
|
|
|
std::pair< AString, AString > cWebPlugin::GetTabNameForRequest(HTTPRequest * a_Request)
|
2012-08-22 07:22:21 -07:00
|
|
|
{
|
2012-08-22 16:29:15 -07:00
|
|
|
std::pair< AString, AString > Names;
|
2012-08-22 07:22:21 -07:00
|
|
|
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 )
|
|
|
|
{
|
2012-08-22 16:29:15 -07:00
|
|
|
AString RetVal;
|
2012-08-22 07:22:21 -07:00
|
|
|
for( unsigned int i = 0; i < a_String.size(); ++i )
|
|
|
|
{
|
|
|
|
char c = a_String[i];
|
|
|
|
if( c == ' ' )
|
|
|
|
{
|
|
|
|
c = '_';
|
|
|
|
}
|
|
|
|
RetVal.push_back( c );
|
|
|
|
}
|
|
|
|
return RetVal;
|
2011-10-03 11:41:19 -07:00
|
|
|
}
|