/* Snippet: GuestBook5 (based on GuestBook3 & 4) - Etomite v0.6.1 final - Modified 2007-01-08 Created By: Ralph A. Dahlgren - rad14701[at]yahoo.com Modified By: Jarda Travnicek - jarda[at]csol-mb.net And: Miroslav "churchyard" H. - churchyard[at]gmail.com New in GuestBook4: text formatting with bbcode spam protection against email address crawlers email notice on new post ip logging New in GuestBook5: alias working calling snippets protection To-Do: spam protection with captcha codes Usage: Create an Etomite user or admin as GuestBook owner in Etomite Manager Change $defaultadmin variable (to this user will be delivered the messages) 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 */ $aliasu = "guestbook.htm"; // put page.htm or "index.php?id=$etomite->documentIdentifier" or something like that // DEF: "index.php?id=$etomite->documentIdentifier" $defaultadmin = "guestbook"; // Default GuestBook admin to use if $gbadmin not passed $gap = " :: "; // Separator between $type and $subject in User Messages Subject field $messages = 10; // Number of messages on one page $message_box_style = 'class="message_box_style"'; // Css style for message box $order = "DESC"; // Order of messages by postdate: DESC = descending, ASC = ascending /* time & date zone settings */ setlocale(LC_TIME, "cs_CZ"); // for cz (for en 'LC_TIME, "en_EN"', for sk 'LC_TIME, "Slovak"') $dateformat = "%a %d.%m.%y v %H:%M:%S"; // Preferred Date & Time display format, European dateformat is "%d.%m.%Y %H:%M:%S" $server_offset_time = 0; // number of seconds for timezone difference /* emails */ $toAdmin = 'admin@example.com'; $MailSubject = 'Etomite GuestBook'; $fromMail = 'guestbook@example.com'; $mailCharset = 'utf-8'; /* Czech language for guestbook */ $_lang_guestbook["write_new_message"] = "Přidat zprávu"; $_lang_guestbook["messages"] = "Zprávy"; $_lang_guestbook["name_or_alias"] = "Jméno"; $_lang_guestbook["send"] = "Poslat"; $_lang_guestbook["reset"] = "Reset"; $_lang_guestbook["next_page"] = "Další strana"; $_lang_guestbook["previous_page"] = "Předchozí strana"; $_lang_guestbook["message"] = "Text zprávy"; $_lang_guestbook["count_message"] = "Počet zpráv:"; $_lang_guestbook["date_and_time"] = "Datum zaslání:"; $_lang_guestbook["sender"] = "Zaslal:"; $_lang_guestbook["cancel"] = "Zrušit"; $_lang_guestbook["code"] = "Kód"; $_lang_guestbook["quoting"] = "Cituji"; $_lang_guestbook["error"] = "Objevila se chyba..."; $_lang_guestbook["email_author"] = "Autor: "; $_lang_guestbook["email_message"] = "Zprava:"; $_lang_guestbook["javascript_disabled"] = 'Tlačítko nefunguje, pokud nemáte povolen JavaScript (je to slabá obrana proti jednodušším SPAM botům) - pokud váš prohlížeč nepodporuje JavaScript, napište za URL ?new_message=TRUE, nebo zkuste Firefox.'; /* Slovak language for guestbook $_lang_guestbook["write_new_message"] = "Pridať správu"; $_lang_guestbook["messages"] = "Správy"; $_lang_guestbook["name_or_alias"] = "Meno"; $_lang_guestbook["send"] = "Poslať"; $_lang_guestbook["reset"] = "Reset"; $_lang_guestbook["next_page"] = "Ďalšia strana"; $_lang_guestbook["previous_page"] = "Predchádzajúca strana"; $_lang_guestbook["message"] = "Text správy"; $_lang_guestbook["count_message"] = "Počet správ:"; $_lang_guestbook["date_and_time"] = "Datum odoslania:"; $_lang_guestbook["sender"] = "Poslal:"; $_lang_guestbook["cancel"] = "Zrušiť"; $_lang_guestbook["code"] = "Kód"; $_lang_guestbook["quoting"] = "Citujem"; $_lang_guestbook["error"] = "Objavila sa chyba..."; $_lang_guestbook["email_author"] = "SK Autor: "; $_lang_guestbook["email_message"] = "Zprava:"; $_lang_guestbook["javascript_disabled"] = 'Tlačítko nefunguje, pokud nemáte povolen JavaScript (je to slabá obrana proti jednodušším SPAM botům) - pokud váš prohlížeč nepodporuje JavaScript, napište za URL ?new_message=TRUE, nebo zkuste Firefox.'; */ /* 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 make bbcode formatting function bbcode($message) { $preg = array( // text '/\[b(?::\w+)?\](.*?)\[\/b(?::\w+)?\]/si' => '$1', '/\[i(?::\w+)?\](.*?)\[\/i(?::\w+)?\]/si' => '$1', '/\[u(?::\w+)?\](.*?)\[\/u(?::\w+)?\]/si' => '$1', // code '/\[code(?::\w+)?\](.*?)\[\/code(?::\w+)?\]/si' => '
Kód:
$1
', // email '/\[email(?::\w+)?\](.*?)\[\/email(?::\w+)?\]/si' => '$1', '/\[email=(.*?)(?::\w+)?\](.*?)\[\/email(?::\w+)?\]/si' => '$1', // url '/\[url(?::\w+)?\](.*?)\[\/url(?::\w+)?\]/si' => '$1', '/\[url(?::\w+)?\]^(^http|https|news|ftp|www)(.*?)\[\/url(?::\w+)?\]/si' => 'www.$1', '/\[url(?::\w+)?\]((?:http|https|news|ftp)\:\/\/.*?)\[\/url(?::\w+)?\]/si' => '$1', '/\[url=((?:http|https|news|ftp)\:\/\/.*?)(?::\w+)?\](.*?)\[\/url(?::\w+)?\]/si' => '$2', '/\[url(?::\w+)?\](mailto\:)(.*?)\[\/url(?::\w+)?\]/si' => '$1', '/\[url=(mailto\:)(.*?)(?::\w+)?\](.*?)\[\/url(?::\w+)?\]/si' => '$2', // quote '/\[quote(?::\w+)?\](.*?)\[\/quote(?::\w+)?\]/si' => '
$1
', '/\[quote=(?:"|"|\')?(.*?)["\']?(?:"|"|\')?\](.*?)\[\/quote(?::\w+)?\]/si' => '
Cituji $1:
$2
', /* list - not used '/\[\*(?::\w+)?\]\s*([^\[]*)/si' => '
  • $1
  • ', '/\[list(?::\w+)?\](.*?)\[\/list(?::\w+)?\]/si' => '', '/\[list(?::\w+)?\](.*?)\[\/list:u(?::\w+)?\]/s' => '', '/\[list=1(?::\w+)?\](.*?)\[\/list(?::\w+)?\]/si' => '
      $1
    ', '/\[list=i(?::\w+)?\](.*?)\[\/list(?::\w+)?\]/s' => '
      $1
    ', '/\[list=I(?::\w+)?\](.*?)\[\/list(?::\w+)?\]/s' => '
      $1
    ', '/\[list=a(?::\w+)?\](.*?)\[\/list(?::\w+)?\]/s' => '
      $1
    ', '/\[list=A(?::\w+)?\](.*?)\[\/list(?::\w+)?\]/s' => '
      $1
    ', '/\[list(?::\w+)?\](.*?)\[\/list:o(?::\w+)?\]/s' => '
      $1
    ', // some cosmetic :) '/(?:.*?)/si' => '', '/(?:.*?)/si' => '', */ ); $message = preg_replace(array_keys($preg), array_values($preg), $message); // function to make clickable() Taken from: Nathan Codding - 6th February 2001 $ret = ' ' . $message; // adding break to make 1st line functional /* filtruje "xxxx://yyyy" URL na zacatku lajny nebo po mezere. xxxx muze byt pouze pismenny kod. yyyy je cokoliv po mezere, tabu, entru, carce, apostrofe nebo < . */ $ret = preg_replace('#([\t\r\n ])([a-z0-9]+?){1}://([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*)?)#i', '$1$2://$3', $ret); /* filtruje "www|ftp.xxxx.yyyy[/zzzz]", neco jako lazy URL Musi obsahovat aspon dve tecky. xxxx je alfanumericky nebo "-" zzzz je volitelny... */ $ret = preg_replace('#([\t\r\n ])(www|ftp)\.(([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*)?)#i', '$1$2.$3', $ret); /* filtruje email@domain typy adres na zacatku lajny i na konci. POZNAMKA: Pouze nasledujici znaky jsou povoleny: alfanumericky, "-", "_" a/nebo ".". NEED [[AntiSpam]] Snippet */ $ret = preg_replace('#([\n ])([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i', '$1[[AntiSpam?email=$2@$3]]', $ret); // Getting rid of bordel :-)... $ret = substr($ret, 1); $ret = nl2br($ret); return $ret; } // Don't allow unwanted re-posts of messages if($_POST['submitted'] == "TRUE") header( "Location: $aliasu" ); // Send email to admin when somebody posted a message if($_POST['submitted'] == "TRUE") { $MailMessage = $_lang_guestbook["email_author"].$_POST["subject"]."\r\n"; $MailMessage .= $_lang_guestbook["email_message"]."\r\n"; $MailMessage .= $_POST["message"]."\r\n"; $Headers = 'MIME-Version: 1.0' . "\r\n"; $Headers .= 'Content-type: text/plain; charset=' . $mailCharset . "\r\n"; $Headers .= 'Content-Transfer-Encoding: QUOTED-PRINTABLE' . "\r\n"; $Headers .= 'X-Mailer: PHP/' . phpversion() . "\r\n"; $Headers .= 'To: ' . $toAdmin . "\r\n"; $Headers .= 'From: ' . $fromMail . "\r\n"; mail($toAdmin, $MailSubject, $MailMessage, $Headers); } // Don't allow anybody to post snippets calls in GBook function nosnippet($nocalltext) { $preg = array( // [[neco]] '/\[\[(.*?)\]\]/si' => "[ [ $1 ] ]", // [!neco!] '/\[\!(.*?)\!\]/si' => "[ ! $1 ! ]", // [*neco*] '/\[\*(.*?)\*\]/si' => "[ * $1 * ]", ); $nocalltext = preg_replace(array_keys($preg), array_values($preg), $nocalltext); return $nocalltext; } // 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 = htmlspecialchars($_POST['message']); $sender_ip = $_SERVER['REMOTE_ADDR']; $sender_host = gethostbyaddr($_SERVER['REMOTE_ADDR']); // Query to INSERT a new GuestBook message into user_messages $sql = "INSERT INTO $msgdb ( id , type , subject , message , sender , recipient , private , postdate , messageread , sender_ip , sender_host ) VALUES ( '', '$type', '$subject', '$message', '0', '$recipient', '0', '$postdate', '0', '$sender_ip', '$sender_host');"; $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 .= ''; $output .= '
    '; $output .= '
    '; $output .= ''; $output .= $_lang_guestbook["name_or_alias"].'
    '; $output .= '
    '.$_lang_guestbook["message"].'
    '; $output .= '
    '; $output .= '
    '; $output .= '
    '; $output .= ' '; $output .= '
    '; $output .= '
    '; $output .= '
    '; } // Display write new message link else { $output .= '
    '; $output .= ''; $output .= ''; $output .= '
    '; } $output .= "

    ".$_lang_guestbook["messages"]."

    "; // 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 .= ' '; // Next page link $nextpage = $page+1; $nextpage_text = ' " onclick="window.location.href=\''.$pageurl.'&page='.$nextpage.'\'" />'; // Previous and next page links at top of the page $output .= '
    '; if ($previouspage > 0) { $output .= $previouspage_text; } if ($nextpage <= $pages) { $output .= $nextpage_text; } $output .= '
    '; // Empty lines if ($total > $messages) { $output .= "

    "; } // Show if is IP logged or not // (still working on it :) ) // 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 = $guestbookrec['message']; $postdate = strftime($dateformat, $guestbookrec['postdate']+$server_offset_time); $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= '
    '.$_lang_guestbook["sender"].' ' . nosnippet($poster) . '' . $postdate . '
    '.bbcode(nosnippet($message)).'
     '.$_lang_guestbook["count_message"].' ' . $number . '/' . $total . '

    '; } // Previous and next page links at bottom of the page $output .= '
    '; if ($previouspage > 0) { $output .= $previouspage_text; } if ($nextpage <= $pages) { $output .= $nextpage_text; } $output .= '
    '; } // If no valid GuestBook owner is found display error message... else $output = $_lang_guestbook["error"]; // Output return $output;