Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 03-12-2005, 10:13 AM
neocorteqz's Avatar
neocorteqz neocorteqz is offline
 
Join Date: May 2002
Location: Barefoot Bay Fl
Posts: 473
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Adding Template Conditionals to vB.

Trying to add the following to functions.php

PHP Code:
// #################### Start is os ##########################
// os detection script
function is_os($os)
{
    global 
$_SERVER;
    static 
$is;
    if (!
is_array($is))
    {
        
$useragent strtolower($_SERVER['HTTP_USER_AGENT']);
        
$is = array(
            
'linux' => 0,
            
'mac' => 0,
            
'windows' => 0,
            
'webtv' => 0
        
);

        
// detect windows
        
if (strpos($useragent'winnt,win32,windows,32bit') !== false)
        {
            
$is['windows'] = 1;
        }
        
        
// detect macintosh
        
if (strpos($useragent'mac') !== false)
        {
            
$is['mac'] = 1;
        }

        
        
// detect linux
        
if (strpos($useragent'linux,x11,u,i686') !== false)
        {
            
$is['linux'] = 1;
        }

        
        
// detect web tv
        
if (strpos($useragent'webtv') !== false)
        {
            
preg_match('#webtv/([0-9\.]+)#'$useragent$regs);
            
$is['webtv'] = $regs[1];
        }

    }

    
// sanitize the incoming os name
    
$os strtolower($os);
    if (
substr($os03) == 'is_')
    {
        
$os substr($os3);
    }

}
// #################### End is os ########################## 
But when i try to use it i get this error



Are there other files I need to edit to add template conditionals?

And a second question.

is the 'if' in the code above correct?
This:
PHP Code:
if (strpos($useragent'winnt,win32,windows,32bit') !== false
Reply With Quote
  #2  
Old 03-12-2005, 10:14 AM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Normally you can not use any other then the default conditionals in template.
Reply With Quote
  #3  
Old 03-12-2005, 10:19 AM
neocorteqz's Avatar
neocorteqz neocorteqz is offline
 
Join Date: May 2002
Location: Barefoot Bay Fl
Posts: 473
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by MarcoH64
Normally you can not use any other then the default conditionals in template.
I know. which makes what I want to do, kinda hard. So i was trying to add something to where i can use a custom conditional in a template.

Is there way I can add what i'm trying to do to say is_browser?

it's basically an os specific conditional, so i can use some plugin that require certain operating systems.
Reply With Quote
  #4  
Old 03-12-2005, 10:30 AM
Revan's Avatar
Revan Revan is offline
 
Join Date: Jan 2004
Location: Norway
Posts: 1,671
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You have to add the function to an array defined somewhere in adminfunctions_template.php
Give me 1 min and I will edit this post with the exact name and place

In adminfunctions_template.php find:

PHP Code:
// vBulletin-defined functions
            
'can_moderate',          // obvious one
            
'can_moderate_calendar'// another obvious one
            
'exec_switch_bg',        // harmless function that we use sometimes
            
'is_browser',            // function to detect browser and versions
            
'is_member_of',          // function to check if $user is member of $usergroupid 
under, add:
PHP Code:
'is_os',          // function to check the OS of the member 
Original Thread
Kall wrote the thread, but I was the one to put him on the right track to find this code
Reply With Quote
  #5  
Old 03-12-2005, 05:46 PM
neocorteqz's Avatar
neocorteqz neocorteqz is offline
 
Join Date: May 2002
Location: Barefoot Bay Fl
Posts: 473
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Revan
You have to add the function to an array defined somewhere in adminfunctions_template.php
Give me 1 min and I will edit this post with the exact name and place

In adminfunctions_template.php find:

PHP Code:
// vBulletin-defined functions
            
'can_moderate',          // obvious one
            
'can_moderate_calendar'// another obvious one
            
'exec_switch_bg',        // harmless function that we use sometimes
            
'is_browser',            // function to detect browser and versions
            
'is_member_of',          // function to check if $user is member of $usergroupid 
under, add:
PHP Code:
'is_os',          // function to check the OS of the member 
Original Thread
Kall wrote the thread, but I was the one to put him on the right track to find this code
Now i can see if my code works. which I believe it should. I knew there was another file i needed to add somethning.

thanks!

Alright, that allows me to use the template conditional, now All i need to do is figure out why it's not working. well kinda working, but it's not showing for any os listed in the code.
Reply With Quote
  #6  
Old 03-12-2005, 06:07 PM
kall's Avatar
kall kall is offline
 
Join Date: Apr 2004
Location: New Zealand
Posts: 2,608
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Revan
Kall wrote the thread, but I was the one to put him on the right track to find this code
And I am eternally grateful.

That's what makes this place great, the fact that people are prepared to help others get their heads around the code.
Reply With Quote
  #7  
Old 03-12-2005, 06:37 PM
neocorteqz's Avatar
neocorteqz neocorteqz is offline
 
Join Date: May 2002
Location: Barefoot Bay Fl
Posts: 473
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

kall, i know hat ya mean, it's great.

Looking for a little help now.

Here is the revised code.

PHP Code:
// #################### Start is os ##########################
// os detection script
function is_os($os)
{
    global 
$_SERVER;
    static 
$is;
    if (!
is_array($is))
    {
        
$useragent strtolower($_SERVER['HTTP_USER_AGENT']);
        
$is = array(
            
'linux' => 0,
            
'mac' => 0,
            
'windows' => 0,
            
'webtv' => 0
        
);

        
// detect windows
        
if ((strpos($useragent'winnt') !== false) AND (strpos($useragent'win32') !== false))
        {
            
$is['windows'] = 1;
        }
        
        
// detect macintosh
        
if (strpos($useragent'mac') !== false)
        {
            
$is['mac'] = 1;
        }

        
        
// detect linux
        
if ((strpos($useragent'linux') !== false) AND (strpos($useragent'x11') !== false) AND (strpos($useragent'i686') !== false)))
        {
            
$is['linux'] = 1;
        }

        
        
// detect web tv
        
if (strpos($useragent'webtv') !== false)
        {
            
preg_match('#webtv/([0-9\.]+)#'$useragent$regs);
            
$is['webtv'] = $regs[1];
        }

    }

    
// sanitize the incoming os name
    
$os strtolower($os);
    if (
substr($os03) == 'is_')
    {
        
$os substr($os3);
    }

}
// #################### End is os ########################## 
Is there anything wrong in that?
Because i use the conditional
HTML Code:
<if condition="is_os('windows')">
code here
</if>
And nothing shows up.

Now I know I'm in windows. and I know is_browser('ie') works.

did i miss something in the code?? I used exosting vB code as a model (specifically is_browser)

do i need to add the user agent strings to the code as they have in is_browser?
Reply With Quote
  #8  
Old 03-12-2005, 06:43 PM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hmm maybe i am missing something, but i can't see where the incoming string 'windows' ($os) is being tested against the detected os. The function should return a TRUE or FALSE.

Just try your function first with a test script, without templates, just call it from a plain php testfile. Much easier to debaug.
Reply With Quote
  #9  
Old 03-12-2005, 08:05 PM
neocorteqz's Avatar
neocorteqz neocorteqz is offline
 
Join Date: May 2002
Location: Barefoot Bay Fl
Posts: 473
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by MarcoH64
Hmm maybe i am missing something, but i can't see where the incoming string 'windows' ($os) is being tested against the detected os. The function should return a TRUE or FALSE.

Just try your function first with a test script, without templates, just call it from a plain php testfile. Much easier to debaug.
how would I do that?

I'm still very much a noobie when it comes to this stuff.
Reply With Quote
  #10  
Old 03-13-2005, 07:01 AM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
<?php
require_once('./includes/yourincludefile.php');

if (
is_os('windows'))
{
   echo 
"<br />Yes windows";
}
else
{
   echo 
"<br />No windows";
}

?>
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 07:51 AM.


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.04489 seconds
  • Memory Usage 2,314KB
  • Queries Executed 13 (?)
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
  • (1)bbcode_html
  • (8)bbcode_php
  • (4)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete