/*
* Box Socialâ„¢
* http://boxsocial.net/
* Copyright © 2007, David Lachlan Smith
*
* $Id:$
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using BoxSocial;
using BoxSocial.Groups;
using BoxSocial.Internals;
using BoxSocial.IO;
using BoxSocial.Networks;
namespace BoxSocial.FrontEnd
{
public partial class account : TPage
{
private List accountModules = new List();
private List accountSubModules = new List();
private Dictionary> modulesList = new Dictionary>();
public account()
: base("account_master.html")
{
}
void OnRegisterModule(object sender, EventArgs e)
{
}
public void AddModule(string token, Dictionary subModules)
{
modulesList.Add(token, subModules);
}
Dictionary modules = new Dictionary();
private void loadModules(Account accountObject, List applicationsList, string module)
{
/*
* Dashboard
*/
Assembly dashboardAssembly = Assembly.GetAssembly(typeof(AccountDashboard));
loadModulesFromAssembly(accountObject, dashboardAssembly, module);
loadSubModulesFromAssembly(accountObject, dashboardAssembly, module);
/*
* Applications
*/
foreach (ApplicationEntry ae in applicationsList)
{
if (ae.Modules != null && ae.Modules.Count > 0)
{
string assemblyPath;
if (ae.IsPrimitive)
{
assemblyPath = Path.Combine(core.Http.AssemblyPath, string.Format("{0}.dll", ae.AssemblyName));
}
else
{
assemblyPath = Path.Combine(core.Http.AssemblyPath, Path.Combine("applications", string.Format("{0}.dll", ae.AssemblyName)));
}
Assembly assembly = Assembly.LoadFrom(assemblyPath);
loadModulesFromAssembly(accountObject, assembly, module);
loadSubModulesFromAssembly(accountObject, assembly, module);
}
}
}
private void loadModulesFromAssembly(Account accountObject, Assembly assembly, string module)
{
Type[] types = assembly.GetTypes();
foreach (Type type in types)
{
if (type.IsSubclassOf(typeof(AccountModule)))
{
try
{
AccountModule newModule = System.Activator.CreateInstance(type, accountObject) as AccountModule;
if (newModule != null)
{
newModule.assembly = assembly;
accountModules.Add(newModule);
if (newModule.Key == module)
{
core.AddPageAssembly(assembly);
}
}
}
catch (TargetInvocationException)
{
continue;
}
}
}
}
private void loadSubModulesFromAssembly(Account accountObject, Assembly assembly, string module)
{
Type[] types = assembly.GetTypes();
foreach (Type type in types)
{
if (type.IsSubclassOf(typeof(AccountSubModule)))
{
AccountSubModule newModule = System.Activator.CreateInstance(type, new object[] { }) as AccountSubModule;
if (newModule != null)
{
if (newModule.ModuleKey == module && (newModule.Primitives & AppPrimitives.Member) == AppPrimitives.Member)
{
accountSubModules.Add(newModule);
}
}
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
string module = (!String.IsNullOrEmpty(core.Http.Form["module"])) ? core.Http.Form["module"] : core.Http.Query["module"];
string submodule = (!String.IsNullOrEmpty(core.Http.Form["sub"])) ? core.Http.Form["sub"] : core.Http.Query["sub"];
module = (module == null) ? "" : module;
module = (module == "") ? "dashboard" : module;
submodule = (submodule == null) ? "" : submodule;
List args = new List();
if ((!session.IsLoggedIn) || loggedInMember == null)
{
foreach (string key in Request.QueryString.Keys)
{
if (key != null)
{
if (key.ToLower() != "sid" && key.ToLower() != "module" && key.ToLower() != "sub")
{
args.Add(string.Format("{0}={1}", key, Request.QueryString[key]));
}
}
}
core.Http.Redirect(core.Uri.BuildLoginUri(core.Uri.StripSid(core.Uri.BuildAccountSubModuleUri((Primitive)null, module, submodule, args.ToArray()))));
return;
}
loggedInMember.LoadProfileInfo();
template.Parse("ACCOUNT_TITLE", "My Account");
/*if ((loggedInMember.Permissions & 0x1111) == 0x0000)
{
template.ParseRaw("NO_PERMISSIONS", "You have not set any view permissions for your profile. No-one will be able to see your profile until you give they access. You can set access permissions from the Profile Permissions panel.");
}*/
if (!loggedInMember.Info.ShowCustomStyles && !string.IsNullOrEmpty(loggedInMember.Style.RawCss))
{
template.ParseRaw("NO_CUSTOM_STYLE", "You have set a custom style for your site, yet you cannot view it as you have disabled custom styles. To view your custom style you must enable custom styles in your account preferences.");
}
Account accountObject = new Account(Core);
loadModules(accountObject, BoxSocial.Internals.Application.GetModuleApplications(core, session.LoggedInMember), module);
accountObject.RegisterModule += new Account.RegisterModuleHandler(OnRegisterModule);
accountObject.RegisterAllModules();
accountModules.Sort();
foreach (AccountModule accountModule in accountModules)
{
VariableCollection modulesVariableCollection = template.CreateChild("module_list");
modulesVariableCollection.Parse("NAME", accountModule.Name);
if (string.IsNullOrEmpty(accountModule.Key))
{
modulesVariableCollection.Parse("URI", loggedInMember.AccountUriStub);
}
else
{
modulesVariableCollection.Parse("URI", loggedInMember.AccountUriStub + accountModule.Key);
}
if (module == accountModule.Key)
{
ApplicationEntry ae = null;
if (accountModule.assembly.GetName().Name != "BoxSocial.Internals")
{
ae = new ApplicationEntry(core, loggedInMember, accountModule.assembly.GetName().Name);
}
accountModule.SetOwner = loggedInMember;
accountModule.CreateTemplate();
// catch all errors, don't want a single application to crash the account panel
try
{
accountModule.RegisterSubModules(submodule);
modules = accountModule.SubModules;
//accountModule.RenderTemplate();
}
catch (System.Threading.ThreadAbortException)
{
// ignore this informational exception
}
catch (Exception ex)
{
// TODO: e-mail application author of the error details
accountModule.DisplayError("");
core.LoadUserProfile(ae.CreatorId);
core.Email.SendEmail(core.PrimitiveCache[ae.CreatorId].Info.PrimaryEmail, "An Error occured in your application `" + ae.Title + "` at ZinZam.com", ex.ToString());
}
if (ae != null && ae.HasJavascript)
{
VariableCollection javaScriptVariableCollection = template.CreateChild("javascript_list");
javaScriptVariableCollection.Parse("URI", @"/scripts/" + ae.Key + @".js");
}
}
}
accountSubModules.Sort();
foreach (AccountSubModule asm in accountSubModules)
{
if (!string.IsNullOrEmpty(asm.Key) && asm.Order >= 0)
{
VariableCollection modulesVariableCollection = template.CreateChild("account_links");
asm.SetOwner = loggedInMember;
modulesVariableCollection.Parse("TITLE", asm.Title);
modulesVariableCollection.Parse("SUB", asm.Key);
modulesVariableCollection.Parse("MODULE", asm.ModuleKey);
modulesVariableCollection.Parse("URI", asm.BuildUri(core));
}
if ((asm.Key == submodule || (string.IsNullOrEmpty(submodule) && asm.IsDefault)) && asm.ModuleKey == module)
{
//try
{
asm.ModuleVector(core);
}
/*catch (Exception ex)
{
throw new Exception(ex.ToString() + "\n\n\n" + db.ErrorList + "\n\n" + db.QueryList);
}*/
}
}
EndResponse();
}
}
}