Example #1
0
        private static string GetScriptPath(JavaScriptLibrary js, Page page)
        {
            if (Host.CdnEnabled)
            {
                // load custom CDN path setting
                var customCdn = HostController.Instance.GetString("CustomCDN_" + js.LibraryName);
                if (!string.IsNullOrEmpty(customCdn))
                {
                    return(customCdn);
                }

                // cdn enabled but jsl does not have one defined
                if (!string.IsNullOrEmpty(js.CDNPath))
                {
                    var cdnPath = js.CDNPath;
                    if (cdnPath.StartsWith("//"))
                    {
                        cdnPath = $"{(UrlUtils.IsSecureConnectionOrSslOffload(page.Request) ? "https" : "http")}:{cdnPath}";
                    }

                    return(cdnPath);
                }
            }

            return("~/Resources/libraries/" + js.LibraryName + "/" + Globals.FormatVersion(js.Version, "00", 3, "_") + "/" + js.FileName);
        }
Example #2
0
        /// <summary>
        ///     returns the version of a javascript library from the database
        /// </summary>
        /// <param name="jsname">the library name</param>
        /// <returns></returns>
        public static string Version(String jsname)
        {
            JavaScriptLibrary library =
                JavaScriptLibraryController.Instance.GetLibrary(l => l.LibraryName == jsname);

            return(library != null?Convert.ToString(library.Version) : String.Empty);
        }
Example #3
0
        /// <summary>
        ///     returns the version of a javascript library from the database
        /// </summary>
        /// <param name="jsname">the library name</param>
        /// <returns></returns>
        public static string Version(String jsname)
        {
            //JavaScriptLibrary library = JavaScriptLibraryController.Instance.GetLibrary(l => l.LibraryName.Equals(jsname, StringComparison.OrdinalIgnoreCase));
            JavaScriptLibrary library = GetHighestVersionLibrary(jsname);

            return(library != null?Convert.ToString(library.Version) : String.Empty);
        }
Example #4
0
        /// <summary>
        ///     adds a request for a script into the page items collection
        /// </summary>
        /// <param name="jsname">the library name</param>
        public static void RequestRegistration(String jsname)
        {
            //handle case where script has no javascript library
            switch (jsname)
            {
            case CommonJs.DnnPlugins:
                RequestRegistration(CommonJs.jQueryUI);
                RequestRegistration(CommonJs.HoverIntent);
                AddPreInstallorLegacyItemRequest(jsname);
                return;

            case CommonJs.HoverIntent:
            case CommonJs.jQueryFileUpload:
                AddPreInstallorLegacyItemRequest(jsname);
                return;
            }

            JavaScriptLibrary library = GetHighestVersionLibrary(jsname);

            if (library != null)
            {
                AddItemRequest(library.JavaScriptLibraryID);
            }
            else
            {
                //covers case where upgrading to 7.2.0 and JSL's are not installed
                AddPreInstallorLegacyItemRequest(jsname);
            }
        }
Example #5
0
 private static string GetScriptPath(JavaScriptLibrary js)
 {
     if (Host.CdnEnabled)
     {
         //cdn enabled but jsl does not have one defined
         if (!String.IsNullOrEmpty(js.CDNPath))
         {
             return(js.CDNPath);
         }
     }
     return("~/Resources/libraries/" + js.LibraryName + "/" + js.Version + "/" + js.FileName);
 }
Example #6
0
 /// <summary>Save a library to the database</summary>
 /// <param name="library">Library to be saved</param>
 public void SaveLibrary(JavaScriptLibrary library)
 {
     library.JavaScriptLibraryID = DataProvider.Instance().ExecuteScalar <int>("SaveJavaScriptLibrary",
                                                                               library.JavaScriptLibraryID,
                                                                               library.PackageID,
                                                                               library.LibraryName,
                                                                               library.Version.ToString(3),
                                                                               library.FileName,
                                                                               library.ObjectName,
                                                                               library.PreferredScriptLocation,
                                                                               library.CDNPath);
     ClearCache();
 }
