Class: VBulletin

VBulletin

vBulletin API

Extends

Methods

staticVBulletin.iframe_callbacks(target_origin, cookie_domains)

communicate from an iframe to the parent window

For security reasons, .login() cannot inject JavaScript into iframes in different origins. Instead, the calling code must arrange for this function to be called. It's sometimes useful to use VBulletin's no-cookie fallback mode (e.g. using the "trailing dot" domain on a site that hard-codes the cookie domain). Passing cookie_domain ensures cookies are deleted to resemble a cookieless browser
Name Type Description
target_origin string expected origin of the parent window
cookie_domains Array.<string> domains that cookies are normally set for (default: do not delete cookies)

inherited abstract,protected_add_standard_data(data){jQuery.Promise}

Add parameters required for standard POST requests

Name Type Description
data Object parameters passed to jQuery
Returns:
Type Description
jQuery.Promise deferred object that will return when all necessary parameters have been found

activity(){jQuery.Promise}

get recent threads/posts on the forum

Returns:
Type Description
jQuery.Promise

attachments_delete(attachments){jQuery.Promise}

delete an array of attachments

Name Type Description
attachments Array.<Object> attachment info, as returned from post_info()
Returns:
Type Description
jQuery.Promise

bbcode_html(thread_id, bbcode){jQuery.Promise}

Convert bbcode to HTML, for an existing thread

Name Type Description
thread_id Number ID of thread to post in
bbcode string text to convert
Returns:
Type Description
jQuery.Promise

bbcode_html_newthread(forum_id, bbcode){jQuery.Promise}

Convert bbcode to HTML, for a new thread in the specified forum

Name Type Description
forum_id Number ID of forum to post in
bbcode string text to convert
Returns:
Type Description
jQuery.Promise

inherited protectedbuild_url(url, valid_args, args, hash)

Convenience function to construct a URL

Name Type Description
url string base URL (e.g. "http://www.example.com/example.html")
valid_args Array.<Object> arguments that could be added to this URL
args Object.<string, string> arguments to add to the URL
hash string optional string added after the '#'
Example
// returns "/example.html?f=qux&b=default+value"
bb.build_url(
    '/example.html',
    [
        { key: 'foo', param: 'f' },
        { key: 'bar', param: 'b', default: 'default value' },
        { key: 'baz', param: 'bb' },
    ],
    { foo: 'qux' }
);

check_login(lazy){jQuery.Promise}

Check we're logged in, and update login credentials

you should only need set "lazy" for code that runs on a timer, potentially in many tabs. This stops people with many tabs open from spamming the server too often.
Name Type Description
lazy boolean optional only updating credentials if the session_timeout has elapsed
Returns:
Type Description
jQuery.Promise promise that returns when credential update succeeds or fails

add or change configuration values

Name Type Description
config Object new configuration values
Returns:
(updated) configuration

css_add(page_types)

add CSS for different page types to the current page

Sometimes we want to insert content that resembles one page on a different type of page (e.g the dashboard uses content from several pages). As vBulletin uses different CSS on different pages, we need to include the extra files by hand.
Name Type Description
page_types Array.<string> types of page to add CSS for

css_keys(){Object.<string, string>}

Get keys for use in building dynamic CSS

Bulletin board software often uses theme-specific values to control various bits of CSS. We retrieve those from the page, in a format compatible with Variables.parse()
Returns:
Type Description
Object.<string, string> CSS keys and values

date_parser(html, jqXHR){Date}

build a function to parse dates on a page

VBulletin often returns dates relative to "now", which depends on time zones, server error etc. To reliably parse dates, we need to get the server time from the HTTP headers.
Name Type Description
html string page contents
jqXHR jqXHR page XMLHttpRequest (to get the unambiguous server date)
Returns:
Type Description
Date date

inherited abstract,protecteddetect_post_error(reply)

Return the error string contained in a reply to post(), or null on success

Name Type Description
reply HTMLDocumentObject | XMLDocumentObject | string
string | null

editor_get(){string}

get the contents of the page's main edit box

Returns:
Type Description
string text contents

set the contents of the page's main edit box

Name Type Description
text string text to set

convert a relative URL to use the correct origin

BulletinBoards can have an origin other than the site we're currently on (so we can e.g. browse as one user and post as another)
Name Type Description
url string URL to translate
Returns:
Type Description
string absolute URL

folder_pms(folder_id){jQuery.Promise}

Get recent private messages in a folder

Name Type Description
folder_id Number folder to download
Returns:
Type Description
jQuery.Promise

forum_metadata(forum_id){jQuery.Promise}

Get metadata about a forum

Name Type Description
forum_id Number
Returns:
Type Description
jQuery.Promise

forum_threads(forum_id, recent){jQuery.Promise}

Get information about threads from the first page of a forum

Name Type Description
forum_id number ID of forum to get threads for
recent Boolean only download recently-changed threads (usually the past 24 hours)
See:
  • {thread_posts}
Returns:
Type Description
jQuery.Promise Deferred object that will return when all pages have loaded

forums(){jQuery.Promise}

Get a tree of forums on the site

Returns:
Type Description
jQuery.Promise Deferred object that will return when all pages have loaded

inherited protectedget(url, data){jQuery.Promise}

Send a message to the server as an AJAX request

Name Type Description
url string URL to get
data Object parameters
Returns:
Type Description
jQuery.Promise

inherited abstractget_pages(doc){Array.<number>}

Get the current and maximum page number

Name Type Description
doc string | jQuery | HTMLDocument document to get posts for
Returns:
Type Description
Array.<number> current and maximum page numbers, number of posts on the page

inherited abstractget_posts(doc){jQuery}

Get all documents on the specified page

Name Type Description
doc string | jQuery | HTMLDocument document to get posts for
Returns:
Type Description
jQuery list of posts

infraction_give(data){jQuery.Promise}

Give an infraction to a user

Name Type Description
data Object infraction information
Returns:
Type Description
jQuery.Promise
Example
bb.infraction_give({
    administrative_note: 'administrative note',
    ban_reason         : 'reason to show the user if the infraction triggers a ban',
    bbcode             : 'message body',
    user_id            : 1234, // must pass user_id or post_id
    post_id            : 2345,
    is_warning         : true,
    infraction_id      : 1
});

infraction_give_custom(data){jQuery.Promise}

Give an infraction to a user

Name Type Description
data Object infraction information
Returns:
Type Description
jQuery.Promise
Example
bb.infraction_give_custom({
    administrative_note: 'administrative note',
    reason             : 'ban reason to show the user',
    bbcode             : 'message body',
    user_id            : 1234, // must pass user_id or post_id
    post_id            : 2345,
    is_warning         : true,
    points             : 2, // number of infraction points to assign the user
    period             : 'M', // Months, Days etc.
    expires            : 3 // number of periods
});

infraction_ids(user_id){jQuery.Promise}

get the valid infractions IDs for a user

All users should have the same infractions available, but there's no API to retrieve infraction without a user ID. User ID 37 is high enough that it's unlikely to be a special un-infractable user, but low enough it's likely to exist. You should only need to pass a different ID if the above isn't true of your user #37
Name Type Description
user_id string optional ID of user to get (default: 37)
Returns:
Type Description
jQuery.Promise

ip_users(ip){jQuery.Promise}

get accounts used by an IP address

Name Type Description
ip string IP address to check
Returns:
Type Description
jQuery.Promise

login(iframe, default_user, hint)

log in to the site

This function pops up an iframe with login details for the main site. Note: for security reasons, the calling code must ensure that VBulletin.iframe_callbacks() is called in the iframe page. (this could be done automatically when logging in to the current site, but not when logging in to another domain)
Name Type Description
iframe jQuery iframe element to use
default_user String account to log in as
hint String hint to show the user
jQuery.Promise

login_auto(username, password)

log in to the site without user interaction

This function logs in automatically. If you need the user to type the password, use .login() instead.
Name Type Description
username String account to log in as
password String account password
jQuery.Promise

moderation_page(iframe, url, page_top_selector, page_bottom_selector)

log in to ModCP and get a URL

ModCP authentication is unrelated to normal site authentication, and it's easy to get logged out of one but stay in the other. This function pops up an iframe with login details if necessary.
Name Type Description
iframe jQuery iframe element to use
url string URL to get
page_top_selector string optional selector that indicates the top of the final page (default: '#cpform')
page_bottom_selector string optional selector that indicates the bottom of the final page (default: '.copyright')
jQuery.Promise

on_posts_modified(callback)

Monitor the list of posts
Name Type Description
callback function function to call when a post is modified

inherited parse(name, text){Object}

Retrieve a string previously encoded with .stringify()

Name Type Description
name string object name
text string post text
Returns:
Type Description
Object parsed object

inherited parse_post(name, post){Object}

Retrieve a string previously encoded with .stringify()

Name Type Description
name string object name
post Object post data returned from process_posts()
Returns:
Type Description
Object parsed object

inherited protectedping(var_args){jQuery.Promise}

Connect to the server and get some very basic information

the return value contains 'results ('success' or 'fail'), 'duration' (milliseconds taken for the round trip), and 'offset' (number of milliseconds the server is ahead of the client, which can be negative)
Name Type Description
var_args Object repeatable passed to $.get()
Returns:
Type Description
jQuery.Promise

pm_send(to, title, bbcode, request_receipt){jQuery.Promise}

Send a private message

Name Type Description
to string username(s) to send to
title string message title
bbcode string message body
request_receipt boolean optional whether to request a message receipt
Returns:
Type Description
jQuery.Promise

inherited protectedpost(url, data, use_form){jQuery.Promise}

Send a message to the server as either an AJAX request or a form

Name Type Description
url string URL to send to
data Object parameters to send
use_form boolean send a form requset instead of an AJAX request
Returns:
Type Description
jQuery.Promise

post_create(date, username, user_title, post_title, post_body_html){jQuery}

Create a new element that resembles a post
Name Type Description
date string text to show as the date
username string text to show as the user's name
user_title string text to show as the user's title (e.g. "moderator")
post_title string text to show as the post title
post_body_html string HTML to show as the post body
Returns:
Type Description
jQuery new post element

post_delete(post_ID, reason){jQuery.Promise}

Soft-delete a post

VBulletin supports hard-deleting posts (or just their attachments). We do not expose this functionality because there is no circumstance where a moderator would want to destroy their paper trail.
Name Type Description
post_ID Number ID of post to retrieve
reason string optional deletion reason
Returns:
Type Description
jQuery.Promise

post_edit(data){jQuery.Promise}

Change the contents of a post

Name Type Description
data Object
Returns:
Type Description
jQuery.Promise
Example
bb.post_edit({
    post_id: 123,
    bbcode : 'post [i]body[/i]',
    reason : 'reason for change', // optional, default: keep old reason
});

post_info(post_ID){jQuery.Promise}

Get information about a post (vBCode and attachment info)

Name Type Description
post_ID Number ID of post to retrieve
Returns:
Type Description
jQuery.Promise

post_report(post_id, bbcode, ajax_url){jQuery.Promise}

Report a post

Name Type Description
post_id Number ID of post to report
bbcode string report body
ajax_url string URL to return from AJAX request
Returns:
Type Description
jQuery.Promise

post_summary(post){string}

Get summary text for a post returned by process_posts()

Name Type Description
post Object post to summarise
Returns:
Type Description
string short summary

posts_moderated(){jQuery.Promise}

Get posts in the moderation queue

Returns:
Type Description
jQuery.Promise

posts_move(thread_id, post_ids)

move an array of posts to the specified thread

Name Type Description
thread_id Number destination thread ID
post_ids Array.<Number> posts to move

inherited abstractprocess_posts(posts){Array.<Object>}

Map a list of elements returned by get_posts() to data about the posts they represent

Name Type Description
posts jQuery list of post elements
Returns:
Type Description
Array.<Object> list of hashes describing each post

inherited quotes_process(text){Array.Object}

Map BBCode to a list of (non-nested) quotes

Note: supports vBCode's [quote=author;post_id] syntax
Name Type Description
text string BBCode to parse
Returns:
Type Description
Array.Object

redirect_modcp_ipsearch(params)

Redirect from the "moderation_ipsearch" page to the right page

We would like to link to the IP search page, but it needs various extra parameters for authentication and CSRF protection. This function redirects from the fake page to the real one.
Name Type Description
params Object page parameters

server_stats(){Object}

Statistics about the server running the bulletin board

Returns:
Type Description
Object one, five and fifteen minute load averages; total, logged-in and logged-out users online

spammer_delete(user_ID, post_ID){jQuery.Promise}

Ban a spambot and delete all their posts as spam

Name Type Description
user_ID Number ID of the user to ban
post_ID Number ID of the post that made you realise this was a spambot
Returns:
Type Description
jQuery.Promise

inherited stringify(name, object, cmp){string}

Escape an object in a way that's safe to put in a forum post

Name Type Description
name string object name
object Object object to stringify
cmp function comparison function
Returns:
Type Description
string text to include in a post

thread_bump(thread_ID){jQuery.Promise}

Bump a thread

Name Type Description
thread_ID Number ID of thread to bump
Returns:
Type Description
jQuery.Promise

thread_create(data){jQuery.Promise}

Create a new thread

Name Type Description
data Object
Returns:
Type Description
jQuery.Promise
Example
bb.thread_create({
    forum_id: 12,
     icon_id: 1,
    prefix  : 'some_prefix',
    title   : 'thread title',
    bbcode  : 'thread bbcode'
    close_thread: true, // optional, default: thread is open
    stick_thread: true, // optional, default: thread is not sticky
});

thread_debump(thread_ID){jQuery.Promise}

De-bump a thread

Name Type Description
thread_ID Number ID of thread to de-bump
Returns:
Type Description
jQuery.Promise

thread_delete(data){jQuery.Promise}

Delete thread

this soft-deletes a post - physically removing posts is not supported
Name Type Description
data Object
Returns:
Type Description
jQuery.Promise
Example
bb.thread_delete({
    thread_id: 123,
    reason   : 'reason for deletion',
});

thread_edit(data){jQuery.Promise}

Change thread metadata

Name Type Description
data Object
Returns:
Type Description
jQuery.Promise
Example
bb.thread_edit({
    thread_id       : 123,
    title           : 'post title',
    notes           : 'edit notes'
    icon_id         : 1, // optional
    prefix_id       : 1, // optional, default: no prefix
    close_thread    : true, // optional, default: open thread
    unapprove_thread: true, // optional, default: do not unapprove
    delete_thread   : true // optional, default: leave in current state
    delete_reason   : 'reason why thread was deleted',
});

thread_merge(data){jQuery.Promise}

Merge a set of threads together

Name Type Description
data Object
Returns:
Type Description
jQuery.Promise
Example
bb.thread_merge({
    forum_id  : 12,
    thread_ids: [ 123, 234, 345 ],
    url       : '/foo.php' // optional, default: post with AJAX to avoid page load
});

thread_metadata(thread_id){jQuery.Promise}

Get metadata about a thread

Name Type Description
thread_id Number
Returns:
Type Description
jQuery.Promise

thread_move(data){jQuery.Promise}

Move a thread from one forum to another

Name Type Description
data Object
Returns:
Type Description
jQuery.Promise
Example
bb.thread_move({
    thread_id     : 123,
             title: 'new thread title',
    redirect_title: 'thread title for redirect',
    forum_id      : 12,
    redirect      : { period: 1, frame: 'w' }, // see parse_duration()
    url           : '/foo.php' // optional, default: post with AJAX to avoid page load
});

thread_openclose(thread_id, open){jQuery.Promise}

Open or close a thread

Note: this is guaranteed to perform the desired action, whereas thread_reply() suffers from race conditions
Name Type Description
thread_id Number ID of thread to open or close
open boolean whether the thread status should be set to "open" (instead of "closed")
Returns:
Type Description
jQuery.Promise

inherited thread_posts(thread_id, doc, skip_images){jQuery.Promise}

Get information about posts from many pages in a thread

We need to get a single page first, to work out the number of pages in the thread. Passing in that first page will make the function return faster, and will cause only pages after that one to be loaded.
Name Type Description
thread_id number ID of thread to get posts for
doc string | jQuery | HTMLDocument document to get posts for
skip_images boolean convert all images to - significantly improves performance
Returns:
Type Description
jQuery.Promise Deferred object that will return when all pages have loaded

thread_reply(data){jQuery.Promise}

Create a new reply in a thread (AJAX)

Note: 'flip_thread_openness' suffers from a race condition - when two people flip the state at the same time, it cancels out. See thread_openclose for a safer solution.
Name Type Description
data Object
Returns:
Type Description
jQuery.Promise
Example
bb.thread_reply({
    thread_id           : 123,
    title               : 'post title', // optional, default: no title
    bbcode              : 'post [i]body[/i]',
    flip_thread_openness: false,
    url                 : '/foo.php' // optional, default: post with AJAX to avoid page load
}).then(function(new_post_id) {
    ...
});

thread_title(thread)

Get the title of a thread

Name Type Description
thread string | HTMLElement thread to get page for (default: current page)
Returns:
string

thread_whoposted(thread_id){jQuery.Promise}

Get the list of posters in a thread

Note: this is quite inefficient for threads with over 2,500 posts
Name Type Description
thread_id Number ID of thread to check
Returns:
Type Description
jQuery.Promise

threads_complete(substring){Array.<Object>}

suggest possible completions given a partial thread title

Name Type Description
substring string partial thread title
Returns:
Type Description
Array.<Object> list of thread titles and IDs

threads_recent(substring){Array.<Object>}

list recent threads with at least one reply, sorted by reply count

