View source
<?php
if (module_exists("spam") == true) {
if (file_exists("modules/spam/spam.module")) {
include_once "modules/spam/spam.module";
}
else {
if (file_exists("sites/all/modules/spam/spam.module")) {
include_once "sites/all/modules/spam/spam.module";
}
}
}
define('GUESTBOOK_SITE_GUESTBOOK', 0x1);
define('GUESTBOOK_USER_GUESTBOOKS', 0x2);
define('GUESTBOOK_PAGER_ABOVE', 0x1);
define('GUESTBOOK_PAGER_BELOW', 0x2);
define('GUESTBOOK_TEXTAREA_ROWS', 8);
function guestbook_menu($may_cache) {
global $user;
$items = array();
$guestbook_mode = variable_get('guestbook_mode', GUESTBOOK_SITE_GUESTBOOK | GUESTBOOK_USER_GUESTBOOKS);
if ($may_cache) {
$items[] = array(
'path' => 'admin/settings/guestbook',
'title' => t('Guestbook'),
'callback' => 'drupal_get_form',
'callback arguments' => array(
'guestbook_admin_settings',
),
'access' => user_access('administer site configuration'),
);
if ($guestbook_mode & GUESTBOOK_USER_GUESTBOOKS) {
$items[] = array(
'path' => 'guestbook',
'title' => t('Guestbooks'),
'access' => user_access('access site guestbook') || user_access('access user guestbooks'),
'callback' => 'guestbook_list',
);
}
else {
$items[] = array(
'path' => 'guestbook',
'title' => variable_get('guestbook_site_title', t('Site guestbook')),
'access' => user_access('access site guestbook'),
'callback' => 'guestbook_page',
);
}
}
else {
if ($guestbook_mode & GUESTBOOK_USER_GUESTBOOKS) {
if ($user->uid > 0 && _guestbook_exists($user->uid)) {
$unread = _guestbook_newentries();
$unread = $unread ? ' (' . $unread . ')' : "";
$items[] = array(
'path' => 'guestbook/' . $user->uid,
'title' => t('My guestbook') . $unread,
'type' => MENU_DYNAMIC_ITEM,
);
}
}
if (arg(0) == 'guestbook' && is_numeric(arg(1))) {
$uid = arg(1);
$title = _guestbook_info($uid, 'title');
if ($guestbook_mode & GUESTBOOK_USER_GUESTBOOKS) {
$items[] = array(
'path' => 'guestbook/' . $uid,
'title' => $title,
'access' => $uid == 0 ? user_access('access site guestbook') : user_access('access user guestbooks'),
'type' => MENU_CALLBACK,
'callback' => 'guestbook_page',
'callback arguments' => array(
$uid,
),
);
}
$items[] = array(
'path' => 'guestbook/' . $uid . '/form',
'title' => t('Add guestbook entry'),
'access' => $uid == 0 ? user_access('post in site guestbook') : user_access('post in user guestbooks'),
'type' => MENU_CALLBACK,
'callback' => 'guestbook_page_form',
'callback arguments' => array(
$uid,
),
);
}
}
return $items;
}
function guestbook_user($op, &$edit, &$user, $category = '') {
$guestbook_mode = variable_get('guestbook_mode', GUESTBOOK_SITE_GUESTBOOK | GUESTBOOK_USER_GUESTBOOKS);
if ($guestbook_mode & GUESTBOOK_USER_GUESTBOOKS) {
switch ($op) {
case 'view':
if (user_access('access user guestbooks') && $user->guestbook_status == 0) {
$title = t("Read @username's guestbook.", array(
'@username' => $user->name,
));
$link = l(t('View recent guestbook entries'), "guestbook/{$user->uid}", array(
'title' => $title,
));
$items[] = array(
'title' => t('Guestbook'),
'value' => $link,
'class' => 'guestbook',
);
return array(
t('Guestbook') => $items,
);
}
break;
case 'form':
if ($category == 'account') {
$form['guestbook'] = array(
'#type' => 'fieldset',
'#title' => t('User guestbook'),
);
$form['guestbook']['guestbook_status'] = array(
'#type' => 'radios',
'#title' => t('Status'),
'#default_value' => $edit['guestbook_status'],
'#options' => array(
t('Enabled'),
t('Disabled'),
),
);
$form['guestbook']['guestbook_send_email'] = array(
'#type' => 'checkbox',
'#title' => t('Send email notification'),
'#description' => t("Uncheck if you don't wish to be notified of new entries to your guestbook."),
'#default_value' => isset($edit['guestbook_send_email']) ? $edit['guestbook_send_email'] : 1,
);
$form['guestbook']['guestbook_intro'] = array(
'#type' => 'textarea',
'#title' => t('Intro text'),
'#default_value' => $edit['guestbook_intro'],
'#cols' => 70,
'#rows' => GUESTBOOK_TEXTAREA_ROWS,
'#description' => t('The text that appears on top of your guestbook.'),
);
return $form;
}
break;
case 'delete':
db_query("DELETE FROM {guestbook} WHERE recipient = %d", $user->uid);
db_query("UPDATE {guestbook} SET author = 0 WHERE author = %d", $user->uid);
db_query("UPDATE {guestbook} SET commentauthor = 0 WHERE commentauthor = %d", $user->uid);
break;
}
}
}
function guestbook_perm() {
return array(
'access site guestbook',
'access user guestbooks',
'post in site guestbook',
'post in user guestbooks',
'administer all guestbooks',
);
}
function guestbook_help($section) {
switch ($section) {
case 'admin/modules#description':
return t('Adds a site guestbook and individual user guestbooks.');
}
}
function guestbook_admin_settings() {
$form['guestbook_mode'] = array(
'#type' => 'radios',
'#title' => t('Mode'),
'#default_value' => variable_get('guestbook_mode', GUESTBOOK_SITE_GUESTBOOK | GUESTBOOK_USER_GUESTBOOKS),
'#options' => array(
GUESTBOOK_SITE_GUESTBOOK | GUESTBOOK_USER_GUESTBOOKS => t('Site and user guestbooks'),
GUESTBOOK_SITE_GUESTBOOK => t('Site guestbook only'),
GUESTBOOK_USER_GUESTBOOKS => t('User guestbooks only'),
),
);
$form['site_guestbook'] = array(
'#type' => 'fieldset',
'#title' => t('Site guestbook'),
);
$form['site_guestbook']['guestbook_site_title'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
'#default_value' => variable_get('guestbook_site_title', t('Site guestbook')),
'#size' => 30,
'#maxlength' => 128,
'#description' => t("The site guestbook's page title."),
);
$form['site_guestbook']['guestbook_site_intro'] = array(
'#type' => 'textarea',
'#title' => t('Intro text'),
'#default_value' => variable_get('guestbook_site_intro', ''),
'#cols' => 70,
'#rows' => GUESTBOOK_TEXTAREA_ROWS,
'#description' => t('The text that appears on top of the site guestbook.'),
);
$form['site_guestbook']['guestbook_send_email'] = array(
'#type' => 'textfield',
'#title' => t('Send an notification to the following e-mail address about new guestbook entries'),
'#description' => t("Leave blank if you don't wish to be notified"),
'#size' => 30,
'#maxlength' => 128,
'#default_value' => variable_get('guestbook_send_email', ''),
);
$form['user_guestbooks'] = array(
'#type' => 'fieldset',
'#title' => t('User guestbooks'),
'#description' => t('Users can individually disable their guestbook or add an intro text on the user account page.'),
);
$form['user_guestbooks']['guestbook_user_link_to'] = array(
'#type' => 'radios',
'#title' => t('User link to profile or guestbook'),
'#description' => t('When displaying a user should the link show the user profile or the user guestbook?'),
'#options' => array(
'profile' => t('User profile'),
'guestbook' => t('User guestbook'),
),
'#default_value' => variable_get('guestbook_user_link_to', 'profile'),
);
$form['display_options'] = array(
'#type' => 'fieldset',
'#title' => t('Display options'),
);
$form['display_options']['guestbook_entries_per_page'] = array(
'#type' => 'textfield',
'#title' => t('Entries per page'),
'#default_value' => variable_get('guestbook_entries_per_page', 20),
'#size' => 3,
'#maxlength' => 3,
'#description' => t('The number of guestbook entries per page.'),
);
$form['display_options']['guestbook_display'] = array(
'#type' => 'checkboxes',
'#title' => t('Toggle display'),
'#default_value' => variable_get('guestbook_display', array(
'date',
'email',
'website',
'comments',
)),
'#options' => array(
'date' => t('Submission date'),
'email' => t('Anonymous poster e-mail'),
'website' => t('Anonymous poster website'),
'comments' => t('Comments'),
),
);
$form['display_options']['guestbook_pager_position'] = array(
'#type' => 'radios',
'#title' => t('Position of pager'),
'#default_value' => variable_get('guestbook_pager_position', GUESTBOOK_PAGER_BELOW),
'#options' => array(
GUESTBOOK_PAGER_ABOVE => t('Above the entries'),
GUESTBOOK_PAGER_BELOW => t('Below the entries'),
GUESTBOOK_PAGER_ABOVE | GUESTBOOK_PAGER_BELOW => t('Above and below the entries'),
),
);
$form['posting_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Posting settings'),
);
$form['posting_settings']['guestbook_input_format'] = filter_form(variable_get('guestbook_input_format', 0), NULL, array(
'guestbook_input_format',
));
$form['posting_settings']['guestbook_input_format']['#type'] = 'item';
$form['posting_settings']['guestbook_filter_tips'] = array(
'#type' => 'checkbox',
'#title' => t('Display filter tips'),
'#default_value' => variable_get('guestbook_filter_tips', TRUE),
'#description' => t('If enabled filter tips are displayed below the message textarea.'),
);
$form['posting_settings']['guestbook_anonymous_fields'] = array(
'#type' => 'checkboxes',
'#title' => t('Anonymous poster fields'),
'#default_value' => variable_get('guestbook_anonymous_fields', array(
'email',
'website',
)),
'#description' => t('Additional information that anonymous posters may supply.'),
'#options' => array(
'email' => 'E-mail',
'website' => 'Website',
),
);
$form['posting_settings']['guestbook_form_location'] = array(
'#type' => 'radios',
'#title' => t('Location of entry submission form'),
'#default_value' => variable_get('guestbook_form_location', 'above'),
'#options' => array(
'above' => t('Above entries'),
'below' => t('Below entries'),
'separate page' => t('Separate page'),
),
);
$form['array_filter'] = array(
'#type' => 'value',
'#value' => TRUE,
);
return system_settings_form($form);
}
function guestbook_page($uid = 0, $op = NULL, $op_id = NULL) {
global $user;
if (!_guestbook_exists($uid)) {
drupal_not_found();
return;
}
if ($uid > 0 && $user->uid == $uid) {
user_save($user, array(
'guestbook_visited' => time(),
));
}
$comment_entry = '';
if (_guestbook_access('administer', $uid) && is_numeric($op_id)) {
switch ($op) {
case 'delete':
return guestbook_delete_entry_confirm_page($uid, $op_id);
case 'comment':
$comment_entry = $op_id;
break;
}
}
$limit = variable_get('guestbook_entries_per_page', 20);
$result = pager_query("SELECT g.*, u1.name, u1.data, u1.picture, u2.name as commentby \n FROM {guestbook} g \n LEFT JOIN {users} u1 ON g.author = u1.uid \n LEFT JOIN {users} u2 ON g.commentauthor = u2.uid \n WHERE g.recipient = %d\n ORDER BY g.created DESC", $limit, 0, "SELECT COUNT(*) FROM {guestbook} WHERE recipient = %d", $uid);
$entries = array();
while ($entry = db_fetch_array($result)) {
$entries[] = $entry;
}
return theme('guestbook', $uid, $entries, $comment_entry, $limit);
}
function guestbook_page_form($uid) {
if (!_guestbook_exists($uid)) {
drupal_not_found();
return;
}
return guestbook_form_entry($uid, 'page');
}
function guestbook_list() {
$limit = 40;
$guestbooks = array();
$guestbook_mode = variable_get('guestbook_mode', GUESTBOOK_SITE_GUESTBOOK | GUESTBOOK_USER_GUESTBOOKS);
$header = array(
array(
'data' => t('user'),
'field' => 'u.name',
),
array(
'data' => t('entries'),
'field' => 'num',
),
array(
'data' => t('last update'),
'field' => 'created',
'sort' => 'desc',
),
);
$result = pager_query("SELECT u.uid, u.name, u.data, MAX(g.created) as created, COUNT(g.recipient) as num \n FROM {users} u \n LEFT OUTER JOIN {guestbook} g ON u.uid = g.recipient \n GROUP BY u.uid, u.name, u.data, g.recipient" . tablesort_sql($header), $limit, 0, "SELECT COUNT(*) FROM {users}");
while ($guestbook = db_fetch_array($result)) {
if ($guestbook['uid'] == 0 && user_access('access site guestbook') && $guestbook_mode & GUESTBOOK_SITE_GUESTBOOK) {
$guestbooks[0] = $guestbook;
}
else {
if ($guestbook['uid'] > 0 && user_access('access user guestbooks')) {
$data = unserialize($guestbook['data']);
if ($data['guestbook_status'] == 0) {
$guestbooks[$guestbook['uid']] = $guestbook;
}
}
}
}
return theme('guestbook_list', $guestbooks, $header, $limit);
}
function guestbook_form_entry($uid, $display = '') {
$output = drupal_get_form('guestbook_form_entry_form', $uid, $display);
return $output;
}
function guestbook_form_entry_form($uid, $display = '') {
global $user;
$form = array();
if ($user->uid == 0) {
$form['anonname'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
'#size' => 32,
'#maxlength' => 64,
'#required' => TRUE,
);
$anonymous_fields = (array) variable_get('guestbook_anonymous_fields', array(
'email',
'website',
));
if (in_array('email', $anonymous_fields)) {
$form['anonemail'] = array(
'#type' => 'textfield',
'#title' => t('E-mail'),
'#size' => 32,
'#maxlength' => 128,
);
}
if (in_array('website', $anonymous_fields)) {
$form['anonwebsite'] = array(
'#type' => 'textfield',
'#title' => t('Homepage'),
'#size' => 32,
'#maxlength' => 128,
);
}
}
$filter_tips = variable_get('guestbook_filter_tips', TRUE) ? _guestbook_form_filter_tips() : NULL;
$form['message'] = array(
'#type' => 'textarea',
'#title' => t('Message'),
'#cols' => 32,
'#rows' => GUESTBOOK_TEXTAREA_ROWS,
'#description' => $filter_tips,
'#required' => TRUE,
);
$form['send'] = array(
'#type' => 'submit',
'#value' => t('Send'),
);
$form['uid'] = array(
'#type' => 'value',
'#value' => $uid,
);
$form['access'] = array(
'#type' => 'value',
'#value' => _guestbook_access('post', $uid),
);
$form['display'] = array(
'#type' => 'value',
'#value' => $display,
);
return $form;
}
function guestbook_form_entry_form_submit($form_id, $edit) {
global $user;
$uid = $edit['uid'];
$message = $edit['message'];
$result = db_query("SELECT message FROM {guestbook} WHERE recipient = %d ORDER BY id DESC LIMIT 1", $uid);
$entry = db_fetch_array($result);
if ($entry['message'] == $message) {
return;
}
if ($message == '') {
return;
}
if (module_exists('spam')) {
$spamcheck = $edit['anonname'] . ' ' . $edit['anonemail'] . ' ' . $edit['anonwebsite'];
if (spam_content_filter('guestbook', 1, $spamcheck, $message, '_guestbook_spam')) {
return;
}
}
$iSendEmail = '';
$guestbook_mode = variable_get('guestbook_mode', GUESTBOOK_SITE_GUESTBOOK | GUESTBOOK_USER_GUESTBOOKS);
if ($uid == 0 && $guestbook_mode & GUESTBOOK_SITE_GUESTBOOK) {
$iSendEmail = variable_get('guestbook_send_email', '');
}
else {
if ($guestbook_mode & GUESTBOOK_USER_GUESTBOOKS) {
$guestbook_user = $uid != $user->uid ? user_load(array(
'uid' => $uid,
'status' => 1,
)) : $user;
if ($guestbook_user->uid && $guestbook_user->guestbook_status == 0 && $guestbook_user->guestbook_send_email) {
$iSendEmail = $guestbook_user->mail;
}
}
}
$from = variable_get('site_mail', ini_get('sendmail_from'));
if ($iSendEmail) {
drupal_mail('guestbook_notification', $iSendEmail, 'New guestbook entry', $message, $from);
}
if (_guestbook_access('post', $uid) == 'allowed') {
if ($user->uid == 0) {
$entryid = db_next_id('{guestbook}_id');
$result = db_query("INSERT INTO {guestbook} (id, anonname, anonemail, anonwebsite, author, recipient, message, created)\n VALUES(%d, '%s', '%s', '%s', %d, %d, '%s', %d)", $entryid, $edit['anonname'], $edit['anonemail'], $edit['anonwebsite'], 0, $uid, $message, time());
}
else {
$entryid = db_next_id('{guestbook}_id');
$result = db_query("INSERT INTO {guestbook} (id, author, recipient, message, created)\n VALUES(%d, %d, %d, '%s', %d)", $entryid, $user->uid, $uid, $message, time());
}
}
return 'guestbook/' . $uid;
}
function theme_guestbook_form_entry_form($form) {
$output = '';
$access = $form['access']['#value'];
$display = $form['display']['#value'];
$uid = $form['uid']['#value'];
switch ($access) {
case 'allowed':
if ($display == 'link') {
$output .= '<p>» ' . l(t('Add guestbook entry'), "guestbook/{$uid}/form") . '</p>';
}
else {
$output .= $display == 'page' ? '' : '<h3>' . t('Add guestbook entry') . '</h3>';
$output .= drupal_render($form);
}
break;
case 'own guestbook':
$output .= ' ';
break;
case 'not logged in':
$output .= '<p class="links">» ' . t('You must be logged in to post a comment.') . '</p>';
break;
case 'not allowed':
$output .= '<p class="links">» ' . t('You are not allowed to post in this guestbook.') . '</p>';
break;
}
return $output;
}
function guestbook_form_comment($uid, $entry) {
$output = drupal_get_form('guestbook_form_comment_form', $uid, $entry);
return $output;
}
function guestbook_form_comment_form($uid, $entry) {
$form = array();
$form['comment'] = array(
'#type' => 'textfield',
'#default_value' => check_plain($entry['comment']),
'#size' => 64,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Comment'),
);
$form['entry_id'] = array(
'#type' => 'value',
'#value' => $entry['id'],
);
$form['uid'] = array(
'#type' => 'value',
'#value' => $uid,
);
return $form;
}
function guestbook_form_comment_form_submit($form_id, $edit) {
global $user;
if (_guestbook_access('administer', $edit['uid'])) {
db_query("UPDATE {guestbook} SET comment = '%s', commentauthor = %d WHERE id = %d", $edit['comment'], $user->uid, $edit['entry_id']);
}
return array(
'guestbook/' . $edit['uid'],
$_GET['page'] ? 'page=' . $_GET['page'] : NULL,
);
}
function theme_guestbook_form_comment_form($form) {
$output = '';
$output .= '<div class="container-inline">';
$output .= drupal_render($form);
$output .= '</div>';
return $output;
}
function guestbook_delete_entry_confirm_page($uid, $entry_id) {
return drupal_get_form('guestbook_delete_entry_confirm', $uid, $entry_id);
}
function guestbook_delete_entry_confirm($uid, $entry_id) {
$entry = db_fetch_array(db_query("SELECT g.*, u1.name, u1.data, u1.picture, u2.name as commentby \n FROM {guestbook} g \n LEFT JOIN {users} u1 ON g.author = u1.uid \n LEFT JOIN {users} u2 ON g.commentauthor = u2.uid \n WHERE g.id = %d", $entry_id));
$form = array();
$form['entry_id'] = array(
'#type' => 'value',
'#value' => $entry_id,
);
$form['uid'] = array(
'#type' => 'value',
'#value' => $uid,
);
return confirm_form($form, t('Are you sure you want to delete this guestbook entry?\\n'), 'guestbook/' . $uid, theme('guestbook_entry', $uid, $entry, NULL, NULL, TRUE), t('Delete'), t('Cancel'));
}
function guestbook_delete_entry_confirm_submit($form_id, $form_values) {
if (_guestbook_access('administer', $form_values['uid']) && $form_values['confirm']) {
db_query("DELETE FROM {guestbook} WHERE id = %d", $form_values['entry_id']);
}
return 'guestbook/' . $form_values['uid'];
}
function theme_guestbook($uid, $entries, $comment_entry, $limit = 20) {
global $user;
$form_location = variable_get('guestbook_form_location', 'above');
$pager_position = variable_get('guestbook_pager_position', GUESTBOOK_PAGER_BELOW);
$intro = _guestbook_info($uid, 'intro');
$output = $intro ? check_markup($intro) : '';
$output .= _guestbook_user_profile_link($uid);
$output .= $form_location == 'separate page' ? guestbook_form_entry($uid, 'link') : '';
$output .= $form_location == 'above' ? guestbook_form_entry($uid) : '';
$output .= $pager_position & GUESTBOOK_PAGER_ABOVE ? theme('pager', NULL, $limit, 0) : '';
$i = 0;
foreach ($entries as $entry) {
$zebra = $i % 2 ? 'odd' : 'even';
$output .= theme('guestbook_entry', $uid, $entry, $comment_entry, $zebra);
$i++;
}
$output .= $pager_position & GUESTBOOK_PAGER_BELOW ? theme('pager', NULL, $limit, 0) : '';
$output .= $form_location == 'below' ? guestbook_form_entry($uid) : '';
return '<div class="guestbook">' . $output . "</div>\n";
}
function theme_guestbook_entry($uid, $entry, $comment_entry = NULL, $zebra, $confirm_delete = false) {
global $user;
$output = '';
$display = (array) variable_get('guestbook_display', array(
'date',
'email',
'website',
'comments',
));
$output .= "\n<div class=\"comment guestbook-entry {$zebra}\">\n";
if ($comment_entry == $entry['id']) {
$output .= '<a name="comment-entry"></a>';
}
if ($entry['author'] == 0) {
$author = "<b>" . check_plain($entry['anonname']) . "</b>";
}
else {
$author = "<b>" . theme('guestbook_user_picture', $entry['author']) . "</b>";
}
$output .= '<div class="author">' . $author . '</div>';
$output .= '<div class="submitted">';
if (in_array('date', $display)) {
$output .= format_date($entry['created'], 'medium');
}
if (in_array('email', $display) && !empty($entry['anonemail'])) {
$output .= ' | <a href="mailto:' . check_url($entry['anonemail']) . '">' . t('E-mail') . '</a>';
}
if (in_array('website', $display) && !empty($entry['anonwebsite'])) {
if (strpos($entry['anonwebsite'], '://') === FALSE) {
$entry['anonwebsite'] = 'http://' . $entry['anonwebsite'];
}
$output .= ' | <a href="' . check_url($entry['anonwebsite']) . '">' . t('Website') . '</a> ';
}
$output .= '</div>';
$output .= '<div class="content guestbook-message">' . check_markup($entry['message'], variable_get('guestbook_input_format', 1), FALSE) . '</div>';
if ($entry['picture']) {
$output .= '<div style="clear:both;"></div>';
}
$output .= theme('guestbook_entry_comment', $uid, $entry, $comment_entry);
if (_guestbook_access('administer', $uid) && !$confirm_delete) {
if ($comment_entry != $entry['id']) {
$pager = $_GET['page'] ? 'page=' . $_GET['page'] : NULL;
$output .= '<div class="links">» ';
$output .= l(t('Delete entry'), "guestbook/{$uid}/delete/{$entry['id']}", array(), $pager) . ' | ';
$output .= l($entry['comment'] == '' ? t('Add comment') : t('Edit comment'), "guestbook/{$uid}/comment/{$entry['id']}", array(), $pager, 'comment-entry');
$output .= '</div>';
}
}
$output .= "\n</div>";
return $output;
}
function theme_guestbook_user_picture($uid) {
$account = user_load(array(
'uid' => $uid,
));
$output = $account->name;
if (variable_get('user_pictures', 0)) {
if ($account->picture && file_exists($account->picture)) {
$picture = file_create_url($account->picture);
}
else {
if (variable_get('user_picture_default', '')) {
$picture = variable_get('user_picture_default', '');
}
}
if (variable_get('guestbook_mode', -1) == GUESTBOOK_SITE_GUESTBOOK && user_access('access user profiles')) {
$user_link = "user/{$account->uid}";
$user_text = t('View user profile.');
}
else {
if (variable_get('guestbook_user_link_to', 'profile') == 'profile' && user_access('access user profiles')) {
$user_link = 'user/' . $account->uid;
$user_text = t('View user profile.');
}
else {
if (variable_get('guestbook_user_link_to', 'profile') == 'guestbook' && user_access('access user guestbooks')) {
$user_link = "guestbook/{$account->uid}";
$user_text = t('View user guestbook.');
}
else {
$user_link = 'guestbook';
$user_text = t('View guestbooks.');
}
}
}
$output = l($account->name ? $account->name : variable_get('anonymous', 'Anonymous'), $user_link, array(
'title' => $user_text,
));
if (isset($picture)) {
$alt = t("@user's picture", array(
'@user' => $account->name ? $account->name : variable_get('anonymous', 'Anonymous'),
));
$picture = theme('image', $picture, $alt, $alt, '', false);
if (!empty($account->uid) && user_access('access user profiles')) {
$picture = l($picture, $user_link, array(
'title' => $user_text,
), NULL, NULL, FALSE, TRUE);
}
$output .= "<div class=\"picture\">{$picture}</div>";
}
}
return $output;
}
function theme_guestbook_entry_comment($uid, $entry, $comment_entry) {
$display = (array) variable_get('guestbook_display', array(
'date',
'email',
'website',
'comments',
));
$output = '';
if ($comment_entry == $entry['id']) {
$output .= guestbook_form_comment($uid, $entry);
}
else {
if (in_array('comments', $display) && $entry['comment'] != '') {
$commentby = user_access('access user profiles') ? l($entry['commentby'], "user/{$entry['commentauthor']}") : $entry['commentby'];
$output .= '<small>' . t('Comment by') . ' ' . $commentby . "</small><br />";
$output .= '<em>' . check_plain($entry['comment']) . '</em>';
}
}
return '<div class="guestbook-comment content">' . $output . '</div>';
}
function theme_guestbook_list($guestbooks, $header, $limit = 40) {
$output = '';
if (isset($guestbooks[0])) {
$output .= '<p>' . l(variable_get('guestbook_site_title', t('Site guestbook')), 'guestbook/0');
$output .= ' (' . format_plural($guestbooks[0]['num'], '1 entry', '@count entries') . ', ' . t('last update') . ': ' . _guestbook_timeinterval($guestbooks[0]['created']) . ')</p>';
unset($guestbooks[0]);
}
if (count($guestbooks)) {
$output .= '<h4>' . t('User guestbooks') . '</h4>';
$rows = array();
foreach ($guestbooks as $guestbook) {
$rows[] = array(
l($guestbook['name'], 'guestbook/' . $guestbook['uid']),
format_plural($guestbook['num'], '1 entry', '@count entries'),
array(
'data' => _guestbook_timeinterval($guestbook['created']),
'align' => 'right',
),
);
}
$output .= theme('table', $header, $rows);
}
$output .= theme('pager', NULL, $limit, 0);
return $output;
}
function _guestbook_info($uid, $data) {
global $user;
static $info;
$guestbook_mode = variable_get('guestbook_mode', GUESTBOOK_SITE_GUESTBOOK | GUESTBOOK_USER_GUESTBOOKS);
if (!isset($info[$uid])) {
if ($uid == 0 && $guestbook_mode & GUESTBOOK_SITE_GUESTBOOK) {
$info[$uid]['title'] = variable_get('guestbook_site_title', t('Site guestbook'));
$info[$uid]['intro'] = variable_get('guestbook_site_intro', '');
}
else {
if ($guestbook_mode & GUESTBOOK_USER_GUESTBOOKS) {
$guestbook_user = $uid != $user->uid ? user_load(array(
'uid' => $uid,
)) : $user;
if ($guestbook_user->uid && ($guestbook_user->status || user_access('administer users')) && empty($guestbook_user->guestbook_status)) {
$info[$uid]['title'] = t("@username's guestbook", array(
'@username' => $guestbook_user->name,
));
$info[$uid]['intro'] = $guestbook_user->guestbook_intro;
}
}
}
}
return $info[$uid][$data];
}
function _guestbook_user_profile_link($uid) {
global $user;
$guestbook_mode = variable_get('guestbook_mode', GUESTBOOK_SITE_GUESTBOOK | GUESTBOOK_USER_GUESTBOOKS);
$output = '';
if ($guestbook_mode & GUESTBOOK_USER_GUESTBOOKS && user_access('access user profiles') && $uid != $user->uid) {
$guestbook_user = user_load(array(
'uid' => $uid,
'status' => 1,
));
if ($guestbook_user->uid && $guestbook_user->guestbook_status == 0) {
$namelink = l($guestbook_user->name, "user/{$uid}", array(
'title' => t('View user profile.'),
));
$output .= '<div class="submitted">' . t("Visit !username's profile", array(
'!username' => $namelink,
)) . '</div>';
}
}
return $output;
}
function _guestbook_exists($uid) {
$title = _guestbook_info($uid, 'title');
return !empty($title);
}
function _guestbook_access($action, $uid) {
global $user;
switch ($action) {
case 'post':
if ($uid == 0 ? user_access('post in site guestbook') : user_access('post in user guestbooks')) {
if (!($user->uid == $uid && $user->uid > 0)) {
return 'allowed';
}
else {
return 'own guestbook';
}
}
else {
if ($user->uid == 0) {
return 'not logged in';
}
else {
if ($user->uid != $uid) {
return 'not allowed';
}
}
}
break;
case 'administer':
return user_access('administer all guestbooks') || $uid == $user->uid && $user->uid > 0;
}
}
function _guestbook_timeinterval($time) {
if ($time == 0) {
return t('never');
}
else {
return format_interval(time() - $time, 1);
}
}
function _guestbook_newentries() {
global $user;
$count = db_result(db_query("SELECT COUNT(created) FROM {guestbook} WHERE recipient = %d AND created > %d", $user->uid, $user->guestbook_visited));
return $count;
}
function _guestbook_form_filter_tips() {
$format = variable_get('guestbook_input_format', 1);
$tips = theme('filter_tips', _filter_tips($format));
return $tips;
}
function _guestbook_spam($source, $id, $header, $body, $probability, $old, $action) {
if ($probability > 98) {
$msgtext = t('Entry is spam: ') . $header . ' ' . $body . ' probability: ' . $probability;
watchdog('guestbook', $msgtext, WATCHDOG_WARNING);
drupal_set_message($msgtext, 'error');
return TRUE;
}
return FALSE;
}