Re: Update to SMF2 -> some assistance with db_query required [SOLVED]

Started by plasmatic, October 14, 2014, 07:40:52 PM

Previous topic - Next topic

plasmatic

I'm actually about to update my board from SMF 1.1.20 to 2.0.9. The update itself worked surprisingly smooth and most of the customizing is already done, but now i'm stuck while converting a PHP script with a SQL-query to the SMF 2 format.

The script connects an Ajax-Chat to the board and adds a box, showing a list with the users currently chatting.

Any help would be greatly appreciated.


$result = db_query("SELECT a.userID, a.userName, a.userRole, a.channel, m.realName
FROM ajax_chat_online AS a
LEFT JOIN {$db_prefix}boards AS b ON (b.ID_BOARD = a.channel)
LEFT JOIN {$db_prefix}members AS m ON (m.ID_MEMBER = a.userID)
WHERE NOW() <= DATE_ADD(dateTime, interval 2 MINUTE)
AND (a.channel = 0
OR {$user_info['query_see_board']})", __FILE__, __LINE__);

while ($row = mysql_fetch_assoc($result)) {
        $id = $row['userID'];
$users[$id]['is_guest'] = $row['userRole'] == $memGroupGuest;
$users[$id]['channel'] = $row['channel'];
$users[$id]['userName'] = htmlspecialchars(utf8_decode($row['userName']));
}

mysql_free_result($result);

vbgamer45

Here you go

$result = $smcFunc['db_query']('', "SELECT a.userID, a.userName, a.userRole, a.channel, m.real_name
FROM ajax_chat_online AS a
LEFT JOIN {db_prefix}boards AS b ON (b.ID_BOARD = a.channel)
LEFT JOIN {db_prefix}members AS m ON (m.ID_MEMBER = a.userID)
WHERE NOW() <= DATE_ADD(dateTime, interval 2 MINUTE)
AND (a.channel = 0
OR {$user_info['query_see_board']})");

while ($row = $smcFunc['db_fetch_assoc']($result)) {
        $id = $row['userID'];
$users[$id]['is_guest'] = $row['userRole'] == $memGroupGuest;
$users[$id]['channel'] = $row['channel'];
$users[$id]['userName'] = htmlspecialchars(utf8_decode($row['userName']));
}

$smcFunc['db_free_result']($result);
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

margarett

It's pretty much one-on-one with $smcFunc ;)

$result = $smcFunc['db_query']('', '
SELECT a.userID, a.userName, a.userRole, a.channel, m.realName
FROM ajax_chat_online AS a
LEFT JOIN {$db_prefix}boards AS b ON (b.ID_BOARD = a.channel)
LEFT JOIN {$db_prefix}members AS m ON (m.ID_MEMBER = a.userID)
WHERE NOW() <= DATE_ADD(dateTime, interval 2 MINUTE)
AND (a.channel = 0
OR {query_see_board})'
);
while ($row = $smcFunc['db_fetch_assoc']($result))
{
        $id = $row['userID'];
$users[$id]['is_guest'] = $row['userRole'] == $memGroupGuest;
$users[$id]['channel'] = $row['channel'];
$users[$id]['userName'] = htmlspecialchars(utf8_decode($row['userName']));
}
$smcFunc['db_free_result']($result);

Not tested, use with caution :P

edit: ninja'd ;D
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

vbgamer45

Also camalcase columns like realName are changed to real_name  with the _ divider.
{$db_prefix} changed to {db_prefix}
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

plasmatic

Thanks for your help, guys.

Tried both patches, but unfortunally without success.

With both i got in the apachelog
"PHP Fatal error:  Cannot redeclare ssi_shutdown() (previously declared in /home/xxxxx/public_html/board/SSI.php:199) in /home/xxxxx/public_html/board/SSI.php on line 199"

SMF-errorlog keeps empty..

vbgamer45

Make sure top of your script has require_once("SSI.php");
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

plasmatic

global $boarddir;

require_once $boarddir.'/SSI.php';

// Liste Online Chat User

global $db_prefix, $scripturl, $txt, $user_info;
   
    // Board- und Benutzergruppen IDs
    $boardBS = 11;
    $memGroupBS = 9;
    $memGroupGuest = 0;
   
    $txt['chat_no_user'] = 'Kein Benutzer im <a href="/wohnzimmer/" target="_blank">Chat</a>';
    $txt['chat_users'] = ' Benutzer im <a href="/wohnzimmer/" target="_blank">Chat</a>';
$txt['chat_bs_no_user'] = 'Kein Benutzer im <a href="/wohnzimmer/index.php?channelID=' . $boardBS . '" target="_blank"> Hinterzimmer</a>';
$txt['chat_bs_user'] = ' Benutzer im <a href="/wohnzimmer/index.php?channelID=' . $boardBS . '" target="_blank">Hinterzimmer</a>';
   
$users = array();
    $numChatUsers = 0;
    $numBsUsers = 0;
   
$result = $smcFunc['db_query']('', "SELECT a.userID, a.userName, a.userRole, a.channel, m.real_name
FROM ajax_chat_online AS a
LEFT JOIN {db_prefix}boards AS b ON (b.ID_BOARD = a.channel)
LEFT JOIN {db_prefix}members AS m ON (m.ID_MEMBER = a.userID)
WHERE NOW() <= DATE_ADD(dateTime, interval 2 MINUTE)
AND (a.channel = 0
OR {$user_info['query_see_board']})");

while ($row = $smcFunc['db_fetch_assoc']($result)) {
        $id = $row['userID'];
$users[$id]['is_guest'] = $row['userRole'] == $memGroupGuest;
$users[$id]['channel'] = $row['channel'];
$users[$id]['userName'] = htmlspecialchars(utf8_decode($row['userName']));

// Falls Forumuser sich umbenannt hat, entferne Klammern, ansonsten nutze Forumsnamen
$name = $users[$id]['userName'];
if (! $users[$id]['is_guest']) {
if (strlen($name) > 2 && substr($name, 0, 1) == '(' && substr($name, -1) == ')')
$users[$id]['userName'] = substr($name, 1, -1);

else $users[$id]['userName'] = htmlspecialchars($row['realName']);
}
        switch ($users[$id]['channel']) {
            case 0        : $numChatUsers++; break;
            case $boardBS : $numBsUsers++; break;
        }
    }
   
$smcFunc['db_free_result']($result);

echo '<div class="smalltext">';

// User Wohnzimmer ausgeben
if ($numChatUsers > 0) {
echo '<b>' . $numChatUsers . $txt['chat_users'] . '</b><br /><br />';

// Zuerst Forumuser ausgeben
foreach ($users as $id => $userData) {
if ($userData['channel'] == 0 && !$userData['is_guest'])
echo '<img src="./Themes/default/images/TPdivider2.gif" alt="" style="margin:0 2px 0 0;" />',
     '<a href="' . $scripturl . '?action=profile;u=' . $id . '">' . $userData['userName'] . '</a><br />';
}

// Gäste ausgeben
foreach ($users as $userData) {
if ($userData['is_guest'])
echo '<img src="./Themes/default/images/TPdivider2.gif" alt="" style="margin:0 2px 0 0;" />' . $userData['userName'] . '<br />';
}
}
else echo $txt['chat_no_user'] . '<br />';

// Hinterzimmer User ausgeben
if ($user_info['is_admin'] || in_array($memGroupBS, $user_info['groups'])) {
if ($numBsUsers > 0) {
echo '<br /><b>' . $numBsUsers . $txt['chat_bs_user'] .'</b><br /><br />';
foreach ($users as $id => $userData) {
if ($userData['channel'] == $boardBS)
echo '<img src="./Themes/default/images/TPdivider2.gif" alt="" style="margin:0 2px 0 0;" />',
'<a href="' . $scripturl . '?action=profile;u=' . $id . '">' . $userData['userName'] . '</a><br />';
}
}
else echo '<br />' . $txt['chat_bs_no_user'];
}
             
    echo '</div>';


Changing "require" with "require_once" changes  the errormessage to: " PHP Fatal error:  Function name must be a string in /home/xxxxx/public_html/board/Sources/PortalBlocks.php(3592) : eval()'d code on line 23,"

vbgamer45

Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

plasmatic

YES! Works!  8) :) ;D :D :laugh:

Additionally i changed Line43:
else $users[$id]['userName'] = htmlspecialchars($row['realname']);
to
else $users[$id]['userName'] = htmlspecialchars($row['real_name']);



Thank you very much!!!

Advertisement: