Add methods to CModule to get the web path

Add these values to the template and use them when linking to any module
This commit is contained in:
Kyle Fuller
2012-02-09 16:55:58 +00:00
parent b1593238d5
commit b1ed9c9b74
14 changed files with 46 additions and 21 deletions
+2
View File
@@ -376,6 +376,8 @@ public:
* @return The Title.
*/
virtual CString GetWebMenuTitle() { return ""; }
virtual CString GetWebPath();
virtual CString GetWebFilesPath();
/** For WebMods: Called before the list of registered SubPages will be checked.
* Important: If you return true, you need to take care of calling WebSock.Close!
* This allows for stuff like returning non-templated data, long-polling and other fun.
+2 -2
View File
@@ -73,11 +73,11 @@ public:
fPemFile.Close();
}
WebSock.Redirect("/mods/cert/");
WebSock.Redirect(GetWebPath());
return true;
} else if (sPageName == "delete") {
CFile::Delete(PemFile());
WebSock.Redirect("/mods/cert/");
WebSock.Redirect(GetWebPath());
return true;
}
+2 -2
View File
@@ -249,7 +249,7 @@ public:
return true;
} else if (sPageName == "add") {
AddKey(pUser, WebSock.GetParam("key"));
WebSock.Redirect("/mods/certauth/");
WebSock.Redirect(GetWebPath());
return true;
} else if (sPageName == "delete") {
MSCString::iterator it = m_PubKeys.find(pUser->GetUserName());
@@ -263,7 +263,7 @@ public:
}
}
WebSock.Redirect("/mods/certauth/");
WebSock.Redirect(GetWebPath());
return true;
}
+2 -2
View File
@@ -1,12 +1,12 @@
<? INC Header.tmpl ?>
<? IF Cert ?>
<p>You already have a certificate set, use the form below to overwrite the current certificate. Alternatively click <a href="/mods/cert/delete">here</a> to <a href="/mods/cert/delete">delete</a> your certificate.</p>
<p>You already have a certificate set, use the form below to overwrite the current certificate. Alternatively click <a href="<? VAR ModPath ?>delete">here</a> to <a href="<? VAR ModPath ?>delete">delete</a> your certificate.</p>
<? ELSE ?>
<p>You do not have a cert.</p>
<? ENDIF ?>
<form method="post" action="/mods/cert/update">
<form method="post" action="<? VAR ModPath ?>update">
<? INC _csrf_check.tmpl ?>
<div class="section">
<h3>Certificate</h3>
+2 -2
View File
@@ -1,6 +1,6 @@
<? INC Header.tmpl ?>
<form method="post" action="/mods/certauth/add">
<form method="post" action="<? VAR ModPath ?>add">
<? INC _csrf_check.tmpl ?>
<div class="section">
<h3>Add A Note</h3>
@@ -32,7 +32,7 @@
<tbody>
<? LOOP KeyLoop ?>
<tr class="<? IF __EVEN__ ?>evenrow<? ELSE ?>oddrow<? ENDIF ?>">
<td>[<a href="/mods/certauth/delete?key=<? VAR Key ESC=URL,HTML ?>">del</a>]</td>
<td>[<a href="<? VAR ModPath ?>delete?key=<? VAR Key ESC=URL,HTML ?>">del</a>]</td>
<td><? VAR Key ?></td>
</tr>
<? ENDLOOP ?>
+2 -2
View File
@@ -17,8 +17,8 @@
<td><? VAR LastSeen DEFAULT="- unknown -" ?></td>
<td><? VAR Info ?></td>
<? IF WebAdminLoaded TOP ?><td><span class="nowrap">
[<a href="/mods/webadmin/edituser?user=<?VAR Username ESC=URL?>">Edit</a>]
<? IF !IsSelf ?>[<a href="/mods/webadmin/deluser?user=<?VAR Username ESC=URL?>">Delete</a>]<? ENDIF ?>
[<a href="/mods/global/webadmin/edituser?user=<?VAR Username ESC=URL?>">Edit</a>]
<? IF !IsSelf ?>[<a href="/mods/global/webadmin/deluser?user=<?VAR Username ESC=URL?>">Delete</a>]<? ENDIF ?>
</span></td><? ENDIF ?>
</tr>
<? ENDLOOP ?>
+2 -2
View File
@@ -1,6 +1,6 @@
<? INC Header.tmpl ?>
<form method="post" action="/mods/notes/addnote">
<form method="post" action="<? VAR ModPath ?>addnote">
<? INC _csrf_check.tmpl ?>
<div class="section">
<h3>Add A Note</h3>
@@ -37,7 +37,7 @@
<tbody>
<? LOOP NotesLoop ?>
<tr class="<? IF __EVEN__ ?>evenrow<? ELSE ?>oddrow<? ENDIF ?>">
<td><a href="/mods/notes/delnote?key=<? VAR Key ESC=URL,HTML ?>"><img src="/modfiles/<? VAR ModName TOP ?>/trash.gif" alt="[del]" /></a></td>
<td><a href="<? VAR ModPath TOP ?>delnote?key=<? VAR Key ESC=URL,HTML ?>"><img src="<? VAR ModFilesPath TOP ?>trash.gif" alt="[del]" /></a></td>
<td><? VAR Key ?></td>
<td><? VAR Note ?></td>
</tr>
+1 -1
View File
@@ -1,6 +1,6 @@
<? INC Header.tmpl ?>
<form method="post" action="/mods/perform/">
<form method="post" action="<? VAR ModPath ?>">
<? INC _csrf_check.tmpl ?>
<div class="section">
<h3>Perform</h3>
+1 -1
View File
@@ -1,6 +1,6 @@
<? INC Header.tmpl ?>
<form method="post" action="/mods/send_raw/">
<form method="post" action="<? VAR ModPath ?>">
<? INC _csrf_check.tmpl ?>
<div class="section">
+2 -2
View File
@@ -200,11 +200,11 @@ public:
return true;
} else if (sPageName == "delnote") {
DelNote(WebSock.GetParam("key", false));
WebSock.Redirect("/mods/notes/");
WebSock.Redirect(GetWebPath());
return true;
} else if (sPageName == "addnote") {
AddNote(WebSock.GetParam("key"), WebSock.GetParam("note"));
WebSock.Redirect("/mods/notes/");
WebSock.Redirect(GetWebPath());
return true;
}
+1 -1
View File
@@ -136,7 +136,7 @@ public:
virtual bool OnWebRequest(CWebSock& WebSock, const CString& sPageName, CTemplate& Tmpl) {
if (sPageName != "index") {
// only accept requests to /mods/perform/
// only accept requests to index
return false;
}
+18
View File
@@ -156,6 +156,24 @@ const CString& CModule::GetSavePath() const {
return m_sSavePath;
}
CString CModule::GetWebPath() {
switch (m_eType) {
case CModInfo::GlobalModule: return "/mods/global/" + GetModName() + "/";
case CModInfo::UserModule: return "/mods/user/" + GetModName() + "/";
case CModInfo::NetworkModule: return "/mods/network/" + m_pNetwork->GetName() + "/" + GetModName() + "/";
default: return "/";
}
}
CString CModule::GetWebFilesPath() {
switch (m_eType) {
case CModInfo::GlobalModule: return "/modfiles/global/" + GetModName() + "/";
case CModInfo::UserModule: return "/modfiles/user/" + GetModName() + "/";
case CModInfo::NetworkModule: return "/modfiles/network/" + m_pNetwork->GetName() + "/" + GetModName() + "/";
default: return "/";
}
}
bool CModule::LoadRegistry() {
//CString sPrefix = (m_pUser) ? m_pUser->GetUserName() : ".global";
return (m_mssRegistry.ReadFromDisk(GetSavePath() + "/.registry") == MCString::MCS_SUCCESS);
+5
View File
@@ -342,6 +342,7 @@ bool CWebSock::AddModLoop(const CString& sLoopName, CModule& Module) {
CTemplate& Row = m_Template.AddRow(sLoopName);
Row["ModName"] = Module.GetModName();
Row["ModPath"] = Module.GetWebPath();
Row["Title"] = sTitle;
if (m_sModName == Module.GetModName()) {
@@ -367,6 +368,7 @@ bool CWebSock::AddModLoop(const CString& sLoopName, CModule& Module) {
CTemplate& SubRow = Row.AddRow("SubPageLoop");
SubRow["ModName"] = Module.GetModName();
SubRow["ModPath"] = Module.GetWebPath();
SubRow["PageName"] = SubPage->GetName();
SubRow["Title"] = SubPage->GetTitle().empty() ? SubPage->GetName() : SubPage->GetTitle();
@@ -667,6 +669,9 @@ CWebSock::EPageReqResult CWebSock::OnPageRequestInternal(const CString& sURI, CS
break;
}
m_Template["ModPath"] = pModule->GetWebPath();
m_Template["ModFilesPath"] = pModule->GetWebFilesPath();
if (!pModule) {
return PAGE_NOTFOUND;
} else if (pModule->WebRequiresLogin() && !ForceLogin()) {
+4 -4
View File
@@ -6,9 +6,9 @@
<li class="topitem parent"><span class="title">Global Modules</span>
<ul>
<? LOOP GlobalModLoop SORTASC=ModName ?>
<li class="modtitle<? IF Active ?> active<? ENDIF ?>"><a href="/mods/global/<? VAR ModName ?>"><? VAR Title ?></a></li>
<li class="modtitle<? IF Active ?> active<? ENDIF ?>"><a href="<? VAR ModPath ?>"><? VAR Title ?></a></li>
<? LOOP SubPageLoop ?>
<li class="subitem<? IF Active ?> active<? ENDIF ?>"><a href="/mods/global/<? VAR ModName ?>/<? VAR PageName ?><? IF Params ?>?<? VAR Params ?><? ENDIF ?>"><? VAR Title ?></a></li>
<li class="subitem<? IF Active ?> active<? ENDIF ?>"><a href="<? VAR ModPath ?><? VAR PageName ?><? IF Params ?>?<? VAR Params ?><? ENDIF ?>"><? VAR Title ?></a></li>
<? ENDLOOP ?>
<? ENDLOOP ?>
</ul>
@@ -19,9 +19,9 @@
<li class="topitem parent"><span class="title">User Modules</span>
<ul>
<? LOOP UserModLoop SORTASC=ModName ?>
<li class="modtitle<? IF Active ?> active<? ENDIF ?>"><a href="/mods/user/<? IF ModUser ?><? VAR ModUser ?>:<? ENDIF ?><? VAR ModName ?>"><? VAR Title ?></a></li>
<li class="modtitle<? IF Active ?> active<? ENDIF ?>"><a href="<? VAR ModPath ?>"><? VAR Title ?></a></li>
<? LOOP SubPageLoop ?>
<li class="subitem<? IF Active ?> active<? ENDIF ?>"><a href="/mods/user/<? VAR ModName ?>/<? VAR PageName ?><? IF Params ?>?<? VAR Params ?><? ENDIF ?>"><? VAR Title ?></a></li>
<li class="subitem<? IF Active ?> active<? ENDIF ?>"><a href="<? VAR ModPath ?><? VAR PageName ?><? IF Params ?>?<? VAR Params ?><? ENDIF ?>"><? VAR Title ?></a></li>
<? ENDLOOP ?>
<? ENDLOOP ?>
</ul>