[TYPO3] Extension "comments" notification without the need to approve each comment?
Thomas Hirt
info at thomas-hirt.at
Thu Oct 2 19:01:53 CEST 2008
Hi!
I did my first steps creating a hook for comments.
Basically it seems to work. See the code below.
When someone fills in the emailfields of the extension flexform without
checking the checkbox for approval it will send an email out of a
template file.
I basically have three questions:
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?
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?
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.
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
<?php
if (!defined ('TYPO3_MODE')) die ('Access denied.');
// New columns
$tempColumns = array (
'tx_commentsemail_enable' => Array (
'exclude' => 1,
'label' =>
'LLL:EXT:comments_email/locallang_db.xml:tx_commentsemail_enable',
'config' => array (
'type' => 'check',
'items' => array(
array('', '')
),
'default' => '0'
)
),
);
// tt_news
if (isset($TCA['tt_news'])) {
t3lib_div::loadTCA('tt_news');
t3lib_extMgm::addTCAcolumns('tt_news', $tempColumns, 1);
$TCA['tt_news']['ctrl']['requestUpdate'] = ',tx_commentsemail_enable';
}
// tx_commerce_products
if (isset($TCA['tx_commerce_products'])) {
t3lib_div::loadTCA('tx_commerce_products');
t3lib_extMgm::addTCAcolumns('tx_commerce_products', $tempColumns, 1);
$TCA['tx_commerce_products']['ctrl']['requestUpdate'] =
',tx_commentsemail_enable';
}
?>
AND
pi1/class.tx_commentsemail_hooks.php
<?php
require_once(PATH_tslib . 'class.tslib_pibase.php');
class tx_commentsemail_hooks extends tslib_pibase {
function hookFunc(&$params, &$pObj) {
$checkSpamProtect = $pObj->conf['spamProtect.']['requireApproval'];
$toEmail = $pObj->conf['spamProtect.']['notificationEmail'];
$fromEmail = $pObj->conf['spamProtect.']['fromEmail'];
if (($checkSpamProtect==0) && t3lib_div::validEmail($toEmail) &&
t3lib_div::validEmail($fromEmail)) {
$commentUri = $_SERVER['SCRIPT_URI'];
$commentFirstName = $params['record']['firstname'];
$commentLastName = $params['record']['lastname'];
$commentEmail = $params['record']['email'];
$commentLocation = $params['record']['location'];
$commentHomepage = $params['record']['homepage'];
$commentContent = $params['record']['content'];
$commentRemoteAddr = $params['record']['remote_addr'];
$templateCode =
$pObj->cObj->fileResource("EXT:comments_email/res/email.txt");
$markers = array(
'###URL###' => t3lib_div::getIndpEnv('TYPO3_REQUEST_URL'),
'###FIRSTNAME###' => $commentFirstName,
'###LASTNAME###' => $commentLastName,
'###EMAIL###' => $commentEmail,
'###LOCATION###' => $commentLocation,
'###HOMEPAGE###' => $commentHomepage,
'###CONTENT###' => $commentContent,
'###REMOTE_ADDR###' => t3lib_div::getIndpEnv('REMOTE_ADDR'),
);
$content = $pObj->cObj->substituteMarkerArray($templateCode, $markers);
$subject = $pObj->pi_getLL('email.subject');
t3lib_div::plainMailEncoded($toEmail, $subject, $content, 'From: ' .
$fromEmail);
}
//exit ("exit");
}
}
if (defined('TYPO3_MODE') &&
$TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/comments_email/pi1/class.tx_commentsemail_hooks.php'])
{
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/comments_email/pi1/class.tx_commentsemail_hooks.php']);
}
I hope Dmitry book will come out soon and I hope it covers some of this
basic issues, thanks,
Thomas
?>
Dmitry Dulepov schrieb:
>
> If it is a hook, use $pObj instead of $this to access functions from
> tslib_pibase.
>
More information about the TYPO3-english
mailing list