Example #1
0
        public static ISiteObject GetSiteObject(SiteDb SiteDb, Guid ObjectId, byte ConstType, bool UseColumnOnly = false)
        {
            var type = ConstTypeService.GetModelType(ConstType);

            var repo = SiteDb.GetRepository(type);

            if (repo == null || ObjectId == default(Guid))
            {
                return(null);
            }

            var siteobject = repo.Get(ObjectId);

            if (siteobject != null)
            {
                return(siteobject as ISiteObject);
            }

            else
            {
                var item = repo.GetLastEntryFromLog(ObjectId);
                if (item != null)
                {
                    return(item as ISiteObject);
                }
            }

            return(null);
        }
Example #2
0
        public static string GetObjectRelativeUrl(SiteDb SiteDb, SiteObject SiteObject)
        {
            if (SiteObject == null)
            {
                return(null);
            }

            if (SiteObject is IEmbeddable)
            {
                var embedded = SiteObject as IEmbeddable;
                if (embedded.IsEmbedded)
                {
                    var modeltype    = ConstTypeService.GetModelType(embedded.OwnerConstType);
                    var repo         = SiteDb.GetRepository(modeltype);
                    var parentobject = repo.Get(embedded.OwnerObjectId) as SiteObject;
                    return(GetObjectRelativeUrl(SiteDb, parentobject));
                }
            }

            if (SiteObject is CmsCssRule)
            {
                var rule  = SiteObject as CmsCssRule;
                var style = SiteDb.Styles.Get(rule.ParentStyleId);
                return(GetObjectRelativeUrl(SiteDb, style));
            }

            if (SiteObject is CmsCssDeclaration)
            {
                var decl  = SiteObject as CmsCssDeclaration;
                var style = SiteDb.Styles.Get(decl.ParentStyleId);
                return(GetObjectRelativeUrl(SiteDb, style));
            }

            if (Kooboo.Sites.Service.ObjectService.IsRoutable(SiteObject, false))
            {
                return(SiteDb.Routes.GetObjectPrimaryRelativeUrl(SiteObject.Id));
            }

            string name = SiteObject.Id.ToString();

            if (Attributes.AttributeHelper.IsNameAsId(SiteObject))
            {
                name = SiteObject.Name;
            }

            var modeltypex = ConstTypeService.GetModelType(SiteObject.ConstType);

            return(Systems.Routes.SystemRouteTemplate.Replace("{objecttype}", modeltypex.Name).Replace("{nameorid}", name));
        }
Example #3
0
        public static ObjectInfo GetObjectInfo(SiteDb SiteDb, ISiteObject siteobject)
        {
            if (siteobject == null)
            {
                return(null);
            }
            ObjectInfo info = new ObjectInfo();

            info.ObjectId  = siteobject.Id;
            info.ConstType = siteobject.ConstType;

            if (info.ConstType > 0)
            {
                info.ModelType = ConstTypeService.GetModelType(siteobject.ConstType);
            }

            if (info.ModelType == null)
            {
                info.ModelType = siteobject.GetType();
            }

            if (siteobject is IBinaryFile)
            {
                info.Size = ((IBinaryFile)siteobject).Size;
            }
            else if (siteobject is ITextObject)
            {
                info.Size = (((ITextObject)siteobject).Body ?? "").Length;
            }


            if (Kooboo.Lib.Reflection.TypeHelper.HasInterface(info.ModelType, typeof(IEmbeddable)))
            {
                var embeddable = siteobject as IEmbeddable;
                if (embeddable.IsEmbedded)
                {
                    return(GetObjectInfo(SiteDb, embeddable.OwnerObjectId, embeddable.OwnerConstType));
                }
            }

            if (Kooboo.Sites.Service.ObjectService.IsRoutable(siteobject, false))
            {
                info.Url         = GetObjectRelativeUrl(SiteDb, siteobject as SiteObject);
                info.DisplayName = info.Url;
                info.Name        = siteobject.Name;
                return(info);
            }
            else
            {
                if (info.ModelType == typeof(CmsCssRule))
                {
                    var rule = siteobject as CmsCssRule;
                    if (rule == null)
                    {
                        return(null);
                    }
                    if (rule.IsInline)
                    {
                        return(GetObjectInfo(SiteDb, rule.OwnerObjectId, rule.OwnerObjectConstType));
                    }
                    else
                    {
                        return(GetObjectInfo(SiteDb, rule.ParentStyleId, ConstObjectType.Style));
                    }
                }

                info.Url         = "/__kb/" + info.ModelType.Name + "/" + info.ObjectId.ToString();
                info.DisplayName = siteobject.Name;
                info.Name        = siteobject.Name;

                if (info.ModelType == typeof(TextContent))
                {
                    info.Name        = Kooboo.Sites.Helper.ContentHelper.GetSummary(siteobject as TextContent, SiteDb.WebSite.DefaultCulture);
                    info.DisplayName = info.Name;
                }

                if (info.ModelType == typeof(DataMethodSetting))
                {
                    var datamethod = siteobject as DataMethodSetting;
                    if (datamethod != null)
                    {
                        info.Name        = datamethod.OriginalMethodName;
                        info.DisplayName = datamethod.OriginalMethodName;
                    }
                }

                return(info);
            }
        }
Example #4
0
        public static string GetEditRoute(ISiteObject obj, SiteDb sitedb)
        {
            var modeltype = ConstTypeService.GetModelType(obj.ConstType);

            if (modeltype == typeof(Page))
            {
                // / _Admin / Page / EditPage ? SiteId = 9f4c626c - f49f - 3538 - 05c5 - 97bb3a206f01 & Id = 9207f022 - d11e - 480a - 8ddf - aacb5cb4b1b3
                /// _Admin / Page / EditRichText ? SiteId = 9f4c626c - f49f - 3538 - 05c5 - 97bb3a206f01 & Id = 5fbb992d - 423f - 4a26 - b27e - 067a743eabc6
                ///_Admin/Page/EditLayout?SiteId=9f4c626c-f49f-3538-05c5-97bb3a206f01&Id=685e3801-762d-44be-be1e-7f4d4237d47a&layoutId=7186a2e9-a55b-c58b-4964-fd9b73b82985
                var page = obj as Page;
                if (page.Type == PageType.Normal)
                {
                    return("/_Admin/Page/EditPage?SiteId=" + sitedb.Id.ToString() + "&Id=" + page.Id.ToString());
                }
                else if (page.Type == PageType.Layout)
                {
                    /// _Admin / Page / EditLayout ? SiteId = 9f4c626c - f49f - 3538 - 05c5 - 97bb3a206f01 & Id = 685e3801 - 762d - 44be - be1e - 7f4d4237d47a & layoutId = 7186a2e9 - a55b - c58b - 4964 - fd9b73b82985
                    var layout = new Layout();
                    layout.Name = page.LayoutName;

                    var url = "/_Admin/Page/EditLayout?SiteId=" + sitedb.Id.ToString();
                    url += "&Id=" + page.Id.ToString();
                    url += "&layoutId=" + layout.Id.ToString();
                    return(url);
                }
                else if (page.Type == PageType.RichText)
                {
                    /// _Admin / Page / EditRichText ? SiteId = 9f4c626c - f49f - 3538 - 05c5 - 97bb3a206f01 & Id = 5fbb992d - 423f - 4a26 - b27e - 067a743eabc6
                    ///
                    return("/_Admin/Page/EditRichText?SiteId=" + sitedb.Id.ToString() + "&Id=" + page.Id.ToString());
                }
                else
                {
                    return(null);
                }
            }
            else if (modeltype == typeof(View))
            {
                //_Admin/Development/View?SiteId=9f4c626c-f49f-3538-05c5-97bb3a206f01&Id=a16aa2f1-e4ff-f5a3-a49b-c719e1a58d11

                return("/_Admin/Development/View?SiteId=" + sitedb.Id.ToString() + "&Id=" + obj.Id.ToString());
            }
            else if (modeltype == typeof(Style))
            {
                //_Admin/Development/Style?SiteId=02182faa-207a-0a69-bfd3-677269d75360&Id=41be6f57-6d78-a959-38ba-17f628f5c726
                return("/_Admin/Development/Style?SiteId=" + sitedb.Id.ToString() + "&Id=" + obj.Id.ToString());
            }
            else if ((modeltype == typeof(Script)))
            {
                //_Admin/Development/Script?SiteId=02182faa-207a-0a69-bfd3-677269d75360&Id=c9dc9ec1-c29e-4ce5-b024-f18183c00502
                return("/_Admin/Development/Script?SiteId=" + sitedb.Id.ToString() + "&Id=" + obj.Id.ToString());
            }
            else if (modeltype == typeof(Code))
            {
                ///_Admin/Development/EditCode?SiteId=02182faa-207a-0a69-bfd3-677269d75360&id=d2e30679-aa6f-4901-bc0d-5b006057d9a3

                return("/_Admin/Development/EditCode?SiteId=" + sitedb.Id.ToString() + "&Id=" + obj.Id.ToString());
            }
            else if (modeltype == typeof(Layout))
            {
                ///_Admin/Development/Layout?SiteId=02182faa-207a-0a69-bfd3-677269d75360&Id=0da593e9-562e-9ad4-9ae4-7e88961ccd36
                return("/_Admin/Development/Layout?SiteId=" + sitedb.Id.ToString() + "&Id=" + obj.Id.ToString());
            }

            else
            {
                /// system route.
                //string SystemRouteTemplate = "/__kb/{objecttype}/{nameorid}";
                return("/__kb/" + modeltype.Name + "/" + obj.Id.ToString());
            }
        }