public static dynamic Add(PortalSettings PortalSettings, CustomBlock CustomBlock, int ForceCount = 0)
            {
                dynamic Result = new ExpandoObject();

                try
                {
                    if (BlockFactory.Get(PortalSettings.PortalId, CustomBlock.Name) == null)
                    {
                        if (ForceCount == 0)
                        {
                            CustomBlock.Guid = Guid.NewGuid().ToString().ToLower();
                        }

                        CustomBlock.PortalID  = PortalSettings.PortalId;
                        CustomBlock.CreatedBy = PortalSettings.UserId;
                        CustomBlock.UpdatedBy = PortalSettings.UserId;
                        CustomBlock.CreatedOn = DateTime.UtcNow;
                        CustomBlock.UpdatedOn = DateTime.UtcNow;
                        CustomBlock.Locale    = PageManager.GetCultureCode(PortalSettings);
                        BlockFactory.AddUpdate(CustomBlock);
                        CustomBlock cb = BlockFactory.GetAll(PortalSettings.PortalId).Where(b => b.Guid.ToLower() == CustomBlock.Guid.ToLower() && b.Locale == null).FirstOrDefault();
                        if (cb == null)
                        {
                            cb        = CustomBlock;
                            cb.Locale = null;
                            cb.ID     = 0;
                            BlockFactory.AddUpdate(cb);
                        }
                        Result.Status = "Success";
                        Result.Guid   = CustomBlock.Guid;
                    }
                    else
                    {
                        if (ForceCount > 0)
                        {
                            CustomBlock.Name = CustomBlock.Name + ForceCount;
                            ForceCount++;
                            Result = Add(PortalSettings, CustomBlock, ForceCount);
                        }
                        else
                        {
                            Result.Status = "Exist";
                        }
                    }
                }
                catch (Exception ex)
                {
                    Result.Status = ex.Message.ToString();
                    DotNetNuke.Services.Exceptions.Exceptions.LogException(ex);
                }
                return(Result);
            }
