Sharing flash tagcloud (wpCumulus) integration

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 years ago
thanks steveeb,

any idea about adding this functionality in Blog Tags ?
13 years ago
v1.6, which I'm using, doesn't have BlogTags.

In 1.8:

WARNING:  This should work OK, but I have not run it because I'm using 1.6.  It's to give you an idea of what to do.  You may need to debug it.

Add to ../libraries/nop.businesslogic/content/blog/blogposttag.cs the following

public string Link { get; set; }


Duplicate BlogPopularTags.ascx and all the code-behind.  Rename it BlogPopularFlashTags.ascx

Change BlogPopularFlashTags.ascx.cs

public partial class BlogPopularFlashTagsControl : BaseNopUserControl
    {
        double _mean;
        double _stdDev;
        protected override void OnPreRender(EventArgs e)
        {
            BindData();
            base.OnPreRender(e);
        }

        protected void BindData()
        {
            //get all tags
            int maxItems = 20;
            var blogPostTags = BlogManager.GetAllBlogPostTags(NopContext.Current.WorkingLanguage.LanguageId);
            if (blogPostTags.Count == 0)
            {
                this.Visible = false;
            }
            else
            {
                List<BlogPostTag> cloudItems = new List<BlogPostTag>();
                for (int i = 0; i < blogPostTags.Count; i++)
                {
                    BlogPostTag blogTag = blogPostTags[i];
                    blogTag.Link = CommonHelper.GetStoreLocation() + "blog.aspx?tag=" + blogTag.Name;
                    if (i < maxItems)
                    {
                        cloudItems.Add(blogTag);
                    }
                }
            }
            
        }
      
        ...


And then edit the BlogPopularFlashTags.ascx:

<%@ Control Language="C#" AutoEventWireup="true" Inherits="NopSolutions.NopCommerce.Web.Modules.BlogPopularFlashTagsControl"
    CodeBehind="BlogPopularFlashTags.ascx.cs" %>

<%@ Register assembly="wpCumulus" namespace="wpCumulus" tagprefix="cc1" %>
<div class="block block-popular-blogtags">
    <div class="title">
        <%=GetLocaleResourceString("Blog.TagsCloud.Title")%>
    </div>
    <div class="clear">
    </div>
    <cc1:WPCumulus ID="WPCumulus1" runat="server" DataCountField="BlogPostCount" DataTextField="Name" DataUrlField="Link" Width="189" Height="190" BackColor="#F3F3F3" HiColor="#000000" TagColor1="#B3FF14" TagColor2="#777777"  Distr="True"  />
</div>


You'll obviously have to change the BackColor, HiColor, TagColor1 & 2 to your color scheme.  

Now change your code to point to the new module BlogPopularFlashTags.ascx.
13 years ago
I use TagCloud 3D more simply - change PopularTags.ascx/cs and BlogPopularTags.ascx/cs and add new settings ProductTagsCloud.3D.Enable/Blog.TagsCloud.3D.Enable to switch beetween representation. Also add
ProductTagsCloud.MaxTags
ProductTagsCloud.3D.Width
ProductTagsCloud.3D.Height
ProductTagsCloud.3D.TColor
ProductTagsCloud.3D.TColor2
ProductTagsCloud.3D.HiColor
ProductTagsCloud.3D.TSpeed
ProductTagsCloud.3D.Distr
ProductTagsCloud.3D.WMode
ProductTagsCloud.3D.Mode
for customize.
http://www.beautylib.ru
13 years ago
For you guys that did a rebuild on WPCumulus, did you change the target framework porperty from .Net 3.5 to 4.0 or leave as is?
13 years ago
jnet wrote:
For you guys that did a rebuild on WPCumulus, did you change the target framework porperty from .Net 3.5 to 4.0 or leave as is?


No
13 years ago
steveeb wrote:
v1.6, which I'm using, doesn't have BlogTags.

In 1.8:

WARNING:  This should work OK, but I have not run it because I'm using 1.6.  It's to give you an idea of what to do.  You may need to debug it.

Now change your code to point to the new module BlogPopularFlashTags.ascx.


Hello steveeb, i followed your steps but getting 2 errors when i recompile the solution:

Error  66  The name 'rptrTagCloud' does not exist in the current context  C:\Documents and Settings\Desktop\BlogFlash\NopCommerceStore\Modules\BlogPopularFlashTags.ascx.cs  61  17  NopCommerceStore


Error  67  The name 'rptrTagCloud' does not exist in the current context  C:\Documents and Settings\Desktop\BlogFlash\NopCommerceStore\Modules\BlogPopularFlashTags.ascx.cs  62  17  NopCommerceStore


This is my code and what i did:

1) Added wpCumulus.dll reference (By: right click on NopCommerceStore > Add Reference > Browse > selected wpCumulus.dll

Double check : i see wpCumulus.dll reference in the "Reference Folder" in the solution

2) added code line in "BlogPostTag.cs:

