Topic: Personal HomePage
Being inspired from PunPortal, I am designing a Personal Homepage (My Page) for punbb. In the My Page a user can see many information about himself.
I will share the codes with you here. any suggestion & optimization is welcome.
------------------My Overview------------------------------------
//Start Subst - <pun_my_overview>.
ob_start();
?>
<div class="block" id="myoverview">
<h2><span><?php echo $lang_my['Overview'] ?></span></h2>
<div class="box">
<div class="inbox">
<?
$result = $db->query('SELECT u.registered,u.num_posts,u.last_post FROM '.$db->prefix.'users as u WHERE id='.$pun_user['id'].' LIMIT 1') or error('Unable to fetch user information',__FILE__,__LINE__, $db->error());
$myinfo = $db->fetch_assoc($result);
//save db values to variable
$regdate=$myinfo['registered'];
$num_posts=$myinfo['num_posts'];
$last_post=$myinfo['last_post'];
//now get total number of topics created by user
$result = $db->query('SELECT count(t.id) as thread FROM '.$db->prefix.'topics as t JOIN '.$db->prefix.'users as u ON t.poster=u.username WHERE u.id='.$pun_user['id']) or error('Unable to fetch user\'s total topics',__FILE__,__LINE__, $db->error());
$myinfo = $db->fetch_assoc($result);
//saving database values to variable
$num_topics=$myinfo['thread'];
//fetch my reputation
$uid = $pun_user['id'];
if ($uid<2)
message($lang_common['Bad request']);
$result = $db->query('SELECT SUM(rep_plus) - SUM(rep_minus) AS repu FROM '.$db->prefix.'reputation as r WHERE r.user_id='.$uid) or error('Unable to fetch reputation info', __FILE__, __LINE__, $db->error());
if ($db->num_rows($result)){
$user_rep = $db->fetch_assoc($result);
$user_rep = $user_rep['repu'];
} else {
message($lang_common['Bad request']);
}
//making list
$showalltopics="search.php?action=search&keywords=&author=".$pun_user['username']."&forum =-1&search_in=topic&sort_by=0&sort_dir=DESC&show_as=topics";
$myoverview = '<ul>';
if(!empty($regdate)) $myoverview .='<li>'.$lang_my['Reg Date'].': '.date($pun_config['o_date_format'], $regdate).'</li>';
if(!empty($num_posts)) $myoverview .='<li>'.$lang_my['Total Posts'].': '.$num_posts.'</li>';
if(!empty($last_post)) $myoverview .='<li>'.$lang_my['Last Post'].': '.date($pun_config['o_date_format'], $last_post).'</li>';
if(!empty($num_topics)) $myoverview .='<li><a href="'.$showalltopics.'">'.$lang_my['Total Topics'].'<a/>: '.$myinfo['thread'].'</li>';
$myoverview .= '<li><a href="'.$pun_config['o_base_url'].'/reputation.php?uid='.$pun_user['id'].'">'.$lang_my['Reputation'].'</a>: '.unicode($user_rep) .'</li>';
$myoverview .='</ul>';
echo $myoverview;
?>
</div>
</div>
</div>
<?
$tpl_temp = trim(ob_get_contents());
$tpl_main = str_replace('<pun_my_overview>', $tpl_temp, $tpl_main);
ob_end_clean();
//End Subst - <pun_my_overview>.
--------------------My Overview----------------------------------
------------------My Recent Topics------------------------------------
//Start Subst - <pun_my_recent_topics>. topic created by me
ob_start();
$topicslimit =10; //$pun_config['o_portal_topics_limit'];
?>
<div class="block" id="myrecenttopics">
<h2><span><?php echo $lang_my['Recent Topics'] ?></span></h2>
<div class="box">
<div class="inbox">
<?
$result = $db->query('SELECT t.id,t.subject,t.poster FROM '.$db->prefix.'topics AS t JOIN '.$db->prefix.'users AS u ON t.poster=u.username AND u.id="'.$pun_user['id'].'" ORDER BY t.posted DESC LIMIT '.$topicslimit) or error('Unable to fetch recent topic list', __FILE__, __LINE__, $db->error());
while($cur_topics = $db->fetch_assoc($result))
{
$recent_topics = '<ul><li><a href="'.$pun_config['o_base_url'].'/viewtopic.php?id='.$cur_topics['id'].'">'.$cur_topics['subject'].'</a></li></ul>';
echo $recent_topics;
}
?>
</div>
</div>
</div>
<?
$tpl_temp = trim(ob_get_contents());
$tpl_main = str_replace('<pun_my_recent_topics>', $tpl_temp, $tpl_main);
ob_end_clean();
//End Subst - <pun_my_recent_topics>. topic created by me
------------------My Recent Topics------------------------------------
------------------My Recent Posts-------------------------------------
//Start Subst - <pun_my_recent_posts>. post created by me
ob_start();
$postslimit =10;
?>
<div class="block" id="myrecentposts">
<h2><span><?php echo $lang_my['Recent Posts'] ?></span></h2>
<div class="box">
<div class="inbox">
<?
$result = $db->query('SELECT p.id,p.message,p.poster_id,t.subject FROM '.$db->prefix.'posts as p JOIN '.$db->prefix.'topics as t ON p.topic_id=t.id WHERE poster_id='.$pun_user['id'].' ORDER BY p.posted desc LIMIT '.$postslimit) or error('Unable to fetch recent posts list',__FILE__,__LINE__, $db->error());
while($cur_posts = $db->fetch_assoc($result))
{
$recent_posts = '<ul><li><a href="'.$pun_config['o_base_url'].'/viewtopic.php?pid='.$cur_posts['id'].'#p'.$cur_posts['id'].'">'.$cur_posts['subject'].'</a></li></ul>';
echo $recent_posts;
}
?>
</div>
</div>
</div>
<?
$tpl_temp = trim(ob_get_contents());
$tpl_main = str_replace('<pun_my_recent_posts>', $tpl_temp, $tpl_main);
ob_end_clean();
//End Subst - <pun_my_recent_posts>.
------------------My Recent Posts-------------------------------------
-----------------My Subscriptions-------------------------------------
//Start Subst - <pun_my_subscription>. topics to which I am subscribed
ob_start();
?>
<div class="block" id="mysubscriptions">
<h2><span><?php echo $lang_my['Subscribed Topics'] ?></span></h2>
<div class="box">
<div class="inbox">
<?
$result = $db->query('SELECT t.id,t.subject FROM '.$db->prefix.'topics AS t JOIN '.$db->prefix.'subscriptions AS s ON t.id=s.topic_id AND s.user_id="'.$pun_user['id'].'" ORDER BY t.posted DESC LIMIT 100') or error('Unable to fetch your subscribed topics', __FILE__, __LINE__, $db->error());
while($cur_topics = $db->fetch_assoc($result))
{
$subscribed_topics = '<ul><li><a href="'.$pun_config['o_base_url'].'/viewtopic.php?id='.$cur_topics['id'].'">'.$cur_topics['subject'].'</a> <a title="Click here to unsubscribe from this topic" href="'.$pun_config['o_base_url'].'/misc.php?unsubscribe='.$cur_topics['id'].'"><img src="img/my/minus.gif"/></a></li></ul>';
echo $subscribed_topics;
}
?>
</div>
</div>
</div>
<?
$tpl_temp = trim(ob_get_contents());
$tpl_main = str_replace('<pun_my_subscriptions>', $tpl_temp, $tpl_main);
ob_end_clean();
//End Subst - <pun_my_subscription>.
-----------------My Subscriptions-------------------------------------
I have developed a mod named My Favorite Topics. i will disclose those codes in another thread
---------------New Posts AFter my last Visit--------------------------
//Start Subst - <pun_my_newpost>. new posts after my last visit
ob_start();
?>
<div class="block" id="mynewposts">
<h2><span><?php echo $lang_my['New Posts'] ?></span></h2>
<div class="box">
<div class="inbox">
<?
$result = $db->query('SELECT t.id,t.subject,t.last_post_id FROM '.$db->prefix.'topics as t WHERE t.last_post >'.$pun_user['last_visit']) or error('Unable to fetch new posts from your last visit',__FILE__,__LINE__, $db->error());
//die($db->num_rows($result));
if($db->num_rows($result))
{
while($cur_posts = $db->fetch_assoc($result))
{
$new_posts = '<ul><li><a href="'.$pun_config['o_base_url'].'/viewtopic.php?pid='.$cur_posts['last_post_id'].'#p'.$cur_posts['last_post_id'].'">'.$cur_posts['subject'].'</a></li></ul>';
echo $new_posts;
}
} else {
require PUN_ROOT.'lang/'.$pun_user['language'].'/search.php';
echo ($lang_search['No new posts']);
}
?>
</div>
</div>
</div>
<?
$tpl_temp = trim(ob_get_contents());
$tpl_main = str_replace('<pun_my_new_posts>', $tpl_temp, $tpl_main);
ob_end_clean();
//Start Subst - <pun_my_newpost>
---------------New Posts AFter my last Visit--------------------------
Now i need to do something more. A user's all posts can be listed by using search.php?action=show_user&user_id=xxx
but is there in code already done in the search.php to list all topics by a particular user. I can make it, but it will be best if i can do it without writing/editing search.php file.
actually I am doing these things so far without changing any current files. So far I just added a line in the header.php (template file)
thanks