能否在用戶資訊view頁面上加上給屬主的guestbook鏈接

使用情景:
1)各用戶的資訊都反應在用戶自己的view頁面上,當訪客在查看用戶頁面時希望可以直接留言
2)guestbook模組現在都是通過用戶的列表訪問的

我的問題是
能否在用戶資訊view頁面上加上給屬主的guestbook鏈接

say2sky 的照片

Re:

當使用drupal4.7版本時, 是用如下方法實現view頁面上的用戶guestbook鏈接和用戶guestbook頁面返回用戶view鏈接, 當然我有知道這樣改不是好辦法, 但是對drupal的理解還是不夠.

1)實現view頁面上的用戶guestbook鏈接
在modules/views/views.module模組的
function views_build_view($type, &$view, $args = array(), $use_pager = false, $limit = 0, $page = 0, $offset = 0)中

添加
foreach (explode('/', $view->url) as $num => $element) {
if ($element == '$arg') {
$view_username = arg($num);
$result = db_result(db_query('SELECT uid FROM {users} WHERE name = "' . $view_username .'"' ));
$view->real_url ='/';
$output .= '
' . '' . $view_username . '的留言本' . '' . '

';
}
else {
//$output .= $element;
}
}

2)留言簿顯示頁面的用戶view返回鏈接
在modules/guestbook/guestbook.module模組

的function _guestbook_user_profile_link($uid)中

/*
$nametitle = t("Visit %name's profile", array('%name' => $guestbook_user->name));
$namelink = l($guestbook_user->name, "user/$uid", array("title" => $nametitle));

$output .= ' ' . t("Visit %name's profile", array('%name' => $namelink)) . "";
*/

$nametitle = t("Visit %name's profile", array('%name' => $guestbook_user->name));
$namelink = l($guestbook_user->name, "view/$guestbook_user->name", array("title" => $nametitle));

$output .= t("返回 %name 的健康檔案", array('%name' => $namelink));
替代

現在希望能有一個比較好的方法, 請給點建議 和指導

hom 的照片

Re:

gusetbook 的部分
通常這種修改盡量去找模組內有寫 theme function 的部分
在版型裡用 phptemplate 開頭的同名 function 再去覆寫 theme function
可以把原本的 theme function 內的程式碼直接複製到 覆寫的 function 下面 作修改
或是可以把覆寫的 function 改成完全不一樣的
可以避免直接去改寫原始的模組檔案

gusetbook.module 裡面的 theme function

<?php
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 text
 
$intro = _guestbook_info($uid, 'intro');
 
$output = $intro ? check_markup($intro) : '';
 
$output .= _guestbook_user_profile_link($uid);

 
// form on separate page
 
$output .= $form_location == 'separate page' ? guestbook_form_entry($uid, 'link') : '';
 
// form and pager above entries
 
$output .= $form_location == 'above' ? guestbook_form_entry($uid) : '';
 
$output .= $pager_position & GUESTBOOK_PAGER_ABOVE ? theme('pager', NULL, $limit, 0) : '';

  foreach (
$entries as $entry) {
   
$output .= theme('guestbook_entry', $uid, $entry, $comment_entry);
  }
 
 
// form and pager below entries
 
$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";
}
?>

把開頭換成 phptemplate 放到版型的 template.php 裡面

<?php
function phptemplate_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 text
 
$intro = _guestbook_info($uid, 'intro');
 
$output = $intro ? check_markup($intro) : '';

 
//$output .= _guestbook_user_profile_link($uid); 這部分改成你自己要的輸出

  // form on separate page
 
$output .= $form_location == 'separate page' ? guestbook_form_entry($uid, 'link') : '';
 
// form and pager above entries
 
$output .= $form_location == 'above' ? guestbook_form_entry($uid) : '';
 
$output .= $pager_position & GUESTBOOK_PAGER_ABOVE ? theme('pager', NULL, $limit, 0) : '';

  foreach (
$entries as $entry) {
   
$output .= theme('guestbook_entry', $uid, $entry, $comment_entry);
  }
 
 
// form and pager below entries
 
$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";
}
?>

say2sky 的照片

Re:

hom 我完成了.

雖然感謝是不夠的, 但是還是要說一聲謝謝, 你幫助我解決了好幾個最關鍵的問題. 讓我實現了構想中的所有功能.

也要感謝drupaltaiwan.org的其他朋友給予的幫助和指導.

同時也期望drupal的快速發展去幫助更多的用戶去實現他們的構想.