This is the code:



using System;
using System.Collections.Generic;


namespace NopSolutions.NopCommerce.BusinessLogic.Content.Blog
{

    /// <summary>
    /// Represents a product blog tag
    /// </summary>
    public partial class BlogPostTag

    {
        #region Ctor
        /// <summary>
        /// Creates a new instance of the BlogPostTag class
        /// </summary>
        public BlogPostTag()
        {
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets or sets the name
        /// </summary>
        public string Name { get; set; }
        public string Link { get; set; }

        /// <summary>
        /// Gets or sets the tagged product count
        /// </summary>
        public int BlogPostCount { get; set; }
        

        #endregion
    }
}







3) In modules > i added new module, named as " BlogPopularFlashTags.ascx.ascx"

Here is the code:


<%@ Control Language="C#" AutoEventWireup="true" Inherits="NopSolutions.NopCommerce.Web.Modules.BlogPopularFlashTagsControl"
    CodeBehind="BlogPopularFlashTags.ascx.cs" %>

<%@ Register assembly="wpCumulus" namespace="wpCumulus" tagprefix="cc1" %>
<div class="block block-popular-blogtags">
    <div class="title">
        Flash Cloud
    </div>
    <div class="clear">
    </div>
    <cc1:WPCumulus ID="WPCumulus1" runat="server" DataCountField="BlogPostCount" DataTextField="Name" DataUrlField="Link" Width="180" Height="190" BackColor="#F3F3F3" HiColor="#000000" TagColor1="#B3FF14" TagColor2="#777777"  Distr="True"  />
</div>




Here is the BlogPopularFlashTags.ascx.cs code:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using NopSolutions.NopCommerce.BusinessLogic;
using NopSolutions.NopCommerce.BusinessLogic.Content.Blog;
using NopSolutions.NopCommerce.BusinessLogic.SEO;
using NopSolutions.NopCommerce.Common.Utils;
using NopSolutions.NopCommerce.Controls;

namespace NopSolutions.NopCommerce.Web.Modules
{
    public partial class BlogPopularFlashTags : BaseNopUserControl
    {
        double _mean;
        double _stdDev;
        protected override void OnPreRender(EventArgs e)
        {
            BindData();
            base.OnPreRender(e);
        }

        protected void BindData()
        {
            //get all tags
            int maxItems = 15;
            var blogPostTags = BlogManager.GetAllBlogPostTags(NopContext.Current.WorkingLanguage.LanguageId);
            List<BlogPostTag> cloudItems = new List<BlogPostTag>();
            for (int i = 0; i < blogPostTags.Count; i++)
            {
                BlogPostTag blogTag = blogPostTags[i];
                if (i < maxItems)
                {
                    cloudItems.Add(blogTag);
                }
            }

            //calculate weights
            _mean = 0;
            List<double> itemWeights = new List<double>();
            foreach (var blogTag in cloudItems)
            {
                itemWeights.Add(blogTag.BlogPostCount);
            }
            _stdDev = StdDev(itemWeights, out _mean);

            //sorting
            cloudItems.Sort(new BlogTagComparer());

            //binding
            if (cloudItems.Count > 0)
            {
                rptrTagCloud.DataSource = cloudItems;
                rptrTagCloud.DataBind();
            }
            else
                this.Visible = false;
        }

