vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=187)
-   -   [How-To] vBulletin API Basics: Variables, Functions, Objects (https://vborg.vbsupport.ru/showthread.php?t=98047)

akanevsky 10-09-2005 10:00 PM

[How-To] vBulletin API Basics: Variables, Functions, Objects
 
vBulletin API Basics: Variables, Functions, Objects

This How-To should serve as a reference to coders, who have a basic knowledge of PHP and who want to make their own mods.

$vbulletin (Type: Object)

Contains vBulletin data that has been in separate variables in vB 3.0.x.
Below you can find a translation table of changed variables and functions.
This is an expanded version of the list that you can find in vBulletin's source code (functions_legacy.php).
vBulletin 3.0.3 locations are on the left hand side, and the corresponding vBulletin 3.5.0 locations are on the right hand side.
Legacy locations can be enabled by running legacy_enable(), although this is officially not recommended for long term compatibility.

Code:

* $vboptions['x']                            --> $vbulletin->options['x']
* $iforumcache                              --> $vbulletin->iforumcache
* $forumcache                                --> $vbulletin->forumcache
* $usergroupcache                            --> $vbulletin->usergroupcache
* $datastore['wol_spiders']                  --> $vbulletin->wol_spiders
* $smiliecache                              --> $vbulletin->smiliecache
* $stylechoosercache                        --> $vbulletin->stylecache
* $datastore['x']                            --> $vbulletin->x
* $bbuserinfo['x']                          --> $vbulletin->userinfo['x']
* $session['x']                              --> $vbulletin->session->vars['x']
*
* $_BITFIELD['usergroup']                    --> $vbulletin->bf_ugp
* $_BITFIELD['usergroup']['x']              --> $vbulletin->bf_ugp_x
* $_BITFIELD['usergroup']['x']['y']          --> $vbulletin->bf_ugp_x['y']
* $_BITFIELD['calmoderatorpermissions']['x'] --> $vbulletin->bf_misc_calmoderatorpermissions['x']
* $_BITFIELD['moderatorpermissions']['x']    --> $vbulletin->bf_misc_moderatorpermissions['x']
* $_BITFIELD['languageoptions']['x']        --> $vbulletin->bf_misc_languageoptions['x']
* $_USEROPTIONS['x']                        --> $vbulletin->bf_misc_useroptions['x']
* $_FORUMOPTIONS['x']                        --> $vbulletin->bf_misc_forumoptions['x']
* $_INTPERMS                                --> $vbulletin->bf_misc_intperms
* $_INTPERMS['x']                            --> $vbulletin->bf_misc_intperms['x']
*
* ------------------------------------------------------------------------------
* Variables and Functions below are NOT affected/re-enabled by legacy_enable()
* ------------------------------------------------------------------------------
*
* $_GET/$_POST/$_REQUEST/$_COOKIE/$_FILES    --> $vbulletin->GPC['x']
* $DB_Site->x()                              --> $vbulletin->db->x()
* $url                                      --> $vbulletin->url
* $nozip                                    --> $vbulletin->nozip
* $script                                    --> $vbulletin->script
* $scriptpath                                --> $vbulletin->scriptpath
*
* HTML_SELECTED                              --> not defined anymore in vB 3.5
* HTML_CHECKED                              --> not defined anymore in vB 3.5
*
* bbcode_parse()                            --> $bbcode_parser->parse
* iif($condition, $r_true, $r_false)        --> obsolete, use ($condition ? $r_true : $r_false) instead;

Please note the following:
  1. $vbulletin
    Inside of object classes, you should access $vbulletin->[...] as $this->registry->[...]. Therefore, use that structure when modifying code inside of any classes.
    .
  2. VARIABLES ENABLED FOR TEMPLATES
    $vboptions['x'], $bbuserinfo['x'] and $session['x'] do work in the template system without running legacy_enable().
    .
  3. SUPERGLOBALS
    $_GET/$_POST/$_REQUEST/$_COOKIE/$_FILES/$_SERVER/$_ENV are available anywhere, but generally you should avoid using them. Instead, "clean" those variables and place them into $vbulletin->GPC using $vbulletin->input->clean_gpc() and $vbulletin->input->clean_array_gpc() methods.
    You can read more about these two "cleaning" methods here.

    As a summary:
    1. Use $vbulletin->input->clean_gpc() for a single variable, and $vbulletin->input->clean_array_gpc() for arrays.
    2. After variables are patched through, they can be accessed using $vbulltin->GPC (which is an array).
    3. Cleaning 'somevar' will not create variable $somevar.
    4. $vbulletin->input->clean_gpc() returns the clean value, therefore the following code will work out nicely:

      Code:

      $id = $vbulletin->input->clean_gpc('r', 'id', TYPE_UINT);

    Once you get to know the syntax of those functions, you can use the following as a reference:

    Code:

    ------------------------------------
    SOURCES AND THEIR EQUIVALENTS
    ------------------------------------

    'g'                    - $_GET
    'p'                    - $_POST
    'r'                    - $_REQUEST
    'c'                    - $_COOKIE
    's'                    - $_SERVER
    'e'                    - $_ENV
    'f'                    - $_FILES

    ------------------------------------
    VALID DATA TYPES
    ------------------------------------

    TYPE_BOOL              - Boolean
    TYPE_INT              - Integer
    TYPE_UINT              - Unsigned Integer
    TYPE_NUM              - Floating Point Number
    TYPE_UNUM              - Unsigned Floating Point Number
    TYPE_UNIXTIME          - Unix Timestamp (Unsigned Integer)
    TYPE_STR              - Trimmed String (No leading or trailing whitespace)
    TYPE_NOTRIM            - String
    TYPE_NOHTML            - Trimmed String sent through htmlspecialchars_uni()
    TYPE_ARRAY            - Array
    TYPE_FILE              - File
    TYPE_NOCLEAN          - Unvalidated

  4. GLOBALIZING VARIABLES IN FUNCTIONS
    Since most of the variables can be found within the $vbulletin class, there is generally no need to globalize more than one variable (which is $vbulletin). An exception would be the $vbphrase array, which currently cannot be found within the $vbulletin class.

    Taking the above account, the following code is not good:

    Code:

    function foo()
    {
        global $forumcache, $vbulletin, $vboptions;

        $forumcache =& $vbulletin->forumcache;
        $vboptions =& $vbulletin->options;

        foreach ($forumcache AS $forumid => $forum)
        {
            if ($vboptions['something'])
            {
                // do stuff
            }
        }
    }

    Instead, you should use the following code (which is, obviously, shorter and easier to use):

    Code:

    function foo()
    {
        global $vbulletin;

        foreach ($vbulletin->forumcache AS $forumid => $forum)
        {
            if ($vbulletin->options['something'])
            {
                // do something
            }
        }
    }

  5. DATASTORE ITEMS
    In vBulletin 3.0.x you could commonly see the following code:

    PHP Code:

    if (isset($datastore_item)) 

    Unfortunately, this does not work in vBulletin 3.5.0, since the datastore items are now contained within $vbulletin class.
    You need to use the following code instead:

    PHP Code:

    if ($vbulletin->datastore_item !== null

  6. BITFIELDS
    In case you have been wondering, "ugp" stands for "UserGroup Permissions".
    To avoid the confusing "$object->array[key1][key2][key3][key4]...[key10]" stuff, there are references set up that allow you to talk to deep elements quickly. For example, $vbulletin->bf_ugp_adminpermissions is a reference to $vbulletin->bf_ugp['adminpermissions'].
    .
  7. BBCODE PARSE
    BBCode Parser has changed slightly in vBulletin 3.5.
    To familiarize yourself with the new syntax, check out KirbyDE's How-To.
    .
  8. MISCELLANEOUS
    It is impossible to list here every aspect of vBulletin code, therefore you should familizarize yourself with the contents of init.php and class_core.php before beginning to hack into the system (and I know you are in a rush ;)).

$db (Type: Object)

As you might have judged from the Table 1 in this tutorial, the database object in vB3.5 is $vbulletin->db.
However, $db is another way to access that object; it is the way that used everywhere unless you call it from within a function. In functions, use $vbulletin->db.
Obviously, the purpose of the database method is to perform various operations on the database. Most common methods are described below.
  • $db->query();
    Deprecated in favor of below methods (to save memory).
    Returns: MySQL Resource
    .
  • $db->query_read();
    Performs SELECT and SHOW operations only.
    These queries will execute on the slave server, if one is defined.
    Returns: MySQL Resource
    .
  • $db->query_write();
    Performs INSERT, REPLACE, UPDATE, DROP, ALTER and other data-modifying queries.
    These queries will execute on the master server.
    Returns: MySQL Resource
    .
  • $db->query_first();
    Same as query_read(), but returns first result as an array.
    Returns: array on success / boolean false on failure
    .
  • $db->num_rows($mysql_resource_var);
    Input: A MySQL resource variable (usually output of the first three methods).
    Returns: int Amount of Resulting Rows
    .
  • $db->fetch_array($mysql_resource_var);
    Input: A MySQL resource variable (usually output of the first three methods).
    Returns: array One row from the mysql results on success / boolean false on failure

    To fetch each row consecutively, use the following code:

    Code:

    while ($var = $db->fetch_array($mysql_resource_var))
    {
            // your code ($var contains the array);
    }

  • $db->insert_id();
    Input: None.
    Returns: int Row ID of the latest INSERT operation.
    .
  • $db->escape_string(); and $db->escape_string_like();
    Input: String.
    Returns: string A string with appropriate characters escaped.

    These two functions must be used instead of the PHP built-in addslashes() and addslashes_like().
    Using the PHP built-in functions may cause problems on non-MySQL systems.
    .
  • $db->show_errors(); and $db->hide_errors();
    Input: None.
    Returns: None.

    The first function enables sql error output (default), whereas the second function disables such output.
    Useful when you do not want the script to die on error (example: no die on product installation if a table already exists).

Data Managers

Data Managers (DMs) are an interface to various data objects used within vBulletin. They enforce necessary constraints and administrator-set options on the data to ensure that the data is valid.
You can read more about Data Managers in vBulletin's online manual.
Also, you can read specifically about the User DM in this KirbyDE's How-To, and about Thread DM here.

Authentication Storage

The authentication data is stored in the following way (thank to Kirby for this info):

$_COOKIE:
{cookiepfx}userid - plain(userid)
{cookiepfx}password - md5(md5(md5('PlaintextPassword') . salt) . 'LicenseNo').

TABLE user:
password - md5(md5('PlaintextPassword') . salt)

Note that for cookie, {cookiepfx} is your board's cookie prefix. It is configurable via admincp and is accessible via the COOKIE_PREFIX constant.

Important Functions
  • construct_page_nav($pagenumber, $perpage, $results, $address, $address2 = '');

    Returns the HTML for multi-page navigation.
    Two latest arguments are not used yet, therefore they are not documented.

    Code:

    $pagenumber        int    Total number of items found
    $perpage        string  Base address for links eg: showthread.php?t=99{&page=4}
    $results        string  Ending portion of address for links

  • eval(standard_error(fetch_error('error_phrase')));

    Outputs a standard error message with a phrase of your choice.
    fetch_error looks up the phrase you specify in the "Front-End Error Messages" phrase category.
    Error phrases must be prefixed with "error_".
    .
  • print_standard_redirect($redir_phrase, $doquery = true, $forceredirect = false);

    Returns eval()-able code to initiate a standard redirect
    $vbulletin->url should contain the target url for the redirect.

    Code:

    $redir_phrase        string  Name of redirect phrase
    $doquery        boolean  If true, it will fetch $redir_phrase from "Front-End Redirect Messages" phrase category. Must be prefixed with "redirect_".
                            If false, it will use the value of $redir_phrase as the phrase itself.
    $forceredirect  boolean  Should generally be set to true.

  • is_valid_email($email);

    Checks an email for validity and returns true or false.
    .
  • can_moderate($forumid = 0, $do = '', $userid = -1, $usergroupids = '');

    Checks whether a user can moderate a certain forum.

    Code:

    $forumid      int      Specific forum to check. If not set, will check whether the user is a moderator of any forum at all.
    $do            string    Specific mod action to check. If not set, will check whether the user is a moderator of the forum specified in $forumid.
    $userid        int      User ID to check. If not set, will use $vbulletin->userinfo.
    $usergroupids  string    List of group IDs, separate by commas, to which the user belongs. Should be generally left blank.

  • can_administer();

    Checks whether or not the visiting user has administrative permissions

    This function can optionally take any number of parameters, each of which
    should be a particular administrative permission you want to check. For example:
    can_administer('canadminsettings', 'canadminstyles', 'canadminlanguages')
    If any one of these permissions is met, the function will return true.
    If no parameters are specified, the function will simply check that the user is an administrator.
    .
  • convert_bits_to_array(&$bitfield, $_FIELDNAMES);

    Converts a bitfield into an array of 1 / 0 values based on the array describing the resulting fields. Returns an array.

    Code:

    &$bitfield      int      (ref) Bitfield
    $_FIELDNAMES    array    Array containing field definitions - array('canx' => 1, 'cany' => 2, 'canz' => 4) etc.

  • function convert_array_to_bits(&$arry, $_FIELDNAMES, $unset = 0);

    Takes an array and returns the bitwise value.

    Code:

    &arry          array    Array for input.
    $_FIELDNAMES    array    Array containing field definitions - array('canx' => 1, 'cany' => 2, 'canz' => 4) etc.
    $unset          int      Defines whether to unset the array data once it has been converted to bits

  • fetch_template($templatename, $escape = 0, $gethtmlcomments = true);

    Returns a single template from the templatecache or the database.

    Code:

    $templatename    string  Name of template to be fetched
    $escape          int      Escape quotes in template? 1: escape; -1: unescape; 0: do nothing
    $gethtmlcomments boolean  Wrap template in HTML comments showing the template name?

    Two most common uses are:

    Code:

    eval('$mycustomvar .= "' . fetch_template('mycustomtemplate') . '";');
    eval('print_output("' . fetch_template('mycustomtemplate') . '");');

  • vbsetcookie($name, $value = '', $permanent = true);

    Sets a cookie based on vBulletin environmental settings.

    Code:

    $name          string    Cookie name
    $value          mixed    Value to store in the cookie
    $permanent      boolean  If true, do not set an expiry date for the cookie

  • vb_number_format($number, $decimals = 0, $bytesize = false, $decimalsep = null, $thousandsep = null);

    Formats a number with user's own decimal and thousands chars and returns the formatted number.

    Code:

    $number          mixed    Number to be formatted: integer / 8MB / 16 GB / 6.0 KB / 3M / 5K / ETC
    $decimals        integer  Number of decimal places to display
    $bytesize        boolean  Special case for byte-based numbers
    $decimalsep      string    Custom decimal separator (to override user's preference)
    $thousandsep    string    Custom thousands separator (to override user's preference)

  • vbmail($toemail, $subject, $message, $notsubscription = false, $from = '', $uheaders = '', $username = '');

    Starts the process of sending an email - either immediately or by adding it to the mail queue.

    Code:

    $toemail          string    Destination email address
    $subject          string    Email message subject
    $message          string    Email message body
    $notsubscription  boolean    If true, do not use the mail queue and send immediately
    $from            string    Optional name/email to use in 'From' header
    $uheaders        string    Additional headers
    $username        string    Username of person sending the email

Sources Used

>> EOD

Kusadasi-Guy 10-10-2005 07:00 PM

this is my first subscribed thread (no email notifications).
in other way, i bookmarked.

Thank You so much, DV!

UK Jimbo 10-10-2005 10:20 PM

very handy. thanks.

waza 10-12-2005 06:31 PM

Excellent!!

Deviation 10-16-2005 12:15 AM

NICE work Dark Visor. :D

Xtrm2Matt 10-16-2005 12:29 PM

Very nice! Bookmarking for future references :)

Great job.

Matt

akanevsky 10-20-2005 09:28 PM

Thanks everyone for feedback.

Tutorial has been updated with two pairs of emendations to the $db class documentation:
- $db->escape_string(); + $db->escape_string_like();
- $db->show_errors(); + $db->hide_errors();

keithl 11-02-2005 05:22 AM

Brilliant - I've actually bookmarked this thread. Why do Jelsoft make it so bloody difficult for people? I've been looking for some simple software documentation on this type of thing and it's just "not provided".

Many thanks, keep up the good work!

Keith L

eXtremeTim 11-02-2005 05:57 PM

Not bad young grasshoper. Not bad at all. :)

akanevsky 11-02-2005 06:01 PM

Quote:

Not bad young grasshoper. Not bad at all.
Of course ;)

