5
* @author Frank Karlitschek
7
* @copyright 2012 Frank Karlitschek frank@owncloud.org
9
* This library is free software; you can redistribute it and/or
10
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
11
* License as published by the Free Software Foundation; either
12
* version 3 of the License, or any later version.
14
* This library is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
19
* You should have received a copy of the GNU Affero General Public
20
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
25
* This class provides an easy way for apps to store config values in the
32
* @brief Get the url of the OCS AppStore server.
33
* @returns string of the AppStore server
35
* This function returns the url of the OCS AppStore server. It´s possible
36
* to set it in the config file or it will fallback to the default
38
private static function getAppStoreURL() {
39
if(OC_Util::getEditionString()===''){
40
$default='http://api.apps.owncloud.com/v1';
44
$url = OC_Config::getValue('appstoreurl', $default);
50
* @brief Get the content of an OCS url call.
51
* @returns string of the response
52
* This function calls an OCS server and returns the response. It also sets a sane timeout
54
private static function getOCSresponse($url) {
55
$data = \OC_Util::getUrlContent($url);
60
* @brief Get all the categories from the OCS server
61
* @returns array with category ids
62
* @note returns NULL if config value appstoreenabled is set to false
63
* This function returns a list of all the application categories on the OCS server
65
public static function getCategories() {
66
if(OC_Config::getValue('appstoreenabled', false)==false) {
69
$url=OC_OCSClient::getAppStoreURL().'/content/categories';
70
$xml=OC_OCSClient::getOCSresponse($url);
74
$data=simplexml_load_string($xml);
79
foreach($tmp->category as $value) {
81
$id= (int) $value->id;
82
$name= (string) $value->name;
91
* @brief Get all the applications from the OCS server
92
* @returns array with application data
94
* This function returns a list of all the applications on the OCS server
96
public static function getApplications($categories, $page, $filter) {
97
if(OC_Config::getValue('appstoreenabled', false)==false) {
101
if(is_array($categories)) {
102
$categoriesstring=implode('x', $categories);
104
$categoriesstring=$categories;
107
$version='&version='.implode('x', \OC_Util::getVersion());
108
$filterurl='&filter='.urlencode($filter);
109
$url=OC_OCSClient::getAppStoreURL().'/content/data?categories='.urlencode($categoriesstring)
110
.'&sortmode=new&page='.urlencode($page).'&pagesize=100'.$filterurl.$version;
112
$xml=OC_OCSClient::getOCSresponse($url);
117
$data=simplexml_load_string($xml);
119
$tmp=$data->data->content;
120
for($i = 0; $i < count($tmp); $i++) {
122
$app['id']=(string)$tmp[$i]->id;
123
$app['name']=(string)$tmp[$i]->name;
124
$app['label']=(string)$tmp[$i]->label;
125
$app['version']=(string)$tmp[$i]->version;
126
$app['type']=(string)$tmp[$i]->typeid;
127
$app['typename']=(string)$tmp[$i]->typename;
128
$app['personid']=(string)$tmp[$i]->personid;
129
$app['license']=(string)$tmp[$i]->license;
130
$app['detailpage']=(string)$tmp[$i]->detailpage;
131
$app['preview']=(string)$tmp[$i]->smallpreviewpic1;
132
$app['changed']=strtotime($tmp[$i]->changed);
133
$app['description']=(string)$tmp[$i]->description;
134
$app['score']=(string)$tmp[$i]->score;
143
* @brief Get an the applications from the OCS server
144
* @returns array with application data
146
* This function returns an applications from the OCS server
148
public static function getApplication($id) {
149
if(OC_Config::getValue('appstoreenabled', false)==false) {
152
$url=OC_OCSClient::getAppStoreURL().'/content/data/'.urlencode($id);
153
$xml=OC_OCSClient::getOCSresponse($url);
156
OC_Log::write('core', 'Unable to parse OCS content', OC_Log::FATAL);
159
$data=simplexml_load_string($xml);
161
$tmp=$data->data->content;
164
$app['name']=$tmp->name;
165
$app['version']=$tmp->version;
166
$app['type']=$tmp->typeid;
167
$app['label']=$tmp->label;
168
$app['typename']=$tmp->typename;
169
$app['personid']=$tmp->personid;
170
$app['detailpage']=$tmp->detailpage;
171
$app['preview1']=$tmp->smallpreviewpic1;
172
$app['preview2']=$tmp->smallpreviewpic2;
173
$app['preview3']=$tmp->smallpreviewpic3;
174
$app['changed']=strtotime($tmp->changed);
175
$app['description']=$tmp->description;
176
$app['detailpage']=$tmp->detailpage;
177
$app['score']=$tmp->score;
183
* @brief Get the download url for an application from the OCS server
184
* @returns array with application data
186
* This function returns an download url for an applications from the OCS server
188
public static function getApplicationDownload($id, $item) {
189
if(OC_Config::getValue('appstoreenabled', false)==false) {
192
$url=OC_OCSClient::getAppStoreURL().'/content/download/'.urlencode($id).'/'.urlencode($item);
193
$xml=OC_OCSClient::getOCSresponse($url);
196
OC_Log::write('core', 'Unable to parse OCS content', OC_Log::FATAL);
199
$data=simplexml_load_string($xml);
201
$tmp=$data->data->content;
203
if(isset($tmp->downloadlink)) {
204
$app['downloadlink']=$tmp->downloadlink;
206
$app['downloadlink']='';