        protected void rptrTagCloud_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                var blogPostTag = e.Item.DataItem as BlogPostTag;
                var hlLink = e.Item.FindControl("hlLink") as HyperLink;
                if (hlLink != null)
                {
                    hlLink.NavigateUrl = SEOHelper.GetBlogUrlForTag(blogPostTag.Name);
                    hlLink.Font.Size = new FontUnit(GetFontSize(blogPostTag.BlogPostCount), UnitType.Percentage);
                }
            }
        }

        protected int GetFontSize(double weight, double mean, double stdDev)
        {
            double factor = (weight - mean);

            if (factor != 0 && stdDev != 0) factor /= stdDev;

            return (factor > 2) ? 150 :
                (factor > 1) ? 120 :
                (factor > 0.5) ? 100 :
                (factor > -0.5) ? 90 :
                (factor > -1) ? 85 :
                (factor > -2) ? 80 :
                75;
        }

        protected int GetFontSize(int blogPostCount)
        {
            int result = GetFontSize(blogPostCount, _mean, _stdDev);
            return result;
        }

        protected double Mean(IEnumerable<double> values)
        {
            double sum = 0;
            int count = 0;

            foreach (double d in values)
            {
                sum += d;
                count++;
            }

            return sum / count;
        }

        protected double StdDev(IEnumerable<double> values, out double mean)
        {
            mean = Mean(values);
            double sumOfDiffSquares = 0;
            int count = 0;

            foreach (double d in values)
            {
                double diff = (d - mean);
                sumOfDiffSquares += diff * diff;
                count++;
            }

            return Math.Sqrt(sumOfDiffSquares / count);
        }

        protected double StdDev(IEnumerable<double> values)
        {
            double mean;
            return StdDev(values, out mean);
        }

        protected class BlogTagComparer : IComparer<BlogPostTag>
        {
            public int Compare(BlogPostTag x, BlogPostTag y)
            {
                if (y == null || String.IsNullOrEmpty(y.Name))
                    return -1;
                if (x == null || String.IsNullOrEmpty(x.Name))
                    return 1;
                return x.Name.CompareTo(y.Name);
            }
        }
    }
}






4) Added flash tag cloud in blog section, this is the code of my Blog.aspx page:

<%@ Page Language="C#" MasterPageFile="~/MasterPages/TwoColumn.master" AutoEventWireup="true"
    Inherits="NopSolutions.NopCommerce.Web.BlogPage" Codebehind="Blog.aspx.cs" %>

<%@ Register TagPrefix="nopCommerce" TagName="Blog" Src="~/Modules/Blog.ascx" %>
<%@ Register TagPrefix="nopCommerce" TagName="BlogMonths" Src="~/Modules/BlogMonths.ascx" %>
<%@ Register TagPrefix="nopCommerce" TagName="BlogPopularTags" Src="~/Modules/BlogPopularTags.ascx" %>
<%@ Register TagPrefix="nopCommerce" TagName="BlogPopularFlashTags" Src="~/Modules/BlogPopularFlashTags.ascx" %>

<asp:Content ID="Content2" ContentPlaceHolderID="cph2" runat="server">
    <nopCommerce:BlogMonths ID="ctrlBlogMonths" runat="server" />
    <div class="clear">
    </div>
    <nopCommerce:BlogPopularTags ID="ctrlBlogPopularTags" runat="server" />
    <div class="clear">
    </div>
    <nopCommerce:BlogPopularFlashTags ID="ctrlBlogPopularFlashTags" runat="server" />
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="cph1" runat="Server">
    <nopCommerce:Blog ID="ctrlBlog" runat="server" />
</asp:Content>



Any help would be appreciated...
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.