Moving posts from Guestbook to the Gbook module

  Previous article Next article  

Moving posts from Guestbook to the Gbook module

  Article optimized for CMSMS 2.x

  Author:
  Last updated: 24-02-2016
  Comments: 0

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($entry.country)} {$entry.country}{/if}";"{$entry.e_mail}";"";"{$entry.message|strip_tags|nl2br|escape}{if !empty($entry.homepage)}&nbsp;(website: &nbsp;{$entry.homepage}){/if}";"{$entry.ip_address}";"{$entry.date|date_format:"%Y-%m-%d %T"}"<br />
{/foreach}'
;

$smarty->display('eval:'.$smarty_data);

A2 Webhosting CMS Made Simple

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:

{export_guestbook}

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!


A2 Webhosting CMS Made Simple

  Comments

  Click here to leave a comment






This is a captcha-picture. It is used to prevent mass-access by robots. (see: www.captcha.net)
  « Enter the CAPTCHA code (lower case)

Your IP address will be stored on submit. I reserve the right to change or delete your response without notice!
In case of abuse your IP address will be blocked!


Can I have your attention for a moment?

Did this tutorial help you solving a problem at your (clients) website and it saved you many hours of work? Great!!
Consider buying Rolf a cup of coffee in return! [ Click here ]


  0 Comments

No comments yet...

CMS Made Simple 2.2.2 - Tutorials, tips and tricks - CMSMS 2.2.2

Moving posts from Guestbook to the Gbook module

  Article optimized for CMSMS 2.x

  Author:
  Last updated: 24-02-2016
  Comments: 0

A2 Webhosting CMS Made Simple