Hello All,

I am trying to integrate guestbook.module and user_profile.tpl.php. Here is how I would like it to work.

Ideally,

I would like the whole user guestbook to be included right alongside all of the other users info in the profile page. For example, the last 10 user guestbook entries (with user photos) would be included in the user profile page.

Alternatively,

the guestbook can be all by itself in a new tab. For example,
* view
* guestbook
* edit
* track
* contact
However, this solution would not be as desireable as the first one.

As a last resort,

Just making a simple link work to the users guestbook (view $users guestbook). This is how the guestbook hooks into the user profile now, but how could I make that work with the user_profile.tpl.php? Again, this solution is only what is needed if neither of the first two are doable.

Please use the contact tab in my user profile at the link below to send any bids and how long this job would take.
http://drupal.org/user/32425/contact

or if it is a simple enough solution for a non-coder to tackle, just post in this thread and I will be much appreciative of your troubles

Comments

neablo’s picture

sorry, I cannot help you
but I need this one, too!!!

Dublin Drupaller’s picture

I just tried this with Drupal 4.6.5 and it works fine..

Change the Div classes to suit. It's very lengthy, but it works.

This snippet is for use with a custom user_profile.tpl.php file.

Instructions: paste the entire snippet below/above/whatever content you want it to appear in the user profile page, edit the "no messages text" and DIV class/text to suit.

<!--start of  guest book snippet for user_profile.tpl.php -->
<div class="guestbook">
<h2><?php print $user->name;?> 's Guestbook</h2>
<P>Here's a list of messages for <?php print $user->name; ?>.</p>

<?php

/**
* do not chhange anything below this line unless you know what you are doing
* Tested with Drupal 4.6.3
* change $limit to the number of guestbook entries displayed.
* change $nomessages to display some nice text for users with no guestbook entries
*/


$uid=$user->uid;
$limit= 10;
$nomessages = "<p>Sorry, there are no messages left for $user->name yet.</p>";
/**
* do not chhange anything below this line unless you know what you are doing
* Tested with Drupal 4.6.3
*/


global $user;
	if (( $user->uid != $uid && $user->uid > 0 ) 
      || ( $user->uid == 0 && $uid == 0) ) {
    $output .= "<div class=content>" . t('Add questbook entry:') 
      . "<br /><form method=post action=\"" . url("/guestbook/$uid") . "\">";

    if ( $user->uid == 0 ) {
      $output .= "Name: <input type=text size=16 name=guestbook_anonname><br />";
    }

    $output .= "<textarea type=text rows=3 cols=50 name=guestbook_newentry></textarea>"
      . "<input type=hidden name=guestbook value=newentry>"
      . "<input type=submit name=guestbook_submit value=\""
      . t('send') . "\"></form></div><br />\n";
  } 
  else if ( $user->uid == 0 ) {
    $output .= "<br><div class=\"links\">&raquo; You must be logged in to post a comment</div><br>";   
 	 }
$result = pager_query("SELECT g.id, g.anonname, g.author, g.recipient, 
    g.comment, g.message, g.created, u.name, u.data, u.picture FROM {guestbook} g, {users} u 
    WHERE g.author = u.uid AND g.recipient = '$uid' ORDER BY g.id DESC", 
    $limit, 
    0, "SELECT COUNT(*) FROM {guestbook} WHERE recipient='$uid'");

  while ($entry = db_fetch_array($result)) {
    if ( $entry["author"] == 0 && $entry["anonname"] != "" ) {
      $authorname = $entry["anonname"]; 
    }
    else {
      if ($entry["picture"]) {
        $avatarpicture = "<img src=\"/" . $entry["picture"]
          . "\" height=70 border=0 align=left hspace=5 vspace=2>";
      }
      else $avatarpicture = "";

      $authorname = "<a href=\"" . url("/user/{$entry["author"]}/view") . "\">" 
        . $avatarpicture . $entry["name"] . "</a>";   
    }
    $output .= "<div class=comment>\n<div class=author>$authorname (" 
      .  format_date($entry["created"], "small") . ")\n";

    if ( ( user_access("administer all guestbooks") || $entry["recipient"] == $user->uid ) && $user->uid > 0) {
      $output .= "&nbsp;&nbsp;<a href=\"" . url("/guestbook/$uid?guestbook_deleteentry={$entry["id"]}") 
        .  "\">" . t('delete entry') . "</a>\n";
    }

    $output .= "</div>\n<div class=content>" . $entry["message"] . "</div>\n";

    $output .= "<div class=content>\n";

    if ( $entry["recipient"] == $user->uid && $user->uid >0 ) {
      if ( $_GET["guestbook_editcomment"] == $entry["id"] ) {
        $output .= "<form method=post action=\"" . url("/guestbook/$uid") 
          . "\"><input size=50 type=text name=guestbook_comment value=\"{$entry["comment"]}\">"
          . "<input type=hidden name=guestbook_entryid value={$entry["id"]}>" 
          . "<input type=hidden name=guestbook value=comment>"
          . "<input type=submit name=guestbook_submit value=\"" . t('comment') . "\"></form>";
      }
      else if ( $entry["comment"] == "" ) {
        $output .= "<small><a href=\"" . url("/guestbook/$uid?guestbook_editcomment={$entry["id"]}") . "\">" . t('add comment') . "</a></small>";
      }
      else {
        $output .= "<em>&nbsp;&nbsp;" . $entry["comment"] . "</em>&nbsp;&nbsp;"
          . "&nbsp;&nbsp;<small><a href=\"" . url("/guestbook/$uid?guestbook_editcomment={$entry["id"]}") . "\">" . t('edit comment') . "</a></small>";
      }
    }
    else if ( $entry["comment"] != "" ) {
      $output .= "<em>&nbsp;&nbsp;" . $entry["comment"] . "</em>";
    }
    $output .= "</div> <div style=\"clear: both;\"></div>  </div><br />";
  }
  if (!$output) {$output = $nomessages;} else {$output .= theme_pager(NULL, $limit, 0);}

  $breadcrumb[] = l(t("Home"), NULL);
  $breadcrumb[] = l(t("Guestbooks"), "/guestbook");
  $breadcrumb[] = t("%name's guestbook", array("%name" => $bookowner));

  print $output;
?>
</div>
<!--end of  guest book snippet for user_profile.tpl.php -->

Hope that helps..

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

flufftronix’s picture

Now, if only guestbook.module was 4.7 compatible.. ;p

neablo’s picture

I cant test it right now, my ftp-server is down
but nevertheless I want to thank you very much, dublin drupaller!

Anonymous’s picture

Yes, thank you very much indeed!

Works exactly like I wanted it to!

hba’s picture

This issue is tracked on http://drupal.org/node/34484. If anyone is updating this hack for 4.7, please post the patch there.

kgp22’s picture

Thanks for the snippet, dub.
Here's something that validates:

<div id="user-testimonials">
<h1 class="testimonials"><?php print l($user->user_name.' s testimonials' ,'user/'. $user->uid); ?> </h1>
<?php

/**
* do not chhange anything below this line unless you know what you are doing
* Tested with Drupal 4.6.3
* change $limit to the number of guestbook entries displayed.
* change $nomessages to display some nice text for users with no guestbook entries
*/

$uid=$user->uid;
$limit= 10;
$nomessages = "<p>Sorry, there are no  left for $user->name yet.</p>";
/**
* do not chhange anything below this line unless you know what you are doing
* Tested with Drupal 4.6.3
*/

global $user;
    if (( $user->uid != $uid && $user->uid > 0 )
      || ( $user->uid == 0 && $uid == 0) ) {
    $output .= "<div class=content>" . t('Add a Testimonial:')
      . "<br /><form method=post action=\"" . url("/guestbook/$uid") . "\">";

    if ( $user->uid == 0 ) {
      $output .= "Name: <input type=text size=16 name=guestbook_anonname><br />";
    }

    $output .= "<textarea  rows=3 cols=50 name=guestbook_newentry></textarea>"
      . "<input type=hidden name=guestbook value=newentry />"
      . "<input type=submit name=guestbook_submit value=\""
      . t('send') . "\"/></form></div><br />\n";
  }
  else if ( $user->uid == 0 ) {
    $output .= "<br><div class=\"links\">&raquo; You must be logged in to post a comment</div><br>"; 
      }
$result = pager_query("SELECT g.id, g.anonname, g.author, g.recipient,
    g.comment, g.message, g.created, u.name, u.data, u.picture FROM {guestbook} g, {users} u
    WHERE g.author = u.uid AND g.recipient = '$uid' ORDER BY g.id DESC",
    $limit,
    0, "SELECT COUNT(*) FROM {guestbook} WHERE recipient='$uid'");

  while ($entry = db_fetch_array($result)) {
    if ( $entry["author"] == 0 && $entry["anonname"] != "" ) {
      $authorname = $entry["anonname"];
    }
    else {
      if ($entry["picture"]) {
        $avatarpicture = "<img src=\"/" . $entry["picture"]
          . "\"  alt=user height=70 border=0 align=left hspace=5 vspace=2 />";
      }
      else $avatarpicture = "";

      $authorname = "<div class='userpictestimonial'><a href=\"" . url("http://www.yoursite.com/user/{$entry["author"]}/view") . "\">"
        . $avatarpicture . $entry["name"] . "</a></div>"; 
    }
    $output .= "<div class=comment>\n<div class=author>$authorname ("
      .  format_date($entry["created"], "small") . ")\n";

    if ( ( user_access("administer all guestbooks") || $entry["recipient"] == $user->uid ) && $user->uid > 0) {
      $output .= "&nbsp;&nbsp;<a href=\"" . url("/guestbook/$uid?guestbook_deleteentry={$entry["id"]}")
        .  "\">" . t('delete entry') . "</a>\n";
    }

    $output .= "</div>\n<div id=testimonial>" . $entry["message"] . "</div>\n";

    $output .= "<div id=content>\n";

    if ( $entry["recipient"] == $user->uid && $user->uid >0 ) {
      if ( $_GET["guestbook_editcomment"] == $entry["id"] ) {
        $output .= "<form method=post action=\"" . url("/guestbook/$uid")
          . "\"><input size=50 type=text name=guestbook_comment value=\"{$entry["comment"]}\">"
          . "<input type=hidden name=guestbook_entryid value={$entry["id"]}>"
          . "<input type=hidden name=guestbook value=comment>"
          . "<input type=submit name=guestbook_submit value=\"" . t('comment') . "\"></form>";
      }
      else if ( $entry["comment"] == "" ) {
        $output .= "<small><a href=\"" . url("/guestbook/$uid?guestbook_editcomment={$entry["id"]}") . "\">" . t('add comment') . "</a></small>";
      }
      else {
        $output .= "<em>&nbsp;&nbsp;" . $entry["comment"] . "</em>&nbsp;&nbsp;"
          . "&nbsp;&nbsp;<small><a href=\"" . url("/guestbook/$uid?guestbook_editcomment={$entry["id"]}") . "\">" . t('edit comment') . "</a></small>";
      }
    }
    else if ( $entry["comment"] != "" ) {
      $output .= "<em>&nbsp;&nbsp;" . $entry["comment"] . "</em>";
    }
    $output .= "</div> <div style=\"clear: both;\"></div>  </div><br />";
  }
  if (!$output) {$output = $nomessages;} else {$output .= theme_pager(NULL, $limit, 0);}

  $breadcrumb[] = l(t("Home"), NULL);
  $breadcrumb[] = l(t("Guestbooks"), "/guestbook");
  $breadcrumb[] = t("%name's guestbook", array("%name" => $bookowner));

  print $output;
?>
</div>

--
Even a clock that does not tick is right twice in a day

Julius’s picture

from other forum

$uid5= arg(1);
print module_invoke('guestbook', 'page', $uid5);

The $uid5 could be simpler, but I forgot, this works anyway. (in 4.7)

dakku’s picture

Thank you so much for the code you posted above. I had to tweak it a little, but you can see an example here: http://www.themes4urmobilephone.com/user/corleno

Next up: modify the actual guestbook page itself..

Thanks again..

. - dot’s picture

can you post a photo (not a profle photo) to a guestbook node?

. - dot’s picture

kk

. - dot’s picture

,

dakku’s picture

Hi,
It is possible to modify the guestbook page too. Although i have only done a basic mod due to limited time. But a lot can be done with a little bit of imagination. see example on my site..(http://www.themes4urmobilephone.com/guestbook/6554).

gurukripa’s picture

Hi

you user profile page is very nice.

can u share the code..so we can figure it out too..u cld upload the file here..then we can learn...or cld u paste it in the comment box.
thanks

My internet voluntary services include

1. Helping answer queries on www.krishna.com
2. Learning & Helping in the Vedic section of www.spiritualnectar.com
3. Helped in some aspects to make www.indiapoised.org
4. Learning & ( Helping newbies) on www.

childfreecommunity_com’s picture

For Drupal 6.9 this worked for me...

I do a direct call to the function in guestbook.module that creates the guestbook page. Paste this code into your user-profile.tpl.php:

   if (module_exists('guestbook')) { 
      if(!$account->guestbook_status){  
         print guestbook_page($account, $op = NULL, $op_id = NULL, $page = TRUE);
      }
   }

It works beautifully and returns the user back to the profile page after posting.

halloffame’s picture

Heya! The above code does not return you to profile page after posting. After pressing the send button you are redirected to guestbook page.