Joomla - Auto Create Joomla Articles from Text Files RSS Text File

Revision as of 16:15, 18 December 2019 by Ardaut (talk | changes) (File /var/www/WEBSITE_JOOMLA/administrator/createarticle_news_bottom.php)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

You can create with this script Joomla articles automatically (through e.g.: a cronjob) from saved RSS feed entries. Please use the program rsstail to save rss feed entries as a txt file.

Shell script to create joomla article -


#Load RSS Feed entry ***
su ran -c "rsstail -N -d -P -z -n 1 -u https://RSS_NEWS_WEBSITE/feed.xml > /home/USER/rssnews_news_content.txt &"
sleep 10
pkill rsstail
sed -i '1d' /home/USER/rssnews_news_content.txt
su ran -c "rsstail -N -z -P -n 1 -u https://RSS_NEWS_WEBSITE/feed.xml > /home/USER/rssnews_news_titel.txt &"
sleep 13
pkill rsstail
#su ran -c "rsstail -N -l -z -P -n 1 -u https://RSS_NEWS_WEBSITE/feed.xml > /home/USER/rssnews_news_link.txt &"
#sleep 19
#pkill rsstail
sed -i '1d' /home/USER/rssnews_news_link.txt

sed -i 's/(...)/./' /home/USER/rssnews_news_content.txt
#replace problematic char
sed -i "s/'/´/g" /home/USER/rssnews_news_content.txt

cat /var/www/WEBSITE_JOOMLA/administrator/createarticle_news_header.php > /var/www/WEBSITE_JOOMLA/administrator/artikelerstellen_news.php

# Pattern TITELTITEL... Replace article with title from feed
sed -i -e "s/TITELTITELTITELTITEL/$(sed 's:/:\\/:g' /home/USER/rssnews_news_titel.txt)/" /var/www/WEBSITE_JOOMLA/administrator/createarticle_news.php
#sed -i -e "s/LINKLINKLINKLINK/$(sed 's:/:\\/:g' /home/USER/rssnews_news_link.txt)/" /var/www/WEBSITE_JOOMLA/administrator/createarticle_news.php

cat /home/USER/rssnews_news_content.txt >> /var/www/WEBSITE_JOOMLA/administrator/createarticle_news.php

cat /var/www/WEBSITE_JOOMLA/administrator/createarticle_news_bottom.php >> /var/www/WEBSITE_JOOMLA/administrator/createarticle_news.php
cd /var/www/WEBSITE_JOOMLA/administrator
/usr/bin/php /var/www/WEBSITE_JOOMLA/administrator/createarticle_news.php

File /var/www/WEBSITE_JOOMLA/administrator/createarticle_news_header.php


const _JEXEC = 1;
ini_set('display_errors', 1);

// Load system defines
if (file_exists(dirname(__DIR__) . '/defines.php'))
require_once dirname(__DIR__) . '/defines.php';

if (!defined('_JDEFINES'))
define('JPATH_BASE', dirname(__DIR__));
require_once JPATH_BASE . '/includes/defines.php';

// Get the framework.
require_once JPATH_LIBRARIES . '/import.legacy.php';

// Bootstrap the CMS libraries.
require_once JPATH_LIBRARIES . '/cms.php';

// Load the configuration
require_once JPATH_CONFIGURATION . '/configuration.php';

require_once JPATH_BASE . '/includes/framework.php';

$article = JTable::getInstance('content');

$article->title            = 'TITELTITELTITELTITEL';
$article->alias            = JFilterOutput::stringURLSafe('TITELTITELTITELTITEL');
$article->introtext        = '<p dir="ltr" style="font-size:14pt">

File /var/www/WEBSITE_JOOMLA/administrator/createarticle_news_bottom.php

Please enter your category id of your Joomla category.

$article->catid            = YOUR_CATEGORY_ID;
$article->created          = JFactory::getDate()->toSQL();;
$article->created_by_alias = 'Super User';
$article->state            = 1;
$article->access           = 1;
$article->metadata         = '{"page_title":"","author":"","robots":""}';
$article->language         = '*';

// Check to make sure our data is valid, raise notice if it's not.
if (!$article->check()) {
        JError::raiseNotice(500, $article->getError());

        return FALSE;

// Now store the article, raise notice if it doesn't get stored.
if (!$article->store(TRUE)) {
        JError::raiseNotice(500, $article->getError());

        return FALSE;