Forum

Thread tagged as: Question, Addons, Events

Automatically sharing new pages with Facebook

Hi.

Is it possible to automatically share a new content, in my case an event, with Facebook and/or Twitter? Even if I could only generate an email with the event details and handle it with IFTTT this would be enough to be able to sync new events with Facebook.

Thanks in advance.

Mike Knowles

Mike Knowles 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Could you do that with an RSS feed? That would be easy to generate.

Ah. Now that's a thought!

I'll give it a go...

Ta!

I finally got round to doing this and I thought I would share the very basic code I've used.

First I create a simple Perch template:

/perch/templates/events/rss/rss.html
    <item>
        <title><perch:events id="eventDateTime" format="%A %B %d %Y" /> @ <perch:events id="eventDateTime" format="%I:%M%p" /> | <perch:events id="eventTitle" /></title>
        <description><perch:events id="eventDescRaw" encode="false" /></description>
        <link>https://www.gtrbl.org.uk<perch:events id="eventURL" /></link>
        <category><perch:events id="category_names" /></category>
    </item>
<perch:after>        

</perch:after>

I then created a simple RSS PHP script in the root folder:

<?php include('perch/runtime.php'); ?>
<?php
    header("Content-Type: application/rss+xml; charset=ISO-8859-1");
    echo '<?xml version="1.0" encoding="ISO-8859-1" ?>';
?>
<rss version="2.0">
<channel>
    <title>GTRBL RSS feed</title>
    <link>https://www.gtrbl.org.uk</link>
    <description>This feed contains details of our upcoming events</description>
    <language>en-gb</language>
    <copyright>Copyright (C) <?php echo date("Y"); ?> gtrbl.org.uk</copyright>
<?php 
    $opts_events_rss = array( 
        'filter'=>'eventDateTime',
        'match'=>'gte',
        'value'=>date('Y-m-d H:i:s'), 
        'template'=>'events/rss/rss.html',
        'sort-order'=>'desc'
    );

    $result = perch_events_custom($opts_events_rss, true);

    if (strlen($result) > 0) {
        echo $result;
    } else {
        // No events to show
    }
?>
</channel>
</rss>

That's the RSS feed done. The only thing I need to work out is the pubDate element in the <item /> node. I can't see that there is a built in template field for the date the event was added to the database?

One thing I had forgotten was a <![CDATA[ ]]> instruction around the description:

<description><![CDATA[<perch:events id="eventDescRaw" encode="false" />]]></description>

With that in place it shouldn't bork the feed when there are cr/lf pairs in the field output.

Hi Mike,

Thanks for sharing your code sample. I'll be trying it out for our event calendar.