First you should include the files that our FAQ article says as before for creating items
Code:
<?php
// Get Joomla! framework
define( '_JEXEC', 1 );
define( '_VALID_MOS', 1 );
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' );
$app = JFactory::getApplication('site');
$app->initialise();
global $globalcats;
if (empty($globalcats))
{
JPluginHelper::importPlugin('system', 'flexisystem');
// add the category tree to categories cache
$catscache = JFactory::getCache('com_flexicontent_cats');
$catscache->setCaching(1); //force cache
$catscache->setLifeTime(84600); //set expiry to one day
$globalcats = $catscache->get(
array('plgSystemFlexisystem', 'getCategoriesTree'),
array()
);
//$globalcats = plgSystemFlexisystem::getCategoriesTree();
}
// Define component paths IF FLEXIcontent v3.1.0 or older
// You do not need them for v3.1.1 or later !!
define( 'JPATH_COMPONENT_SITE', JPATH_SITE.DS.'components'.DS.'com_flexicontent' );
define( 'JPATH_COMPONENT_ADMINISTRATOR', JPATH_ADMINISTRATOR.DS.'components'.DS.'com_flexicontent' );
// Create a log file
$user = JFactory::getUser();
$log_filename = 'item_creation_'.($user->id).'.php';
jimport('joomla.log.log');
JLog::addLogger(array('text_file' => $log_filename));
error_reporting(E_ALL & ~E_STRICT);
ini_set('display_errors',1);
// **************************************
// Include the needed classes and helpers
// **************************************
if (!defined('DS')) define('DS',DIRECTORY_SEPARATOR);
require_once (JPATH_SITE.DS.'components'.DS.'com_flexicontent'.DS.'classes'.DS.'flexicontent.helper.php');
require_once (JPATH_SITE.DS.'components'.DS.'com_flexicontent'.DS.'classes'.DS.'flexicontent.categories.php');
require_once (JPATH_SITE.DS.'components'.DS.'com_flexicontent'.DS.'classes'.DS.'flexicontent.fields.php');
require_once (JPATH_SITE.DS.'components'.DS.'com_flexicontent'.DS.'classes'.DS.'flexicontent.acl.php');
require_once (JPATH_SITE.DS.'components'.DS.'com_flexicontent'.DS.'helpers'.DS.'permission.php');
require_once (JPATH_SITE.DS.'components'.DS.'com_flexicontent'.DS.'helpers'.DS.'route.php');
// Add component's table directory to the include path
JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR.DS.'tables');
// *******************
// Load language files
// *******************
// (BACKEND) Load english language file for 'com_content' component then override with current language file
JFactory::getLanguage()->load('com_content', JPATH_ADMINISTRATOR, 'en-GB', true);
JFactory::getLanguage()->load('com_content', JPATH_ADMINISTRATOR, null, true);
// (BACKEND) Load english language file for 'com_flexicontent' component then override with current language file
JFactory::getLanguage()->load('com_flexicontent', JPATH_ADMINISTRATOR, 'en-GB', true);
JFactory::getLanguage()->load('com_flexicontent', JPATH_ADMINISTRATOR, null, true);
// (FRONTEND) Load english language file for 'com_content' component then override with current language file
JFactory::getLanguage()->load('com_content', JPATH_SITE, 'en-GB', true);
JFactory::getLanguage()->load('com_content', JPATH_SITE, null, true);
// (FRONTEND) Load english language file for 'com_flexicontent' component then override with current language file
JFactory::getLanguage()->load('com_flexicontent', JPATH_SITE, 'en-GB', true);
JFactory::getLanguage()->load('com_flexicontent', JPATH_SITE, null, true);
// Set item to delete, YOU DECIDE IF YOU CHECKING ACL IS NEEDED
$id = 4444444;
JLoader::register('FlexicontentModelItems', JPATH_ADMINISTRATOR.DS.'components'.DS.'com_flexicontent'.DS.'models'.DS.'items.php');
JLoader::register('FlexicontentModelItem', JPATH_BASE.DS.'components'.DS.'com_flexicontent'.DS.'models'.DS.'item.php');
$model = new FlexicontentModelItems();
$itemmodel = new FlexicontentModelItem();
$app = JFactory::getApplication();
$db = JFactory::getDbo();
$user = JFactory::getUser();
// Get owner and other item data
$q = 'SELECT id, created_by, catid FROM #__content WHERE id = ' . (int) $id;
$itemdata = $db->setQuery($q)->loadObjectList('id');
if (!$itemdata)
{
die('Item ' . $id . ' not found');
}
// Check authorization for delete operation
$isOwner = $itemdata[$id]->created_by == $user->id;
$asset = 'com_content.article.' . $id;
$canDelete = $user->authorise('core.delete', $asset) || ($user->authorise('core.delete.own', $asset) && $isOwner);
// CHECK or not check if user is allowed to delete
if (1 || $canDelete)
{
// Try to delete
if ($model->delete(array($id), $itemmodel))
{
echo 'delete success';
}
// Try to delete
else
{
echo 'delete failed';
}
}
else
{
echo 'No access to delete failed';
}