As of 4/4/2013
This class has now been updated and posted here: http://www.daniweb.com/web-development/php/code/451674/all-in-one-daniweb-api-class#
ORIGINAL POST
This code can be used to retrieve a forum list with various options with regard to display. This class could be extended for articles, posts, etc etc.
The retrieval methods include file_get_contents()
and cURL
. The constructor allows manually setting the method or allowing php to determine whether a retrieval method is available.
The call to retrieve data is pretty simple, for example:
//CLIENT CODE
require 'dwapi.class.php';
$dw = new dwAPI;
echo $dw->getForums();
Alternatively if you needed more specific output, the getForums() method takes 3 optional params:
1) (bool) 'include self' default = false
2) (mixed) 'forum list' default = false [can be: array e.g. array(1,3,4); string e.g. '1,3,4'; int e.g. 4]
3) (string) 'relatives' default = false [can be 'children'|'descendants'|'ancestors']
e.g.1
require 'dwapi.class.php';
$dw = new dwAPI;
echo $dw->getForums(false,'1,3,4'); //get details for forums 1,3 and 4
e.g.2
require 'dwapi.class.php';
$dw = new dwAPI;
echo $dw->getForums(true, array(1,2), 'descendants');
The output will be in json format, but you could to the following to get php assoc array:
require 'dwapi.class.php';
$dw = new dwAPI;
$arr = $dw->json2Array($dw->getForums(true, array(1,2), 'descendants'));
echo "<pre>";print_r($arr);echo "</pre>";
Anyhow, I'm sure seasoned OOPers will find plenty to complain about. If so, please send in your improvements.