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() { | |
6 | return true; | |
7 | } | |
8 | ||
9 | static public function handle($args) { | |
10 | if (!self::canRunServices()) { | |
11 | header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden'); | |
12 | echo "You're not allowed to run the webservices"; | |
13 | exit; | |
14 | } | |
15 | $service = null; | |
16 | switch ($args) { | |
17 | case 'createBlog': | |
18 | $service = array('XorgWebservice', $args); | |
19 | break; | |
20 | } | |
21 | if ($service == null) { | |
22 | header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found'); | |
23 | echo 'Webservice does not handle "' . $args . '"'; | |
24 | exit; | |
25 | } | |
26 | global $core; | |
27 | $result = $core->auth->sudo($service); | |
28 | if ($result['status']) { | |
29 | header($_SERVER['SERVER_PROTOCOL'] . ' 200 Success'); | |
30 | } else { | |
31 | header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error'); | |
32 | } | |
33 | echo $result['message']; | |
34 | exit; | |
35 | } | |
36 | ||
37 | static public function createBlog() { | |
38 | global $core; | |
39 | if (!isset($_GET['owner']) || !isset($_GET['url']) || !isset($_GET['type'])) { | |
40 | return array('status' => false, | |
41 | 'message' => 'Missing parameters'); | |
42 | } | |
43 | $owner = $_GET['owner']; | |
44 | $url = $_GET['url']; | |
45 | $type = $_GET['type']; | |
46 | if ($type != 'user' && $type != 'group-member' && $type != 'group-admin') { | |
47 | return array('status' => false, | |
48 | 'message' => 'Invalid blog type required'); | |
49 | } | |
50 | if (isset($_GET['ownername'])) { | |
51 | $ownername = $_GET['ownername']; | |
52 | } else { | |
53 | $ownername = $owner; | |
54 | } | |
55 | ||
56 | $cur = new cursor($core->con, 'dc_blog'); | |
57 | $cur->blog_id = $owner; | |
58 | $cur->blog_uid = $owner; | |
59 | $cur->blog_url = $url; | |
60 | $cur->blog_name = 'Blog de ' . $ownername; | |
61 | $cur->blog_status = 1; | |
62 | $core->addBlog($cur); | |
63 | ||
64 | $settings = new dcSettings($core, $owner); | |
65 | xorgBlogOwnerWidget::setXorgOwner($settings, $type, $owner); | |
66 | ||
67 | return array('status' => true, | |
68 | 'message' => 'blog created'); | |
69 | } | |
70 | } | |
71 | ||
72 | ?> |