示例#1
0
 public void DisplayChildren(Sitecore.Data.Items.Item parent)
 {
     //string iconName = parent.Appearance.Icon.ToLower();
     Sitecore.Layouts.LayoutDefinition layout = Sitecore.Layouts.LayoutDefinition.Parse(parent[Sitecore.FieldIDs.LayoutField]);
     if (layout != null && parent[Sitecore.FieldIDs.LayoutField].Length > 0)//(iconName.Contains("document") || iconName.Contains("folder")) && !iconName.Contains("Resources"))
     {
         Sitecore.Links.UrlOptions options = new Sitecore.Links.UrlOptions();
         options.AlwaysIncludeServerUrl = true;
         string href = Sitecore.Links.LinkManager.GetItemUrl(parent, options);
         litTree.Text += "<li><b><a href=" + href + " target='_blank'>" + parent.Name + "</a></b><br/>" + href + "<br/>Status code: " + GetHttpStatus(href);
         udpTree.Update();
         if (parent.HasChildren)
         {
             bool closeIt = false;
             bool opened  = false;
             foreach (Sitecore.Data.Items.Item child in parent.Children)
             {
                 if (!child.Name.Contains("Resources"))
                 {
                     if (!opened)
                     {
                         litTree.Text += "<ul>"; opened = true;
                     }
                     DisplayChildren(child);
                     closeIt = true;
                 }
             }
             if (closeIt)
             {
                 litTree.Text += "</ul>";
             }
         }
         litTree.Text += "</li>";
     }
 }
        public string DisplayChildren(Sitecore.Data.Items.Item parent)
        {
            string content  = "";
            string iconName = parent.Appearance.Icon.ToLower();

            Sitecore.Layouts.LayoutDefinition layout = Sitecore.Layouts.LayoutDefinition.Parse(parent[Sitecore.FieldIDs.LayoutField]);
            if (layout != null && parent[Sitecore.FieldIDs.LayoutField].Length > 0)
            {
                Sitecore.Links.UrlOptions options = new Sitecore.Links.UrlOptions();
                options.AlwaysIncludeServerUrl = true;
                string loc     = Sitecore.Links.LinkManager.GetItemUrl(parent, options);
                string lastMod = parent.Statistics.Updated.ToLongDateString();
                content += "\n\t<url>\n\t\t<loc>" + loc + "</loc>\n\t\t<lastmod>" + lastMod + "</lastmod>\n\t</url>";
                if (parent.HasChildren)
                {
                    string childContent = "";
                    foreach (Sitecore.Data.Items.Item child in parent.Children)
                    {
                        if (!child.Name.Contains("Resources"))
                        {
                            childContent += DisplayChildren(child);
                        }
                    }
                    if (!string.IsNullOrEmpty(childContent))
                    {
                        content += childContent;
                    }
                }
            }
            return(content);
        }
