30.03.08 12:18 Age: 236 days
Category: TYPO3

Using frontend-methods in the backend

 

The last days i had to develope a newsletter extension with a sending module in the backend, and therefor i wanted to use some frontend functionality such as template-parsing, typoscript configurations, image generation,...
Doing some research and debugging i found out which steps have to be taken to instantiate a full TYPO3 frontend session in an arbitrary PHP file.

// plugin-baseclass
require_once(PATH_tslib.'class.tslib_pibase.php');
// classes for retrieving the typoscript configuration of the current page
require_once(PATH_t3lib.'class.t3lib_page.php');
require_once(PATH_t3lib.'class.t3lib_tstemplate.php');
require_once(PATH_t3lib.'class.t3lib_tsparser_ext.php');
// class for rendering content, retrieving and substituting markers in templates,...
require_once(PATH_tslib.'class.tslib_content.php');
// tools
require_once(PATH_t3lib.'class.t3lib_div.php');
// extensionmanager
require_once(PATH_t3lib.'class.t3lib_extmgm.php');
require_once(PATH_t3lib.'config_default.php');
// basic configuration of TYPO3 - can be configured via the install tool
require_once(PATH_typo3conf.'localconf.php');
// main frontend class
require_once(PATH_tslib.'class.tslib_fe.php');
// classes for user authentication for frontend and backendusers, sessionmanagement
require_once(PATH_t3lib.'class.t3lib_userauth.php');
require_once(PATH_tslib.'class.tslib_feuserauth.php');

class myFEOutput extends tslib_pibase {
 
  var $id;
  var $conf;
 
  function main(){
    return "hello world!";
  }  
}

// creating a fake TSFE object
$TSFEclassName = t3lib_div::makeInstanceClassName('tslib_fe');
// retrieving the id of the current page
$id = isset($HTTP_GET_VARS['id'])?$HTTP_GET_VARS['id']:0;
// configure the TSFE object
$GLOBALS['TSFE'] = new $TSFEclassName($TYPO3_CONF_VARS, $id, '0', 1, '', '','','');
$GLOBALS['TSFE']->connectToMySQL();
$GLOBALS['TSFE']->initFEuser();
$GLOBALS['TSFE']->fetch_the_id();
$GLOBALS['TSFE']->getPageAndRootline();
$GLOBALS['TSFE']->initTemplate();
$GLOBALS['TSFE']->tmpl->getFileName_backPath = PATH_site;
$GLOBALS['TSFE']->forceTemplateParsing = 1;
$GLOBALS['TSFE']->getConfigArray();

// create a plugin object    
$plugin = t3lib_div::makeInstance('myFEOutput');
// assign a contentobject for rendering content
$plugin->cObj = t3lib_div::makeInstance('tslib_cObj');
$sysPageObj = t3lib_div::makeInstance('t3lib_pageSelect');
// retrieve rootline
$rootLine = $sysPageObj->getRootLine($id);
// create a Typoscript parser object
$TSObj = t3lib_div::makeInstance('t3lib_tsparser_ext');
$TSObj->tt_track = 0;
$TSObj->init();
// parse the templates
$TSObj->runThroughTemplates($rootLine);
$TSObj->generateConfig();
$plugin->conf = $TSObj->setup['plugin.']['myFEOutput.'];

// output html
echo($plugin->main());


Add comment

* - required field

*

*



*
*

 
 

 

Hi this is my developer blog here on synapsick.net. Its not just another TYPO3 blog concerning news, or gossip about OS-community.
Most of the time i'm developing extensions for TYPO3 and Microsoft Sharepoint.
My intention is to create a database with tricky solutions for tricky problems, in a very technical way.

Contact me at ra@synapsick.net

You can subscribe to my newsfeed here: