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 02-01-2008, 12:47 PM
davide101 davide101 is offline
 
Join Date: Dec 2005
Posts: 100
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Convert $userinfo[posts] from a string to a number

First, I've never created a plugin before, so please be gentle!

$userinfo[posts] and $post[posts] outputs a user's posts as a string (why, I don't know). This makes it useless for doing comparisons. I need to create a plugin that will take that output, convert it to a string, and store it in a variable so I can do comparison.

Where exactly do I begin? Is there something out there that does something similar that I can reverse engineer? Do you have any pointers on how to get going?
Reply With Quote
  #2  
Old 02-01-2008, 01:43 PM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Are you sure? I thought vB converted them to integers. Otherwise its a string because MySQL returns data from a query as an array of strings (it doesn't convert them to integers automatically). You can use the intval() function to convert a string to a integer.
Reply With Quote
  #3  
Old 02-01-2008, 02:15 PM
Nifty_xxl Nifty_xxl is offline
 
Join Date: Jul 2006
Posts: 3
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Plugins are pure php, so there is no need to convert it by youreself. Php has no types if a variable contains a number you can use it as such.

// This one will use it as number
if( $userinfo[posts] >5){
}

// THis will use it as String
echo("Posts:" . $userinfo[posts] );
Reply With Quote
  #4  
Old 02-01-2008, 03:27 PM
davide101 davide101 is offline
 
Join Date: Dec 2005
Posts: 100
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Opserty, I'm pretty sure. You can read my thread on vbulletin.com about it. In short, I used the conditional below and it only worked on threads above 2000. If someone can explain why that is, I'd love to know.

Code:
<if condition="$post[posts] >= '1000'"> &gt;1000<else /> $post[posts]</if>
Nifty_xxl, that's good to know. So far, I can see two possible approaches. Is either of these the best way to do it?

Way 1 I override the behavior of $userinfo[posts] and $post[posts] within a plugin. This is ideal because I could change them to output the number below 1000 and just > 1000 above. There would be no template edits.

Way 2 Create new variables with the relevant post count and edit the templates. Are those two variables even accessible by a plugin? Are they available everywhere or just within a certain hook?

If I'm conceptually off, please let me know. I really appreciate the feedback. If I can find a way to do this that's straightforward and doesn't require edits, it would make a great mod.
Reply With Quote
  #5  
Old 02-01-2008, 04:58 PM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You could use str_replace() on the variable:

PHP Code:
// I think its $post if not then try $this->post
$post['posts_int'] = intval(str_replace(','''$post['posts'])); 
Reply With Quote
  #6  
Old 02-01-2008, 05:52 PM
davide101 davide101 is offline
 
Join Date: Dec 2005
Posts: 100
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

THANK YOU! I created three plugins, one for the memberlist_resultbit, profile_complete (or whatever it's called), and postbit_complete. It worked like a charm and all the conditionals are now functioning. At some point in time, I may just overwrite the string rather than using template conditionals to make upgrading easier, but at least it works. I really appreciate the help. Hopefully this will ease some of the fluff posts that have become so common.
Reply With Quote
  #7  
Old 02-01-2008, 06:13 PM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

No problem, the only reason I chose not to overwrite the variable is that it is used in the template in its comma separated form (10,000 e.t.c.) in the postbit template.
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 04:47 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.03548 seconds
  • Memory Usage 2,216KB
  • 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_code
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)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_postinfo_query
  • fetch_postinfo
  • 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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete