1: <?php
2: /**
3: * Default class for the Horde Application API.
4: *
5: * Copyright 2009-2012 Horde LLC (http://www.horde.org/)
6: *
7: * See the enclosed file COPYING for license information (LGPL). If you
8: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
9: *
10: * @author Michael Slusarz <slusarz@horde.org>
11: * @category Horde
12: * @package Core
13: */
14: class Horde_Registry_Application
15: {
16: /**
17: * Does this application support an ajax view?
18: *
19: * @var boolean
20: */
21: public $ajaxView = false;
22:
23: /**
24: * The list of available authentication capabilities handled by this
25: * application.
26: * The full capability list can be found in Horde_Core_Auth_Application.
27: *
28: * @var array
29: */
30: public $auth = array();
31:
32: /**
33: * The init params used.
34: *
35: * @var array
36: */
37: public $initParams = array();
38:
39: /**
40: * Does this application support a mobile view?
41: *
42: * @var boolean
43: */
44: public $mobileView = false;
45:
46: /**
47: * The application's version.
48: *
49: * @var string
50: */
51: public $version = 'unknown';
52:
53: /**
54: * Has init() previously been called?
55: *
56: * @var boolean
57: */
58: protected $_initDone = false;
59:
60: /**
61: * Application-specific code to run if application auth fails.
62: * Called from Horde_Registry::appInit().
63: *
64: * @param Horde_Exception $e The exception object.
65: */
66: public function appInitFailure($e)
67: {
68: }
69:
70: /**
71: * Initialization. Does any necessary init needed to setup the full
72: * environment for the application.
73: *
74: * Global constants defined:
75: * <pre>
76: * [APPNAME]_TEMPLATES - (string) Location of template files.
77: * </pre>
78: */
79: final public function init()
80: {
81: if (!$this->_initDone) {
82: $this->_initDone = true;
83:
84: $appname = Horde_String::upper($GLOBALS['registry']->getApp());
85: if (!defined($appname . '_TEMPLATES')) {
86: define($appname . '_TEMPLATES', $GLOBALS['registry']->get('templates'));
87: }
88:
89: $this->_init();
90: }
91: }
92:
93: /**
94: * Initialization code for an application.
95: */
96: protected function _init()
97: {
98: }
99:
100: /**
101: * Add additional items to the menu.
102: *
103: * @param Horde_Menu $menu The menu object.
104: */
105: public function menu($menu)
106: {
107: }
108:
109:
110: // Functions called from Horde's API.
111:
112: /**
113: * Tasks to perform at logout.
114: */
115: public function logout()
116: {
117: }
118:
119: /**
120: * Removes user data.
121: *
122: * @param string $user Name of user to remove data for.
123: *
124: * @throws Horde_Exception
125: */
126: public function removeUserData($user)
127: {
128: }
129:
130: // Horde permissions.
131:
132: /**
133: * Returns a list of available permissions.
134: *
135: * @return array An array describing all available permissions.
136: */
137: public function perms()
138: {
139: return array();
140: }
141:
142: /**
143: * Returns the specified permission for the given app permission.
144: *
145: * @param string $permission The permission to check.
146: * @param mixed $allowed The allowed permissions.
147: * @param array $opts Additional options ('value').
148: *
149: * @return mixed The value of the specified permission.
150: */
151: public function hasPermission($permission, $allowed, $opts = array())
152: {
153: return true;
154: }
155:
156:
157: // Horde_Notification methods.
158:
159: /**
160: * Modifies the global notification handler.
161: *
162: * @param Horde_Notification_Handler $handler A notification handler.
163: */
164: public function setupNotification(Horde_Notification_Handler $handler)
165: {
166: }
167:
168:
169: // Horde_Alarm methods.
170:
171: /**
172: * Lists alarms for a given moment.
173: *
174: * @param integer $time The time to retrieve alarms for.
175: * @param string $user The user to retreive alarms for. All users if
176: * null.
177: *
178: * @return array An array of UIDs
179: */
180: public function listAlarms($time, $user = null)
181: {
182: return array();
183: }
184:
185:
186: // Horde_Core_Auth_Application methods.
187:
188: /**
189: * Return login parameters used on the login page.
190: *
191: * @return array See Horde_Core_Auth_Application#authLoginParams().
192: */
193: public function authLoginParams()
194: {
195: return array(
196: 'js_code' => array(),
197: 'js_files' => array(),
198: 'params' => array()
199: );
200: }
201:
202: /**
203: * Tries to authenticate with the server and create a session.
204: *
205: * @param string $userId The username of the user.
206: * @param array $credentials Credentials of the user.
207: *
208: * @throws Horde_Auth_Exception
209: */
210: public function authAuthenticate($userId, $credentials)
211: {
212: throw new Horde_Auth_Exception('Authentication failed.');
213: }
214:
215: /**
216: * Tries to transparently authenticate with the server and create a
217: * session.
218: *
219: * @param Horde_Core_Auth_Application $auth_ob The authentication object.
220: *
221: * @return boolean Whether transparent login is supported.
222: * @throws Horde_Auth_Exception
223: */
224: public function authTransparent($auth_ob)
225: {
226: return false;
227: }
228:
229: /**
230: * Does necessary authentication tasks reliant on a full app environment.
231: *
232: * @throws Horde_Auth_Exception
233: */
234: public function authAuthenticateCallback()
235: {
236: }
237:
238: /**
239: * Validates an existing authentication.
240: *
241: * @since Horde_Core 1.4.0
242: *
243: * @return boolean Whether the authentication is still valid.
244: */
245: public function authValidate()
246: {
247: return false;
248: }
249:
250: /**
251: * Adds a user defined by authentication credentials.
252: *
253: * @param string $userId The user ID to add.
254: * @param array $credentials An array of login credentials.
255: *
256: * @throws Horde_Auth_Exception
257: */
258: public function authAddUser($userId, $credentials)
259: {
260: }
261:
262: /**
263: * Update an existing user's credentials.
264: *
265: * @param string $oldId The old user ID.
266: * @param string $newId The new user ID.
267: * @param array $credentials The new login credentials.
268: *
269: * @throws Horde_Auth_Exception
270: */
271: public function authUpdateUser($oldId, $newId, $credentials)
272: {
273: }
274:
275: /**
276: * Deletes a user defined by authentication credentials.
277: *
278: * @param string $userId The user ID to delete.
279: *
280: * @throws Horde_Auth_Exception
281: */
282: public function authRemoveUser($userId)
283: {
284: }
285:
286: /**
287: * Does a user exist?
288: *
289: * @param string $userId The user ID to check.
290: *
291: * @return boolean True if the user exists.
292: */
293: public function authUserExists($userId)
294: {
295: return false;
296: }
297:
298: /**
299: * Lists all users in the system.
300: *
301: * @return array The array of user IDs.
302: * @throws Horde_Auth_Exception
303: */
304: public function authUserList()
305: {
306: return array();
307: }
308:
309: /**
310: * Reset a user's password.
311: *
312: * @param string $userId The user id for which to reset the password.
313: *
314: * @return string The new password.
315: * @throws Horde_Auth_Exception
316: */
317: public function authResetPassword($userId)
318: {
319: return '';
320: }
321:
322:
323: // Horde_Core_Prefs_Ui functions.
324:
325: /**
326: * Run on init when viewing prefs for an application.
327: *
328: * @param Horde_Core_Prefs_Ui $ui The UI object.
329: */
330: public function prefsInit($ui)
331: {
332: }
333:
334: /**
335: * Determine active prefs when displaying a group. This is where all
336: * suppress/overrides should be defined.
337: *
338: * This function may be run multiple times in a single page - once on init
339: * and once after prefs are updated.
340: *
341: * @param Horde_Core_Prefs_Ui $ui The UI object.
342: */
343: public function prefsGroup($ui)
344: {
345: }
346:
347: /**
348: * Called when preferences are changed.
349: *
350: * @param Horde_Core_Prefs_Ui $ui The UI object.
351: */
352: public function prefsCallback($ui)
353: {
354: }
355:
356: /**
357: * Generate code used to display a special preference.
358: *
359: * @param Horde_Core_Prefs_Ui $ui The UI object.
360: * @param string $item The preference name.
361: *
362: * @return string The HTML code to display on the preferences page.
363: */
364: public function prefsSpecial($ui, $item)
365: {
366: return '';
367: }
368:
369: /**
370: * Special preferences handling on update.
371: *
372: * @param Horde_Core_Prefs_Ui $ui The UI object.
373: * @param string $item The preference name.
374: *
375: * @return boolean True if preference was updated.
376: */
377: public function prefsSpecialUpdate($ui, $item)
378: {
379: return false;
380: }
381:
382:
383: // Horde_Config functions.
384:
385: /**
386: * Returns values for <configspecial> configuration settings.
387: *
388: * @param string $what The configuration setting to return.
389: *
390: * @return array The values for the requested configuration setting.
391: */
392: public function configSpecialValues($what)
393: {
394: return array();
395: }
396:
397:
398: // Horde_Core_Sidebar method.
399:
400: /**
401: * Add node(s) to the sidebar tree.
402: *
403: * @param Horde_Tree_Base $tree Tree object.
404: * @param string $parent The current parent element.
405: * @param array $params Additional parameters.
406: *
407: * @throws Horde_Exception
408: */
409: public function sidebarCreate(Horde_Tree_Base $tree, $parent = null,
410: array $params = array()) {}
411:
412:
413: // Language change callback.
414:
415: /**
416: * Code to run if the language preference changes.
417: *
418: * Called only in applications the user is currently authenticated to in
419: * the current session.
420: */
421: public function changeLanguage()
422: {
423: }
424:
425: }
426: