Advertisement
Guest User

TYPO3 Extbase TSFE in CommandController

a guest
Sep 5th, 2013
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.96 KB | None | 0 0
  1. <?php
  2. namespace SMS\Importer\Command;
  3.  
  4. use TYPO3\CMS\Core\TimeTracker\TimeTracker;
  5. use TYPO3\CMS\Core\Utility\GeneralUtility;
  6. use TYPO3\CMS\Extbase\Mvc\Controller\CommandController;
  7. use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
  8. use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
  9.  
  10. require_once(PATH_tslib . 'class.tslib_fe.php');
  11. require_once(PATH_t3lib . 'class.t3lib_userauth.php');
  12. require_once(PATH_tslib . 'class.tslib_feuserauth.php');
  13. require_once(PATH_t3lib . 'class.t3lib_cs.php');
  14. require_once(PATH_tslib . 'class.tslib_content.php');
  15. require_once(PATH_t3lib . 'class.t3lib_tstemplate.php');
  16. require_once(PATH_t3lib . 'class.t3lib_page.php');
  17.  
  18. /**
  19.  * Class FrontendEnabledCommandController
  20.  *
  21.  * @package SMS\Importer\Command
  22.  * @@author Thorsten Kohpeiß <kohpeiss@sitegeist.de>
  23.  */
  24. class FrontendEnabledCommandController extends CommandController {
  25.  
  26.     public function __construct() {
  27.         $this->buildTSFE();
  28.     }
  29.  
  30.     public function buildTSFE($pid = 1) {
  31.         if (!is_object($GLOBALS['TT'])) {
  32.             $GLOBALS['TT'] = new TimeTracker();
  33.             $GLOBALS['TT']->start();
  34.         }
  35.  
  36.         $GLOBALS['TSFE'] = new TypoScriptFrontendController($GLOBALS['TYPO3_CONF_VARS'], $pid, '0', 1, '', '', '', '');
  37.         $GLOBALS['TSFE']->connectToDB();
  38.         $GLOBALS['TSFE']->initFEuser();
  39.         $GLOBALS['TSFE']->fetch_the_id();
  40.         $GLOBALS['TSFE']->getPageAndRootline();
  41.         $GLOBALS['TSFE']->initTemplate();
  42.         $GLOBALS['TSFE']->tmpl->getFileName_backPath = PATH_site;
  43.         $GLOBALS['TSFE']->forceTemplateParsing = 1;
  44.         $GLOBALS['TSFE']->getConfigArray();
  45.         $GLOBALS['TSFE']->cObj = new ContentObjectRenderer();
  46.     }
  47.  
  48.     public function getLinkToPage($uid) {
  49.         $uid = intval($uid);
  50.  
  51.         if ($uid > 0) {
  52.             $typolinkConf = array(
  53.                 'parameter' => $uid
  54.             );
  55.             $url = $GLOBALS['TSFE']->cObj->typoLink_URL($typolinkConf);
  56.             if ($url == '') {
  57.                 $url = '/';
  58.             }
  59.         } else {
  60.             throw new \InvalidArgumentException('$uid must be an integer > 0', 123);
  61.         }
  62.  
  63.         return $url;
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement