Skip to content

Commit

Permalink
getting the blog and cms stable with locking records code highlightin…
Browse files Browse the repository at this point in the history
…g looking at form plugins
  • Loading branch information
dogmatic69 committed Dec 23, 2009
1 parent 54f3ab9 commit 0822f02
Show file tree
Hide file tree
Showing 464 changed files with 86,785 additions and 2 deletions.
78 changes: 78 additions & 0 deletions app/plugins/blog/blog_app_controller.php
@@ -0,0 +1,78 @@
<?php
/**
* Blog App Controller class file.
*
* The parent class that all the blog plugin controller classes extend from.
* This is used to make functionality that is needed all over the blog
* plugin.
*
* Copyright (c) 2009 Carl Sutton ( dogmatic69 )
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright (c) 2009 Carl Sutton ( dogmatic69 )
* @link http://www.dogmatic.co.za
* @package blog
* @subpackage blog.controllers.blogAppController
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
class BlogAppController extends AppController
{
/**
* The helpers that the blog plugin needs to function
*/
var $helpers = array(
//cake helpers
'Time', 'Text', 'Form',

//core helpers
'Core.TagCloud',

//plugin helpers
'Blog.Blog', 'Google.Chart',

//layout helpers
'Blog.PostLayout', 'Blog.CommentLayout'
);

/**
* beforeFilter callback
*
* this method is run before any of the controllers in the blog plugin.
* It is used to set up a cache config and some other variables that are
* needed throughout the plugin.
*
* @param nothing
* @return nothing
*/
function beforeFilter()
{
parent::beforeFilter();

$this->set( 'tagCount', ClassRegistry::init( 'Blog.Tag' )->getCount() );

$this->set( 'postDates', ClassRegistry::init( 'Blog.Post' )->getDates() );
$this->set( 'postLatest', ClassRegistry::init( 'Blog.Post' )->getLatest() );
$this->set( 'postPending', ClassRegistry::init( 'Blog.Post' )->getPending() );
$this->set( 'postPopular', ClassRegistry::init( 'Blog.Post' )->getPopular() );

$this->set( 'commentCount', ClassRegistry::init( 'Blog.Comment' )->getCounts() );
}

/**
* afterFilter callback.
*
* used to do stuff before the code is rendered but after all the
* controllers have finnished.
*
* @param nothing
* @return nothing
*/
function afterFilter()
{
parent::afterFilter();
}
}
?>
43 changes: 43 additions & 0 deletions app/plugins/blog/blog_app_model.php
@@ -0,0 +1,43 @@
<?php
class BlogAppModel extends AppModel
{
var $useDbConfig = 'blog';

function beforeSave()
{
parent::beforeSave();

$this->__clearCache();
return true;
}

function afterDelete()
{
parent::afterDelete();

$this->__clearCache();
return true;
}

private function __clearCache()
{
App::import( 'Folder' );

$Folder = new Folder( CACHE.'blog' );

$files = $Folder->read();

if ( empty( $files[1] ) )
{
return true;
}

foreach( $files[1] as $file )
{
unlink( CACHE.'blog'.DS.$file );
}

return true;
}
}
?>
119 changes: 119 additions & 0 deletions app/plugins/blog/controllers/comments_controller.php
@@ -0,0 +1,119 @@
<?php
/**
* Blog Comments Controller class file.
*
* This is the main controller for all the blog comments. It extends
* {@see BlogAppController} for some functionality.
*
* Copyright (c) 2009 Carl Sutton ( dogmatic69 )
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright (c) 2009 Carl Sutton ( dogmatic69 )
* @link http://www.dogmatic.co.za
* @package blog
* @subpackage blog.controllers.comments
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
class CommentsController extends BlogAppController
{
var $name = 'Comments';

function add()
{
if ( !empty( $this->data ) )
{
$this->Comment->create();

if ( $this->Comment->save( $this->data ) )
{
$this->Session->setFlash( 'Your comment has been submitted for review.' );
$this->redirect( $this->referer() );
}
}
}

function admin_index( $active = null )
{
$conditions = array();
if ( $active !== null )
{
$conditions = array( 'Comment.active' => $active );
}

$this->paginate = array(
'fields' => array(
'Comment.id',
'Comment.name',
'Comment.email',
'Comment.website',
'Comment.comment',
'Comment.active',
'Comment.post_id',
'Comment.created',
),
'conditions' => $conditions,
'order' => array(
'Comment.active' => 'ASC',
'Comment.created' => 'ASC',
),
'limit' => 20,
'contain' => array(
'Post' => array(
'fields' => array(
'Post.title',
'Post.slug',
)
)
)
);

$comments = $this->paginate( 'Comment' );

$this->set( compact( 'comments' ) );
}

function admin_perge( $date = null )
{
if ( !$date )
{
$date = date( 'Y-m-d h:i:s', mktime( 0, 0, 0, date( 'm' ) -1, date( 'd' ), date( 'y' ) ) );
}

$old = $this->Comment->find(
'list',
array(
'fields' => array(
'Comment.id',
'Comment.id'
),
'conditions' => array(
'Comment.created < ' => $date,
'Comment.active' => 0
),
'contain' => false
)
);

if ( empty( $old ) )
{
$this->Session->setFlash( __( 'No old comments found', true ) );
$this->redirect( $this->referer() );
}

$i = 0;
foreach( $old as $id )
{
if ( $this->Comment->delete( $id ) )
{
$i++;
}
}

$this->Session->setFlash( sprintf( '%s %s', $i, __( 'Comments deleted', true ) ) );
}

}
?>

0 comments on commit 0822f02

Please sign in to comment.