eXtremeTim 11-02-2005 09:40 PM

Quote:

Originally Posted by Dark Visor
Of course ;)

I dont need the reference but I will definally pass it on to people im working on training. Since I do php training and vbulletin training for new coders.

akanevsky 11-02-2005 11:30 PM

Quote:

Originally Posted by eXtremeTim
I dont need the reference but I will definally pass it on to people im working on training. Since I do php training and vbulletin training for new coders.

No problem, except don't reprint it anywhere...
Pass it on as a link to this thread.

eXtremeTim 11-03-2005 08:27 PM

Quote:

Originally Posted by Dark Visor
No problem, except don't reprint it anywhere...
Pass it on as a link to this thread.

You dont have to worry about me reprinting it. :)

If I was gonna have a vbulletin 3.5 change tutorial on my site I would definatly make my own.

akanevsky 11-03-2005 08:37 PM

Quote:

If I was gonna have a vbulletin 3.5 change tutorial on my site I would definatly make my own.
By plagiarising this tutorial? No... I'd prefer that, if you want, reprint it on your site via copy-and-paste method, but leave me my credits and a link to this thread :P Thanks

Lea Verou 11-13-2005 01:30 AM

Quote:

Originally Posted by Psionic Vision
By plagiarising this tutorial? No... I'd prefer that, if you want, reprint it on your site via copy-and-paste method, but leave me my credits and a link to this thread :P Thanks

Ermm sorry but if I were extremeTim I would get offended with that comment of yours...

Anyway thanks for the great tutorial :)

akanevsky 11-13-2005 01:47 AM

Quote:

Ermm sorry but if I were extremeTim I would get offended with that comment of yours...
Yes, hmm, I misread this "If I was gonna have a vbulletin 3.5 change tutorial on my site I would definatly make my own."... but unfortunately, too late.

Quote:

Anyway thanks for the great tutorial
NP :)

Lea Verou 11-13-2005 01:55 AM

I need to make a query (from the table user) that returns an array and the key of the array would be the userid and the value would be the value of another field in the database (eg referrerid).
For example if the array is $array and the users with userid 100, 200, 300 have a referrerid of 1,1 and 50 respectively that array should have the values $array[100]=1 $array[200]=1 $array[300]=50

Is that hard? How can I do it without adding many queries?
Thanks a lot in advance :)

edit: [offtopic] OMG I just saw you are 16!!! Wow! I'd never had expected that! I thought you were about 25+! OMG, most 16 year olds in Greece do not know how an opening tag of php is and generally they only care about playing games... Of course there are exeptions, like my bf which is in that age but still there is a huge difference... OMG, I still can't believe it! [/offtopic]

Nevermind, I figured out another way to get the results I wanted :)

akanevsky 11-13-2005 02:25 AM

That could be done with just one query. :)

PHP Code:

$getusers $db->query_read("SELECT userid, referrerid  FROM " TABLE_PREFIX "user WHERE userid IN (100, 200, 300)");

 while (
$userinfo $db->fetch_array($getusers))
 {
     
$referrer_array["$userinfo[userid]"] = $userinfo['referrerid'];
 }

 print(
"<pre>");
 
print_r($referrer_array);
 print(
"</pre>"); 

This code is not tested but should be working properly.

Quote:

[offtopic] OMG I just saw you are 16!!! Wow! I'd never had expected that! I thought you were about 25+! OMG, most 16 year olds in Greece do not know how an opening tag of php is and generally they only care about playing games... Of course there are exeptions, like my bf which is in that age but still there is a huge difference... OMG, I still can't believe it! [/offtopic]
That's right, I am 16 :)

EDIT:

Quote:

Nevermind, I figured out another way to get the results I wanted
:( (lol)... How did you do it?

Lea Verou 11-13-2005 02:30 AM

Something similar but WAY more messy than yours :o

However the 100,200,300 where just examples, in an actual forum it should go through all the userids :)
Well, that's not very hard to change, I'll just put instead of your WHERE a WHERE referrerid>0 (cause I want it to only return the users with a referrer) :)

Thanks so much!! That's much more organized than my code. I'm still trying to figure out how those SQL things work, it's quite hard :nervous:

edit: And it works too! Woo hoo!! :D Thanks, thanks, thanks!!! :D :D :D

akanevsky 11-13-2005 02:35 AM

np, and what are you trying to make, if it's not a secret? :)

Lea Verou 11-13-2005 02:38 AM

I'm trying to make a mod to display referrer statistics, so that a forum can have referrer contests etc. I've seen this requested many times in the modification requests and I would also like it for my forum. :)
I have lots of learning to do though in order to make it, but I'm determined :p :p

akanevsky 11-13-2005 02:42 AM

Quote:

Originally Posted by Michelle
I'm trying to make a mod to display referrer statistics, so that a forum can have referrer contests etc. I've seen this requested many times in the modification requests and I would also like it for my forum. :)
I have lots of learning to do though in order to make it, but I'm determined :p :p

Ah, great, I remember back in 2.3.x days there was a "vbStats 230.b created by Bane for Talkloud.NET" hack, but that project was abandoned (or at least it is not free anymore). Even though I PM-ed them many times :(... Then I forgot about it, but now if you going to make it, that'd be great, and I'll gladly help you :)

EDIT:

Yes, I thought so. They have it, but they do not release it anymore:
http://www.talkloud.net/forums/vbsta...on=memberrefer :(

