tiki-users3d_xmlrpc.php 2.1 KB
Newer Older
changi67's avatar
changi67 committed
1
<?php
changi67's avatar
changi67 committed
2 3 4
/**
 * @package tikiwiki
 */
5
// (c) Copyright 2002-2015 by authors of the Tiki Wiki CMS Groupware Project
changi67's avatar
changi67 committed
6 7 8
// 
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
changi67's avatar
changi67 committed
9
// $Id$
changi67's avatar
changi67 committed
10 11 12 13

include_once ('tiki-setup.php');
if ($prefs['feature_xmlrpc'] != 'y' || $prefs['wiki_feature_3d'] != 'y') {
	die;
14
}
changi67's avatar
changi67 committed
15 16
$map = array("getSubGraph" => array("function" => "getSubGraph"));
$server = new XML_RPC_Server($map);
17 18 19 20
/**
 * @param $params
 * @return XML_RPC_Response
 */
21 22
function getSubGraph($params)
{
changi67's avatar
changi67 committed
23
	global $dbTiki, $base_url;
24
	$userlib = new UsersLib;
changi67's avatar
changi67 committed
25 26 27 28 29 30 31 32 33
	$nodeName = $params->getParam(0);
	$nodeName = $nodeName->scalarVal();
	$depth = $params->getParam(1);
	$depth = $depth->scalarVal();
	$nodes = array();
	$passed = array($nodeName => true);
	$queue = array($nodeName);
	$i = 0;
	$neighbours = array();
34
	while ($i <= $depth && count($queue) > 0) {
changi67's avatar
changi67 committed
35
		$nextQueue = array();
36
		foreach ($queue as $nodeName) {
changi67's avatar
changi67 committed
37 38 39 40 41 42
			$similar = $userlib->related_users($nodeName, 5);
			if (isset($neighbours[$nodeName])) {
				$myNeighbours = $neighbours[$nodeName];
			} else {
				$myNeighbours = array();
			}
43
			foreach ($similar as $user) {
changi67's avatar
changi67 committed
44 45 46
				$myNeighbours[] = $user['login'];
				$neighbours[$user['login']][] = $nodeName;
			}
47
			$temp_max = count($myNeighbours);
changi67's avatar
changi67 committed
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
			for ($j = 0; $j < $temp_max; $j++) {
				if (!isset($passed[$myNeighbours[$j]])) {
					$nextQueue[] = $myNeighbours[$j];
					$passed[$myNeighbours[$j]] = true;
				}
				$myNeighbours[$j] = new XML_RPC_Value($myNeighbours[$j]);
			}
			$node = array();
			$actionUrl = "javascript:listObjects('$nodeName');";
			$color = '#0000FF';
			$node['neighbours'] = new XML_RPC_Value($myNeighbours, "array");
			if (!empty($color)) {
				$node['color'] = new XML_RPC_Value($color, "string");
			}
			$node['actionUrl'] = new XML_RPC_Value($actionUrl, "string");
			$nodes[$nodeName] = new XML_RPC_Value($node, "struct");
64
		}
changi67's avatar
changi67 committed
65 66
		$i++;
		$queue = $nextQueue;
67
	}
changi67's avatar
changi67 committed
68 69
	$response = array("graph" => new XML_RPC_Value($nodes, "struct"));
	return new XML_RPC_Response(new XML_RPC_Value($response, "struct"));
70
}