[TYPO3] Extension "comments" notification without the need to approve each comment?

Dmitry Dulepov dmitry at typo3.org
Thu Oct 2 19:22:30 CEST 2008


Hi!

Thomas Hirt wrote:
> 1)This code will not work:
> $templateCode = $pObj->cObj->fileResource($conf['templateFile']);
> Even if I have a file called: ext_typoscript_setup.txt
> With the following code: plugin.tx_commentsemail_pi1.templateFile = 
> EXT:comments_email/res/email.txt
> How can I use a variable instead of a hardcoded path?

What does it mean "will not work"? "will not work" may mean "returns empty string", "returns wrong result", "crashes web server", etc. Please, always provide exact description of the problem, otherwise you cannot expect a solution or advice.

> 2)This wont work neither
> $subject = $pObj->pi_getLL('comments_email_subject_no_approval');
> I created the file locallang.xml in pi1 but it doesn't seems to be 
> called by my funktion.
> How can I use a locallang file in my hook?

pi_getLL will load only strings from parent plugin. You have to instantiate language object yourself if you want to get strings from your language file:

require_once(t3lib_extMgm::extPath('lang', 'lang.php'));
$lang = t3lib_div::makeInstance('language');
$lang->init($GLOBALS['TSFE']->lang);
$string = $lang->sL('EXT:comments_email/locallang.xml:comments_email_subject_no_approval');

I did not check the code above, there can be some mistakes in calls.

> 3) I would like to add a field with a checkbox (send an email without 
> the need to approve each commet) and an input field for the path of the 
> template file for my emailto the tt_news or tt_product flexform.
> I created the file ext_tables.php and a file called ext_tables.sql.
> The MySQL tables are created correctly. But I can se no checkbox or text 
> input field in tt_news.

Read about types in "TYPO3 core API" and see how comments_ic extension does it.

> What are the basic steps to add a checkbox and an input field to tt_news 
> or tt_product?
> 
> Here my code from ext_tables.php

Missing t3lib_extMgm::addToAllTCAtypes() call :)

> AND
> pi1/class.tx_commentsemail_hooks.php
> 
> <?php
> 
> require_once(PATH_tslib . 'class.tslib_pibase.php');
> 
> class tx_commentsemail_hooks extends tslib_pibase {   

Do not extend hook from tslib_pibase. This will not work properly. tslib_pibase assumes that it is called in a certain way, which is not true for hooks.

>     function hookFunc(&$params, &$pObj) {

...

>             $commentUri = $_SERVER['SCRIPT_URI'];

$commentUri = t3lib_div::getIndpEnv('TYPO3_REQUEST_URL');

Btw, this variable is unused.

>             $templateCode = 
> $pObj->cObj->fileResource("EXT:comments_email/res/email.txt");

In TYPO3 always use single quotes, not double.

The rest looks ok.

> I hope Dmitry book will come out soon and I hope it covers some of this 
> basic issues, thanks,

It is out already but there is a lot of orders, so shipping is delayed by nearly two weeks.

-- 
Dmitry Dulepov
TYPO3 Core team
My TYPO3 book: http://www.packtpub.com/typo3-extension-development/book
In the blog: http://typo3bloke.net/post-details/duplicate_content_with_realurl/


More information about the TYPO3-english mailing list