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

Thomas Hirt info at thomas-hirt.at
Fri Oct 3 12:44:27 CEST 2008


Sorry, for my incorrect description.

CODE
$templateCode = $pObj->cObj->fileResource($conf['templateFile']);
var_dump ($templateCode);

RETURNS
NULL

So I think "$conf['templateFile']" is the problem.
How can I fill my variable with the content of the file 
"ext_typoscript_setup.txt" where I have the following code:

plugin.tx_commentsemail_pi1.templateFile = EXT:comments_email/res/email.txt

(The User could the write the following typoscript code in setup, 
couldn't he?
plugin.tx_commentsemail_pi1.templateFile = whatever)

----------------------------------------------------
Thanks for that code snippet. But I cannot get it to work.
It return the string I put in...

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

RETURNS
string(71) 
"EXT:comments_email/pi1/locallang.xml:comments_email_subject_no_approval"

My locallang.xml in pi1 Folder:
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<T3locallang>
	<meta type="array">
		<description>Language labels for comments (hook) email without 
notification</description>
		<type>module</type>
		<csh_table></csh_table>
		<fileId>EXT:comments_email/pi1/locallang.xml</fileId>
		<labelContext type="array">
			<label index="tt_content.list_type_pi1"></label>
		</labelContext>
	</meta>
	<data type="array">
		<languageKey index="default" type="array">
			<label index="comments_email_subject_no_approval">Notification about 
new comment</label>
		</languageKey>
		<languageKey index="de" type="array">
			<label index="comments_email_subject_no_approval">Nachricht über neue 
Kommentare</label>
		</languageKey>
	</data>
</T3locallang>
----------------------------------------------------

I changed
class tx_commentsemail_hooks extends tslib_pibase {

into
class tx_commentsemail_hooks  {

Thanks for that tip!
----------------------------------------------------

I deleted the variable "$commentUri = $_SERVER['SCRIPT_URI'];"
You're right, it was unused!
----------------------------------------------------

OK, just single quotes are fine
----------------------------------------------------

UPS, I made a mistake....
I don't want do add a checkbox and input field to tt_news or tt_product 
flexform.
(Actually my code worked fine an the field apeared in tt_news or 
tt_products)

I want to add this two field to the comments extension!
So people can check the box when they whant to receive Email without 
approving each comment and
that they can define there path to the template for the email.

I found out that the file flexform_ds_spamprotect.xml contains the 
flexform where I want to add field.
But how could this work? Also through ext_tables.php?
No clue how this could work and where this information (if a box is 
checked or unchecked) is stored.
I looked in the mySQL DB but can't find any hint.


----------------------------------------------------

I bought dmitrys book yesterday...
I hope it will cover all this issues

Great help!
Thomas



Dmitry Dulepov schrieb:
> 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.
> 


More information about the TYPO3-english mailing list