More in this section

Forums / Developing with Sitefinity / Are there any Adsense modules?

Are there any Adsense modules?

12 posts, 0 answered
  1. Plamen
    Plamen avatar
    3 posts
    Registered:
    26 Feb 2008
    13 Mar 2009
    Link to this post
    Hello, I'm considering using Sitefinity for a blog, but I want to use some Adsense module that will allow me to embed Adsense content within the articles.

    I really want to use Sitefinity, because I'm familiar with Telerik controls and ASP.NET development and I guess it will be easier to modify, but if there is no easy-to-use module for Adsense it'll be a deal-breaker for me. I guess I'll have to go with WordPress if so.

    So, are there any Adsense modules for Sitefinity?

    Best,
    Plamen Petrov
  2. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    13 Mar 2009
    Link to this post
    the blog module (and in fact all modules in sitefinity) allow you to customize their output either by the master list or the individual page. by downloading and linking to the external templates in your client.net account, you can paste in your adsense code either to appear after every post in the post list, or at the bottom or top of the single post page.

    you could also make one or more general user controls with different types of adsense code (such as a tall banner for your sidebar and either drop it on your master page or add it to web.config to drag and drop into individual pages at different locations...

    granted, this isn't exactly the "built-in" solution you're looking for, but it is an example of how open the sitefinity system is to customizations. if you would like more details on a specific method let me know and I'll do what I can to help you get started!
  3. Plamen
    Plamen avatar
    3 posts
    Registered:
    26 Feb 2008
    13 Mar 2009
    Link to this post
    Hello SelArom,

    I'm not much into Sitefinity, so I hardly understand some of the terms you're using. Forgive me if I didn't understand.

    I'm looking for something that allows me to put an ad in the middle of my text with a simple meta keyword like:

    Some text
    <show_inline_adsense>
    Text continues

    You said it'll be easy to put adsense at the top and bottom of my post, but what about functionality like that? I'll have to swap these meta keywords with adsense  within the text of the blog post on redrering , but would I have such a high level of control?

    Thank you,
    Plamen Petrov
  4. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    13 Mar 2009
    Link to this post
    no need to apologize in fact I'm sorry for getting so technical, I didn't pay close enough attention and assumed you were already using sitefinity... so let me give you a quick rundown, and let me know if I go to fast or skip any details!

    sitefinity uses templates to render things like blog posts and post lists. by default, the system uses embedded templates so you don't have to do any configuration out of the box to get started. however if you want to change the layout of your posts, or add customizations, then you can download the templates for the specific area (blog post, post list, etc) and make your changes, and tell the system to point to your template instead of the embedded one...

    that being said, it would be trivial to download the template, add your code to say the bottom or top of a blog post so that it shows up on every post... however if you want to be able to put in code a-la wordpress, it's not so straightforward, but I can try and help you come up with a solution, but will involve programming in asp.net

    the simplest way I can think of is to handle the page_load event and search the blog text for your meta code and replace it with adsense code...

    something like below, where Content is the label that holds the body of your blog. Sitefinity will automatically populate this with your blog text before loading the page, so you can then modify it with your changes afterwards...

    at least I'm pretty sure this is how it works, any one from sitefinity team care to confirm this can be done?

    string const adsensecode = "your code here";

     

    protected void Page_Load(object sender, EventArgs e)
    {
        Content.Text = Content.Text.Replace("[yourmetacode]", adsensecode);
    }










  5. Plamen
    Plamen avatar
    3 posts
    Registered:
    26 Feb 2008
    13 Mar 2009
    Link to this post
    Wow, thank you so much for your comprehensive replies!

    I have no problem with writing some asp.net code, and if its really THAT simple, I'd be sold to sitefinity. I hope that someone could officially confirm this. If not, I'll try it myself as soon as I find the free time to do it.

    Thank you again!

    Best,
    Plamen Petrov
  6. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    16 Mar 2009
    Link to this post
    Hello Plamen,

    We confirm this. The fastest and easier approach would be to create a user control which prints the code on load. You can even expose the code value through a property, in case you have several track codes.
    It is really that simple :)

    Please check this video Adding simple functionality with user controls.

    Let us know if we could be of further help.

    Greetings,
    Georgi
    the Telerik team


    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  7. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    16 Mar 2009
    Link to this post
    awesome, however the problem is that the user wants to be able to inject the adsense code INLINE inside of his posts, not necessarily at a given point on the post. a user control would certainly be the best option to place at head or foot of post,

    however the user wants to be able to type something like [adsense] WITHIN his blog post content, then have this text replaced with adsense code at load time. as far as I can tell, doing a String.Replace (or better yet using Regex to replace) on the page load is the only way I can think of to do this...

    I know a lot of blog engines do this, it might be a good idea to consider exposing this specific part as an event that users can subscribe to something like Content.Loading so that users can handle that event and extend functionality by replacing inline code with other text like adsense, mp3 players, videos, etc
  8. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    17 Mar 2009
    Link to this post
    Hello,

    Okay then, I am going to suggest you 3 ways for injecting the adsense code :)

    1. Event subscription, replacing on Save:
    global.asax
    void Application_Start(object sender, EventArgs e) 
        Telerik.Cms.Engine.ContentManager.Executing += new EventHandler<Telerik.ExecutingEventArgs>(ContentManager_Executing); 
     
    void ContentManager_Executing(object sender, Telerik.ExecutingEventArgs e) 
        Telerik.Cms.Engine.IContent cntItem = e.CommandArguments as Telerik.Cms.Engine.IContent; 
        if (cntItem != null
        { 
            if (e.CommandName.Equals("CreateContent") || e.CommandName.Equals("UpdateContent")) 
            { 
                if (cntItem.ProviderName.Equals("Generic_Content") || 
                    cntItem.ProviderName.Equals("News") || 
                    cntItem.ProviderName.Equals("Blogs")) 
                { 
                    string adSenseCode = "<some_code>"
                    Telerik.Cms.Engine.ContentProviderBase provider = sender as Telerik.Cms.Engine.ContentProviderBase; 
                    cntItem.Content = cntItem.Content.ToString().Replace("[adsense]", adSenseCode); 
                } 
            } 
     
        } 
                 
     

    2. RadEditor content filters.
    The RadEditor supports content filters which can be executed on Save or when the user is changing the modes - Implementing Custom Content Filters

    3. RadEditor snippets - actually I like this approach. You will have a snippet button, allowing you to insert code/text/content to the current cursor position. Here is the example - Code Snippets

    The choice is yours :)

    Kind regards,
    Georgi
    the Telerik team


    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  9. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    17 Mar 2009
    Link to this post
    if i might extend on this, depending on the user needs it might not be a good idea to directly convert the meta code into adsense BEFORE inserting to the database...

    the idea is to capture the output before it is RENDERED on the page. this way, if the adsense code changes for whatever reason (change colors, size, or even a different advertising provider) you would change the output code that is replaced at that time, instead of going into your post and changing the saved text.

    i hope that makes sense
  10. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    17 Mar 2009
    Link to this post
    Hi,

    It is getting more and more interesting. If you want to change just the rendered code, you could override the page Render event :)

    1. Create a new class HtmlTweak.cs in the App_Code directory:
    HtmlTweak.cs:
    using System; 
    using System.Data; 
    using System.Configuration; 
    using System.Linq; 
    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 System.Xml.Linq; 
    using Telerik.Cms.Web; 
    using System.IO; 
     
    /// <summary> 
    /// Summary description for HtmlTweak 
    /// </summary> 
    namespace Telerik.Samples 
        public class HtmlTweak : InternalPage 
        { 
            public HtmlTweak() 
            { 
                // 
                // TODO: Add constructor logic here 
                // 
            } 
            protected override void Render(HtmlTextWriter writer) 
            { 
                HtmlTextWriter output = new HtmlTextWriter(new StringWriter()); 
                base.Render(output); 
                string outputString = output.InnerWriter.ToString().Replace("[adsense]""[helloAdSenseCode]"); 
                writer.Write(outputString); 
            } 
        } 

    2. Open the file cmsentrypoint.aspx located in \[YourProject]\Sitefinity\ directory, and make sure it inherits the HtmlTweak class:
    <%@ Page Inherits="Telerik.Samples.HtmlTweak" MasterPageFile="~/Sitefinity/Dummy.master" %> 

    That said, if there is any [adsense] metacode in the page (anywhere, not just in the Generic Content based modules content), it will be replaced with [helloAdSenseCode].

    What do you think?

    Greetings,
    Georgi
    the Telerik team


    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  11. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    17 Mar 2009
    Link to this post
    i like that this gives you a more global approach so you can do this for any content, very cool. this is almost what I was trying to go for...

    but I still think this would be best specialized with a public event for each content (and maybe a global one like this too!) so that extending things like blogs, events, etc can be handled individually and specifically, and we can add unlimited modular extensions just by hooking additional handlers to the event

    like (forgive the bad pseudocode)
    blogpost.render += new EventHandler(renderMp3player);  
    if (!user.loggedin) // only show ads to non registered members  
        blogpost.render += new EventHandler(renderAdsense);  
    newsitem.render += new EventHandler(outlookReminder); 


    stuff like that you know? then each of these individual handlers could be created and maintained separately...
  12. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    18 Mar 2009
    Link to this post
    Hi SelArom,

    We have plans to implement more events in the managers dealing with the content and the pages. Then, this will be completely possible.

    You can still override the NewsView and the rest of the controls, and to replace the such metacode on the fly when the page is loading, but I do not think this is a good approach.

    Best wishes,
    Georgi
    the Telerik team


    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Register for webinar
12 posts, 0 answered