Example #7
0
        private static void RequestSpecificVersionLibraryRegistration(string jsname, Version version)
        {
            JavaScriptLibrary library = JavaScriptLibraryController.Instance.GetLibrary(l => l.LibraryName.Equals(jsname, StringComparison.OrdinalIgnoreCase) && l.Version == version);

            if (library != null)
            {
                AddItemRequest(library.JavaScriptLibraryID);
            }
            else
            {
                // this will only occur if a specific library is requested and not available
                LogCollision(string.Format("Missing Library request - {0} : {1}", jsname, version));
            }
        }
Example #8
0
        /// <summary>
        ///     adds a request for a script into the page items collection
        /// </summary>
        /// <param name="jsname">the library name</param>
        public static void RequestRegistration(String jsname, Version version)
        {
            JavaScriptLibrary library = JavaScriptLibraryController.Instance.GetLibrary(l => l.Version == version);

            if (library != null)
            {
                AddItemRequest(library.JavaScriptLibraryID);
            }
            else
            {
                //this will only occur if a specific library is requested and not available
                LogCollision(String.Format("Missing Library request - {0} : {1}", jsname, version));
            }
        }
Example #9
0
        private static void RegisterScript(Page page, JavaScriptLibrary jsl)
        {
            if (string.IsNullOrEmpty(jsl.FileName))
            {
                return;
            }

            ClientResourceManager.RegisterScript(page, GetScriptPath(jsl, page), GetFileOrder(jsl), GetScriptLocation(jsl), jsl.LibraryName, jsl.Version.ToString(3));

            // workaround to support IE specific script until we move to IE version that no longer requires this
            if (jsl.LibraryName == CommonJs.jQueryFileUpload)
            {
                ClientResourceManager.RegisterScript(
                    page,
                    "~/Resources/Shared/Scripts/jquery/jquery.iframe-transport.js");
            }

            if (Host.CdnEnabled && !string.IsNullOrEmpty(jsl.ObjectName))
            {
                string pagePortion;
                switch (jsl.PreferredScriptLocation)
                {
                case ScriptLocation.PageHead:

                    pagePortion = "ClientDependencyHeadJs";
                    break;

                case ScriptLocation.BodyBottom:
                    pagePortion = "ClientResourcesFormBottom";
                    break;

                case ScriptLocation.BodyTop:
                    pagePortion = "BodySCRIPTS";
                    break;

                default:
                    pagePortion = "BodySCRIPTS";
                    break;
                }

                Control scriptloader = page.FindControl(pagePortion);
                var     fallback     = new DnnJsIncludeFallback(jsl.ObjectName, VirtualPathUtility.ToAbsolute("~/Resources/libraries/" + jsl.LibraryName + "/" + Globals.FormatVersion(jsl.Version, "00", 3, "_") + "/" + jsl.FileName));
                if (scriptloader != null)
                {
                    // add the fallback control after script loader.
                    var index = scriptloader.Parent.Controls.IndexOf(scriptloader);
                    scriptloader.Parent.Controls.AddAt(index + 1, fallback);
                }
            }
        }
Example #10
0
        private static IEnumerable <JavaScriptLibrary> GetAllDependencies(JavaScriptLibrary library)
        {
            var package = PackageController.Instance.GetExtensionPackage(Null.NullInteger, p => p.PackageID == library.PackageID);

            foreach (var dependency in package.Dependencies)
            {
                var dependencyLibrary = GetHighestVersionLibrary(dependency.PackageName);
                yield return(dependencyLibrary);

                foreach (var childDependency in GetAllDependencies(dependencyLibrary))
                {
                    yield return(childDependency);
                }
            }
        }
Example #11
0
        private static string GetScriptLocation(JavaScriptLibrary js)
        {
            switch (js.PreferredScriptLocation)
            {
            case ScriptLocation.PageHead:
                return("DnnPageHeaderProvider");

            case ScriptLocation.BodyBottom:
                return("DnnFormBottomProvider");

            case ScriptLocation.BodyTop:
                return("DnnBodyProvider");
            }

            return(string.Empty);
        }
