From ecfe6ab65bd1fc2c7f5733fe6ef4e6ddaac44a26 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Sun, 23 Sep 2012 22:09:57 +0000 Subject: Source files cleanup: The rest of the files renamed. git-svn-id: http://mc-server.googlecode.com/svn/trunk@887 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/WebPlugin.cpp | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 source/WebPlugin.cpp (limited to 'source/WebPlugin.cpp') diff --git a/source/WebPlugin.cpp b/source/WebPlugin.cpp new file mode 100644 index 000000000..93619ef14 --- /dev/null +++ b/source/WebPlugin.cpp @@ -0,0 +1,109 @@ + +#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() +{ + LOG("cWebPlugin::cWebPlugin()"); + cWebAdmin* WebAdmin = cRoot::Get()->GetWebAdmin(); + if( WebAdmin ) WebAdmin->AddPlugin( this ); +} + + + + + +cWebPlugin::~cWebPlugin() +{ + LOG("~cWebPlugin::cWebPlugin()"); + cWebAdmin* WebAdmin = cRoot::Get()->GetWebAdmin(); + if( WebAdmin ) WebAdmin->RemovePlugin( this ); + + for( TabList::iterator itr = m_Tabs.begin(); itr != m_Tabs.end(); ++itr ) + { + delete *itr; + } + m_Tabs.clear(); +} + + + + + +std::list< std::pair > cWebPlugin::GetTabNames() +{ + 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( 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 -- cgit v1.2.3