2

I have a news article with internal links. In the RTE I see links like

http://www.yourdomain.com/?id=3

in the html text mode. The problem is that this link also appears on the frontend. RealURL should convert this link to something like

http://www.yourdomain.com/products/

The content of RTE is currently parsed like this

$parseObj = t3lib_div::makeInstance('t3lib_parsehtml_proc'); 
$txt = $parseObj->TS_links_rte($result['bodytext']);
$txt = $parseObj->TS_transform_rte($txt);

I read that I should use something like this

$pObj = t3lib_div::makeInstance('tslib_pibase');
$txt = $pObj->pi_RTEcssText($result['bodytext']);

but I don't know how can I access this function. I get

Fatal error: Call to a member function parseFunc() on a non-object in /home/myuser/www/home/typo3/sysext/cms/tslib/class.tslib_pibase.php on line 1384

What is the right way doing this? How can I access the function pi_RTEcssText? Do I have to use a class? Are there other ways doing it without a class?

EDIT:

I created a new template with TemplaVoila and defined lib.newscontent as TS object path.

TS Main Template

includeLibs.user_news = fileadmin/templates/php_scripts/news/class.news.php

lib.newscontent = USER_INT
lib.newscontent {
  userFunc = user_news->main
  userFunc.bodytext.parseFunc < lib.parseFunc_RTE
}  

class.news.php

<?

class user_news {

    var $cObj;

    private $conf;

    function main($content,$conf) {
        $this->conf = $conf; 
        $this->setPreferences();        
        $content .= $this->aktuelleNews();

        return $content;
    }

    private function aktuelleNews() {
        $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
                '*',         // SELECT ...
                'tt_news',     // FROM ...
                'pid=22 AND deleted=0 AND hidden=0',    // WHERE...
                '',            // GROUP BY...
                'datetime DESC'    // ORDER BY...
        );

        $i = 1;
        $out_list = '<ul id="news">';
        while ($data = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
            $date = date("d.m.Y",$data['datetime']);
            $out_list .= '<li><a href="#section'.$i.'">'.$date.': '.$data['title'].'</a></li>';
            $out_detail.= $this->outputnewsdetail($data,$i);

            $i++;
        }
        $out_list .= '</ul>';
        return $out_list . $out_detail;
    }

    private function outputnewsdetail($result,$count){
        $this->cObj->start($result, 'tt_news');

        $bodytext = $this->cObj->stdWrap($result['bodytext'], $this->conf['bodytext']);
        $bodytext = $this->cObj->parseFunc($bodytext,$GLOBALS['TSFE']->tmpl->setup['lib.']['parseFunc_RTE.']);

        return $bodytext;

    }

    private function setPreferences() {

    }

}
?>

localconf.php

include(PATH_site.'fileadmin/templates/php_scripts/news/class.news.php');

Remaining question

Why does the rendering part in the TS Main Template doesn't work? I used

$this->cObj->parseFunc($bodytext,$GLOBALS['TSFE']->tmpl->setup['lib.']['parseFunc_RTE.']);

to get my result.

testing
  • 19,681
  • 50
  • 236
  • 417

1 Answers1

1

I would prefer:

$txt = $this->cObj->stdWrap($result['bodytext'], $this->conf['bodytext.']);

You need in your main method: $this->conf = $conf;

In your TypoScript add the parseFunc to bodytext:

 plugin.tx_yourplugin_pi1 {
    bodytext.parseFunc < lib.parseFunc_RTE
 }

The main idea is to use the usual parseFunc which is used by content elements. So you have the same rendering. Another benefit is, that your application is more flexible.

Just as a side note. It is worth to make a lokal cObj for that and hand over the complete data. So you are able to use alle fields in TypoScript. F.e. field = bodytext in your case.

# create lokal cObj - do not override the original data!
$cObj = t3lib_div::makeInstance('tslib_cObj');
foreach ($row = ...) {
   # override data array with row. Every field in $row is now accesible via 
   # TypoScript field = fieldname
   $cObj->start($row, $tableName);
   $content .= $cObj->stdWrap($row['bodytext'], $this->conf['bodytext.']);
}

# TS Setup:
# in your case you could do somesthing like:
plugin.tx_yourplugin_pi1 {
    bodytext.parseFunc < lib.parseFunc_RTE
    bodytext.wrap = <div class="hide">|</div>
    bodytext.prepend = TEXT
    bodytext.prepend.field = bodytext
    bodytext.prepend.stripHtml = 1
    bodytext.prepend.crop = 30 | ... | 1
    bodytext.prepend.wrap = <span title="|" onclick="showBodytext()">info</span>
}

If you need it in an user function try it like this:

function user_yourfunction($content,$conf) {
    $result = *magic*
    $cObj = t3lib_div::makeInstance('tslib_cObj');
    $cObj->start($result, 'your table name');
    return $cObj->stdWrap($result['bodytext'], $conf['bodytext.']);
}

In TypoScript:

includeLibs.something = media/scripts/example_callfunction.php
page.10 = TEXT
page.10 {
   value = Hello World
   postUserFunc = user_yourfunction
   postUserFunc.bodytext.parseFunc < lib.parseFunc_RTE
}
maholtz
  • 3,631
  • 1
  • 17
  • 17
  • I don't have an own plugin. It is a simple PHP script. So it looks like that I would have to implement a user function? Would it work with a user function? – testing Sep 05 '12 at 09:15
  • just install "kickstarter" and create an plugin. – maholtz Sep 05 '12 at 12:01
  • well, added an example for userfunctions – maholtz Sep 05 '12 at 12:09
  • What does `$cObj->start($result, 'your table name');` mean? Can it be any table name? Your TS at the end: `page.10 = TEXT` is only an example? So I also could use `lib.comments = USER` for example? – testing Sep 05 '12 at 16:24
  • 'your table name' should be the name of the table. But start($result) will work too, but you cannot use DBAL then (see also: http://api.typo3.org/typo3v4/current/html/classtslib__c_obj.html#a00be5ebb4209ad03ad6b5cb5491706d2) . And page.10 is an example for sure. Did you try? – maholtz Sep 06 '12 at 07:00
  • I got managed this. See my edited question. One question is remaining. – testing Oct 12 '12 at 15:45
  • $bodytext = $this->cObj->stdWrap($result['bodytext'], $this->conf['bodytext.']); // the missing dot! and remove the second parseFunc call – maholtz Oct 15 '12 at 11:16
  • I added the dot in the call and removed this line: `$bodytext = $this->cObj->parseFunc($bodytext,$GLOBALS['TSFE']->tmpl->setup['lib.']['parseFunc_RTE.']);`. Now the content is not formated anymore. What I'm doing wrong? – testing Oct 15 '12 at 17:38
  • check the content of $this->conf['bodytext.'] and compare it with $GLOBALS['TSFE']->tmpl->setup['lib.']['parseFun‌​c_RTE.'] – maholtz Oct 16 '12 at 07:46
  • I echoed it with `
    ` and `print_r()`. $this->conf['bodytext.'] and $this->conf['bodytext'] is empty. What does that mean?
    – testing Oct 16 '12 at 16:15
  • remove "userFunc." at the begining of this line: "userFunc.bodytext.parseFunc < lib.parseFunc_RTE". Debug $this->conf and you will see an array 'userFunc.' => 'bodytext.' => ... – maholtz Oct 17 '12 at 08:49
  • Now I use `bodytext.parseFunc < lib.parseFunc_RTE` in the main TS and if I debug `$this->conf` I see [userFunc] => user_news->main and the array [bodytext.], but no array [userFunc.] ... – testing Oct 17 '12 at 16:08
  • update your code; check for the missing dot; where is $cObj = t3lib_div::makeInstance('tslib_cObj'); Read TSref Documentation; Read TSref in 45 Minutes – maholtz Oct 18 '12 at 07:09