summaryrefslogtreecommitdiffstats
path: root/lib/app.php
blob: 52c9f11456ac605e99b4e876e5b5d7fe10627ddf (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
<?php
/**
 * ownCloud
 *
 * @author Frank Karlitschek
 * @author Jakob Sack
 * @copyright 2010 Frank Karlitschek karlitschek@kde.org
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
 *
 * You should have received a copy of the GNU Affero General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

/**
 * This class manages the apps. It allows them to register and integrate in the
 * owncloud ecosystem. Furthermore, this class is responsible for installing,
 * upgrading and removing apps.
 */
class OC_APP{
	static private $init = false;
	static private $apps = array();
	static private $adminpages = array();
	static private $navigation = array();
	static private $personalmenu = array();

	/**
	 * @brief loads all apps
	 * @returns true/false
	 *
	 * This function walks through the owncloud directory and loads all apps
	 * it can find. A directory contains an app if the file /appinfo/app.php
	 * exists.
	 */
	public static function loadApps(){
		global $SERVERROOT;

		// Did we allready load everything?
		if( $self::init ){
			return true
		}

		// Get all appinfo
		$dir = opendir( $SERVERROOT );
		while( false !== ( $filename = readdir( $dir ))){
			if( substr( $filename, 0, 1 ) != '.' ){
				if( file_exists( "$SERVERROOT/$filename/appinfo/app.php" )){
					oc_require( "$filename/appinfo/app.php" );
				}
			}
		}
		closedir( $dir );

		$self::init = true;

		// return
		return true;
	}

	/**
	 * @brief makes owncloud aware of this app
	 * @param $data array with all information
	 * @returns true/false
	 *
	 * This function registers the application. $data is an associative array.
	 * The following keys are required:
	 *   - id: id of the application, has to be unique ("addressbook")
	 *   - name: Human readable name ("Addressbook")
	 *   - version: array with Version (major, minor, bugfix) ( array(1, 0, 2))
	 *
	 * The following keys are optional:
	 *   - order: integer, that influences the position of your application in
	 *     a list of applications. Lower values come first.
	 *
	 */
	public static function register( $data ){
		OC_APP::$apps[] = $data;
	}

	/**
	 * @brief returns information of all apps
	 * @return array with all information
	 *
	 * This function returns all data it got via register().
	 */
	public static function get(){
		return OC_APP::$apps;
	}

	/**
	 * @brief adds an entry to the navigation
	 * @param $data array containing the data
	 * @returns true/false
	 *
	 * This function adds a new entry to the navigation visible to users. $data
	 * is an associative array.
	 * The following keys are required:
	 *   - id: unique id for this entry ("addressbook_index")
	 *   - href: link to the page
	 *   - name: Human readable name ("Addressbook")
	 *
	 * The following keys are optional:
	 *   - icon: path to the icon of the app
	 *   - order: integer, that influences the position of your application in
	 *     the navigation. Lower values come first.
	 */
	public static function addNavigationEntry( $data ){
		// TODO: write function
		OC_APP::$navigation[] = $data;
		return true;
	}

	/**
	 * @brief adds a sub entry to the navigation
	 * @param $parent id of the parent
	 * @param $data array containing the data
	 * @returns true/false
	 *
	 * This function adds a new sub entry to the navigation visible to users.
	 * these entries are visible only if the parent navigation entry is marked
	 * as being active (see activateNavigationEntry()). $data is an associative
	 * array.
	 * The following keys are required:
	 *   - id: unique id for this entry ("addressbook_index")
	 *   - href: link to the page
	 *   - name: Human readable name ("Addressbook")
	 *
	 * The following keys are optional:
	 *   - icon: path to the icon of the app
	 *   - order: integer, that influences the position of your application in
	 *     the navigation. Lower values come first.
	 */
	public static function addNavigationSubEntry( $parent, $data ){
		// TODO: write function
		return true;
	}

	/**
	 * @brief marks a navigation entry as active
	 * @param $id id of the entry
	 * @returns true/false
	 *
	 * This function sets a navigation entry as active and removes the "active"
	 * property from all other entries. The templates can use this for
	 * highlighting the current position of the user.
	 */
	public static function activateNavigationEntry( $id ){
		// TODO: write function
		return true;
	}

	/**
	 * @brief adds an entry to the personal menu
	 * @param $data array containing the data
	 * @returns true/false
	 *
	 * This function adds a new entry to the personal menu visible to users
	 * only. $data is an associative array.
	 * The following keys are required:
	 *   - id: unique id for this entry ("logout")
	 *   - href: link to the page
	 *   - name: Human readable name ("Logout")
	 *
	 * The following keys are optional:
	 *   - order: integer, that influences the position of your application in
	 *     the personal menu. Lower values come first.
	 */
	public static function addPersonalMenuEntry( $data ){
		// TODO: write function
		OC_APP::$personalmenu[] = $data;
		return true;
	}

	/**
	 * @brief registers an admin page
	 * @param $data array containing the data
	 * @returns true/false
	 *
	 * This function registers a admin page that will be shown in the admin
	 * menu. $data is an associative array.
	 * The following keys are required:
	 *   - id: unique id for this entry ("files_admin")
	 *   - href: link to the admin page
	 *   - name: Human readable name ("Files Administration")
	 *
	 * The following keys are optional:
	 *   - order: integer, that influences the position of your application in
	 *     the list. Lower values come first.
	 */
	public static function addAdminPage( $data = array()){
		// TODO: write function
		OC_APP::$adminpages[] = $data;
		return true;
	}

	/**
	 * @brief Returns the navigation
	 * @returns associative array
	 *
	 * This function returns an array containing all entries added. The
	 * entries are sorted by the key "order" ascending. Additional to the keys
	 * given for each app the following keys exist:
	 *   - active: boolean, signals if the user is on this navigation entry
	 *   - children: array that is empty if the key "active" is false or
	 *     contains the subentries if the key "active" is true
	 */
	public static function getNavigation(){
		// TODO: write function
		return OC_APP::$navigation;
	}

	/**
	 * @brief Returns the personal menu
	 * @returns associative array
	 *
	 * This function returns an array containing all personal menu entries
	 * added. The entries are sorted by the key "order" ascending.
	 */
	public static function getPersonalMenu(){
		// TODO: write function
		return OC_APP::$personalmenu;
	}

	/**
	 * @brief Returns the admin pages
	 * @returns associative array
	 *
	 * This function returns an array containing all admin pages added. The
	 * entries are sorted by the key "order" ascending.
	 */
	public static function getAdminPages(){
		// TODO: write function
		return OC_APP::$adminpages;
	}

	/**
	 * @brief Installs an app
	 * @param $data array with all information
	 * @returns integer
	 *
	 * This function installs an app. All information needed are passed in the
	 * associative array $data.
	 * The following keys are required:
	 *   - source: string, can be "path" or "http"
	 *
	 * One of the following keys is required:
	 *   - path: path to the file containing the app
	 *   - href: link to the downloadable file containing the app
	 *
	 * The following keys are optional:
	 *   - pretend: boolean, if set true the system won't do anything
	 *   - noinstall: boolean, if true the function oc_app_install will be
	 *     skipped
	 *   - inactive: boolean, if set true the appconfig/app.sample.php won't be
	 *     renamed
	 *
	 * This function works as follows
	 *   -# fetching the file
	 *   -# unzipping it
	 *   -# including appinfo/installer.php
	 *   -# executing "oc_app_install()"
	 *   -# renaming appinfo/app.sample.php to appinfo/app.php
	 *
	 * It is the task of oc_app_install to create the tables and do whatever is
	 * needed to get the app working.
	 */
	public static function installApp( $data = array()){
		// TODO: write function
		return true;
	}

	/**
	 * @brief Installs an application
	 * @param $data array with all information
	 * @returns integer
	 *
	 * This function installs an app. All information needed are passed in the
	 * associative array $data.
	 * The following keys are required:
	 *   - source: string, can be "path" or "http"
	 *
	 * One of the following keys is required:
	 *   - path: path to the file containing the app
	 *   - href: link to the downloadable file containing the app
	 *
	 * The following keys are optional:
	 *   - pretend: boolean, if set true the system won't do anything
	 *   - noupgrade: boolean, if true the function oc_app_upgrade will be
	 *     skipped
	 *   - keepappinfo: boolean. If set true, the folder appinfo will not be
	 *     deleted, appinfo/app.php will not be replaced by a new version
	 *
	 * This function works as follows
	 *   -# fetching the file
	 *   -# removing the old files
	 *   -# unzipping new file
	 *   -# including appinfo/installer.php
	 *   -# executing "oc_app_upgrade( $options )"
	 *   -# renaming appinfo/app.sample.php to appinfo/app.php
	 */
	public static function upgradeApp( $data = array()){
		// TODO: write function
		return true;
	}

	/**
	 * @brief Removes an app
	 * @param $name name of the application to remove
	 * @param $options array with options
	 * @returns true/false
	 *
	 * This function removes an app. $options is an associative array. The
	 * following keys are optional:ja
	 *   - keeppreferences: boolean, if true the user preferences won't be deleted
	 *   - keepappconfig: boolean, if true the config will be kept
	 *   - keeptables: boolean, if true the database will be kept
	 *   - keepfiles: boolean, if true the user files will be kept
	 *
	 * This function works as follows
	 *   -# including appinfo/installer.php
	 *   -# executing "oc_app_uninstall( $options )"
	 *   -# removing the files
	 *
	 * The function will not delete preferences, tables and the configuration,
	 * this has to be done by the function oc_app_uninstall().
	 */
	public static function removeApp( $name, $options = array()){
		// TODO: write function
		return true;
	}
}
?>