Lea Verou 11-13-2005 02:48 AM

Thanks so much!!! :D
How can I ask you if I have a question? In this thread or via pm? :nervous:
I wish I could code for hours today, I am really eager to do it but I have a trip so I have to start packing in about an hour, so I'll continue working at night when I arrive (it's 6:46 in the morning here) :)
Anyway, when I really want to make something I can sit at the computer for hours till I make it, lol :p I made smilie maker in one night and for my (low) level of knowledge that's an achievement :p

Quote:

Originally Posted by Psionic Vision
Yes, I thought so. They have it, but they do not release it anymore:
http://www.talkloud.net/forums/vbsta...on=memberrefer :(

That's really mean of them. :(
Anyway mine will be better :p

OMG I am totally insane! :p
I postponed my trip 5 hours so I can work at the script! LOOOOOOOOOOL!!! :p

akanevsky 11-13-2005 11:17 AM

Quote:

How can I ask you if I have a question? In this thread or via pm?
It's better via PM or even AIM, so as not to clutter up this thread :)

Quote:

Anyway, when I really want to make something I can sit at the computer for hours till I make it, lol
Same here. :)

Quote:

Anyway mine will be better
Nice attitude :)

Quote:

I postponed my trip 5 hours so I can work at the script!
Wow. Hopefully it wasn't a business trip or an interview appointment lol.

Update:
Added "Authentication Storage" section, based on a random Kirby's post that I've found.

FamilyCorner 11-14-2005 03:36 PM

I hope someone here can help me :( I have a hack that stopped working after upgrading to 3.5.1. I have already made the change for "db" from "DB_site", but this page seems to still be having a problem:
http://www.familycorner.com/forums/contest.php3

You will see if you scroll down to where it says "Posts Today" in a purple box that the total number of posts are missing. This is what the post count is calling from:

PHP Code:

<?php 
while ($user $db->fetch_array($users)) 

$username $user["username"]; 
echo (
"$username<br>"); 

echo (
"<br>"); 
while (
$user $db->fetch_array($admin)) 

$username $user["username"]; 
echo (
"$username<br>"); 

?> 
<br> 
</font> 
</td> 
<td align="center"> 
<FONT face="verdana,verdana" size="2"> 
<br> 
<?php 
$db
->data_seek(0,$users); 
while (
$user $db->fetch_array($users)) 

$count $user["count"]; 
echo (
"$count<br>"); 

echo (
"<br>"); 
$db->data_seek(0,$admin); 
while (
$user $db->fetch_array($admin)) 

$count $user["count"]; 
echo (
"$count<br>"); 

?>

What else do I need to change from the old version code to update it to work on 3.5.1?

THANK YOU!

Sorry, I should have posted this as well. This code is at the top of the page, just under the body tag:

PHP Code:

<?php
$date1 
"UNIX_TIMESTAMP(\"2005-11-10\")";
$date2 "UNIX_TIMESTAMP(\"2005-11-11\")";

$users $db->query(
"SELECT post.userid, count(post.userid) as count, user.username from " .
"post, user WHERE post.dateline >= $date1 and post.dateline <= $date2 " .
"and post.userid = user.userid and user.username <> 'Dawn' group ".

"by post.userid order by count DESC");
$admin $db->query(
"SELECT post.userid, count(post.userid) as count, user.username from " .
"post, user WHERE post.dateline >= $date1 and post.dateline <= $date2 " .
"and post.userid = user.userid and user.username = 'Dawn' group ".
"by post.userid order by count DESC");

 
?>

and this is at the very top of the page, before the HTML tag:

PHP Code:

<?php require("global.php3"); ?>


vietkieu_cz 02-05-2006 08:24 AM

Some screenshot please?

bairy 03-08-2006 09:06 PM

Not exactly related to the first post but some things I find very very useful when coding.

At the bottom of includes/functions.php I have the following:

PHP Code:

function pre($var) {
    if (
$_SERVER['REMOTE_ADDR'] == 'xxx.xxx.xxx.xxx' or $_SERVER['REMOTE_ADDR'] == '127.0.0.1') {
        echo 
"<pre>";
        
print_r($var);
        echo 
"</pre><br />";
    }
}

function 
echoa($var) {
    if (
$_SERVER['REMOTE_ADDR'] == 'xxx.xxx.xxx.xxx' or $_SERVER['REMOTE_ADDR'] == '127.0.0.1') echo $var;
}

class 
microtimer {
// Starts, Ends and Displays Page Creation Time
   
function getmicrotime() {
       list(
$usec$sec) = explode(" "microtime());
       return ((float)
$usec + (float)$sec);
   }
   
   function 
s() {
   
$this->st $this->getmicrotime();
   }
       
   function 
e() {
       
$this->et $this->getmicrotime();
       if (
$_SERVER['REMOTE_ADDR'] == 'xxx.xxx.xxx.xxx' or $_SERVER['REMOTE_ADDR'] == 'xxx.xxx.xxx.xxx') echo round(($this->et $this->st), 6);
   }
}
$tm = new microtimer

where xxx.xxx.xxx.xxx is your internet IP and 127.0.0.1 is if you have an installation on your pc.

All of the above were taken off user comments at php.net


Usages:
PHP Code:

pre($var);

e.gpre($vbulletin->userinfo); 

This will print_r a variable in a formatted way (print_r is a php function that outputs the value of variables, good for arrays).
Extremely useful for seeing what vB knows at any point, especially if you need to call some of that data. A tip: don't pre($vbulletin), it's really messy.

PHP Code:

echoa $var

Does what echo $var does, but as you can see from the code, it only shows you so it doesn't disrupt the board.

PHP Code:

$tm->s(); 

and
PHP Code:

$tm->e(); 

This is a microtimer, put the s() just before the code you want to time, and the e() after, and it will echo the time it took in seconds. Change the 6 to control the number of decimal places. So:
PHP Code:

$tm->s();
for (
$i=0;$i 1000000$i++) {
  
$tmp 1;


That will tell you how long it takes the system to assign a value to a variable 1 million times (I got 0.35secs on a 2.4ghz P4, if anyone cares).


These are all bound to your IP or localhost to save unnecessary outputting to the board.

DrewM 06-15-2006 07:43 PM

Quote:

$db->mysql_insert_id();
Input: None.
Returns: int Row ID of the latest INSERT operation.
this isn't right it's $db->insert_id();

akanevsky 06-15-2006 07:57 PM

Thank you for pointing that out. Corrected.

Antivirus 06-16-2006 08:30 PM

Thanks for taking the time to put this together anthony, i have been using it as a reference quite frequently.

akanevsky 06-16-2006 08:33 PM

Yup. :)

Ninth Dimension 08-23-2006 03:49 PM

Quote:

Originally Posted by Psionic Vision
Authentication Storage

The authentication data is stored in the following way (thank to Kirby for this info):

$_COOKIE:
{cookiepfx}userid - plain(userid)
{cookiepfx}password - md5(md5(md5('PlaintextPassword'), salt), 'LicenseNo').

TABLE user:
password - md5(md5('PlaintextPassword'), salt)

Note that for cookie, {cookiepfx} is your board's cookie prefix. It is configurable via admincp and is accessible via the COOKIE_PREFIX constant.

Hi, I believe you have an error in the above code, where you've put
Code:

md5(md5('PlaintextPassword'), salt)
I believe it should say
Code:

md5(md5('PlaintextPassword'). 'salt')
I.e. what the script does it takes the plain password, md5()s it, the adds the salt to the end, then md5()s it again. At least that is what i think it does in vB 3.6.0..

I'd be keen on getting some clarification on this, cheers :D

akanevsky 08-24-2006 01:13 AM

I got that from Kirby's post and haven't actually verified the information, but you are most likely correct.

Adrian Schneider 08-24-2006 01:19 AM

Yep you need a . instead of , otherwise things will go horribly wrong.

akanevsky 08-24-2006 01:30 AM

Quote:

Yep you need a . instead of , otherwise things will go horribly wrong.
Thank you. May I ask why you are not responding to my private message over at your site?

vietkieu_cz 10-01-2006 04:34 PM

Hi Psionic Vision, do you know what do I wrong?

Here is the code:
PHP Code:

$query $db->query_read("SELECT title FROM thread WHERE forumid = 2 ASC");
while (
$hienthithreads $db->fetch_array($query))
{
    
$hienthithreads[title] = $hienthithreads[title];


And how do I do to show Selected Threads on forum?

Thank you

akanevsky 10-01-2006 04:39 PM

Quote:

$query = $db->query_read("SELECT title FROM thread WHERE forumid = 2 ASC");
ASC cannot be there alone without ORDER BY something before it. You can either remove ASC or write ORDER BY title DESC.

Second question - don't know, sorry. Post in modification questions please.

hotwheels 10-02-2006 12:05 AM

holy cow, how did i miss this thread.............

mike.fro 05-12-2008 12:20 AM

Any updates for 3.7 on this article? Looking to get some documentation as I am trying to write a hack but am completely stumped when it comes to vBulletin and writing hacks for it.

Antivirus 05-14-2008 12:51 AM

most of the stuff herein still applies to 3.7


All times are GMT. The time now is 10:48 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.01960 seconds
  • Memory Usage 1,979KB
  • 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
  • (18)bbcode_code_printable
  • (13)bbcode_php_printable
  • (20)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
  • (40)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