Moving posts from Guestbook to the Gbook module

  Previous article Next article  

The popular Guestbook module for CMS Made Simple™ sadly hasn't had any development lately... But lucky for us, there is an alternative: the well maintained Gbook module.

The Gbook module has a built in function for importing posts, but the Guestbook module doesn't have a function to export them... Now what??

In this tutorial I will show you a User Defined Tag (UDT) that exports the Guestbook posts in Gbook import format!

  How to use

Create a new User Defined Tag named "export_guestbook" with the content:

$id = isset($params['id']) ? $params['id'] : '1';

$db = cmsms()->GetDb();
$query = "SELECT * FROM " . cms_db_prefix() . "module_guestbook WHERE approved='1' AND guestbook=" . $id . " ORDER BY date ASC";
$result = $db->Execute($query);

$entries = Array();

while ($result && $row = $result->FetchRow())
   $i = count($entries);
   $entries[$i]['sender'] = $row['sender'];
   $entries[$i]['e_mail'] = $row['e_mail'];
   $entries[$i]['homepage'] = $row['homepage'];
   $entries[$i]['country'] = $row['country'];
   $entries[$i]['location'] = $row['location'];
   $entries[$i]['message'] = $row['message'];
   $entries[$i]['date'] = $row['date'];
   $entries[$i]['ip_address'] = $row['ip_address'];

$smarty->assign('entries', $entries);

$smarty_data = '{foreach from=$entries item=entry}
"{$entry.sender}{if !empty($entry.location)} - {$entry.location}{/if}{if !empty($} {$}{/if}";"{$entry.e_mail}";"";"{$entry.message|strip_tags|nl2br|escape}{if !empty($entry.homepage)}&nbsp;(website: &nbsp;{$entry.homepage}){/if}";"{$entry.ip_address}";"{$|date_format:"%Y-%m-%d %T"}"<br />


Create a new page at your website with WYSIWYG editor off and do not include the page in the menu. Add to the content of the page only the tag:


Or when you have multiple guestbooks use the id parameter to select the correct guestbook, in example:

{export_guestbook id=2}

When visiting this page you will see the semicolon separated export of the Guestbook module. Simply select and copy the text, and paste it into a CSV file.

Go to the Gbook module and import the file! If you don't see the file in the file picker, change the selector to "All Files".
Warning: just to be on the safe side, make an export of the database before you actually start the import...

One down side to this method is the Guestbook module doesn't store real line breaks, so they can't be exported either. I tackled this by changing "new lines" to <br /> tags. You'll need manually change the tags for actual line breaks in the Gbook posts...

  Working example

I used this method to port 100+ posts at my own website and also a few other Dutch CMSMS users used it successfully!

Buy Me A Coffee

  Show related articles:

  Comment Form


Click here to open the form



No comments yet...

Buy Me A Coffee

CMS Made Simple - Tutorials, Tips and Tricks - CMSMS

Moving posts from Guestbook to the Gbook module

  Article optimized for CMSMS 2.x

  Last tested in: CMSMS 1.12.2
  Last updated: 21-05-2018
  Comments: 0

Buy Me A Coffee


Ads help me to help you! Thanks!

Ads help me to help you! Buy products from these advertisers!