Search by

georgringer / news-importicsxml

georgringer

Versatile news import from ICS + XML (local files or remote URLs) including images and category mapping

3.0.0 2018-06-09 16:59 UTC

README

core 13 core 14

This extension provides an import interface for xml and ics files which can either be located on the same server or reached via URL. The import is done by the scheduler.

Requirements

  • TYPO3 CMS 13.4 LTS or 14 LTS
  • EXT:news 13 / 14

Sponsors

Screenshots

Screenshot #1: Creation of an import task

screenshot-task.png

Screenshot #2: Metadata of an imported ICS item

screenshot-import-ics.png

Installation

Installation using Composer

The recommended way to install the extension is by using composer. In your composer based TYPO3 project root, just do composer require georgringer/news-importicsxml.

Installation as extension from TYPO3 Extension Repository (TER)

Download and install the extension with the extension manager module.

Configuration

After installing the extension, switch to the module scheduler and create a new task Execute console commands. Select the command news:importicsxml and fill the arguments:

  • path: Define a local path like fileadmin/data.xml or any URL like https://typo3.org/xml-feeds/rss.xml.
  • pid: Define a page id where the new records will be saved.
  • format: Either xml or ics.
  • slug, cleanBeforeImport, persistAsExternalUrl, email, mapping: Optional, see below.

The same import can be started on the command line: vendor/bin/typo3 news:importicsxml fileadmin/data.xml 42 xml.

Category mapping

A category mapping can be used to add categories to the news records based on categories found in the feed.

A typical feed item can look like this:

	<item>
		<title>A possible title</title>
		<link>http://www.examle.com/feed.xml</link>
		<description>Lorem ipsum</description>
		<content:encoded><![CDATA[A lot of text]]></content:encoded>
		<category>Sports</category>
		<category>Tech</category>
		<category>Information</category>
		<pubDate>Tue, 02 Jun 2015 16:54:00 +0200</pubDate>
	</item>

An ICS entry with a category can look like this:

	BEGIN:VCALENDAR
	PRODID:QIS-LSF HIS eG
	VERSION:2.0
	BEGIN:VTIMEZONE
	TZID:Europe/Berlin
	X-LIC-LOCATION:Europe/Berlin
	BEGIN:DAYLIGHT
	TZOFFSETFROM:+0100
	TZOFFSETTO:+0200
	TZNAME:CEST
	DTSTART:19700329T020000
	RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3
	END:DAYLIGHT
	BEGIN:STANDARD
	TZOFFSETFROM:+0200
	TZOFFSETTO:+0100
	TZNAME:CET
	DTSTART:19701025T030000
	RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
	END:STANDARD
	END:VTIMEZONE
	METHOD:PUBLISH
	BEGIN:VEVENT
	DTSTART;TZID=Europe/Berlin:20171016T141500
	DTEND;TZID=Europe/Berlin:20171016T154500
	RRULE:FREQ=WEEKLY;UNTIL=20171211T235900Z;INTERVAL=2;BYDAY=MO
	EXDATE;TZID=Europe/Berlin:
	LOCATION:C12 - C12 / 024
	DTSTAMP:20180216T113640Z
	UID:52965155936
	DESCRIPTION:
	SUMMARY:MK.1890a - Finite Berechnungsverfahren  Praktikum (A-Zug) (Eufinger)
	CATEGORIES:Praktikum
	END:VEVENT
	END:VCALENDAR

A possible category mapping would look like this:

	5:Sports
	17:Tech
	17:Information

As a result, the imported news record will belong to the categories of the IDs 5 & 17.

Email notification

Add an email address which will get notified after each run.

Important: This feature is not yet implemented!

Persist article with type external page

If set, the news article is saved with the type "External Url".

Further information

Clear the cache after an import

The import writes the records without the DataHandler, therefore TCEMAIN.clearCacheCmd is not evaluated. EXT:news dispatches the event GeorgRinger\News\Event\NewsPostImportEvent once an import has been done. Use it to flush the caches of the pages which show the news, the cache tags of EXT:news are tx_news_pid_<pid> and tx_news_uid_<uid>:

<?php

declare(strict_types=1);

namespace Vendor\MyExtension\EventListener;

use GeorgRinger\News\Event\NewsPostImportEvent;
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Core\Cache\CacheManager;

#[AsEventListener]
final class FlushNewsCacheAfterImport
{
    public function __construct(private readonly CacheManager $cacheManager) {}

    public function __invoke(NewsPostImportEvent $event): void
    {
        $pids = array_unique(array_column($event->getImportData(), 'pid'));
        $this->cacheManager->flushCachesInGroupByTags(
            'pages',
            array_map(static fn ($pid): string => 'tx_news_pid_' . $pid, $pids)
        );
    }
}

Proxy

XML feeds, ICS files and enclosures are fetched with the HTTP client of TYPO3. All settings of $GLOBALS['TYPO3_CONF_VARS']['HTTP'], like proxy (including no), are respected.

Debugging

This extension uses the logging API of TYPO3 CMS. You can find some basic information in the log files (default typo3temp/var/logs/typo3_****.log).

Extending the import

If you need to import additional data from a feed or ics item or you need to modify the data, use the Event Dispatching of the extension news. Most likely, you will need the NewsImportPostHydrateEvent EventListener.

  • Check the documentation of the news extension for a full list of available events: https://docs.typo3.org/p/georgringer/news/main/en-us/Reference/Events/Index.html
  • An example on how to use the NewsImportPostHydrateEvent EventListener is available in ext:eventnews