public List <UsedByRelation> Relation(ApiCall call) { var sitedb = call.WebSite.SiteDb(); string type = call.GetValue("type", "by"); if (string.IsNullOrEmpty(type)) { return(null); } byte consttype = ConstObjectType.GetByte(type); if (call.ObjectId != default(Guid)) { return(sitedb.Styles.GetUsedBy(call.ObjectId) .Where(it => it.ConstType == consttype) .Select(it => { it.Url = sitedb.WebSite.BaseUrl(it.Url); return it; }).ToList()); } return(null); }
public PagedListViewModel <ExternalResourceItemViewModel> External(ApiCall call) { var sitedb = call.WebSite.SiteDb(); var pager = ApiHelper.GetPager(call, 50); PagedListViewModel <ExternalResourceItemViewModel> result = new PagedListViewModel <ExternalResourceItemViewModel>(); var alllinks = sitedb.ExternalResource.All(); var total = alllinks.Count; result.TotalCount = total; result.TotalPages = ApiHelper.GetPageCount(total, pager.PageSize); result.PageNr = pager.PageNr; List <ExternalResourceItemViewModel> list = new List <ExternalResourceItemViewModel>(); var items = alllinks.OrderBy(o => o.Name).Skip(pager.SkipCount).Take(pager.PageSize); foreach (var item in items) { ExternalResourceItemViewModel model = new ExternalResourceItemViewModel(); model.Id = item.Id; model.FullUrl = item.FullUrl; model.ResourceType = ConstObjectType.GetName(item.DestinationObjectType); model.LastModified = item.LastModified; model.Relations = Sites.Helper.RelationHelper.Sum(sitedb.ExternalResource.GetUsedBy(item.Id)); list.Add(model); } result.List = list; return(result); }
private List <UsedByRelation> PageRelation(SiteDb sitedb, string by, Guid PageId) { string baseurl = sitedb.WebSite.BaseUrl(); byte consttype = ConstObjectType.GetByte(by); List <UsedByRelation> result = new List <UsedByRelation>(); var relations = sitedb.Relations.GetRelations(PageId, consttype); foreach (var item in relations) { var objectinfo = ObjectService.GetObjectInfo(sitedb, item.objectYId, item.ConstTypeY); if (objectinfo != null) { UsedByRelation relation = new UsedByRelation(); relation.Name = objectinfo.DisplayName; relation.Url = objectinfo.Url; if (!string.IsNullOrEmpty(relation.Url)) { relation.Url = Lib.Helper.UrlHelper.Combine(baseurl, relation.Url); } relation.ModelType = objectinfo.ModelType; relation.ObjectId = objectinfo.ObjectId; relation.ConstType = objectinfo.ConstType; result.Add(relation); } } return(result); }
public string RenderSystemLink(RenderContext context, Routing.Route route) { Render.FrontContext frontContext = context.GetItem <Render.FrontContext>(); route.Parameters = ObjectRoute.ParseParameters(route, this.Url); var constTypeString = route.Parameters.GetValue("objecttype"); byte constType = ConstObjectType.Unknown; if (!byte.TryParse(constTypeString, out constType)) { constType = ConstObjectType.GetByte(constTypeString); } var id = route.Parameters.GetValue("nameorid"); if (constType == ConstObjectType.View) { var view = context.WebSite.SiteDb().Views.GetByNameOrId(id); if (view != null) { var relation = context.WebSite.SiteDb().Relations.GetReferredBy(view, ConstObjectType.Page); if (relation != null && relation.Count > 0) { var pageid = relation[0].objectXId; var pageroute = context.WebSite.SiteDb().Routes.GetByObjectId(pageid); if (pageroute != null) { return(RenderPageRoute(context, pageroute)); } } /// if view was not rendered within and by the page... try to render with rendercode. if (frontContext.Page != null && frontContext.ExecutingView != null) { string currenturl = context.Request.RelativeUrl; var values = PageRoute.GetViewParameterValues(context.WebSite.SiteDb(), view, frontContext); var alternativeviewcode = Cache.ViewInSamePosition.GetAlternativeCode(frontContext.ExecutingView.Id, view.Id); values.Add(SiteConstants.AlternativeViewQueryName, alternativeviewcode.ToString()); return(Kooboo.Lib.Helper.UrlHelper.AppendQueryString(currenturl, values)); } else if (frontContext.Page == null) { var values = PageRoute.GetViewParameterValues(context.WebSite.SiteDb(), view, frontContext); return(Kooboo.Lib.Helper.UrlHelper.AppendQueryString(this.Url, values)); } } } return(null); }
private PagedListViewModel <MediaFileViewModel> GetPagedFilesBy(SiteDb siteDb, string by, int PageSize, int PageNumber) { string baseurl = siteDb.WebSite.BaseUrl(); // by = View, Page, Layout, TextContent, Style. byte consttype = ConstObjectType.GetByte(by); var images = siteDb.Images.ListUsedBy(consttype); int totalskip = 0; if (PageNumber > 1) { totalskip = (PageNumber - 1) * PageSize; } PagedListViewModel <MediaFileViewModel> Result = new PagedListViewModel <MediaFileViewModel>(); Result.TotalCount = images.Count(); Result.TotalPages = ApiHelper.GetPageCount(Result.TotalCount, PageSize); Result.PageSize = PageSize; Result.PageNr = PageNumber; List <MediaFileViewModel> list = new List <MediaFileViewModel>(); foreach (var item in images.Skip(totalskip).Take(PageSize)) { MediaFileViewModel model = new MediaFileViewModel(); model.Id = item.Id; model.Height = item.Height; model.Width = item.Width; model.Size = item.Size; model.Name = item.Name; model.LastModified = item.LastModified; model.Thumbnail = ThumbnailService.GenerateThumbnailUrl(item.Id, 90, 0, siteDb.Id); model.Url = ObjectService.GetObjectRelativeUrl(siteDb, item); model.IsImage = true; model.PreviewUrl = Lib.Helper.UrlHelper.Combine(baseurl, model.Url); var usedby = siteDb.Images.GetUsedBy(item.Id); if (usedby != null) { model.References = usedby.GroupBy(it => it.ConstType).ToDictionary( key => { return(ConstTypeService.GetModelType(key.Key).Name); }, value => value.Count()); } list.Add(model); } Result.List = list; return(Result); }
public static void Render(FrontContext context) { //systemroute.Name = "__kb/{objecttype}/{nameorid}"; defined in Routes. var paras = context.Route.Parameters; var constTypeString = paras.GetValue("objecttype"); byte constType = ConstObjectType.Unknown; if (!byte.TryParse(constTypeString, out constType)) { constType = ConstObjectType.GetByte(constTypeString); } var id = paras.GetValue("nameorid"); switch (constType) { case ConstObjectType.ResourceGroup: ResourceGroupRender(context, id); return; case ConstObjectType.View: ViewRender(context, id, paras); return; case ConstObjectType.Image: { ImageRender(context, id, paras); return; } case ConstObjectType.File: { FileRender(context, id, paras); return; } case ConstObjectType.kfile: { KFileRender(context, paras); return; } //case ConstObjectType.TextContent: // { // TextContentRender(context, id, paras); // return; // } default: DefaultRender(context, constType, id, paras); break; } }
public override List <object> List(ApiCall call) { List <ExternalResourceItemViewModel> result = new List <ExternalResourceItemViewModel>(); var sitedb = call.WebSite.SiteDb(); foreach (var item in sitedb.ExternalResource.All()) { ExternalResourceItemViewModel model = new ExternalResourceItemViewModel(); model.Id = item.Id; model.FullUrl = item.FullUrl; model.ResourceType = ConstObjectType.GetName(item.DestinationObjectType); model.LastModified = item.LastModified; model.Relations = Sites.Helper.RelationHelper.Sum(sitedb.ExternalResource.GetUsedBy(item.Id)); result.Add(model); } return(result.ToList <object>()); }
public List <UsedByRelation> ShowBy(ApiCall call) { var sitedb = call.WebSite.SiteDb(); string type = call.GetValue("type"); string by = call.GetValue("by"); if (string.IsNullOrEmpty(type) || string.IsNullOrEmpty(by)) { return(null); } if (type.ToLower() == "page") { return(PageRelation(sitedb, by, call.ObjectId)); } var repo = sitedb.GetRepository(type); var siteobject = repo?.Get(call.ObjectId); if (repo == null || siteobject == null) { return(null); } string baseurl = call.WebSite.BaseUrl(); byte consttype = ConstObjectType.GetByte(by); List <UsedByRelation> result = new List <UsedByRelation>(); var usedby = repo.GetUsedBy(call.ObjectId).Where(o => o.ConstType == consttype).ToList(); foreach (var item in usedby) { item.Url = sitedb.WebSite.BaseUrl(item.Url); } return(usedby); }
private List <MediaFileViewModel> GetFilesBy(SiteDb siteDb, string by) { string baseurl = siteDb.WebSite.BaseUrl(); // by = View, Page, Layout, TextContent, Style. byte consttype = ConstObjectType.GetByte(by); var images = siteDb.Images.ListUsedBy(consttype); List <MediaFileViewModel> Result = new List <MediaFileViewModel>(); foreach (var item in images) { MediaFileViewModel model = new MediaFileViewModel(); model.Id = item.Id; model.Height = item.Height; model.Width = item.Width; model.Size = item.Size; model.Name = item.Name; model.LastModified = item.LastModified; model.Thumbnail = ThumbnailService.GenerateThumbnailUrl(item.Id, 90, 0, siteDb.Id); model.Url = ObjectService.GetObjectRelativeUrl(siteDb, item); model.IsImage = true; model.PreviewUrl = Lib.Helper.UrlHelper.Combine(baseurl, model.Url); var usedby = siteDb.Images.GetUsedBy(item.Id); if (usedby != null) { model.References = usedby.GroupBy(it => it.ConstType).ToDictionary( key => { return(ConstTypeService.GetModelType(key.Key).Name); }, value => value.Count()); } Result.Add(model); } return(Result); }
public PagedListViewModel <RouteItemViewModel> Internal(ApiCall apiCall) { var sitedb = apiCall.WebSite.SiteDb(); var pager = ApiHelper.GetPager(apiCall, 30); PagedListViewModel <RouteItemViewModel> result = new PagedListViewModel <RouteItemViewModel>(); var allroutes = sitedb.Routes.All(); var total = allroutes.Count; result.TotalCount = total; result.TotalPages = ApiHelper.GetPageCount(total, pager.PageSize); result.PageNr = pager.PageNr; List <RouteItemViewModel> list = new List <RouteItemViewModel>(); string baseurl = sitedb.WebSite.BaseUrl(); var items = allroutes.OrderBy(o => o.Name).Skip(pager.SkipCount).Take(pager.PageSize); foreach (var item in items) { RouteItemViewModel model = new RouteItemViewModel(); model.Id = item.Id; model.Name = item.Name; model.ResourceType = ConstObjectType.GetName(item.DestinationConstType); model.ObjectId = item.objectId; model.LastModified = item.LastModified; model.Relations = Sites.Helper.RelationHelper.Sum(sitedb.Routes.GetUsedBy(item.Id)); model.PreviewUrl = Kooboo.Lib.Helper.UrlHelper.Combine(baseurl, model.Name); list.Add(model); } result.List = list; return(result); }
public List <UsedByRelation> ShowRelation(ApiCall call) { var viewdatamethod = call.WebSite.SiteDb().ViewDataMethods.Query.Where(o => o.MethodId == call.ObjectId).SelectAll(); string by = call.GetValue("by"); if (string.IsNullOrEmpty(by)) { return(null); } byte consttype = ConstObjectType.GetByte(by); var usedby = call.WebSite.SiteDb().Images.GetUsedBy(call.ObjectId).Where(o => o.ConstType == consttype).ToList(); foreach (var item in usedby) { item.Url = call.WebSite.SiteDb().WebSite.BaseUrl(item.Url); } return(usedby); }
public object Relation(ApiCall call) { string type = call.GetValue("type", "by"); if (string.IsNullOrEmpty(type)) { return(null); } byte consttype = ConstObjectType.GetByte(type); if (call.ObjectId != default(Guid)) { return(call.WebSite.SiteDb().Scripts.GetUsedBy(call.ObjectId) .Where(it => it.ConstType == consttype) .Select(it => { it.Url = call.WebSite.BaseUrl(it.Url); return it; })); } return(null); }
protected void RaiseBeforeEvent(TValue value, ChangeType changetype, TValue oldValue = default(TValue)) { if (this.SiteObjectType == typeof(Page)) { var maxpages = Kooboo.Data.Authorization.QuotaControl.MaxPages(this.SiteDb.WebSite.OrganizationId); if (maxpages != int.MaxValue) { var count = this.SiteDb.Pages.Count(); if (count >= maxpages) { throw new Exception(Kooboo.Data.Language.Hardcoded.GetValue("Max number of pages per site has been reached, service level upgrade required")); } } } if (this.SiteDb.WebSite.EnableConstraintFixOnSave && changetype != ChangeType.Delete) { Constraints.ConstraintChecker.FixOnSave(this.SiteDb, value as SiteObject); } // for kscript parameters. if (value is IScriptable) { var kscriptobject = value as IScriptable; var domobjct = value as IDomObject; if (kscriptobject != null && domobjct != null) { kscriptobject.RequestParas = Kooboo.Sites.Scripting.ScriptHelper.GetkScriptParaFromDom(this.SiteDb, domobjct.Dom); } } if (value is Kooboo.Sites.Models.Code) { var code = value as Kooboo.Sites.Models.Code; if (code.CodeType == Sites.Models.CodeType.PageScript) { code.Parameters = Kooboo.Sites.Scripting.ScriptHelper.GetKScriptParameters(code.Body); } } if (value is Kooboo.Sites.Models.CoreObject && changetype != ChangeType.Delete) { if (value is Kooboo.Sites.Routing.Route) { return; } var size = Kooboo.Sites.Service.ObjectService.GetSize(value); if (!Kooboo.Data.Infrastructure.InfraManager.Test(this.WebSite.OrganizationId, Data.Infrastructure.InfraType.Disk, size)) { var message = Data.Language.Hardcoded.GetValue("Over Disk Quota"); throw new Exception(message); } else { string msg = ConstObjectType.GetName(value.ConstType); var objinfo = Kooboo.Sites.Service.ObjectService.GetObjectInfo(this.SiteDb, value); if (objinfo != null) { msg += "| " + objinfo.DisplayName; } else { msg += "| " + value.Name; } Kooboo.Data.Infrastructure.InfraManager.Add(this.WebSite.OrganizationId, Data.Infrastructure.InfraType.Disk, size, msg); } } }