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

Reply
 
Thread Tools Display Modes
  #1  
Old 08-13-2008, 12:04 PM
veenuisthebest's Avatar
veenuisthebest veenuisthebest is offline
 
Join Date: Mar 2008
Location: India
Posts: 1,416
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Few general vb coding queries

I have a custom vb page.php that has many subpages like do=this and do=that and accesses database in every sub-page. Now my queries in relation to page.php are:-


1. I use $db->free_result($query); every time I use SELECT query to fetch multiple rows. But when, where and why is $db->close(); used ?

2. I want to add one setting to ENABLE/DISABLE access to page.php, how do I do that? I know how to add settings, but what next ? I want to display an error message on page.php when set to DISABLED, but let admins view it. (almost similar to the forums turn off or arcade.php turn off feature)

3. This is a simple INSERT query:-

PHP Code:
$db->query_write("
    INSERT INTO " 
TABLE_PREFIX "linkdir
        (name, email, ip)
    VALUES
        ('
$name', '$email', '$ip')
"
); 
This gives an error when escape characters are inserted like ', /, etc. How do I allow escape characters to be inserted in all the columns? Is this $vbulletin->db->escape_string_like(htmlspecialchars_uni($variable )) the only solution ?

4. What is the difference between `" . TABLE_PREFIX . "mytable` and " . TABLE_PREFIX . "mytable (notice the ` symbol)

5. To display a standard redirect, we use this:-

PHP Code:
$vbulletin->url "page.php?" $vbulletin->session->vars['sessionurl'] ."$row_id";
  if (isset(
$_SERVER['QUERY_STRING'])) {
eval(
print_standard_redirect('redirect_myphrase'truetrue));} 
What variable should be put in place of $row_id ? If $row_id contains 10, then the URL becomes page.php?10 , It does not create any problem but it doesn't look good. What should I put in there when I do NOT need to pass anything onto the next page? Also, how does vb redirects user to previous page?

6. Why is it considered a good practise to use vbphrases in templates and not direct text. Say, in the template for my page.php there is just one phrase that won't be repeated like "Welcome to our Page", can I just write it directly in the template without creating a vbphrase ?

7. I am inserting current TIMESTAMP into mytable from page.php, how do I make it show in the vbstyle? I mean, how to automatically correct it according to per user timezone setting? and leave it default for guests.


I hope someone takes out time to answer these, it will help many others I think.

Thank You
Reply With Quote
  #2  
Old 08-13-2008, 01:04 PM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

1. Not sure, personally I have never used it.
2. Add a vBulletin option setting then use PHP like:
PHP Code:
if(!$vbulletin->option['pageenable'] AND is_member_of($vbulletin->userinfo6))
{
    
// Bla bla

3. You should be using the vBulletin input cleaner, use the TYPE_NOHTML type to automatically use htmlspecialchars() there is an article about it in Articles section. Then use $db->escape_string(); on them there is an article about it in the Articles section, check it out.

4. There isn't much, some people prefer to enclose column/table names in backticks. Sometimes useful if you use a reserved MySQL word for a name (though you shouldn't really do this).

5. Just remove it from the $vbulletin->url variable...
PHP Code:
$vbulletin->url "page.php?" $vbulletin->session->vars['sessionurl']; 
6. So people can create their own translations, for what you have written, if they need to. (This way they can run more then 1 language on the same board).

7. When converting from TIMESTAMP to a "text date" e.g. "3rd Aug", the vbdate() function should automatically factor in timezones.
Reply With Quote
  #3  
Old 08-13-2008, 01:26 PM
veenuisthebest's Avatar
veenuisthebest veenuisthebest is offline
 
Join Date: Mar 2008
Location: India
Posts: 1,416
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

1. Okay (but still need to know coz I have seen it at few places)

2. This means my whole code in page.php would be wrapped with this ?? like below:-

PHP Code:
if(!$vbulletin->option['pageenable'] AND is_member_of($vbulletin->userinfo6))
{
if(empty(
$_REQUEST['do'])) 
{
     
# Go to a default catch all
     
$_REQUEST['do'] = 'main';
}

if(
$_REQUEST['do'] == 'main') {
  
// Main page code
}

if(
$_REQUEST['do'] == 'sub1') {
  
// sub page 1 code...

}
if(
$_REQUEST['do'] == 'sub2') {
  
// sub page 2 code...

}
//and so on..
}
else
{
eval(
standard_error(fetch_error('error_sorry_noaccess')));

Is this correct ??

3. Okay, I'll check it out

4. So, is it okay to NOT to use backticks ?

5. Ah.. why I didn't thought of that .. thanks

6. So, if I'm not using any other language, is it okay to NOT to use phrases at all for simple text ?

7. See, I am inserting current time in this format $TIMESTAMP=date('jS \of F, Y h:i:s A'); , and simply retrieving it. It shows time in GMT to all. Can you please give an example of this on how to use vbdate().

Thank You so much
Reply With Quote
  #4  
Old 08-13-2008, 02:20 PM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

1. Check the articles section for the thread about using the vBulletin Database Class

2. No give them a no permission error. or some message:
PHP Code:
if(!$vbulletin->option['pageenable'] AND !is_member_of($vbulletin->userinfo6))

    
print_no_permission();

4. I doesn't really make much difference. I prefer to use them, but vBulletin never does in its SQL commands

6. If it is just for your own board then its up to you. Personally I keep it in a phrase so I can edit it easier, instead of editing a template I just edit a phrase. If you are release the product as a modification you should use phrases.

7. A timestamp is a number (google: "Unix Timestamp" for info about it). What you wrote there is a date/time not a timestamp. Use the TIMENOW constant to fetch the timestamp when a script is executing, insert that into your database not the date() thing. When you fetch the timestamp from the database then you use vbdate/date function.
PHP Code:
$date vbdate('jS \of F, Y h:i:s A'$row['timestamp']); 
Reply With Quote
  #5  
Old 08-13-2008, 02:58 PM
veenuisthebest's Avatar
veenuisthebest veenuisthebest is offline
 
Join Date: Mar 2008
Location: India
Posts: 1,416
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

1. okay, got this in articles:-

Quote:
- function close

Usage within vBulletin: $DB_site->close();

Runs native php function: mysql_close();

Closes connection to database server, in most cases this is called automatically by php when the script is done executing


And thank you so much for the rest !! Will come up with more queries later . Thanks
Reply With Quote
  #6  
Old 08-14-2008, 03:06 PM
veenuisthebest's Avatar
veenuisthebest veenuisthebest is offline
 
Join Date: Mar 2008
Location: India
Posts: 1,416
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks for answering all my above 7 queries. I have understood each one of them.
Few more things:-

8. Whenever we create a setting for our product, it is available globally at $vbulletin->options['var-name']; and we can use this option anywhere as it would be available throughout our site i.e. in all pages. Am I correct?

If yes, then I wanted to know, if suppose we are having 100 products installed with 10 settings each, will there be 1000 unnecessary variables lying in the memory? How can I restrict a setting to be available only to a specific page.php and must not be available on any other vbpage.

9. Also, in relation to above, how do I use the setting variable in the associated template? Say I want to display a link from the template if the option is enabled in the product otherwise not.

10. I have read about vbulletin input cleaner. But can someone please explain me, when to use TYPE_STR and when TYPE_NOHTML coz I am able to achieve what i want from both and both allow $db->escape_string

11. vB uses this code to redirect to any location (in our case page.php), how do I redirect to previous page that user accessed?

PHP Code:
$vbulletin->url "page.php" $vbulletin->session->vars['sessionurl'];
  if (isset(
$_SERVER['QUERY_STRING'])) {
eval(
print_standard_redirect('redirect_linkdir'truetrue));} 

Thank You
Reply With Quote
  #7  
Old 08-15-2008, 04:14 PM
veenuisthebest's Avatar
veenuisthebest veenuisthebest is offline
 
Join Date: Mar 2008
Location: India
Posts: 1,416
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

waiting for reply plz..
Reply With Quote
  #8  
Old 08-15-2008, 09:15 PM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

8. Yes (but use "_" (underscore) instead of "-" (hyphen)). No you can't restrict to single page.

9. Just use <if> conditions....

10. TYPE_STR allows HTML, TYPE_NOHTML does not allow HTML (it uses htmlspecialchars() basically). $db->escape_string is not related to input, you use it escape strings that you insert into the database. It will change " to \" e.t.c.
Reply With Quote
  #9  
Old 08-19-2008, 12:35 PM
veenuisthebest's Avatar
veenuisthebest veenuisthebest is offline
 
Join Date: Mar 2008
Location: India
Posts: 1,416
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

thank you for so much help uptill now..

Few more things please:-

12. vB has a system of putting things in moderation queue and then wait for moderator's approval to show them publicly.
It would be pretty easy to do so by taking input from user and inserting the records in a temporary table and then after reviewing let mods move them to the main table. But, is this the same way vB does this? How do I create a notification sort of for achieving that thing ?

13. Also, how does vB sends emails to users? Is it the same old php mail() function? Can I use the same in my page.php? or there is a better way to do it off vB?
Reply With Quote
  #10  
Old 08-19-2008, 02:35 PM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

12. It is done by a status column in the post table (visible).

13. Yes the old mail() function with a small wrapper around it: vbmail().
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:55 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.09224 seconds
  • Memory Usage 2,291KB
  • 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
  • (8)bbcode_php
  • (1)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
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (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
  • 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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete