/// <summary>
        /// The script file url o fsite
        /// </summary>
        /// <param name="frontUrlHelper">The front url helper</param>
        /// <param name="site">The site</param>
        /// <param name="baseUri">Base uri</param>
        /// <param name="relativeScriptFilePath">The relative script file path of site</param>
        /// <returns></returns>
        public static IHtmlString ScriptFileUrl(this FrontUrlHelper frontUrlHelper, Site site, string baseUri, string relativeScriptFilePath, bool forceSSL = false)
        {
            string resourceDomain = site.ResourceDomain.FormatUrlWithProtocol(forceSSL);

            bool scriptFileExists = false;
            string scriptFileUrl = String.Empty;
            string scriptFilePhysicalPath = String.Empty;

            do
            {
                site = site.AsActual();

                ScriptFile scriptFile = new ScriptFile(site, String.Empty);
                if (scriptFile != null)
                {
                    scriptFileUrl = UrlUtility.Combine(scriptFile.VirtualPath, relativeScriptFilePath);

                    scriptFilePhysicalPath = HttpContext.Current.Server.MapPath(scriptFileUrl);
                    scriptFileExists = File.Exists(scriptFilePhysicalPath);
                }

                site = site.Parent;
            } while (site != null && !scriptFileExists);

            if (!String.IsNullOrEmpty(resourceDomain))
            {
                baseUri = resourceDomain; // CDN have high priority
            }
            return new HtmlString(UrlUtility.ToHttpAbsolute(baseUri, scriptFileUrl));
        }
示例#2
0
 public static Repository GetRepository(this Site site)
 {
     site = site.AsActual();
     if (!string.IsNullOrEmpty(site.Repository))
     {
         return(new Repository(site.Repository));
     }
     return(null);
 }
示例#3
0
        public static Kooboo.CMS.Membership.Models.Membership GetMembership(this Site site)
        {
            site = site.AsActual();

            if (site != null && !string.IsNullOrEmpty(site.Membership))
            {
                return(new Kooboo.CMS.Membership.Models.Membership(site.Membership).AsActual());
            }
            return(null);
        }
示例#4
0
 public static string Decrypt(Site site, string cryptedString)
 {
     if (String.IsNullOrEmpty(cryptedString))
     {
         return cryptedString;
     }
     var key = GetKey(site.AsActual());
     DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
     MemoryStream memoryStream = new MemoryStream
             (Convert.FromBase64String(cryptedString));
     CryptoStream cryptoStream = new CryptoStream(memoryStream,
         cryptoProvider.CreateDecryptor(key, key), CryptoStreamMode.Read);
     StreamReader reader = new StreamReader(cryptoStream);
     return reader.ReadToEnd();
 }
示例#5
0
        public void OnExcluded(Site site)
        {
            var repository = site.AsActual().GetRepository();
            if (repository != null)
            {
                TextFolder productFolder = new TextFolder(repository, "Product");
                if (productFolder.AsActual() != null)
                {
                    _textFolderManager.Remove(repository, productFolder);
                }
                Schema productSchema = new Schema(repository, "Product");
                if (productSchema.AsActual() != null)
                {
                    _schemaManager.Remove(repository, productSchema);
                }

            }
        }
示例#6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FrontRequestContext"/> class.
        /// </summary>
        /// <param name="site">The site.</param>
        /// <param name="page">The page.</param>
        /// <param name="requestChannel">The request channel.</param>
        /// <param name="httpContext">The HTTP context.</param>
        /// <param name="pageRequestUrl">The page request url with out page virtual path.</param>
        public PageRequestContext(ControllerContext controllerContext, Site site, Page page, FrontRequestChannel requestChannel, string pageRequestUrl)
        {
            RouteValues = new RouteValueDictionary();

            this.ControllerContext = controllerContext;

            var httpContext = HttpContext.Current;

            this.Site = site.AsActual();
            this.Page = page.AsActual();
            this.RequestChannel = requestChannel;

            this.AllQueryString = new NameValueCollection(httpContext.Request.QueryString);

            HttpContextBase pageContext = new PageHttpContenxt(httpContext, new PageHttpRequest(httpContext.Request, "~/" + pageRequestUrl, ""));
            var routeData = page.Route.ToMvcRoute().GetRouteData(pageContext);

            if (routeData != null)
            {
                RouteValues = routeData.Values;
                //Combine page parameters to [QueryString].
                foreach (var item in RouteValues)
                {
                    if (item.Value != null)
                    {
                        AllQueryString[item.Key] = item.Value.ToString();
                    }
                }
            }

            var moduleUrl = AllQueryString[ModuleUrlSegment];
            ModuleUrlContext = new ModuleUrlContext(this, moduleUrl);
        }
示例#7
0
        public static IHtmlString WrapperUrl(string url, Site site, FrontRequestChannel channel, bool? requireSSL)
        {
            if (string.IsNullOrEmpty(url))
            {
                return new HtmlString(url);
            }
            var applicationPath = HttpContext.Current.Request.ApplicationPath.TrimStart(new char[] { '/' });
            if (!url.StartsWith("/") && !string.IsNullOrEmpty(applicationPath))
            {
                url = "/" + applicationPath + "/" + url;
            }

            var sitePath = site.AsActual().SitePath;
            if (channel == FrontRequestChannel.Debug || channel == FrontRequestChannel.Design || channel == FrontRequestChannel.Unknown)
            {
                sitePath = SiteHelper.PREFIX_FRONT_DEBUG_URL + site.FullName;
            }
            var urlSplit = url.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
            IEnumerable<string> urlPaths = urlSplit;
            if (!string.IsNullOrEmpty(sitePath))
            {
                if (urlSplit.Length > 0 && applicationPath.EqualsOrNullEmpty(urlSplit[0], StringComparison.OrdinalIgnoreCase))
                {
                    urlPaths = new string[] { applicationPath, sitePath }.Concat(urlSplit.Skip(1));
                }
                else
                {
                    urlPaths = new string[] { sitePath }.Concat(urlSplit);
                }
            }
            var endWithSlash = url.EndsWith("/");
            url = "/" + string.Join("/", urlPaths.ToArray());
            if (endWithSlash && !url.EndsWith("/"))
            {
                url = url + "/";
            }

            #region SSL
            if (requireSSL.HasValue)
            {
                if (channel == FrontRequestChannel.Host || channel == FrontRequestChannel.HostNPath)
                {
                    if (HttpContext.Current.Request.IsSecureConnection)
                    {
                        //if (!requireSSL.Value)
                        //{
                        //    url = "http://" + HttpContext.Current.Request.Url.Host + url;
                        //}
                    }
                    else if (requireSSL.Value)
                    {
                        url = "https://" + HttpContext.Current.Request.Url.Host + url;
                    }
                }
            }

            #endregion

            return new HtmlString(url);
        }
示例#8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PageRequestContext" /> class.
        /// </summary>
        /// <param name="controllerContext">The controller context.</param>
        /// <param name="rawSite">The raw.</param>
        /// <param name="site">The site.</param>
        /// <param name="page">The page.</param>
        /// <param name="requestChannel">The request channel.</param>
        /// <param name="pageRequestUrl">The page request url with out page virtual path.</param>
        public PageRequestContext(ControllerContext controllerContext, Site rawSite, Site site, Page rawPage, Page page, FrontRequestChannel requestChannel, string pageRequestUrl)
        {
            RouteValues = new RouteValueDictionary();

            this.ControllerContext = controllerContext;

            var httpContext = HttpContext.Current;

            this.RawSite = rawSite;
            this.RawPage = rawPage;
            this.Site = site.AsActual();
            this.Page = page.AsActual();
            this.RequestChannel = requestChannel;

            this.AllQueryString = new NameValueCollection();
            var queryString = httpContext.Request.QueryString;
            foreach (var key in queryString.AllKeys)
            {
                var value = queryString[key];
                if (!string.IsNullOrEmpty(value))
                {
                    AllQueryString[HttpUtility.HtmlEncode(key)] = HttpUtility.HtmlEncode(value);
                }
                else
                {
                    AllQueryString[HttpUtility.HtmlEncode(key)] = value;
                }

            }

            HttpContextBase pageContext = new PageHttpContenxt(httpContext, new PageHttpRequest(httpContext.Request, "~/" + pageRequestUrl, ""));
            var routeData = page.Route.ToMvcRoute().GetRouteData(pageContext);

            if (routeData != null)
            {
                RouteValues = routeData.Values;
                //Combine page parameters to [QueryString].
                foreach (var item in RouteValues)
                {
                    if (item.Value != null)
                    {
                        AllQueryString[item.Key] = item.Value.ToString();
                    }
                }
            }

            var moduleUrl = AllQueryString[ModuleUrlContext.ModuleUrlSegment];
            ModuleUrlContext = new ModuleUrlContext(this, moduleUrl);
        }
        /// <summary>
        /// The theme file url of site
        /// </summary>
        /// <param name="frontUrlHelper">The front url helper</param>
        /// <param name="site">The site</param>
        /// <param name="baseUri">Base uri</param>
        /// <param name="relativeThemeFilePath">The relative theme file path of site</param>
        /// <returns></returns>
        public static IHtmlString ThemeFileUrl(this FrontUrlHelper frontUrlHelper, Site site, string baseUri, string relativeThemeFilePath)
        {
            string resourceDomain = site.ResourceDomain;

            bool themeFileExists = false;
            string themeFileUrl = String.Empty;
            string themeFilePhysicalPath = String.Empty;

            do
            {
                site = site.AsActual();

                Theme theme = new Theme(site, site.Theme).LastVersion();
                themeFileUrl = UrlUtility.Combine(theme.VirtualPath, relativeThemeFilePath);
                themeFilePhysicalPath = HttpContext.Current.Server.MapPath(themeFileUrl);
                themeFileExists = File.Exists(themeFilePhysicalPath);

                site = theme.Site.Parent;
            } while (site != null && !themeFileExists);

            if (!String.IsNullOrEmpty(resourceDomain))
            {
                baseUri = resourceDomain; // CDN have high priority
            }
            return new HtmlString(UrlUtility.ToHttpAbsolute(baseUri, themeFileUrl));
        }
示例#10
0
        protected virtual void FlushWebResourceCache(Site site, PathResource resource)
        {
            site = site.AsActual();
            var ticks = DateTime.UtcNow.ToString("yyyyMMddHHmmss");
            var versions = (string.IsNullOrEmpty(site.Version) ? "1.0.0.0" : site.Version).Split('.');
            versions[versions.Length - 1] = ticks;

            site.Version = string.Join(".", versions);

            ServiceFactory.SiteManager.Update(site);
        }
示例#11
0
        public static IHtmlString WrapperUrl(string url, Site site, FrontRequestChannel channel)
        {
            if (string.IsNullOrEmpty(url))
            {
                return new HtmlString(url);
            }
            var applicationPath = HttpContext.Current.Request.ApplicationPath.TrimStart(new char[] { '/' });
            if (!url.StartsWith("/") && !string.IsNullOrEmpty(applicationPath))
            {
                url = "/" + applicationPath + "/" + url;
            }
            var urlSplit = url.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);

            var sitePath = site.AsActual().SitePath;
            if(channel == FrontRequestChannel.Debug || channel == FrontRequestChannel.Design || channel == FrontRequestChannel.Unknown)
            {
                sitePath = SiteHelper.PREFIX_FRONT_DEBUG_URL + site.FullName;
            }
            IEnumerable<string> urlPaths = urlSplit;
            if (!string.IsNullOrEmpty(sitePath))
            {
                if (urlSplit.Length > 0 && applicationPath.EqualsOrNullEmpty(urlSplit[0], StringComparison.OrdinalIgnoreCase))
                {
                    urlPaths = new string[] { applicationPath, sitePath }.Concat(urlSplit.Skip(1));
                }
                else
                {
                    urlPaths = new string[] { sitePath }.Concat(urlSplit);
                }
            }

            url = "/" + string.Join("/", urlPaths.ToArray());
            return new HtmlString(url);
        }
示例#12
0
        public void OnIncluded(Site site)
        {
            var repository = site.AsActual().GetRepository();
            if (repository != null)
            {
                //import the content types. the zip file contains "Category" content type.
                //var contentTypePath = new ModulePathHelper(ModuleAreaRegistration.ModuleName).GetModuleInstallationFilePath("ContentType.zip");
                //if (File.Exists(contentTypePath.PhysicalPath))
                //{
                //    using (FileStream fs = new FileStream(contentTypePath.PhysicalPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                //    {
                //        _schemaManager.Import(repository, fs, true);
                //    }
                //}
                Schema productSchema = new Schema(repository, "Product");
                productSchema.AddColumn("ProductName", "TextBox", DataType.String, "", true, true);
                productSchema.AddColumn("ProductDetail", "Tinymce", DataType.String, "", false, true);
                if (productSchema.AsActual() == null)
                {
                    _schemaManager.Add(repository, productSchema);
                }

                TextFolder productFolder = new TextFolder(repository, "Product")
                {
                    SchemaName = "Product"
                };
                if (productFolder.AsActual() == null)
                {
                    _textFolderManager.Add(repository, productFolder);
                }
            }
        }