1

I have a TemplaVoila based TYPO3 website and I need to access my TV page content from within an eID script. How can I access the content in that CE field from my script? I know how to provide the eID script with the ID of the needed page and with the name of the TV field.

It seems that I can't find any information about how to access TV content from within my own extension or eID script, although I searched the web back and forth.

Jpsy
  • 20,077
  • 7
  • 118
  • 115

1 Answers1

0

The basic problem of my question is that the eID process is not designed for tasks that require such complex TYPO3 functions as the TV record mechanics or the TYPO3 HTML renderer.

I actually considered to revert back to the full TYPO3 engine by using a dedicated page type. But I had to call my code many times in a single page to render images from TV content, so I had to look for a streamlined process. I decided to stay with eID instead of firing up the full TYPO3 core.

Here is the hack that I finally came up with.

Be warned:
This code has multiple weaknesses:

  1. It does not care about language overlays (but could probably be extended to do so).
  2. It does not use any dedicated TYPO3 HTML renderer and the HTML output will not validate in many cases. (In particular the output may contain H1, H2, ... and P tags nested within surrounding P tags, due to the very simple renderer that I have sketched here.)
  3. Any typolinks will not be contained - only the most basic HTML output will survive.

But this worked nicely for my special problem (single language website, PDF renderer consuming created HTML). So it might help others too.

<?php
if (!defined('PATH_typo3conf'))
   die('Could not access this script directly!');

tslib_eidtools::connectDB(); //Connect to database

$id = t3lib_div::_GP('id');
$htmlData = readContentfromDB($id, 'myFieldName');
if(is_string($htmlData))  exit('Error: '.$htmlData);

$html = $htmlData['html'];
$lastChange = $htmlData['tstamp'];

exit($html);


// ----------
// readContentfromDB()
// returns string with error msg or assoc array with array( 'html'=>string([HTML CODE]), 'tstamp'=>int([LAST CHANGE TIMESTAMP]) )
// ----------
function readContentfromDB($id, $fieldName){
    global $TYPO3_DB;

    $res = $TYPO3_DB->exec_SELECTgetRows('tx_templavoila_flex', 'pages', 'uid='.(int)$id);
    if(!$res)  return 'Reading flexXML from page '.$id.' failed.';
    $flexXml = simplexml_load_string($res[0]['tx_templavoila_flex']);
    $recordsNodes = $flexXml->xpath('//field[@index="'.$fieldName.'"]/value');
    $records = explode(',', (string)$recordsNodes[0]);

    $html = '';
    $htmlTstamp = 0;
    foreach($records as $rec){
        $res = $TYPO3_DB->exec_SELECTgetRows('header, bodytext, tstamp', 'tt_content', "uid=$rec");
        if(!$res)  return 'Reading tt_content record '.$rec.' failed.';
        $tstamp = (int)$res[0]['tstamp'];
        $htmlTstamp = max($tstamp, $htmlTstamp);
        $header = '<h1>' . $res[0]['header'] . '</h1>';
        $bodyRaw =   $res[0]['bodytext'];
        $bodyArr = explode("\n", $bodyRaw);
        $body = '';
        foreach($bodyArr as $bodyLine) $body .= '<p>'.trim($bodyLine).'</p>';
        $html .= $header . $body;
    }

    return array('html'=>$html, 'tstamp'=>$htmlTstamp);
}

// ----------
?>

If somebody comes up with a way to use the original TYPO3 renderer within eID I will be happy to accept your better answer!

Jpsy
  • 20,077
  • 7
  • 118
  • 115