whats wrong with this code ? working outside ..not working inside the forum

Started by samozin, February 11, 2024, 10:44:24 AM

Previous topic - Next topic

samozin

iam trying to insert this code in atemplate or in aportal block ... shows nothing but when i put it in aseparate .php file near SSI.php its working ..... its taken from a mod for smf 2.0 and am using 2.1.4
any body can guess whats the trick here ?
<?php

require_once("SSI.php");

global 
$txt$context$scripturl$user_profile;

    
// Load buddy list (copied from WirelessAddBuddy, indent to distinguish from that part)
        
$context['buddies'] = array();
$width '220px';
$height '220px';
        if (!empty(
$user_info['buddies']))
        {
            
$request $smcFunc['db_query']('''
                SELECT mem.id_member, mem.member_name, mem.real_name, mem.avatar, mg.online_color, a.id_attach, a.attachment_type, a.filename
                FROM {db_prefix}members mem
                    LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = mem.id_member)
                    LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = CASE WHEN mem.id_group = {int:reg_member_group} THEN mem.id_post_group ELSE mem.id_group END)
                WHERE mem.id_member IN ({array_int:buddy_list})
                ORDER BY mem.real_name'
,
                array(
                    
'reg_member_group' => 0,
                    
'buddy_list' => $user_info['buddies'],
                )
            );
            while (
$row $smcFunc['db_fetch_assoc']($request))
                
$context['buddies'][] = array(
                    
'id' => $row['id_member'],
                    
'member_name' => $row['member_name'],
                    
'real_name' => $row['real_name'],
                    
'color' => $row['online_color'],
                    
'avatar' => array(
                                
'image' => empty($row['avatar']) ? ($row['id_attach'] > '<img src="' . (empty($row['attachment_type']) ? $scripturl '?action=dlattach;attach=' $row['id_attach'] . ';type=avatar' $modSettings['custom_avatar_url'] . '/' $row['filename']) . '" alt="" border="0" width="'.$width.'" height="'.$height.'" title="'.$row['real_name'].'" />' '') : (stristr($row['avatar'], 'http://') ? '<img src="' $row['avatar'] . '" alt="" border="0" width="'.$width.'" height="'.$height.'" title="'.$row['real_name'].'" />' '<img src="' $modSettings['avatar_url'] . '/' htmlspecialchars($row['avatar']) . '" alt="" border="0" width="'.$width.'" height="'.$height.'" title="'.$row['real_name'].'" />'),
                              ),
                );
            
$smcFunc['db_free_result']($request);
        }

        echo 
'<br>        
<div class="wholebuddylist">'
;
        foreach (
$context['buddies'] as $buddy) {
            echo 
'<div class="onebuddy"> 
                                <div class="buddyname">'
$buddy['real_name'] ,'</div>
                                <div class="buddyavatar"><a href="' 
$scripturl '?action=profile;area=showposts;u=' $buddy['id'] . '"> '$buddy['avatar']['image'] ,'  </a></div>
                                </div>'
;
        }
            echo 
'</div>';
        
?>


thats what i put in portal block


global $txt, $context, $scripturl, $user_profile;

// Load buddy list (copied from WirelessAddBuddy, indent to distinguish from that part)
$context['buddies'] = array();
$width = '220px';
$height = '220px';
if (!empty($user_info['buddies']))
{
$request = $smcFunc['db_query']('', '
SELECT mem.id_member, mem.member_name, mem.real_name, mem.avatar, mg.online_color, a.id_attach, a.attachment_type, a.filename
FROM {db_prefix}members mem
    LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = mem.id_member)
LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = CASE WHEN mem.id_group = {int:reg_member_group} THEN mem.id_post_group ELSE mem.id_group END)
WHERE mem.id_member IN ({array_int:buddy_list})
ORDER BY mem.real_name',
array(
'reg_member_group' => 0,
'buddy_list' => $user_info['buddies'],
)
);
while ($row = $smcFunc['db_fetch_assoc']($request))
$context['buddies'][] = array(
'id' => $row['id_member'],
'member_name' => $row['member_name'],
'real_name' => $row['real_name'],
'color' => $row['online_color'],
'avatar' => array(
                    'image' => empty($row['avatar']) ? ($row['id_attach'] > 0 ? '<img src="' . (empty($row['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $row['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) . '" alt="" border="0" width="'.$width.'" height="'.$height.'" title="'.$row['real_name'].'" />' : '') : (stristr($row['avatar'], 'http://') ? '<img src="' . $row['avatar'] . '" alt="" border="0" width="'.$width.'" height="'.$height.'" title="'.$row['real_name'].'" />' : '<img src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($row['avatar']) . '" alt="" border="0" width="'.$width.'" height="'.$height.'" title="'.$row['real_name'].'" />'),
                       ),
);
$smcFunc['db_free_result']($request);
}

echo '<br>
<div class="wholebuddylist">';
foreach ($context['buddies'] as $buddy) {
echo '<div class="onebuddy">
    <div class="buddyname">', $buddy['real_name'] ,'</div>
<div class="buddyavatar"><a href="' . $scripturl . '?action=profile;area=showposts;u=' . $buddy['id'] . '"> ', $buddy['avatar']['image'] ,'  </a></div>
    </div>';
}
    echo '</div>';

it gives nothing even no errors nor warnings ...?
 

Arantor

The block needs to have $user_info in the global list too. It's automatically global courtesy of SSI but not in a block.

Doug Heffernan

What portal mod are you using? I think it would be best to post at its support topic/forum. That being said, a quick scan of the code shows that $smcFunc and $user_info have not being defined as global variables.

samozin

i added $user_info still  the same result
 iam using
Light Portal
The mod version: 2.0, PHP version: 7.4.0, MySQL version: 10.4.10-MariaDB.
i dont think its related to the portal ... cuz i tried to put it in a custom template.php  not workning too ...

 i think its something exists in ssi.php  not in my code ....

samozin

its

global $settings, $context, $txt, $smcFunc, $user_info, $scripturl, $boardurl, $modSettings;


that solved it ... i was missing   $modSettings  $user_info  $smcFunc

now the working code will be
global $settings, $context, $txt, $smcFunc, $user_info, $scripturl, $boardurl, $modSettings;

// Load buddy list (copied from WirelessAddBuddy, indent to distinguish from that part)
$context['buddies'] = array();
$width = '220px';
$height = '220px';
if (!empty($user_info['buddies']))
{
$request = $smcFunc['db_query']('', '
SELECT mem.id_member, mem.member_name, mem.real_name, mem.avatar, mg.online_color, a.id_attach, a.attachment_type, a.filename
FROM {db_prefix}members mem
    LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = mem.id_member)
LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = CASE WHEN mem.id_group = {int:reg_member_group} THEN mem.id_post_group ELSE mem.id_group END)
WHERE mem.id_member IN ({array_int:buddy_list})
ORDER BY mem.real_name',
array(
'reg_member_group' => 0,
'buddy_list' => $user_info['buddies'],
)
);
while ($row = $smcFunc['db_fetch_assoc']($request))
$context['buddies'][] = array(
'id' => $row['id_member'],
'member_name' => $row['member_name'],
'real_name' => $row['real_name'],
'color' => $row['online_color'],
'avatar' => array(
                    'image' => empty($row['avatar']) ? ($row['id_attach'] > 0 ? '<img src="' . (empty($row['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $row['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) . '" alt="" border="0" width="'.$width.'" height="'.$height.'" title="'.$row['real_name'].'" />' : '') : (stristr($row['avatar'], 'http://') ? '<img src="' . $row['avatar'] . '" alt="" border="0" width="'.$width.'" height="'.$height.'" title="'.$row['real_name'].'" />' : '<img src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($row['avatar']) . '" alt="" border="0" width="'.$width.'" height="'.$height.'" title="'.$row['real_name'].'" />'),
                       ),
);
$smcFunc['db_free_result']($request);
}

echo '<br>
<div class="wholebuddylist">';
foreach ($context['buddies'] as $buddy) {
echo '<div class="onebuddy">
    <div class="buddyname">', $buddy['real_name'] ,'</div>
<div class="buddyavatar"><a href="' . $scripturl . '?action=profile;area=showposts;u=' . $buddy['id'] . '"> ', $buddy['avatar']['image'] ,'  </a></div>
    </div>';
}
    echo '</div>';


thanx guys for the help

 this codes gives u alist of buddies you are following  compatable with smf 2.1.4

Advertisement: