vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Posts, replys & Views "counts" without comma? (https://vborg.vbsupport.ru/showthread.php?t=325131)

RaYdeN.ADM 05-24-2017 03:44 AM

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

MarkFL 05-24-2017 04:03 AM

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>


RaYdeN.ADM 05-24-2017 04:13 AM

Quote:

Originally Posted by MarkFL (Post 2586872)
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>


https://vborg.vbsupport.ru/external/2017/05/7.png

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 ?.

MarkFL 05-24-2017 05:00 AM

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


RaYdeN.ADM 05-24-2017 05:22 AM

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

plugin 1:
https://vborg.vbsupport.ru/external/2017/05/8.png

plugin 2:
https://vborg.vbsupport.ru/external/2017/05/9.png

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:

https://vborg.vbsupport.ru/external/2017/05/10.png

MarkFL 05-24-2017 05:29 AM

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.

RaYdeN.ADM 05-24-2017 05:43 AM

hmm so?:

plugin1 - main
https://vborg.vbsupport.ru/external/2017/05/11.png

plugin2 - hook1
https://vborg.vbsupport.ru/external/2017/05/12.png

plugin3 - hook2
https://vborg.vbsupport.ru/external/2017/05/13.png

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:
https://vborg.vbsupport.ru/external/2017/05/14.png










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.

MarkFL 05-24-2017 05:53 AM

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

The function definition needs to be in 2 plugins.

RaYdeN.ADM 05-24-2017 06:03 AM

Quote:

Originally Posted by MarkFL (Post 2586880)
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. :confused: :(

MarkFL 05-24-2017 06:12 AM

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. :)


All times are GMT. The time now is 06:40 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.01312 seconds
  • Memory Usage 1,766KB
  • 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
  • (2)bbcode_code_printable
  • (2)bbcode_html_printable
  • (5)bbcode_php_printable
  • (2)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