Author Topic: Code for adding Friendship Request counter and different layout "Home"  (Read 2485 times)

Jeroen

  • Active Member
  • ***
  • Posts: 37
  • Karma: +8/-0
In the thread "Code for receiving message when someone else accepts your friend request" Utah proposed the following:




To do this, you can make the following changes:


In home.php replace the following:

Code: [Select]
$my_stats=get_user_stats($_SESSION[_LICENSE_KEY_]['user']['user_id'],array('total_photos','pviews','num_friends'));
$query="SELECT count(*) FROM `{$dbtable_prefix}user_inbox` WHERE `fk_user_id`='".$_SESSION[_LICENSE_KEY_]['user']['user_id']."' AND `del`=0";
if (!($res=@mysql_query($query))) {trigger_error(mysql_error(),E_USER_ERROR);}
$my_stats['total_messages']=mysql_result($res,0,0);
$query="SELECT count(*) FROM `{$dbtable_prefix}user_inbox` WHERE `is_read`=0 AND `fk_user_id`='".$_SESSION[_LICENSE_KEY_]['user']['user_id']."' AND `del`=0";
if (!($res=@mysql_query($query))) {trigger_error(mysql_error(),E_USER_ERROR);}
$my_stats['new_messages']=mysql_result($res,0,0);

$tpl->set_file('content','home.html');
$tpl->set_var('output',$output);
$tpl->set_var('my_stats',$my_stats);
$tpl->process('content','content');

with

Code: [Select]
$my_stats=get_user_stats($_SESSION[_LICENSE_KEY_]['user']['user_id'],array('total_photos','pviews','num_friends'));
$query="SELECT count(*) FROM `{$dbtable_prefix}user_inbox` WHERE `fk_user_id`='".$_SESSION[_LICENSE_KEY_]['user']['user_id']."' AND `del`=0";
if (!($res=@mysql_query($query))) {trigger_error(mysql_error(),E_USER_ERROR);}
$my_stats['total_messages']=mysql_result($res,0,0);
$query="SELECT count(*) FROM `{$dbtable_prefix}user_inbox` WHERE `is_read`=0 AND `fk_user_id`='".$_SESSION[_LICENSE_KEY_]['user']['user_id']."' AND `del`=0";
if (!($res=@mysql_query($query))) {trigger_error(mysql_error(),E_USER_ERROR);}
$my_stats['new_messages']=mysql_result($res,0,0);
// BEGIN Set Friendship Request counter
$query="SELECT count(*) FROM `{$dbtable_prefix}user_networks` WHERE `fk_user_id_other`='".$_SESSION[_LICENSE_KEY_]['user']['user_id']."'  AND `fk_net_id`=1 AND `nconn_status` = 0";
if (!($res=@mysql_query($query))) {trigger_error(mysql_error(),E_USER_ERROR);}
$my_stats['friendship_requests']=mysql_result($res,0,0);
// END

$tpl->set_file('content','home.html');
$tpl->set_var('output',$output);
$tpl->set_var('my_stats',$my_stats);
$tpl->process('content','content');

and in skins_site/dev/home.html

replace:

Code: [Select]
<ul id="stats">
<li>Hi <strong>{tplvars.myself.user}</strong></li>
<li id="messages"><a class="content-link simple" href="{tplvars.relative_url}mailbox.php">Messages</a>: {my_stats.total_messages} ({my_stats.new_messages} new)</li>
<li id="photos"><a class="content-link simple" href="{tplvars.relative_url}my_photos.php">Approved Photos</a>: {my_stats.total_photos}</li>
<li id="friends"><a class="content-link simple" href="{tplvars.relative_url}my_networks.php">Friends</a>: {my_stats.num_friends}</li>
<li id="pviews">Your profile has been viewed {my_stats.pviews} times since {output.date_added}</li>
<li id="membership">Your Membership: {output.m_name}</li>
<li id="paid_until">Membership Expires: {output.paid_until}. <a class="content-link simple" href="subscriptions.php" title="Update membership">Update or renew</a> your membership now!</li>
</ul>

<div id="s">
<a class="content-link simple" href="{tplvars.relative_url}friendship_requests.php">Friendship Requests</a>
</div>

with

Code: [Select]
<ul id="stats">
<li>Hi <strong>{tplvars.myself.user}</strong></li>
<li id="messages"><a class="content-link simple" href="{tplvars.relative_url}mailbox.php">Messages</a>: {my_stats.total_messages} ({my_stats.new_messages} new)</li>
<li id="photos"><a class="content-link simple" href="{tplvars.relative_url}my_photos.php">Approved Photos</a>: {my_stats.total_photos}</li>
<li id="friends"><a class="content-link simple" href="{tplvars.relative_url}my_networks.php">Friends</a>: {my_stats.num_friends}</li>
<li id="friendshiprequests"><a class="content-link simple" href="{tplvars.relative_url}friendship_requests.php">Friendship Requests</a>: {my_stats.friendship_requests}</li>
</ul>

<div id="s">
<ul id="statsbottom">
<li id="pviews">Your profile has been viewed {my_stats.pviews} times since {output.date_added}</li>
<li id="membership">Your Membership: {output.m_name}</li>
<li id="paid_until">Membership Expires: {output.paid_until}. <a class="content-link simple" href="subscriptions.php" title="Update membership">Update or renew</a> your membership now!</li>
</ul>
</div>

This worked for me. If you want to apply this, please do so first in a development environment, and test it through, so that you are sure for yourself that it works.

I had a lot of troubles because of the single quotes in the database query. So if the counter doesn´t show the right number, try to change the single quotes in:

Code: [Select]
// BEGIN Set Friendship Request counter
$query="SELECT count(*) FROM `{$dbtable_prefix}user_networks` WHERE `fk_user_id_other`='".$_SESSION[_LICENSE_KEY_]['user']['user_id']."'  AND `fk_net_id`=1 AND `nconn_status` = 0";
if (!($res=@mysql_query($query))) {trigger_error(mysql_error(),E_USER_ERROR);}
$my_stats['friendship_requests']=mysql_result($res,0,0);
// END

For me the single quotes work in the code above.
 
Greets!

utah

  • Prime Member
  • ****
  • Posts: 146
  • Karma: +9/-0
Hi

I tried your code and it's working!  Great work, thanks!





sharkthis

  • Active Member
  • ***
  • Posts: 65
  • Karma: +4/-2
Yes works great thanks sharkthis.com


AngryPanda

  • Active Member
  • ***
  • Posts: 51
  • Karma: +0/-0
Great job with the mysql Friendship Request count query Jeroen! I couldn't work out why the query I had wasn't working. Would've taken me a while to work out that it came down to the singles quotes.

Thanks for posting a solution.