Esempio n. 2
0
            private static void BuildGlobalBlockMarkup(int PortalId, int UserId, HtmlNode item)
            {
                string blockguid = item.Attributes.Where(a => a.Name == "data-guid").FirstOrDefault().Value;

                if (!string.IsNullOrEmpty(blockguid))
                {
                    CustomBlock customBlock = BlockManager.GetByLocale(PortalId, blockguid, GetCultureCode(PortalController.Instance.GetCurrentSettings() as PortalSettings));
                    if (customBlock == null)
                    {
                        customBlock = new CustomBlock
                        {
                            Guid      = blockguid.ToLower(),
                            PortalID  = PortalId,
                            Name      = item.Attributes.Where(a => a.Name == "data-name").FirstOrDefault().Value,
                            Category  = item.Attributes.Where(a => a.Name == "data-category").FirstOrDefault().Value,
                            IsGlobal  = true,
                            CreatedBy = UserId,
                            UpdatedBy = UserId,
                            CreatedOn = DateTime.UtcNow,
                            UpdatedOn = DateTime.UtcNow
                        };
                        string[] str = item.InnerHtml.Split(new string[] { "</style>" }, StringSplitOptions.None);
                        if (str.Length > 1)
                        {
                            customBlock.Html = str[1];
                            customBlock.Css  = str[0];
                        }
                        else
                        {
                            customBlock.Html = str[0];
                        }

                        BlockFactory.AddUpdate(customBlock);
                    }
                    item.InnerHtml = item.Attributes.Where(a => a.Name == "data-block-type").FirstOrDefault().Value;
                    item.Attributes.Remove("data-category");
                    item.Attributes.Remove("data-name");
                }
            }
            public static dynamic Edit(PortalSettings PortalSettings, CustomBlock CustomBlock)
            {
                dynamic Result = new ExpandoObject();

                try
                {
                    CustomBlock cb = BlockFactory.GetAll(PortalSettings.PortalId).Where(b => b.Guid.ToLower() == CustomBlock.Guid.ToLower() && b.Locale == PageManager.GetCultureCode(PortalSettings)).FirstOrDefault();
                    if (cb == null)
                    {
                        cb = BlockFactory.GetAll(PortalSettings.PortalId).Where(b => b.Guid.ToLower() == CustomBlock.Guid.ToLower() && b.Locale == null).FirstOrDefault();
                        if (cb != null)
                        {
                            cb.Locale = PageManager.GetCultureCode(PortalSettings);
                            cb.ID     = 0;
                            BlockFactory.AddUpdate(cb);
                        }
                    }
                    if (cb != null)
                    {
                        cb.Name     = CustomBlock.Name;
                        cb.Category = CustomBlock.Category;

                        if (CustomBlock.IsGlobal && !string.IsNullOrEmpty(CustomBlock.Html))
                        {
                            HtmlDocument html = new HtmlDocument();
                            html.LoadHtml(CustomBlock.Html);
                            IEnumerable <HtmlNode> query = html.DocumentNode.Descendants("div");
                            foreach (HtmlNode item in query.ToList())
                            {
                                if (item.Attributes.Where(a => a.Name == "dmid").FirstOrDefault() != null && item.Attributes.Where(a => a.Name == "mid").FirstOrDefault() != null && !string.IsNullOrEmpty(item.Attributes.Where(a => a.Name == "mid").FirstOrDefault().Value))
                                {
                                    int        mid   = int.Parse(item.Attributes.Where(a => a.Name == "mid").FirstOrDefault().Value);
                                    ModuleInfo minfo = ModuleController.Instance.GetModule(mid, Null.NullInteger, false);
                                    if (minfo != null && !minfo.AllTabs)
                                    {
                                        minfo.AllTabs = true;
                                        ModuleController.Instance.UpdateModule(minfo);
                                        List <TabInfo> listTabs = TabController.GetPortalTabs(minfo.PortalID, Null.NullInteger, false, true);
                                        foreach (TabInfo destinationTab in listTabs)
                                        {
                                            ModuleInfo module = ModuleController.Instance.GetModule(minfo.ModuleID, destinationTab.TabID, false);
                                            if (module != null)
                                            {
                                                if (module.IsDeleted)
                                                {
                                                    ModuleController.Instance.RestoreModule(module);
                                                }
                                            }
                                            else
                                            {
                                                if (!PortalSettings.Current.ContentLocalizationEnabled || (minfo.CultureCode == destinationTab.CultureCode))
                                                {
                                                    ModuleController.Instance.CopyModule(minfo, destinationTab, minfo.PaneName, true);
                                                }
                                            }
                                        }
                                    }
                                    item.InnerHtml = "<div vjmod=\"true\"><app id=\"" + mid + "\"></app>";
                                }
                                else if (item.Attributes.Where(a => a.Name == "data-block-type").FirstOrDefault() != null)
                                {
                                    if (item.Attributes.Where(a => a.Name == "data-block-type").FirstOrDefault().Value.ToLower() != "global")
                                    {
                                        item.InnerHtml = item.Attributes.Where(a => a.Name == "data-block-type").FirstOrDefault().Value;
                                    }
                                }
                            }
                            CustomBlock.Html = html.DocumentNode.OuterHtml;
                        }

                        cb.Html      = CustomBlock.Html;
                        cb.Css       = CustomBlock.Css;
                        cb.IsGlobal  = CustomBlock.IsGlobal;
                        cb.UpdatedBy = PortalSettings.Current.UserId;
                        cb.UpdatedOn = DateTime.UtcNow;
                        BlockFactory.AddUpdate(cb);
                        Result.Status      = "Success";
                        Result.Guid        = cb.Guid;
                        Result.CustomBlock = cb;
                    }
                    else
                    {
                        Result.Status = "Not exist";
                    }
                }
                catch (Exception ex)
                {
                    Result.Status = ex.Message.ToString();
                    DotNetNuke.Services.Exceptions.Exceptions.LogException(ex);
                }
                return(Result);
            }