示例#3
0
        public ActionResult FacultyDirectoryCorporateProfile()
        {
            FacultyDirectoryCorporateProfile facultyProfile = new FacultyDirectoryCorporateProfile();

            facultyProfile.rendering = Sitecore.Mvc.Presentation.RenderingContext.CurrentOrNull.Rendering;
            facultyProfile.pageItem  = PageContext.Current.Item;
            facultyProfile.showError = "";

            try
            {
                // Set datasource if it is empty
                if (String.IsNullOrEmpty(facultyProfile.rendering.DataSource))
                {
                    using (new Sitecore.SecurityModel.SecurityDisabler())
                    {
                        //Get current rendering item
                        Sitecore.Layouts.RenderingReference[] renderings = facultyProfile.pageItem.Visualization.GetRenderings(Sitecore.Context.Device, true).Where(r => r.RenderingID == facultyProfile.rendering.RenderingItem.ID).ToArray();

                        // Get the layout definitions and the device
                        Sitecore.Data.Fields.LayoutField  layoutField      = new Sitecore.Data.Fields.LayoutField(facultyProfile.pageItem.Fields[Sitecore.FieldIDs.FinalLayoutField]);
                        Sitecore.Layouts.LayoutDefinition layoutDefinition = Sitecore.Layouts.LayoutDefinition.Parse(layoutField.Value);
                        Sitecore.Layouts.DeviceDefinition deviceDefinition = layoutDefinition.GetDevice(Sitecore.Context.Device.ID.ToString());
                        foreach (Sitecore.Layouts.RenderingReference rendering in renderings)
                        {
                            // Update the renderings datasource value as current item path
                            deviceDefinition.GetRendering(rendering.RenderingID.ToString()).Datasource = facultyProfile.pageItem.ID.ToString();
                            // Save the layout changes
                            facultyProfile.pageItem.Editing.BeginEdit();
                            layoutField.Value = layoutDefinition.ToXml();
                            facultyProfile.pageItem.Editing.EndEdit();
                        }
                    }
                }

                Sitecore.Marketing.Wildcards.WildcardTokenizedString wts    = Sitecore.Marketing.Wildcards.WildcardManager.Provider.GetWildcardUrl(facultyProfile.PageItem, Sitecore.Context.Site);
                System.Collections.Specialized.NameValueCollection   tokens = wts.FindTokenValues(Request.Path.ToLower().Replace(' ', '-'));
                facultyProfile.strPID = tokens["%Person_ID%"];
                if (facultyProfile.strPID != null)
                {
                    facultyProfile.validId = Int32.TryParse(facultyProfile.strPID, out facultyProfile.personID);
                }
                if (facultyProfile.validId && !Sitecore.Context.PageMode.IsExperienceEditorEditing)
                {
                    facultyProfile.person = new HealthIS.Apps.FacultyDirectory.Profile(facultyProfile.personID, HealthIS.Apps.FacultyDirectory.Profile.ProfileType.Research, HealthIS.Apps.FacultyDirectory.Profile.ProfileParts.All);
                }
            }
            catch (Exception ex)
            {
                facultyProfile.showError = "Sorry for the inconvenience.<br />We&rsquo;re performing some maintenance at the moment.";
                Sitecore.Diagnostics.Log.SingleWarn("Error from faculty profile page at " + Request.Url.Host + " - " + ex.Message, this);
                facultyProfile.person = null;
            }
            return(PartialView(facultyProfile));
        }
        public override void Relink(
            SC.Links.ItemLink itemLink,
            SC.Data.Items.Item newLink)
        {
            SC.Diagnostics.Assert.ArgumentNotNull(itemLink, "itemLink");
            SC.Diagnostics.Assert.ArgumentNotNull(newLink, "newLink");
            base.Relink(itemLink, newLink);
            string xml = this.Value;

            if (String.IsNullOrEmpty(xml))
            {
                return;
            }

            SC.Layouts.LayoutDefinition layoutDetails =
                SC.Layouts.LayoutDefinition.Parse(xml);
            ArrayList devices = layoutDetails.Devices;

            if (devices == null)
            {
                return;
            }

            foreach (SC.Layouts.DeviceDefinition device in devices)
            {
                if (device == null || device.Renderings == null)
                {
                    continue;
                }

                foreach (SC.Layouts.RenderingDefinition rendering in device.Renderings)
                {
                    if (!String.IsNullOrEmpty(rendering.Datasource) &&
                        (rendering.Datasource.Equals(itemLink.TargetPath, StringComparison.InvariantCultureIgnoreCase) ||
                         rendering.Datasource.Equals(itemLink.TargetItemID.ToString(), StringComparison.InvariantCultureIgnoreCase)))
                    {
                        rendering.Datasource = newLink.ID.ToString();
                    }
                }
            }

            this.Value = layoutDetails.ToXml();
        }
        public override void Apply(T ruleContext)
        {
            SC.Diagnostics.Assert.ArgumentNotNull(ruleContext, "ruleContext");
            SC.Diagnostics.Assert.ArgumentNotNull(
                ruleContext.Item,
                "ruleContext.Item");
            SC.Data.Fields.LayoutField layoutDetails =
                ruleContext.Item.Fields[SC.FieldIDs.LayoutField];
            SC.Diagnostics.Assert.IsNotNull(layoutDetails, "layoutDetails");

            if (String.IsNullOrEmpty(layoutDetails.Value) ||
                layoutDetails.InnerField.ContainsStandardValue)
            {
                return;
            }

            SC.Layouts.LayoutDefinition layout =
                SC.Layouts.LayoutDefinition.Parse(layoutDetails.Value);
            bool modified = false;

            for (int i = 0; i < layout.Devices.Count; i++)
            {
                SC.Layouts.DeviceDefinition device =
                    layout.Devices[i] as SC.Layouts.DeviceDefinition;
                SC.Diagnostics.Assert.IsNotNull(device, "device");

                for (int j = 0; j < device.Renderings.Count; j++)
                {
                    SC.Layouts.RenderingDefinition rendering =
                        device.Renderings[j] as SC.Layouts.RenderingDefinition;
                    SC.Diagnostics.Assert.IsNotNull(rendering, "rendering");

                    if (String.IsNullOrEmpty(rendering.Datasource) ||
                        !rendering.Datasource.StartsWith("/"))
                    {
                        continue;
                    }

                    SC.Data.Items.Item dataSource =
                        ruleContext.Item.Database.GetItem(rendering.Datasource);

                    if (dataSource == null)
                    {
                        string msg = this
                                     + " : unable to retrieve data source item "
                                     + rendering.Datasource
                                     + " in "
                                     + ruleContext.Item.Paths.FullPath;
                        SC.Diagnostics.Log.Warn(msg, this);
                        continue;
                    }

                    rendering.Datasource = dataSource.ID.ToString();
                    modified             = true;
                }
            }

            if (modified)
            {
                using (new SC.Data.Items.EditContext(ruleContext.Item, false, false))
                {
                    layoutDetails.Value = layout.ToXml();
                }
            }
        }