php脚本正在解析RTE(tt_news)中的内容,但内部链接未显示为口述网址 [英] php script is parsing content from RTE (tt_news) but internal links are not appearing as speaking url

查看:112
本文介绍了php脚本正在解析RTE(tt_news)中的内容,但内部链接未显示为口述网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一条带有内部链接的新闻文章.在RTE中,我看到类似

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

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

在html文本模式下.问题在于此链接也出现在前端. RealURL应该将此链接转换为类似的

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/

RTE的内容当前是按以下方式解析的

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

正确的做法是什么?如何访问功能pi_RTEcssText?我必须上课吗?不用上课还有其他方法吗?

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?

我用TemplaVoila创建了一个新模板,并将lib.newscontent定义为TS对象路径.

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

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');

剩余问题

为什么TS主模板中的渲染部分不起作用?我用过

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.']);

得到我的结果.

推荐答案

我希望:

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

您的主要方法中需要:$ this-> conf = $ conf;

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

在您的TypoScript中,将parseFunc添加到正文中:

In your TypoScript add the parseFunc to bodytext:

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

主要思想是使用内容元素使用的常规parseFunc.因此,您具有相同的渲染.另一个好处是,您的应用程序更加灵活.

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.

仅作为旁注.为此,值得进行总体评估并交出完整的数据.因此,您可以在TypoScript中使用alle字段. F.e. field =您的情况下的正文.

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.']);
}

在TypoScript中:

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
}

这篇关于php脚本正在解析RTE(tt_news)中的内容,但内部链接未显示为口述网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