FUDAPI

From FUDforum Wiki
Jump to: navigation, search

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.

Functions

This API provides the following functions:

  • fud_fetch_msg($message_id)
  • fud_fetch_recent_msg($days=1)
  • fetch_fetch_msg_by_user($poster_id)
  • fud_fetch_full_topic($thread_id)
  • fud_fetch_topic($thread_id)
  • fud_fetch_poll($poll_id)
  • fud_fetch_attachment($att_id)
  • fud_fetch_forum($forum_id)
  • fud_fetch_cat($cat_id)
  • fud_fetch_cat_forums($forum_id)
  • fud_forum_stats()
  • fud_fetch_online_users()
  • fud_fetch_user($user_id)
  • fud_fetch_newest_user()
  • fud_fetch_random_user()
  • fud_fetch_top_poster()
  • fud_add_user($vals, &$err)
  • fud_update_user($uid, $vals, &$err)
  • fud_new_topic($subject, $body, $mode, $author, $forum, $icon=null, $attach=null, $poll=null, $time=null, $tdescr=null)
  • fud_new_reply($subject, $body, $mode, $author, $rep_id, $icon=null, $attach=null, $poll=null, $time=null)
  • fud_update_message($subject, $body, $mode, $author, $mid, $icon=null, $attach=null, $poll=null)
  • fud_delete_msg($message_id)
  • fud_delete_topic($thread_id)
  • fud_delete_poll($poll_id)
  • fud_delete_attachment($att_id)
  • fud_delete_user($user_id)

Examples

Some FUDAPI examples to get you started:

  • Get current login:
<?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";
 ?>
  • List all logged-in users on the forum:
<?php
 require_once 'GLOBALS.php';
 require_once 'fudapi.inc.php';
 $ret = fud_fetch_online_users();
 foreach ($ret as $item) {
    echo $item->alias;
 }
 ?>
  • Fetch the newest member and top poster:
<?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";
 ?>
  • Fetch a message from the forum:
<?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";
 ?>
  • List all messages posted during the past 24 hours:
<?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";
 }
 ?>
  • Display all messages belonging to a particular topic:
<?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";
 }
 ?>
  • A more complicated example displaying the last 10 topics (without replies) from a particular forum for your site's news page:
<?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";
 }
 ?>
  • Add a new user to the forum:
<?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);
 ?>
  • Remove a forum user:
<?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);
 ?>
  • Add a list of users from a CSV file:
<?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);
 ?>

Also see

Languages
Personal tools
This is a cached copy of the requested page, and may not be up to date.

Sorry! This site is experiencing technical difficulties.
Try waiting a few minutes and reloading.

(Can't contact the database server: Cannot return last error, no db connection)


You can try searching via Google in the meantime.
Note that their indexes of our content may be out of date.