vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Convert $userinfo[posts] from a string to a number (https://vborg.vbsupport.ru/showthread.php?t=169350)

davide101 02-01-2008 12:47 PM

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?

Opserty 02-01-2008 01:43 PM

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.

Nifty_xxl 02-01-2008 02:15 PM

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] );

davide101 02-01-2008 03:27 PM

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.

Opserty 02-01-2008 04:58 PM

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'])); 


davide101 02-01-2008 05:52 PM

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.

Opserty 02-01-2008 06:13 PM

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.


All times are GMT. The time now is 04:44 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.02003 seconds
  • Memory Usage 1,725KB
  • 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_code_printable
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)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
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete