vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Adding Template Conditionals to vB. (https://vborg.vbsupport.ru/showthread.php?t=77965)

neocorteqz 03-12-2005 10:13 AM

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

http://upload.nemesisforums.net/./us...b_error_01.png

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


Marco van Herwaarden 03-12-2005 10:14 AM

Normally you can not use any other then the default conditionals in template.

neocorteqz 03-12-2005 10:19 AM

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.

Revan 03-12-2005 10:30 AM

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 :p

neocorteqz 03-12-2005 05:46 PM

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 :p

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. :p well kinda working, but it's not showing for any os listed in the code. :D

kall 03-12-2005 06:07 PM

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 :p

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.

neocorteqz 03-12-2005 06:37 PM

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

Looking for a little help now. :p

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?

Marco van Herwaarden 03-12-2005 06:43 PM

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.

neocorteqz 03-12-2005 08:05 PM

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.

Marco van Herwaarden 03-13-2005 07:01 AM

PHP Code:

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

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

?>



All times are GMT. The time now is 10:51 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.01239 seconds
  • Memory Usage 1,791KB
  • 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
  • (1)bbcode_html_printable
  • (8)bbcode_php_printable
  • (4)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (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
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete