DEPRECATION WARNING

This documentation is not using the current rendering mechanism and is probably outdated. The extension maintainer should switch to the new system. Details on how to use the rendering mechanism can be found here.

Comments

Author:Dmitry Dulepov
Created:2002-11-01T00:32:00
Changed:2013-07-12T12:40:59
Email:dmitry@typo3.org
Info 1:Dmitry Dulepov
Info 2:
Info 3:
Info 4:

Comments

Extension Key: comments

Copyright 2007-2008, Dmitry Dulepov <dmitry@typo3.org>

Copyright 2008-2013, Ingo Renner <ingo@typo3.org>

This document is published under the Open Content License

available from http://www.opencontent.org/opl.shtml

The content of this document is related to TYPO3

- a GNU/GPL CMS/Framework available from typo3.org

Table of Contents

Commenting system 1

Introduction 1

What does it do? 1

Features 1

Screenshots 2

Acknowledgments 3

Having questions? 3

Users manual 3

Inserting comments to page 3

Customizing comments 4

Approving comments 5

FAQ 5

Administration 6

Adding TypoScript template 6

Configuration 6

Main configuration 6

Advanced options (->ADVANCED) 7

Spam protection (->SPAMPROTECT) 7

Prefix-to-table map (->PREFIXMAP) 8

showUid map (->SHOWUIDMAP) 8

Using comments in other extensions 8

tt_news 8

Hooks 9

Using hooks 9

Common hook parameters 9

List of hooks 9

Translating the extension 10

To-Do list 10

Introduction

What does it do?

This extension provides commenting capabilities to TYPO3 pages or to virtually any TYPO3 record available in frontend in a single view (like single news item, single album image, etc).

Features

  • Comment pages
  • Comment records
  • Comments are displayed in pages
  • Highly customizable template, for example:
    • Number of messages per page
    • Show/hide fields to comments
  • Available fields (labels can be customized):
    • First name
    • Last name
    • E-mail
    • Home page
    • Location (city, for example)
    • Comment
  • Set fields as required or optional
  • E-mail address syntax validation
  • Fully localizable (including date format through PHP strtoftime() function)
  • Automatically clear cache for any page(s) when comment is added
  • Close comments after predefined period
  • Close comments for individual records immediately or after period (through supplemental comments_ic extension)
  • Prevent duplicate comments (for example, several subsequent POST requests)
  • See IP address of the commenter in BE
  • Spam control
    • Filter out typical guestbook spam
    • Force all messages to pass approval
    • Automatically decide if message should be approved before it can appear on the web page
    • Send e-mail to designated e-mail address about suspicious messages
    • Hook to connect external spam checkers
  • Full TYPO3 caching supported (USER object!), which highly improves web site performance
  • Automatic cleanup: removes comments if "parent" record is removed
  • External CSS stylesheet can be included through the template (no need to modify web site TS setup for this!)
  • Automatically use FE user data to fill comment form
  • Extends tt_news to show number of comments in LIST, SEARCH and LATEST views
  • Integrates ratings from “ratings” extension
  • Automatically find links in comment text and convert them to clickable links (can be turned on and off)
  • Lots of hooks to customize comments

Screenshots

There are screenshots also in other sections of this manual. This screenshot shows the default template with default styles with ratings enabled.

img-1

Users manual

Inserting comments on a page

When inserting a new content element, scroll down to the end of the "New content element" wizard and select "Comments":

img-2

This will insert a plugin for commentis as a new content element. This operation has to be done twice: once for comment list, another for the comment form. See next section for details on configuring the plugin.

Customizing comments

All comments options can be configured either through TypoScript or through the plugin's configuration when it is inserted as a content element. TypoScript configuration should be used when the plugin is inserted through TypoScript. For information on TypoScript configuration options see "Configuration" section later in this manual.

Warning! Flexform configuration will always override the TypoScript configuration when corresponding field is set!

Plugin configuration consists of several tabs.

General tab

img-3

Mode defines what the plugin displays: comment listing and/or form to add comments.

Triggering prefix defines what parameter in the URL triggers rendering of comments. The value depends on another plugin and its URL GET parameters. Typically this parameter is something like tx_extkey_pi1 but other plugins may have different values (for example, tx_ttnews for the tt_news plugin). The special value pages allows to comment on pages instead of records. Note for plugin authors: Please read the Configuration section for information about enabling comments for your extension.

Storage page specifies where records should be stored. If empty, current the page is used. You probably want to set this using TypoScript.

Template file defines the template file to be used. It can either be a path relative to the web site root (like fileadmin/templates/comments.tmpl ) or an extension path (for example, EXT:comments/res/pi1_template ).

Advanced tab

img-4

Comments per page specifies how many comments to show per page.

Close commenting after allows to automatically disable commenting if a record is older than the specified time. The time is a number followed by suffix. The suffix can be h (hour), m (month), y (year) or d (day). The comments extension takes care to change the page caching time so that the page cache expires when comments should be closed.

Enable ratings enables ratings for comment items. This option is only available if EXT:ratings is installed. Note that users may rate comments only if comments are not closed for the item. If comments are closed, users will see the ratings but will not be able to rate comments further. The option to close comments must be set not only on form but also on the comments list plugin instance.

Show newer comments first reverses the sorting order for the comment listing. Normally comments are display from oldest to newest. Checking this option reverses the order and newer comments are show first.

Anti-spam tab

img-5

Require approval of each comment puts comments on hold and sends an e-mail to the e-mail address provided in Send notification to this e-mail with comment information (submitted form fields) and links to approve, delete or kill (i.e. completely remove from database). Approving comment also clears cache for the page and approved comment appears on the page.

Check referrer makes the extension check that a request comes from the current web site. This option may have undesired results because many firewalls block referrer information and some browsers do not send this information reliably. It is not recommended to use this option unless you are really paranoid.

Use captcha allows to select one of two captcha extensions ( captcha or sr_freecap ) to use while submitting comments. The corresponding extension must be installed. The comments extension already has good spam catching capabilities, so you may want to try without any captcha first (captchas usually annoy users very much).

Send notification to this e-mail specifies the e-mail address where to send messages with links to approve or delete comments.

Send e-mail from this address specifies th "From" e-mail address for notifications about new comments.

Template file for e-mails sets the template file for e-mails.

Approving comments

If a comment is set to “disapproved” because it may be spam or the Require approval of each comment option is set, comments will not be visible on the page instantly. An administrator will receive a notification e-mail with links to approve or reject comments. Alternatively it can be done through Web>List module. Disapproved comments have different icon in the List module:

img-6

The first comment record in the screenshot above is a disapproved comment. When opened for editing, this flag will set whether a comment is approved or not:

img-7

If the checkbox is set, the comment is approved.

Administration

Adding TypoScript template

The extension's TypoScript template must be added to site's TypoScript template for the plugins to work. To add a template, go to the Template submodule in the Web module, click Info/Modify and then Click here to edit whole template record . In the go to Include static (from extensions) and select Comments (comments) in the right box. It should then be added in the left box.

img-8

Configuration Reference

Main configuration

code

Property

code

Data type

string

Description

COMMENTS or FORM. Shows a comment list or the form to submit comments.

Default

COMMENTS

storagePid

Property

storagePid

Data type

integer / list of integers

Description

The page uid where comment records will be stored. If this is empty, the current page will be used.

Starting with version 1.4.0 this can be a comma-separated list of page UID values. Comments will search in all these pages but will save comments to the first page in this list.

Default

empty (value of {$plugin.tx_comments_pi1.storagePid} constant)

externalPrefix

Property

externalPrefix

Data type

string

Description

See Triggering prefix in User guide.

Default

