Support https in blog URLs
[dotclear.git] / page.webservice.php
1 <?php
2 require_once dirname(__FILE__) . '/widget.blog.owner.php';
3
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']) {
9 return true;
10 }
11 }
12 return false;
13 }
14
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";
19 exit;
20 }
21 $service = null;
22 switch ($args) {
23 case 'createBlog':
24 $service = array('XorgWebservice', $args);
25 break;
26 }
27 if ($service == null) {
28 header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found');
29 echo 'Webservice does not handle "' . $args . '"';
30 exit;
31 }
32 global $core;
33 $result = $core->auth->sudo($service);
34 if ($result['status']) {
35 header($_SERVER['SERVER_PROTOCOL'] . ' 200 Success');
36 } else {
37 header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error');
38 }
39 echo $result['message'];
40 exit;
41 }
42
43 static public function createBlog() {
44 global $core;
45 if (!isset($_GET['owner']) || !isset($_GET['url']) || !isset($_GET['type']) || !isset($_GET['baseurl'])) {
46 return array('status' => false,
47 'message' => 'Missing parameters');
48 }
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');
56 }
57 if (isset($_GET['ownername'])) {
58 $ownername = $_GET['ownername'];
59 } else {
60 $ownername = $owner;
61 }
62
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;
69 $core->addBlog($cur);
70
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');
79
80 return array('status' => true,
81 'message' => 'blog created');
82 }
83 }
84
85 ?>