I code MOD: Who viewed my profile (free). Each user see result in uniq page.
- Additional user fields in uniq page - include.
- Paging in uniq page - include (need: Universal Paging class from V@no).
- Total visit count in uniq page - include.
- Total visit in member profile - include.
- Function check for insert / update - each user - include.
- If want add userpic - possible.
- If want add avatar - possible.
- Test - 4images v1.74 - is test.
// Step 1
In ROOT_PATH , create file: member_viewprofile.php .
Add:
<?php
$main_template = "member_viewprofile";
define('ROOT_PATH', './');
include(ROOT_PATH . 'global.php');
require(ROOT_PATH . 'includes/sessions.php');
@include_once(ROOT_PATH . 'includes/page_header.php');
if ($user_info['user_level'] < USER) {
redirect($url);
}
if ($action == "") {
$action = "viewprofile";
}
if ($action == "viewprofile") {
$sql = "
SELECT SUM(uvp.view_count) AS total_visits
FROM " . USERS_VIEWPROFILE_TABLE . " uvp
LEFT JOIN " . USERS_TABLE . " u ON (" . get_user_table_field("u.", "user_id") . " = uvp.user_id)
WHERE uvp.other_user_id = " . $user_info['user_id'] . " AND " . get_user_table_field("u.", "user_level") . " >= '" . USER . "'
ORDER BY uvp.view_date DESC
";
$row = $site_db->query_firstrow($sql);
$total_visits = (isset($row['total_visits'])) ? (int)$row['total_visits'] : 0;
$sql = "
SELECT SUM(uvp.user_id) AS total_rows
FROM " . USERS_VIEWPROFILE_TABLE . " uvp
LEFT JOIN " . USERS_TABLE . " u ON (" . get_user_table_field("u.", "user_id") . " = uvp.user_id)
WHERE uvp.other_user_id = " . $user_info['user_id'] . " AND " . get_user_table_field("u.", "user_level") . " >= '" . USER . "'
ORDER BY uvp.view_date DESC
";
$row = $site_db->query_firstrow($sql);
$member_viewprofile_num_all = (isset($row['total_rows'])) ? (int)$row['total_rows'] : 0;
if (defined('MEMBER_VIEWPROFILE_PERPAGE_ACTIVATION') && MEMBER_VIEWPROFILE_PERPAGE_ACTIVATION == 1) {
@include_once(ROOT_PATH.'includes/paging.php');
$member_viewprofile_perpage = (defined('MEMBER_VIEWPROFILE_PERPAGE_ACTIVATION') && MEMBER_VIEWPROFILE_PERPAGE_ACTIVATION == 1 && defined('MEMBER_VIEWPROFILE_SET_PERPAGE') && MEMBER_VIEWPROFILE_SET_PERPAGE > 0) ? intval(trim(MEMBER_VIEWPROFILE_SET_PERPAGE)) : 0;
$link_arg = $site_sess->url(ROOT_PATH."member_viewprofile.php?action=viewprofile&".URL_USER_ID."=".intval(trim($user_info['user_id'])));
$text = preg_replace("/".$site_template->start."total_member_viewprofile_posts".$site_template->end."/siU", "{total_cat_images}", $lang['member_viewprofile_total_paging_result']);
$form = false;
$getpaging = new Paging($page, $member_viewprofile_perpage, $member_viewprofile_num_all, $link_arg, $text, '', '', '', '', $form);
$offset = (defined('MEMBER_VIEWPROFILE_PERPAGE_ACTIVATION') && MEMBER_VIEWPROFILE_PERPAGE_ACTIVATION == 1 && defined('MEMBER_VIEWPROFILE_SET_PERPAGE') && MEMBER_VIEWPROFILE_SET_PERPAGE > 0) ? $getpaging->get_offset() : "";
$site_template->register_vars(array(
"member_viewprofile_paging" => (defined('MEMBER_VIEWPROFILE_PERPAGE_ACTIVATION') && MEMBER_VIEWPROFILE_PERPAGE_ACTIVATION == 1 && defined('MEMBER_VIEWPROFILE_SET_PERPAGE') && MEMBER_VIEWPROFILE_SET_PERPAGE > 0) ? $getpaging->get_paging() : "",
"member_viewprofile_paging_stats" => (defined('MEMBER_VIEWPROFILE_PERPAGE_ACTIVATION') && MEMBER_VIEWPROFILE_PERPAGE_ACTIVATION == 1 && defined('MEMBER_VIEWPROFILE_SET_PERPAGE') && MEMBER_VIEWPROFILE_SET_PERPAGE > 0) ? $getpaging->get_paging_stats() : ""
));
$condition = (defined('MEMBER_VIEWPROFILE_PERPAGE_ACTIVATION') && MEMBER_VIEWPROFILE_PERPAGE_ACTIVATION == 1 && defined('MEMBER_VIEWPROFILE_SET_PERPAGE') && MEMBER_VIEWPROFILE_SET_PERPAGE > 0) ? "LIMIT ".$offset.", ".$member_viewprofile_perpage : "";
} else {
$no_paging_activated = $lang['member_viewprofile_total_paging_no_result'];
$site_template->register_vars("no_paging_activated", trim($no_paging_activated));
}
if (isset($additional_user_fields) && is_array($additional_user_fields) && !empty($additional_user_fields)) {
$additional_sql = "";
foreach ($additional_user_fields as $key => $val) {
$additional_sql .= ", u." . $key;
}
}
$sql = "
SELECT uvp.user_id, uvp.view_date, uvp.view_count" . get_user_table_field(", u.", "user_name") . $additional_sql . "
FROM " . USERS_VIEWPROFILE_TABLE . " uvp
LEFT JOIN " . USERS_TABLE . " u ON (" . get_user_table_field("u.", "user_id") . " = uvp.user_id)
WHERE uvp.other_user_id = " . $user_info['user_id'] . " AND " . get_user_table_field("u.", "user_level") . " >= '" . USER . "'
ORDER BY uvp.view_date DESC
" . ((isset($condition) && !empty($condition)) ? $condition : "");
$result = $site_db->query($sql);
$num_rows = $site_db->get_numrows($result);
if (isset($num_rows) && $num_rows <= 0) {
$msg = preg_replace("/" . $site_template->start . "user_name" . $site_template->end . "/siU", format_text(trim($user_info['user_name']), 2), $lang['member_viewprofile_no_content']);
} elseif (isset($num_rows) && $num_rows > 0) {
$viewprofile_content = "";
while ($view_row = $site_db->fetch_array($result)) {
$user_id = $view_row['user_id'];
$user_name = format_text(trim($view_row[$user_table_fields['user_name']]), 2);
$view_date = format_date($config['date_format'] . ", " . $config['time_format'], $view_row['view_date']);
$view_count = $view_row['view_count'];
$site_template->register_vars(array(
"user_id" => (isset($user_id)) ? $user_id : "",
"user_name" => (isset($user_name)) ? $user_name : "",
"user_url" => (isset($user_id)) ? $site_sess->url(ROOT_PATH . "member.php?action=showprofile&" . URL_USER_ID . "=" . $user_id) : "",
"view_date" => (isset($view_date)) ? $view_date : "",
"view_count" => (isset($view_count)) ? $view_count : ""
));
if (isset($additional_user_fields) && is_array($additional_user_fields) && !empty($additional_user_fields)) {
$additional_field_array = array();
foreach ($additional_user_fields as $key => $val) {
$additional_field_array[$key] = (!empty($view_row[$key])) ? format_text($view_row[$key], 1) : REPLACE_EMPTY;
$additional_field_array['lang_'.$key] = $val[0];
}
if (!empty($additional_field_array)) {
$site_template->register_vars($additional_field_array);
}
}
$viewprofile_content .= $site_template->parse_template("member_viewprofile_content");
}
}
}
$clickstream = "<a href=\"" . $site_sess->url(ROOT_PATH . "index.php") . "\">" . $lang['home'] . "</a>" . $config['category_separator'] . $lang['member_viewprofile_title'];
$site_template->register_vars(array(
"clickstream" => trim($clickstream),
"msg" => trim($msg),
"lang_member_viewprofile_title" => $lang['member_viewprofile_title'],
"lang_member_viewprofile_user_name" => $lang['member_viewprofile_user_name'],
"lang_member_viewprofile_view_date" => $lang['member_viewprofile_view_date'],
"lang_member_viewprofile_view_count" => $lang['member_viewprofile_view_count'],
"lang_member_viewprofile_total_visits" => $lang['member_viewprofile_total_visits_title'],
"lang_member_viewprofile_paging_stats_title" => $lang['member_viewprofile_paging_stats_title'],
"viewprofile_content" => (isset($viewprofile_content)) ? trim($viewprofile_content) : "",
"total_visits" => (isset($total_visits)) ? preg_replace("/" . $site_template->start . "total_visits" . $site_template->end . "/siU", $total_visits, $lang['member_viewprofile_total_visits']) : ""
));
$site_template->print_template($site_template->parse_template($main_template));
@include_once(ROOT_PATH . 'includes/page_footer.php');
?>
// Step 2
In member.php file,
find:
if ($user_row = get_user_info($user_id)) {
add after:
if (function_exists('member_viewprofile_check_user')) {
member_viewprofile_check_user($user_info['user_id'], $user_row[$user_table_fields['user_id']], $user_info['user_level']);
}
find:
else {
$user_email = REPLACE_EMPTY;
$user_email_save = REPLACE_EMPTY;
$user_mailform_link = REPLACE_EMPTY;
$user_email_button = REPLACE_EMPTY;
}
add after:
$sql = "
SELECT COUNT(uvp.view_count) AS total_rows
FROM " . USERS_VIEWPROFILE_TABLE . " uvp
LEFT JOIN " . USERS_TABLE . " u ON (" . get_user_table_field("u.", "user_id") . " = uvp.user_id)
WHERE uvp.other_user_id = " . $user_id;
$row = $site_db->query_firstrow($sql);
$total_views = (isset($row['total_rows'])) ? (int)$row['total_rows'] : 0;
find:
"user_comments" => (isset($user_row['user_comments'])) ? $user_row['user_comments'] : REPLACE_EMPTY,
add after:
"lang_member_viewprofile_from_profile" => $lang['member_viewprofile_from_profile'],
"member_viewprofile_from_profile_total_views" => (isset($total_views)) ? (int)$total_views : "",
// Step 3
In includes/constants.php file,
add in top ?>:
define('MEMBER_VIEWPROFILE_PERPAGE_ACTIVATION', 1); // Active: 1 - Inactive: 0.
define('MEMBER_VIEWPROFILE_SET_PERPAGE', 10); // Rows value per page.
find:
define('USERS_TABLE', $table_prefix.'users');
add after:
define('USERS_VIEWPROFILE_TABLE', $table_prefix . 'users_viewprofile');
// Step 4
In global.php file,
find:
$site_db = new Db($db_host, $db_user, $db_password, $db_name);
add after:
//-----------------------------------------------------
//--- Creates ignore users table ----------------------
//-----------------------------------------------------
if (function_exists('member_viewprofile_check_table')) {
member_viewprofile_check_table();
}
// Step 5
In lang/english/main.php file,
add in top ?>:
$lang['member_viewprofile_title'] = "Who viewed my profile";
$lang['member_viewprofile_no_content'] = "Sorry <b>{user_name}</b>, no users viewed your profile yet.";
$lang['member_viewprofile_user_name'] = "<b>Username</b>";
$lang['member_viewprofile_view_date'] = "<b>Date</b>";
$lang['member_viewprofile_view_count'] = "<b>Count</b>";
$lang['member_viewprofile_total_visits'] = "Total visits on your profile: {total_visits}";
$lang['member_viewprofile_total_visits_title'] = "Total visits";
$lang['member_viewprofile_paging_stats_title'] = "Statistics for this profile";
$lang['member_viewprofile_total_paging_result'] = "Found: {total_member_viewprofile_posts} visits on {total_pages} page(s).";
$lang['member_viewprofile_from_profile'] = "Total users who viewed my profile:";
// Step 6
In includes/functions.php file,
add in top ?>:
if (!function_exists('member_viewprofile_check_table')) {
function member_viewprofile_check_table() {
global $site_db, $table_prefix;
if (!defined('USERS_VIEWPROFILE_TABLE')) {
define('USERS_VIEWPROFILE_TABLE', $table_prefix . 'users_viewprofile');
}
$sql = "
CREATE TABLE IF NOT EXISTS " . USERS_VIEWPROFILE_TABLE . " (
field_id int(11) unsigned NOT NULL AUTO_INCREMENT,
user_id int(11) NOT NULL DEFAULT '0',
other_user_id int(11) NOT NULL DEFAULT '0',
view_date int(11) NOT NULL DEFAULT '0',
view_count int(11) NOT NULL DEFAULT '0',
PRIMARY KEY(field_id)
) TYPE=MyISAM;
";
$result = $site_db->query($sql);
}
}
if (!function_exists('member_viewprofile_check_user')) {
function member_viewprofile_check_user($user_id = 0, $other_user_id = 0, $user_level = GUEST) {
global $site_db;
$user_id = preg_replace("/[^0-9]+/i", "", $user_id);
$other_user_id = preg_replace("/[^0-9]+/i", "", $other_user_id);
$user_level = preg_replace("/[^0-9]+/i", "", $user_level);
if (empty($user_id) || empty($other_user_id) || $user_level == GUEST || $user_level == USER_AWAITING) {
return;
}
if ($user_id == $other_user_id) {
return;
}
$sql = "
SELECT uvp.user_id, uvp.other_user_id
FROM " . USERS_VIEWPROFILE_TABLE . " uvp
LEFT JOIN " . USERS_TABLE . " u ON (" . get_user_table_field("u.", "user_id") . " = uvp.user_id)
WHERE uvp.user_id = " . $user_id . " AND uvp.other_user_id = " . $other_user_id . " AND " . get_user_table_field("u.", "user_level") . " >= '" . USER . "'
";
$get_info = $site_db->query_firstrow($sql);
if (isset($get_info['user_id']) && $user_id == $get_info['user_id'] && isset($get_info['other_user_id']) && $other_user_id == $get_info['other_user_id']) {
$site_db->query("UPDATE " . USERS_VIEWPROFILE_TABLE . " SET view_count = view_count + 1, view_date = '" . time() . "' WHERE user_id = " . $user_id . " AND other_user_id = " . $other_user_id);
return $user_id;
return $other_user_id;
return $user_level;
} elseif (isset($get_info['user_id']) && $user_id != $get_info['user_id'] && isset($get_info['other_user_id']) && $other_user_id != $get_info['other_user_id']) {
$sql = "
INSERT INTO " . USERS_VIEWPROFILE_TABLE . "
(field_id, user_id, other_user_id, view_date, view_count)
VALUES(NULL, '" . $user_id . "', '" . $other_user_id . "', '" . time() . "', '1')
";
$result = $site_db->query($sql);
return $user_id;
return $other_user_id;
return $user_level;
} elseif (!$site_db->not_empty($sql)) {
$sql = "
INSERT INTO " . USERS_VIEWPROFILE_TABLE . "
(field_id, user_id, other_user_id, view_date, view_count)
VALUES(NULL, '" . $user_id . "', '" . $other_user_id . "', '" . time() . "', '1')
";
$result = $site_db->query($sql);
return $user_id;
return $other_user_id;
return $user_level;
}
}
}
// Step 7
In templates/your_template - create file: member_viewprofile.html .
(Note: I use ULM)
Add:
{header}
{ste_layout_top}
{ste_layout_left}
{if is_admin}<! -- Who viewed my profile -- >{endif is_admin}
{if msg}{ifno viewprofile_content}
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="head1">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="head1" valign="top">{lang_member_viewprofile_title}</td>
</tr>
</table>
</td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="row2" align="center" /><br /><b>{msg}</b><br /><br /></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="head2"> </td>
</tr>
</table>
<br />
{endifno viewprofile_content}{endif msg}
{if is_admin}<! -- End - Who viewed my profile -- >{endif is_admin}
{if is_admin}<! -- Who viewed my profile -- >{endif is_admin}
{ifno msg}{if viewprofile_content}
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="head1">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" class="head1" valign="top">{lang_member_viewprofile_title}</td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" class="row2"> </td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" class="head1" valign="top">{lang_member_viewprofile_total_visits}</td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" class="row2" valign="top" align="center" />{if total_visits}<br />{total_visits}{endif total_visits}</td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" class="row2"> </td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" class="head1" valign="top">{lang_member_viewprofile_paging_stats_title}</td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" class="row2" align="center" /><br />{member_viewprofile_paging_stats}<br /></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" class="row2"> </td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="head2"> </td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" class="row2"> </td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" class="row2" align="right" />{member_viewprofile_paging}</td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="33%" class="head1" align="center" valign="top">{lang_member_viewprofile_user_name}</td>
<td width="33%" class="head1" align="center" valign="top">{lang_member_viewprofile_view_date}</td>
<td width="33%" class="head1" align="center" valign="top">{lang_member_viewprofile_view_count}</td>
</tr>
</table>
</td>
</tr>
</table>
<table width="100%" border="1" cellspacing="0" cellpadding="0" class="tablebottom">
{viewprofile_content}
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="row2"> </td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="head2"> </td>
</tr>
</table>
<br />
{endif viewprofile_content}{endifno msg}
{if is_admin}<! -- End - Who viewed my profile -- >{endif is_admin}
{ste_layout_below}
{footer}
// Step 8
In templates/your_template - create file: member_viewprofile_content.html .
(Note: I use ULM)
Add:
<tr>
<td width="33%" class="row2" align="center"><a href="{user_url}" class="link" />{user_name}</a></td>
<td width="33%" class="row2" align="center">{view_date}</td>
<td width="33%" class="row2" align="center">{view_count}</td>
</tr>
// Step 9
In templates/your_template/member_profile.html file,
find:
<tr>
<td class="row2"><b>{lang_icq}</b></td>
<td class="row2">{if user_icq}<a href="http://www.icq.com/people/about_me.php?uin={user_icq}" target="_blank">{user_icq}</a> (<b>{user_icq_status}</b>){endif user_icq}</td>
</tr>
add after:
{if member_viewprofile_from_profile_total_views}
<tr>
<td class="row1"><b>{lang_member_viewprofile_from_profile}</b></td>
<td class="row1">{member_viewprofile_from_profile_total_views}</td>
</tr>
{endif member_viewprofile_from_profile_total_views}
// Step 10
In includes/page_header.php file,
find:
"url_captcha_image" => $site_sess->url(ROOT_PATH."captcha.php"),
add after:
"url_member_viewprofile" => $site_sess->url(ROOT_PATH . "member_viewprofile.php"),
find:
"lang_images_per_page" => $lang['images_per_page'],
add after:
"lang_member_viewprofile_title" => $lang['member_viewprofile_title'],
// Step 11
In templates/your_template/user_logininfo.html file,
find:
» <a href="{url_control_panel}">{lang_control_panel}</a><br />
add after:
» <a href="{url_member_viewprofile}">{lang_member_viewprofile_title}</a><br />
Finish.