vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   foreach doesnt work with IE (https://vborg.vbsupport.ru/showthread.php?t=298195)

emath 05-15-2013 06:55 PM

foreach doesnt work with IE
 
I made this script : ( in a hook )

PHP Code:

if ($_REQUEST['do'] == 'rqusers' AND $vbulletin->options['active_users_onoff'] AND isset($activeusers) )
{
    
$first=true;
    foreach ( 
$activeusers as $row ) {
        if ( 
$first )    { 
            
$first false;
            
$str "<li><a class=\"username\" href=\" \"> " $row["musername"] . "</a></li>";    } 
        else { 
            
$str .= ",&nbsp<li><a class=\"username\" href=\" \"> " $row["musername"] . "</a></li>";    }            
    }    
    echo 
"<p>" construct_phrase($vbphrase['users_currently_browsing_x_y_z'], $totalonline$numberregistered$numberguest) . "</p><ol class=\"commalist\">" $str "</ol>" ;
    exit;


though, on IE, and only IE this doesnt work ( it doesnt through the IF .. )

if i take off the AND isset($activeusers) then i get the error :

Invalid argument supplied for foreach()

any ideas with this ? i tried to do as $key => $value

but it didnt work, again this only happening with IE, with CHROME and FIREFOX everything works great.

nhawk 05-15-2013 07:10 PM

PHP isn't a client side language, it's server side. So if it works with FF or any other browser, it will work with IE.

What hook did you use?

Where is $activeusers being populated?

Is $activeusers an array?

emath 05-15-2013 07:21 PM

the hook is showthread_complete .

all im saying, this is what happening . FF and Chrome works well, on IE i get the above error message ( if the isset() is not stated also at the IF condition ) .

$activeusers is an array defined on the showthread.php file .

nhawk 05-15-2013 07:40 PM

1 Attachment(s)
I just tested your code, but to do so I had to remove your if condition because there's no DO condition like that on my system and there's no 'active_users_onoff' that I know of in a standard vB4 install.

So I ended up testing this...
PHP Code:

   $first=true
    foreach ( 
$activeusers as $row ) { 
        if ( 
$first )    {  
            
$first false
            
$str "<li><a class=\"username\" href=\" \"> " $row["musername"] . "</a></li>";    } 
         else {  
            
$str .= ",&nbsp<li><a class=\"username\" href=\" \"> " $row["musername"] . "</a></li>";    }            
     }     
    echo 
"<p>" construct_phrase($vbphrase['users_currently_browsing_x_y_z'], $totalonline$numberregistered$numberguest) . "</p><ol class=\"commalist\">" $str "</ol>" ;
     exit; 

It worked fine with IE.

The other question I have is why not just use the 'Show Users Browsing Threads' option that's built in to vB?

emath 05-15-2013 07:53 PM

whats the 'Show Users Browsing Threads' option?

nhawk 05-15-2013 07:57 PM

1 Attachment(s)
It does exactly what you're doing with your code. It shows who's currently viewing a thread.

It's in ACP->Settings->Options->Thread Display Options(showthread).

emath 05-15-2013 08:07 PM

oh, i thought there is a variable for that.

i have made a refresh button for the thread information using ajax... so thats the replaced text when clicking on the button .

regarding the issue, it does happend also on firefox now for some reason, but i have no idea what is the problem .

why would $activeusers would be invalid for foreach ..

--------------- Added [DATE]1368652200[/DATE] at [TIME]1368652200[/TIME] ---------------

this is the code for $activeusers in showthread :



PHP Code:

    $activeusers = array();
    if (
$vbulletin->userinfo['userid']) // fakes the user being in this thread
    
{
        
$loggedin = array(
            
'userid'        => $vbulletin->userinfo['userid'],
            
'username'      => $vbulletin->userinfo['username'],
            
'invisible'     => $vbulletin->userinfo['invisible'],
            
'invisiblemark' => $vbulletin->userinfo['invisiblemark'],
            
'inthread'      => $threadinfo['threadid'],
            
'lastactivity'  => TIMENOW,
            
'musername'     => $vbulletin->userinfo['musername'],
        );
        
$numberregistered 1;
        
$numbervisible 1;
        
fetch_online_status($loggedin);

        
$loggedin['comma'] = $vbphrase['comma_space'];
        
$activeusers[$numberregistered] = $loggedin;
        
$doneuser["{$vbulletin->userinfo['userid']}"] = 1


nhawk 05-15-2013 08:17 PM

I've never done something like this with ajax, but if I'm not mistaken you need to rebuild the activeusers with a database query in your ajax code and save it to the ajax xml.

The way it is now, you don't have $activeusers in your ajax code. That's why the error is popping up.

Perhaps someone with more ajax experience than me will chime in on this.

emath 05-15-2013 08:18 PM

1 Attachment(s)
you can see it on action on this page : http://www.emath.co.il/forums/%D7%97...7%9D/68746.htm

you need to click the button on the left ( see pic )

EDIT : IT IS WORKING FOR CHROME and WORKED for firefox... probably its something with the cookies the reason it worked with ff and not its not. though it is working, no need to rebuild the $activeusers ...

emath 05-15-2013 08:22 PM

IT seems that if im not logged in, its working otherwise, gives the invalid error.

--------------- Added [DATE]1368653172[/DATE] at [TIME]1368653172[/TIME] ---------------

*sigh*

i guess the error is because the $activeusers is empty (when no user is logged in..)

thanks for the help..


All times are GMT. The time now is 01:00 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01165 seconds
  • Memory Usage 1,761KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete