2 require_once dirname(__FILE__
) . '/widget.blog.owner.php';
4 class XorgWebservice
extends dcUrlHandlers
{
5 static private function canRunServices() {
6 $addrs = explode(',', XORG_SERV_ADDRS
);
7 foreach ($addrs as $addr) {
8 if ($addr == $_SERVER['REMOTE_ADDR']) {
15 static public function handle($args) {
16 if (!self
::canRunServices()) {
17 header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden');
18 echo "You're not allowed to run the webservices";
24 $service = array('XorgWebservice', $args);
27 if ($service == null
) {
28 header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found');
29 echo 'Webservice does not handle "' . $args . '"';
33 $result = $core->auth
->sudo($service);
34 if ($result['status']) {
35 header($_SERVER['SERVER_PROTOCOL'] . ' 200 Success');
37 header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error');
39 echo $result['message'];
43 static public function createBlog() {
45 if (!isset($_GET['owner']) ||
!isset($_GET['url']) ||
!isset($_GET['type']) ||
!isset($_GET['baseurl'])) {
46 return array('status' => false
,
47 'message' => 'Missing parameters');
49 $owner = $_GET['owner'];
50 $url = rtrim($_GET['url'], '/') . '/';
51 $baseurl = rtrim($_GET['baseurl'], '/') . '/';
52 $type = $_GET['type'];
53 if ($type != 'user' && $type != 'connected' && $type != 'group-member' && $type != 'group-admin') {
54 return array('status' => false
,
55 'message' => 'Invalid blog type required');
57 if (isset($_GET['ownername'])) {
58 $ownername = $_GET['ownername'];
63 $cur = new cursor($core->con
, 'dc_blog');
64 $cur->blog_id
= $owner;
65 $cur->blog_uid
= $owner;
66 $cur->blog_url
= $url;
67 $cur->blog_name
= 'Blog de ' . $ownername;
68 $cur->blog_status
= 1;
71 $settings = new dcSettings($core, $owner);
72 $settings->system
->put('public_path', 'public/' . $owner);
73 $settings->system
->put('public_url', $baseurl . 'public/');
74 $settings->system
->put('themes_path', 'themes/');
75 $settings->system
->put('themes_url', $baseurl . 'themes/');
76 $xorgauth = $settings->addNamespace('xorgauth');
77 $xorgauth->put('xorg_blog_type', $type, 'string', 'Type de blog X.org');
78 $xorgauth->put('xorg_blog_owner', $owner, 'string', 'PropriƩtaire X.org du blog');
80 return array('status' => true
,
81 'message' => 'blog created');