View Full Version : Few general vb coding queries
veenuisthebest
08-13-2008, 12:04 PM
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:-
$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:-
$vbulletin->url = "page.php?" . $vbulletin->session->vars['sessionurl'] ."$row_id";
if (isset($_SERVER['QUERY_STRING'])) {
eval(print_standard_redirect('redirect_myphrase', true, true));}
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
Opserty
08-13-2008, 01:04 PM
1. Not sure, personally I have never used it.
2. Add a vBulletin option setting then use PHP like:
if(!$vbulletin->option['pageenable'] AND is_member_of($vbulletin->userinfo, 6))
{
// 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...
$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.
veenuisthebest
08-13-2008, 01:26 PM
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:-
if(!$vbulletin->option['pageenable'] AND is_member_of($vbulletin->userinfo, 6))
{
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_noacc ess')));
}
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
Opserty
08-13-2008, 02:20 PM
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:
if(!$vbulletin->option['pageenable'] AND !is_member_of($vbulletin->userinfo, 6))
{
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.
$date = vbdate('jS \of F, Y h:i:s A', $row['timestamp']);
veenuisthebest
08-13-2008, 02:58 PM
1. okay, got this in articles:-
- 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
veenuisthebest
08-14-2008, 03:06 PM
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?
$vbulletin->url = "page.php" . $vbulletin->session->vars['sessionurl'];
if (isset($_SERVER['QUERY_STRING'])) {
eval(print_standard_redirect('redirect_linkdir', true, true));}
Thank You
veenuisthebest
08-15-2008, 04:14 PM
waiting for reply plz..
Opserty
08-15-2008, 09:15 PM
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.
veenuisthebest
08-19-2008, 12:35 PM
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?
Marco van Herwaarden
08-19-2008, 02:35 PM
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().
veenuisthebest
08-24-2008, 12:18 PM
14. Just curious to know, why has vb changed functions like mail to vbmail, date to vbdate and so on. What is the difference in the two?
15. By following this article (https://vborg.vbsupport.ru/showthread.php?t=98009), I was able to create online locations for my vbpage via plugins. I wanted to know, how do I make it so that it shows a different location for sub-pages as well.
Like, if a person is viewing page.php?do=edit , then it should display the correct location and not the location of page.php
Thank You
Marco van Herwaarden
08-24-2008, 01:34 PM
14. To see the difference, have a look at these functions in the ./includes/functions.php file.
15. Make sure the usergroup of the user browsing the WOL has permission to view detailed locations.
veenuisthebest
08-25-2008, 12:18 PM
14. Thank You.. It did helped me.
15. Ofcourse the permissions are all set to YES. See this is my code
Hook: online_location_process
if ($filename == 'page.php')
{
$userinfo['activity'] = 'Viewing Page';
}
if ($filename == 'page.php?do=edit')
{
$userinfo['activity'] = 'Editing Page';
}
Hook: online_location_unknown
if ($userinfo['activity'] == 'Viewing Page')
{
$userinfo['action'] = 'Viewing Page';
$handled = true;
}
if ($userinfo['activity'] == 'Editing Page')
{
$userinfo['action'] = 'Editing Page';
$handled = true;
}
Now... my problem is that even on viewing page.php?do=edit , it shows "Viewing Page" INSTEAD OF "Editing Page" at whos online !
Thank You
Opserty
08-25-2008, 12:45 PM
How about:
if ($filename == 'page.php' AND $_REQUEST['do'] == 'edit')
{
$userinfo['activity'] = 'Editing Page';
}
elseif ($filename == 'page.php')
{
$userinfo['activity'] = 'Viewing Page';
}
veenuisthebest
08-25-2008, 01:36 PM
I had put the above code in online_location_process hook but its still showing "Viewing Page" for page.php?do=edit
by the way, can the reason be that my actual subpage is page.php?do=edit&uid=$row_id
Any other way pleasee.. ?
veenuisthebest
08-27-2008, 10:48 AM
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?
$vbulletin->url = "page.php" . $vbulletin->session->vars['sessionurl'];
if (isset($_SERVER['QUERY_STRING'])) {
eval(print_standard_redirect('redirect_linkdir', true, true));}
15. How do I create online locations for my sub-pages. Solution in post #14 (https://vborg.vbsupport.ru/showpost.php?p=1606513&postcount=14) doesn't work for me.
16. After reading Send PMs (automatically) (https://vborg.vbsupport.ru/showthread.php?t=82786), it was easy to send PM's. Just have a few queries, what does $pmdm->set_info('is_automated', true); AND cache_permissions($fromuser, false); does ? coz I can't see any difference with/without them.
veenuisthebest
08-30-2008, 03:06 PM
One more plz:-
17. How do we use vbmail function in our page? I think there's something wrong in my code as I am getting very late mails OR not getting them at all. The other default mailing functions are working perfect i.e. I receive mails instantly when using contact us or any other email function but only not through my custom page.
$emailto = "email@email.com";
$subject = "my email subject";
$message = "my message body";
vbmail($emailto, $subject, $message, false, $vbulletin->options['webmasteremail'], '', $row_name);
veenuisthebest
09-02-2008, 07:36 AM
anyone ??
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.