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

The below how-to assumes that you already have a block object (or block id).

The simple way to add a comment to a specific guestbook is like so:

  <?php
  Loader::block('guestbook');
  $com = new GuestBookBlockEntry($bID, $cID);//$bID is the block ID
  $approved = 1;//approved the comment
  $com->addEntry($commentText, $name, $email, $approved, $cID, $uID);//for a guest $uID is 0
  ?>

the problem with that is that all comments will have the same timestamps (when they are added). That is good for some cases, but others you may need to put in the date/time.

Below is an example function that can be used to specify the timestamp aswell (its kinda hacky and made for 5.4.2)

function addEntry($bID, $comment, $name, $email, $approved, $cID, $uID=0, $timestamp) {
    $txt = Loader::helper('text');

    $db = Loader::db();
    $query = "INSERT INTO btGuestBookEntries (bID, cID, uID, user_name, user_email, commentText, approved, entryDate) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
    $res = $db->query($query, array($bID, $cID, intval($uID), $txt->sanitize($name), $txt->sanitize($email), $txt->sanitize($comment), $approved, $timestamp) );

    $number = 1;//stupid cache stuff
    $ca   = new Cache();
    $db   = Loader::db();      
    $count = $ca->get('GuestBookCount',$cID."-".$bID);
    if($count && $number){
      $count += $number;        
    } else{
      $q = 'SELECT count(bID) as count
      FROM btGuestBookEntries
      WHERE bID = ?
      AND cID = ?
      AND approved=1';        
      $v = array($bID, $cID);
      $rs = $db->query($q,$v);
      $row = $rs->FetchRow();
      $count = $row['count'];
    }
    $ca->set('GuestBookCount',$cID."-".$bID,$count);
  }

It has some code in there to update the cache, which is why its kinda hacky. It can be called like so:

addEntry(23, 'Muahahah', 'Sir Derp A lot', '1@2.com', 1, 105, 0, '2011-08-24 20:23:53');

Make sure you format the time stamp properly!

Loading Conversation