tx_ttnews (the value of {$plugin.tx_comments_pi1.externalPrefix} constant

templateFile

Property

templateFile

Data type

string

Description

Template file for the plugin. Accepts either site-relative path or extension-related path (EXT: prefix)

Default

EXT:comments/res/pi1_template.html (value of {$plugin.tx_comments_pi1.templateFile} constant)

additionalClearCachePages

Property

additionalClearCachePages

Data type

list of integers

Description

Addition page uids to clear when a comment is submitted or approved.

Default

advanced

Property

advanced

Data type

->ADVANCED

Description

Default

preventDuplicatePosts

Property

preventDuplicatePosts

Data type

boolean

Description

If set, prevents duplicate comments on the same page

Default

1

requiredFields

Property

requiredFields

Data type

list of values

Description

Comma-separated list of fields to be required for comments. Available values:

  • firstname
  • lastname,
  • email
  • homepage
  • location
  • content

Default

firstname,email,content

spamProtect

Property

spamProtect

Data type

->SPAMPROTECT

Description

Default

requiredFields_errorWrap

Property

requiredFields_errorWrap

Data type

stdWrap

Description

stdWrap for required field if field is not filled properly

Default

noTrimWrap = |<span class="tx-comments-required-error">Error: |</span>|

prefixToTableMap

Property

prefixToTableMap

Data type

->PREFIXMAP

Description

Default

showUidMap

Property

showUidMap

Data type

->SHOWUIDMAP

Description

Default

ratingsConfig

Property

ratingsConfig

Data type

“ratings” plugin configuration

Description

Allows to specify alternative confguration for the ratings plugin. Typical usage:

ratingsConfig < plugin.tx_ratings_pi1
ratingsConfig.additionalCSS = EXT:myext/res/ratings_css_for_comments.css

Obviously userFunc is ignored. This parameter is not defined by default and completely optional. If default ratings configurations suits your needs, do not define this parameter.

Default

empty

firstName_stdWrap

Property

firstName_stdWrap

Data type

string

Description

Wraps “First name” field

Default

empty

lastName_stdWrap

Property

lastName_stdWrap

Data type

string

Description

Wraps “Last name” field

Default

empty

email_stdWrap

Property

email_stdWrap

Data type

string

Description

Wraps “E-mail” field

Default

empty

webSite_stdWrap

Property

webSite_stdWrap

Data type

string

Description

Wraps “Web site” field

Default

empty

location_stdWrap

Property

location_stdWrap

Data type

string

Description

Wraps “Location” field

Default

empty

content_stdWrap

Property

content_stdWrap

Data type

string

Description

Wraps “Content” field

Default

empty

Advanced options (->ADVANCED)

commentsPerPage

Property

commentsPerPage

Data type

int

Description

Number of comments per page

Default

100 (value of {$plugin.tx_comments_pi1.commentsPerPage} constant)

closeCommentsAfter

Property

closeCommentsAfter

Data type

string

Description

If set, automatically disables commenting for items older than this period. See Close commenting after in the User manual for more information.

Default

empty

dateFormat

Property

dateFormat

Data type

string

Description

Defines date format to use for date/time information about posts. Format specifiers depend on dateFormatMode configuration option. See PHP function date() and strftime() for information about format specifiers. If empty, defaults to concatenation of SYS->ddmmyy and SYS->hhmm system variables (from Install tool) and dateFormatMode is foreced to “date”

Default

empty

dateFormatMode

Property

dateFormatMode

Data type

string

Description

Determines what PHP function to use for date formatting. Defaults to “date”. If you want to use month or week days in national language, you have to use “strftime”.

Valid values are:

  • date
  • strftime

Default

date

preFillFormFromFeUser

Property

preFillFormFromFeUser

Data type

boolean

Description

If enabled and a FE user is logged in, fills form data with the information from the FE user record. If sr_feuser_register is installed, attempts to use its fields too

Default

1

enableRatings

Property

enableRatings

Data type

boolean

Description

If EXT:ratings is installed, allows users to rate comments. Note that ratings are only available if comments are not closed for an item. When comments are closed, ratings automatically become read-only.

Default

0

reverseSorting

Property

reverseSorting

Data type

boolean

Description

Reverses sorting order of comments in list view. Normally comments are sorted from oldest to newest.

Default

0

Spam protection (->SPAMPROTECT)

requireApproval

Property

requireApproval

Data type

boolean

Description

If enabled, messages will be disapproved by default and a notification email will be sent to an administrator (see notificationEmail below). If approval is not set to required but checkTypicalSpam is set, messages can still be set to disapproved automatically and a notification is sent.

Default

1 (value of {$plugin.tx_comments_pi1.requireApproval} constant)

useCaptcha

Property

useCaptcha

Data type

string

Description

Enables using captcha to post comments. Possible values are:

  • 0 – do not use captcha
  • 1 – use captcha extension
  • 2 – use sr_freecap extension

If value is not 0, corresponding extension must be installed to TYPO3

Default

0 (value of {$plugin.tx_comments_pi1.useCaptcha} constant)

checkTypicalSpam

Property

checkTypicalSpam

Data type

boolean

Description

If set, the extension automatically checks all comments for typical spam. If comments receive more than 1000 spam points, it is automatically set to disapproved and a notification is sent to the author.

Default

1

considerReferer

Property

considerReferer

Data type

boolean

Description

If set, checks that the referer of the current page is within the same/current web site. If not, a comment is set to disapproved and a notification is sent to an administrator. See Check referer in User guide for more information and possible risks associated with this option.

Default

0

notificationEmail

Property

notificationEmail

Data type

string

Description

E-mail address to send notifications to

Default

fromEmail

Property

fromEmail

Data type

string

Description

E-mail address to send notifications from

Default

emailTemplate

Property

emailTemplate

Data type

string

Description

E-mail template. See Template file for e-mails in User guide for more information

Default

EXT:comments/res/email.txt

spamCutOffPoint

Property

spamCutOffPoint

Data type

integer

Description

If the number of points is greater than this value, a comment is ignored, the user receives a spam warning message and no approval e-mail is sent to an administrator.

Default

1000

Prefix-to-table map (->PREFIXMAP)

The comments extension must know the table name of the commented record to perform automatic cleanup. The extension's configuration contains a map of triggering prefix names to table names. By default it looks like:

prefixToTableMap.tx_album3x_pi1 = tx_album3x_images
prefixToTableMap.tx_commerce_pi1 = tx_commerce_products
prefixToTableMap.tx_irfaq_pi1 = tx_irfaq_q
prefixToTableMap.tx_mininews_pi1 = tx_mininews_news
prefixToTableMap.tx_ttnews = tt_news
prefixToTableMap.tx_news_pi1 = tx_news_domain_model_news

Extension authors who want to enable commenting for their records, may add entries to setup.txt for their own extension to extend this map. Here is an example:

plugin.tx_comments_pi1.prefixToTableMap.tx_myext_pi1 = tx_myext_mytable

So, if the URL looks like this:

http://www.example.com/index.php?id=12345&tx_myext_pi1[showUid]=67890

than the comments extension will understand that it must refer to tx_myext_mytable for triggering prefix tx_myext_pi1.

showUid map (->SHOWUIDMAP)

By default EXT:comments will try to get the commented record's uid using the showUid GET parameter. The comments extension needs to know the name to find the record's uid. By default, only EXT:tt_news and EXT:news are configured:

showUidMap.tx_ttnews = tt_news
showUidMap.tx_news_pi1 = news

It is possible to use custom parameters with the comments extension, here is an example:

plugin.tx_comments_pi1.showUidMap.tx_myext_pi1 = uid

So, if the URL looks like this:

http://www.example.com/index.php?id=12345&tx_myext_pi1[uid]=67890

than the comments extension will understand that the record's uid value is 67890.

Using comments in other extensions

tt_news

The comments extension provides a custom marker for tt_news to display the number of comments in List, Latest and Search views. The marker is ###TX_COMMENTS_COUNT###. By default it will produce the following HTML:

<a href="url/to/news/item#tx-comments-comments-uid" class="tx-comments-count">5 comments(s)</span>

This HTML can be customized by modifying the template that ships with the comments extension. See ###TTNEWS_COMMENT_COUNT_SUB### subpart in the template. The tt_news marker is typically included after the “more” link.

Hooks

Using hooks

New hooks can be used from other extensions using the following code in ext_localconf.php in the other extension:

$TYPO3_CONF_VARS['EXTCONF']['comments'][hookName][yourextkey] = 'EXT:yourextkey/class.tx_yourextkey_hooks.php:&tx_yourextkey_hooks->methodName';

Common hook parameters

Each hook uses two arguments:

$params

Argument

$params

Type

array

Description

Contains hook parameters (specific for each hook, see hooks list below) and 'pObj', which is identical to $pObj hook parameter.

$pObj

Argument

$pObj

Type

tx_comments_pi1

Description

Reference to calling class.

Available hooks

closeCommentsAfter

This hook is called when deciding whether commenting is closed for an item.

table

Argument

table

Type

string

Description

Table name

uid

Argument

uid

Type

int

Description

uid of the record

The hook should return an integer Unix time value to indicate if commenting for the item is closed. Returning “false” means “do not know”. The first integer value stops processing of other hooks.

comments

This hook is called when the marker array is prepared for rendering the comments list as whole.

template

Argument

template

Type

string

Description

Template subsection to be used

markers

Argument

markers

Type

array

Description

Existing markers

The hook should return a modified array with markers.

comments_getComments

This hook is called when the marker array is prepared for rendering a single comment in a list.

template

Argument

template

Type

string

Description

Template subsection to be used

markers

Argument

markers

Type

array

Description

Existing markers

row

Argument

row

Type

array

Description

Current comment record

The hook should return a modified array with markers.

externalSpamCheck

This hook is called when checking messages for spam. Hook can add or remove spam points based on its own logic.

formdata

Argument

formdata

Type

array

Description

A shortcut $pObj->piVars

points

Argument

points

Type

int

Description

Currently earned points

The hook should return integer value, which will be added to the current number of spam points. To block a message completely the accumulated points value must be greater than “spamProtect.spamCutOffPoint”.

eID_postProc

This hook is called by the eID script when approving or deleting comments using the link in the notificatiion e-mail. It allows to post-process e-mail commands. The hook does not receive any custom parameters.

form

This hook is called when the marker array is prepared for rendering the form.

template

Argument

template

Type

string

Description

Template subsection to be used

markers

Argument

markers

Type

array

Description

Existing markers

The hook should return a modified array with markers.

mergeConfiguration

This hook allows to alter/add configuration values for tx_comments_pi1. There are no additional parameters to the hook. The hook should modify the configuration in the following way:

$pObj->conf['section.']['param']='value';

processSubmission

This hook is executed before a comment record is inserted into the database.

record

Argument

record

Type

array

Description

Record array

The hook should return a modified record array.

sendNotificationMail

This hook is called when the marker array is prepared for sending the notification email to an administrator.

template

Argument

template

Type

string

Description

Template subsection to be used

check

Argument

check

Type

string

Description

Hashed check value for eID call

markers

Argument

markers

Type

array

Description

Existing markers

The hook should return a modified array with markers.

processValidComment

This hook is called when a comment is posted and visible on the web site. It is not called when comment is approved by the administrator manually!

uid

Argument

uid

Type

integer

Description

uid of the new comment record

Return value is ignored.

Comments - 10