Seblod: External PHP Script for manipulating Seblod Joomla Article
Autor: Christian Hamberger, Kategorie: Seblod, Erstellt am: 28.10.2020, Bearbeitet: 28.10.2020, Aufrufe: 2514
This a example for an external PHP Script, which allows you generate Joomla Seblod Article or call data from them.
There are a lot of comments - therefore no further description.
Initialisation and Test
<?php
// Errors for debugging and runtime
// error_reporting(E_ALL);
// ini_set('display_errors', 1);
// Get Joomla! framework
define( '_JEXEC', 1 );
define( '_VALID_MOS', 1 );
// Here you need you generate the relative path to you joomla base directory
// In this case this php file is in folder /myjoomlainstance/test/
define( 'JPATH_BASE', realpath(dirname(__FILE__) . '/..'));
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
$mainframe =& JFactory::getApplication('site');
// $mainframe->initialise();
// Seblod inclusions
JPluginHelper::importPlugin( 'cck_storage_location' );
// Test Joomla Framework Works -> If not you will get an PHP error here
$joomla_test = JFactory::getDbo();
// Test Seblod Works -> If not you will get an PHP error here
$seblod_test = new JCckContentJoomla_Article;
Creating a Joomla Seblod article
// Pre Data base
$content_type = 'publications'; // Systemname of content type
$title = 'Testarticle ' . (string)date(DATE_RFC822);
$state = 1; // 1 is published
$access = 1; // 1 is public
$language = '*'; // * is all languages
$category = 10; // joomla category id
$user = 834; // joomla user id
// Pre Data more
$kind_of_pub = 'Book';
$price = '9 EUR';
// Class JCckContentJoomla_Article extends libraries/cms/cck/content.php
$content = new JCckContentJoomla_Article;
// Joomla Article Data
$data_base = array(
'catid' => $category,
'state' => $state,
'access' => $access,
'created_by' => $user,
'language' => $language,
'title' => $title
);
// Content type Data
$data_more = array(
'kind_of_publication' => $kind_of_pub,
'price' => $price
);
// Disable Seblod permission control
$content->setOptions(array( 'check_permissions' => 0 ));
// Execution with success control
if ( $content->create($content_type, $data_base, $data_more )->isSuccessful()) {
echo 'ok.';
} else {
echo 'ko.';
}
Call data from existing Joomla Seblod article
// Pre Data
$article_id = 14;
// Get Article
$joomla_article = JCckContentJoomla_Article::getInstance($article_id);
echo $joomla_article->getProperty( 'title' ); // Output Article Title
echo $joomla_article->getProperty( 'kind_of_publication' ); // Output addition Seblod field
Further instructions, but with some outdated information.
- Manipulating Content: Joomla! Article (Seblod Manual)
- Manipulating Content: Introduction (Seblod Manual)