summaryrefslogtreecommitdiffstats
path: root/src/Bindings/WebPlugin.cpp
blob: 1178c127af602d30a4ee4ac15ef2772da30784da (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117

#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 = NULL;
		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!
				{
					Tab = *itr;
					break;
				}
			}
		}
		else  // Otherwise show the first tab
		{
			if (GetTabs().size() > 0)
				Tab = *GetTabs().begin();
		}

		if (Tab != NULL)
		{
			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;
}