public NumberedItemsCache(Core core) { this.core = core; this.db = core.Db; if (itemsPersisted == null) { object o = core.Cache.GetCached("NumberedItems"); if (o != null && o is Dictionary<NumberedItemId, NumberedItem>) { itemsPersisted = (Dictionary<NumberedItemId, NumberedItem>)o; } else { itemsPersisted = new Dictionary<NumberedItemId, NumberedItem>(32); } } if (itemsPersisted != null) { foreach (NumberedItemId nii in itemsPersisted.Keys) { itemsCached.Add(nii, itemsPersisted[nii]); } } }
public UploadForm(Core core, PPage page) { this.core = core; this.page = page; this.db = core.Db; this.template = core.Template; this.Owner = page.Owner; this.LoggedInMember = core.Session.LoggedInMember; }
/// <summary> /// Initializes a new instance of the ControlPanelSubModule class. /// </summary> /// <param name="core">The Core token.</param> public ControlPanelSubModule(Core core, Primitive owner) { this.core = core; this.db = core.Db; this.session = core.Session; this.tz = core.Tz; this.LoggedInMember = session.LoggedInMember; this.Owner = owner; core.Prose.AddApplication(Assembly.GetAssembly(this.GetType()).GetName().Name); }
public OPage() { timer = new Stopwatch(); timer.Start(); rand = new Random(); Stopwatch initTimer = new Stopwatch(); initTimer.Start(); db = new Mysql(WebConfigurationManager.AppSettings["mysql-user"], WebConfigurationManager.AppSettings["mysql-password"], WebConfigurationManager.AppSettings["mysql-database"], WebConfigurationManager.AppSettings["mysql-host"]); ResponseFormats responseFormat = ResponseFormats.Json; // we should default to json but give the option for xml output bool isAjax = (HttpContext.Current.Request.QueryString["ajax"] == "true"); if (!isAjax) { isAjax = (HttpContext.Current.Request.Form["ajax"] == "true"); if (isAjax) { responseFormat = ResponseFormats.Xml; } } bool isJson = (HttpContext.Current.Request.QueryString["json"] == "true"); if (!isJson) { isJson = (HttpContext.Current.Request.Form["json"] == "true"); if (isJson) { responseFormat = ResponseFormats.Json; } } core = new Core(this, responseFormat, db); httpContext = HttpContext.Current; }
public void SetUpForNonStaticMembers() { db = new Mysql("root", "", "zinzam0_test", "192.168.56.101"); template = new Template(Path.Combine(@"c:\SVN\BoxSocial\BoxSocial", "templates"), "default.html"); core = new Core(db, template); functions = new Functions(core); }
/// <summary> /// /// </summary> /// <param name="db"></param> /// <param name="userName"></param> /// <param name="eMail"></param> /// <returns></returns> public static bool CheckUserNameUnique(Mysql db, string userName) { if (db.Query(string.Format("SELECT user_name FROM user_keys WHERE user_name_lower = '{0}';", Mysql.Escape(userName.ToLower()))).Rows.Count > 0) { return false; } return true; }
public Pages(Core core, Primitive owner) { this.owner = owner; this.core = core; this.db = core.Db; }
public TPage() { timer = new Stopwatch(); timer.Start(); rand = new Random(); Stopwatch initTimer = new Stopwatch(); initTimer.Start(); db = new Mysql(WebConfigurationManager.AppSettings["mysql-user"], WebConfigurationManager.AppSettings["mysql-password"], WebConfigurationManager.AppSettings["mysql-database"], WebConfigurationManager.AppSettings["mysql-host"]); template = new Template(Server.MapPath("./templates/"), ""); HttpContext.Current.Response.AppendHeader("x-ua-compatible", "IE=edge,chrome=1"); string u = HttpContext.Current.Request.ServerVariables["HTTP_USER_AGENT"]; if ((!string.IsNullOrEmpty(u)) && ((b.IsMatch(u) || v.IsMatch(u.Substring(0, 4))))) { isMobile = true; template.Medium = DisplayMedium.Mobile; template.Parse("IS_MOBILE", "TRUE"); } else { isMobile = false; } ResponseFormats responseFormat = ResponseFormats.Html; isAjax = (HttpContext.Current.Request.QueryString["ajax"] == "true"); if (!isAjax) { isAjax = (HttpContext.Current.Request.Form["ajax"] == "true"); } if (isAjax) { responseFormat = ResponseFormats.Xml; } isJson = (HttpContext.Current.Request.QueryString["json"] == "true"); if (!isJson) { isJson = (HttpContext.Current.Request.Form["json"] == "true"); } if (isJson) { responseFormat = ResponseFormats.Json; } core = new Core(this, responseFormat, db, template); pageTitle = core.Settings.SiteTitle + (!string.IsNullOrEmpty(core.Settings.SiteSlogan) ? " • " + core.Settings.SiteSlogan : string.Empty); HttpContext httpContext = HttpContext.Current; string[] redir = httpContext.Request.RawUrl.Split(';'); if (redir.Length > 1) { core.PagePath = redir[1]; Uri cUri = new Uri(core.PagePath); core.PagePath = cUri.AbsolutePath.TrimEnd(new char[] { '/' }); } else { if (httpContext.Request.Url.Host.ToLower() == Hyperlink.Domain) { Core.PagePath = httpContext.Request.RawUrl.TrimEnd(new char[] { '/' }); } else { Core.PagePath = "/"; } } #if DEBUG Stopwatch httpTimer = new Stopwatch(); httpTimer.Start(); #endif session = new SessionState(Core, db, User, HttpContext.Current.Request, HttpContext.Current.Response); loggedInMember = session.LoggedInMember; #if DEBUG httpTimer.Stop(); HttpContext.Current.Response.Write(string.Format("<!-- section A in {0} -->\r\n", httpTimer.ElapsedTicks / 10000000.0)); #endif long loadStart = initTimer.ElapsedTicks; tz = new UnixTime(core, UnixTime.UTC_CODE); core.Session = session; core.CoreDomain = AppDomain.CurrentDomain; if (loggedInMember != null) { tz = loggedInMember.UserInfo.GetTimeZone; } // move it here core.Tz = tz; // As a security measure we use the http object to prevent // applications hijacking the response output core.Http = new Http(); Template.Path = core.Http.TemplatePath; core.Prose = new Prose(); core.Prose.Initialise(core, "en"); //List<string> asmNames = core.GetLoadedAssemblyNames(); foreach (string asm in BoxSocial.Internals.Application.AssemblyNames.Keys) { core.Prose.AddApplication(asm); } //List<Assembly> asms = core.GetLoadedAssemblies(); foreach (Assembly asm in BoxSocial.Internals.Application.LoadedAssemblies.Values) { template.AddPageAssembly(asm); } template.SetProse(core.Prose); string pageString = core.Http.Query["p"]; if (!string.IsNullOrEmpty(pageString)) { string[] pages = pageString.Split(new char[] { ',' }); page = new int[pages.Length]; for (int i = 0; i < pages.Length; i++) { if (!int.TryParse(pages[i], out page[i])) { page[i] = 1; } } } else { page = new int[] { 1 }; } string offsetString = core.Http.Query["o"]; if (!string.IsNullOrEmpty(offsetString)) { string[] offsets = offsetString.Split(new char[] { ',' }); offset = new long[offsets.Length]; for (int i = 0; i < offsets.Length; i++) { if (!long.TryParse(offsets[i], out offset[i])) { offset[i] = 0; } } } else { offset = new long[] { 0 }; } if (session != null && session.SignedIn && core.IsMobile && core.ResponseFormat == ResponseFormats.Html) { List<ApplicationEntry> applications = BoxSocial.Internals.Application.GetApplications(core, core.Session.LoggedInMember); foreach (ApplicationEntry ae in applications) { BoxSocial.Internals.Application.LoadApplication(core, AppPrimitives.Member, ae); } core.InvokePostHooks(new HookEventArgs(core, AppPrimitives.Member, core.Session.LoggedInMember)); } loadTime = (initTimer.ElapsedTicks - loadStart); initTimer.Stop(); initTime += initTimer.ElapsedTicks; }
public SessionState(Core core, User user) { if (core == null) { throw new NullCoreException(); } this.core = core; this.db = core.Db; isLoggedIn = true; /* only used by the installer, and background worker two factor will not be enabled at this point */ this.signInState = SessionSignInState.SignedIn; loggedInMember = user; ipAddress = new IPAddress(0); }
public Core(TPage page, ResponseFormats responseFormat, Mysql db, Template template) { HeadHooks += new HookHandler(Core_HeadHooks); PrimitiveHeadHooks += new HookHandler(Core_PrimitiveHeadHooks); FootHooks +=new HookHandler(Core_FootHooks); PageHooks += new HookHandler(Core_Hooks); PostHooks += new HookHandler(Core_PostHooks); LoadApplication += new LoadHandler(Core_LoadApplication); this.page = page; this.db = db; this.template = template; this.responseFormat = responseFormat; ItemKey.populateItemTypeCache(this); //QueryCache.populateQueryCache(); userProfileCache = new PrimitivesCache(this); itemsCache = new NumberedItemsCache(this); accessControlCache = new AccessControlCache(this); primitiveTypes = ItemKey.GetPrimitiveTypes(this); }
public Core(Mysql db) { this.db = db; ItemKey.populateItemTypeCache(this); userProfileCache = new PrimitivesCache(this); itemsCache = new NumberedItemsCache(this); accessControlCache = new AccessControlCache(this); primitiveTypes = ItemKey.GetPrimitiveTypes(this); }
public Core(OPage page, ResponseFormats responseFormat, Mysql db) { LoadApplication += new LoadHandler(Core_LoadApplication); this.db = db; this.responseFormat = responseFormat; ItemKey.populateItemTypeCache(this); //QueryCache.populateQueryCache(); userProfileCache = new PrimitivesCache(this); itemsCache = new NumberedItemsCache(this); accessControlCache = new AccessControlCache(this); primitiveTypes = ItemKey.GetPrimitiveTypes(this); }
public static void LoadAssemblies(Mysql db) { string assemblyPath = null; SelectQuery query = new SelectQuery("applications"); query.AddField(new DataField("applications", "application_id")); query.AddField(new DataField("applications", "application_assembly_name")); query.AddField(new DataField("applications", "application_locked")); query.AddField(new DataField("applications", "application_update")); query.AddField(new DataField("applications", "application_primitive")); query.AddCondition("application_type", (byte)ApplicationType.Native); System.Data.Common.DbDataReader applicationReader = db.ReaderQuery(query); while (applicationReader.Read()) { long applicationId = (long)applicationReader["application_id"]; string assemblyName = (string)applicationReader["application_assembly_name"]; bool isPrimitive = false; if (applicationReader["application_primitive"] is bool) { isPrimitive = (bool)applicationReader["application_primitive"]; } else if (applicationReader["application_primitive"] is byte) { isPrimitive = ((byte)applicationReader["application_primitive"] > 0) ? true : false; } else if (applicationReader["application_primitive"] is sbyte) { isPrimitive = ((sbyte)applicationReader["application_primitive"] > 0) ? true : false; } else { isPrimitive = false; } if (isPrimitive) { if (Directory.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin"))) { assemblyPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin", assemblyName + ".dll"); } else { assemblyPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, assemblyName + ".dll"); } } else { if (Directory.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin"))) { assemblyPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin", "applications", assemblyName + ".dll"); } else { assemblyPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "applications", assemblyName + ".dll"); } } if (!string.IsNullOrEmpty(assemblyPath)) { Assembly assembly = Assembly.LoadFrom(assemblyPath); LoadedAssemblies[applicationId] = assembly; AssemblyNames[assemblyName] = applicationId; } } applicationReader.Close(); applicationReader.Dispose(); }
/// <summary> /// Bind the module to the account panel. /// </summary> /// <param name="account"></param> private void Bind(Account account) { account.RegisterModule += new Account.RegisterModuleHandler(RegisterModule); core = account.core; page = account.core.page; db = account.core.Db; loggedInMember = account.core.Session.LoggedInMember; tz = account.core.Tz; session = account.core.Session; }
public SessionState(Core core, Mysql db, System.Security.Principal.IPrincipal User, HttpRequest Request, HttpResponse Response) { if (core == null) { throw new NullCoreException(); } this.Request = Request; this.Response = Response; this.db = db; this.core = core; this.isLoggedIn = false; this.signInState = SessionSignInState.SignedOut; ipAddress = IPAddress.Parse(SessionState.ReturnRealIPAddress(Request.ServerVariables)); #if DEBUG Stopwatch httpTimer = new Stopwatch(); httpTimer.Start(); #endif SessionPagestart(ipAddress.ToString()); #if DEBUG httpTimer.Stop(); HttpContext.Current.Response.Write(string.Format("<!-- section A.1 in {0} -->\r\n", httpTimer.ElapsedTicks / 10000000.0)); #endif return; }
public SessionState(Core core, Mysql db, OAuthToken token, HttpRequest Request, HttpResponse Response) { if (core == null) { throw new NullCoreException(); } this.Request = Request; this.Response = Response; this.db = db; this.core = core; applicationId = token.ApplicationId; SelectQuery query = new SelectQuery(typeof(PrimitiveApplicationInfo)); query.AddCondition("application_id", token.ApplicationId); query.AddCondition("app_oauth_access_token", token.Token); System.Data.Common.DbDataReader appReader = core.Db.ReaderQuery(query); if (appReader.HasRows) { appReader.Read(); PrimitiveApplicationInfo pai = new PrimitiveApplicationInfo(core, appReader); appReader.Close(); appReader.Dispose(); if (pai.Owner is User) { this.core = core; this.db = core.Db; isLoggedIn = true; this.signInState = SessionSignInState.SignedIn; loggedInMember = (User)pai.Owner; ipAddress = IPAddress.Parse(SessionState.ReturnRealIPAddress(Request.ServerVariables)); this.sessionMethod = SessionMethods.OAuth; } } else { appReader.Close(); appReader.Dispose(); this.core = core; this.db = core.Db; isLoggedIn = false; this.signInState = SessionSignInState.SignedOut; ipAddress = IPAddress.Parse(SessionState.ReturnRealIPAddress(Request.ServerVariables)); this.sessionMethod = SessionMethods.OAuth; } }
public static bool CheckNetworkEmailUnique(Mysql db, string eMail) { DataTable networkMemberTable = db.Query(string.Format("SELECT user_id, member_email FROM network_members WHERE LCASE(member_email) = '{0}';", Mysql.Escape(eMail.ToLower()))); if (networkMemberTable.Rows.Count > 0) { //lastEmailId = (long)networkMemberTable.Rows[0]["user_id"]; return false; } return true; }
/// <summary> /// We do this so we don't have to keep re-declaring the same /// constructor /// </summary> /// <param name="core">Core token</param> /// <param name="owner">Owner</param> public void ModuleVector(Core core, Primitive owner, VariableCollection vc) { if (core == null) { throw new NullCoreException(); } this.core = core; this.db = core.Db; this.session = core.Session; this.tz = core.Tz; this.Owner = owner; this.LoggedInMember = session.LoggedInMember; this.parentModulesVariableCollection = vc; CreateTemplate(); string mode = core.Http["mode"]; EventHandler loadHandler = Load; if (loadHandler != null) { loadHandler(this, new EventArgs()); } if (string.IsNullOrEmpty(mode) || !HasModeHandler(mode)) { EventHandler showHandler = Show; if (showHandler != null) { showHandler(this, new EventArgs()); } } else if (!string.IsNullOrEmpty(mode)) { ShowMode(mode); } RenderTemplate(); }
protected void Application_Start(object sender, EventArgs e) { AppDomainSetup ads = AppDomain.CurrentDomain.SetupInformation; ads.ShadowCopyFiles = bool.TrueString; if (ads.ShadowCopyDirectories != null) { if (ads.ShadowCopyDirectories == "") { ads.ShadowCopyDirectories = HttpContext.Current.Server.MapPath("/applications/"); } else { ads.ShadowCopyDirectories = string.Format("{0};{1}", ads.ShadowCopyDirectories, HttpContext.Current.Server.MapPath("/applications/")); } } ads.ShadowCopyDirectories = ads.ShadowCopyDirectories + ";" + Server.MapPath(@"/applications/"); //AppDomain.CurrentDomain.SetShadowCopyPath(ads.ShadowCopyDirectories + ";" + Server.MapPath(@"/applications/")); // // Load all applications // Mysql db = new Mysql(WebConfigurationManager.AppSettings["mysql-user"], WebConfigurationManager.AppSettings["mysql-password"], WebConfigurationManager.AppSettings["mysql-database"], WebConfigurationManager.AppSettings["mysql-host"]); BoxSocial.Internals.Application.LoadAssemblies(db); db.CloseConnection(); // // Implements a message queue processor // lock (queueLock) { // Check the queues and create is not exist if (Queue != null) { if (!Queue.QueueExists(WebConfigurationManager.AppSettings["queue-default-priority"])) { Queue.CreateQueue(WebConfigurationManager.AppSettings["queue-default-priority"]); } } // Starts the queue processor worker.WorkerReportsProgress = false; worker.WorkerSupportsCancellation = true; worker.DoWork += new DoWorkEventHandler(worker_DoWork); worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted); worker.RunWorkerAsync(); if (queue != null) { Queue.CloseConnection(); Queue = null; } } Regex.CacheSize = 256; }
protected void worker_DoWork(object sender, DoWorkEventArgs e) { int wait = 15; for (int i = 0; i < wait * 100; i++) { // The sleep should happen on the worker thread rather than the application thread System.Threading.Thread.Sleep(10); if (e.Cancel) { // Poll the thread every [wait] seconds to work out if the worker should be cancelled return; } } //HttpContext.Current = (HttpContext)e.Argument; Mysql db = new Mysql(WebConfigurationManager.AppSettings["mysql-user"], WebConfigurationManager.AppSettings["mysql-password"], WebConfigurationManager.AppSettings["mysql-database"], WebConfigurationManager.AppSettings["mysql-host"]); Core core = new Core(db); string processViews = WebConfigurationManager.AppSettings["queue-process-views"]; if (!string.IsNullOrEmpty(processViews) && processViews.ToLower() == "true") { try { ItemView.ProcessViews(core); } catch (Exception ex) { InsertQuery iQuery = new InsertQuery(typeof(ApplicationError)); iQuery.AddField("error_title", "An Error occured at " + Hyperlink.Domain + " in global.asax"); iQuery.AddField("error_body", "EXCEPTION THROWN:\n" + ex.ToString()); core.Db.Query(iQuery); } } string cronApplication = WebConfigurationManager.AppSettings["queue-cron-application"]; if (!string.IsNullOrEmpty(cronApplication)) { List<ApplicationEntry> aes = new List<ApplicationEntry>(); if (cronApplication == "*") { aes.AddRange(core.GetCronApplications()); } else { ApplicationEntry ae = core.GetApplication(cronApplication); if (ae != null) { BoxSocial.Internals.Application.LoadApplication(core, AppPrimitives.Any, ae); aes.Add(ae); } } foreach (ApplicationEntry ae in aes) { if (UnixTime.UnixTimeStamp() % ae.CronFrequency < 15) { Application jobApplication = BoxSocial.Internals.Application.GetApplication(core, AppPrimitives.Any, ae); if (jobApplication != null) { try { if (!jobApplication.ExecuteCron()) { StringBuilder failedCronLog = new StringBuilder(); failedCronLog.AppendLine("Application Id: " + ae.ApplicationId); InsertQuery iQuery = new InsertQuery(typeof(ApplicationError)); iQuery.AddField("error_title", "Cron failed at " + Hyperlink.Domain); iQuery.AddField("error_body", "FAILED CRON:\n" + failedCronLog.ToString()); core.Db.Query(iQuery); } } catch (Exception ex) { InsertQuery iQuery = new InsertQuery(typeof(ApplicationError)); iQuery.AddField("error_title", "An Error occured at " + Hyperlink.Domain + " in global.asax"); iQuery.AddField("error_body", "EXCEPTION THROWN:\n" + ex.ToString() + "\n\n" + core.Console.ToString()); core.Db.Query(iQuery); } } } } } try { bool flag = false; lock (queueLock) { if (queue != null) { flag = true; } } if (flag) { int failedJobs = 0; // Retrieve Jobs Dictionary<string, int> queues = new Dictionary<string, int>(); queues.Add(WebConfigurationManager.AppSettings["queue-default-priority"], 10); StringBuilder failedJobsLog = new StringBuilder(); foreach (string queueName in queues.Keys) { List<Job> jobs = null; lock (queueLock) { try { jobs = Queue.ClaimJobs(queueName, queues[queueName]); } catch { return; } } foreach (Job job in jobs) { core.LoadUserProfile(job.UserId); } foreach (Job job in jobs) { core.CreateNewSession(core.PrimitiveCache[job.UserId]); // Load Application if (job.ApplicationId > 0) { ApplicationEntry ae = core.GetApplication(job.ApplicationId); BoxSocial.Internals.Application.LoadApplication(core, AppPrimitives.Any, ae); } // Execute Job if (core.InvokeJob(job)) { lock (queueLock) { Queue.DeleteJob(job); } } else { failedJobs++; //queue.ReleaseJob(job); #if DEBUG failedJobsLog.AppendLine("Application Id: " + job.ApplicationId); failedJobsLog.AppendLine("Item Id: " + job.ItemId); failedJobsLog.AppendLine("Item Type Id: " + job.ItemTypeId); failedJobsLog.AppendLine("Function: " + job.Function); failedJobsLog.AppendLine("Body: " + job.Body); failedJobsLog.AppendLine("Message: " + job.Message); failedJobsLog.AppendLine("Error: " + job.Error); failedJobsLog.AppendLine("===================="); #endif } } } if (failedJobs > 0) { InsertQuery iQuery = new InsertQuery(typeof(ApplicationError)); iQuery.AddField("error_title", "Jobs failed at " + Hyperlink.Domain); iQuery.AddField("error_body", "FAILED JOB COUNT:\n" + failedJobs.ToString() + "\n\n" + failedJobsLog.ToString()); core.Db.Query(iQuery); #if DEBUG core.Email.SendEmail(WebConfigurationManager.AppSettings["error-email"], "Jobs failed at " + Hyperlink.Domain, "FAILED JOB COUNT:\n" + failedJobs.ToString() + "\n\n" + failedJobsLog.ToString()); #endif } } } catch (Exception ex) { try { InsertQuery iQuery = new InsertQuery(typeof(ApplicationError)); iQuery.AddField("error_title", "An Error occured at " + Hyperlink.Domain + " in global.asax"); iQuery.AddField("error_body", "EXCEPTION THROWN:\n" + ex.ToString()); core.Db.Query(iQuery); core.Email.SendEmail(WebConfigurationManager.AppSettings["error-email"], "An Error occured at " + Hyperlink.Domain + " in global.asax", "EXCEPTION THROWN:\n" + ex.ToString()); } catch { try { core.Email.SendEmail(WebConfigurationManager.AppSettings["error-email"], "An Error occured at " + Hyperlink.Domain + " in global.asax", "EXCEPTION THROWN:\n" + ex.ToString()); } catch { } } } // Cleanup lock (queueLock) { if (queue != null) { Queue.CloseConnection(); Queue = null; } } core.CloseProse(); core.CloseSearch(); core.CloseCache(); core = null; db.CloseConnection(); db = null; }
protected void Application_BeginRequest(object sender, EventArgs e) { HttpContext httpContext = HttpContext.Current; string[] redir = httpContext.Request.RawUrl.Split(';'); string host = httpContext.Request.Url.Host.ToLower(); bool isSecure = httpContext.Request.Url.Scheme.ToLower() == Uri.UriSchemeHttps.ToLower(); Settings settings = new Settings(null); if (host == "www." + Hyperlink.Domain) { UriBuilder noWwwUri = new UriBuilder(httpContext.Request.Url); noWwwUri.Host = Hyperlink.Domain; if (settings.UseSecureCookies) { noWwwUri.Scheme = Uri.UriSchemeHttps; noWwwUri.Port = -1; } Response.Redirect(noWwwUri.ToString()); Response.End(); return; } string currentURI = null; Uri cUri = null; if (httpContext.Request.RawUrl.Contains(";http://") || httpContext.Request.RawUrl.Contains("?http://")) { if (redir.Length > 1) // Apache2/IIS { currentURI = redir[1]; cUri = new Uri(currentURI); currentURI = cUri.AbsolutePath; if (currentURI.EndsWith("index.php", StringComparison.Ordinal)) { currentURI = currentURI.Substring(0, currentURI.Length - 9); Response.Redirect(currentURI, true); Response.End(); return; } if (currentURI.EndsWith(".php", StringComparison.Ordinal)) { currentURI = currentURI.Substring(0, currentURI.Length - 4); Response.Redirect(currentURI, true); Response.End(); return; } } else // NGINX { int i = httpContext.Request.RawUrl.IndexOf('?'); if (httpContext.Request.RawUrl.Length >= i) { currentURI = httpContext.Request.RawUrl.Substring(i + 1); } cUri = new Uri(currentURI); currentURI = cUri.AbsolutePath; } } /*else { currentURI = httpContext.Request.RawUrl; cUri = new Uri(currentURI); currentURI = cUri.AbsolutePath; }*/ if (!httpContext.Request.RawUrl.Contains("404.aspx")) { if (settings.UseSecureCookies && (!isSecure) && host == Hyperlink.Domain) { UriBuilder secureUri = new UriBuilder(httpContext.Request.RawUrl); secureUri.Host = host; secureUri.Scheme = Uri.UriSchemeHttps; secureUri.Port = -1; if (secureUri.Path.ToLower() == "/default.aspx") { secureUri.Path = "/"; } if (secureUri.Query == "?") { secureUri.Query = ""; } Response.Redirect(secureUri.ToString()); Response.End(); return; } if (host == Hyperlink.Domain) { return; } else { if (httpContext.Request.RawUrl.Contains("default.aspx")) { cUri = httpContext.Request.Url; currentURI = "/"; } } } if (currentURI != null) { if (settings.UseSecureCookies && (!isSecure) && host == Hyperlink.Domain) { UriBuilder secureUri = new UriBuilder(cUri); secureUri.Host = host; secureUri.Scheme = Uri.UriSchemeHttps; secureUri.Port = -1; if (secureUri.Query == "?") { secureUri.Query = ""; } Response.Redirect(secureUri.ToString()); Response.End(); return; } List<string[]> patterns = new List<string[]>(); if (host != Hyperlink.Domain) { SelectQuery query = new SelectQuery("dns_records"); query.AddFields("dns_domain", "dns_owner_id", "dns_owner_type", "dns_owner_key"); query.AddCondition("dns_domain", host); Mysql db = new Mysql(WebConfigurationManager.AppSettings["mysql-user"], WebConfigurationManager.AppSettings["mysql-password"], WebConfigurationManager.AppSettings["mysql-database"], WebConfigurationManager.AppSettings["mysql-host"]); long userTypeId = 0; long groupTypeId = 0; long applicationTypeId = 0; Dictionary<string, long> primitiveTypeIds; System.Web.Caching.Cache cache; object o = null; if (HttpContext.Current != null && HttpContext.Current.Cache != null) { cache = HttpContext.Current.Cache; } else { cache = new System.Web.Caching.Cache(); } if (cache != null) { try { o = cache.Get("primitiveTypeIds"); } catch (NullReferenceException) { } } if (o != null && o is Dictionary<string, long>) { primitiveTypeIds = (Dictionary<string, long>)o; userTypeId = primitiveTypeIds[typeof(User).FullName]; groupTypeId = primitiveTypeIds[typeof(UserGroup).FullName]; applicationTypeId = primitiveTypeIds[typeof(ApplicationEntry).FullName]; } else { SelectQuery query2 = new SelectQuery("item_types"); query2.AddFields("type_id", "type_namespace"); query2.AddCondition("type_primitive", true); System.Data.Common.DbDataReader typeReader = db.ReaderQuery(query2); primitiveTypeIds = new Dictionary<string, long>(256, StringComparer.Ordinal); while(typeReader.Read()) { primitiveTypeIds.Add((string)typeReader["type_namespace"], (long)typeReader["type_id"]); if ((string)typeReader["type_namespace"] == typeof(User).FullName) { userTypeId = (long)typeReader["type_id"]; } else if ((string)typeReader["type_namespace"] == typeof(UserGroup).FullName) { groupTypeId = (long)typeReader["type_id"]; } } typeReader.Close(); typeReader.Dispose(); if (cache != null) { cache.Add("primitiveTypeIds", primitiveTypeIds, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(12, 0, 0), CacheItemPriority.High, null); } } System.Data.Common.DbDataReader dnsReader = db.ReaderQuery(query); if (dnsReader.HasRows) { dnsReader.Read(); long typeId = (long)dnsReader["dns_owner_type"]; string dnsOwnerKey = (string)dnsReader["dns_owner_key"]; dnsReader.Close(); dnsReader.Dispose(); if (typeId == groupTypeId) { patterns.Add(new string[] { @"^/comment(/|)$", @"/comment.aspx" }); patterns.Add(new string[] { string.Format(@"^/styles/group/{0}.css$", dnsOwnerKey), string.Format(@"/groupstyle.aspx?gn={0}", dnsOwnerKey) }); patterns.Add(new string[] { string.Format(@"^/images/group/_([a-z]+)/{0}.png$", dnsOwnerKey), string.Format(@"/identicon.aspx?gn={0}&mode=$1", dnsOwnerKey) }); patterns.Add(new string[] { string.Format(@"^/images/group/_([a-z]+)/{0}@2x.png$", dnsOwnerKey), string.Format(@"/identicon.aspx?gn={0}&mode=$1&retina=true", dnsOwnerKey) }); patterns.Add(new string[] { @"^/account/([a-z\-]+)/([a-z\-]+)(/|)$", string.Format(@"/groupaccount.aspx?gn={0}&module=$1&sub=$2", dnsOwnerKey) }); patterns.Add(new string[] { @"^/account/([a-z\-]+)(/|)$", string.Format(@"/groupaccount.aspx?gn={0}&module=$1", dnsOwnerKey) }); patterns.Add(new string[] { @"^/account(/|)$", string.Format(@"/groupaccount.aspx?gn={0}", dnsOwnerKey) }); patterns.Add(new string[] { @"^(/|)$", string.Format(@"/grouppage.aspx?gn={0}&path=", dnsOwnerKey) }); patterns.Add(new string[] { @"^/(.+)(/|)$", string.Format(@"/grouppage.aspx?gn={0}&path=$1", dnsOwnerKey) }); } if (typeId == userTypeId) { patterns.Add(new string[] { @"^/comment(/|)$", @"/comment.aspx" }); patterns.Add(new string[] { @"^/api/acl/get-groups(/|)$", @"/functions.aspx?fun=permission-groups-list" }); patterns.Add(new string[] { @"^/api/acl(/|)$", @"/acl.aspx" }); patterns.Add(new string[] { @"^/api/statistics(/|)$", @"/statistics.aspx" }); patterns.Add(new string[] { @"^/api/rate(/|)$", @"/rate.aspx" }); patterns.Add(new string[] { @"^/api/comment(/|)$", @"/comment.aspx" }); patterns.Add(new string[] { @"^/api/like(/|)$", @"/like.aspx" }); patterns.Add(new string[] { @"^/api/share(/|)$", @"/share.aspx" }); patterns.Add(new string[] { @"^/api/subscribe(/|)$", @"/subscribe.aspx" }); patterns.Add(new string[] { @"^/api/functions(/|)$", @"/functions.aspx" }); patterns.Add(new string[] { @"^/api/friends(/|)$", @"/functions.aspx?fun=friend-list" }); patterns.Add(new string[] { @"^/api/tags(/|)$", @"/functions.aspx?fun=tag-list" }); patterns.Add(new string[] { @"^/api/card(/|)$", @"/functions.aspx?fun=contact-card" }); patterns.Add(new string[] { @"^/api/feed(/|)$", @"/functions.aspx?fun=feed" }); patterns.Add(new string[] { @"^/api/oembed(/|)$", @"/functions.aspx?fun=embed" }); patterns.Add(new string[] { @"^/api/log-view(/|)$", @"/functions.aspx?fun=log-view" }); patterns.Add(new string[] { string.Format(@"^/styles/user/{0}.css$", dnsOwnerKey), string.Format(@"/userstyle.aspx?un={0}", dnsOwnerKey) }); patterns.Add(new string[] { string.Format(@"^/images/user/_([a-z]+)/{0}.png$", dnsOwnerKey), string.Format(@"/identicon.aspx?un={0}&mode=$1", dnsOwnerKey) }); patterns.Add(new string[] { string.Format(@"^/images/user/_([a-z]+)/{0}@2x.png$", dnsOwnerKey), string.Format(@"/identicon.aspx?un={0}&mode=$1&retina=true", dnsOwnerKey) }); patterns.Add(new string[] { @"^/account/([a-z\-]+)/([a-z\-]+)(/|)$", @"/account.aspx?module=$1&sub=$2" }); patterns.Add(new string[] { @"^/account/([a-z\-]+)(/|)$", @"/account.aspx?module=$1" }); patterns.Add(new string[] { @"^/account(/|)$", @"/account.aspx" }); patterns.Add(new string[] { @"^(/|)$", string.Format(@"/memberpage.aspx?un={0}&path=", dnsOwnerKey) }); patterns.Add(new string[] { @"^/(.+)(/|)$", string.Format(@"/memberpage.aspx?un={0}&path=$1", dnsOwnerKey) }); } } else { dnsReader.Close(); dnsReader.Dispose(); return; } db.CloseConnection(); } else { patterns.Add(new string[] { @"^/images/corners-(top|bottom|middle)-([0-9a-f\-_]{6})-([0-9\-_]+)-([0-9\-_]+).png$", @"/corners.aspx?location=$1&width=$3&roundness=$4&colour=$2&ext=png" }); patterns.Add(new string[] { @"^/images/corners-(top|bottom|middle)-([0-9a-f\-_]{6})-([0-9\-_]+)-([0-9\-_]+).gif$", @"/corners.aspx?location=$1&width=$3&roundness=$4&colour=$2&ext=gif" }); patterns.Add(new string[] { @"^/images/corners-(top|bottom|middle)-(left|right|centre)-([0-9a-f\-_]{6})-([0-9\-_]+)-([0-9\-_]+).png$", @"/corners.aspx?location=$1,$2&width=$4&roundness=$5&colour=$3&ext=png" }); patterns.Add(new string[] { @"^/images/corners-(top|bottom|middle)-(left|right|centre)-([0-9a-f\-_]{6})-([0-9\-_]+)-([0-9\-_]+).gif$", @"/corners.aspx?location=$1,$2&width=$4&roundness=$5&colour=$3&ext=gif" }); patterns.Add(new string[] { @"^/about(/|)$", @"/about.aspx" }); patterns.Add(new string[] { @"^/opensource(/|)$", @"/opensource.aspx" }); patterns.Add(new string[] { @"^/safety(/|)$", @"/safety.aspx" }); patterns.Add(new string[] { @"^/privacy(/|)$", @"/privacy.aspx" }); patterns.Add(new string[] { @"^/terms-of-service(/|)$", @"/tos.aspx" }); patterns.Add(new string[] { @"^/site-map(/|)$", @"/sitemap.aspx" }); patterns.Add(new string[] { @"^/copyright(/|)$", @"/copyright.aspx" }); patterns.Add(new string[] { @"^/register(/|)$", @"/register.aspx" }); patterns.Add(new string[] { @"^/sign-in(/|)$", @"/login.aspx" }); patterns.Add(new string[] { @"^/login(/|)$", @"/login.aspx" }); patterns.Add(new string[] { @"^/search(/|)$", @"/search.aspx" }); patterns.Add(new string[] { @"^/comment(/|)$", @"/comment.aspx" }); patterns.Add(new string[] { @"^/api/acl/get-groups(/|)$", @"/functions.aspx?fun=permission-groups-list" }); patterns.Add(new string[] { @"^/api/acl(/|)$", @"/acl.aspx" }); patterns.Add(new string[] { @"^/api/statistics(/|)$", @"/statistics.aspx" }); patterns.Add(new string[] { @"^/api/rate(/|)$", @"/rate.aspx" }); patterns.Add(new string[] { @"^/api/comment(/|)$", @"/comment.aspx" }); patterns.Add(new string[] { @"^/api/like(/|)$", @"/like.aspx" }); patterns.Add(new string[] { @"^/api/share(/|)$", @"/share.aspx" }); patterns.Add(new string[] { @"^/api/subscribe(/|)$", @"/subscribe.aspx" }); patterns.Add(new string[] { @"^/api/functions(/|)$", @"/functions.aspx" }); patterns.Add(new string[] { @"^/api/friends(/|)$", @"/functions.aspx?fun=friend-list" }); patterns.Add(new string[] { @"^/api/tags(/|)$", @"/functions.aspx?fun=tag-list" }); patterns.Add(new string[] { @"^/api/card(/|)$", @"/functions.aspx?fun=contact-card" }); patterns.Add(new string[] { @"^/api/feed(/|)$", @"/functions.aspx?fun=feed" }); patterns.Add(new string[] { @"^/api/oembed(/|)$", @"/functions.aspx?fun=embed" }); patterns.Add(new string[] { @"^/api/log-view(/|)$", @"/functions.aspx?fun=log-view" }); patterns.Add(new string[] { @"^/api/twitter/callback(/|)$", @"/functions.aspx?fun=twitter" }); patterns.Add(new string[] { @"^/api/googleplus/callback(/|)$", @"/functions.aspx?fun=googleplus" }); patterns.Add(new string[] { @"^/api/facebook/callback(/|)$", @"/functions.aspx?fun=facebook" }); patterns.Add(new string[] { @"^/api/tumblr/callback(/|)$", @"/functions.aspx?fun=tumblr" }); patterns.Add(new string[] { @"^/api/boxsocial/callback(/|)$", @"/functions.aspx?fun=boxsocial" }); patterns.Add(new string[] { @"^/api/sms/callback/([a-z\-]+)(/|)$", @"/functions.aspx?fun=sms&provider=$1" }); patterns.Add(new string[] { @"^/oauth/request_token(/|)$", @"/oauth.aspx?global_method=request_token" }); patterns.Add(new string[] { @"^/oauth/authorize(/|)$", @"/functions.aspx?fun=oauth&method=authorize" }); patterns.Add(new string[] { @"^/oauth/approve(/|)$", @"/functions.aspx?fun=oauth&method=approve" }); patterns.Add(new string[] { @"^/oauth/access_token(/|)$", @"/oauth.aspx?global_method=access_token" }); patterns.Add(new string[] { @"^/oauth/([A-Za-z0-9\-_]+)/([A-Za-z0-9\-_\/]+)(/|)$", @"/oauth.aspx?global_method=call&global_an=$1&global_call=$2" }); patterns.Add(new string[] { @"^/account/([a-z\-]+)/([a-z\-]+)(/|)$", @"/account.aspx?module=$1&sub=$2" }); patterns.Add(new string[] { @"^/account/([a-z\-]+)(/|)$", @"/account.aspx?module=$1" }); patterns.Add(new string[] { @"^/account(/|)$", @"/account.aspx" }); patterns.Add(new string[] { @"^/s/([A-Za-z0-9\-_]+)(/|)$", @"/shorturl.aspx?key=$1" }); patterns.Add(new string[] { @"^/group/([A-Za-z0-9\-_]+)/account/([a-z\-]+)/([a-z\-]+)(/|)$", @"/groupaccount.aspx?gn=$1&module=$2&sub=$3" }); patterns.Add(new string[] { @"^/group/([A-Za-z0-9\-_]+)/account/([a-z\-]+)(/|)$", @"/groupaccount.aspx?gn=$1&module=$2" }); patterns.Add(new string[] { @"^/group/([A-Za-z0-9\-_]+)/account(/|)$", @"/groupaccount.aspx?gn=$1" }); patterns.Add(new string[] { @"^/music/([A-Za-z0-9\-_]+)/account/([a-z\-]+)/([a-z\-]+)(/|)$", @"/musicaccount.aspx?mn=$1&module=$2&sub=$3" }); patterns.Add(new string[] { @"^/music/([A-Za-z0-9\-_]+)/account/([a-z\-]+)(/|)$", @"/musicaccount.aspx?mn=$1&module=$2" }); patterns.Add(new string[] { @"^/music/([A-Za-z0-9\-_]+)/account(/|)$", @"/musicaccount.aspx?mn=$1" }); patterns.Add(new string[] { @"^/styles/user/([A-Za-z0-9\-_\.]+).css$", @"/userstyle.aspx?un=$1" }); patterns.Add(new string[] { @"^/styles/group/([A-Za-z0-9\-_\.]+).css$", @"/groupstyle.aspx?gn=$1" }); patterns.Add(new string[] { @"^/styles/music/([A-Za-z0-9\-_\.]+).css$", @"/musicstyle.aspx?gn=$1" }); patterns.Add(new string[] { @"^/images/user/_([a-z]+)/([A-Za-z0-9\-_\.]+).png$", @"/identicon.aspx?un=$2&mode=$1"}); patterns.Add(new string[] { @"^/images/user/_([a-z]+)/([A-Za-z0-9\-_\.]+)@2x.png$", @"/identicon.aspx?un=$2&mode=$1&retina=true" }); patterns.Add(new string[] { @"^/images/group/_([a-z]+)/([A-Za-z0-9\-_\.]+).png$", @"/identicon.aspx?gn=$2&mode=$1" }); patterns.Add(new string[] { @"^/images/group/_([a-z]+)/([A-Za-z0-9\-_\.]+)@2x.png$", @"/identicon.aspx?gn=$2&mode=$1&retina=true" }); patterns.Add(new string[] { @"^/images/application/_([a-z]+)/([A-Za-z0-9\-_\.]+).png$", @"/identicon.aspx?an=$2&mode=$1" }); patterns.Add(new string[] { @"^/images/application/_([a-z]+)/([A-Za-z0-9\-_\.]+)@2x.png$", @"/identicon.aspx?an=$2&mode=$1&retina=true" }); patterns.Add(new string[] { @"^/help(/|)$", @"/help.aspx" }); patterns.Add(new string[] { @"^/help/([a-z\-]+)(/|)$", @"/help.aspx?topic=$1" }); patterns.Add(new string[] { @"^/applications(/|)$", @"/viewapplications.aspx$1" }); patterns.Add(new string[] { @"^/applications/register(/|)$", @"/registerapplication.aspx$1" }); patterns.Add(new string[] { @"^/application/([A-Za-z0-9\-_]+)/manage/([a-z\-]+)/([a-z\-]+)(/|)$", @"/applicationmanage.aspx?an=$1&module=$2&sub=$3" }); patterns.Add(new string[] { @"^/application/([A-Za-z0-9\-_]+)/manage/([a-z\-]+)(/|)$", @"/applicationmanage.aspx?an=$1&module=$2" }); patterns.Add(new string[] { @"^/application/([A-Za-z0-9\-_]+)/manage(/|)$", @"/applicationmanage.aspx?an=$1" }); patterns.Add(new string[] { @"^/application/([A-Za-z0-9\-_]+)(/|)$", @"/applicationpage.aspx?an=$1&path=" }); //patterns.Add(new string[] { @"^/groups/create(/|)$", @"/creategroup.aspx" }); patterns.Add(new string[] { @"^/groups/register(/|)$", @"/staticpage.aspx?path=groups/register" }); patterns.Add(new string[] { @"^/groups(/|)$", @"/staticpage.aspx?path=groups" }); patterns.Add(new string[] { @"^/groups/([A-Za-z0-9\-_]+)(/|)$", @"/staticpage.aspx?path=groups/$1" }); patterns.Add(new string[] { @"^/group/([A-Za-z0-9\-_]+)(/|)$", @"/grouppage.aspx?gn=$1&path=" }); //patterns.Add(new string[] { @"^/group/([A-Za-z0-9\-_]+)/images/([A-Za-z0-9\-_/\.]+)$", @"/viewimage.aspx?gn=$1&path=$2" }); patterns.Add(new string[] { @"^/networks(/|)$", @"/viewnetworks.aspx" }); patterns.Add(new string[] { @"^/networks/([A-Za-z0-9\-_\.]+)(/|)$", @"/viewnetworks.aspx?type=$1" }); patterns.Add(new string[] { @"^/network/([A-Za-z0-9\-_\.]+)(/|)$", @"/networkpage.aspx?nn=$1&path=" }); //patterns.Add(new string[] { @"^/network/([A-Za-z0-9\-_\.]+)/images/([A-Za-z0-9\-_/\.]+)$", @"/viewimage.aspx?nn=$1&path=$2" }); //patterns.Add(new string[] { @"^/musicians/create(/|)$", @"/createmusician.aspx" }); //patterns.Add(new string[] { @"^/musicians(/|)$", @"/viewmusicians.aspx$1" }); //patterns.Add(new string[] { @"^/musician/([A-Za-z0-9\-_]+)(/|)$", @"/viewmusicians.aspx?genre=$1" }); //patterns.Add(new string[] { @"^/musician/([A-Za-z0-9\-_]+)(/|)([A-Za-z0-9\-_]+)(/|)$", @"/viewmusicians.aspx?genre=$1&sub=$2" }); patterns.Add(new string[] { @"^/music/register(/|)$", @"/staticpage.aspx?path=music/register" }); patterns.Add(new string[] { @"^/music(/|)$", @"/staticpage.aspx?path=music" }); patterns.Add(new string[] { @"^/music/chart(/|)$", @"/staticpage.aspx?path=music/chart" }); patterns.Add(new string[] { @"^/music/directory(/|)$", @"/staticpage.aspx?path=music/directory" }); patterns.Add(new string[] { @"^/music/directory/genres(/|)$", @"/staticpage.aspx?path=music/directory/genres" }); patterns.Add(new string[] { @"^/music/directory/genre/([a-z0-9\-_\+]+)(/|)$", @"/staticpage.aspx?path=music/directory/genres/$1" }); patterns.Add(new string[] { @"^/music/([A-Za-z0-9\-_]+)(/|)$", @"/musicpage.aspx?mn=$1&path=" }); patterns.Add(new string[] { @"^/user/([A-Za-z0-9\-_\.]+)(/|)$", @"/memberpage.aspx?un=$1&path=" }); //patterns.Add(new string[] { @"^/([A-Za-z0-9\-_]+)/profile(/|)$", @"/viewprofile.aspx?un=$1" }); //patterns.Add(new string[] { @"^/([A-Za-z0-9\-_]+)/images/([A-Za-z0-9\-_/\.]+)$", @"/viewimage.aspx?un=$1&path=$2" }); /* Wildcard for application loader */ patterns.Add(new string[] { @"^/application/([A-Za-z0-9\-_]+)/(.+)(/|)$", @"/applicationpage.aspx?an=$1&path=$2" }); patterns.Add(new string[] { @"^/group/([A-Za-z0-9\-_]+)/(.+)(/|)$", @"/grouppage.aspx?gn=$1&path=$2" }); patterns.Add(new string[] { @"^/network/([A-Za-z0-9\-_\.]+)/(.+)(/|)$", @"/networkpage.aspx?nn=$1&path=$2" }); patterns.Add(new string[] { @"^/music/([A-Za-z0-9\-_]+)/(.+)(/|)$", @"/musicpage.aspx?mn=$1&path=$2" }); patterns.Add(new string[] { @"^/user/([A-Za-z0-9\-_\.]+)/(.+)(/|)$", @"/memberpage.aspx?un=$1&path=$2" }); } // fast cull int ioc = currentURI.IndexOf('/', 1); if (ioc >= 1) { for (int i = 0; i < patterns.Count; i++) // (string[] pattern in patterns) { string[] pattern = patterns[i]; int iop = pattern[0].IndexOf('/', 2); if (iop >= 2) { if (currentURI.Substring(1, ioc - 1).Equals(pattern[0].Substring(2, iop - 2))) { if (Regex.IsMatch(currentURI, pattern[0])) { Regex rex = new Regex(pattern[0]); currentURI = rex.Replace(currentURI, pattern[1]); if (currentURI.Contains("?")) { httpContext.RewritePath(currentURI.TrimEnd(new char[] { '/' }) + "&" + cUri.Query.TrimStart(new char[] { '?' })); return; } else { httpContext.RewritePath(currentURI.TrimEnd(new char[] { '/' }) + cUri.Query); return; } } } } } } // full catch all for (int i = 0; i < patterns.Count; i++) //foreach (string[] pattern in patterns) { string[] pattern = patterns[i]; if (Regex.IsMatch(currentURI, pattern[0])) { Regex rex = new Regex(pattern[0]); currentURI = rex.Replace(currentURI, pattern[1]); if (currentURI.Contains("?")) { httpContext.RewritePath(currentURI.TrimEnd(new char[] { '/' }) + "&" + cUri.Query.TrimStart(new char[] { '?' })); return; } else { httpContext.RewritePath(currentURI.TrimEnd(new char[] { '/' }) + cUri.Query); return; } } } } }
public PrimitivesCache(Core core) { this.core = core; this.db = core.Db; }
/// <summary> /// Checks a given gallery slug to ensure uniqueness /// </summary> /// <param name="db">Database</param> /// <param name="owner">Gallery owner</param> /// <param name="parentFullPath">Parent path</param> /// <param name="slug">Slug to check for uniqueness</param> /// <returns>True if slug is unique given owner and parent</returns> public static bool CheckGallerySlugUnique(Mysql db, Primitive owner, string parentFullPath, string slug) { DataTable galleryGalleryTable = db.Query(string.Format("SELECT gallery_path FROM user_galleries WHERE gallery_item_id = {0} AND gallery_item_type_id = {1} AND gallery_parent_path = '{2}' AND gallery_path = '{3}';", owner.Id, owner.TypeId, Mysql.Escape(parentFullPath), Mysql.Escape(slug))); if (galleryGalleryTable.Rows.Count > 0) { return false; } else { return true; } }