Skip to content

Commit

Permalink
finished up commentable integration, adding form to test email sendin…
Browse files Browse the repository at this point in the history
…g in newsletter manager.
  • Loading branch information
dogmatic69 committed Dec 29, 2009
1 parent becc57f commit f22ee63
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 28 deletions.
32 changes: 15 additions & 17 deletions app/app_controller.php
Expand Up @@ -146,34 +146,32 @@ private function __setupCache()
* Common methods for the app
*/

protected function comment()
protected function comment($id = null)
{
if ( !empty( $this->data ) )
if ( !empty( $this->data['Comment'] ) )
{
if ( !isset( $this->data[Inflector::classify( $this->name )]['id'] ) )

$message = 'Your comment has been saved and will be available after admin moderation.';
if ( Configure::read( 'Comments.auto_moderate' ) === true )
{
$this->Session->setFlash( __( 'There is a problem with your comment.', true ) );
$this->redirect( $this->referer() );
$this->data['Comment']['active'] = 1;
$message = 'Your comment has been saved and is active.';
}

$this->data['Comment']['foreign_id'] = $this->data[Inflector::classify( $this->name )]['id'];
$this->data['Comment']['class'] = $this->__getClassName();

$comment['Comment'] = $this->data['Comment'];

ClassRegistry::init( 'Core.Comment' )->create();

if ( ClassRegistry::init( 'Core.Comment' )->save( $comment ) )
if ( $this->Post->createComment( $id, $this->data ) )
{
$this->Session->setFlash( __( 'Your comment has been saved for review.', true ) );
$this->redirect( $this->referer() );
$this->Session->setFlash( __( $message, true ) );
$this->redirect( array( 'action' => 'view', $this->data[$this->modelClass]['id'] ) );
}

$this->Session->setFlash( __( 'Your comment could not be saved, please try again.', true ) );
$this->redirect( $this->referer() );
else
{
$this->Session->setFlash( __( 'Your comment was not saved. Please check for errors and try again', true ) );
}
}
}


function __getClassName()
{
if ( isset( $this->params['plugin'] ) )
Expand Down
3 changes: 2 additions & 1 deletion app/plugins/blog/models/post.php
Expand Up @@ -33,7 +33,8 @@ class Post extends BlogAppModel
var $actsAs = array(
'Core.Sluggable',
'Core.Viewable',
'Core.Feedable'
'Core.Feedable',
'Core.Commentable'
);

var $validate = array(
Expand Down
3 changes: 3 additions & 0 deletions app/plugins/blog/views/posts/comment.ctp
@@ -0,0 +1,3 @@
<?php
echo $this->element( 'comments/add', array( 'plugin' => 'core', 'fk' => $this->data['Post']['id'] ) );
?>
43 changes: 33 additions & 10 deletions app/plugins/core/models/behaviors/commentable.php
Expand Up @@ -30,6 +30,7 @@ class CommentableBehavior extends ModelBehavior
'class' => 'Comment', // name of Comment model
'foreign_key' => 'foreign_id', // foreign key of Comment model
'counter_cache' => true,
'counter_cache_scope' => array( 'Comment.active' => 1 ),
'dependent' => true, // model dependency
'conditions' => array(), // conditions for find method on Comment model
'auto_bind' => true, // automatically bind the model to the User model (default true),
Expand All @@ -40,7 +41,7 @@ class CommentableBehavior extends ModelBehavior
'column_email' => 'email', // Column name for the authors email
'column_website' => 'website', // Column name for the authors website
'column_foreign_id' => 'foreign_id', // Column name of the foreign id that links to the article/entry/etc
'column_status' => 'active', // Column name for automatic rating
'column_status' => 'status', // Column name for automatic rating
'column_points' => 'points', // Column name for accrued points
'blacklist_keywords' => array(
'levitra', 'viagra', 'casino', 'sex', 'loan', 'finance',
Expand Down Expand Up @@ -88,10 +89,12 @@ function setup( &$model, $settings = array() )
'foreignKey' => $this->__settings[$model->alias]['foreign_key'],
'dependent' => $this->__settings[$model->alias]['dependent'],
'conditions' => $this->__settings[$model->alias]['conditions'] ) );

$commentBelongsTo = array( $model->alias => array(
'className' => $model->alias,
'foreignKey' => $this->__settings[$model->alias]['foreign_key'],
'counterCache' => $this->__settings[$model->alias]['counter_cache']
'counterCache' => $this->__settings[$model->alias]['counter_cache'],
'counterScope' => $this->__settings[$model->alias]['counter_cache_scope']
)
);
$model->bindModel( array( 'hasMany' => $hasManyComment ), false );
Expand Down Expand Up @@ -151,6 +154,17 @@ function createComment( &$model, $id, $data = array() )
$data[$this->__settings[$model->alias]['class']][$this->__settings[$model->alias]['column_class']] = $model->alias;
$data[$this->__settings[$model->alias]['class']][$this->__settings[$model->alias]['column_foreign_id']] = $id;
$data[$this->__settings[$model->alias]['class']] = $this->_rateComment( $model, $data['Comment'] );

if ( $data[$this->__settings[$model->alias]['class']]['status'] == 'spam' )
{
$data[$this->__settings[$model->alias]['class']]['active'] == 0;
}

else if ( Configure::read( 'Comments.auto_moderate' ) === true && $data[$this->__settings[$model->alias]['class']]['status'] != 'spam')
{
$data[$this->__settings[$model->alias]['class']]['active'] == 1;
}

if ( $this->__settings[$model->alias]['sanitize'] )
{
App::import( 'Sanitize' );
Expand Down Expand Up @@ -243,11 +257,11 @@ function _rateLinks( $model, $data )
$data[$this->__settings[$model->alias]['column_content']], $matches );
$links = $matches[0];

$totalLinks = count( $links );
$this->totalLinks = count( $links );
$length = mb_strlen( $data[$this->__settings[$model->alias]['column_content']] );
// How many links are in the body
// -1 per link if over 2, otherwise +2 if less than 2
$points = ( $totalLinks > 2 ) ? $totalLinks * - 1 : 2;
$points = ( $this->totalLinks > 2 ) ? $totalLinks * - 1 : 2;
// URLs that have certain words or characters in them
// -1 per blacklisted word
// URL length
Expand All @@ -274,13 +288,18 @@ function _rateLength( $model, $data )
// How long is the body
// +2 if more then 20 chars and no links, -1 if less then 20
$length = mb_strlen( $data[$this->__settings[$model->alias]['column_content']] );
if ( $length >= 20 && $totalLinks <= 0 )

if ( $length >= 20 && $this->totalLinks <= 0 )
{
return 2;
} elseif ( $length >= 20 && $totalLinks == 1 )
}

elseif ( $length >= 20 && $this->totalLinks == 1 )
{
return 1;
} elseif ( $length < 20 )
}

elseif ( $length < 20 )
{
return - 1;
}
Expand All @@ -291,13 +310,15 @@ function _rateEmail( $model, $data )
$points = 0;
// Number of previous comments from email
// +1 per approved, -1 per spam
$comments = $model->Comment->find( 'all', array(
$comments = $model->Comment->find(
'all', array(
'fields' => array( 'Comment.id', 'Comment.status' ),
'conditions' => array(
'Comment.' . $this->__settings[$model->alias]['column_email'] => $data[$this->__settings[$model->alias]['column_email']] ),
'recursive' => - 1,
'contain' => false
) );
)
);

if ( !empty( $comments ) )
{
Expand All @@ -306,7 +327,9 @@ function _rateEmail( $model, $data )
if ( $comment['Comment']['status'] == 'spam' )
{
--$points;
} elseif ( $comment['Comment']['status'] == 'approved' )
}

elseif ( $comment['Comment']['status'] == 'approved' )
{
++$points;
}
Expand Down
24 changes: 24 additions & 0 deletions app/plugins/newsletter/controllers/campaigns_controller.php
Expand Up @@ -167,6 +167,30 @@ function admin_toggle( $id = null )

function admin_delete( $id = null )
{

if ( !$id )
{
$this->Session->setFlash( 'That Campaign could not be found', true );
$this->redirect( $this->referer() );
}

$campaign = $this->Campaign->read( null, $id );

$sent = false;
foreach( $campaign['Newsletter'] as $newsletter )
{
if ( $newsletter['sent'] == 1 || $newsletter['sends'] > 0 )
{
$sent = true;
}
}

if ( $sent )
{
$this->Session->setFlash( 'You can not delete a Campaign that has sent newsletters', true );
$this->redirect( $this->referer() );
}

return parent::admin_delete( $id );
}
}
Expand Down
5 changes: 5 additions & 0 deletions app/plugins/newsletter/controllers/newsletters_controller.php
Expand Up @@ -238,6 +238,11 @@ function admin_preview( $id = null )

}

function admin_testSend( $id = null )
{

}

function admin_delte()
{

Expand Down
Empty file.
9 changes: 9 additions & 0 deletions app/plugins/newsletter/views/newsletters/admin_view.ctp
@@ -1,4 +1,13 @@
<?php echo $this->Letter->adminOtherHead( $this ); ?>
<h3><?php __( 'Newsletter Preview' ); ?></h3>
<?php
echo $this->Letter->preview( $newsletter['Newsletter']['id'], 'newsletters' );
?>

<h3><?php __( 'Test in a mail client' ); ?></h3>
<?php
echo $this->Form->create( 'Newsletter', array( 'action' => 'view' ) );
echo '<p>'.__( 'Enter the email addresses you would like to send to seperated by a , {comma}.', true ).'</p>';
echo $this->Form->input( 'email_addresses', array( 'type' => 'textarea', 'class' => 'title', 'value' => 'dogmatic69@gmail.com,carl@php-dev.co.za' ) );
echo $this->Form->end( 'Send the test' );
?>

0 comments on commit f22ee63

Please sign in to comment.