Commit | Line | Data |
---|---|---|
5322432c FB |
1 | <?php |
2 | require_once dirname(__FILE__) . '/widget.blog.owner.php'; | |
3 | ||
4 | class XorgWebservice extends dcUrlHandlers { | |
5 | static private function canRunServices() { | |
7e805ddd FB |
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; | |
5322432c FB |
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'])) { | |
46 | return array('status' => false, | |
47 | 'message' => 'Missing parameters'); | |
48 | } | |
49 | $owner = $_GET['owner']; | |
58266dd3 | 50 | $url = rtrim($_GET['url'], '/') . '/'; |
5322432c FB |
51 | $type = $_GET['type']; |
52 | if ($type != 'user' && $type != 'group-member' && $type != 'group-admin') { | |
53 | return array('status' => false, | |
54 | 'message' => 'Invalid blog type required'); | |
55 | } | |
56 | if (isset($_GET['ownername'])) { | |
57 | $ownername = $_GET['ownername']; | |
58 | } else { | |
59 | $ownername = $owner; | |
60 | } | |
61 | ||
62 | $cur = new cursor($core->con, 'dc_blog'); | |
63 | $cur->blog_id = $owner; | |
64 | $cur->blog_uid = $owner; | |
65 | $cur->blog_url = $url; | |
66 | $cur->blog_name = 'Blog de ' . $ownername; | |
67 | $cur->blog_status = 1; | |
68 | $core->addBlog($cur); | |
69 | ||
70 | $settings = new dcSettings($core, $owner); | |
9921376e | 71 | $settings->system->put('public_path', 'public/' . $owner); |
0c941b48 | 72 | $settings->system->put('public_url', '/public/' . $owner); |
925cc548 RB |
73 | $xorgauth = $settings->addNamespace('xorgauth'); |
74 | $xorgauth->put('xorg_blog_type', $type, 'string', 'Type de blog X.org'); | |
75 | $xorgauth->put('xorg_blog_owner', $owner, 'string', 'Propriétaire X.org du blog'); | |
58266dd3 | 76 | |
5322432c FB |
77 | return array('status' => true, |
78 | 'message' => 'blog created'); | |
79 | } | |
80 | } | |
81 | ||
82 | ?> |