Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 General Discussions

Reply
 
Thread Tools Display Modes
  #21  
Old 12-04-2014, 10:57 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by KGodel View Post
With JSON you can get the contents on other sites. This is how many Streaming service APIs work. It's simply an ordered list. They keep it updated, whereas if I were to create one it'd be edited every time. I considered switching the keys and such but meh, I'm not sure how much it will make a difference.

I did switch to array_search though.
I think you're right, it's a relatively small array so it won't make a lot of difference. And that json thing is cool, I hadn't really seen that before.

Not to criticize the other guys who are being helpful, but I didn't want to rewrite all your code for you because you didn't ask. But one thing I think I would do is change the function so it only gets the array once and saves it in a static or a global variable. That way at least you aren't getting it from a remote server once for each post.

Edit : BTW, there's also a function that swaps keys and values, but I can't remember what that one's called either.
Reply With Quote
  #22  
Old 12-04-2014, 11:01 PM
ozzy47's Avatar
ozzy47 ozzy47 is offline
 
Join Date: Jul 2009
Location: USA
Posts: 10,929
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Or you can write a cron job, t get it once a day, or weekly, then save that in a static or a global variable.
Reply With Quote
Благодарность от:
kh99
  #23  
Old 12-04-2014, 11:31 PM
vBNinja's Avatar
vBNinja vBNinja is offline
 
Join Date: May 2011
Location: USA
Posts: 239
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by KGodel View Post
With JSON you can get the contents on other sites. This is how many Streaming service APIs work. It's simply an ordered list. They keep it updated, whereas if I were to create one it'd be edited every time. I considered switching the keys and such but meh, I'm not sure how much it will make a difference.

I did switch to array_search though.
Im pretty sure everyone here knows how json works. I would create a cron or fetch it on demand but I see no point in this situation since it is countries and i don't think a country is added/removed as often
Another thing to think about is what happens if the server you're fetching from is down? Well so will your "plugin"
Reply With Quote
Благодарность от:
ozzy47
  #24  
Old 12-04-2014, 11:33 PM
ozzy47's Avatar
ozzy47 ozzy47 is offline
 
Join Date: Jul 2009
Location: USA
Posts: 10,929
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yup, that is why I suggested getting the info in a cron.
Reply With Quote
  #25  
Old 12-04-2014, 11:46 PM
KGodel's Avatar
KGodel KGodel is offline
 
Join Date: May 2011
Location: Indiana
Posts: 332
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Do I simply need to define a global variable in the cron itself and save it?
Reply With Quote
  #26  
Old 12-05-2014, 01:05 AM
nerbert nerbert is offline
 
Join Date: May 2008
Posts: 784
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

If you can get it into the form of a php array you could serialize it and store it in datastore. Is it available as such an array? I could get some code for storing in datastore.

Also, did you see my post in the country flags thread? I have small flags for all countries. Not sure how up to date it is though
Reply With Quote
  #27  
Old 12-05-2014, 01:20 AM
KGodel's Avatar
KGodel KGodel is offline
 
Join Date: May 2011
Location: Indiana
Posts: 332
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I was able to get a set that matches the list pretty well. I can get the array and serialize it yes.
Reply With Quote
  #28  
Old 12-05-2014, 01:31 AM
nerbert nerbert is offline
 
Join Date: May 2008
Posts: 784
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

To store in datastore
Code:
require_once(DIR . '/includes/functions.php');
build_datastore('countries', serialize($countries), 1);

You need a plugin in "init_startup"
Code:
if(THIS_SCRIPT == 'showthread') // or whatever file reads the array
{
	$datastore_fetch[] = "'countries'";
}
Then the array should be available as $vbulletin->countries

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

Quote:
Originally Posted by kh99 View Post
Edit : BTW, there's also a function that swaps keys and values, but I can't remember what that one's called either.
array_flip()

http://www.w3schools.com/php/func_array_flip.asp
Reply With Quote
Благодарность от:
KGodel
  #29  
Old 12-05-2014, 06:18 PM
KGodel's Avatar
KGodel KGodel is offline
 
Join Date: May 2011
Location: Indiana
Posts: 332
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I decided to save the codes to a DB where I can add/edit as I please. Is there a way to get them as you did in the init_startup without using datastore, or by using datastore some other way? Right now I have:

PHP Code:
if(THIS_SCRIPT == 'showthread') {

        
$sql "SELECT * FROM " TABLE_PREFIX "countrycodes";
        
$result $db->query_read_slave($sql);
        
        while (
$c mysql_fetch_array($result) {
            
$countries[$c[0]] = $c[1];
        }
    } 
Reply With Quote
  #30  
Old 12-05-2014, 08:35 PM
nerbert nerbert is offline
 
Join Date: May 2008
Posts: 784
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well, I think init_startup is as good a place to run your SELECT query as any (provided it's not too early, before the connection to the database is created), but showthread_start would work too. Theoretically you can edit the contents of datastore but it's stored as a compressed blob that's hard to read.

As for your flag images have you considered a country flag sprite? I'm working on converting a project to use sprites instead of images. There are several such sprites open source to download.
Reply With Quote
Reply

Thread Tools
Display Modes

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 05:22 PM.


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.06716 seconds
  • Memory Usage 2,269KB
  • Queries Executed 11 (?)
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
  • (1)bbcode_php
  • (3)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
  • (3)pagenav_pagelink
  • (10)post_thanks_box
  • (3)post_thanks_box_bit
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (3)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_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