Follow Sebastiaan de Jonge on Twitter
Sebastiaan de Jonge

Blog

27Sep

T3BLOG: Whitelist for comments

Posted on September 27, 2010 in Extensions by Sebastiaan de Jonge

Since I there are several people who frequently comment in my blog articles, I thought some kind of white list for these people would be a good idea. This would save me some time, so I wouldn't have to approve all their comments. This didn't exist in t3blog yet though..

What does exist is a hook in t3blog that is called after a comment is saved. Which would be perfect for my cause.

What does it do?

It's pretty simple, in your TYPO3 backend you can simply enter what should be checked for when a comment is posted. This can be one of the following: name, e-mail address and/or IP-address. Furthermore you can choose if all criteria should match, or if just one of the criteria is enough.

After a comment is posted, the extension will automatically check if the posted data matches this of the data in the whitelist. If it does, the comment is automatically approved.

Screenshots

t3blog 1.0.0

I initially developed this extension under t3blog 0.9.1. After I upgraded my own blog I discovered the extension no longer worked properly. After some research I discovered this was due to a bug in the most recent version of t3blog. It's something that is easy to fix, you just have to know about it.

So in case you are running t3blog 1.0.0 and you are interested in running this extension, you will be required to make the following changes.

T3BLOG 1.0.0 Fix 
  1. protected function insertNewComment(array $data) {
  2.         $data['pid'] = t3blog_div::getBlogPid();
  3.         $data['date'] = $data['crdate'] = $GLOBALS['EXEC_TIME'];
  4.         $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_t3blog_com', $data);
  5.         $commentUid = $GLOBALS['TYPO3_DB']->sql_insert_id(); // Add this
  6.         $this->updateRefIndex('tx_t3blog_com', $GLOBALS['TYPO3_DB']->sql_insert_id());
  7.  
  8.         // Hook after comment insertion
  9.         if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3blog']['aftercommentinsertion'])) {
  10.                 foreach($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3blog']['aftercommentinsertion'] as $userFunc) {
  11.                         $params = array(
  12.                                 'data' => &$data,
  13.                                 'table' => 'tx_t3blog_com',
  14.                                 'postUid' => $data['fk_post'],
  15.                                 'commentUid' => $commentUid, // Change this
  16.                         );
  17.                         t3lib_div::callUserFunction($userFunc, $params, $this);
  18.                 }
  19.         }
  20. }
protected function insertNewComment(array $data) {
	$data['pid'] = t3blog_div::getBlogPid();
	$data['date'] = $data['crdate'] = $GLOBALS['EXEC_TIME'];
	$GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_t3blog_com', $data);
	$commentUid = $GLOBALS['TYPO3_DB']->sql_insert_id(); // Add this
	$this->updateRefIndex('tx_t3blog_com', $GLOBALS['TYPO3_DB']->sql_insert_id());

	// Hook after comment insertion
	if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3blog']['aftercommentinsertion'])) {
		foreach($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3blog']['aftercommentinsertion'] as $userFunc) {
			$params = array(
				'data' => &$data,
				'table' => 'tx_t3blog_com',
				'postUid' => $data['fk_post'],
				'commentUid' => $commentUid, // Change this
			);
			t3lib_div::callUserFunction($userFunc, $params, $this);
		}
	}
}

This code can be found in the following file inside t3blog: 'pi1/widgets/blogList/class.singleFunctions.php' on line 783.

Of course, I have posted a bug report on TYPO3 Forge. The issue can be found here in the tracker.

Unpublished

Since this bug exists in the most recent version of t3blog I have decided to wait with publishing this to the TER. I will probably also still create a small manual. Of course the extension is included at the bottom of this post. As version 0.0.0, just for you to play around with.

Attached files

Arrow downt3blog_whitelist-0.0.0.t3x
5.1 K

Comments (1)

  1. Gravatar: Pim BroensPim Broenson September 27, 2010
    at 12:15
    Reply to this comment

    good idea

    What a great idea mate! glad you came up with it, might be an additional feature to select whitelist/blacklist in the element?
    That way you can also block people automatically with the same extension.

Got something to say?

 
Notify me when someone adds another comment to this post
 

Search

Categories

Tags

Archive

Blogroll

Syndicate