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

Reply
 
Thread Tools Display Modes
  #1  
Old 05-13-2016, 02:52 AM
Dr.CustUmz's Avatar
Dr.CustUmz Dr.CustUmz is offline
 
Join Date: Aug 2013
Location: USA
Posts: 647
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default [SOLVED] vbulletin doesn't like ternary operators?

for simplistic code sake I'm trying to use ternary operators in my products.

Here's what im trying to simplify:

Code:
if ($vbulletin->options['drc_embed_vine_smpl']) {
    $drc_embed_vine =  '<iframe src="https://vine.co/v/$2/embed/simple" width="480" height="480" frameborder="0"></iframe>';
  } else {
    $drc_embed_vine =  '<iframe src="https://vine.co/v/$2/embed/postcard" width="480" height="480" frameborder="0"></iframe>';
  }
Now I have tried

Code:
$drc_embed_vine = '<iframe src="https://vine.co/v/$2/embed/'.(($vbulletin->options['drc_embed_vine_smpl']) ? "simple" : "postcard").'" width="480" height="480" frameborder="0"></iframe>';
Code:
$drc_embed_vine='<iframe src="https://vine.co/v/$2/embed/'.(($vbulletin->options['drc_embed_vine_smpl'])?'simple':'postcard')).' width="480" height="480" frameborder="0">';
Code:
$drc_embed_vine='<iframe src="https://vine.co/v/$2/embed/'.(($vbulletin->options[\'drc_embed_vine_smpl\'])?'simple':'postcard')).' width="480" height="480" frameborder="0">';
not one of these worked =/

although
Code:
$drc_embed_vine = '<iframe src="https://vine.co/v/$2/embed/'.(($vbulletin->options['drc_embed_vine_smpl']) ? "simple" : "postcard").'" width="480" height="480" frameborder="0"></iframe>';
does use the postcard option but it does whether the option is yes or no

btw
Code:
$vbulletin->options['drc_embed_vine_smpl']
is a simple yesno boolean

where am i going wrong =/
Reply With Quote
  #2  
Old 05-13-2016, 12:29 PM
Dave Dave is offline
 
Join Date: May 2010
Posts: 2,583
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

vBulletin does like it, it's just that you probably use the if statement wrong of the ternary operator.

Does $vbulletin->options['drc_embed_vine_smpl'] literally contain a boolean: true/false or does it contain a number 1 (true) and 0 (false)?

If it's really a boolean, then the following should work just fine:
PHP Code:
($vbulletin->options['drc_embed_vine_smpl'] === true "simple" "postcard"
If it contains a number:
PHP Code:
($vbulletin->options['drc_embed_vine_smpl'] === "simple" "postcard"
Reply With Quote
Благодарность от:
Dr.CustUmz
  #3  
Old 05-13-2016, 03:18 PM
Dr.CustUmz's Avatar
Dr.CustUmz Dr.CustUmz is offline
 
Join Date: Aug 2013
Location: USA
Posts: 647
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It does return a number, but for some reason it still not working, the option exist. I do toggle it one to the other, but it always shows postcard.

I Tried
Code:
($vbulletin->options['drc_embed_vine_smpl'] === 1 ? "simple" : "postcard")
and

Code:
($vbulletin->options['drc_embed_vine_smpl'] == 1 ? "simple" : "postcard")
this is the plugin
Code:
<hookname>postbit_display_complete</hookname>
<phpcode><![CDATA[
      $drc_embed_vine = '<iframe src="https://vine.co/v/$2/embed/'.($vbulletin->options['drc_embed_vine_smpl'] == 1 ? "simple" : "postcard").'" width="480" height="480" frameborder="0"></iframe>';
        $this->post['message'] = preg_replace('~(<a href="https?://vine.co)/v/(.*)" target="_blank">(https?://vine.co)/v/(.*)<\/a>~', $drc_embed_vine, $this->post['message']);
]]></phpcode>
and the option
Code:
<setting varname="drc_embed_vine_smpl" displayorder="1">
<datatype>boolean</datatype>
<optioncode>yesno</optioncode>
<defaultvalue>1</defaultvalue>
</setting>
Reply With Quote
  #4  
Old 05-13-2016, 03:22 PM
Dave Dave is offline
 
Join Date: May 2010
Posts: 2,583
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Add the following somewhere before you call the ternary operator so you can see what it contains:
PHP Code:
var_dump($vbulletin->options['drc_embed_vine_smpl']); 
Reply With Quote
Благодарность от:
MarkFL
  #5  
Old 05-13-2016, 03:29 PM
Dr.CustUmz's Avatar
Dr.CustUmz Dr.CustUmz is offline
 
Join Date: Aug 2013
Location: USA
Posts: 647
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

i placed it at the beginning of the plugin, this is what it spat out in my showthread.

Reply With Quote
  #6  
Old 05-13-2016, 03:40 PM
Dr.CustUmz's Avatar
Dr.CustUmz Dr.CustUmz is offline
 
Join Date: Aug 2013
Location: USA
Posts: 647
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Adding the product for reference

I changed the option in this version, thinking maybe i had a conflict, but no luck
Attached Files
File Type: xml [DRC] - Auto Embed Vine.xml (2.3 KB, 4 views)
Reply With Quote
  #7  
Old 05-13-2016, 04:53 PM
Dave Dave is offline
 
Join Date: May 2010
Posts: 2,583
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

drc_embed_vine_smpl is not defined in your import file. I think you're using the wrong variable.
Reply With Quote
  #8  
Old 05-13-2016, 05:41 PM
Dr.CustUmz's Avatar
Dr.CustUmz Dr.CustUmz is offline
 
Join Date: Aug 2013
Location: USA
Posts: 647
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Dave View Post
drc_embed_vine_smpl is not defined in your import file. I think you're using the wrong variable.
i change it all to "drc_ae_vine_styl" in that version attached thinking maybe I had a conflict somewhere.
Reply With Quote
  #9  
Old 05-13-2016, 07:06 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I think you need to globalize $vbulletin in the postbit_display_complate hook location.
Reply With Quote
2 благодарности(ей) от:
Dr.CustUmz, MarkFL
  #10  
Old 05-13-2016, 07:09 PM
Dr.CustUmz's Avatar
Dr.CustUmz Dr.CustUmz is offline
 
Join Date: Aug 2013
Location: USA
Posts: 647
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Lynne View Post
I think you need to globalize $vbulletin in the postbit_display_complate hook location.
ive never had to do this, but have seen it done somewhere before.

this is as simple as adding
Code:
global $vbulletin;
correct?

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

yup, THANK YOU SO MUCH LYNNE!

I had no clue why this wouldn't work, so for future ref. how do I know when I need to globalize a var other than just giving it a shot lol
Reply With Quote
Благодарность от:
MarkFL
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 08:24 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.08505 seconds
  • Memory Usage 2,300KB
  • Queries Executed 12 (?)
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
  • (11)bbcode_code
  • (3)bbcode_php
  • (2)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
  • (5)post_thanks_box_bit
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (4)post_thanks_postbit
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (1)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
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • postbit_attachment
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete