This is the documentation for concrete5 version 5.6 and earlier. View Current Documentation

Overview

This turns out to be a really simple mod.The guestbook addon is structured in such a way that the form to add a comment is at the bottom. Basically what we're going to do is add an if else statement to a template for guestbooks view.php that checks if the current date is longer than a month from when the page was added. If it is, we'll disable posting, if not, then let it run. We want to create the custom template at this path root/blocks/guestbook/templates/closed_comments.php and copy the contents of closed_comments.php from root/concrete/blocks/guesbook/view.php

The Code

So now that we know what we need to do, lets implement it. Initially this is the code in guestbooks view.php file that allows user to post their own comment.

<a name="guestBookForm-<?=$controller->bID?>"></a>
<div id="guestBook-formBlock-<?=$controller->bID?>" class="guestBook-formBlock">
    <h5 class="guestBook-formBlock-title"><?php echo t('Leave a Reply')?></h5>
    <form method="post" action="<?=$this->action('form_save_entry', '#guestBookForm-'.$controller->bID)?>">
    <? if(isset($Entry->entryID)) { ?>
        <input type="hidden" name="entryID" value="<?=$Entry->entryID?>" />
    <? } ?>

    <? if(!$controller->authenticationRequired){ ?>
        <label for="name"><?=t('Name')?>:</label><?=(isset($errors['name'])?"<span class=\"error\">".$errors['name']."</span>":"")?><br />
        <input type="text" name="name" value="<?=$Entry->user_name ?>" /> <br />
        <label for="email"><?=t('Email')?>:</label><?=(isset($errors['email'])?"<span class=\"error\">".$errors['email']."</span>":"")?><br />
        <input type="text" name="email" value="<?=$Entry->user_email ?>" /> <span class="note">(<?=t('Your email will not be publicly displayed.')?>)</span> <br />
    <? } ?>

    <?=(isset($errors['commentText'])?"<br /><span class=\"error\">".$errors['commentText']."</span>":"")?>
    <textarea name="commentText" rows="10" cols="150"><?=$Entry->commentText ?></textarea><br />
    <?
    if($controller->displayCaptcha) {

        echo(t('Please type the letters and numbers shown in the image.'));              

        $captcha = Loader::helper('validation/captcha');               
        $captcha->display();
        print '<br/>';
        $captcha->showInput();       

        echo isset($errors['captcha'])?'<span class="error">' . $errors['captcha'] . '</span>':'';

    }
    ?>
    <br/><br/>
    <input type="submit" name="Post Comment" value="<?=t('Post Comment')?>" class="button"/>
    </form>
</div>

so first we want to add a month to the date the page was modified at the start of our if wrapper, so above the before code

    <?php getCollectionDateAdded('F j, Y') . '+ 1 month');

what this code does is it sets the variable pageExpires to equal the date the page was added ($c->getCollectionDateAdded) and adds one month to that date. You can change 1 month to whatever variable you want, like 10 seconds, or 30 minutes. Then we want to compare it to the current date, so we load the date time helper.

      $date = Loader::helper("date");

and then we want to compare pageExpire to current time, and if pageExpire is less than the current time diplay the block

     if($pageExpires < $date->getLocalDateTime('now',$mask = 'F j, Y')) { ?>

and then finally at the bottom display a message if comments are closed.

            <?php  else{   echo t('Comments for this Discussion Have Been Closed.');
            }
    ?>

Putting It All Together

The relevant parts of my completed template file look like this.

                    <?php
$pageExpires= strtotime($c->getCollectionDateAdded('F j, Y') . '+ 8 seconds');
  $date = Loader::helper("date");

  if($pageExpires < $date->getLocalDateTime('now',$mask = 'F j, Y')) { ?>

         <a name="guestBookForm-<?=$controller->bID?>"></a>
        <div id="guestBook-formBlock-<?=$controller->bID?>" class="guestBook-formBlock">
            <h5 class="guestBook-formBlock-title"><?php echo t('Leave a Reply')?></h5>
            <form method="post" action="<?=$this->action('form_save_entry', '#guestBookForm-'.$controller->bID)?>">
            <? if(isset($Entry->entryID)) { ?>
                <input type="hidden" name="entryID" value="<?=$Entry->entryID?>" />
            <? } ?>

            <? if(!$controller->authenticationRequired){ ?>
                <label for="name"><?=t('Name')?>:</label><?=(isset($errors['name'])?"<span class=\"error\">".$errors['name']."</span>":"")?><br />
                <input type="text" name="name" value="<?=$Entry->user_name ?>" /> <br />
                <label for="email"><?=t('Email')?>:</label><?=(isset($errors['email'])?"<span class=\"error\">".$errors['email']."</span>":"")?><br />
                <input type="text" name="email" value="<?=$Entry->user_email ?>" /> <span class="note">(<?=t('Your email will not be publicly displayed.')?>)</span> <br />
            <? } ?>

            <?=(isset($errors['commentText'])?"<br /><span class=\"error\">".$errors['commentText']."</span>":"")?>
            <textarea name="commentText" rows="10" cols="150"><?=$Entry->commentText ?></textarea><br />
            <?
            if($controller->displayCaptcha) {

                echo(t('Please type the letters and numbers shown in the image.'));              

                $captcha = Loader::helper('validation/captcha');               
                $captcha->display();
                print '<br/>';
                $captcha->showInput();       

                echo isset($errors['captcha'])?'<span class="error">' . $errors['captcha'] . '</span>':'';

            }
            ?>
            <br/><br/>
            <input type="submit" name="Post Comment" value="<?=t('Post Comment')?>" class="button"/>
            </form>
        </div>



        <?php  } else {
        echo t('Comments for this Discussion Have Been Closed.');
        }
?>
Loading Conversation