Beispiel #1
0
        /// <summary>
        /// Gets the field content from database instead of the published XML via the APIs.
        /// </summary>
        /// <param name="nodeIdInt">The node id.</param>
        /// <param name="currentField">The field that should be fetched.</param>
        /// <returns>The contents of the <paramref name="currentField"/> from the <paramref name="nodeIdInt"/> content object</returns>
        protected virtual string GetContentFromDatabase(AttributeCollectionAdapter itemAttributes, int nodeIdInt, string currentField)
        {
            Content c = new Content(nodeIdInt);

            Property property = c.getProperty(currentField);

            if (property == null)
            {
                throw new ArgumentException(String.Format("Could not find property {0} of node {1}.", currentField, nodeIdInt));
            }

            item   umbItem            = new item(property.Value.ToString(), itemAttributes);
            string tempElementContent = umbItem.FieldContent;

            // If the current content object is a document object, we'll only output it if it's published
            if (c.nodeObjectType == cms.businesslogic.web.Document._objectType)
            {
                try
                {
                    Document d = (Document)c;
                    if (!d.Published)
                    {
                        tempElementContent = "";
                    }
                }
                catch { }
            }

            // Add the content to the cache
            if (!String.IsNullOrEmpty(tempElementContent))
            {
                HttpContext.Current.Cache.Insert(String.Format("contentItem{0}_{1}", nodeIdInt.ToString(), currentField), tempElementContent);
            }
            return(tempElementContent);
        }
Beispiel #2
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Init"/> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs"/> object that contains the event data.</param>
        protected override void OnInit(EventArgs e)
        {
            Attributes.Add("field", Field);
            LegacyAttributes = new AttributeCollectionAdapter(Attributes);
            Renderer.Init(this);

            base.OnInit(e);
        }
        protected virtual string GetContentFromDatabase(AttributeCollectionAdapter itemAttributes, int nodeIdInt, string currentField)
        {
            var c = new Content(nodeIdInt);

            var property = c.getProperty(currentField);

            if (property == null)
            {
                throw new ArgumentException(String.Format("Could not find property {0} of node {1}.", currentField, nodeIdInt));
            }

            var umbItem            = new item(property.Value.ToString(), itemAttributes);
            var tempElementContent = umbItem.FieldContent;

            // If the current content object is a document object, we'll only output it if it's published
            if (c.nodeObjectType == Document._objectType)
            {
                try
                {
                    var d = (Document)c;
                    if (!d.Published)
                    {
                        tempElementContent = "";
                    }
                }
                catch { }
            }

            // Add the content to the cache
            if (!string.IsNullOrEmpty(tempElementContent))
            {
                ApplicationContext.Current.ApplicationCache.RuntimeCache.InsertCacheItem(
                    string.Format("{0}{1}_{2}", CacheKeys.ContentItemCacheKey, nodeIdInt, currentField),
                    priority:       CacheItemPriority.Default,
                    getCacheItem:   () => tempElementContent);
            }
            return(tempElementContent);
        }
        /// <summary>
        /// Renders an field to the template
        /// </summary>
        /// <param name="currentPage"></param>
        /// <param name="fieldAlias"></param>
        /// <param name="altFieldAlias"></param>
        /// <param name="altText"></param>
        /// <param name="insertBefore"></param>
        /// <param name="insertAfter"></param>
        /// <param name="recursive"></param>
        /// <param name="convertLineBreaks"></param>
        /// <param name="removeParagraphTags"></param>
        /// <param name="casing"></param>
        /// <param name="encoding"></param>
        /// <param name="formatAsDate"></param>
        /// <param name="formatAsDateWithTime"></param>
        /// <param name="formatAsDateWithTimeSeparator"></param>
        //// <param name="formatString"></param>
        /// <returns></returns>
        public IHtmlString Field(IPublishedContent currentPage, string fieldAlias,
                                 string altFieldAlias                 = "", string altText            = "", string insertBefore = "", string insertAfter = "",
                                 bool recursive                       = false, bool convertLineBreaks = false, bool removeParagraphTags = false,
                                 RenderFieldCaseType casing           = RenderFieldCaseType.Unchanged,
                                 RenderFieldEncodingType encoding     = RenderFieldEncodingType.Unchanged,
                                 bool formatAsDate                    = false,
                                 bool formatAsDateWithTime            = false,
                                 string formatAsDateWithTimeSeparator = "")

        //TODO: commented out until as it is not implemented by umbraco:item yet
        //,string formatString = "")
        {
            Mandate.ParameterNotNull(currentPage, "currentPage");
            Mandate.ParameterNotNullOrEmpty(fieldAlias, "fieldAlias");

            //TODO: This is real nasty and we should re-write the 'item' and 'ItemRenderer' class but si fine for now

            var attributes = new Dictionary <string, string>
            {
                { "field", fieldAlias },
                { "recursive", recursive.ToString().ToLowerInvariant() },
                { "useifempty", altFieldAlias },
                { "textifempty", altText },
                { "stripparagraph", removeParagraphTags.ToString().ToLowerInvariant() },
                {
                    "case", casing == RenderFieldCaseType.Lower ? "lower"
                                                                : casing == RenderFieldCaseType.Upper ? "upper"
                                                                        : casing == RenderFieldCaseType.Title ? "title"
                                                                                : string.Empty
                },
                { "inserttextbefore", insertBefore },
                { "inserttextafter", insertAfter },
                { "convertlinebreaks", convertLineBreaks.ToString().ToLowerInvariant() },
                { "formatasdate", formatAsDate.ToString().ToLowerInvariant() },
                { "formatasdatewithtime", formatAsDateWithTime.ToString().ToLowerInvariant() },
                { "formatasdatewithtimeseparator", formatAsDateWithTimeSeparator }
            };

            switch (encoding)
            {
            case RenderFieldEncodingType.Url:
                attributes.Add("urlencode", "true");
                break;

            case RenderFieldEncodingType.Html:
                attributes.Add("htmlencode", "true");
                break;

            case RenderFieldEncodingType.Unchanged:
            default:
                break;
            }

            //need to convert our dictionary over to this weird dictionary type
            var attributesForItem = new AttributeCollectionAdapter(
                new AttributeCollection(
                    new StateBag()));

            foreach (var i in attributes)
            {
                attributesForItem.Add(i.Key, i.Value);
            }



            var item = new Item(currentPage)
            {
                Field            = fieldAlias,
                TextIfEmpty      = altText,
                LegacyAttributes = attributesForItem
            };

            //here we are going to check if we are in the context of an Umbraco routed page, if we are we
            //will leave the NodeId empty since the underlying ItemRenderer will work ever so slightly faster
            //since it already knows about the current page. Otherwise, we'll assign the id based on our
            //currently assigned node. The PublishedContentRequest will be null if:
            // * we are rendering a partial view or child action
            // * we are rendering a view from a custom route
            if ((_umbracoContext.PublishedContentRequest == null ||
                 _umbracoContext.PublishedContentRequest.PublishedContent.Id != currentPage.Id) &&
                currentPage.Id > 0)    // in case we're rendering a detached content (id == 0)
            {
                item.NodeId = currentPage.Id.ToString(CultureInfo.InvariantCulture);
            }


            var containerPage = new FormlessPage();

            containerPage.Controls.Add(item);

            using (var output = new StringWriter())
                using (var htmlWriter = new HtmlTextWriter(output))
                {
                    ItemRenderer.Instance.Init(item);
                    ItemRenderer.Instance.Load(item);
                    ItemRenderer.Instance.Render(item, htmlWriter);

                    //because we are rendering the output through the legacy Item (webforms) stuff, the {localLinks} will already be replaced.
                    return(new HtmlString(output.ToString()));
                }
        }
Beispiel #5
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Init"/> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs"/> object that contains the event data.</param>
        protected override void OnInit(EventArgs e)
        {
            Attributes.Add("field", Field);
            LegacyAttributes = new AttributeCollectionAdapter(Attributes);
            Renderer.Init(this);

            base.OnInit(e);
        }  
Beispiel #6
0
        protected virtual string GetContentFromDatabase(AttributeCollectionAdapter itemAttributes, int nodeIdInt, string currentField)
        {
            var c = new Content(nodeIdInt);

            var property = c.getProperty(currentField);
            if (property == null)
                throw new ArgumentException(String.Format("Could not find property {0} of node {1}.", currentField, nodeIdInt));

            var umbItem = new item(property.Value.ToString(), itemAttributes);
            var tempElementContent = umbItem.FieldContent;

            // If the current content object is a document object, we'll only output it if it's published
            if (c.nodeObjectType == Document._objectType)
            {
                try
                {
                    var d = (Document)c;
                    if (!d.Published)
                        tempElementContent = "";
                }
                catch { }
            }

            // Add the content to the cache
            if (!string.IsNullOrEmpty(tempElementContent))
            {
                ApplicationContext.Current.ApplicationCache.InsertCacheItem(
                    string.Format("{0}{1}_{2}", CacheKeys.ContentItemCacheKey, nodeIdInt, currentField),
                    CacheItemPriority.Default, () => tempElementContent);
            }
            return tempElementContent;
        }
		/// <summary>
		/// Gets the field content from database instead of the published XML via the APIs.
		/// </summary>
		/// <param name="nodeIdInt">The node id.</param>
		/// <param name="currentField">The field that should be fetched.</param>
		/// <returns>The contents of the <paramref name="currentField"/> from the <paramref name="nodeIdInt"/> content object</returns>
        protected virtual string GetContentFromDatabase(AttributeCollectionAdapter itemAttributes, int nodeIdInt, string currentField)
		{
			Content c = new Content(nodeIdInt);

			Property property = c.getProperty(currentField);
			if (property == null)
				throw new ArgumentException(String.Format("Could not find property {0} of node {1}.", currentField, nodeIdInt));

			item umbItem = new item(property.Value.ToString(), itemAttributes);
			string tempElementContent = umbItem.FieldContent;

			// If the current content object is a document object, we'll only output it if it's published
			if (c.nodeObjectType == cms.businesslogic.web.Document._objectType)
			{
				try
				{
					Document d = (Document)c;
					if (!d.Published)
						tempElementContent = "";
				}
				catch { }
			}

			// Add the content to the cache
			if (!String.IsNullOrEmpty(tempElementContent))
				HttpContext.Current.Cache.Insert(String.Format("contentItem{0}_{1}", nodeIdInt.ToString(), currentField), tempElementContent);
			return tempElementContent;
		}
