Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 05-15-2013, 06:55 PM
emath emath is offline
 
Join Date: Sep 2008
Posts: 252
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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.
Reply With Quote
  #2  
Old 05-15-2013, 07:10 PM
nhawk nhawk is offline
 
Join Date: Jan 2011
Posts: 1,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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?
Reply With Quote
  #3  
Old 05-15-2013, 07:21 PM
emath emath is offline
 
Join Date: Sep 2008
Posts: 252
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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 .
Reply With Quote
  #4  
Old 05-15-2013, 07:40 PM
nhawk nhawk is offline
 
Join Date: Jan 2011
Posts: 1,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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?
Attached Images
File Type: jpg result.jpg (89.0 KB, 0 views)
Reply With Quote
  #5  
Old 05-15-2013, 07:53 PM
emath emath is offline
 
Join Date: Sep 2008
Posts: 252
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

whats the 'Show Users Browsing Threads' option?
Reply With Quote
  #6  
Old 05-15-2013, 07:57 PM
nhawk nhawk is offline
 
Join Date: Jan 2011
Posts: 1,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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).
Attached Images
File Type: jpg viewing.jpg (52.5 KB, 0 views)
Reply With Quote
  #7  
Old 05-15-2013, 08:07 PM
emath emath is offline
 
Join Date: Sep 2008
Posts: 252
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #8  
Old 05-15-2013, 08:17 PM
nhawk nhawk is offline
 
Join Date: Jan 2011
Posts: 1,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #9  
Old 05-15-2013, 08:18 PM
emath emath is offline
 
Join Date: Sep 2008
Posts: 252
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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 ...
Attached Images
File Type: jpg Capture.JPG (28.9 KB, 0 views)
Reply With Quote
  #10  
Old 05-15-2013, 08:22 PM
emath emath is offline
 
Join Date: Sep 2008
Posts: 252
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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..
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:53 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.06672 seconds
  • Memory Usage 2,295KB
  • Queries Executed 14 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (3)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (3)postbit_attachment
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • postbit_attachment
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete