Created
November 27, 2012 10:16
-
-
Save smichaelsen/4153478 to your computer and use it in GitHub Desktop.
cObject in Backend
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define('PATH_tslib', PATH_site . 'typo3/sysext/cms/tslib/'); | |
class Tx_MyExt_Utility_BeCobj { | |
/** | |
* @var tslib_fe | |
*/ | |
protected static $tsfe; | |
/** | |
* @static | |
* @param int $pid | |
* @return tslib_cObj | |
*/ | |
static function createCObj($pid = 1) { | |
if (!is_a(self::$tsfe, 'tslib_de')) { | |
self::createTSFE($pid); | |
} | |
self::$tsfe->newCObj(); | |
return self::$tsfe->cObj; | |
} | |
/** | |
* @param int $pid | |
* @return bool | |
*/ | |
protected static function createTSFE($pid = 1) { | |
require_once(PATH_site . 'typo3/sysext/cms/tslib/class.tslib_fe.php'); | |
require_once(PATH_site . 't3lib/class.t3lib_userauth.php'); | |
require_once(PATH_site . 'typo3/sysext/cms/tslib/class.tslib_feuserauth.php'); | |
require_once(PATH_site . 't3lib/class.t3lib_cs.php'); | |
require_once(PATH_site . 'typo3/sysext/cms/tslib/class.tslib_content.php'); | |
require_once(PATH_site . 't3lib/class.t3lib_tstemplate.php'); | |
require_once(PATH_site . 't3lib/class.t3lib_page.php'); | |
require_once(PATH_site . 't3lib/class.t3lib_timetrack.php'); | |
/** @var $tsfe tslib_fe */ | |
$tsfe = t3lib_div::makeInstance('tslib_fe', $GLOBALS['TYPO3_CONF_VARS'], $pid, '0', 0, '', '', '', ''); | |
/** @var $timeTrack t3lib_timeTrack */ | |
$timeTrack = t3lib_div::makeInstance('t3lib_timeTrack'); | |
$timeTrack->start(); | |
$tsfe->config['config']['language'] = $_GET['L']; | |
// Fire all the required function to get the typo3 FE all set up. | |
$tsfe->id = $pid; | |
$tsfe->connectToDB(); | |
// Prevent mysql debug messages from messing up the output | |
$sqlDebug = $GLOBALS['TYPO3_DB']->debugOutput; | |
$GLOBALS['TYPO3_DB']->debugOutput = FALSE; | |
$tsfe->initLLVars(); | |
$tsfe->initFEuser(); | |
// Look up the page | |
$tsfe->sys_page = t3lib_div::makeInstance('t3lib_pageSelect'); | |
$tsfe->sys_page->init($tsfe->showHiddenPage); | |
// If the page is not found (if the page is a sysfolder, etc), then return no URL, preventing any further processing which would result in an error page. | |
$page = $tsfe->sys_page->getPage($pid); | |
if (count($page) == 0) { | |
$GLOBALS['TYPO3_DB']->debugOutput = $sqlDebug; | |
return FALSE; | |
} | |
// If the page is a shortcut, look up the page to which the shortcut references, and do the same check as above. | |
if ($page['doktype'] == 4 && count($tsfe->getPageShortcut($page['shortcut'], $page['shortcut_mode'], $page['uid'])) == 0) { | |
$GLOBALS['TYPO3_DB']->debugOutput = $sqlDebug; | |
return FALSE; | |
} | |
// Spacer pages and sysfolders result in a page not found page too… | |
if ($page['doktype'] == 199 || $page['doktype'] == 254) { | |
$GLOBALS['TYPO3_DB']->debugOutput = $sqlDebug; | |
return FALSE; | |
} | |
$tsfe->getPageAndRootline(); | |
$tsfe->initTemplate(); | |
$tsfe->forceTemplateParsing = 1; | |
// Find the root template | |
$tsfe->tmpl->start($tsfe->rootLine); | |
// Fill the pSetup from the same variables from the same location as where tslib_fe->getConfigArray will get them, so they can be checked before this function is called | |
$tsfe->sPre = $tsfe->tmpl->setup['types .'][$tsfe->type]; // toplevel – objArrayName | |
$tsfe->pSetup = $tsfe->tmpl->setup[$tsfe->sPre . '.']; | |
// If there is no root template found, there is no point in continuing which would result in a 'template not found' page and then call exit php. Then there would be no clickmenu at all. | |
// And the same applies if pSetup is empty, which would result in a "The page is not configured" message. | |
if (!$tsfe->tmpl->loaded || ($tsfe->tmpl->loaded && !$tsfe->pSetup)) { | |
$GLOBALS['TYPO3_DB']->debugOutput = $sqlDebug; | |
return TRUE; | |
} | |
$tsfe->getConfigArray(); | |
$tsfe->getCompressedTCarray(); | |
$tsfe->inituserGroups(); | |
$tsfe->connectToDB(); | |
$tsfe->determineId(); | |
self::$tsfe = $tsfe; | |
$GLOBALS['TT'] = $timeTrack; | |
return TRUE; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment