/*
Snippet: GuestBook3 (based on GuestBook2) - Etomite v0.6.3 - Modified 2005-09-05
Created By: Ralph A. Dahlgren - [email protected]
Modified By: Mikko K. Lammi - [email protected] - www.parea.fi
Modified By: Rain R. Visser
Demo URL GB2: http://www.parea.fi/raaputuksia/guestbook.html
Usage: Create an Etomite user or admin as GuestBook owner in Etomite Manager
Change $defaultadmin variable to match GuestBook owner
OR
Messages will be deposited into that mailbox, but only GuestBook
messages will be displayed within the GuestBook listing.
Place the .gifs in assets\images
Place the .JS in assets\site
Variables: $gbtype - Referenced in GuestBook admin User Messages Subject
$gbadmin - Etomite User/Admin who will receive this message
Examples: Use the [!SnippetName!] syntax instead of regular [[SnippetName]]:
[!GuestBook!] - Will use snippet defaults for $gbtype and $gbadmin
[!GuestBook?gbtype=GuestBook&gbadmin=guestbook!] - Self Explanatory
[!GuestBook?gbadmin=someuser!] - Uses $etomite->documentObject['pagetitle'] for $gbtype
[!GuestBook?bgtype=SomeTopic!] - Uses $defaultadmin for $gbadmin
Note: $etomite->documentObject['createdby'] was not used for $gbadmin intentionally
To implement this capability would entail and additonal DB Query before Inserts
*/
// BEGIN SETTINGS -------------------------------------------------------------
// Variables you may want to change
$defaultadmin = "admin"; // Default GuestBook admin to use if $gbadmin not passed
$gap = " :: "; // Separator between $type and $subject in User Messages Subject field
$messages = 3; // Number of messages on one page
$header_style = "style='font-size: medium;'"; // Css style for header
$message_box_style = "style='padding: 1px;'"; // Css style for message box
$dateformat = "%H:%M %d.%m.%Y"; // Preferred Date & Time display format, European dateformat is "%d.%m.%Y %H:%M:%S"
$order = "DESC"; // Order of messages by postdate: DESC = descending, ASC = ascending
$server_offset_time = 21600; // number of seconds for timezone difference
// Russia language for guestbook
$_lang_guestbook["write_new_message"] = "Новое сообщение";
$_lang_guestbook["messages"] = "Сообщения";
$_lang_guestbook["name_or_alias"] = "Ваше имя:";
$_lang_guestbook["send"] = "Отправить";
$_lang_guestbook["reset"] = "Обновить";
$_lang_guestbook["next_page"] = "След. страница";
$_lang_guestbook["previous_page"] = "Пред. страница";
$_lang_guestbook["message"] = "Сообщение:";
$_lang_guestbook["date_and_time"] = "Дата сообщения";
$_lang_guestbook["sender"] = "Отправитель";
$_lang_guestbook["cancel"] = "Отменить";
$_lang_guestbook["error"] = "GuestBook User/Manager not found... Check your settings...";
// END SETTINGS ---------------------------------------------------------------
// Variables you should not need to change
$type = isset($gbtype) ? $gbtype : $etomite->documentObject['pagetitle']; // Set $type field for new entry
$trimtype=substr($type,0,15); // Truncate $type to 15 character limit for field
$guestbookadmin = isset($gbadmin) ? $gbadmin : $defaultadmin; // Set GuestBook admin
$pageid=$etomite->documentIdentifier; // ID of the calling document
$pageurl=$etomite->makeURL($pageid); // URL if you don't have friendly uri
$tbl = $etomite->dbConfig['dbase'].".".$etomite->dbConfig['table_prefix'];
$msgdb = $tbl."user_messages"; // DB.Prefix_user_messages variable
// Function to show smileys
function smile($text) {
$text = str_replace(":)", "<img src=\"assets/images/smile.gif\">", $text);
$text = str_replace(":D", "<img src=\"assets/images/biggrin.gif\">", $text);
$text = str_replace(":haha:","<img src=\"assets/images/laugh.gif\">", $text);
$text = str_replace(";)","<img src=\"assets/images/wink.gif\">", $text);
$text = str_replace(":cool:","<img src=\"assets/images/cool.gif\">", $text);
$text = str_replace(":o","<img src=\"assets/images/blush.gif\">", $text);
$text = str_replace(":(","<img src=\"assets/images/frown.gif\">", $text);
$text = str_replace(":foei:","<img src=\"assets/images/nono.gif\">", $text);
$text = str_replace(":schrik:","<img src=\"assets/images/eek.gif\">", $text);
$text = str_replace(":boos:","<img src=\"assets/images/mad.gif\">", $text);
$text = str_replace(":dood:","<img src=\"assets/images/dead.gif\">", $text);
$text = str_replace(":huil:","<img src=\"assets/images/cry.gif\">", $text);
$text = str_replace(":kus:", "<img src=\"assets/images/kiss.gif\">", $text);
$text = str_replace(":love:","<img src=\"assets/images/rose.gif\">", $text);
$text = str_replace(":stil:", "<img src=\"assets/images/quiet.gif\">", $text);
$text = str_replace(":kijk:","<img src=\"assets/images/look.gif\">", $text);
$text = str_replace(":poets:", "<img src=\"assets/images/brushteeth.gif\">", $text);
$text = str_replace(":proost:","<img src=\"assets/images/cheers.gif\">", $text);
$text = str_replace(":clown:","<img src=\"assets/images/clown.gif\">", $text);
$text = str_replace(":td:","<img src=\"assets/images/notgood.gif\">", $text);
$text = str_replace(":tu:", "<img src=\"assets/images/perfect.gif\">", $text);
$text = str_replace(":buig:","<img src=\"assets/images/hail.gif\">", $text);
$text = str_replace(":spring:","<img src=\"assets/images/bouncey.gif\">", $text);
$text = str_replace(":nerd:","<img src=\"assets/images/nerd.gif\">", $text);
$text = str_replace(":idee:","<img src=\"assets/images/idea.gif\">", $text);
$text = str_replace(":zzz:","<img src=\"assets/images/sleep.gif\">", $text);
$text = str_replace(":P","<img src=\"assets/images/tongue.gif\">", $text);
$text = str_replace(":zwaai:","<img src=\"assets/images/wave.gif\">", $text);
$text = str_replace(":fluit:", "<img src=\"assets/images/whissle.gif\">", $text);
$text = str_replace(":verbaasd:","<img src=\"assets/images/confused.gif\">", $text);
return $text;
}
// Function to make hyperlinks
function hyperlink($text) {
$search = array ("/([\w\.\/\&\=\?\-]+)@([\w\.\/\&\=\?\-]+)/","/((ftp(7?):\/\/)|(ftp\.))([\w\.\/\&\=\?\-]+)/","/((http(s?):\/\/)|(www\.))([\w\.\/\&\=\?\-]+)/");
$replace = array ("<a href='mailto:$1@$2'>$1@$2</a>","<a href='ftp$3://$4$5' target='_blank'>$4$5</a>","<a href='http$3://$4$5' target='_blank'>$4$5</a>");
return preg_replace ($search, $replace, $text);
}
// Don't allow unwanted re-posts of messages
if($_POST['submitted'] == "TRUE") header( "Location: index.php?id=$etomite->documentIdentifier" );
// Query for the user ID (id) for the GuestBook owner
$sql = "SELECT id FROM ".$tbl."manager_users WHERE ".$tbl."manager_users.username='$guestbookadmin';";
$rs = $etomite->dbQuery($sql);
$limit = $etomite->recordCount($rs);
// Check to make sure $guestbookadmin has been created and assigned
if($limit == 1) {
$userrec = $etomite->fetchRow($rs);
$userid = $userrec['id'];
// Check to see if a valid message has been submitted
if(isset($_POST['submit']) && ($_POST['subject'] > "") && ($_POST['message'] > "")){
$postdate = time();
$recipient = $userid;
$subject = $type . $gap . strip_tags($_POST['subject']);
$message = strip_tags($_POST['message']);
// Query to INSERT a new GuestBook message into user_messages
$sql = "INSERT INTO $msgdb ( id , type , subject , message , sender , recipient , private , postdate , messageread ) VALUES ( '', '$type', '$subject', '$message', '0', '$recipient', '0', '$postdate', '0' );";
$rs = $etomite->dbQuery($sql); // Execute the Query
$submitted="TRUE";
}
else $submitted = "TRUE";
// Display write new message form
if ($_GET['new_message'] == "TRUE") {
// Display a Form for submitting a new message
$output .= "<script language=\"javascript\" type=\"text/javascript\" src=\"assets/site/gb.js\"></script>";
$output .= "<table width='95%'><tr><td>";
$output .= "<form name=\"form\" method='post' action='index.php'>";
$output .= "<input type='hidden' name='id' value='$pageid' />";
$output .= "<input type='hidden' name='submitted' value='$submitted' />";
$output .= $_lang_guestbook["name_or_alias"]."<br /><input name='subject' size='40' class='input'/>";
$output .= "<br />".$_lang_guestbook["message"]."<br /><text"."area rows='6' cols='50' name='message' class='input'></textarea><br>";
$output .= "<input type='submit' name='submit' class='button' value='".$_lang_guestbook["send"]."'>";
$output .= " <input type='button' value='".$_lang_guestbook["cancel"]."' class='button' onClick=\"window.location.href='$pageurl&new_message=FALSE'\">";
$output .= "</form>";
$output .= "</td></tr></table>";
}
// Display write new message link
else {
// $output .= "<div style=\"text-align:right;margin-right:7px;margin-top:7px;\"><a href='index.php?id=35&new_message=TRUE'\">".$_lang_guestbook["write_new_message"]."</a></div>";
}
// Query to COUNT existing messages
$sql = "SELECT * FROM ".$tbl."user_messages
WHERE ".$tbl."user_messages.recipient=$userid
AND ".$tbl."user_messages.type='".$trimtype."'
ORDER BY ".$tbl."user_messages.postdate $order;";
$rs = $etomite->dbQuery($sql); // Execute the Query
$total = $etomite->recordCount($rs); // Number of messages found
// Message page number from GET
if (isset($_GET["page"])) { $page = $_GET["page"]; }
else { $page = 1; }
// Index where to start in result set
$from = 0 + ($page-1)*$messages;
// Query to SELECT existing messages
$sql = "SELECT * FROM ".$tbl."user_messages
WHERE ".$tbl."user_messages.recipient=$userid
AND ".$tbl."user_messages.type='".$trimtype."'
ORDER BY ".$tbl."user_messages.postdate $order LIMIT $from, $messages;";
$rs = $etomite->dbQuery($sql); // Execute the Query
$limit = $etomite->recordCount($rs); // Number of messages found
// Number of pages
$pages = ceil($total/$messages);
// Previous page link
$previouspage = $page-1;
$previouspage_text = "<a href='index.php?id=35&page=$previouspage'>« ".$_lang_guestbook["previous_page"]." [$previouspage/$pages]</a> ";
// Next page link
$nextpage = $page+1;
$nextpage_text = "<a href='index.php?id=35&page=$nextpage'>".$_lang_guestbook["next_page"]." [$nextpage/$pages] »</a>";
// Previous and next page links at top of the page
if ($previouspage > 0) { $output .= $previouspage_text; }
if ($nextpage <= $pages) { $output .= $nextpage_text; }
// Empty lines
if ($total > $messages) {
$output .= "<br /><br />";
}
// Loop through each of the messages and format for display
for ($y = 0; $y < $limit; $y++) {
if ($order == "DESC") { $number = $total - $from - $y; }
if ($order == "ASC") { $number = $from + $y + 1; }
$guestbookrec = $etomite->fetchRow($rs);
$poster = str_replace($type.$gap,"",$guestbookrec['subject']);
$message = nl2br($guestbookrec['message']);
$postdate = strftime($dateformat, $guestbookrec['postdate']+$server_offset_time);
$output .= "<table $message_box_style width='100%'>";
$output .= "<tr><td nowrap width='80%' class='gb_name'>$poster</td>";
$output .= "<td nowrap width='20%' align=right class='gb_date'>$postdate</td>";
$output .= "<tr><td colspan=\"2\"> </td>";
$output .= "<tr><td colspan=\"2\" class='gb_text'>".hyperlink(smile($message))."</td>";
$output .= "<tr><td width='80%'> </td>";
$output .= "<td width='20%' nowrap align=right class='gb_nmessage'>".$_lang_guestbook["message"].": $number/$total</td>";
$output .= "</table><br />";
}
// Previous and next page links at bottom of the page
if ($previouspage > 0) { $output .= $previouspage_text; }
if ($nextpage <= $pages) { $output .= $nextpage_text; }
}
// If no valid GuestBook owner is found display error message...
else $output = $_lang_guestbook["error"];
// Output
return $output;