I'm not sure if this has been covered before.. I searched and couldn't
find anything.

I am trying to create an antiflood system for my comments. Outside of
cake this is an easy task by doing something like:

if (isset($_SESSION['antiflood'])) {
                $past = $_SESSION['antiflood'] + ANTIFLOOD_TIME;
                if (time() < $past) {
                        $msg = 'you have to wait at least <strong>' . 
ANTIFLOOD_TIME .
'</strong> seconds between posts';
                }
                } else {
/* validation, insert into db.. etc */

/* set antiflood time into session */
$_SESSION['antiflood'] = time();
}

I've been trying to use something similar in cake but i'm having a
hard time getting this working and i'm sure it's something simple I am
overlooking.

In my comments controller, I have a function for grabbing comments for
a specific news_id.

    function GrabNewsComments($id)
    {
        //$this->Comment->id = $id;
        $this->Comment->recursive = 0;
                $GrabNewsComments = $this->Comment->findAll('Comment.news_id = 
'.
$id, null, 'Comment.created asc');
                return $GrabNewsComments;
    }

I have an element called news_comments.ctp for which I do a
requestAction to grab comments for the current news id we're viewing.
The element is called from the News view.ctp.

$comments = $this->requestAction('/comments/GrabNewsComments/'.
$data['News']['id']);

In this same element, I have the display of the comments which are
looped in a foreach, and then I have the add comment form.

<div id="a_frm">
<?php
                $news_id = $data['News']['id'];
                $slug = $data['News']['slug'];
?>
<?php echo $form->create('Comment', array('action'=>'/add/'.
$news_id)); ?>
<?php
        echo $form->hidden('Comment.user_id',array('value'=> $othAuth-
>user('id')));
        echo $form->hidden('News.news_id',array('value'=> $news_id));
?>
<br />
<fieldset>
    <legend>Add Comment</legend>
    <br />
          <label for="CommentSubject">Title: <small>(optional)</small>
            <?php echo $form->input('Comment.title', array('label'=>false,
'size'=>'50')); ?>
          </label>
          <label for="CommentComment">Comment:
            <?php echo $form->textarea('Comment.comment',
array('label'=>false,'rows'=>'4','cols'=>'55')); ?>
          </label>
<br />
<?php echo $form->submit('Add Comment') ?>
</fieldset>
<?php echo $form->end(); ?>
</div>

The first message posts fine, but after that the antiflood session
doesnt get recognized or something, because it don't make it out of
the antiflood checking. Here is my add method in the
comments_controller.

    function add($id)
    {
                if (!empty($this->data))
                {

        if ($this->Session->read('antiflood')) {
                $past = $this->Session->read('antiflood') + $this->Conf-
>get('general.comment_floodtime');
                $blah = time();
                if ($blah < $past) {
                        //$msg = 'you have to wait at least 
<strong>'.$this->Conf-
>get('general.comment_floodtime').'</strong> seconds to post that.';
                        //$this->set('msg', $msg);
                        //$this->set('now', $blah);
                        //$this->set('past', $past);
                }
                } else {

                    $this->data['Comment']['news_id'] = $id;
                    $newsSlug = $this->Comment->News->findById($id);

                    $this->Comment->create();
                    if ($this->Comment->save($this->data))
                    {
                        $this->Session->write('antiflood', time());
                        $this->Session->setFlash('Your comment has been
added.', 'flash-ok');
                        $this->redirect('/news/view/' . $newsSlug['News']
['slug']);

                    }
                }
            }
    }

If anyone has any ideas, I'd really appreciate it!


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to