问题
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.
回答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
}
来源:https://stackoverflow.com/questions/12267124/php-script-is-parsing-content-from-rte-tt-news-but-internal-links-are-not-appe