Skip to content

Commit

Permalink
mode cs fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dogmatic69 committed Nov 24, 2012
1 parent ca8e40c commit 2a8ea5c
Show file tree
Hide file tree
Showing 40 changed files with 656 additions and 686 deletions.
58 changes: 24 additions & 34 deletions Core/Comments/Config/config.php
@@ -1,36 +1,26 @@
<?php
/**
* Configuration defaults for the comments plugin
*
* Default options should always be overlaoded in the backend via the
* congfigs plugin.
*
* @filesource
* @copyright Copyright (c) 2010 Carl Sutton ( dogmatic69 )
* @link http://www.infinitas-cms.org
* @package Infinitas.Comments
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
* @since 0.8a
*
* @author Carl Sutton <dogmatic69@infinitas-cms.org>
*
*
*
*/
/**
* Configuration defaults for the comments plugin
*
* Default options should always be overlaoded in the backend via the
* congfigs plugin.
*
* @copyright Copyright (c) 2010 Carl Sutton ( dogmatic69 )
* @link http://www.infinitas-cms.org
* @package Infinitas.Comments
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
* @since 0.8a
*
* @author Carl Sutton <dogmatic69@infinitas-cms.org>
*/

$config['Comments'] = array(
/**
* configuration
*/
'auto_moderate' => true, // automatically accept and acticvate comments that are not spam
'purge' => '4 weeks', // automatic spam purge
'time_limit' => '4 weeks', // after this time commets are closed
'fields' => 'username,email,website,comment', // fileds for the form

/**
* rating params
*/
'spam_threshold' => -25, // below this things are just ignored
'maximum_links' => 2, // number of links before things are considered spammy
'minimum_length' => 20 // below this its spammy
);
$config['Comments'] = array(
'auto_moderate' => true, // automatically accept and acticvate comments that are not spam
'purge' => '4 weeks', // automatic spam purge
'time_limit' => '4 weeks', // after this time commets are closed
'fields' => 'username,email,website,comment', // fileds for the form

'spam_threshold' => -25, // below this things are just ignored
'maximum_links' => 2, // number of links before things are considered spammy
'minimum_length' => 20 // below this its spammy
);
221 changes: 106 additions & 115 deletions Core/Comments/Controller/CommentsAppController.php
@@ -1,118 +1,109 @@
<?php
/**
* @page Comments-Plugin Comments plugin
*
* @section charts-overview What is it
*
* The Comments plugin allows you to add comments to any row of data for your
* entire application by simply adding some fields to your database and including
* the elements where needed.
*
* The comments can be anything, not only comments in the sence of blogs. For
* example they could also be used for notes on shop orders, communication in
* a bugtracker etc.
*
* The fields used in the comments are flexible, having only the comment field
* and the users email address as required fields for the form. Adding extra
* fields to the form will be saved in a EAV table handled by the ExpandableBehavior
*
* @section categories-usage How to use it
*
* To get comments running in your plugin you will need to do a few things, first
* of which is adding a field to the table you wish to allow users to comment on
* The field should be called 'comment_count' and should be of type INT() MEDIUMINT()
* or any other integer type field you would require.
*
* After that has been done you will need to include the element for the comment
* form and latest comments in your views where you would like to see it. Example
* usage is below.
*
* The comments plugin uses a nifty rating system that checks a number of
* configurable details of the comment and gives it a score. If the score is
* too low it is regarded as spam. If it is below the threshold it will not
* even be saved. A number of factors are included in the score such as the lenght
* of the comment, the number of previous comments that were accepted and number
* of links that are in the comment body.
*
* @code
* // simple when using the correct conventions
* // infinitas will figure out the title, and where to save the comment
* echo $this->element('modules/comment', array('plugin' => 'comments'));
*
* // more advanced for wierd setups
* // when you dont use conventions you will need to tell infinitas what is what
* $this->element(
* 'modules/comment',
* array(
* 'plugin' => 'comments',
* 'content' => $model,
* 'modelName' => 'Model'
* )
* );
* @endcode
*
* @todo currently passing foreign_id which is not needed, the comment element
* should figure this out as the model is being passed. it can be obtained from
* the data using ->primaryKey
*
* That is all there is to it. Should you wish to do something really different
* you can overlaod the comment module in a theme. you can also change the
* plugin that is passed in the second param to anything you like should you
* overload it, just remember where and create the file in the corresponding
* directory. The other option is to just define your own comment element and
* call it in your view. Take note of the core one as there are some conditions
* that need to be met like setting the action of the form and the data that
* should be passed in.
*
*
* @section categories-code How it works
*
* Currently the comments are saved by a method in AppController::comment() so
* that you can just set the action to 'comment' and it will work as all controllers
* extend AppController they inherit the method.
*
* After the comment is submitted it under goes a rating and a score is determined
* for. It can then based on the configuration be accepted and marked as active
* automatically if it has passed, or if its edge case will be marked as pending
* for admin to later activte it. Comments with very low scores can be set to
* not save.
*
* @image html sql_comments_plugin.png "Comments Plugin table structure"
*
* @todo record ip addresses of people repeatedly entering comments and block
* them for a set time with the ip blocking stuff simmilar to the brute force
* attacks. can help reduce sever load by blackholing spam bots.
*
* @todo limit comments to x per hour or something (setting)
*
* @section categories-see-also Also see
* @ref EventCore
* @ref FilterHelper
* @ref GravatarHelper
* @ref ExpandableBehavior
* @ref ExpandableBehavior
*/
/**
* @page Comments-Plugin Comments plugin
*
* @section charts-overview What is it
*
* The Comments plugin allows you to add comments to any row of data for your
* entire application by simply adding some fields to your database and including
* the elements where needed.
*
* The comments can be anything, not only comments in the sence of blogs. For
* example they could also be used for notes on shop orders, communication in
* a bugtracker etc.
*
* The fields used in the comments are flexible, having only the comment field
* and the users email address as required fields for the form. Adding extra
* fields to the form will be saved in a EAV table handled by the ExpandableBehavior
*
* @section categories-usage How to use it
*
* To get comments running in your plugin you will need to do a few things, first
* of which is adding a field to the table you wish to allow users to comment on
* The field should be called 'comment_count' and should be of type INT() MEDIUMINT()
* or any other integer type field you would require.
*
* After that has been done you will need to include the element for the comment
* form and latest comments in your views where you would like to see it. Example
* usage is below.
*
* The comments plugin uses a nifty rating system that checks a number of
* configurable details of the comment and gives it a score. If the score is
* too low it is regarded as spam. If it is below the threshold it will not
* even be saved. A number of factors are included in the score such as the lenght
* of the comment, the number of previous comments that were accepted and number
* of links that are in the comment body.
*
* @code
* // simple when using the correct conventions
* // infinitas will figure out the title, and where to save the comment
* echo $this->element('modules/comment', array('plugin' => 'comments'));
*
* // more advanced for wierd setups
* // when you dont use conventions you will need to tell infinitas what is what
* $this->element(
* 'modules/comment',
* array(
* 'plugin' => 'comments',
* 'content' => $model,
* 'modelName' => 'Model'
* )
* );
* @endcode
*
* That is all there is to it. Should you wish to do something really different
* you can overlaod the comment module in a theme. you can also change the
* plugin that is passed in the second param to anything you like should you
* overload it, just remember where and create the file in the corresponding
* directory. The other option is to just define your own comment element and
* call it in your view. Take note of the core one as there are some conditions
* that need to be met like setting the action of the form and the data that
* should be passed in.
*
*
* @section categories-code How it works
*
* Currently the comments are saved by a method in AppController::comment() so
* that you can just set the action to 'comment' and it will work as all controllers
* extend AppController they inherit the method.
*
* After the comment is submitted it under goes a rating and a score is determined
* for. It can then based on the configuration be accepted and marked as active
* automatically if it has passed, or if its edge case will be marked as pending
* for admin to later activte it. Comments with very low scores can be set to
* not save.
*
* @image html sql_comments_plugin.png "Comments Plugin table structure"
*
* @section categories-see-also Also see
* @ref EventCore
* @ref FilterHelper
* @ref GravatarHelper
* @ref ExpandableBehavior
*/

App::uses('AppController', 'Controller');
App::uses('AppController', 'Controller');

/**
* CommentsAppController is the base class that all comments controllers extend
*
* @copyright Copyright (c) 2010 Carl Sutton ( dogmatic69 )
* @link http://www.infinitas-cms.org
* @package Infinitas.Comments
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
* @since 0.8a
*
* @author Carl Sutton <dogmatic69@infinitas-cms.org>
*/
class CommentsAppController extends AppController{
/**
* some helpers to load for this plugin
*
* @var array
*/
public $helpers = array(
'Libs.Gravatar'
);
}
/**
* CommentsAppController is the base class that all comments controllers extend
*
* @copyright Copyright (c) 2010 Carl Sutton ( dogmatic69 )
* @link http://www.infinitas-cms.org
* @package Infinitas.Comments
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
* @since 0.8a
*
* @author Carl Sutton <dogmatic69@infinitas-cms.org>
*/

class CommentsAppController extends AppController{

/**
* some helpers to load for this plugin
*
* @var array
*/
public $helpers = array(
'Libs.Gravatar'
);
}
94 changes: 47 additions & 47 deletions Core/Comments/Controller/Component/CommentsComponent.php
@@ -1,51 +1,51 @@
<?php
App::uses('InfinitasComponent', 'Libs.Controller/Component');
/**
* Comments component
*
*
*/
class CommentsComponent extends InfinitasComponent {
/**
* allow posting comments to any controller
*
* @todo this needs to be moved to the Comments plugin and is part of
* the reason this code needs to be more extendable
*
* @return void
*/
public function actionComment() {
if (!empty($this->Controller->request->data[$this->Controller->modelClass.'Comment'])) {
$message = 'Your comment has been saved and will be available after admin moderation.';
if (Configure::read('Comments.auto_moderate') === true) {
$message = 'Your comment has been saved and is active.';
}

$this->Controller->request->data[$this->Controller->modelClass.'Comment']['ip_address'] = $this->Controller->request->clientIp();
$this->Controller->request->data[$this->Controller->modelClass.'Comment']['class'] = $this->Controller->request->plugin . '.' . $this->Controller->modelClass;

if (!empty($this->Controller->request->data[$this->Controller->modelClass.'Comment']['om_non_nom'])) {
$this->Controller->Session->write('Spam.bot', true);
$this->Controller->Session->write('Spam.detected', time());

$this->Controller->notice(
__d('comments', 'Not so fast spam bot.'),
array(
'redirect' => '/?bot=true'
)
);
}

if ($this->Controller->{$this->Controller->modelClass}->createComment($this->Controller->request->data)) {
$this->Controller->notice(
__d('comments', $message),
array('redirect' => true)
);
}

$this->Controller->notice('not_saved');
App::uses('InfinitasComponent', 'Libs.Controller/Component');
/**
* Comments component
*
*
*/

class CommentsComponent extends InfinitasComponent {

/**
* Allow posting comments to any controller
*
* @return void
*/
public function actionComment() {
$modelClass = $this->Controller->modelClass . 'Comment';
if (!empty($this->Controller->request->data[])) {
$message = 'Your comment has been saved and will be available after admin moderation.';
if (Configure::read('Comments.auto_moderate') === true) {
$message = 'Your comment has been saved and is active.';
}

return $this->Controller->render(null, null, App::pluginPath('Comments') . 'View' . DS . 'InfinitasComments' . DS . 'add.ctp');
$this->Controller->request->data[$modelClass]['ip_address'] = $this->Controller->request->clientIp();
$this->Controller->request->data[$modelClass]['class'] = $this->Controller->request->plugin . '.' . $this->Controller->modelClass;

if (!empty($this->Controller->request->data[$modelClass]['om_non_nom'])) {
$this->Controller->Session->write('Spam.bot', true);
$this->Controller->Session->write('Spam.detected', time());

$this->Controller->notice(
__d('comments', 'Not so fast spam bot.'),
array(
'redirect' => '/?bot=true'
)
);
}

if ($this->Controller->{$this->Controller->modelClass}->createComment($this->Controller->request->data)) {
$this->Controller->notice(
__d('comments', $message),
array('redirect' => true)
);
}

$this->Controller->notice('not_saved');
}
}

return $this->Controller->render(null, null, App::pluginPath('Comments') . 'View' . DS . 'InfinitasComments' . DS . 'add.ctp');
}
}

0 comments on commit 2a8ea5c

Please sign in to comment.