Re: [FINAL] AJAX Userinfo 1.0.4
Verfasst: 19.01.2012 18:50
Hallo! Die Antwort auf die Frage von Secretly fänd ich auch sehr interessant, also wenn da jemand Hilfe oder einen Rat hat, wären wir schon zwei dankbare Persönchen! 

phpBB.de - Die deutsche phpBB-Community
https://www.phpbb.de/community/
Ja, ist ja auch logisch. Du musst natürlich erst einmal die SQL-Abfrage schreiben, da du ja Daten aus einer anderen Tabelle (PROFILE_FIELDS_DATA_TABLE --> also phpbb_profile_fields_data ) holen möchtest.Secretly hat geschrieben:Hallo,
besteht die Möglichkeit, dass man den Inhalt auch gegen Profilfelder austauschen kann? Ich hatte es schon mit viewtopic.php?p=1178888#p1178888 diesem versucht, bzw. nach dem Muster, aber leider mache ich da wohl etwas falsch.
(status ist die Feld-Kennung des Profilfelds)Code: Alles auswählen
echo '<profile_status><![CDATA[' . $row['user_profile_status'] . ']]></profile_status>';
Code: Alles auswählen
// Select some userdata from DB
$sql = 'SELECT username, username_clean, user_regdate, user_posts, user_from, user_lastvisit, user_avatar, user_avatar_type, user_avatar_width, user_avatar_height, user_colour, user_website, user_rank
FROM ' . USERS_TABLE . '
WHERE user_id = '. (int) $ajax_userid;
$result = $db->sql_query($sql);
Code: Alles auswählen
// Select some userdata from DB
$sql = 'SELECT user_profile_status
FROM ' . PROFILE_FIELDS_DATA_TABLE . '
WHERE user_id = '. (int) $ajax_userid;
$result1 = $db->sql_query($sql);
Code: Alles auswählen
if($row = $db->sql_fetchrow($result))
Code: Alles auswählen
if($row = $db->sql_fetchrow($result) and $row1 = $db->sql_fetchrow($result1))
Code: Alles auswählen
// Get username with usercolor
$username = get_username_string('full', $ajax_userid, $row['username'], $row['user_colour'], $row['username_clean']);
Code: Alles auswählen
//Zeilenumbruch ab 30 Zeilen
$user_profile_status = $row1['user_profile_status'];
$user_profile_status = wordwrap( $user_profile_status, 30, "<br />\n" );
Code: Alles auswählen
echo '<lastvisit><![CDATA[' . (!empty($row['user_lastvisit']) ? $user->format_date($row['user_lastvisit']) : $user->lang['NA']) . ']]></lastvisit>';
echo '<website><![CDATA[' . (!empty($row['user_website']) ? $row['user_website'] : $user->lang['NA']) . ']]></website>';
Code: Alles auswählen
echo '<user_profile_status><![CDATA[' . (!empty($user_profile_status) ? $user_profile_status : $user->lang['NA']) . ']]></user_profile_status>';
Code: Alles auswählen
$db->sql_freeresult($result);
Code: Alles auswählen
$db->sql_freeresult($result1);
Code: Alles auswählen
document.getElementById('ajax_website').innerHTML = ' ';
Code: Alles auswählen
document.getElementById('ajax_user_profile_status').innerHTML = ' ';
Code: Alles auswählen
document.getElementById('ajax_website').innerHTML = xmlDoc.getElementsByTagName('website')[0].firstChild.nodeValue;
Code: Alles auswählen
document.getElementById('ajax_user_profile_status').innerHTML = xmlDoc.getElementsByTagName('user_profile_status')[0].firstChild.nodeValue;
Code: Alles auswählen
<strong>{L_WEBSITE}:</strong> <span id="ajax_website"></span><br />
Code: Alles auswählen
<strong>Profilstatus:</strong> <span id="ajax_user_profile_status"></span><br />
Code: Alles auswählen
<script type="text/javascript">
// <![CDATA[
// show the popup
function show_popup(UserID) {
if(http_getuser) {
document.getElementById('popup').style.display='block'; sendRequest(UserID);
}
}
// hide the popup
function close_popup() {
document.getElementById('popup').style.display='none';
document.getElementById('ajax_username').innerHTML = ' ';
document.getElementById('ajax_registert').innerHTML = ' ';
document.getElementById('ajax_posts').innerHTML = ' ';
document.getElementById('ajax_website').innerHTML = ' ';
document.getElementById('ajax_user_profile_size').innerHTML = ' ';
document.getElementById('ajax_user_profile_figure').innerHTML = ' ';
document.getElementById('ajax_user_profile_eye').innerHTML = ' ';
document.getElementById('ajax_user_profile_hair').innerHTML = ' ';
document.getElementById('ajax_user_profile_features').innerHTML = ' ';
document.getElementById('ajax_from').innerHTML = ' ';
document.getElementById('ajax_last_visit').innerHTML = ' ';
document.getElementById('ajax_rank').innerHTML = ' ';
document.getElementById('ajax_avatar').innerHTML = ' ';
document.getElementById('ajax_rankimage').innerHTML = ' ';
}
// Make the request
function createRequestObject() {
if(window.XMLHttpRequest){
ro = new XMLHttpRequest();
} else if(window.ActiveXObject) {
ro = new ActiveXObject("Msxml2.XMLHTTP");
if(!ro) {
ro = new ActiveXObject("Microsoft.XMLHTTP");
}
}
return ro;
}
var http_getuser = createRequestObject();
function sendRequest(UserID) {
var userinfo_url = '{AJAX_USERINFO_PATH}';
http_getuser.open('get', userinfo_url.replace('USERID', UserID));
http_getuser.onreadystatechange = handleResponse;
http_getuser.send(null);
}
// fill in the response
function handleResponse() {
if(http_getuser.readyState == 4 ){
var xmlDoc = http_getuser.responseXML;
if(xmlDoc.hasChildNodes()) {
document.getElementById('ajax_username').innerHTML = xmlDoc.getElementsByTagName('username')[0].firstChild.nodeValue;
document.getElementById('ajax_registert').innerHTML = xmlDoc.getElementsByTagName('regdate')[0].firstChild.nodeValue;
document.getElementById('ajax_posts').innerHTML = xmlDoc.getElementsByTagName('posts')[0].firstChild.nodeValue;
document.getElementById('ajax_website').innerHTML = xmlDoc.getElementsByTagName('website')[0].firstChild.nodeValue;
document.getElementById('ajax_user_profile_size').innerHTML = xmlDoc.getElementsByTagName('user_profile_size')[0].firstChild.nodeValue;
document.getElementById('ajax_user_profile_figure').innerHTML = xmlDoc.getElementsByTagName('user_profile_figure')[0].firstChild.nodeValue;
document.getElementById('ajax_user_profile_eye').innerHTML = xmlDoc.getElementsByTagName('user_profile_eye')[0].firstChild.nodeValue;
document.getElementById('ajax_user_profile_hair').innerHTML = xmlDoc.getElementsByTagName('user_profile_hair')[0].firstChild.nodeValue;
document.getElementById('ajax_user_profile_features').innerHTML = xmlDoc.getElementsByTagName('user_profile_features')[0].firstChild.nodeValue;
document.getElementById('ajax_from').innerHTML = xmlDoc.getElementsByTagName('from')[0].firstChild.nodeValue;
document.getElementById('ajax_last_visit').innerHTML = xmlDoc.getElementsByTagName('lastvisit')[0].firstChild.nodeValue;
document.getElementById('ajax_rank').innerHTML = xmlDoc.getElementsByTagName('rank')[0].firstChild.nodeValue;
document.getElementById('ajax_avatar').innerHTML = xmlDoc.getElementsByTagName('avatar')[0].firstChild.nodeValue;
document.getElementById('ajax_rankimage').innerHTML = xmlDoc.getElementsByTagName('rankimage')[0].firstChild.nodeValue;
//document.getElementById('popup').style.display='block';
}
}
}
// set popup to mouse possition
function set_div_to_mouse(e) {
var docX, docY;
if(e) {
if(typeof(e.pageX) == 'number') { docX = e.pageX; docY = e.pageY;}
else {docX = e.clientX; docY = e.clientY;}
} else {
e = window.event;
docX = e.clientX; docY = e.clientY;
if(document.documentElement && (document.documentElement.scrollTop || document.documentElement.scrollLeft)) {
docX += document.documentElement.scrollLeft; docY += document.documentElement.scrollTop;
}
else if(document.body && (document.body.scrollTop || document.body.scrollLeft)) {
docX += document.body.scrollLeft; docY += document.body.scrollTop;
}
}
if (docX > document.body.offsetWidth - 400) {
document.getElementById('popup').style.left = (docX - 350) + "px";
} else {
document.getElementById('popup').style.left = (docX - 5) + "px";
}
document.getElementById('popup').style.top = (docY + 30) + "px";
}
document.onmousemove = set_div_to_mouse;
// ]]>
</script>
<div class="forabg" id="popup" style="display: none;">
<div class="inner">
<span class="corners-top"><span></span></span>
<ul class="topiclist fullwidth">
<li class="header"><dl><dt>{L_READ_PROFILE}</dt></dl></li>
</ul>
<ul class="topiclist forums">
<li><dl>
<dd style="width:100%">
<strong>{L_USERNAME}:</strong> <span id="ajax_username"></span><br />
<strong>{L_TOTAL_POSTS}:</strong> <span id="ajax_posts"></span><br />
<strong>{L_SORT_RANK}:</strong> <span id="ajax_rank"></span><br />
<strong>{L_JOINED}:</strong> <span id="ajax_registert"></span><br />
<strong>{L_LAST_VISIT}:</strong> <span id="ajax_last_visit"></span><br />
<strong>{L_LOCATION}:</strong> <span id="ajax_from"></span><br />
<strong>{L_WEBSITE}:</strong> <span id="ajax_website"></span><br />
<strong>Größe:</strong> <span id="ajax_user_profile_size"></span><br />
<strong>Statur:</strong> <span id="ajax_user_profile_figure"></span><br />
<strong>Augenfarbe:</strong> <span id="ajax_user_profile_eye"></span><br />
<strong>Haarfarbe:</strong> <span id="ajax_user_profile_hair"></span><br />
<strong>Besondere Merkmale:</strong> <span id="ajax_user_profile_features"></span><br />
<br style="clear: both;" />
</dd>
</dl></li>
</ul>
<span class="corners-bottom"><span></span></span>
</div>
</div>
Code: Alles auswählen
<?php
/**
*
* @package AJAX userinfo
* @version $Id: ajax_user.php, V1.0.3 2009-01-28 22:55:27 tas2580 $
* @copyright (c) 2007 SEO phpBB http://www.phpbb-seo.de
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
define('IN_PHPBB', true);
$phpbb_root_path = './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
// Start session management
$user->session_begin(false);
$auth->acl($user->data);
$user->setup();
if(!$auth->acl_gets('u_viewprofile'))
{
trigger_error($user->lang['NO_AUTH_OPERATION']);
}
$ajax_userid = request_var('userid', 0);
// Select some userdata from DB
$sql = 'SELECT username, username_clean, user_regdate, user_posts, user_from, user_lastvisit, user_avatar, user_avatar_type, user_avatar_width, user_avatar_height, user_colour, user_website, user_rank
FROM ' . USERS_TABLE . '
WHERE user_id = '. (int) $ajax_userid;
$result = $db->sql_query($sql);
// Select some userdata from DB
$sql = 'SELECT user_profile_size, user_profile_figure, user_profile_eye, user_profile_hair, user_profile_features
FROM ' . PROFILE_FIELDS_DATA_TABLE . '
WHERE user_id = '. (int) $ajax_userid;
$result1 = $db->sql_query($sql);
if($row = $db->sql_fetchrow($result) and $row1 = $db->sql_fetchrow($result1))
{
// Get the Avatar
$theme_path = generate_board_url() . "/styles/" . $user->theme['theme_path'] . '/theme';
$avatar = get_user_avatar($row['user_avatar'], $row['user_avatar_type'], $row['user_avatar_width'], $row['user_avatar_height']);
// Get rank
$rank_title = $rank_img = $rank_img_src = '';
get_user_rank($row['user_rank'], $row['user_posts'], $rank_title, $rank_img, $rank_img_src);
// Get username with usercolor
$username = get_username_string('full', $ajax_userid, $row['username'], $row['user_colour'], $row['username_clean']);
//Zeilenumbruch ab 30 Zeilen
$user_profile_size = $row1['user_profile_size'];
$user_profile_size = wordwrap( $user_profile_size, 30, "<br />\n" );
//Zeilenumbruch ab 30 Zeilen
$user_profile_figure = $row1['user_profile_figure'];
$user_profile_figure = wordwrap( $user_profile_figure, 30, "<br />\n" );
//Zeilenumbruch ab 30 Zeilen
$user_profile_eye = $row1['user_profile_eye'];
$user_profile_eye = wordwrap( $user_profile_eye, 30, "<br />\n" );
//Zeilenumbruch ab 30 Zeilen
$user_profile_hair = $row1['user_profile_hair'];
$user_profile_hair = wordwrap( $user_profile_hair, 30, "<br />\n" );
//Zeilenumbruch ab 30 Zeilen
$user_profile_features = $row1['user_profile_features'];
$user_profile_features = wordwrap( $user_profile_features, 30, "<br />\n" );
// Send XML File
header('Content-Type: text/xml; charset=utf-8');
echo '<' . '?xml version="1.0" encoding="UTF-8"?' . '>';
echo '<userdata>';
echo '<username><![CDATA[' . $username . ']]></username>';
echo '<regdate><![CDATA[' . $user->format_date($row['user_regdate']) . ']]></regdate>';
echo '<posts><![CDATA[' . $row['user_posts'] . ']]></posts>';
echo '<from><![CDATA[' . (!empty($row['user_from']) ? $row['user_from'] : $user->lang['NA']) . ']]></from>';
echo '<lastvisit><![CDATA[' . (!empty($row['user_lastvisit']) ? $user->format_date($row['user_lastvisit']) : $user->lang['NA']) . ']]></lastvisit>';
echo '<website><![CDATA[' . (!empty($row['user_website']) ? $row['user_website'] : $user->lang['NA']) . ']]></website>';
echo '<user_profile_size><![CDATA[' . (!empty($user_profile_size) ? $user_profile_size : $user->lang['NA']) . ']]></user_profile_size>';
echo '<user_profile_figure><![CDATA[' . (!empty($user_profile_figure) ? $user_profile_figure : $user->lang['NA']) . ']]></user_profile_figure>';
echo '<user_profile_eye><![CDATA[' . (!empty($user_profile_eye) ? $user_profile_eye : $user->lang['NA']) . ']]></user_profile_eye>';
echo '<user_profile_hair><![CDATA[' . (!empty($user_profile_hair) ? $user_profile_hair : $user->lang['NA']) . ']]></user_profile_hair>';
echo '<user_profile_features><![CDATA[' . (!empty($user_profile_features) ? $user_profile_features : $user->lang['NA']) . ']]></user_profile_features>';
echo '<avatar><![CDATA[' . (!empty($avatar) ? $avatar : '<img src="' . $theme_path . '/images/no_avatar.gif" alt="" />') . ']]></avatar>';
echo '<rank><![CDATA[' . (!empty($rank_title) ? $rank_title : $user->lang['NA']) . ']]></rank>';
echo '</userdata>';
}
else
{
trigger_error($user->lang['GENERAL_ERROR']);
}
$db->sql_freeresult($result);
$db->sql_freeresult($result1);
exit;
?>