@@ -1,70 +1,70 @@
#region License and copyright notice
/*
* Kaliko Content Management System
*
* Copyright (c) Fredrik Schultz
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
* http://www.gnu.org/licenses/lgpl-3.0.html
*/
#endregion

namespace KalikoCMS.Admin.Content.PropertyType {
using System;
using System.Globalization;
using System.Web.UI;
using Configuration;
using Core;
using KalikoCMS.PropertyType;

public partial class LinkPropertyEditor : PropertyEditorBase {
public override string PropertyLabel {
set { LabelText.Text = value; }
}

public override PropertyData PropertyValue {
get {
string url = Url.Value;
string type = Type.Value;
return new LinkProperty(url, type);
}
set {
var linkProperty = ((LinkProperty)value);
DisplayField.Text = linkProperty.Url;
Url.Value = linkProperty.Url;
Type.Value = ((int)linkProperty.Type).ToString(CultureInfo.InvariantCulture);
}
}

public override string Parameters {
set { throw new NotImplementedException(); }
}

public override bool Validate() {
throw new NotImplementedException();
}

public override bool Validate(bool required) {
throw new NotImplementedException();
}

protected override void OnLoad(EventArgs e) {
base.OnLoad(e);

ScriptManager.RegisterClientScriptInclude(this, typeof(LinkPropertyEditor), "Admin.Content.PropertyType.LinkPropertyEditor", SiteSettings.Instance.AdminPath + "Content/PropertyType/LinkPropertyEditor.js");
ScriptManager.RegisterClientScriptInclude(this, typeof(FilePropertyEditor), "Admin.Content.PropertyType.FilePropertyEditor", SiteSettings.Instance.AdminPath + "Content/PropertyType/FilePropertyEditor.js");
ScriptManager.RegisterClientScriptInclude(this, typeof(PageLinkPropertyEditor), "Admin.Content.PropertyType.PageLinkPropertyEditor", SiteSettings.Instance.AdminPath + "Content/PropertyType/PageLinkPropertyEditor.js");

string clickScript = string.Format("top.propertyEditor.link.openDialog('#{0}','#{1}', '#{2}');return false;", Url.ClientID, Type.ClientID, DisplayField.ClientID);
SelectButton.Attributes["onclick"] = clickScript;
}
}
#region License and copyright notice
/*
* Kaliko Content Management System
*
* Copyright (c) Fredrik Schultz
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
* http://www.gnu.org/licenses/lgpl-3.0.html
*/
#endregion

namespace KalikoCMS.Admin.Content.PropertyType {
using System;
using System.Globalization;
using System.Web.UI;
using Configuration;
using Core;
using KalikoCMS.PropertyType;

public partial class LinkPropertyEditor : PropertyEditorBase {
public override string PropertyLabel {
set { LabelText.Text = value; }
}

public override PropertyData PropertyValue {
get {
string url = Url.Value;
string type = Type.Value;
return new LinkProperty(url, type);
}
set {
var linkProperty = ((LinkProperty)value);
DisplayField.Text = linkProperty.Url;
Url.Value = linkProperty.Url;
Type.Value = ((int)linkProperty.Type).ToString(CultureInfo.InvariantCulture);
}
}

public override string Parameters {
set { throw new NotImplementedException(); }
}

public override bool Validate() {
throw new NotImplementedException();
}

public override bool Validate(bool required) {
throw new NotImplementedException();
}

protected override void OnLoad(EventArgs e) {
base.OnLoad(e);

ScriptManager.RegisterClientScriptInclude(this, typeof(LinkPropertyEditor), "Admin.Content.PropertyType.LinkPropertyEditor", SiteSettings.Instance.AdminPath + "Content/PropertyType/LinkPropertyEditor.js");
ScriptManager.RegisterClientScriptInclude(this, typeof(FilePropertyEditor), "Admin.Content.PropertyType.FilePropertyEditor", SiteSettings.Instance.AdminPath + "Content/PropertyType/FilePropertyEditor.js");
ScriptManager.RegisterClientScriptInclude(this, typeof(PageLinkPropertyEditor), "Admin.Content.PropertyType.PageLinkPropertyEditor", SiteSettings.Instance.AdminPath + "Content/PropertyType/PageLinkPropertyEditor.js");

string clickScript = string.Format("top.propertyEditor.link.openDialog('#{0}','#{1}', '#{2}');return false;", Url.ClientID, Type.ClientID, DisplayField.ClientID);
SelectButton.Attributes["onclick"] = clickScript;
}
}
}
@@ -1,26 +1,26 @@
(function (propertyEditor) {
propertyEditor.link = {
openDialog: function (urlField, typeField, displayField) {
var url = $(urlField).val();
var type = $(typeField).val();

var callback = function (newUrl, newType) {
$(urlField).val(newUrl);
$(typeField).val(newType);
$(displayField).val(newUrl);
};

top.registerCallback(callback);

top.propertyEditor.dialogs.openSelectLinkDialog(url, type);
}
};
})(top.propertyEditor || (top.propertyEditor = {}));


(function (dialogs) {
dialogs.openSelectLinkDialog = function (url, type) {
parent.openModal("Content/Dialogs/SelectLinkDialog.aspx?url=" + escape(url) + "&type=" + type, 500, 240);
return false;
};
(function (propertyEditor) {
propertyEditor.link = {
openDialog: function (urlField, typeField, displayField) {
var url = $(urlField).val();
var type = $(typeField).val();

var callback = function (newUrl, newType) {
$(urlField).val(newUrl);
$(typeField).val(newType);
$(displayField).val(newUrl);
};

top.registerCallback(callback);

top.propertyEditor.dialogs.openSelectLinkDialog(url, type);
}
};
})(top.propertyEditor || (top.propertyEditor = {}));


(function (dialogs) {
dialogs.openSelectLinkDialog = function (url, type) {
parent.openModal("Content/Dialogs/SelectLinkDialog.aspx?url=" + escape(url) + "&type=" + type, 500, 240);
return false;
};
})(top.propertyEditor.dialogs || (top.propertyEditor.dialogs = {}));
@@ -1,83 +1,83 @@
#region License and copyright notice
/*
* Kaliko Content Management System
*
* Copyright (c) Fredrik Schultz
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
* http://www.gnu.org/licenses/lgpl-3.0.html
*/
#endregion

namespace KalikoCMS.Admin.Content.PropertyType {
using System;
using System.Globalization;
using System.Web.UI;
using KalikoCMS.Core;
using KalikoCMS.Extensions;
using KalikoCMS.PropertyType;

public partial class PageLinkPropertyEditor : PropertyEditorBase {

public override string PropertyLabel {
set { LabelText.Text = value; }
}

public override PropertyData PropertyValue {
get {
Guid pageId;
if (PageId.Value.TryParseGuid(out pageId)) {
// TODO: Lägg till språkhantering!!
return new PageLinkProperty(Language.CurrentLanguageId, pageId);
}
else {
return new PageLinkProperty();
}
}
set {
var pageLinkProperty = ((PageLinkProperty)value);

if (!pageLinkProperty.IsValid) {
return;
}

var page = pageLinkProperty.Page;

if (page != null) {
DisplayField.Text = page.PageName;
LanguageId.Value = page.LanguageId.ToString(CultureInfo.InvariantCulture);
PageId.Value = page.PageId.ToString();
}
}
}

public override string Parameters {
set { throw new NotImplementedException(); }
}

public override bool Validate() {
throw new NotImplementedException();
}

public override bool Validate(bool required) {
throw new NotImplementedException();
}

protected override void OnLoad(EventArgs e) {
base.OnLoad(e);

ScriptManager.RegisterClientScriptInclude(this, typeof(PageLinkPropertyEditor), "Admin.Content.PropertyType.PageLinkPropertyEditor", "Content/PropertyType/PageLinkPropertyEditor.js");

string clickScript = string.Format("top.propertyEditor.pageLink.openDialog($('#{0}'),$('#{1}'),$('#{2}'));return false;", LanguageId.ClientID, PageId.ClientID, DisplayField.ClientID);
SelectButton.Attributes["onclick"] = clickScript;
}
}
#region License and copyright notice
/*
* Kaliko Content Management System
*
* Copyright (c) Fredrik Schultz
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
* http://www.gnu.org/licenses/lgpl-3.0.html
*/
#endregion

namespace KalikoCMS.Admin.Content.PropertyType {
using System;
using System.Globalization;
using System.Web.UI;
using KalikoCMS.Core;
using KalikoCMS.Extensions;
using KalikoCMS.PropertyType;

public partial class PageLinkPropertyEditor : PropertyEditorBase {

public override string PropertyLabel {
set { LabelText.Text = value; }
}

public override PropertyData PropertyValue {
get {
Guid pageId;
if (PageId.Value.TryParseGuid(out pageId)) {
// TODO: Lägg till språkhantering!!
return new PageLinkProperty(Language.CurrentLanguageId, pageId);
}
else {
return new PageLinkProperty();
}
}
set {
var pageLinkProperty = ((PageLinkProperty)value);

if (!pageLinkProperty.IsValid) {
return;
}

var page = pageLinkProperty.Page;

if (page != null) {
DisplayField.Text = page.PageName;
LanguageId.Value = page.LanguageId.ToString(CultureInfo.InvariantCulture);
PageId.Value = page.PageId.ToString();
}
}
}

public override string Parameters {
set { throw new NotImplementedException(); }
}

public override bool Validate() {
throw new NotImplementedException();
}

public override bool Validate(bool required) {
throw new NotImplementedException();
}

protected override void OnLoad(EventArgs e) {
base.OnLoad(e);

ScriptManager.RegisterClientScriptInclude(this, typeof(PageLinkPropertyEditor), "Admin.Content.PropertyType.PageLinkPropertyEditor", "Content/PropertyType/PageLinkPropertyEditor.js");

string clickScript = string.Format("top.propertyEditor.pageLink.openDialog($('#{0}'),$('#{1}'),$('#{2}'));return false;", LanguageId.ClientID, PageId.ClientID, DisplayField.ClientID);
SelectButton.Attributes["onclick"] = clickScript;
}
}
}
@@ -1,25 +1,25 @@
(function (propertyEditor) {
propertyEditor.pageLink = {
openDialog: function (languageField, pageField, displayField) {
var languageId = languageField.val();
var pageId = pageField.val();

var callback = function (newPageId, newPageName) {
pageField.val(newPageId);
displayField.val(newPageName);
};

top.registerCallback(callback);

top.propertyEditor.dialogs.openSelectPageDialog(pageId, languageId);
}
};
})(top.propertyEditor || (top.propertyEditor = {}));


(function (dialogs) {
dialogs.openSelectPageDialog = function(pageId, languageId) {
parent.openModal("Content/Dialogs/SelectPageDialog.aspx?pageId=" + pageId + "&languageId=" + languageId, 500, 400);
return false;
};
(function (propertyEditor) {
propertyEditor.pageLink = {
openDialog: function (languageField, pageField, displayField) {
var languageId = languageField.val();
var pageId = pageField.val();

var callback = function (newPageId, newPageName) {
pageField.val(newPageId);
displayField.val(newPageName);
};

top.registerCallback(callback);

top.propertyEditor.dialogs.openSelectPageDialog(pageId, languageId);
}
};
})(top.propertyEditor || (top.propertyEditor = {}));


(function (dialogs) {
dialogs.openSelectPageDialog = function(pageId, languageId) {
parent.openModal("Content/Dialogs/SelectPageDialog.aspx?pageId=" + pageId + "&languageId=" + languageId, 500, 400);
return false;
};
})(top.propertyEditor.dialogs || (top.propertyEditor.dialogs = {}));
@@ -1,60 +1,60 @@
#region License and copyright notice
/*
* Kaliko Content Management System
*
* Copyright (c) Fredrik Schultz
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
* http://www.gnu.org/licenses/lgpl-3.0.html
*/
#endregion

namespace KalikoCMS.Admin.Content.PropertyType {
using KalikoCMS.Core;
using KalikoCMS.PropertyType;

public partial class StringPropertyEditor : PropertyEditorBase {

public override string PropertyLabel {
set {
LabelText.Text = value;
}
}

public override PropertyData PropertyValue {
set {
ValueField.Text = ((StringProperty)value).Value;
}
get { return new StringProperty(ValueField.Text); }
}

public override string Parameters {
set { throw new System.NotImplementedException(); }
}

public override bool Validate() {
ErrorText.Visible = false;
return true;
}

public override bool Validate(bool required) {
if(required) {
if(string.IsNullOrEmpty(ValueField.Text)) {
ErrorText.Text = "* Required";
ErrorText.Visible = true;
return false;
}
}

return Validate();
}
}
#region License and copyright notice
/*
* Kaliko Content Management System
*
* Copyright (c) Fredrik Schultz
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
* http://www.gnu.org/licenses/lgpl-3.0.html
*/
#endregion

namespace KalikoCMS.Admin.Content.PropertyType {
using KalikoCMS.Core;
using KalikoCMS.PropertyType;

public partial class StringPropertyEditor : PropertyEditorBase {

public override string PropertyLabel {
set {
LabelText.Text = value;
}
}

public override PropertyData PropertyValue {
set {
ValueField.Text = ((StringProperty)value).Value;
}
get { return new StringProperty(ValueField.Text); }
}

public override string Parameters {
set { throw new System.NotImplementedException(); }
}

public override bool Validate() {
ErrorText.Visible = false;
return true;
}

public override bool Validate(bool required) {
if(required) {
if(string.IsNullOrEmpty(ValueField.Text)) {
ErrorText.Text = "* Required";
ErrorText.Visible = true;
return false;
}
}

return Validate();
}
}
}
@@ -1,56 +1,56 @@
#region License and copyright notice
/*
* Kaliko Content Management System
*
* Copyright (c) Fredrik Schultz
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
* http://www.gnu.org/licenses/lgpl-3.0.html
*/
#endregion

namespace KalikoCMS.Admin.Content.PropertyType {
using KalikoCMS.Core;
using KalikoCMS.PropertyType;

public partial class TextPropertyEditor : PropertyEditorBase {

public override string PropertyLabel {
set { LabelText.Text = value; }
}

public override PropertyData PropertyValue {
set { ValueField.Text = ((TextProperty)value).Value; }
get { return new TextProperty(ValueField.Text); }
}

public override string Parameters {
set { throw new System.NotImplementedException(); }
}

public override bool Validate() {
ErrorText.Visible = false;
return true;
}

public override bool Validate(bool required) {
if (required) {
if (string.IsNullOrEmpty(ValueField.Text)) {
ErrorText.Text = "* Required";
ErrorText.Visible = true;
return false;
}
}

return Validate();
}
}
#region License and copyright notice
/*
* Kaliko Content Management System
*
* Copyright (c) Fredrik Schultz
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
* http://www.gnu.org/licenses/lgpl-3.0.html
*/
#endregion

namespace KalikoCMS.Admin.Content.PropertyType {
using KalikoCMS.Core;
using KalikoCMS.PropertyType;

public partial class TextPropertyEditor : PropertyEditorBase {

public override string PropertyLabel {
set { LabelText.Text = value; }
}

public override PropertyData PropertyValue {
set { ValueField.Text = ((TextProperty)value).Value; }
get { return new TextProperty(ValueField.Text); }
}

public override string Parameters {
set { throw new System.NotImplementedException(); }
}

public override bool Validate() {
ErrorText.Visible = false;
return true;
}

public override bool Validate(bool required) {
if (required) {
if (string.IsNullOrEmpty(ValueField.Text)) {
ErrorText.Text = "* Required";
ErrorText.Visible = true;
return false;
}
}

return Validate();
}
}
}
@@ -1 +1 @@
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="KalikoCMS.Admin.Default" %>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="KalikoCMS.Admin.Default" %>
@@ -1 +1 @@
<%@ WebHandler Language="C#" CodeBehind="FileHandler.ashx.cs" Class="KalikoCMS.Admin.Handlers.FileHandler" %>
<%@ WebHandler Language="C#" CodeBehind="FileHandler.ashx.cs" Class="KalikoCMS.Admin.Handlers.FileHandler" %>
@@ -1,140 +1,140 @@
#region License and copyright notice
/*
* Kaliko Content Management System
*
* Copyright (c) Fredrik Schultz
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
* http://www.gnu.org/licenses/lgpl-3.0.html
*/
#endregion

namespace KalikoCMS.Admin.Handlers {
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using System.Web;
using Configuration;
using Kaliko;

public class FileHandler : IHttpHandler {
private static readonly Regex BlockedFilesRegex = new Regex(SiteSettings.Instance.BlockedFileExtensions, RegexOptions.IgnoreCase);

public void ProcessRequest(HttpContext context) {
context.Response.ContentType = "text/plain";

var uploads = new List<UploadFileInfo>();

var basePath = HttpContext.Current.Request.Form["path"];

if (!basePath.StartsWith(SiteSettings.Instance.FilePath)) {
var exception = new AccessViolationException(string.Format("Wrong path for uploads! {0}", basePath));
Logger.Write(exception, Logger.Severity.Major);
throw exception;
}

basePath = HttpContext.Current.Server.MapPath(basePath);

foreach (string file in context.Request.Files) {
var postedFile = context.Request.Files[file];
string fileName;

if (postedFile.ContentLength == 0) {
continue;
}

if (postedFile.FileName.Contains("\\")) {
string[] parts = postedFile.FileName.Split(new[] {'\\'});
fileName = parts[parts.Length - 1];
}
else {
fileName = postedFile.FileName;
}

if (IsFileExtensionBlocked(fileName)) {
Logger.Write(string.Format("Upload of {0} blocked since file type is not allowed.", fileName), Logger.Severity.Major);
uploads.Add(new UploadFileInfo {
name = Path.GetFileName(fileName),
size = postedFile.ContentLength,
type = postedFile.ContentType,
error = "Filetype not allowed!"
});
continue;
}

var savedFileName = GetUniqueFileName(basePath, fileName);
postedFile.SaveAs(savedFileName);

uploads.Add(new UploadFileInfo {
name = Path.GetFileName(savedFileName),
size = postedFile.ContentLength,
type = postedFile.ContentType
});
}

var uploadResult = new UploadResult(uploads);
var serializedUploadInfo = Serialization.JsonSerialization.SerializeJson(uploadResult);
context.Response.Write(serializedUploadInfo);
}

private bool IsFileExtensionBlocked(string fileName) {
var extension = Path.GetExtension(fileName);

if (extension != null && BlockedFilesRegex.IsMatch(extension)) {
return true;
}

return false;
}

private string GetUniqueFileName(string basePath, string fileName) {
var path = Path.Combine(basePath, fileName);

if (!File.Exists(path)) {
return path;
}

var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(path);
var extension = Path.GetExtension(path);

for (int i = 1; i < 1000; i++) {
path = string.Format("{0}{1}_{2}{3}", basePath, fileNameWithoutExtension, i, extension);
if (!File.Exists(path)) {
return path;
}
}

return basePath + Path.GetRandomFileName() + extension;
}

public bool IsReusable {
get { return false; }
}

// ReSharper disable InconsistentNaming
public class UploadResult {
public UploadResult(List<UploadFileInfo> fileList) {
files = fileList.ToArray();
}

public UploadFileInfo[] files { get; set; }
}

public class UploadFileInfo {
public string name { get; set; }
public long size { get; set; }
public string type { get; set; }
public string error { get; set; }
}
// ReSharper restore InconsistentNaming
}
#region License and copyright notice
/*
* Kaliko Content Management System
*
* Copyright (c) Fredrik Schultz
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
* http://www.gnu.org/licenses/lgpl-3.0.html
*/
#endregion

namespace KalikoCMS.Admin.Handlers {
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using System.Web;
using Configuration;
using Kaliko;

public class FileHandler : IHttpHandler {
private static readonly Regex BlockedFilesRegex = new Regex(SiteSettings.Instance.BlockedFileExtensions, RegexOptions.IgnoreCase);

public void ProcessRequest(HttpContext context) {
context.Response.ContentType = "text/plain";

var uploads = new List<UploadFileInfo>();

var basePath = HttpContext.Current.Request.Form["path"];

if (!basePath.StartsWith(SiteSettings.Instance.FilePath)) {
var exception = new AccessViolationException(string.Format("Wrong path for uploads! {0}", basePath));
Logger.Write(exception, Logger.Severity.Major);
throw exception;
}

basePath = HttpContext.Current.Server.MapPath(basePath);

foreach (string file in context.Request.Files) {
var postedFile = context.Request.Files[file];
string fileName;

if (postedFile.ContentLength == 0) {
continue;
}

if (postedFile.FileName.Contains("\\")) {
string[] parts = postedFile.FileName.Split(new[] {'\\'});
fileName = parts[parts.Length - 1];
}
else {
fileName = postedFile.FileName;
}

if (IsFileExtensionBlocked(fileName)) {
Logger.Write(string.Format("Upload of {0} blocked since file type is not allowed.", fileName), Logger.Severity.Major);
uploads.Add(new UploadFileInfo {
name = Path.GetFileName(fileName),
size = postedFile.ContentLength,
type = postedFile.ContentType,
error = "Filetype not allowed!"
});
continue;
}

var savedFileName = GetUniqueFileName(basePath, fileName);
postedFile.SaveAs(savedFileName);

uploads.Add(new UploadFileInfo {
name = Path.GetFileName(savedFileName),
size = postedFile.ContentLength,
type = postedFile.ContentType
});
}

var uploadResult = new UploadResult(uploads);
var serializedUploadInfo = Serialization.JsonSerialization.SerializeJson(uploadResult);
context.Response.Write(serializedUploadInfo);
}

private bool IsFileExtensionBlocked(string fileName) {
var extension = Path.GetExtension(fileName);

if (extension != null && BlockedFilesRegex.IsMatch(extension)) {
return true;
}

return false;
}

private string GetUniqueFileName(string basePath, string fileName) {
var path = Path.Combine(basePath, fileName);

if (!File.Exists(path)) {
return path;
}

var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(path);
var extension = Path.GetExtension(path);

for (int i = 1; i < 1000; i++) {
path = string.Format("{0}{1}_{2}{3}", basePath, fileNameWithoutExtension, i, extension);
if (!File.Exists(path)) {
return path;
}
}

return basePath + Path.GetRandomFileName() + extension;
}

public bool IsReusable {
get { return false; }
}

// ReSharper disable InconsistentNaming
public class UploadResult {
public UploadResult(List<UploadFileInfo> fileList) {
files = fileList.ToArray();
}

public UploadFileInfo[] files { get; set; }
}

public class UploadFileInfo {
public string name { get; set; }
public long size { get; set; }
public string type { get; set; }
public string error { get; set; }
}
// ReSharper restore InconsistentNaming
}
}
@@ -1,51 +1,51 @@
namespace KalikoCMS.Admin.WebControls {
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

public class BootstrapButton : HtmlButton {
private bool _enabled = true;

public string Icon { get; set; }

public ButtonMode Mode { get; set; }

public string Text { get; set; }

public bool Enabled {
get { return _enabled; }
set { _enabled = value; }
}

protected override void OnPreRender(System.EventArgs e) {
base.OnPreRender(e);

if (!string.IsNullOrEmpty(Icon)) {
var icon = new Literal { Text = string.Format("<i class=\"{0}\"></i> {1}", Icon, Text) };
Controls.AddAt(0, icon);
}

if (!Enabled) {
Attributes["class"] += " disabled";
Attributes.Add("disabled", "disabled");
}

if (Mode == ButtonMode.Primary) {
Attributes["class"] += " btn-primary";
}
else if (Mode == ButtonMode.Danger) {
Attributes["class"] += " btn-danger";
}
else {
Attributes["class"] += " btn-default";
}

Attributes["class"] += " btn";
}

public enum ButtonMode {
Standard,
Primary,
Danger
}
}
namespace KalikoCMS.Admin.WebControls {
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

public class BootstrapButton : HtmlButton {
private bool _enabled = true;

public string Icon { get; set; }

public ButtonMode Mode { get; set; }

public string Text { get; set; }

public bool Enabled {
get { return _enabled; }
set { _enabled = value; }
}

protected override void OnPreRender(System.EventArgs e) {
base.OnPreRender(e);

if (!string.IsNullOrEmpty(Icon)) {
var icon = new Literal { Text = string.Format("<i class=\"{0}\"></i> {1}", Icon, Text) };
Controls.AddAt(0, icon);
}

if (!Enabled) {
Attributes["class"] += " disabled";
Attributes.Add("disabled", "disabled");
}

if (Mode == ButtonMode.Primary) {
Attributes["class"] += " btn-primary";
}
else if (Mode == ButtonMode.Danger) {
Attributes["class"] += " btn-danger";
}
else {
Attributes["class"] += " btn-default";
}

Attributes["class"] += " btn";
}

public enum ButtonMode {
Standard,
Primary,
Danger
}
}
}
@@ -1,62 +1,62 @@
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="KalikoCMS.Admin.Login" %>
<!doctype html>
<html>
<head>
<title>Login</title>
<meta name="robots" content="noindex, nofollow" />
<link href='http://fonts.googleapis.com/css?family=Open+Sans:300' rel='stylesheet' type='text/css' />
<style type="text/css">
body { background: #222222; color: #ffffff; }
body, input { font-family: 'Open Sans' , sans-serif; }
.login { background: #10537B; width: 400px; margin: 100px auto 0; box-shadow: 0 0px 10px rgba(0,0,0,0.18) }
ul { padding: 0; margin: 0; }
li { display: inline-block; list-style: none outside none; }
li a { color: #ffffff; padding: 8px 24px; display: inline-block; text-decoration: none; }
li.active { background: #1570A6; }
.login-form { background: #1570A6; padding: 10px 20px; }
.login-form h1 { margin:0;font-size:40px;font-weight:100;}
.login-form p { margin-top:0; }
.control-group { width: 100%; }
.control-group input[type=text], .control-group input[type=password] { width: 340px; padding: 10px; z-index: 9; position: relative; font-size: 18px; margin-bottom:10px; }
.control-group .controls { display: inline-block; }
.btn { background: #10537B; color:#ffffff; border: medium none; padding: 8px 20px; font-size:16px;font-weight:100; cursor:pointer; margin:0 auto;width:100px; }
.checkbox { float:right; }
</style>
</head>
<body>
<form id="Form1" method="post" runat="server">
<div class="login">
<ul>
<li class="active"><a href="#">Login</a></li>
<!-- TODO: Recover password -->
</ul>
<% ((TextBox)LoginForm.FindControl("UserName")).Attributes.Add("placeholder", "Username"); %>
<% ((TextBox)LoginForm.FindControl("Password")).Attributes.Add("placeholder", "Password"); %>
<div class="login-form">
<asp:Login ID="LoginForm" runat="server" FailureText="Wrong username or password" RenderOuterTable="false">
<LayoutTemplate>
<h1>
Login to website</h1>
<p>
Enter your username and password.</p>
<div class="control-group">
<asp:TextBox ID="UserName" runat="server"></asp:TextBox>
</div>
<div class="control-group">
<asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox>
</div>
<div class="control-group">
<asp:CheckBox ID="RememberMe" runat="server" CssClass="checkbox" Text=" Remember me next time." />
</div>
<asp:Button ID="LoginButton" runat="server" CommandName="Login" Text="Log In" ValidationGroup="Login1" CssClass="btn" />
</LayoutTemplate>
</asp:Login>
</div>
</div>
<asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
<script type="text/javascript">
window.onload = function () { document.getElementById('Login1_UserName').focus(); }
</script>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="KalikoCMS.Admin.Login" %>
<!doctype html>
<html>
<head>
<title>Login</title>
<meta name="robots" content="noindex, nofollow" />
<link href='http://fonts.googleapis.com/css?family=Open+Sans:300' rel='stylesheet' type='text/css' />
<style type="text/css">
body { background: #222222; color: #ffffff; }
body, input { font-family: 'Open Sans' , sans-serif; }
.login { background: #10537B; width: 400px; margin: 100px auto 0; box-shadow: 0 0px 10px rgba(0,0,0,0.18) }
ul { padding: 0; margin: 0; }
li { display: inline-block; list-style: none outside none; }
li a { color: #ffffff; padding: 8px 24px; display: inline-block; text-decoration: none; }
li.active { background: #1570A6; }
.login-form { background: #1570A6; padding: 10px 20px; }
.login-form h1 { margin:0;font-size:40px;font-weight:100;}
.login-form p { margin-top:0; }
.control-group { width: 100%; }
.control-group input[type=text], .control-group input[type=password] { width: 340px; padding: 10px; z-index: 9; position: relative; font-size: 18px; margin-bottom:10px; }
.control-group .controls { display: inline-block; }
.btn { background: #10537B; color:#ffffff; border: medium none; padding: 8px 20px; font-size:16px;font-weight:100; cursor:pointer; margin:0 auto;width:100px; }
.checkbox { float:right; }
</style>
</head>
<body>
<form id="Form1" method="post" runat="server">
<div class="login">
<ul>
<li class="active"><a href="#">Login</a></li>
<!-- TODO: Recover password -->
</ul>
<% ((TextBox)LoginForm.FindControl("UserName")).Attributes.Add("placeholder", "Username"); %>
<% ((TextBox)LoginForm.FindControl("Password")).Attributes.Add("placeholder", "Password"); %>
<div class="login-form">
<asp:Login ID="LoginForm" runat="server" FailureText="Wrong username or password" RenderOuterTable="false">
<LayoutTemplate>
<h1>
Login to website</h1>
<p>
Enter your username and password.</p>
<div class="control-group">
<asp:TextBox ID="UserName" runat="server"></asp:TextBox>
</div>
<div class="control-group">
<asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox>
</div>
<div class="control-group">
<asp:CheckBox ID="RememberMe" runat="server" CssClass="checkbox" Text=" Remember me next time." />
</div>
<asp:Button ID="LoginButton" runat="server" CommandName="Login" Text="Log In" ValidationGroup="Login1" CssClass="btn" />
</LayoutTemplate>
</asp:Login>
</div>
</div>
<asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
<script type="text/javascript">
window.onload = function () { document.getElementById('Login1_UserName').focus(); }
</script>
</form>
</body>
</html>
@@ -1,53 +1,53 @@
#region License and copyright notice
/*
* Kaliko Content Management System
*
* Copyright (c) Fredrik Schultz
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
* http://www.gnu.org/licenses/lgpl-3.0.html
*/
#endregion

namespace KalikoCMS.Admin {
using System;
using System.Web.Security;
using Configuration;

public partial class Login : System.Web.UI.Page {
private void Page_Load(object sender, EventArgs e) {
if (Request.QueryString["cmd"] == "logout") {
FormsAuthentication.SignOut();
Response.Redirect(Request.Path);
}

FailureText.Text = string.Empty;

LoginForm.LoggedIn += LoggedInHandler;
LoginForm.LoginError += LoginErrorHandler;

if (!IsPostBack) {
DataBind();
}
}

void LoginErrorHandler(object sender, EventArgs e) {
FailureText.Text = "Login failed!";
}

private void LoggedInHandler(object sender, EventArgs e) {
if (Roles.IsUserInRole(LoginForm.UserName, "WebAdmin")) {
Response.Redirect(SiteSettings.Instance.AdminPath);
}
}

}
}
#region License and copyright notice
/*
* Kaliko Content Management System
*
* Copyright (c) Fredrik Schultz
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
* http://www.gnu.org/licenses/lgpl-3.0.html
*/
#endregion

namespace KalikoCMS.Admin {
using System;
using System.Web.Security;
using Configuration;

public partial class Login : System.Web.UI.Page {
private void Page_Load(object sender, EventArgs e) {
if (Request.QueryString["cmd"] == "logout") {
FormsAuthentication.SignOut();
Response.Redirect(Request.Path);
}

FailureText.Text = string.Empty;

LoginForm.LoggedIn += LoggedInHandler;
LoginForm.LoginError += LoginErrorHandler;

if (!IsPostBack) {
DataBind();
}
}

void LoginErrorHandler(object sender, EventArgs e) {
FailureText.Text = "Login failed!";
}

private void LoggedInHandler(object sender, EventArgs e) {
if (Roles.IsUserInRole(LoginForm.UserName, "WebAdmin")) {
Response.Redirect(SiteSettings.Instance.AdminPath);
}
}

}
}
@@ -1,30 +1,30 @@
<?xml version="1.0"?>

<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<!--
In the example below, the "SetAttributes" transform will change the value of
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
finds an atrribute "name" that has a value of "MyDB".
<connectionStrings>
<add name="MyDB"
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
-->
<system.web>
<!--
In the example below, the "Replace" transform will replace the entire
<customErrors> section of your web.config file.
Note that because there is only one customErrors section under the
<system.web> node, there is no need to use the "xdt:Locator" attribute.
<customErrors defaultRedirect="GenericError.htm"
mode="RemoteOnly" xdt:Transform="Replace">
<error statusCode="500" redirect="InternalError.htm"/>
</customErrors>
-->
</system.web>
<?xml version="1.0"?>

<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<!--
In the example below, the "SetAttributes" transform will change the value of
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
finds an atrribute "name" that has a value of "MyDB".
<connectionStrings>
<add name="MyDB"
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
-->
<system.web>
<!--
In the example below, the "Replace" transform will replace the entire
<customErrors> section of your web.config file.
Note that because there is only one customErrors section under the
<system.web> node, there is no need to use the "xdt:Locator" attribute.
<customErrors defaultRedirect="GenericError.htm"
mode="RemoteOnly" xdt:Transform="Replace">
<error statusCode="500" redirect="InternalError.htm"/>
</customErrors>
-->
</system.web>
</configuration>
@@ -1,31 +1,31 @@
<?xml version="1.0"?>

<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<!--
In the example below, the "SetAttributes" transform will change the value of
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
finds an atrribute "name" that has a value of "MyDB".
<connectionStrings>
<add name="MyDB"
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
-->
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
<!--
In the example below, the "Replace" transform will replace the entire
<customErrors> section of your web.config file.
Note that because there is only one customErrors section under the
<system.web> node, there is no need to use the "xdt:Locator" attribute.
<customErrors defaultRedirect="GenericError.htm"
mode="RemoteOnly" xdt:Transform="Replace">
<error statusCode="500" redirect="InternalError.htm"/>
</customErrors>
-->
</system.web>
<?xml version="1.0"?>

<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<!--
In the example below, the "SetAttributes" transform will change the value of
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
finds an atrribute "name" that has a value of "MyDB".
<connectionStrings>
<add name="MyDB"
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
-->
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
<!--
In the example below, the "Replace" transform will replace the entire
<customErrors> section of your web.config file.
Note that because there is only one customErrors section under the
<system.web> node, there is no need to use the "xdt:Locator" attribute.
<customErrors defaultRedirect="GenericError.htm"
mode="RemoteOnly" xdt:Transform="Replace">
<error statusCode="500" redirect="InternalError.htm"/>
</customErrors>
-->
</system.web>
</configuration>
@@ -1,40 +1,40 @@
#region License and copyright notice
/*
* Kaliko Content Management System
*
* Copyright (c) Fredrik Schultz
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
* http://www.gnu.org/licenses/lgpl-3.0.html
*/
#endregion

namespace KalikoCMS.Attributes {
using System;

[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
public class PropertyAttribute : Attribute {

public string Header { get; private set; }

public PropertyAttribute(string header) {
Header = header;
}

public virtual string Parameters {
get { return null; }
}

public virtual bool IsTypeValid(Type type) {
return true;
}
}
}
#region License and copyright notice
/*
* Kaliko Content Management System
*
* Copyright (c) Fredrik Schultz
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
* http://www.gnu.org/licenses/lgpl-3.0.html
*/
#endregion

namespace KalikoCMS.Attributes {
using System;

[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
public class PropertyAttribute : Attribute {

public string Header { get; private set; }

public PropertyAttribute(string header) {
Header = header;
}

public virtual string Parameters {
get { return null; }
}

public virtual bool IsTypeValid(Type type) {
return true;
}
}
}
@@ -1,39 +1,39 @@
#region License and copyright notice
/*
* Kaliko Content Management System
*
* Copyright (c) Fredrik Schultz
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
* http://www.gnu.org/licenses/lgpl-3.0.html
*/
#endregion

namespace KalikoCMS.Attributes {
using System;

[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public sealed class PropertyTypeAttribute : Attribute {

public PropertyTypeAttribute(string propertyTypeId, string name, string description, string editorControl) {
PropertyTypeId = propertyTypeId;
Name = name;
Description = description;
EditorControl = editorControl;
}

public string PropertyTypeId { get; private set; }
public string Name { get; private set; }
public string Description { get; private set; }
public string EditorControl { get; private set; }

}
}
#region License and copyright notice
/*
* Kaliko Content Management System
*
* Copyright (c) Fredrik Schultz
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
* http://www.gnu.org/licenses/lgpl-3.0.html
*/
#endregion

namespace KalikoCMS.Attributes {
using System;

[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public sealed class PropertyTypeAttribute : Attribute {

public PropertyTypeAttribute(string propertyTypeId, string name, string description, string editorControl) {
PropertyTypeId = propertyTypeId;
Name = name;
Description = description;
EditorControl = editorControl;
}

public string PropertyTypeId { get; private set; }
public string Name { get; private set; }
public string Description { get; private set; }
public string EditorControl { get; private set; }

}
}
@@ -1,62 +1,62 @@
#region License and copyright notice
/*
* Kaliko Content Management System
*
* Copyright (c) Fredrik Schultz
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
* http://www.gnu.org/licenses/lgpl-3.0.html
*/
#endregion

namespace KalikoCMS.Caching {
using System;
using Configuration;

public static class CacheManager {
private static readonly ICacheProvider CacheProvider = GetCacheProviderTypeFromConfig();

public static void Add<T>(string key, T value, CachePriority priority = CachePriority.Medium, int timeout = 30, bool slidingExpiration = true, bool addRefreshDependency = false) {
CacheProvider.Add(key, value, priority, timeout, slidingExpiration, addRefreshDependency);
}

public static bool Exists(string key) {
return CacheProvider.Exists(key);
}

public static T Get<T>(string key) {
return CacheProvider.Get<T>(key);
}

public static void Remove(string key) {
CacheProvider.Remove(key);
}

public static void RemoveRelated(Guid pageId) {
CacheProvider.RemoveRelated(pageId);
}

private static ICacheProvider GetCacheProviderTypeFromConfig() {
var cacheProvider = SiteSettings.Instance.CacheProvider;

if (string.IsNullOrEmpty(cacheProvider)) {
return new WebCache();
}

var cacheProviderType = Type.GetType(cacheProvider);
if (cacheProviderType == null) {
throw new NullReferenceException("Type.GetType(" + cacheProvider + ") returned null.");
}

return (ICacheProvider)Activator.CreateInstance(cacheProviderType);
}
}
}
#region License and copyright notice
/*
* Kaliko Content Management System
*
* Copyright (c) Fredrik Schultz
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
* http://www.gnu.org/licenses/lgpl-3.0.html
*/
#endregion

namespace KalikoCMS.Caching {
using System;
using Configuration;

public static class CacheManager {
private static readonly ICacheProvider CacheProvider = GetCacheProviderTypeFromConfig();

public static void Add<T>(string key, T value, CachePriority priority = CachePriority.Medium, int timeout = 30, bool slidingExpiration = true, bool addRefreshDependency = false) {
CacheProvider.Add(key, value, priority, timeout, slidingExpiration, addRefreshDependency);
}

public static bool Exists(string key) {
return CacheProvider.Exists(key);
}

public static T Get<T>(string key) {
return CacheProvider.Get<T>(key);
}

public static void Remove(string key) {
CacheProvider.Remove(key);
}

public static void RemoveRelated(Guid pageId) {
CacheProvider.RemoveRelated(pageId);
}

private static ICacheProvider GetCacheProviderTypeFromConfig() {
var cacheProvider = SiteSettings.Instance.CacheProvider;

if (string.IsNullOrEmpty(cacheProvider)) {
return new WebCache();
}

var cacheProviderType = Type.GetType(cacheProvider);
if (cacheProviderType == null) {
throw new NullReferenceException("Type.GetType(" + cacheProvider + ") returned null.");
}

return (ICacheProvider)Activator.CreateInstance(cacheProviderType);
}
}
}