setsites.php
1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
/**
* 2012 Frank Karlitschek frank@owncloud.org
* This file is licensed under the Affero General Public License version 3 or later.
* See the COPYING-README file.
*/
OCP\JSON::checkAppEnabled('external');
OCP\User::checkAdminUser();
OCP\JSON::callCheck();
$sites = array();
for ($i = 0; $i < sizeof($_POST['site_name']); $i++) {
if (!empty($_POST['site_name'][$i]) && !empty($_POST['site_url'][$i])) {
array_push($sites, array(strip_tags($_POST['site_name'][$i]), strip_tags($_POST['site_url'][$i])));
}
}
$l=OC_L10N::get('external');
foreach($sites as $site) {
if (strpos($site[1], 'https://') === 0) {
continue;
}
if (strpos($site[1], 'http://') === 0) {
continue;
}
if (strncmp($site[1], '/', 1) === 0) {
continue;
}
OC_JSON::error(array("data" => array( "message" => $l->t('Please enter valid urls - they have to start with either http://, https:// or /') )));
return;
}
if (sizeof($sites) == 0) {
$appConfig = \OC::$server->getAppConfig();
$appConfig->deleteKey('external', 'sites');
} else {
OCP\Config::setAppValue('external', 'sites', json_encode($sites));
}
OC_JSON::success(array("data" => array( "message" => $l->t("External sites saved.") )));