tiki-wiki3d_xmlrpc.php 2.25 KB
Newer Older
changi67's avatar
changi67 committed
1 2 3 4
<?php
/**
 * @package tikiwiki
 */
5
// (c) Copyright 2002-2013 by authors of the Tiki Wiki CMS Groupware Project
changi67's avatar
changi67 committed
6 7 8 9
// 
// 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.
// $Id$
lfagundes's avatar
lfagundes committed
10

11
include_once('tiki-setup.php');
12
if ($prefs['feature_xmlrpc'] != 'y' || $prefs['wiki_feature_3d'] != 'y') {
13 14 15
  die;  
}

16
require_once("XML/Server.php");
17
include_once('lib/wiki/wikilib.php');
lfagundes's avatar
lfagundes committed
18 19

$map = array ("getSubGraph" => array( "function" => "getSubGraph" ) );
20
$server = new XML_RPC_Server($map);
lfagundes's avatar
lfagundes committed
21

22 23 24 25
/**
 * @param $params
 * @return XML_RPC_Response
 */
26 27
function getSubGraph($params)
{
28
    global $wikilib, $dbTiki, $base_url, $prefs;
lfagundes's avatar
lfagundes committed
29 30 31 32 33 34 35 36 37 38

    $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;

39
    $tikilib = new TikiLib;
40 41
    $existing_color = $prefs['wiki_3d_existing_page_color'];
    $missing_color = $prefs['wiki_3d_missing_page_color'];
42

43
    while ($i <= $depth && count($queue) > 0) {
lfagundes's avatar
lfagundes committed
44 45 46 47 48
	$nextQueue = array();
	foreach ($queue as $nodeName) {

	    $neighbours = $wikilib->wiki_get_neighbours($nodeName);
	    
49
	    $temp_max = count($neighbours);
50
	    for ($j = 0; $j < $temp_max; $j++) {
lfagundes's avatar
lfagundes committed
51 52 53 54
		if (!isset($passed[$neighbours[$j]])) {
		    $nextQueue[] = $neighbours[$j];
		    $passed[$neighbours[$j]] = true;
		}
55
		$neighbours[$j] = new XML_RPC_Value($neighbours[$j]);
lfagundes's avatar
lfagundes committed
56 57
	    }

58 59
	    $node = array();

60
	    if ( $wikilib->page_exists($nodeName) ) {
61
		$color = $existing_color;
62
		$actionUrl = $base_url.'tiki-index.php?page='.$nodeName;
63 64
	    } else {
		$color = $missing_color;
65
		$actionUrl = $base_url.'tiki-editpage.php?page='.$nodeName;
66 67
	    }

68
	    $node['neighbours'] = new XML_RPC_Value($neighbours, "array");
69
	    if ( ! empty($color) ) $node['color'] = new XML_RPC_Value($color, "string");
70

71
	    $node['actionUrl'] = new XML_RPC_Value($actionUrl, "string");
72
	    $nodes[$nodeName] = new XML_RPC_Value($node, "struct");
lfagundes's avatar
lfagundes committed
73 74 75 76 77
	}
	$i++;
	$queue = $nextQueue;
    }

78
    $response = array("graph" => new XML_RPC_Value($nodes, "struct"));
lfagundes's avatar
lfagundes committed
79
    
80
    return new XML_RPC_Response(new XML_RPC_Value($response, "struct"));
lfagundes's avatar
lfagundes committed
81
}