iCal import: Hot hyperlinks in description

WordPress Event Management, Calendars & Registration Forums iCal Extension iCal import: Hot hyperlinks in description

This topic contains 6 replies, has 2 voices, and was last updated by  Stephen Harris 3 months, 2 weeks ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #26447

    Is there a way to get hyperlinks that are written in event descriptions to display hot?

    In the description fields of iCal events that I am importing into EO using the iCal URL feed, I have written links to different sites associated with the event (let’s say a description included a link to https://www.sxsw.com/, for example). When the iCal file is parsed and displayed in my event list, the text for the hyperlink stays, but the link is no longer hot.

    I am guessing that the solution would be in the iCal parser PHP file, but wanted to check with you to see what that line of code would be to restore the hyperlink.

    Much appreciated :)

    Chad Green
    #26448

    Hi Chad,

    Do you have a link to the feed you are importing?

    Stephen Harris
    #26478

    Yes: Feed

    Chad Green
    #26489

    Hi Chad,

    That feed doesn’t contain any links, only URLs. You could make those URLs clickable with the code below, but as for any links with non-URL text, I’m afraid the links are just not in the feed.

    /**
     * Convert an URLs in $value to hyperlinks.
     */
    function linkify($value)
    {
    
        $links = array();
    
        // Extract existing links and tags
        $value = preg_replace_callback('~(.*?|<.*?>)~i', function ($match) use (&$links) { 
            return '<' . array_push($links, $match[1]) . '>'; 
        }, $value);
    
        $value = preg_replace_callback(
            '~(?:(https?)://([^\s<]+)|(www\.[^\s<]+?\.[^\s<]+))(?<![\.,:])~i', 
            function ($match) use (&$links) { 
                $protocol = $match[1] ? $match[1] : 'http';
                $link = $match[2] ?: $match[3]; 
                return '<' . array_push($links, "$protocol://$link") . '>'; 
            },
            $value
        );
    
        // Insert all link
        return preg_replace_callback('/<(\d+)>/', function ($match) use (&$links) { 
            return $links[$match[1] - 1]; 
        }, $value);
    }
    
    add_action( 'eventorganiser_ical_property_description', function($content, $modifiers, $ical_parser ){
        $ical_parser->current_event['post_content'] = linkify( $content );
    }, 10, 3 );
    
    Stephen Harris
    #26493

    Thanks Stephen,

    You know, this code will solve my problem. I had not described my problem correctly. I was looking to make URLs in the description clickable. My mistake, but you picked up on it!

    Much appreciated.

    Chad Green
    #26523

    Where should this code live? I tried inserting it into a couple of different “functions” files one at a time, but had not seen the results after I had refreshed the feed.

    Chad Green
    #26532

    Preferably in your own custom plugin but your theme’s functions.php should do.

    Stephen Harris
Viewing 7 posts - 1 through 7 (of 7 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.