/// <summary> /// On Load /// </summary> /// <param name="e"> /// The e. /// </param> protected override void OnLoad(EventArgs e) { Assert.ArgumentNotNull(e, "e"); base.OnLoad(e); if (!Context.ClientPage.IsEvent) { this.Mode = WebUtil.GetQueryString("mo"); try { this.InternalLinkDataContext.GetFromQueryString(); } catch { } try { this.MediaDataContext.GetFromQueryString(); } catch { } var queryString = WebUtil.GetQueryString("fo"); if (queryString.Length > 0) { if (queryString.EndsWith(".aspx", StringComparison.OrdinalIgnoreCase)) { if (!queryString.StartsWith("/sitecore")) { queryString = FileUtil.MakePath("/sitecore/content", queryString, '/'); } if (queryString.EndsWith(".aspx")) { queryString = StringUtil.Left(queryString, queryString.Length - 5); } this.InternalLinkDataContext.Folder = queryString; } else if (ShortID.IsShortID(queryString)) { queryString = ShortID.Parse(queryString).ToID().ToString(); var item = Client.ContentDatabase.GetItem(queryString); if (item != null) { if (!item.Paths.IsMediaItem) { this.InternalLinkDataContext.Folder = queryString; } else { this.MediaDataContext.Folder = queryString; } } } } } }
/// <summary> /// Raises the load event. /// </summary> /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param> /// <remarks> /// This method notifies the server control that it should perform actions common to each HTTP /// request for the page it is associated with, such as setting up a database query. At this /// stage in the page lifecycle, server controls in the hierarchy are created and initialized, /// view state is restored, and form controls reflect client-side data. Use the IsPostBack /// property to determine whether the page is being loaded in response to a client postback, /// or if it is being loaded and accessed for the first time. /// </remarks> protected override void OnLoad(EventArgs e) { Assert.ArgumentNotNull(e, "e"); base.OnLoad(e); if (Context.ClientPage.IsEvent) { return; } Mode = WebUtil.GetQueryString("mo"); DataContext.GetFromQueryString(); string queryString = WebUtil.GetQueryString("fo"); if (ShortID.IsShortID(queryString)) { DataContext.Folder = ShortID.Parse(queryString).ToID().ToString(); } Context.ClientPage.ServerProperties["mode"] = WebUtil.GetQueryString("mo"); if (!string.IsNullOrEmpty(WebUtil.GetQueryString("databasename"))) { DataContext.Parameters = "databasename=" + WebUtil.GetQueryString("databasename"); } Item folder = DataContext.GetFolder(); Assert.IsNotNull(folder, "Folder not found"); SelectItem(folder); Upload.Click = "media:upload(edit=" + (Settings.Media.OpenContentEditorAfterUpload ? "1" : "0") + ",load=1)"; Upload.ToolTip = Translate.Text("Upload a new media file to the Media Library"); EditButton.ToolTip = Translate.Text("Edit the media item in the Content Editor."); }
protected void ShowConfirm(ClientPipelineArgs args) { Assert.ArgumentNotNull(args, "args"); if (!args.IsPostBack) { SheerResponse.Confirm("Personalize component settings will be removed. Are you sure you want to continue?"); args.WaitForPostBack(); return; } if (!args.HasResult || !(args.Result != "no")) { this.ComponentPersonalization.Checked = true; return; } SheerResponse.Eval("scTogglePersonalizeComponentSection()"); XElement rulesSet = this.RulesSet; foreach (XElement xElement in rulesSet.Elements("rule")) { XElement actionById = PersonalizationFormWithActions.GetActionById(xElement, this.SetRenderingActionId); if (actionById == null) { continue; } actionById.Remove(); HtmlTextWriter htmlTextWriter = new HtmlTextWriter(new StringWriter()); this.RenderSetRenderingAction(xElement, htmlTextWriter); ShortID shortID = ShortID.Parse(xElement.GetAttributeValue("uid")); Assert.IsNotNull(shortID, "ruleId"); SheerResponse.SetInnerHtml(string.Concat(shortID, "_setrendering"), htmlTextWriter.InnerWriter.ToString().Replace("{ID}", shortID.ToString())); } this.RulesSet = rulesSet; }
protected string GetFilterSectionHtml([NotNull] XElement filter, bool fillVisitorCount) { Assert.ArgumentNotNull(filter, "filter"); var writer = new HtmlTextWriter(new StringWriter(CultureInfo.CurrentCulture)); var id = ShortID.Parse(filter.GetAttributeValue("uid")).ToString(); writer.Write("<table id='{ID}_body' cellspacing='0' cellpadding='0' class='rule-body'>"); writer.Write("<tbody>"); writer.Write("<tr>"); writer.Write("<td class='left-column'>"); RenderRuleConditions(filter, writer); writer.Write("</td>"); writer.Write("<td class='right-column'>"); writer.Write(string.Format(CultureInfo.InvariantCulture, "<span>{0}</span>", HttpUtility.HtmlEncode(Translate.Text(SB.Texts.ContactsThatMatchThisRule)))); if (fillVisitorCount) { XElement rule; var number = GetVisitorsCount(GetFilterPosition(id), out rule); writer.Write(string.Format(CultureInfo.InvariantCulture, "<span class='value' id='{1}ID{2}_count'>{0}</span>", number, "{", "}")); } else { writer.Write(string.Format(CultureInfo.InvariantCulture, "<span class='value'>{0}</span>", HttpUtility.HtmlEncode(Translate.Text(SB.Texts.Calculating)))); } writer.Write("</td>"); writer.Write("</tr>"); writer.Write("</tbody>"); writer.Write("</table>"); var panelHtml = writer.InnerWriter.ToString().Replace("{ID}", id); var actionsContext = new CollapsiblePanelRenderer.ActionsContext { IsVisible = true, OnActionClick = "javascript:return Sitecore.CollapsiblePanel.showActionsMenu(this,event)", Menu = GetActionsMenu(id) }; var name = Translate.Text(SB.Texts.SpecifyName); if (!string.IsNullOrEmpty(filter.GetAttributeValue("name"))) { name = filter.GetAttributeValue("name"); } var nameContext = new CollapsiblePanelRenderer.NameContext(name) { Editable = true, OnNameChanged = "javascript:return Sitecore.CollapsiblePanel.renameComplete(this,event)" }; var panelRenderer = new CollapsiblePanelRenderer(); panelRenderer.CssClass = "rule-container"; return(Assert.ResultNotNull(panelRenderer.Render(id, panelHtml, nameContext, actionsContext))); }
/// <summary> /// Gets the filter position. /// </summary> /// <param name="filterElement">The filter.</param> /// <returns>The filter position in list.</returns> protected int GetFilterPosition([NotNull] XElement filterElement) { Assert.ArgumentNotNull(filterElement, "filterElement"); var id = ShortID.Parse(filterElement.GetAttributeValue("uid")).ToString(); return(GetFilterPosition(id)); }
/// <summary> /// Updates the visitor count. /// </summary> /// <param name="count"> /// The count. /// </param> /// <param name="rule"> /// The rule. /// </param> protected void UpdateVisitorCount(long count, [NotNull] XElement rule) { Assert.ArgumentNotNull(rule, "rule"); var id = ShortID.Parse(rule.GetAttributeValue("uid")).ToString(); Assert.IsNotNullOrEmpty(id, "id"); SheerResponse.SetInnerHtml(id + "_count", count.ToString(CultureInfo.CurrentCulture)); }
private static IEnumerable <ID> GetCompatibleRenderingsList(GetChromeDataArgs args) { var morphButton = args.ChromeData.Commands.FirstOrDefault(x => x.Click.StartsWith("chrome:rendering:morph")); if (morphButton == null) { return(new ID[0]); } var ids = morphButton.Click.Split(',', '\'', '"', '(', ')'); return(ids.Where(ShortID.IsShortID).Select(x => ShortID.Parse(x).ToID())); }
private string GetRuleSectionHtml(XElement rule) { Assert.ArgumentNotNull(rule, "rule"); HtmlTextWriter htmlTextWriter = new HtmlTextWriter(new StringWriter()); string str = ShortID.Parse(rule.GetAttributeValue("uid")).ToString(); htmlTextWriter.Write("<table id='{ID}_body' cellspacing='0' cellpadding='0' class='rule-body'>"); htmlTextWriter.Write("<tbody>"); htmlTextWriter.Write("<tr>"); htmlTextWriter.Write("<td class='left-column'>"); this.RenderRuleConditions(rule, htmlTextWriter); htmlTextWriter.Write("</td>"); htmlTextWriter.Write("<td class='right-column'>"); this.RenderRuleActions(rule, htmlTextWriter); htmlTextWriter.Write("</td>"); htmlTextWriter.Write(this.RenderRulePlaceholder("afterAction", rule)); htmlTextWriter.Write("</tr>"); htmlTextWriter.Write("</tbody>"); htmlTextWriter.Write("</table>"); string str1 = htmlTextWriter.InnerWriter.ToString().Replace("{ID}", str); bool flag = PersonalizationFormWithActions.IsDefaultCondition(rule); CollapsiblePanelRenderer.ActionsContext actionsMenu = new CollapsiblePanelRenderer.ActionsContext() { IsVisible = !flag }; if (!flag) { actionsMenu.OnActionClick = "javascript:return Sitecore.CollapsiblePanel.showActionsMenu(this,event)"; actionsMenu.Menu = this.GetActionsMenu(str); } string attributeValue = "Default"; if (!flag || !string.IsNullOrEmpty(rule.GetAttributeValue("name"))) { attributeValue = rule.GetAttributeValue("name"); } CollapsiblePanelRenderer.NameContext nameContext = new CollapsiblePanelRenderer.NameContext(attributeValue) { Editable = !flag, OnNameChanged = "javascript:return Sitecore.CollapsiblePanel.renameComplete(this,event)" }; CollapsiblePanelRenderer.NameContext nameContext1 = nameContext; CollapsiblePanelRenderer collapsiblePanelRenderer = new CollapsiblePanelRenderer() { CssClass = "rule-container" }; return(collapsiblePanelRenderer.Render(str, str1, nameContext1, actionsMenu)); }
public static IEnumerable <Item> ResolveDatasourceItems(this Database db, string datasource, Item contextItem = null) { if (string.IsNullOrWhiteSpace(datasource)) { return(new Item[0]); } try { var ids = ID.ParseArray(datasource); if (ids.Length > 0) { return(ids.Select(db.GetItem).Where(x => x != null)); } } catch { } var itemId = ShortID.IsShortID(datasource) ? ShortID.Parse(datasource).ToID() : ID.Null; if (!ID.IsNullOrEmpty(itemId)) { var item = db.GetItem(itemId); return(item == null ? new Item[0] : new[] { item }); } string query = null; if (!string.IsNullOrWhiteSpace(datasource) && datasource.StartsWith("query:")) { query = datasource.Substring("query:".Length); } else if (!string.IsNullOrWhiteSpace(datasource) && (datasource.StartsWith("/") || datasource.StartsWith("./") || datasource.StartsWith("../"))) { query = EscapeItemPathForQuery(datasource); } if (!string.IsNullOrWhiteSpace(query)) { return((contextItem == null ? db.SelectItems(query) : contextItem.Axes.SelectItems(query)) ?? new Item[0]); } return(new Item[0]); }
public Guid GetItemId(string value) { if (string.IsNullOrWhiteSpace(value)) { return(Guid.Empty); } if (ShortID.IsShortID(value)) { return(ShortID.Parse(value).ToID().Guid); } if (ID.IsID(value)) { return(ID.Parse(value).Guid); } return(Guid.Parse(value)); }
/// <summary> /// Gets the filter position. /// </summary> /// <param name="id">The filter id.</param> /// <returns>The filter position in the list.</returns> protected int GetFilterPosition([NotNull] string id) { Assert.ArgumentNotNull(id, "id"); var ruleElements = FilterSet.Elements("rule"); int position; for (position = 0; position < ruleElements.Count(); position++) { if (string.Compare(ShortID.Parse(ruleElements.ElementAt(position).GetAttributeValue("uid")).ToString(), id, true, CultureInfo.InvariantCulture) == 0) { break; } } return(position); }
/// <summary> /// Gets the target Sitecore Item and spawns a new T object. /// </summary> /// <typeparam name="T">The generic type to return. Must be of type <see cref="Fortis.Model.IItemWrapper"/></typeparam> /// <returns>If the target is not set, returns null, otherwise returns T</returns> public virtual T GetTarget <T>() where T : IItemWrapper { if (string.IsNullOrWhiteSpace(RawValue)) { return(default(T)); } if (ShortID.IsShortID(RawValue)) { return(GetTarget <T>(ShortID.Parse(RawValue).ToID())); } if (ID.IsID(RawValue)) { return(GetTarget <T>(ID.Parse(RawValue))); } return(default(T)); }
/// <summary> /// Gets the target item. /// </summary> /// <returns></returns> public virtual Item GetTarget() { if (string.IsNullOrWhiteSpace(this.RawValue)) { return(null); } if (ShortID.IsShortID(this.RawValue)) { return(this.GetTarget(ShortID.Parse(this.RawValue).ToID())); } if (ID.IsID(this.RawValue)) { return(this.GetTarget(ID.Parse(this.RawValue))); } return(null); }
public static IEnumerable <Guid> ToGuidEnumerable(this IEnumerable ids, bool throwOnBadId = true) { var convertedIds = new List <Guid>(); foreach (var id in ids) { if (id is Guid) { convertedIds.Add((Guid)id); continue; } else { var idString = id.ToString(); Guid idGuid; if (ID.IsID(idString)) { convertedIds.Add(ID.Parse(idString).Guid); continue; } else if (ShortID.IsShortID(idString)) { convertedIds.Add(ShortID.Parse(idString).Guid); continue; } else if (Guid.TryParse(idString, out idGuid)) { convertedIds.Add(idGuid); continue; } } if (throwOnBadId) { throw new Exception("Fortis: Unable to convert enumerable object to Guid"); } } return(convertedIds); }
/// <summary> /// Handles a click on the OK button. /// </summary> /// <param name="sender"/><param name="args"/> /// <remarks> /// When the user clicks OK, the dialog is closed by calling /// the <see cref="M:Sitecore.Web.UI.Sheer.ClientResponse.CloseWindow">CloseWindow</see> method. /// </remarks> /// <contract><requires name="sender" condition="not null"/><requires name="args" condition="not null"/></contract> protected override void OnOK(object sender, EventArgs args) { Assert.ArgumentNotNull(sender, "sender"); Assert.ArgumentNotNull((object)args, "args"); if (!string.IsNullOrEmpty(this.SelectedItemId)) { this.SetDialogResult(ShortID.Parse(this.SelectedItemId).ToID().ToString()); } else { Item selectionItem = this.Treeview.GetSelectionItem(); if (selectionItem != null && this.IsItemRendering(selectionItem)) { this.SetDialogResult(selectionItem.ID.ToString()); } else { SheerResponse.Alert("Please select a rendering item"); } } }
public static IEnumerable <Item> ResolveDatasourceItems(this Database db, string datasource, Item contextItem = null) { if (string.IsNullOrWhiteSpace(datasource)) { return(new Item[0]); } var itemId = ID.IsID(datasource) ? ID.Parse(datasource) : (ShortID.IsShortID(datasource) ? ShortID.Parse(datasource).ToID() : ID.Null); if (!ID.IsNullOrEmpty(itemId)) { var item = db.GetItem(itemId); return(item == null ? new Item[0] : new[] { item }); } string query = null; if (!string.IsNullOrWhiteSpace(datasource) && datasource.StartsWith("query:")) { query = datasource.Substring("query:".Length); } else if (!string.IsNullOrWhiteSpace(datasource) && (datasource.StartsWith("/") || datasource.StartsWith("./") || datasource.StartsWith("../"))) { query = datasource; } if (!string.IsNullOrWhiteSpace(query)) { return(contextItem == null ? db.SelectItems(query) : contextItem.Axes.SelectItems(query)); } return(new Item[0]); }
protected override void OnLoad(EventArgs e) { Assert.ArgumentNotNull(e, "e"); base.OnLoad(e); if (!Context.ClientPage.IsEvent) { this.Mode = WebUtil.GetQueryString(QueryMode); this.InitProperties(); this.DataContext.GetFromQueryString(); this.UploadFrame.SourceUri += string.Format("?type=embed&database={0}", this.DataContext.GetDatabase()); string queryString = WebUtil.GetQueryString(SourceFolder); if (ShortID.IsShortID(queryString)) { queryString = ShortID.Parse(queryString).ToID().ToString(); this.DataContext.Folder = queryString; } var folder = this.DataContext.GetFolder(); Assert.IsNotNull(folder, "Folder not found"); } }
protected void Run(ClientPipelineArgs args) { Assert.ArgumentNotNull((object)args, "args"); parentItemID = args.Parameters["itemid"]; Item itemNotNull = Sitecore.Client.GetItemNotNull(args.Parameters["itemid"], Language.Parse(args.Parameters["language"])); if (args.IsPostBack) { if (!args.HasResult) { return; } string[] strArray = args.Result.Split(new[] { "||" }, StringSplitOptions.None); string id = strArray[0]; string name = Uri.UnescapeDataString(strArray[1]); string displayName = Uri.UnescapeDataString(strArray[2]); string metaTitle = Uri.UnescapeDataString(strArray[3]); if (ShortID.IsShortID(id)) { id = ShortID.Parse(id).ToID().ToString(); } BranchItem branch = Sitecore.Client.ContentDatabase.Branches[id, itemNotNull.Language]; Assert.IsNotNull((object)branch, typeof(BranchItem)); this.ExecuteCommand(itemNotNull, branch, name); Sitecore.Client.Site.Notifications.Disabled = true; Item obj = Context.Workflow.AddItem(name, branch, itemNotNull); Sitecore.Client.Site.Notifications.Disabled = false; if (obj == null) { return; } this.PolicyBasedUnlock(obj); if (!HasPresentationPipeline.Run(obj) || !MainUtil.GetBool(args.Parameters["navigate"], true)) { WebEditCommand.Reload(); } else { UrlOptions defaultOptions = UrlOptions.DefaultOptions; SiteContext site = SiteContext.GetSite(string.IsNullOrEmpty(args.Parameters["sc_pagesite"]) ? Sitecore.Web.WebEditUtil.SiteName : args.Parameters["sc_pagesite"]); if (site == null) { return; } string url = string.Empty; using (new SiteContextSwitcher(site)) { using (new LanguageSwitcher(obj.Language)) url = LinkManager.GetItemUrl(obj, defaultOptions); } WebEditCommand.Reload(new UrlString(url)); SheerResponse.Alert("New page item created."); } HealthIS.Apps.Util.SetDisplayNameAndMetaTitle(obj, displayName, metaTitle); } else if (!itemNotNull.Access.CanCreate()) { SheerResponse.Alert("You do not have permission to create an item here."); } else { UrlString urlString = ResourceUri.Parse("control:CustomAddMasterWebEdit").ToUrlString(); itemNotNull.Uri.AddToUrlString(urlString); SheerResponse.ShowModalDialog(urlString.ToString(), "1200px", "700px", string.Empty, true); args.WaitForPostBack(); } }
public TreeviewRoot GetInitialSource() { if (ID.IsNullOrEmpty(RecommendedRenderingsContext.CurrentItemID)) { return(new TreeviewRoot()); } if (HttpContext.Current.Cache[sourceCacheKey + RecommendedRenderingsContext.CurrentItemID.ToShortID()] != null) { return((TreeviewRoot)HttpContext.Current.Cache[sourceCacheKey + RecommendedRenderingsContext.CurrentItemID.ToShortID()]); } var root = new TreeviewRoot(); var searchResult = SearchService.Search(RecommendedRenderingsContext.CurrentItem, RecommendedRenderingsContext.ContentRootItem, RecommendedRenderingsContext.PlaceholderSettingsRootItem); if (searchResult == null) { return(root); } root.Items.AddRange(searchResult.Renderings.Select(q => RecommendedRenderingsContext.Database.GetItem(ShortID.Parse(q.RenderingID).ToID())).Where(q => q != null).ToList()); HttpContext.Current.Cache.Insert(sourceCacheKey + RecommendedRenderingsContext.CurrentItemID.ToShortID(), root, null, DateTime.Now.AddMinutes(1), Cache.NoSlidingExpiration); return(root); }