protected void GetCtrlName(Widget ww) {
			string sName = "";

			CMSPlugin plug = (from p in cmsHelper.ToolboxPlugins
							  where p.FilePath.ToLower() == ww.ControlPath.ToLower()
							  select p).FirstOrDefault();

			if (plug != null) {
				sName = plug.Caption;
			}

			lnkIndex.NavigateUrl = String.Format("{0}?id={1}", SiteFilename.PageWidgetsURL, ww.Root_ContentID);

			litControlPathName.Text = sName;
		}
        protected void btnDuplicate_Click(object sender, EventArgs e)
        {
            Guid gSrc = new Guid(hdnSelectedItem.Value);
            ContentPage pageSrc = pageHelper.FindContentByID(SiteID, gSrc);

            if (pageSrc != null) {

                phDone.Visible = true;
                List<Guid> lstSel = GeneralUtilities.GetCheckedItemGuidsByValue(gvWidgets, true, "chkContent");
                litCount.Text = string.Format(" {0} ", lstSel.Count);

                if (cmsHelper.cmsAdminWidget != null) {

                    List<Widget> cacheWidget = cmsHelper.cmsAdminWidget;

                    List<Widget> ww = (from w in pageSrc.GetWidgetList()
                                       where lstSel.Contains(w.Root_WidgetID) && w.IsLatestVersion == true
                                       select w).ToList();

                    if (ww != null) {
                        foreach (var w in ww) {
                            Guid newWidget = Guid.NewGuid();

                            Widget wCpy = new Widget {
                                Root_ContentID = guidContentID,
                                Root_WidgetID = newWidget,
                                WidgetDataID = Guid.NewGuid(),
                                PlaceholderName = sZone,
                                ControlPath = w.ControlPath,
                                ControlProperties = w.ControlProperties,
                                IsLatestVersion = true,
                                IsWidgetActive = w.IsWidgetActive,
                                IsPendingChange = true,
                                IsWidgetPendingDelete = false,
                                WidgetOrder = w.WidgetOrder,
                                EditDate = SiteData.CurrentSite.Now
                            };

                            cacheWidget.Add(wCpy);
                        }
                    }

                    cmsHelper.cmsAdminWidget = cacheWidget;
                }
            }
        }
        public WidgetWrapper AddWidget(Control widget, Widget widgetData)
        {
            WidgetWrapper wrapper = new WidgetWrapper();

            wrapper.WidgetData = widgetData;

            wrapper.IsAdminMode = true;
            wrapper.ControlPath = widgetData.ControlPath;
            wrapper.ControlTitle = widgetData.ControlPath;

            wrapper.Order = widgetData.WidgetOrder;
            wrapper.DatabaseKey = widgetData.Root_WidgetID;

            AddWidget(widget, wrapper);

            return wrapper;
        }
