commxmlrpc.php 6.51 KB
Newer Older
1
<?php
2

3
// $Id: /cvsroot/tikiwiki/tiki/commxmlrpc.php,v 1.22.2.3 2007-10-29 17:49:48 sylvieg Exp $
lrargerich's avatar
lrargerich committed
4

5
// Copyright (c) 2002-2007, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
6 7
// 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.
lrargerich's avatar
lrargerich committed
8

9
# $Id: /cvsroot/tikiwiki/tiki/commxmlrpc.php,v 1.22.2.3 2007-10-29 17:49:48 sylvieg Exp $
10 11
include_once("tiki-setup.php");
include_once ("lib/pear/XML/Server.php");
musus's avatar
musus committed
12
include_once ('lib/commcenter/commlib.php');
lrargerich's avatar
lrargerich committed
13

14 15
if ($tikilib->get_preference("feature_comm", 'n') != 'y') {
	die;
lrargerich's avatar
lrargerich committed
16 17
}

18 19
$map = array(
	"sendPage" => array("function" => "sendPage"),
sylvieg's avatar
sylvieg committed
20
	"sendStructurePage" => array("function" => "sendStructurePage"),
21
	"sendArticle" => array("function" => "sendArticle")
lrargerich's avatar
lrargerich committed
22 23
);

24
$s = new XML_RPC_Server($map);
lrargerich's avatar
lrargerich committed
25

sylvieg's avatar
sylvieg committed
26
function sendStructurePage($params) {
27
	global $tikilib, $userlib, $commlib, $prefs;
28 29 30 31
	include_once ('lib/structures/structlib.php');
	$site = $params->getParam(0); $site = $site->scalarval();
	$user = $params->getParam(1); $user = $user->scalarval();
	$pass = $params->getParam(2); $pass = $pass->scalarval();
sylvieg's avatar
sylvieg committed
32 33 34 35 36 37 38 39
	$sName = $params->getParam(3); $sName = $sName->scalarval();
	$pName = $params->getParam(4); $pName = $pName->scalarval();
	$name = $params->getParam(5); $name = $name->scalarval();
	$data = $params->getParam(6); $data = $data->scalarval();
	$comm = $params->getParam(7); $comm = $comm->scalarval();
	$desc = $params->getParam(8); $desc = $desc->scalarval();
	$pos = $params->getParam(9); $pos = $pos->scalarval();
	$alias = $params->getParam(10); $alias = $alias->scalarval();
40

41 42 43 44 45
	if ($user != 'admin' && $prefs['feature_intertiki'] == 'y' && !empty($prefs['feature_intertiki_mymaster'])) {
		$ok = $userlib->intervalidate($prefs['interlist'][$prefs['feature_intertiki_mymaster']], $user, $pass, false);
	} else {
		list($ok, $user, $error) = $userlib->validate_user($user, $pass, '', '');
	}
46 47 48 49 50 51 52 53 54 55 56
	if (!$ok) {
		return new XML_RPC_Response(0, 101, "Invalid username or password");
	}

	// Verify if the user has tiki_p_sendme_pages
	if (!$userlib->user_has_permission($user, 'tiki_p_sendme_pages')) {
		return new XML_RPC_Response(0, 101, "Permissions denied user $user cannot send pages to this site");
	}

	// Store the page in the tiki_received_pages_table
	$data = base64_decode($data);
sylvieg's avatar
sylvieg committed
57
	$commlib->receive_structure_page($name, $data, $comm, $site, $user, $desc, $sName, $pName, $pos, $alias);
58 59 60 61

	return new XML_RPC_Response(new XML_RPC_Value(1, "boolean"));
}

lrargerich's avatar
lrargerich committed
62 63
/* Validates the user and returns user information */
function sendPage($params) {
64
	// Get the page and store it in received_pages
65
	global $tikilib, $userlib, $commlib, $prefs;
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80

	$pp = $params->getParam(0);
	$site = $pp->scalarval();
	$pp = $params->getParam(1);
	$username = $pp->scalarval();
	$pp = $params->getParam(2);
	$password = $pp->scalarval();
	$pp = $params->getParam(3);
	$pageName = $pp->scalarval();
	$pp = $params->getParam(4);
	$data = $pp->scalarval();
	$pp = $params->getParam(5);
	$comment = $pp->scalarval();
	$pp = $params->getParam(6);
	$description = $pp->scalarval();
81

82 83 84 85 86
	if ($username != 'admin' && $prefs['feature_intertiki'] == 'y' && !empty($prefs['feature_intertiki_mymaster'])) {
		$ok = $userlib->intervalidate($prefs['interlist'][$prefs['feature_intertiki_mymaster']], $username, $password, false);
	} else {
		list($ok, $username, $error) = $userlib->validate_user($username, $password, '', '');
	}
87
	if (!$ok) {
88
		return new XML_RPC_Response(0, 101, "Invalid username or password");
89 90 91 92
	}

	// Verify if the user has tiki_p_sendme_pages
	if (!$userlib->user_has_permission($username, 'tiki_p_sendme_pages')) {
93
		return new XML_RPC_Response(0, 101, "Permissions denied user $username cannot send pages to this site");
94 95 96 97 98
	}

	// Store the page in the tiki_received_pages_table
	$data = base64_decode($data);
	$commlib->receive_page($pageName, $data, $comment, $site, $username, $description);
99
	return new XML_RPC_Response(new XML_RPC_Value(1, "boolean"));
lrargerich's avatar
lrargerich committed
100
}
lrargerich's avatar
lrargerich committed
101 102

function sendArticle($params) {
103
	// Get the page and store it in received_pages
104
	global $tikilib, $userlib, $commlib, $prefs;
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134

	$pp = $params->getParam(0);
	$site = $pp->scalarval();
	$pp = $params->getParam(1);
	$username = $pp->scalarval();
	$pp = $params->getParam(2);
	$password = $pp->scalarval();
	$pp = $params->getParam(3);
	$title = $pp->scalarval();
	$pp = $params->getParam(4);
	$authorName = $pp->scalarval();
	$pp = $params->getParam(5);
	$size = $pp->scalarval();
	$pp = $params->getParam(6);
	$use_image = $pp->scalarval();
	$pp = $params->getParam(7);
	$image_name = $pp->scalarval();
	$pp = $params->getParam(8);
	$image_type = $pp->scalarval();
	$pp = $params->getParam(9);
	$image_size = $pp->scalarval();
	$pp = $params->getParam(10);
	$image_x = $pp->scalarval();
	$pp = $params->getParam(11);
	$image_y = $pp->scalarval();
	$pp = $params->getParam(12);
	$image_data = $pp->scalarval();
	$pp = $params->getParam(13);
	$publishDate = $pp->scalarval();
	$pp = $params->getParam(14);
135
	$expireDate = $pp->scalarval();
136
	$pp = $params->getParam(15);
137
	$created = $pp->scalarval();
138
	$pp = $params->getParam(16);
139
	$heading = $pp->scalarval();
140
	$pp = $params->getParam(17);
141
	$body = $pp->scalarval();
142
	$pp = $params->getParam(18);
143
	$hash = $pp->scalarval();
144
	$pp = $params->getParam(19);
145
	$author = $pp->scalarval();
146
	$pp = $params->getParam(20);
147 148
	$type = $pp->scalarval();
	$pp = $params->getParam(21);
149 150
	$rating = $pp->scalarval();

151 152 153 154 155
	if ($username != 'admin' && $prefs['feature_intertiki'] == 'y' && !empty($prefs['feature_intertiki_mymaster'])) {
		$ok = $userlib->intervalidate($prefs['interlist'][$prefs['feature_intertiki_mymaster']], $username, $password, false);
	} else {
		list($ok, $username, $error) = $userlib->validate_user($username, $password, '', '');
	}
156
	if (!$ok) {
157
		return new XML_RPC_Response(0, 101, "Invalid username or password");
158 159 160 161
	}

	// Verify if the user has tiki_p_sendme_pages
	if (!$userlib->user_has_permission($username, 'tiki_p_sendme_articles')) {
162
		return new XML_RPC_Response(0, 101, "Permissions denied user $username cannot send articles to this site");
163 164 165 166 167 168 169 170 171 172
	}

	// Store the page in the tiki_received_pages_table
	$title = base64_decode($title);
	$authorName = base64_decode($authorName);
	$image_data = base64_decode($image_data);
	$heading = base64_decode($heading);
	$body = base64_decode($body);

	$commlib->receive_article($site, $username, $title, $authorName, $size, $use_image, $image_name, $image_type, $image_size,
173
		$image_x, $image_y, $image_data, $publishDate, $expireDate, $created, $heading, $body, $hash, $author, $type, $rating);
174

175
	return new XML_RPC_Response(new XML_RPC_Value(1, "boolean"));
lrargerich's avatar
lrargerich committed
176
}