Beispiel #8
0
        /// <summary>
        /// Renders an field to the template
        /// </summary>
        /// <param name="currentPage"></param>
        /// <param name="fieldAlias"></param>
        /// <param name="altFieldAlias"></param>
        /// <param name="altText"></param>
        /// <param name="insertBefore"></param>
        /// <param name="insertAfter"></param>
        /// <param name="recursive"></param>
        /// <param name="convertLineBreaks"></param>
        /// <param name="removeParagraphTags"></param>
        /// <param name="casing"></param>
        /// <param name="encoding"></param>
        /// <param name="formatAsDate"></param>
        /// <param name="formatAsDateWithTime"></param>
        /// <param name="formatAsDateWithTimeSeparator"></param>
        //// <param name="formatString"></param>
        /// <returns></returns>
        public IHtmlString Field(IPublishedContent currentPage, string fieldAlias,
                                 string altFieldAlias                 = "", string altText            = "", string insertBefore = "", string insertAfter = "",
                                 bool recursive                       = false, bool convertLineBreaks = false, bool removeParagraphTags = false,
                                 RenderFieldCaseType casing           = RenderFieldCaseType.Unchanged,
                                 RenderFieldEncodingType encoding     = RenderFieldEncodingType.Unchanged,
                                 bool formatAsDate                    = false,
                                 bool formatAsDateWithTime            = false,
                                 string formatAsDateWithTimeSeparator = "")

        //TODO: commented out until as it is not implemented by umbraco:item yet
        //,string formatString = "")
        {
            Mandate.ParameterNotNull(currentPage, "currentPage");
            Mandate.ParameterNotNullOrEmpty(fieldAlias, "fieldAlias");

            //TODO: This is real nasty and we should re-write the 'item' and 'ItemRenderer' class but si fine for now

            var attributes = new Dictionary <string, string>
            {
                { "field", fieldAlias },
                { "recursive", recursive.ToString().ToLowerInvariant() },
                { "useifempty", altFieldAlias },
                { "textifempty", altText },
                { "stripparagraph", removeParagraphTags.ToString().ToLowerInvariant() },
                {
                    "case", casing == RenderFieldCaseType.Lower ? "lower"
                                                                : casing == RenderFieldCaseType.Upper ? "upper"
                                                                        : casing == RenderFieldCaseType.Title ? "title"
                                                                                : string.Empty
                },
                { "inserttextbefore", insertBefore },
                { "inserttextafter", insertAfter },
                { "convertlinebreaks", convertLineBreaks.ToString().ToLowerInvariant() },
                { "formatasdate", formatAsDate.ToString().ToLowerInvariant() },
                { "formatasdatewithtime", formatAsDateWithTime.ToString().ToLowerInvariant() },
                { "formatasdatewithtimeseparator", formatAsDateWithTimeSeparator }
            };

            switch (encoding)
            {
            case RenderFieldEncodingType.Url:
                attributes.Add("urlencode", "true");
                break;

            case RenderFieldEncodingType.Html:
                attributes.Add("htmlencode", "true");
                break;

            case RenderFieldEncodingType.Unchanged:
            default:
                break;
            }

            //need to convert our dictionary over to this weird dictionary type
            var attributesForItem = new AttributeCollectionAdapter(
                new AttributeCollection(
                    new StateBag()));

            foreach (var i in attributes)
            {
                attributesForItem.Add(i.Key, i.Value);
            }



            var item = new Item()
            {
                //NodeId = currentPage.Id.ToString();
                Field            = fieldAlias,
                TextIfEmpty      = altText,
                LegacyAttributes = attributesForItem
            };

            //this is here to figure out if this request is in the context of a partial
            if (_umbracoContext.PublishedContentRequest.PublishedContent.Id != _currentPage.Id)
            {
                item.NodeId = _currentPage.Id.ToString();
            }


            var containerPage = new FormlessPage();

            containerPage.Controls.Add(item);

            using (var output = new StringWriter())
                using (var htmlWriter = new HtmlTextWriter(output))
                {
                    ItemRenderer.Instance.Init(item);
                    ItemRenderer.Instance.Load(item);
                    ItemRenderer.Instance.Render(item, htmlWriter);

                    //because we are rendering the output through the legacy Item (webforms) stuff, the {localLinks} will already be replaced.
                    return(new HtmlString(output.ToString()));
                }
        }