Exemple #4
0
        public Widget GetWidgetVersion(Guid widgetDataID)
        {
            Widget w = new Widget(CompiledQueries.cqGetWidgetDataByID_VW(db, widgetDataID));

            return w;
        }
		public void Save() {
			this.CopyCount = 0;
			if (this.Widgets != null) {
				List<Guid> lstSel = this.Widgets.Where(x => x.Selected).Select(x => x.Root_WidgetID).ToList();

				using (ContentPageHelper pageHelper = new ContentPageHelper()) {
					this.SelectedPage = pageHelper.FindContentByID(SiteData.CurrentSiteID, this.SelectedItem);
					this.Widgets = this.SelectedPage.GetWidgetList();
				}

				using (CMSConfigHelper cmsHelper = new CMSConfigHelper()) {
					cmsHelper.OverrideKey(this.Root_ContentID);

					if (cmsHelper.cmsAdminWidget != null) {
						List<Widget> cacheWidget = cmsHelper.cmsAdminWidget;

						List<Widget> ww = (from w in this.SelectedPage.GetWidgetList()
										   where lstSel.Contains(w.Root_WidgetID) && w.IsLatestVersion == true
										   select w).ToList();

						if (ww != null) {
							this.CopyCount = ww.Count;

							foreach (var w in ww) {
								Guid newWidget = Guid.NewGuid();

								Widget wCpy = new Widget {
									Root_ContentID = this.Root_ContentID,
									Root_WidgetID = newWidget,
									WidgetDataID = Guid.NewGuid(),
									PlaceholderName = this.PlaceholderName,
									ControlPath = w.ControlPath,
									ControlProperties = w.ControlProperties,
									IsLatestVersion = true,
									IsPendingChange = true,
									IsWidgetActive = true,
									IsWidgetPendingDelete = false,
									WidgetOrder = w.WidgetOrder,
									GoLiveDate = w.GoLiveDate,
									RetireDate = w.RetireDate,
									EditDate = SiteData.CurrentSite.Now
								};

								cacheWidget.Add(wCpy);
							}
						}

						cmsHelper.cmsAdminWidget = cacheWidget;
					}
				}
			}
		}
        protected void BuildWidgetInstall()
        {
            pnlReview.Visible = true;

            SiteData site = SiteData.CurrentSite;

            CMSAdminModuleMenu thisModule = cmsHelper.GetCurrentAdminModuleControl();
            string sDir = thisModule.ControlFile.Substring(0, thisModule.ControlFile.LastIndexOf("/"));
            List<CMSPlugin> lstPlug = cmsHelper.GetPluginsInFolder(sDir);

            CMSPlugin plug = lstPlug.Where(x => x.FilePath.EndsWith("PhotoGalleryPrettyPhoto.ascx")).FirstOrDefault();

            GalleryHelper gh = new GalleryHelper(site.SiteID);

            foreach (GridViewRow row in gvPages.Rows) {
                Guid gRootPage = Guid.Empty;
                Guid gGallery = Guid.Empty;
                int iPost = 0;

                CheckBox chkSelect = (CheckBox)row.FindControl("chkSelect");

                if (chkSelect.Checked) {
                    HiddenField hdnPostID = (HiddenField)row.FindControl("hdnPostID");

                    iPost = int.Parse(hdnPostID.Value);

                    List<WordPressPost> lstA = (from a in wpSite.Content
                                                where a.PostType == WordPressPost.WPPostType.Attachment
                                                && a.ParentPostID == iPost
                                                orderby a.PostDateUTC
                                                select a).Distinct().ToList();

                    lstA.ToList().ForEach(q => q.ImportFileSlug = ddlFolders.SelectedValue + "/" + q.ImportFileSlug);
                    lstA.ToList().ForEach(q => q.ImportFileSlug = q.ImportFileSlug.Replace("//", "/").Replace("//", "/"));

                    WordPressPost post = (from p in wpSite.Content
                                          where p.PostID == iPost
                                          select p).FirstOrDefault();

                    ContentPage cp = null;

                    List<ContentPage> lstCP = pageHelper.FindPageByTitleAndDate(site.SiteID, post.PostTitle, post.PostName, post.PostDateUTC);

                    if (lstCP != null && lstCP.Any()) {
                        cp = lstCP.FirstOrDefault();
                    }

                    if (cp != null) {
                        gRootPage = cp.Root_ContentID;
                        if (cp.PageText.Contains("[gallery]")) {
                            cp.PageText = cp.PageText.Replace("[gallery]", "");
                            cp.SavePageEdit();
                        }
                    }

                    GalleryGroup gal = gh.GalleryGroupGetByName(post.PostTitle);

                    if (gal == null) {
                        gal = new GalleryGroup();
                        gal.SiteID = site.SiteID;
                        gal.GalleryID = Guid.Empty;
                        gal.GalleryTitle = post.PostTitle;

                        gal.Save();
                    }

                    gGallery = gal.GalleryID;

                    int iPos = 0;

                    foreach (var img in lstA) {
                        img.ImportFileSlug = img.ImportFileSlug.Replace("//", "/").Replace("//", "/");

                        if (!chkFileGrab.Checked) {
                            cmsHelper.GetFile(img.AttachmentURL, img.ImportFileSlug);
                        }

                        if (!string.IsNullOrEmpty(img.ImportFileSlug)) {
                            GalleryImageEntry theImg = gh.GalleryImageEntryGetByFilename(gGallery, img.ImportFileSlug);

                            if (theImg == null) {
                                theImg = new GalleryImageEntry();
                                theImg.GalleryImage = img.ImportFileSlug;
                                theImg.GalleryImageID = Guid.Empty;
                                theImg.GalleryID = gGallery;
                            }
                            theImg.ImageOrder = iPos;
                            theImg.Save();

                            GalleryMetaData theMeta = gh.GalleryMetaDataGetByFilename(img.ImportFileSlug);

                            if (theMeta == null) {
                                theMeta = new GalleryMetaData();
                                theMeta.GalleryImageMetaID = Guid.Empty;
                                theMeta.SiteID = site.SiteID;
                            }

                            if (!string.IsNullOrEmpty(img.PostTitle) || !string.IsNullOrEmpty(img.PostContent)) {
                                theMeta.ImageTitle = img.PostTitle;
                                theMeta.ImageMetaData = img.PostContent;

                                theMeta.Save();
                            }
                        }
                        iPos++;
                    }

                    if (gRootPage != Guid.Empty) {
                        List<Widget> lstW = (from w in cp.GetWidgetList()
                                             where w.ControlPath.ToLower() == plug.FilePath.ToLower()
                                                && w.ControlProperties.ToLower().Contains(gGallery.ToString().ToLower())
                                             select w).ToList();

                        if (lstW.Count < 1) {
                            Widget newWidget = new Widget();
                            newWidget.ControlProperties = null;
                            newWidget.Root_ContentID = gRootPage;
                            newWidget.Root_WidgetID = Guid.NewGuid();
                            newWidget.WidgetDataID = newWidget.Root_WidgetID;
                            newWidget.ControlPath = plug.FilePath;
                            newWidget.EditDate = SiteData.CurrentSite.Now;

                            newWidget.IsLatestVersion = true;
                            newWidget.IsWidgetActive = true;
                            newWidget.IsWidgetPendingDelete = false;
                            newWidget.WidgetOrder = -1;
                            newWidget.PlaceholderName = txtPlaceholderName.Text;

                            List<WidgetProps> lstProps = new List<WidgetProps>();
                            lstProps.Add(new WidgetProps { KeyName = "ShowHeading", KeyValue = chkShowHeading.Checked.ToString() });
                            lstProps.Add(new WidgetProps { KeyName = "ScaleImage", KeyValue = chkScaleImage.Checked.ToString() });
                            lstProps.Add(new WidgetProps { KeyName = "ThumbSize", KeyValue = ddlSize.SelectedValue });
                            lstProps.Add(new WidgetProps { KeyName = "PrettyPhotoSkin", KeyValue = ddlSkin.SelectedValue });
                            lstProps.Add(new WidgetProps { KeyName = "GalleryID", KeyValue = gGallery.ToString() });

                            newWidget.SaveDefaultControlProperties(lstProps);

                            newWidget.Save();
                        }
                    }
                }
            }
        }
		public string CacheWidgetUpdate(string WidgetAddition, string ThisPage) {
			try {
				WidgetAddition = CMSConfigHelper.DecodeBase64(WidgetAddition);
				CurrentPageGuid = new Guid(ThisPage);
				LoadGuids();

				List<Widget> cacheWidget = cmsAdminWidget;

				List<Widget> inputWid = new List<Widget>();
				Dictionary<Guid, int> dictOrder = new Dictionary<Guid, int>();
				int iW = 0;

				WidgetAddition = WidgetAddition.Replace("\r\n", "\n");
				WidgetAddition = WidgetAddition.Replace("\r", "\n");
				string[] arrWidgRows = WidgetAddition.Split('\n');

				foreach (string arrWidgCell in arrWidgRows) {
					if (!String.IsNullOrEmpty(arrWidgCell)) {
						bool bGoodWidget = false;
						string[] w = arrWidgCell.Split('\t');

						Widget rWidg = new Widget();
						if (w[2].ToLower().EndsWith(".cshtml") || w[2].ToLower().EndsWith(".vbhtml")
								|| w[2].ToLower().Contains(":") || w[2].ToLower().Contains("|")) {
							rWidg.ControlPath = w[2];
							rWidg.Root_WidgetID = Guid.NewGuid();

							DateTime dtSite = CMSConfigHelper.CalcNearestFiveMinTime(SiteData.CurrentSite.Now);
							rWidg.GoLiveDate = dtSite;
							rWidg.RetireDate = dtSite.AddYears(200);

							bGoodWidget = true;
						} else {
							if (w[2].ToString().Length == Guid.Empty.ToString().Length) {
								rWidg.Root_WidgetID = new Guid(w[2]);
								bGoodWidget = true;
							}
						}
						if (bGoodWidget) {
							dictOrder.Add(rWidg.Root_WidgetID, iW);

							rWidg.WidgetDataID = Guid.NewGuid();
							rWidg.IsPendingChange = true;
							rWidg.PlaceholderName = w[1].Substring(4);
							rWidg.WidgetOrder = int.Parse(w[0]);
							rWidg.Root_ContentID = CurrentPageGuid;
							rWidg.IsWidgetActive = true;
							rWidg.IsLatestVersion = true;
							rWidg.EditDate = SiteData.CurrentSite.Now;
							inputWid.Add(rWidg);
						}
						iW++;
					}
				}

				foreach (Widget wd1 in inputWid) {
					Widget wd2 = (from d in cacheWidget where d.Root_WidgetID == wd1.Root_WidgetID select d).FirstOrDefault();

					if (wd2 == null) {
						cacheWidget.Add(wd1);
					} else {
						wd2.EditDate = SiteData.CurrentSite.Now;
						wd2.PlaceholderName = wd1.PlaceholderName; // if moving zones

						int i = cacheWidget.IndexOf(wd2);
						cacheWidget[i].WidgetOrder = wd1.WidgetOrder;

						int? mainSort = (from entry in dictOrder
										 where entry.Key == wd1.Root_WidgetID
										 select entry.Value).FirstOrDefault();

						if (mainSort != null) {
							cacheWidget[i].WidgetOrder = Convert.ToInt32(mainSort);
						}
					}
				}

				cmsAdminWidget = cacheWidget;
				return "OK";
			} catch (Exception ex) {
				SiteData.WriteDebugException("webservice", ex);

				return ex.ToString();
			}
		}
		public string CopyWidget(string DBKey, string ThisPage) {
			try {
				CurrentPageGuid = new Guid(ThisPage);
				LoadGuids();

				Guid guidWidget = new Guid(DBKey);

				List<Widget> cacheWidget = cmsAdminWidget;

				List<Widget> ww = (from w in cacheWidget
								   where w.Root_WidgetID == guidWidget
									&& w.IsLatestVersion == true
								   select w).ToList();

				if (ww != null) {
					foreach (var w in ww) {
						Guid newWidget = Guid.NewGuid();

						Widget wCpy = new Widget {
							Root_ContentID = w.Root_ContentID,
							Root_WidgetID = newWidget,
							WidgetDataID = Guid.NewGuid(),
							PlaceholderName = w.PlaceholderName,
							ControlPath = w.ControlPath,
							ControlProperties = w.ControlProperties,
							IsLatestVersion = true,
							IsPendingChange = true,
							IsWidgetActive = true,
							IsWidgetPendingDelete = false,
							WidgetOrder = w.WidgetOrder,
							GoLiveDate = w.GoLiveDate,
							RetireDate = w.RetireDate,
							EditDate = SiteData.CurrentSite.Now
						};

						cacheWidget.Add(wCpy);
					}
				}

				cmsAdminWidget = cacheWidget;

				return "OK";
			} catch (Exception ex) {
				SiteData.WriteDebugException("webservice", ex);

				return ex.ToString();
			}
		}
        //============================
        public static List<ObjectProperty> GetWidgetProperties(Widget w, Guid guidContentID)
        {
            Object widget = new Object();

            List<WidgetProps> lstProps = w.ParseDefaultControlProperties();

            if (w.ControlPath.Contains(":")) {
                if (w.ControlPath.ToUpper().StartsWith("CLASS:")) {
                    try {
                        string className = w.ControlPath.Replace("CLASS:", "");
                        Type t = Type.GetType(className);
                        widget = Activator.CreateInstance(t);
                    } catch (Exception ex) { }
                } else {
                    try {
                        string[] path = w.ControlPath.Split(':');
                        string objectPrefix = path[0];
                        string objectClass = path[1];

                        Type t = Type.GetType(objectClass);
                        Object obj = Activator.CreateInstance(t);

                        Object attrib = ReflectionUtilities.GetAttribute<WidgetActionSettingModelAttribute>(t, objectPrefix);

                        if (attrib != null) {
                            Type s = Type.GetType(((WidgetActionSettingModelAttribute)attrib).ClassName);
                            widget = Activator.CreateInstance(s);
                        }
                    } catch (Exception ex) { }
                }
            }

            if (widget is IAdminModule) {
                var w1 = (IAdminModule)widget;
                w1.SiteID = SiteData.CurrentSiteID;
            }

            if (widget is IWidget) {
                var w1 = (IWidget)widget;
                w1.SiteID = SiteData.CurrentSiteID;
                w1.RootContentID = w.Root_ContentID;
                w1.PageWidgetID = w.Root_WidgetID;
                w1.IsDynamicInserted = true;
            }

            if (widget is IWidgetRawData) {
                var w1 = (IWidgetRawData)widget;
                w1.RawWidgetData = w.ControlProperties;
            }

            List<ObjectProperty> lstDefProps = ObjectProperty.GetObjectProperties(widget);

            //require that widget be attributed to be on the list
            List<string> limitedPropertyList = (from ww in widget.GetType().GetProperties()
                                                where Attribute.IsDefined(ww, typeof(WidgetAttribute))
                                                select ww.Name.ToLower()).ToList();

            List<ObjectProperty> lstPropsToEdit = (from p in lstDefProps
                                                   join l in limitedPropertyList on p.Name.ToLower() equals l.ToLower()
                                                   where p.CanRead == true
                                                       && p.CanWrite == true
                                                   select p).ToList();

            foreach (var dp in lstPropsToEdit) {
                string sName = dp.Name.ToLower();
                List<WidgetProps> lstItmVals = lstProps.Where(x => x.KeyName.ToLower().StartsWith(sName + "|") || x.KeyName.ToLower() == sName).ToList();

                ObjectProperty ListSourceProperty = new ObjectProperty();

                string sListSourcePropertyName = (from p in lstDefProps
                                                  where p.Name.ToLower() == sName.ToLower()
                                                        && !String.IsNullOrEmpty(p.CompanionSourceFieldName)
                                                  select p.CompanionSourceFieldName).FirstOrDefault();

                if (String.IsNullOrEmpty(sListSourcePropertyName)) {
                    sListSourcePropertyName = String.Empty;
                }

                ListSourceProperty = (from p in lstDefProps
                                      where p.CanRead == true
                                         && p.CanWrite == false
                                         && p.Name.ToLower() == sListSourcePropertyName.ToLower()
                                      select p).FirstOrDefault();

                if (lstItmVals != null && lstItmVals.Any() && dp.FieldMode != WidgetAttribute.FieldMode.CheckBoxList) {
                    dp.TextValue = lstItmVals != null ? lstItmVals.FirstOrDefault().KeyValue : String.Empty;
                    dp.DefValue = dp.TextValue;
                }

                Type pt = dp.PropertyType;

                if (ListSourceProperty != null) {
                    if (ListSourceProperty.DefValue is Dictionary<string, string>) {
                        dp.Options = OptionSelections.GetOptionsFromDictionary((Dictionary<string, string>)ListSourceProperty.DefValue);

                        // work with a checkbox list, allow more than one value
                        if (dp.FieldMode == WidgetAttribute.FieldMode.CheckBoxList) {
                            // since this is a multi selected capable field, look for anything that starts with the
                            // field name and has the delimeter trailing

                            if (lstItmVals.Count > 0) {
                                foreach (var v in dp.Options) {
                                    v.Selected = (from p in lstItmVals
                                                  where p.KeyValue == v.Value
                                                  select p.KeyValue).Any();
                                }
                            }
                        }
                    }
                }

                if ((pt == typeof(bool)) || dp.FieldMode == WidgetAttribute.FieldMode.CheckBox) {
                    dp.FieldMode = WidgetAttribute.FieldMode.CheckBox;
                    dp.CheckBoxState = Convert.ToBoolean(dp.DefValue);
                }
            }

            return lstPropsToEdit;
        }
 public WidgetProperties(Widget widget, List<ObjectProperty> properties)
 {
     this.Widget = widget;
     this.Properties = properties;
 }