Overview

Packages

  • Gollem
  • None

Classes

  • Gollem_Application
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Gollem application API.
  4:  *
  5:  * This file defines Horde's core API interface. Other core Horde libraries
  6:  * can interact with Horde through this API.
  7:  *
  8:  * Copyright 2010-2012 Horde LLC (http://www.horde.org/)
  9:  *
 10:  * See the enclosed file COPYING for license information (GPL). If you
 11:  * did not receive this file, see http://www.horde.org/licenses/gpl.
 12:  *
 13:  * @author   Jan Schneider <jan@horde.org>
 14:  * @author   Michael Slusarz <slusarz@horde.org>
 15:  * @author   Ben Klang <bklang@horde.org>
 16:  * @author   Amith Varghese <amith@xalan.com>
 17:  * @category Horde
 18:  * @license  http://www.horde.org/licenses/gpl GPL
 19:  * @package  Gollem
 20:  */
 21: 
 22: /* Determine the base directories. */
 23: if (!defined('GOLLEM_BASE')) {
 24:     define('GOLLEM_BASE', dirname(__FILE__) . '/..');
 25: }
 26: 
 27: if (!defined('HORDE_BASE')) {
 28:     /* If Horde does not live directly under the app directory, the HORDE_BASE
 29:      * constant should be defined in config/horde.local.php. */
 30:     if (file_exists(GOLLEM_BASE . '/config/horde.local.php')) {
 31:         include GOLLEM_BASE . '/config/horde.local.php';
 32:     } else {
 33:         define('HORDE_BASE', GOLLEM_BASE . '/..');
 34:     }
 35: }
 36: 
 37: /* Load the Horde Framework core (needed to autoload
 38:  * Horde_Registry_Application::). */
 39: require_once HORDE_BASE . '/lib/core.php';
 40: 
 41: class Gollem_Application extends Horde_Registry_Application
 42: {
 43:     /**
 44:      */
 45:     public $auth = array(
 46:         'authenticate',
 47:         'transparent',
 48:         'validate'
 49:     );
 50: 
 51:     /**
 52:      */
 53:     public $version = 'H4 (2.0.3-git)';
 54: 
 55:     /**
 56:      * Cached values to add to the session after authentication.
 57:      *
 58:      * @var array
 59:      */
 60:     protected $_cacheSess = array();
 61: 
 62:     /**
 63:      * Server key used in logged out session.
 64:      *
 65:      * @var string
 66:      */
 67:     protected $_oldbackend = null;
 68: 
 69:     /**
 70:      */
 71:     protected function _init()
 72:     {
 73:         $GLOBALS['injector']->bindFactory('Gollem_Vfs', 'Gollem_Factory_VfsDefault', 'create');
 74: 
 75:         if ($backend_key = $GLOBALS['session']->get('gollem', 'backend_key')) {
 76:             Gollem_Auth::changeBackend($backend_key);
 77:         }
 78:     }
 79: 
 80:     /**
 81:      */
 82:     public function perms()
 83:     {
 84:         $perms = array(
 85:             'backends' => array(
 86:                 'title' => _("Backends")
 87:             )
 88:         );
 89: 
 90:         // Run through every backend.
 91:         foreach (Gollem_Auth::getBackend() as $key => $val) {
 92:             $perms['backends:' . $key] = array(
 93:                 'title' => $val['name']
 94:             );
 95:         }
 96: 
 97:         return $perms;
 98:     }
 99: 
100:     /* Horde_Core_Auth_Application methods. */
101: 
102:     /**
103:      * Return login parameters used on the login page.
104:      *
105:      * @return array  See Horde_Core_Auth_Application#authLoginParams().
106:      */
107:     public function authLoginParams()
108:     {
109:         $params = array();
110: 
111:         if ($GLOBALS['conf']['backend']['backend_list'] == 'shown') {
112:             $backend_list = array();
113:             $selected = is_null($this->_oldbackend)
114:                 ? Horde_Util::getFormData('backend_key', Gollem_Auth::getPreferredBackend())
115:                 : $this->_oldbackend;
116: 
117:             foreach (Gollem_Auth::getBackend() as $key => $val) {
118:                 $backend_list[$key] = array(
119:                     'name' => $val['name'],
120:                     'selected' => ($selected == $key)
121:                 );
122:                 if ($selected == $key) {
123:                     if (!empty($val['loginparams'])) {
124:                         foreach ($val['loginparams'] as $param => $label) {
125:                             $params[$param] = array(
126:                                 'label' => $label,
127:                                 'type' => 'text',
128:                                 'value' => isset($val['params'][$param]) ? $val['params'][$param] : ''
129:                             );
130:                         }
131:                     }
132:                     if (Gollem_Auth::canAutoLogin($key)) {
133:                         $params['horde_user'] = null;
134:                         $params['horde_pass'] = null;
135:                     }
136:                 }
137:             }
138:             $params['backend_key'] = array(
139:                 'label' => _("Backend"),
140:                 'type' => 'select',
141:                 'value' => $backend_list
142:             );
143:         }
144: 
145:         return array(
146:             'js_code' => array(),
147:             'js_files' => array(array('login.js', 'gollem')),
148:             'params' => $params
149:         );
150:     }
151: 
152:     /**
153:      * Tries to authenticate with the server and create a session.
154:      *
155:      * @param string $userId      The username of the user.
156:      * @param array $credentials  Credentials of the user. Allowed keys:
157:      *                            'backend', 'password'.
158:      *
159:      * @throws Horde_Auth_Exception
160:      */
161:     public function authAuthenticate($userId, $credentials)
162:     {
163:         $this->init();
164: 
165:         $new_session = Gollem_Auth::authenticate(array(
166:             'password' => $credentials['password'],
167:             'backend_key' => empty($credentials['backend']) ? Gollem_Auth::getPreferredBackend() : $credentials['backend'],
168:             'userId' => $userId
169:         ));
170: 
171:         if ($new_session) {
172:             $this->_cacheSess = $new_session;
173:         }
174:     }
175: 
176:     /**
177:      * Tries to transparently authenticate with the server and create a
178:      * session.
179:      *
180:      * @param Horde_Core_Auth_Application $auth_ob  The authentication object.
181:      *
182:      * @return boolean  Whether transparent login is supported.
183:      * @throws Horde_Auth_Exception
184:      */
185:     public function authTransparent($auth_ob)
186:     {
187:         $this->init();
188: 
189:         if ($result = Gollem_Auth::transparent($auth_ob)) {
190:             $this->_cacheSess = $result;
191:             return true;
192:         }
193: 
194:         return false;
195:     }
196: 
197:     /**
198:      * Does necessary authentication tasks reliant on a full app environment.
199:      *
200:      * @throws Horde_Auth_Exception
201:      */
202:     public function authAuthenticateCallback()
203:     {
204:         if ($GLOBALS['registry']->getAuth()) {
205:             $this->init();
206: 
207:             foreach ($this->_cacheSess as $key => $val) {
208:                 $GLOBALS['session']->set('gollem', $key, $val);
209:             }
210:             $this->_cacheSess = array();
211:         }
212:     }
213: 
214:     /**
215:      * Validates an existing authentication.
216:      *
217:      * @return boolean  Whether the authentication is still valid.
218:      */
219:     public function authValidate()
220:     {
221:         if (($backend_key = Horde_Util::getFormData('backend_key')) &&
222:             $backend_key != $GLOBALS['session']->get('gollem', 'backend_key')) {
223:             Gollem_Auth::changeBackend($backend_key);
224:         }
225: 
226:         return !empty(Gollem::$backend['auth']);
227:     }
228: 
229:     /**
230:      */
231:     public function prefsGroup($ui)
232:     {
233:         foreach ($ui->getChangeablePrefs() as $val) {
234:             switch ($val) {
235:             case 'columnselect':
236:                 Horde_Core_Prefs_Ui_Widgets::sourceInit();
237:                 break;
238:             }
239:         }
240:     }
241: 
242:     /**
243:      */
244:     public function prefsSpecial($ui, $item)
245:     {
246:         switch ($item) {
247:         case 'columnselect':
248:             $cols = json_decode($GLOBALS['prefs']->getValue('columns'));
249:             $sources = array();
250: 
251:             foreach (Gollem_Auth::getBackend() as $source => $info) {
252:                 $selected = $unselected = array();
253:                 $selected_list = isset($cols[$source])
254:                     ? array_flip($cols[$source])
255:                     : array();
256: 
257:                 foreach ($info['attributes'] as $column) {
258:                     if (isset($selected_list[$column])) {
259:                         $selected[$column] = $column;
260:                     } else {
261:                         $unselected[$column] = $column;
262:                     }
263:                 }
264:                 $sources[$source] = array(
265:                     'selected' => $selected,
266:                     'unselected' => $unselected,
267:                 );
268:             }
269: 
270:             return Horde_Core_Prefs_Ui_Widgets::source(array(
271:                 'mainlabel' => _("Choose which columns to display, and in what order:"),
272:                 'selectlabel' => _("These columns will display in this order:"),
273:                 'sourcelabel' => _("Select a backend:"),
274:                 'sources' => $sources,
275:                 'unselectlabel' => _("Columns that will not be displayed:")
276:             ));
277:         }
278: 
279:         return '';
280:     }
281: 
282:     /**
283:      */
284:     public function menu($menu)
285:     {
286:         $backend_key = Gollem_Auth::getPreferredBackend();
287: 
288:         $menu->add(Horde::url('manager.php')->add('dir', Gollem::$backend['home']), _("_My Home"), 'folder_home.png');
289: 
290:         if ($GLOBALS['registry']->isAdmin()) {
291:             $menu->add(Horde::url('permissions.php')->add('backend', $backend_key), _("_Permissions"), 'perms.png');
292:         }
293: 
294:         if (isset(Gollem::$backend['quota_val']) &&
295:             Gollem::$backend['quota_val'] != -1) {
296:             if ($GLOBALS['browser']->hasFeature('javascript')) {
297:                 $quota_url = 'javascript:' . Horde::popupJs(Horde::url('quota.php'), array('params' => array('backend' => $backend_key), 'height' => 300, 'width' => 300, 'urlencode' => true));
298:             } else {
299:                 $quota_url = Horde::url('quota.php')->add('backend', $backend_key);
300:             }
301:             $menu->add($quota_url, _("Check Quota"), 'info_icon.png');
302:         }
303:     }
304: 
305:     /* Sidebar method. */
306: 
307:     /**
308:      */
309:     public function sidebarCreate(Horde_Tree_Base $tree, $parent = null,
310:                                   array $params = array())
311:     {
312:         $icon = Horde_Themes::img('gollem.png');
313:         $url = Horde::url('manager.php');
314: 
315:         foreach (Gollem_Auth::getBackend() as $key => $val) {
316:             $tree->addNode(
317:                 $parent . $key,
318:                 $parent,
319:                 $val['name'],
320:                 1,
321:                 false,
322:                 array(
323:                     'icon' => $icon,
324:                     'url' => $url->add(array('backend_key' => $key))
325:                 )
326:             );
327:         }
328:     }
329: 
330: }
331: 
API documentation generated by ApiGen