. * */ /** * This class provides an easy way for apps to store config values in the * database. */ class OC_OCSClient{ /** * Returns whether the AppStore is enabled (i.e. because the AppStore is disabled for EE) * @return bool */ protected static function isAppstoreEnabled() { if(OC::$server->getConfig()->getSystemValue('appstoreenabled', true) === false OR OC_Util::getEditionString() !== '') { return false; } return true; } /** * Get the url of the OCS AppStore server. * @return string of the AppStore server * * This function returns the url of the OCS AppStore server. It´s possible * to set it in the config file or it will fallback to the default */ private static function getAppStoreURL() { return OC::$server->getConfig()->getSystemValue('appstoreurl', 'https://api.owncloud.com/v1'); } /** * Get the content of an OCS url call. * @return string of the response * This function calls an OCS server and returns the response. It also sets a sane timeout * @param string $url */ private static function getOCSresponse($url) { $data = \OC_Util::getUrlContent($url); return($data); } /** * Get all the categories from the OCS server * @return array|null an array of category ids or null * @note returns NULL if config value appstoreenabled is set to false * This function returns a list of all the application categories on the OCS server * * @param array $targetVersion The target ownCloud version */ public static function getCategories(array $targetVersion) { if(!self::isAppstoreEnabled()) { return null; } $url=OC_OCSClient::getAppStoreURL().'/content/categories'; $url .= '?version='.implode('x', $targetVersion); $xml=OC_OCSClient::getOCSresponse($url); if($xml==false) { return null; } $loadEntities = libxml_disable_entity_loader(true); $data = simplexml_load_string($xml); libxml_disable_entity_loader($loadEntities); $tmp=$data->data; $cats=array(); foreach($tmp->category as $value) { $id= (int) $value->id; $name= (string) $value->name; $cats[$id]=$name; } return $cats; } /** * Get all the applications from the OCS server * @return array|null an array of application data or null * * This function returns a list of all the applications on the OCS server * @param array|string $categories * @param int $page * @param string $filter * @param array $targetVersion The target ownCloud version */ public static function getApplications($categories, $page, $filter, array $targetVersion) { if(!self::isAppstoreEnabled()) { return(array()); } if(is_array($categories)) { $categoriesstring=implode('x', $categories); }else{ $categoriesstring=$categories; } $version='&version='.implode('x', $targetVersion); $filterurl='&filter='.urlencode($filter); $url=OC_OCSClient::getAppStoreURL().'/content/data?categories='.urlencode($categoriesstring) .'&sortmode=new&page='.urlencode($page).'&pagesize=100'.$filterurl.$version; $apps=array(); $xml=OC_OCSClient::getOCSresponse($url); if($xml==false) { return null; } $loadEntities = libxml_disable_entity_loader(true); $data = simplexml_load_string($xml); libxml_disable_entity_loader($loadEntities); $tmp=$data->data->content; for($i = 0; $i < count($tmp); $i++) { $app=array(); $app['id']=(string)$tmp[$i]->id; $app['name']=(string)$tmp[$i]->name; $app['label']=(string)$tmp[$i]->label; $app['version']=(string)$tmp[$i]->version; $app['type']=(string)$tmp[$i]->typeid; $app['typename']=(string)$tmp[$i]->typename; $app['personid']=(string)$tmp[$i]->personid; $app['license']=(string)$tmp[$i]->license; $app['detailpage']=(string)$tmp[$i]->detailpage; $app['preview']=(string)$tmp[$i]->smallpreviewpic1; $app['changed']=strtotime($tmp[$i]->changed); $app['description']=(string)$tmp[$i]->description; $app['score']=(string)$tmp[$i]->score; $apps[]=$app; } return $apps; } /** * Get an the applications from the OCS server * @param string $id * @param array $targetVersion The target ownCloud version * @return array|null an array of application data or null * * This function returns an applications from the OCS server */ public static function getApplication($id, array $targetVersion) { if(!self::isAppstoreEnabled()) { return null; } $url=OC_OCSClient::getAppStoreURL().'/content/data/'.urlencode($id); $url .= '?version='.implode('x', $targetVersion); $xml=OC_OCSClient::getOCSresponse($url); if($xml==false) { OC_Log::write('core', 'Unable to parse OCS content for app ' . $id, OC_Log::FATAL); return null; } $loadEntities = libxml_disable_entity_loader(true); $data = simplexml_load_string($xml); libxml_disable_entity_loader($loadEntities); $tmp=$data->data->content; if (is_null($tmp)) { OC_Log::write('core', 'Invalid OCS content returned for app ' . $id, OC_Log::FATAL); return null; } $app=array(); $app['id']=$tmp->id; $app['name']=$tmp->name; $app['version']=$tmp->version; $app['type']=$tmp->typeid; $app['label']=$tmp->label; $app['typename']=$tmp->typename; $app['personid']=$tmp->personid; $app['detailpage']=$tmp->detailpage; $app['preview1']=$tmp->smallpreviewpic1; $app['preview2']=$tmp->smallpreviewpic2; $app['preview3']=$tmp->smallpreviewpic3; $app['changed']=strtotime($tmp->changed); $app['description']=$tmp->description; $app['detailpage']=$tmp->detailpage; $app['score']=$tmp->score; return $app; } /** * Get the download url for an application from the OCS server * @return array|null an array of application data or null * * This function returns an download url for an applications from the OCS server * @param string $id * @param integer $item * @param array $targetVersion The target ownCloud version */ public static function getApplicationDownload($id, $item, array $targetVersion) { if(!self::isAppstoreEnabled()) { return null; } $url=OC_OCSClient::getAppStoreURL().'/content/download/'.urlencode($id).'/'.urlencode($item); $url .= '?version='.implode('x', $targetVersion); $xml=OC_OCSClient::getOCSresponse($url); if($xml==false) { OC_Log::write('core', 'Unable to parse OCS content', OC_Log::FATAL); return null; } $loadEntities = libxml_disable_entity_loader(true); $data = simplexml_load_string($xml); libxml_disable_entity_loader($loadEntities); $tmp=$data->data->content; $app=array(); if(isset($tmp->downloadlink)) { $app['downloadlink']=$tmp->downloadlink; }else{ $app['downloadlink']=''; } return $app; } } playname_in_sidebar'>artonge/fix/displayname_in_sidebar Nextcloud server, a safe home for all your data: https://github.com/nextcloud/serverwww-data
aboutsummaryrefslogtreecommitdiffstats
path: root/settings/js/settings.js
blob: 3a1e67f41cdffa12d2f07a3fbeec5a747ba1e0f3 (plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
 * Copyright (c) 2014, Vincent Petry <pvince81@owncloud.com>
 * This file is licensed under the Affero General Public License version 3 or later.
 * See the COPYING-README file.
 */
OC.Settings = OC.Settings || {};
OC.Settings = _.extend(OC.Settings, {

	_cachedGroups: null,

	/**
	 * Setup selection box for group selection.
	 *
	 * Values need to be separated by a pipe "|" character.
	 * (mostly because a comma is more likely to be used
	 * for groups)
	 *
	 * @param $elements jQuery element (hidden input) to setup select2 on
	 * @param {Array} [extraOptions] extra options hash to pass to select2
	 * @param {Array} [options] extra options
	 * @param {Array} [options.excludeAdmins=false] flag whether to exclude admin groups
	 */
	setupGroupsSelect: function($elements, extraOptions, options) {
		var self = this;
		options = options || {};
		if ($elements.length > 0) {
			// note: settings are saved through a "change" event registered
			// on all input fields
			$elements.select2(_.extend({
				placeholder: t('core', 'Groups'),
				allowClear: true,
				multiple: true,
				toggleSelect: true,
				separator: '|',
				query: _.debounce(function(query) {
					var queryData = {};
					if (self._cachedGroups && query.term === '') {
						query.callback({results: self._cachedGroups});
						return;
					}
					if (query.term !== '') {
						queryData = {
							pattern: query.term,
							filterGroups: 1
						};
					}
					$.ajax({
						url: OC.generateUrl('/settings/users/groups'),
						data: queryData,
						dataType: 'json',
						success: function(data) {
							var results = [];

							// add groups
							if (!options.excludeAdmins) {
								$.each(data.data.adminGroups, function(i, group) {
									results.push({id:group.id, displayname:group.name});
								});
							}
							$.each(data.data.groups, function(i, group) {
								results.push({id:group.id, displayname:group.name});
							});

							if (query.term === '') {
								// cache full list
								self._cachedGroups = results;
							}
							query.callback({results: results});
						}
					});
				}, 100, true),
				id: function(element) {
					return element.id;
				},
				initSelection: function(element, callback) {
					var selection =
						_.map(($(element).val() || []).split('|').sort(),
							function(groupName) {
						return {
							id: groupName,
							displayname: groupName
						};
					});
					callback(selection);
				},
				formatResult: function (element) {
					return escapeHTML(element.displayname);
				},
				formatSelection: function (element) {
					return escapeHTML(element.displayname);
				},
				escapeMarkup: function(m) {
					// prevent double markup escape
					return m;
				}
			}, extraOptions || {}));
		}
	}
});