Example #12
0
        private static string GetScriptPath(JavaScriptLibrary js)
        {
            if (Host.CdnEnabled)
            {
                //load custom CDN path setting
                var customCdn = HostController.Instance.GetString("CustomCDN_" + js.LibraryName);
                if (!string.IsNullOrEmpty(customCdn))
                {
                    return(customCdn);
                }

                //cdn enabled but jsl does not have one defined
                if (!String.IsNullOrEmpty(js.CDNPath))
                {
                    return(js.CDNPath);
                }
            }
            return("~/Resources/libraries/" + js.LibraryName + "/" + Globals.FormatVersion(js.Version, "00", 3, "_") + "/" + js.FileName);
        }
Example #13
0
        private static int GetFileOrder(JavaScriptLibrary jsl)
        {
            switch (jsl.LibraryName)
            {
            case CommonJs.jQuery:
                return((int)FileOrder.Js.jQuery);

            case CommonJs.jQueryMigrate:
                return((int)FileOrder.Js.jQueryMigrate);

            case CommonJs.jQueryUI:
                return((int)FileOrder.Js.jQueryUI);

            case CommonJs.HoverIntent:
                return((int)FileOrder.Js.HoverIntent);

            default:
                return(jsl.PackageID + (int)FileOrder.Js.DefaultPriority);
            }
        }
        public override void Install()
        {
            try
            {
                //Attempt to get the JavaScript Library
                _installedLibrary = JavaScriptLibraryController.Instance.GetLibrary(l => l.LibraryName == _library.LibraryName && l.Version == _library.Version);

                if (_installedLibrary != null)
                {
                    _library.JavaScriptLibraryID = _installedLibrary.JavaScriptLibraryID;
                }
                //Save JavaScript Library  to database
                _library.PackageID = Package.PackageID;
                JavaScriptLibraryController.Instance.SaveLibrary(_library);

                Completed = true;
                Log.AddInfo(string.Format(Util.LIBRARY_Registered, _library.LibraryName));
            }
            catch (Exception ex)
            {
                Log.AddFailure(ex);
            }
        }
Example #15
0
        private static IEnumerable <JavaScriptLibrary> GetFinalScripts(IEnumerable <string> scripts)
        {
            var finalScripts = new List <JavaScriptLibrary>();

            foreach (string item in scripts)
            {
                JavaScriptLibrary processingLibrary =
                    JavaScriptLibraryController.Instance.GetLibrary(
                        l => l.JavaScriptLibraryID.ToString(CultureInfo.InvariantCulture) == item);

                JavaScriptLibrary existingLatestLibrary =
                    finalScripts.FindAll(lib => lib.LibraryName.Equals(processingLibrary.LibraryName, StringComparison.OrdinalIgnoreCase))
                    .OrderByDescending(l => l.Version)
                    .SingleOrDefault();
                if (existingLatestLibrary != null)
                {
                    //determine previous registration for same JSL
                    if (existingLatestLibrary.Version > processingLibrary.Version)
                    {
                        //skip new library & log
                        LogCollision(existingLatestLibrary.LibraryName + "-" + existingLatestLibrary.Version + " -> " +
                                     processingLibrary.LibraryName + "-" + processingLibrary.Version);
                    }
                    else
                    {
                        finalScripts.Remove(existingLatestLibrary);
                        finalScripts.Add(processingLibrary);
                    }
                }
                else
                {
                    finalScripts.Add(processingLibrary);
                }
            }
            return(finalScripts);
        }
