forked from cluebotng/review
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reviewApi.php
62 lines (56 loc) · 1.8 KB
/
reviewApi.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?PHP
function normalizeReviewAPIInput( $data ) {
if( !is_array( $data ) )
$data = Array( 'list' => $data );
if( isset( $data[ 'list' ] ) )
if( !is_array( $data[ 'list' ] ) )
$data[ 'list' ] = Array( $data[ 'list' ] );
if( isset( $data[ 'get' ] ) )
if( !is_array( $data[ 'get' ] ) )
unset( $data[ 'get' ] );
else
foreach( $data[ 'get' ] as &$value )
if( !is_array( $value ) )
$value = Array( $value );
return $data;
}
function callDataToURL( $data ) {
$parts = Array();
if( isset( $data[ 'list' ] ) ) {
if( in_array( 'users', $data[ 'list' ] ) )
$parts[] = 'listUsers';
if( in_array( 'editgroups', $data[ 'list' ] ) )
$parts[] = 'listEditGroups';
}
if( isset( $data[ 'get' ] ) ) {
if( isset( $data[ 'get' ][ 'user' ] ) ) {
$parts[] = 'getUser';
$parts[] = 'guKeys=' . urlencode( implode( ':', $data[ 'get' ][ 'user' ] ) );
}
if( isset( $data[ 'get' ][ 'edit' ] ) ) {
$parts[] = 'getEdit';
$parts[] = 'geKeys=' . urlencode( implode( ':', $data[ 'get' ][ 'edit' ] ) );
}
if( isset( $data[ 'get' ][ 'editgroup' ] ) ) {
$parts[] = 'getEditGroup';
$parts[] = 'gegKeys=' . urlencode( implode( ':', $data[ 'get' ][ 'editgroup' ] ) );
}
}
$contextArray = Array(
'http' => Array(
'method' => 'POST',
'content' => implode( '&', $parts ),
'header' => 'Content-Type: application/x-www-form-urlencoded'
)
);
$context = stream_context_create( $contextArray );
$url = 'http://cluebotreview.g.cluenet.org/api';
return Array( $url, $context, $contextArray );
}
function callReviewAPI( $data ) {
$data = normalizeReviewAPIInput( $data );
list( $url, $context, $contextData ) = callDataToURL( $data );
$xml = file_get_contents( $url, false, $context );
return simplexml_load_string( $xml );
}
?>