HTML Code Showing in Description When Event Exported to Google Calendar

Home Forums Calendar Products Events Calendar PRO HTML Code Showing in Description When Event Exported to Google Calendar

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #944513
    Betty Clark
    Participant

    Hello,

    When I added an event from the Events Calendar to my Google Calendar, HTML code was showing up in the event description (in Google Calendar). I researched your support forum and added the following code to my theme’s functions.php file.

    add_filter( ‘tribe_google_calendar_parameters’, ‘remove_tags_from_gcal_links’ );

    function remove_tags_from_gcal_links( array $params ) {
    $params[‘details’] = urlencode( strip_tags( urldecode( $params[‘details’] ) ) );
    return $params;
    }

    That took care of stripping out most of the HTML code, however, I am still seeing character entities for things like quote marks, apostrophes and ampersands. Is there some additional and/or revised code that I can place in the functions.php file to strip out these character entities? Please help.

    #944703
    George
    Participant

    Hey @knoxannarbor,

    Apologies for the slight delay in response here, this issue took a bit of playing around to resolve. Fortunately, I modified the original code you posted here and was able to get things working as described. Try out this code instead of the original code you posted:

    
    add_filter( 'tribe_google_calendar_parameters', 'remove_tags_from_gcal_links' );
    
    function remove_tags_from_gcal_links( array $params ) {
        $cleaned           = html_entity_decode( strip_tags( apply_filters( 'the_content', urldecode( $params['details'] ) ) ), ENT_QUOTES, 'UTF-8');
        $params['details'] = urlencode( $cleaned );
        
        return $params;
    }
    

    I hope this helps! There are some limitations as far as what can be passed safely as a URL parameter, which is what we have to do here to send the event to Google for importing into a Google Calendar. Let me know how this alternative works.

    Cheers!
    George

    • This reply was modified 9 years, 2 months ago by George.
    #944745
    Betty Clark
    Participant

    Hi George. Thanks for your help. The code you gave me appears to be working – I am no longer seeing html tags or character entity codes. One issue – by stripping out all of the html, the code also strips out any text links. Is there a way to keep all of the html code out, but keep the text links intact?

    Also, when a user clicks on the “+ Google Calendar” button, can we set it up so that the Google Calendar page opens in a new tab?

    Thanks.

    #944935
    George
    Participant

    Hey @knoxannarbor,

    Unfortunately, text links would require the link being surrounded by an <a href=”{link}”> tag, which if not stripped out the Google-imported description wouldn’t render as an inline link, and then if stripped out, like we’re doing here, it won’t get imported in first place….

    So, unfortunately, this seems like an impassable barrier as far as I can think, or unless there’s something specific to Google that would let these links get transferred to descriptions. You could conceivably do something like add a Regular Expression to the code I shared with you here, that looks for <a> tags before stripping out the HTML, and moves the HREF attribute of these tags (i.e. the URL of the link itself) to be next to the link text in parentheses or something along those lines – that’s a bit outside the scope of the support here, but just an idea that might be possible if this is a majorly-important feature for your project.

    As for getting the Calendar export links to open in a new tab, unfortunately the only simple way I can think of doing this would be to modify core plugin files, which is not recommended at all – you’d have to add target=”_blank” to the HTML of the gCal link in the single_event_links() method of the Tribe__Events__iCal class. Another solution that might be possible would be to override the link behavior with JavaScript.

    Let us know if you have any other questions – if not, I’ll go ahead and close up this ticket because the original problem of HTML in the Google Cal descriptions has been resolved. Sorry to disappoint in regards to some of these other customizations you’re seeking to make!

    Best of luck with your project,
    George

    • This reply was modified 9 years, 2 months ago by George.
    • This reply was modified 9 years, 2 months ago by George.
    #944975
    Betty Clark
    Participant

    Thanks for the clarification and for your help!

    #945166
    George
    Participant

    No problem! Thanks for your patience while I worked on the original code edit to the snippet you posted in your first reply – that took me some time to test and such 🙂

    Be sure to keep a backup of the customized code snippet for your site!

    Cheers,
    George

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘HTML Code Showing in Description When Event Exported to Google Calendar’ is closed to new replies.