Help with Friend/Foe page

Discuss the development of future releases of phpBB (phpBB 3.x minor releases) and MODing/Coding related questions.
Elglobo
Past Contributor
Past Contributor
Posts: 119
Joined: 15 Jul 2008, 19:42

Re: [blazes816] please look at last post/need advice

Post by Elglobo »

eviL<3 wrote:but $row is a bit a confusing name.

Effectively, I was in late when I gave you the code ...

2bit, don't forget improvements that I suggested you, the three points are important ;)
phpBB-Services.com: L'hébergement et l'assistance de votre forum phpBB en toute tranquillité.

Myff.fr - My First forum, créer votre forum phpBB3 facilement !
User avatar
2bit
New member
New member
Posts: 23
Joined: 01 Aug 2008, 23:34

Re: Help with Friend/Foe page

Post by 2bit »

:D I have everything typed out for refrence in case i forget or get lost.

I am currently working on putting together three arrays ($online, $foes, and $friends)
this is what i have so far. I am unshore if it is correct or not.

Code: Select all


$sql = 'SELECT z.friend, u.username, u.username_clean
    FROM ' . ZEBRA_TABLE . ' z, ' . USERS_TABLE . ' u
    WHERE z.user_id = ' . $user->data['user_id'] . '
AND u.user_id = z.zebra_id';
$result = $db->sql_query($sql);

$friends = $foes = array();
while ($row = $db->sql_fetchrow($result))
{
    if ($row['friend'])
    {
        $friends[] = utf8_clean_string($row['username']);
    }
    else
    {
        $foes[] = utf8_clean_string($row['username']);
    }
}
$db->sql_freeresult($result);

if (sizeof($friends))
{
    foreach ($friends as $row)
    {
        $template->assign_block_vars('friendsrow', array(
            'FRIENDS' => $row,
        ));
    }
}

if (sizeof($foes))
{
    foreach ($foes as $row)
    {
        $template->assign_block_vars('foesrow', array(
            'FOES' => $row,
        ));
    }
}

// do this after you have $friends and $foes defined
$users = array_merge($friends, $foes);

$sql = 'SELECT session_user_id, MAX(session_time) AS onlinetime, MIN(session_viewonline) AS viewonline FROM ' . SESSIONS_TABLE . '
WHERE ' . $db->sql_in_set('session_user_id', $users) . '
GROUP BY session_user_id';
$result = $db->sql_query($sql);

$current_time = time();
while ($row = $db->sql_fetchrow($result))
{
if (($row['viewonline'] || $auth->acl_get('u_viewonline')) && $row['onlinetime'] > ($current_time - $config['load_online_time'] * 60))
{
$online[$row['session_user_id']] = true;
}
}
$db->sql_freeresult($result);
BetaDevil
Supporter
Supporter
Posts: 27
Joined: 01 Sep 2007, 12:27
Real name: Tim

Re: Help with Friend/Foe page

Post by BetaDevil »

Here is a friend/foe-page I once made. I lost the style-page and it doesn't make any difference between online and offline users but it might come in handy for you :D

Code: Select all

<?php
/**
*
* @package BetaDevil phpBB3 add-ons
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @ignore
*/
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include(
$phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

// Define some special constants
define('ZEBRA_FRIEND', 1);
define('ZEBRA_FOE', 0);

// Get the zebra data
$sql = 'SELECT z.zebra_id, z.friend, u.username, u.user_colour
    FROM '
 . ZEBRA_TABLE . ' z,
        '
 . USERS_TABLE . ' u,
    WHERE z.user_id = '
 . $user->data['user_id'];
$result = $db->sql_query($sql);

$zebra = array();
while(
$row = $db->sql_fetchrow($result))
{
    $zebra[] = array(
        'type'        => ($row['friend']) ? ZEBRA_FRIEND : ZEBRA_FOE,
        'user_link'    => get_username_string('full', $row['zebra_id'], $row['username'], $row['user_colour']),
    );
}
$db->sql_freeresult($result);

if (sizeof($zebra))
{
    foreach ($zebra as $zebra_data)
    {
        $template->assign_block_vars((($zebra_data['type'] == ZEBRA_FRIEND) ? 'friends_row' : 'foes_row'), array(
            'U_VIEW_PROFILE'    => $zebra_data['user_link'],
        ));
    }
}

// Output page
page_header($user->lang['ZEBRA_PAGE']);

$template->set_filenames(array(
    'body' => 'zebra_body.html')
);

page_footer();

?>
User avatar
2bit
New member
New member
Posts: 23
Joined: 01 Aug 2008, 23:34

Re: Help with Friend/Foe page

Post by 2bit »

Thanks for the code that was awsome!

i have combined the three arrays but am unshore if it is correct. the code is as follows:

Code: Select all

$sql = 'SELECT z.friend, u.username, u.username_clean
    FROM ' . ZEBRA_TABLE . ' z, ' . USERS_TABLE . ' u
    WHERE z.user_id = ' . $user->data['user_id'] . '
AND u.user_id = z.zebra_id';
$result = $db->sql_query($sql);

$friends = $foes = array();
while ($row = $db->sql_fetchrow($result))
{
    if ($row['friend'])
    {
        $friends[] = utf8_clean_string($row['username']);
    }
    else
    {
        $foes[] = utf8_clean_string($row['username']);
    }
}
$db->sql_freeresult($result);

if (sizeof($friends))
{
    foreach ($friends as $row)
    {
        $template->assign_block_vars('friendsrow', array(
            'FRIENDS' => $row,
        ));
    }
}

if (sizeof($foes))
{
    foreach ($foes as $row)
    {
        $template->assign_block_vars('foesrow', array(
            'FOES' => $row,
        ));
    }
}

// do this after you have $friends and $foes defined
$users = array_merge($friends, $foes);

$sql = 'SELECT session_user_id, MAX(session_time) AS onlinetime, MIN(session_viewonline) AS viewonline FROM ' . SESSIONS_TABLE . '
WHERE ' . $db->sql_in_set('session_user_id', $users) . '
GROUP BY session_user_id';
$result = $db->sql_query($sql);

$current_time = time();
while ($row = $db->sql_fetchrow($result))
{
if (($row['viewonline'] || $auth->acl_get('u_viewonline')) && $row['onlinetime'] > ($current_time - $config['load_online_time'] * 60))
{
$online[$row['session_user_id']] = true;
}
}
$db->sql_freeresult($result);
$sql = 'SELECT z.friend, u.username, u.username_clean, z.zebra_id
    FROM ' . ZEBRA_TABLE . ' z, ' . USERS_TABLE . ' u
    WHERE z.user_id = ' . $user->data['user_id'] . '
AND u.user_id = z.zebra_id';
$result = $db->sql_query($sql);

$friends = $foes = array();
while ($row = $db->sql_fetchrow($result))
{
    if ($row['friend'])
    {
        $friends['zebra_id'] = utf8_clean_string($row['username']);
    }
    else
    {
        $foes['zebra_id'] = utf8_clean_string($row['username']);
    }

//Then at the end,


    foreach ($friends as $id => $row)
    {
        $template->assign_block_vars('friendsrow', array(
            'FRIENDS' => $row,
            'S_ONLINE' => $online[$id],
        ));
    }
 foreach ($foes as $id => $row)
    {
        $template->assign_block_vars('foesrow', array(
            'FOES' => $row,
            'S_ONLINE' => $online[$id],
        ));
    }
User avatar
2bit
New member
New member
Posts: 23
Joined: 01 Aug 2008, 23:34

Template code

Post by 2bit »

the following code

Code: Select all

if (sizeof($friends))
{
foreach ($friends as $row)
{
$template->assign_block_vars('friendsrow', array(
'FRIENDS' => $row,
));
}


will be the following on a template

Code: Select all

 <!-- BEGIN friendsrow -->
<tr>
<td>{friendsrow.FRIENDS}</td>
</tr>
<!-- END friendsrow-->


how do you display the following code on a template file?

Code: Select all

foreach ($friends as $id => $row)
{
$template->assign_block_vars('friendsrow', array(
'FRIENDS' => $row,
'S_ONLINE' => $online[$id],
));
}



'S_ONLINE' => $online[$id],
is confusing me on how to display it.
i think it is something like

Code: Select all

<!-- BEGIN friendsrow -->
<tr>
<td>{friendsrow.FRIENDS}</td>
<td>{friendsrow.S_ONLINE}</td>
</tr>
<!-- END friendsrow-->
blazes816
Supporter
Supporter
Posts: 187
Joined: 07 Oct 2006, 03:00
Real name: Tyler
Location: Wichita, Kansas
Contact:

Re: Template code

Post by blazes816 »

That should be correct, yes. :)
User Number 9e071a3a594a8964cbefe784f8a6afaa94c0de17
My MODs: http://github.com/blazes816/MODs
User avatar
Lord Le Brand
Past Contributor
Past Contributor
Posts: 223
Joined: 08 Sep 2006, 15:44
Real name: Leroy
Location: Parkstad, Limburg, the Netherlands (GMT+1)

Re: Template code

Post by Lord Le Brand »

That or if it's a boolean you can use it to style the username, like italic or something:

Code: Select all

<!-- BEGIN friendsrow -->
<tr>
<td><!-- IF friendsrow.S_ONLINE --><em>{friendsrow.FRIENDS}</em><!-- ELSE -->{friendsrow.FRIENDS}<!-- ENDIF --></td>
</tr>
<!-- END friendsrow-->

Also, if you're making this for prosilver, I wouldn't use tables. In fact, I'd only use tables if it would be for subsilver2, and then only if necessary.
Image
User avatar
2bit
New member
New member
Posts: 23
Joined: 01 Aug 2008, 23:34

Re: Template code

Post by 2bit »

:D THANKS

I tried the following and i am getting a blank page no error or anything. I think the code in the php file is wrong somehow.

friends_foes.php

Code: Select all

<?php
/**
*
* @author  2bit  [email protected] -http://jamiedawes.blogspot.com/
.tld
* @author Another Author Username [email protected] - http://domain.tld
*
* @package {friends_foes.php}
* @version $Id$
* @copyright (c) 2008 Atlantis Network
* @license http://opensource.org/licenses/gpl-license.php GNU Public
License
*
/**
* @ignore
*/
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? 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();
$auth->acl($user->data);
$user->setup(mods/friends_foes_lang_file);

$sql = 'SELECT z.friend, u.username, u.username_clean
    FROM ' . ZEBRA_TABLE . ' z, ' . USERS_TABLE . ' u
    WHERE z.user_id = ' . $user->data['user_id'] . '
AND u.user_id = z.zebra_id';
$result = $db->sql_query($sql);

$friends = $foes = array();
while ($row = $db->sql_fetchrow($result))
{
    if ($row['friend'])
    {
        $friends[] = utf8_clean_string($row['username']);
    }
    else
    {
        $foes[] = utf8_clean_string($row['username']);
    }
}
$db->sql_freeresult($result);

if (sizeof($friends))
{
    foreach ($friends as $row)
    {
        $template->assign_block_vars('friendsrow', array(
            'FRIENDS' => $row,
        ));
    }
}

if (sizeof($foes))
{
    foreach ($foes as $row)
    {
        $template->assign_block_vars('foesrow', array(
            'FOES' => $row,
        ));
    }
}

// do this after you have $friends and $foes defined
$users = array_merge($friends, $foes);

$sql = 'SELECT session_user_id, MAX(session_time) AS onlinetime, MIN(session_viewonline) AS viewonline FROM ' . SESSIONS_TABLE . '
WHERE ' . $db->sql_in_set('session_user_id', $users) . '
GROUP BY session_user_id';
$result = $db->sql_query($sql);

$current_time = time();
while ($row = $db->sql_fetchrow($result))
{
if (($row['viewonline'] || $auth->acl_get('u_viewonline')) && $row['onlinetime'] > ($current_time - $config['load_online_time'] * 60))
{
$online[$row['session_user_id']] = true;
}
}
$db->sql_freeresult($result);
$sql = 'SELECT z.friend, u.username, u.username_clean, z.zebra_id
    FROM ' . ZEBRA_TABLE . ' z, ' . USERS_TABLE . ' u
    WHERE z.user_id = ' . $user->data['user_id'] . '
AND u.user_id = z.zebra_id';
$result = $db->sql_query($sql);

$friends = $foes = array();
while ($row = $db->sql_fetchrow($result))
{
    if ($row['friend'])
    {
        $friends['zebra_id'] = utf8_clean_string($row['username']);
    }
    else
    {
        $foes['zebra_id'] = utf8_clean_string($row['username']);
    }

//Then at the end,


    foreach ($friends as $id => $row)
    {
        $template->assign_block_vars('friendsrow', array(
            'FRIENDS' => $row,
            'S_ONLINE' => $online[$id],
        ));
    }
foreach ($foes as $id => $row)
    {
        $template->assign_block_vars('foesrow', array(
            'FOES' => $row,
            'S_ONLINE' => $online[$id],
        ));
    }


// Output page
page_header();

$template->set_filenames(array(
    'body' => 'FF_view.html')
);

page_footer();

?>


this is the template file
FF_view

Code: Select all

<!-- INCLUDE overall_header.html -->



<table>
   <tr>
      <td>My friends:</td>
   </tr>
   <!-- BEGIN friendsrow -->
   <tr>
      <td>{friendsrow.FRIENDS}</td>
      <td>{friendsrow.S_ONLINE}</td>
   </tr>
   <!-- END friendsrow-->
   <table>
      <br />
      <table>
         <tr>
            <td>My foes:</td>
         </tr>
         <!-- BEGIN foesrow -->
         <tr>
            <td>{foesrow.FOES}</td>
            <td>{foesrow.S_ONLINE}</td>
         </tr>
         <!-- END foesrow -->
      </table>

      

<!-- INCLUDE overall_footer.html -->
User avatar
angelside
New member
New member
Posts: 6
Joined: 06 Feb 2007, 15:06
Real name: Sevdin Filiz
Location: Turkey
Contact:

Re: Template code

Post by angelside »

Ok, my code is to advanced

How use template variable to INCLUDE

Code: Select all

$template->assign_vars(array(
     'ACCEPT_LANG' => 'en',
));&
nbsp;&nbsp;&nbsp;&nbsp


Not work ?

Code: Select all

<!-- INCLUDE ads/ads_ACCEPT_LANG.html -->
<!-- INCLUDE ads/ads_{ACCEPT_LANG}.html -->


Too many code

Code: Select all

<!-- IF ACCEPT_LANG == en -->
<!-- INCLUDE ads/ads_en.html -->
<!-- ELSE IF ACCEPT_LANG == tr -->
<!-- INCLUDE ads/ads_tr.html -->
<!-- ENDIF -->

phpBB Türkiye :: Turkish phpBB3 support and development
phpBB3 Portal :: usable version 1.2.2 | phpBB3 Portal :: development version 2.0.0
igorw
Past Contributor
Past Contributor
Posts: 1967
Joined: 01 Jun 2006, 20:48
Real name: Igor

Re: Template code

Post by igorw »

2bit, in your code there's a missing } after:

Code: Select all

while ($row = $db->sql_fetchrow($result))
{
    if ($row['friend'])
    {
        $friends['zebra_id'] = utf8_clean_string($row['username']);
    }
    else
    {
        $foes['zebra_id'] = utf8_clean_string($row['username']);
    }


Also, you're doing the $template->assign_block_vars() twice. And you have a large ammount of queries, they could probably be combined.

angelside, You cannot use template variables for an include. Solution: use language variables.
User avatar
2bit
New member
New member
Posts: 23
Joined: 01 Aug 2008, 23:34

Re: Template code

Post by 2bit »

Thanks a bunch eviL<3,

You have eyes like a hawk three people didnt catch that mistake! :D
I have to put the page on hold for a while its been soaking up all my time lately. I am going to fix it and redo the code so its maybe two querys instead of a whole bunch.
igorw
Past Contributor
Past Contributor
Posts: 1967
Joined: 01 Jun 2006, 20:48
Real name: Igor

Re: Template code

Post by igorw »

So we don't have different code all over the place, shouldn't we put this all in one place? You have three topics...

[url=http://phpbbmodders.net/board/viewtopic.php?f=37&t=2935][DEV] Friends and foes page[/url]
[url=http://phpbbmodders.net/board/viewtopic.php?f=55&t=2920]Help with friends/foes page[/url]
[url=http://phpbbmodders.net/board/viewtopic.php?f=55&t=2938]Template code[/url]

My suggestion: Merge and lock the two topics in MOD author discussion and continue in the MOD development topic.
blazes816
Supporter
Supporter
Posts: 187
Joined: 07 Oct 2006, 03:00
Real name: Tyler
Location: Wichita, Kansas
Contact:

Re: Template code

Post by blazes816 »

I'm gonna go ahead and do that. If you have any protest 2bit, feel free to PM me. :)

merged
Reason: To keep this together
locked
Reason: Continue in the MOD's DEV thread
User Number 9e071a3a594a8964cbefe784f8a6afaa94c0de17
My MODs: http://github.com/blazes816/MODs
Locked