FUDAPI is a set of external calls that can be used to integrate applications with FUDforum.
To use the API, include the fudapi.inc.php script into your project. This script can be found inside the forum's scripts/ directory. You may need to modify the top of the fudapi.inc.php file to reference the correct location of GLOBALS.php. Once you've included the file you can just use the functions found within.
This API provides the following functions:
Some FUDAPI examples to get you started:
<?php require_once 'GLOBALS.php'; require_once 'scripts/fudapi.inc.php'; $cookie = $_COOKIE[ $GLOBALS['COOKIE_NAME'] ] or 0; $ses = _fud_simple_fetch_query(0, "SELECT * FROM {$GLOBALS['DBHOST_TBL_PREFIX']}ses WHERE ses_id = '$cookie'"); echo "Current login is ". fud_fetch_user($ses->user_id)->alias ."\n"; ?>
<?php require_once 'GLOBALS.php'; require_once 'fudapi.inc.php'; $ret = fud_fetch_online_users(); foreach ($ret as $item) { echo $item->alias; } ?>
<?php include_once 'GLOBALS.php'; include_once 'fudapi.inc.php'; echo "Newest user: ". fud_fetch_newest_user()->alias ."\n"; echo "Top poster: ". fud_fetch_top_poster()->alias ."\n"; ?>
<?php include_once 'GLOBALS.php'; include_once 'fudapi.inc.php'; $msg = fud_fetch_msg(1); echo "SUBJECT: ". $msg->subject ."\n"; echo "BODY: ". $msg->body ."\n"; ?>
<?php include_once 'GLOBALS.php'; include_once 'fudapi.inc.php'; $msgs = fud_fetch_recent_msg(1); // last 1 day. foreach($msgs as $msg) { echo 'SUBJECT: '. $msg->subject ."\n"; } ?>
<?php include_once 'GLOBALS.php'; include_once 'fudapi.inc.php'; $t = fud_fetch_full_topic(1); if (is_array($t)) { foreach($t as $m) { echo "SUBJECT: ". $m->subject .", USER: ". $m->login ."\n"; } } else { echo "SUBJECT: ". $t->subject .", USER: ". $t->login ."\n"; } ?>
<?php include_once 'GLOBALS.php'; include_once 'fudapi.inc.php'; $topics = _fud_msg_multi(1, "SELECT root_msg_id FROM ".$GLOBALS['DBHOST_TBL_PREFIX']."thread WHERE forum_id={ARG} ORDER BY id DESC LIMIT 10"); arsort($topics); foreach($topics as $topic) { echo "POSTER: ". $topic->login ."\n"; echo "SUBJECT: ". $topic->subject ."\n"; echo "BODY: ". $topic->body ."\n\n"; } ?>
<?php require_once 'GLOBALS.php'; require_once 'fudapi.inc.php'; fud_add_user( array('login'=>'me', 'passwd'=>'pass', 'email'=>'me@nowhere.com', 'name'=>'Me'), $err); var_dump($err); ?>
<?php require_once 'GLOBALS.php'; require_once 'fudapi.inc.php'; $u = _fud_simple_fetch_query(0, "SELECT * FROM {$GLOBALS['DBHOST_TBL_PREFIX']}users WHERE login = 'me'"); if (!empty($u->id)) fud_delete_user($u->id); ?>
<?php include_once 'GLOBALS.php'; include_once 'fudapi.inc.php'; $fh = fopen ('users.csv', 'r') or die('Could not open CSV file'); while (!feof($fh)) { $fields = fgetcsv($fh, 4096); $err = 0; $vals = array(); $vals['login'] = $fields[0]; $vals['passwd'] = $fields[1]; $vals['email'] = $fields[2]; $vals['name'] = $fields[3]; $vals['reg_ip'] = $fields[5]; $usid = fud_add_user($vals, $err); } fclose ($fh); ?>