Forum URL: markawes.vforums.co.il
Experienced By: Mark Me Hi
Browser: Fire fox 3![]()
Operating System: Windows Vista Home Premium Edition yeah![]()
Problem: Are we allowed to have a board on our forum like you have that streams information to our website? apparently PB dont allow this so i was wondering if you do?
See now i have the API thing enabled on my forum but never knew what it did even though u put the wireless key to our hub as the codeill have a look but im guessing ill be back for help.
![]()
Thank you for your quick reply.
That is all done via the API interface
http://support.vforums.us/board/api
The API allows you to collect information (such as a news feed) and then output it however you want.
ive had a look at the board an im compuzzled, do i copy the php script and upload it to my server?
http://support.vforums.us/board/api/topic/8740/action/view_t opic/api-source-code
Sorry to jump in on this thread but... I thought it was vforums.co.uk not vforums.us![]()
and I am assuming that yeah you do have to upload to your own host.
@ Darkmage - both work!![]()
Ahh I see, So us means United States? I guess I learned something new this morning!![]()
The php script cannot be found on the server when i try and download it from that topic
Here's the php code which our news feed uses
Code:
- <?php
- include_once('vforums_api.php'); // This is the "Source" file
- $vf = new vforums_api('www.support.virtualforums.co.uk', 'API KEY / PASSWORD');
- $news_items = $vf -> request("api/recent/board/BOARDID/max/3/allow_all/1");
- $count = 0;
- if(!is_array($news_items)) {
- $news_items = Array();
- $news_items[0] = Array(
- "description" => "",
- "subject" => "Support Forum/API Offline",
- "message" => "This website is unable to connect to the Support Forums API interface. This may be due to scheduled maintenance or a server error. We hope to have everything back online as soon as possible.",
- "timestamp" => time()
- );
- }
- foreach($news_items as $news) {
- $news_link = explode("|", $news['description']);
- if($count > 0) {
- ?>
- <br />
- <br />
- <br />
- <?php
- }
- ?>
- <h2 class="news_title"><?=htmlspecialchars($news['subject']);?></h2>
- <div class="news_body">
- <?=preg_replace("/&(\s)/", "& ", $news['message']);?>
- </div>
- <div class="news_info">
- <div class="news_date">
- Posted on: <?=gmdate("jS M Y", $news['timestamp']);?>
- </div>
- <?php
- if(isset($news_link[1])) {
- $link_prefix = preg_match("/(board\/|http:\/\/)/", $news_link[0])? (preg_match("/http:\/\//", $news_link[0])? "" : "http://support.virtualforums.co.uk/") : "http://support.virtualforums.co.uk/board/announcements/topic/";
- ?>
- <div class="news_link">
- Read More: <a href="<?=$link_prefix . $news_link[0];?>"><?=htmlspecialchars($news_link[1]);?></a>
- </div>
- <?php
- }
- ?>
- </div>
- <?php
- $count++;
- }
- ?>
Also, I have fixed the download link. And as pointed out, any of the domain names work (virtualforums.co.uk, vforums.co.uk, vforums.us)
Thanks Ross, ive done this what i think i need to do is it correct?#
Code:
- <?php
- /****************
- vForums API Interface
- Release 0.0.1
- Updated 14.04.2008
- ****************/
- class vforums_api {
- var $api_forum;
- var $api_key;
- var $api_user;
- var $api_pass;
- function vforums_api($forum, $key) {
- if($forum && $key) {
- $this -> api_key = $this -> encode($key);
- $this -> api_forum = str_replace('http://', '', $forum);
- // Fix common errors
- ini_set('memory_limit', '128MB');
- ini_set('pcre.backtrack_limit', 100000000);
- ini_set('pcre.recursion_limit', 100000000);
- return true;
- }
- return false;
- }
- function encode($str) {
- return urlencode($str);
- }
- function login_user($user = 'www.markawes.vforums.co.uk', $pass = '2caecb2ce2') {
- // Validate & Login User
- if(isset($_POST[$user]) && isset($_POST[$pass])) {
- $this -> api_user = $this -> encode($_POST[$user]);
- $this -> api_pass = $this -> encode($_POST[$pass]);
- $encrypted = 0;
- } else {
- $this -> api_user = (isset($_COOKIE[$user]))? $this -> encode($_COOKIE[$user]) : false;
- $this -> api_pass = (isset($_COOKIE[$pass]))? $this -> encode($_COOKIE[$pass]) : false;
- $encrypted = 1;
- }
- if($this -> api_user && $this -> api_pass) {
- $user_information = $this -> request("api/profile/encrypted/$encrypted");
- if(isset($user_information['password'])) {
- if(!$encrypted) {
- $login_time = time() + (60 * 60 * 24);
- $password = addslashes($user_information['password']);
- $username = addslashes($user_information['user_name']);
- header("Set-Cookie: $pass=$password; expires=". date("D, d-M-Y H:i:s T", $login_time) ."; path=/; HTTPonly;", false);
- header("Set-Cookie: $user=$username; expires=". date("D, d-M-Y H:i:s T", $login_time) ."; path=/;", false);
- }
- return $user_information;
- }
- $this -> api_user = $this -> api_pass = false;
- }
- return false;
- }
- function request($request) {
- if(!$this -> api_forum || !$this -> api_key) {
- return "vForums API has not been initiated";
- }
- if(is_array($request)) {
- // Construct URL from array \w URL encoding
- $request_temp = "";
- foreach($request as $r) {
- if(!empty($request_temp))
- $request_temp .= "/";
- $request_temp .= $this->encode($r);
- }
- $request = $request_temp;
- }
- $request .= "/key/" . urlencode($this -> api_key);
- if($this -> api_user) {
- $request .= "/username/" . $this -> api_user;
- }
- if($this -> api_pass) {
- $request .= "/password/" . $this -> api_pass;
- }
- // Post to Server
- $header = "GET /$request HTTP/1.0\r\n";
- $header .= "HOST: ".$this -> api_forum."\r\n";
- $header .= 'Content-Type: application/x-www-form-urlencoded\r\n';
- $header .= "Content-Length: " . strlen($request) . "\r\n\r\n";
- $fp = fsockopen ($this -> api_forum, 80, $errno, $errstr, 30);
- if (!$fp) {
- return "Could not initiate connection to the forum.";
- } else {
- fputs ($fp, $header);
- $headerdone = false;
- $data = '';
- while (!feof($fp)) {
- $line = fgets ($fp, 1024);
- if (strcmp($line, "\r\n") == 0) {
- $headerdone = true;
- } else if ($headerdone) {
- $data .= $line;
- }
- }
- }
- // Construct Result
- $results = unserialize($data);
- if(empty($results))
- return $data;
- return $results;
- }
- }
- ?>
bump
Hi Mark.
That code is what I'd recommend as saving and uploading as a seperate file to your server. I tend to always call it "vforums_api.php" as shown in the news example. By keeping this code as a seperate file you can use that same core code for multiple sections and if you ever need to update it then it is all in one place.
The news feed example I posted then uses this vforums_api.php file and uses the code within it to connect to your forum and fetch the requested information.