Name Type Description
substring string partial thread title
Returns:
Type Description
Array.<Object> list of thread titles and IDs

url_decode(url){Object}

convert a URL to the parameters needed to build it

The return value contains the following: * type - the main object of the URL (e.g. "user" or "thread") * subtype - the specific page type (see url_for for a list) * args - arguments to url_for.()
Name Type Description
url string URL to convert
Returns:
Type Description
Object e.g. { type: 'user', url_for: 'user_show', args: { user_id: 1234 } }

user_ban(user, reason, group_id){jQuery.Promise}

Ban a user

Name Type Description
user string name of user to ban
reason string reason to show the user
group_id string set the user to this group
Returns:
Type Description
jQuery.Promise
Example
bb.infraction_give({
    username: 'user name',
    group_id: 123, // set the user to this group
    reason  : 'reason to show user',
    period  : 'M', // Months, Days etc.
    expires : 3 // number of periods
});

user_current(){Object}

Get information about the current user

Returns:
Type Description
Object username and user_id

inherited user_duplicates(user_id){jQuery.Promise}

get information about the specified account and suspected duplicate accounts

Name Type Description
user_id Number user ID
Returns:
Type Description
jQuery.Promise promise
Example
bb.get_duplicates(1234)
    .progress( completed, total )
    .then(function(user) {
        console.log( user.suspiciousness, user.suspected_duplicates ); // see user_moderation_info() for details on users
    });

user_info(user_id){jQuery.Promise}

Get information about a user from their member page

Name Type Description
user_id Number ID of user to gather information about
Returns:
Type Description
jQuery.Promise

user_ips(user, get_overlapping){jQuery.Promise}

get IP addresses used by an account

Note: "overlapping" users includes people that share the same house, share an ISP which uses dynamic IP addresses, or just happen to have used the same router one time.
Name Type Description
user Object user to check (must contain "username" or "user_id")
get_overlapping boolean whether to also return the list of other accounts using those IPs
Returns:
Type Description
jQuery.Promise

user_moderation_info(user_id){jQuery.Promise}

Get information about a user from ModCP

Name Type Description
user_id Number ID of user to gather information about
Returns:
Type Description
jQuery.Promise

user_notes(user_id){jQuery.Promise}

Get user notes for a user

Name Type Description
user_id Number ID of the user
Returns:
Type Description
jQuery.Promise

user_overlapping(username){jQuery.Promise}

get users that have used the same IP address

Note: This includes any use of the same address (registration or posting)
Name Type Description
username string user to check
Returns:
Type Description
jQuery.Promise

user_posts(user_id, get_all_pages){jQuery.Promise}

Get posts for a user

Name Type Description
user_id Number ID of user to get posts for
get_all_pages Boolean whether to download results on pages after the first
Returns:
Type Description
jQuery.Promise

user_signature_get(user_id){jQuery.Promise}

Get user's signature user from ModCP

Name Type Description
user_id Number ID of user to get signature for
Returns:
Type Description
jQuery.Promise

user_signature_set(user_id, signature){jQuery.Promise}

Set user's signature user through ModCP

Name Type Description
user_id Number ID of user to set signature for
signature string new signature text
Returns:
Type Description
jQuery.Promise

usernote_add(user_id, title, bbcode){jQuery.Promise}

Add a note to a user's account

Name Type Description
user_id string ID of note recepient
title string message title
bbcode string message body
Returns:
Type Description
jQuery.Promise

usernote_edit(note_id, title, bbcode){jQuery.Promise}

Change the contents of a user note

Name Type Description
note_id string ID of the note
title string message title
bbcode string message body
Returns:
Type Description
jQuery.Promise

usernote_info(note_id){jQuery.Promise}

Get information about a user note

Name Type Description
note_id string ID of the note
Returns:
Type Description
jQuery.Promise

users_complete(prefix){Array.<Object>}

suggest possible completions given a partial user name

Name Type Description
prefix string partial user name
Returns:
Type Description
Array.<Object> list of user names and IDs

users_list_new(){jQuery.Promise}

Get new users

Returns:
Type Description
jQuery.Promise

inherited when(promises){jQuery.Promise}

Sane wrapper around $.when()

$.when() has several problems: - it wants a variadic list of arguments - it has a different return syntax when passed a single item than many - does not notify on completion of individual promises This workalike solves those issues.
Name Type Description
promises Array.<jQuery.Promise> array of promises to wait for
Returns:
Type Description
jQuery.Promise return values from each promise