Example #16
0
        private static IEnumerable <string> GetScriptVersions()
        {
            List <string> orderedScripts = (from object item in HttpContextSource.Current.Items.Keys
                                            where item.ToString().StartsWith(ScriptPrefix)
                                            select item.ToString().Substring(4)).ToList();

            orderedScripts.Sort();
            List <string> finalScripts = orderedScripts.ToList();

            foreach (string orderedScript in orderedScripts)
            {
                //find dependencies

                JavaScriptLibrary library =
                    JavaScriptLibraryController.Instance.GetLibrary(
                        l => l.JavaScriptLibraryID.ToString() == orderedScript);
                if (library != null)
                {
                    PackageInfo package = PackageController.Instance.GetExtensionPackage(Null.NullInteger,
                                                                                         p => p.PackageID == library.PackageID);
                    if (package.Dependencies.Any())
                    {
                        foreach (PackageDependencyInfo dependency in package.Dependencies)
                        {
                            JavaScriptLibrary dependantlibrary = GetHighestVersionLibrary(dependency.PackageName);
                            if (HttpContextSource.Current.Items[ScriptPrefix + "." + dependantlibrary.JavaScriptLibraryID] ==
                                null)
                            {
                                finalScripts.Add(dependantlibrary.JavaScriptLibraryID.ToString());
                            }
                        }
                    }
                }
            }
            return(finalScripts);
        }
Example #17
0
        /// <summary>
        ///     checks whether the script file is a known javascript library.
        /// </summary>
        /// <param name="jsname">script identifier.</param>
        /// <returns></returns>
        public static bool IsInstalled(string jsname)
        {
            JavaScriptLibrary library = JavaScriptLibraryController.Instance.GetLibrary(l => l.LibraryName.Equals(jsname, StringComparison.OrdinalIgnoreCase));

            return(library != null);
        }
        public override void ReadManifest(XPathNavigator manifestNav)
        {
            //Load the JavaScript Library from the manifest
            _library = CBO.DeserializeObject<JavaScriptLibrary>(new StringReader(manifestNav.InnerXml));
            _library.Version = Package.Version;

            if (Log.Valid)
            {
                Log.AddInfo(Util.LIBRARY_ReadSuccess);
            }
        }
Example #19
0
        private static string GetScriptPath(JavaScriptLibrary js)
        {
            if (Host.CdnEnabled)
            {
                //load custom CDN path setting
                var customCdn = HostController.Instance.GetString("CustomCDN_" + js.LibraryName);
                if (!string.IsNullOrEmpty(customCdn))
                {
                    return customCdn;
                }

                //cdn enabled but jsl does not have one defined
                if (!String.IsNullOrEmpty(js.CDNPath))
                {
                    return js.CDNPath;
                }
            }
            return ("~/Resources/libraries/" + js.LibraryName + "/" + Globals.FormatVersion(js.Version, "00", 3, "_") + "/" + js.FileName);
        }
Example #20
0
 /// <summary>Delete the library reference from the database</summary>
 /// <param name="library">Library to be deleted</param>
 public void DeleteLibrary(JavaScriptLibrary library)
 {
     DataProvider.Instance().ExecuteNonQuery("DeleteJavaScriptLibrary", library.JavaScriptLibraryID);
     ClearCache();
 }
Example #21
0
        /// <summary>
        ///     checks whether the script file is a known javascript library
        /// </summary>
        /// <param name="jsname">script identifier</param>
        /// <returns></returns>
        public static bool IsInstalled(String jsname)
        {
            JavaScriptLibrary library = JavaScriptLibraryController.Instance.GetLibrary(l => l.LibraryName == jsname);

            return(library != null);
        }
Example #22
0
        private static IEnumerable<JavaScriptLibrary> GetAllDependencies(JavaScriptLibrary library)
        {
            var package = PackageController.Instance.GetExtensionPackage(Null.NullInteger, p => p.PackageID == library.PackageID);
            foreach (var dependency in package.Dependencies)
            {
                var dependencyLibrary = GetHighestVersionLibrary(dependency.PackageName);
                yield return dependencyLibrary;

                foreach (var childDependency in GetAllDependencies(dependencyLibrary))
                {
                    yield return childDependency;
                }
            }
        }
        private static int GetFileOrder(JavaScriptLibrary jsl)
        {
            switch (jsl.LibraryName)
            {
                case CommonJs.jQuery:
                    return (int)FileOrder.Js.jQuery;
                case CommonJs.jQueryMigrate:
                    return (int)FileOrder.Js.jQueryMigrate;
                case CommonJs.jQueryUI:
                    return (int)FileOrder.Js.jQueryUI;
                case CommonJs.HoverIntent:
                    return (int)FileOrder.Js.HoverIntent;
                default:
                    return jsl.PackageID + (int) FileOrder.Js.DefaultPriority;

            }
        }
        private static void RegisterScript(Page page, JavaScriptLibrary jsl)
        {
            ClientResourceManager.RegisterScript(page, GetScriptPath(jsl), GetFileOrder(jsl), GetScriptLocation(jsl));

            //workaround to support IE specific script unti we move to IE version that no longer requires this
            if (jsl.LibraryName == CommonJs.jQueryFileUpload)
            {
                ClientResourceManager.RegisterScript(page,
                    "~/Resources/Shared/Scripts/jquery/jquery.iframe-transport.js");
            }

            if (Host.CdnEnabled && !String.IsNullOrEmpty(jsl.ObjectName))
            {
                string pagePortion;
                switch (jsl.PreferredScriptLocation)
                {
                    case ScriptLocation.PageHead:

                        pagePortion = "ClientDependencyHeadJs";
                        break;
                    case ScriptLocation.BodyBottom:
                        pagePortion = "ClientResourcesFormBottom";
                        break;
                    case ScriptLocation.BodyTop:
                        pagePortion = "BodySCRIPTS";
                        break;
                    default:
                        pagePortion = "BodySCRIPTS";
                        break;
                }
                Control scriptloader = page.FindControl(pagePortion);
                var fallback = new DnnJsIncludeFallback(jsl.ObjectName, VirtualPathUtility.ToAbsolute("~/Resources/libraries/" + jsl.LibraryName + "/" + Globals.FormatVersion(jsl.Version, "00", 3, "_") + "/" + jsl.FileName));
                if (scriptloader != null)
                {
                    //add the fallback control after script loader.
                    var index = scriptloader.Parent.Controls.IndexOf(scriptloader);
                    scriptloader.Parent.Controls.AddAt(index + 1, fallback);
                }
            }
        }
        private static string GetScriptLocation(JavaScriptLibrary js)
        {
            switch (js.PreferredScriptLocation)
            {
                case ScriptLocation.PageHead:
                    return "DnnPageHeaderProvider";
                case ScriptLocation.BodyBottom:
                    return "DnnFormBottomProvider";
                case ScriptLocation.BodyTop:
                    return "DnnBodyProvider";
            }

            return String.Empty;
        }
 private static string GetScriptPath(JavaScriptLibrary js)
 {
     if (Host.CdnEnabled)
     {
         //cdn enabled but jsl does not have one defined
         if (!String.IsNullOrEmpty(js.CDNPath))
         {
             return js.CDNPath;
         }
     }
     return ("~/Resources/libraries/" + js.LibraryName + "/" + Globals.FormatVersion(js.Version, "00", 3, "_") + "/" + js.FileName);
 }
Example #27
0
        /// <summary>
        ///     returns the version of a javascript library from the database.
        /// </summary>
        /// <param name="jsname">the library name.</param>
        /// <returns></returns>
        public static string Version(string jsname)
        {
            JavaScriptLibrary library = GetHighestVersionLibrary(jsname);

            return(library != null?Convert.ToString(library.Version) : string.Empty);
        }
        private static string GetLibraryPath(JavaScriptLibrary library)
        {
            if (Host.CdnEnabled)
            {
                var customUrl = HostController.Instance.GetString("CustomCDN_" + library.LibraryName);
                if (!string.IsNullOrEmpty(customUrl))
                {
                    return customUrl;
                }

                if (!string.IsNullOrEmpty(library.CDNPath))
                {
                    return library.CDNPath;
                }
            }

            var versionFolderName = Globals.FormatVersion(library.Version, "00", 3, "_");
            return $"~/Resources/libraries/{library.LibraryName}/{versionFolderName}/{library.FileName}";
        }