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

Reply
 
Thread Tools Display Modes
  #1  
Old 05-24-2017, 03:44 AM
RaYdeN.ADM's Avatar
RaYdeN.ADM RaYdeN.ADM is offline
 
Join Date: May 2006
Location: Los Angeles, CA (US)
Posts: 44
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Posts, replys & Views "counts" without comma?

I need to remove the comma in order to send the variable in javascript and work the number to 1200> 1.2K. The problem is that javascript takes the comma as if it were sending 2 values and only works with numbers without a comma.

So what I need is to remove the comma before sending it to javascript.

Example:

1,000 > 1000
1,000,000 > 1000000

PHP Code:
<script type="text/javascript">
    function 
fHcountHits(num) { 
        if (
num >= 1000000000) { 
            return (
num 1000000000).toFixed(1).replace(/\.0$/, '') + 'G'
        } else if (
num >= 1000000) { 
            return (
num 1000000).toFixed(1).replace(/\.0$/, '') + 'M'
        } else if (
num >= 1000) { 
            return (
num 1000).toFixed(1).replace(/\.0$/, '') + 'K'
        }
 
        return 
num
    }  
</
script
PHP Code:
<script type="text/javascript">document.write(fHcountHits({vb:raw forum.threadcount}));</script>
<
script type="text/javascript">document.write(fHcountHits({vb:raw forum.replycount}));</script
The error is that the {vb:raw forum.threadcount} and {vb:raw forum.replycount} return the numbers with a comma, how do I remove them ?.

thx
Reply With Quote
  #2  
Old 05-24-2017, 04:03 AM
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Location: St. Augustine, FL
Posts: 3,853
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

In your second script, try this:

HTML Code:
<script type="text/javascript">
	var n = {vb:raw forum.threadcount};
	n = n.replace(/\,/g, '');
	n = parseInt(n, 10);
	document.write(fHcountHits(n));
</script>
Reply With Quote
  #3  
Old 05-24-2017, 04:13 AM
RaYdeN.ADM's Avatar
RaYdeN.ADM RaYdeN.ADM is offline
 
Join Date: May 2006
Location: Los Angeles, CA (US)
Posts: 44
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by MarkFL View Post
In your second script, try this:

HTML Code:
<script type="text/javascript">
	var n = {vb:raw forum.threadcount};
	n = n.replace(/\,/g, '');
	n = parseInt(n, 10);
	document.write(fHcountHits(n));
</script>


I have tried it from this method, but without results, it directly does not return anything and with the second script that publishes it returns 1 when it detects a comma.

Any other solution ?.
Reply With Quote
  #4  
Old 05-24-2017, 05:00 AM
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Location: St. Augustine, FL
Posts: 3,853
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You would be better off doing this server side (PHP), rather than client side (javascript). For example, you could define your function by using a plugin hooked at "forumhome_start" with the code:

PHP Code:
function fHcountHits($num)
{
    switch (
$num)
    {
        case (
$num 1000000000):
            
$num round($num/10000000001);
            
$num .= 'G';
            break;
        case (
$num 1000000):
            
$num round($num/10000001);
            
$num .= 'M';
            break;
        case (
$num 1000):
            
$num round($num/10001);
            
$num .= 'K';
            break;
    }

    return 
$num;    

And then, create another plugin, this one hooked at "forumbit_display" with the code:

PHP Code:
$forum['threadcount'] = fHcountHits($forum['threadcount']);
$forum['replycount'] = fHcountHits($forum['replycount']); 
Reply With Quote
  #5  
Old 05-24-2017, 05:22 AM
RaYdeN.ADM's Avatar
RaYdeN.ADM RaYdeN.ADM is offline
 
Join Date: May 2006
Location: Los Angeles, CA (US)
Posts: 44
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I removed my javascript, left the raw default and did this:

plugin 1:


plugin 2:


forumhome:
Apparently it works, at least shows numbers, no counter exceeds 1000 so no wisdom really worked, but at the moment it shows the normal.

forumdisplay = subforum?:
Code:
Fatal error: Call to undefined function fHcountHits() in public_html/forum/includes/functions_forumlist.php(466) : eval()'d code on line 26

edit:

If I move the plugin 1 to global_start, it works, but look how it responds:

Reply With Quote
  #6  
Old 05-24-2017, 05:29 AM
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Location: St. Augustine, FL
Posts: 3,853
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

In order to get the same kind of thing happening on the forumdisplay page, you need to create 2 new plugins...one hooked at "forumdisplay_start" to contain the fHcountHits() function, and another at "threadbit display" with the code:

PHP Code:
$thread['views'] = fHcountHits($thread['views']); 
Just move that line from the one you put it in, to this plugin.
Reply With Quote
  #7  
Old 05-24-2017, 05:43 AM
RaYdeN.ADM's Avatar
RaYdeN.ADM RaYdeN.ADM is offline
 
Join Date: May 2006
Location: Los Angeles, CA (US)
Posts: 44
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

hmm so?:

plugin1 - main


plugin2 - hook1


plugin3 - hook2


now, forumhome error:
Code:
Fatal error: Call to undefined function fHcountHits() in /public_html/forum/includes/functions_forumlist.php(466) : eval()'d code on line 26
and subforum:











edit:

Sorry, I pass it to forumhome_start, also forumehome works and subforum stops working with the same error that the function is not declared.

On the other hand, although this stated does not do what it has to do.
Reply With Quote
  #8  
Old 05-24-2017, 05:53 AM
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Location: St. Augustine, FL
Posts: 3,853
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You need 4 plugins total...you are missing the function definition hooked at "forumhome_start"...

The function definition needs to be in 2 plugins.
Reply With Quote
Благодарность от:
RaYdeN.ADM
  #9  
Old 05-24-2017, 06:03 AM
RaYdeN.ADM's Avatar
RaYdeN.ADM RaYdeN.ADM is offline
 
Join Date: May 2006
Location: Los Angeles, CA (US)
Posts: 44
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by MarkFL View Post
You need 4 plugins total...you are missing the function definition hooked at "forumhome_start"...

The function definition needs to be in 2 plugins.
Ahh okey! XD

Well, the plugins and hooks already work. Now what is wrong for "0G" to write and the "1,"00" > "1200" > "1.2K" ?.. That do not work even if the 4 plugins are working.
Reply With Quote
  #10  
Old 05-24-2017, 06:12 AM
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Location: St. Augustine, FL
Posts: 3,853
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I would have to come to your site to sort it out...so if you want, PM the login credentials to a full admin account to me, and I will come by tomorrow and take a look. It is very late here.
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:50 PM.


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.08125 seconds
  • Memory Usage 2,295KB
  • 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
  • (2)bbcode_code
  • (2)bbcode_html
  • (5)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
  • (1)post_thanks_box_bit
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (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_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
  • 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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete