Overview

Packages

  • Horde
  • None

Classes

  • Horde_Ajax_Application
  • Horde_Api
  • Horde_Block_Account
  • Horde_Block_Account_Base
  • Horde_Block_Account_Finger
  • Horde_Block_Account_Ldap
  • Horde_Block_Account_Localhost
  • Horde_Block_Cloud
  • Horde_Block_FbStream
  • Horde_Block_Feed
  • Horde_Block_Fortune
  • Horde_Block_Google
  • Horde_Block_Iframe
  • Horde_Block_Metar
  • Horde_Block_Moon
  • Horde_Block_Sunrise
  • Horde_Block_Time
  • Horde_Block_TwitterTimeline
  • Horde_Block_Vatid
  • Horde_Block_Weather
  • Horde_LoginTasks_SystemTask_GarbageCollection
  • Horde_LoginTasks_SystemTask_Upgrade
  • Horde_LoginTasks_Task_AdminCheck
  • Horde_LoginTasks_Task_LastLogin
  • Horde_LoginTasks_Task_TosAgreement
  • Horde_Prefs_Ui
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Horde-specific prefs handling.
  4:  *
  5:  * Copyright 2010-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:  * @package Horde
 12:  */
 13: class Horde_Prefs_Ui
 14: {
 15:     /**
 16:      * Code to run on init when viewing prefs for this application.
 17:      *
 18:      * @param Horde_Core_Prefs_Ui $ui  The UI object.
 19:      */
 20:     public function prefsInit($ui)
 21:     {
 22:         global $conf, $injector;
 23: 
 24:         /* Hide prefGroups. */
 25:         try {
 26:             $injector->getInstance('Horde_Core_Factory_Auth')->create()->hasCapability('update');
 27:         } catch (Horde_Exception $e) {
 28:             $ui->suppressGroups[] = 'forgotpass';
 29:         }
 30: 
 31:         if (empty($conf['facebook']['enabled']) ||
 32:             empty($conf['facebook']['id']) ||
 33:             empty($conf['facebook']['secret'])) {
 34:             $ui->suppressGroups[] = 'facebook';
 35:         }
 36: 
 37:         if (empty($conf['twitter']['enabled']) ||
 38:             empty($conf['twitter']['key']) ||
 39:             empty($conf['twitter']['secret'])) {
 40:             $ui->suppressGroups[] = 'twitter';
 41:         }
 42: 
 43:         if (empty($conf['imsp']['enabled'])) {
 44:             $ui->suppressGroups[] = 'imspauth';
 45:         }
 46: 
 47:         if (empty($conf['activesync']['enabled'])) {
 48:             $ui->suppressGroups[] = 'activesync';
 49:         }
 50:     }
 51: 
 52:     /**
 53:      * Determine active prefs when displaying a group.
 54:      *
 55:      * @param Horde_Core_Prefs_Ui $ui  The UI object.
 56:      */
 57:     public function prefsGroup($ui)
 58:     {
 59:         global $injector, $registry;
 60: 
 61:         foreach ($ui->getChangeablePrefs() as $val) {
 62:             switch ($val) {
 63:             case 'initial_application':
 64:                 $out = array();
 65:                 $apps = $registry->listApps(array('active'));
 66:                 foreach ($apps as $a) {
 67:                     $perms = $injector->getInstance('Horde_Perms');
 68:                     if (file_exists($registry->get('fileroot', $a)) &&
 69:                         (($perms->exists($a) && ($perms->hasPermission($a, $registry->getAuth(), Horde_Perms::READ) || $registry->isAdmin())) ||
 70:                          !$perms->exists($a))) {
 71:                         $out[$a] = $registry->get('name', $a);
 72:                     }
 73:                 }
 74:                 asort($out);
 75:                 $ui->override['initial_application'] = $out;
 76:                 break;
 77: 
 78:             case 'language':
 79:                 $ui->override['language'] = $registry->nlsconfig->languages;
 80:                 array_unshift($ui->override['language'], _("Default"));
 81:                 break;
 82: 
 83:             case 'remotemanagement':
 84:                 Horde::addScriptFile('rpcprefs.js', 'horde');
 85:                 $ui->nobuttons = true;
 86:                 break;
 87: 
 88:             case 'theme':
 89:                 $ui->override['theme'] = Horde_Themes::themeList();
 90:                 break;
 91: 
 92:             case 'timezone':
 93:                 $ui->override['timezone'] = Horde_Nls::getTimezones();
 94:                 array_unshift($ui->override['timezone'], _("Default"));
 95:                 break;
 96:             }
 97:         }
 98:     }
 99: 
100:     /**
101:      * Generate code used to display a special preference.
102:      *
103:      * @param Horde_Core_Prefs_Ui $ui  The UI object.
104:      * @param string $item             The preference name.
105:      *
106:      * @return string  The HTML code to display on the options page.
107:      */
108:     public function prefsSpecial($ui, $item)
109:     {
110:         switch ($item) {
111:         case 'categorymanagement':
112:             return $this->_categoryManagement($ui);
113: 
114:         case 'remotemanagement':
115:             return $this->_remoteManagement($ui);
116: 
117:         case 'syncmlmanagement':
118:             return $this->_syncmlManagement($ui);
119: 
120:         case 'activesyncmanagement':
121:             return $this->_activesyncManagement($ui);
122: 
123:         case 'facebookmanagement':
124:             return $this->_facebookManagement($ui);
125: 
126:         case 'twittermanagement':
127:             return $this->_twitterManagement($ui);
128:         }
129: 
130:         return '';
131:     }
132: 
133:     /**
134:      * Special preferences handling on update.
135:      *
136:      * @param Horde_Core_Prefs_Ui $ui  The UI object.
137:      * @param string $item             The preference name.
138:      *
139:      * @return boolean  True if preference was updated.
140:      */
141:     public function prefsSpecialUpdate($ui, $item)
142:     {
143:         switch ($item) {
144:         case 'categorymanagement':
145:             return $this->_updateCategoryManagement($ui);
146: 
147:         case 'remotemanagement':
148:             $this->_updateRemoteManagement($ui);
149:             break;
150: 
151:         case 'syncmlmanagement':
152:             $this->_updateSyncmlManagement($ui);
153:             break;
154: 
155:         case 'activesyncmanagement':
156:             $this->_updateActiveSyncManagement($ui);
157:             break;
158: 
159:         case 'facebookmanagement':
160:             $this->_updateFacebookManagement($ui);
161:             break;
162: 
163:         case 'twittermanagement':
164:             $this->_updateTwitterManagement($ui);
165:         }
166: 
167:         return false;
168:     }
169: 
170:     /**
171:      * Called when preferences are changed.
172:      *
173:      * @param Horde_Core_Prefs_Ui $ui  The UI object.
174:      */
175:     public function prefsCallback($ui)
176:     {
177:         global $prefs, $registry;
178: 
179:         if ($prefs->isDirty('language')) {
180:             $registry->setLanguageEnvironment($prefs->getValue('language'));
181:             foreach ($registry->listApps() as $app) {
182:                 if ($registry->isAuthenticated(array('app' => $app, 'notransparent' => true))) {
183:                     $registry->callAppMethod($app, 'changeLanguage');
184:                 }
185:             }
186:         }
187:     }
188: 
189:     /**
190:      * Create code for category management.
191:      *
192:      * @param Horde_Core_Prefs_Ui $ui  The UI object.
193:      *
194:      * @return string  HTML UI code.
195:      */
196:     protected function _categoryManagement($ui)
197:     {
198:         Horde::addScriptFile('categoryprefs.js', 'horde');
199:         Horde::addScriptFile('colorpicker.js', 'horde');
200:         Horde::addInlineJsVars(array(
201:             'HordeCategoryPrefs.category_text' => _("Enter a name for the new category:")
202:         ));
203: 
204:         $cManager = new Horde_Prefs_CategoryManager();
205:         $categories = $cManager->get();
206:         $colors = $cManager->colors();
207:         $fgcolors = $cManager->fgColors();
208: 
209:         $t = $GLOBALS['injector']->createInstance('Horde_Template');
210:         $t->setOption('gettext', true);
211: 
212:         if (!$GLOBALS['prefs']->isLocked('category_colors')) {
213:             $t->set('picker_img',  Horde::img('colorpicker.png', _("Color Picker")));
214:         }
215:         $t->set('delete_img',  Horde::img('delete.png'));
216: 
217:         // Default Color
218:         $color = isset($colors['_default_'])
219:             ? htmlspecialchars($colors['_default_'])
220:             : '#FFFFFF';
221:         $fgcolor = isset($fgcolors['_default_'])
222:             ? htmlspecialchars($fgcolors['_default_'])
223:             : '#000000';
224:         $color_b = 'color_' . hash('md5', '_default_');
225: 
226:         $t->set('default_color', $color);
227:         $t->set('default_fgcolor', $fgcolor);
228:         $t->set('default_label', Horde::label($color_b, _("Default Color")));
229:         $t->set('default_id', $color_b);
230: 
231:         // Unfiled Color
232:         $color = isset($colors['_unfiled_'])
233:             ? htmlspecialchars($colors['_unfiled_'])
234:             : '#FFFFFF';
235:         $fgcolor = isset($fgcolors['_unfiled_'])
236:             ? htmlspecialchars($fgcolors['_unfiled_'])
237:             : '#000000';
238:         $color_b = 'color_' . hash('md5', '_unfiled_');
239: 
240:         $t->set('unfiled_color', $color);
241:         $t->set('unfiled_fgcolor', $fgcolor);
242:         $t->set('unfiled_label', Horde::label($color_b, _("Unfiled")));
243:         $t->set('unfiled_id', $color_b);
244: 
245:         $entries = array();
246:         foreach ($categories as $name) {
247:             $color = isset($colors[$name])
248:                 ? htmlspecialchars($colors[$name])
249:                 : '#FFFFFF';
250:             $fgcolor = isset($fgcolors[$name])
251:                 ? htmlspecialchars($fgcolors[$name])
252:                 : '#000000';
253:             $color_b = 'color_' . hash('md5', $name);
254: 
255:             $entries[] = array(
256:                 'color' => $color,
257:                 'fgcolor' => $fgcolor,
258:                 'label' => Horde::label($color_b, ($name == '_default_' ? _("Default Color") : htmlspecialchars($name))),
259:                 'id' => $color_b,
260:                 'name' => htmlspecialchars($name)
261:             );
262:         }
263:         $t->set('categories', $entries);
264: 
265:         return $t->fetch(HORDE_TEMPLATES . '/prefs/category.html');
266:     }
267: 
268:     /**
269:      * Create code for remote server management.
270:      *
271:      * @param Horde_Core_Prefs_Ui $ui  The UI object.
272:      *
273:      * @return string  HTML UI code.
274:      */
275:     protected function _remoteManagement($ui)
276:     {
277:         $rpc_servers = @unserialize($GLOBALS['prefs']->getValue('remote_summaries'));
278:         if (!is_array($rpc_servers)) {
279:             $rpc_servers = array();
280:         }
281: 
282:         $js = $serverlist = array();
283:         foreach ($rpc_servers as $key => $val) {
284:             $js[] = array($val['url'], $val['user']);
285:             $serverlist[] = array(
286:                 'i' => $key,
287:                 'l' => htmlspecialchars($val['url'])
288:             );
289:         }
290: 
291:         Horde::addInlineJsVars(array(
292:             'HordeRpcPrefs.servers' => $js
293:         ));
294: 
295:         $t = $GLOBALS['injector']->createInstance('Horde_Template');
296:         $t->setOption('gettext', true);
297: 
298:         $t->set('serverlabel', Horde::label('server', _("Your remote servers:")));
299:         $t->set('serverlist', $serverlist);
300:         $t->set('urllabel', Horde::label('url', _("Remote URL (http://www.example.com/horde):")));
301:         $t->set('userlabel', Horde::label('user', _("Username:")));
302:         $t->set('passwdlabel', Horde::label('passwd', _("Password:")));
303: 
304:         return $t->fetch(HORDE_TEMPLATES . '/prefs/rpc.html');
305:     }
306: 
307:     /**
308:      * Create code for SyncML management.
309:      *
310:      * @param Horde_Core_Prefs_Ui $ui  The UI object.
311:      *
312:      * @return string  HTML UI code.
313:      */
314:     protected function _syncmlManagement($ui)
315:     {
316:         Horde::addScriptFile('syncmlprefs.js', 'horde');
317:         $devices = Horde_SyncMl_Backend::factory('Horde')->getUserAnchors($GLOBALS['registry']->getAuth());
318: 
319:         $t = $GLOBALS['injector']->createInstance('Horde_Template');
320:         $t->setOption('gettext', true);
321: 
322:         $partners = array();
323:         $selfurl = $ui->selfUrl()->add('deleteanchor', 1);
324:         $format = $GLOBALS['prefs']->getValue('date_format') . ' %H:%M';
325: 
326:         foreach ($devices as $device) {
327:             $partners[] = array(
328:                 'anchor'   => htmlspecialchars($device['syncml_clientanchor']),
329:                 'db'       => htmlspecialchars($device['syncml_db']),
330:                 'deviceid' => $device['syncml_syncpartner'],
331:                 'rawdb'    => $device['syncml_db'],
332:                 'device'   => htmlspecialchars($device['syncml_syncpartner']),
333:                 'time'     => strftime($format, $device['syncml_serveranchor'])
334:             );
335:         }
336:         $t->set('devices', $partners);
337: 
338:         return $t->fetch(HORDE_TEMPLATES . '/prefs/syncml.html');
339:     }
340: 
341:     /**
342:      * Create code for ActiveSync management.
343:      *
344:      * @param Horde_Core_Prefs_Ui $ui  The UI object.
345:      *
346:      * @return string HTML UI code.
347:      */
348:     protected function _activesyncManagement($ui)
349:     {
350:         if (empty($GLOBALS['conf']['activesync']['enabled'])) {
351:             return _("ActiveSync not activated.");
352:         }
353: 
354:         $stateMachine = $GLOBALS['injector']->getInstance('Horde_ActiveSyncState');
355:         $devices = $stateMachine->listDevices($GLOBALS['registry']->getAuth());
356: 
357:         $js = array();
358:         foreach ($devices as $key => $val) {
359:             $js[$key] = array(
360:                 'id' => $val['device_id'],
361:                 'user' => $val['device_user']
362:             );
363:         }
364: 
365:         Horde::addScriptFile('activesyncprefs.js', 'horde');
366:         Horde::addInlineJsVars(array(
367:             'HordeActiveSyncPrefs.devices' => $js
368:         ));
369: 
370:         $t = $GLOBALS['injector']->createInstance('Horde_Template');
371:         $t->setOption('gettext', true);
372: 
373:         $selfurl = $ui->selfUrl();
374:         $t->set('reset', $selfurl->copy()->add('reset', 1));
375:         $devs = array();
376: 
377:         foreach ($devices as $key => $device) {
378:             $device['class'] = fmod($key, 2) ? 'rowOdd' : 'rowEven';
379:             $device['key'] = $key;
380: 
381:             $stateMachine->loadDeviceInfo($device['device_id'], $GLOBALS['registry']->getAuth());
382:             $ts = $stateMachine->getLastSyncTimestamp();
383:             $device['ts'] = empty($ts) ? _("None") : strftime($GLOBALS['prefs']->getValue('date_format') . ' %H:%M', $ts);
384: 
385:             switch ($device['device_rwstatus']) {
386:             case Horde_ActiveSync::RWSTATUS_PENDING:
387:                 $status = '<span class="notice">' . _("Wipe is pending") . '</span>';
388:                 $device['ispending'] = true;
389:                 break;
390: 
391:             case Horde_ActiveSync::RWSTATUS_WIPED:
392:                 $status = '<span class="notice">' . _("Device is wiped") . '</span>';
393:                 break;
394: 
395:             default:
396:                 $status = $device['device_policykey']
397:                     ? _("Provisioned")
398:                     : _("Not Provisioned");
399:                 break;
400:             }
401: 
402:             $device['wipe'] = $selfurl->copy()->add('wipe', $device['device_id']);
403:             $device['remove'] = $selfurl->copy()->add('remove', $device['device_id']);
404:             $device['status'] = $status . '<br />' . _("Device id:") . $device['device_id'] . '<br />' . _("Policy Key:") . $device['device_policykey'] . '<br />' . _("User Agent:") . $device['device_agent'];
405: 
406:             $devs[] = $device;
407:         }
408: 
409:         $t->set('devices', $devs);
410: 
411:         return $t->fetch(HORDE_TEMPLATES . '/prefs/activesync.html');
412:     }
413: 
414:     /**
415:      * Facebook session management
416:      *
417:      * @param Horde_Core_Prefs_Ui $ui  The UI object.
418:      *
419:      * @return string  The HTML code to display the Facebook prefs.
420:      */
421:     protected function _facebookManagement($ui)
422:     {
423:         global $prefs;
424: 
425:         try {
426:             $facebook = $GLOBALS['injector']->getInstance('Horde_Service_Facebook');
427:         } catch (Horde_Exception $e) {
428:             return $e->getMessage();
429:         }
430: 
431:         $GLOBALS['injector']->getInstance('Horde_Themes_Css')->addThemeStylesheet('facebook.css');
432:         $t = $GLOBALS['injector']->createInstance('Horde_Template');
433:         $t->setOption('gettext', true);
434:         $t->set('app_name', $GLOBALS['registry']->get('name', 'horde'));
435: 
436:         // Ensure we have authorized horde.
437:         try {
438:             // @TODO: FB is in the process of adding this to the Graph API.
439:             $session_uid = $facebook->auth->getLoggedInUser();
440:             $fbp = unserialize($prefs->getValue('facebook'));
441:             $uid = $fbp['uid'];
442:             // Verify the userid matches the one we expect for the session
443:             if ($fbp['uid'] != $session_uid) {
444:                 $haveSession = false;
445:             } else {
446:                 $haveSession = true;
447:             }
448:         } catch (Horde_Service_Facebook_Exception $e) {
449:             Horde::logMessage($e->getMessage(), 'ERR');
450:             $haveSession = false;
451:             $prefs->setValue('facebook', serialize(array('uid' => '', 'sid' => 0)));
452:         }
453: 
454:         // We have a session, build the template.
455:         if (!empty($haveSession)) {
456:             try {
457:                 $facebook->batchBegin();
458:                 $offline = &$facebook->users->hasAppPermission(Horde_Service_Facebook_Auth::EXTEND_PERMS_OFFLINE, $uid);
459:                 $publish = &$facebook->users->hasAppPermission(Horde_Service_Facebook_Auth::EXTEND_PERMS_PUBLISHSTREAM, $uid);
460:                 $read = &$facebook->users->hasAppPermission(Horde_Service_Facebook_Auth::EXTEND_PERMS_READSTREAM, $uid);
461:                 $friends = &$facebook->users->hasAppPermission(Horde_Service_Facebook_Auth::EXTEND_PERMS_FRIENDS_ABOUT, $uid);
462:                 $facebook->batchEnd();
463: 
464:                 $t->set('have_offline', $offline);
465:                 $t->set('have_publish', $publish);
466:                 $t->set('have_read', $read);
467:                 $t->set('have_friends', $friends);
468: 
469:             } catch (Horde_Service_Facebook_Exception $e) {
470:                 $GLOBALS['notification']->push($e->getMessage(), 'horde.error');
471:             }
472: 
473:             // Get user info. FB recommends using the FB photo and styling.
474:             $fql = 'SELECT first_name, last_name, status, pic_with_logo, current_location FROM user WHERE uid IN (' . $uid . ')';
475:             try {
476:                 $user_info = $facebook->fql->run($fql);
477:             } catch (Horde_Service_Facebook_Exception $e) {
478:                 $GLOBALS['notification']->push(_("Temporarily unable to connect with Facebook, Please try again."), 'horde.alert');
479:             }
480: 
481:             // FB Perms links
482:             $cburl = Horde::url('services/facebook', true);
483:             $url = $facebook->auth->getOAuthUrl($cburl, array(Horde_Service_Facebook_Auth::EXTEND_PERMS_OFFLINE));
484:             $t->set('authUrl', Horde::signQueryString($url));
485:             $t->set('have_session', true);
486:             $t->set('user_pic_url', $user_info[0]['pic_with_logo']);
487:             $t->set('user_name', $user_info[0]['first_name'] . ' ' . $user_info[0]['last_name']);
488: 
489:             $url = $facebook->auth->getOAuthUrl($cburl, array(Horde_Service_Facebook_Auth::EXTEND_PERMS_PUBLISHSTREAM));
490:             $t->set('publish_url', $url);
491: 
492:             // User read perms
493:             $url = $facebook->auth->getOAuthUrl($cburl, array(
494:                 Horde_Service_Facebook_Auth::EXTEND_PERMS_READSTREAM,
495:                 Horde_Service_Facebook_Auth::EXTEND_PERMS_USER_ABOUT,
496:                 Horde_Service_Facebook_Auth::EXTEND_PERMS_USER_BIRTHDAY,
497:                 Horde_Service_Facebook_Auth::EXTEND_PERMS_USER_EVENTS,
498:                 Horde_Service_Facebook_Auth::EXTEND_PERMS_USER_HOMETOWN,
499:                 Horde_Service_Facebook_Auth::EXTEND_PERMS_USER_LOCATION,
500:                 Horde_Service_Facebook_Auth::EXTEND_PERMS_USER_PHOTOS));
501:             $t->set('read_url', Horde::signQueryString($url));
502: 
503:             // Friend read perms
504:             $url = $facebook->auth->getOAuthUrl($cburl, array(
505:                 Horde_Service_Facebook_Auth::EXTEND_PERMS_FRIENDS_ABOUT,
506:                 Horde_Service_Facebook_Auth::EXTEND_PERMS_FRIENDS_BIRTHDAY,
507:                 Horde_Service_Facebook_Auth::EXTEND_PERMS_FRIENDS_HOMETOWN,
508:                 Horde_Service_Facebook_Auth::EXTEND_PERMS_FRIENDS_LOCATION,
509:                 Horde_Service_Facebook_Auth::EXTEND_PERMS_FRIENDS_PHOTOS));
510:             $t->set('friends_url', Horde::signQueryString($url));
511: 
512:             return $t->fetch(HORDE_TEMPLATES . '/prefs/facebook.html');
513:         }
514: 
515:         /* No existing session */
516:         $t->set('have_session', false);
517:         $t->set('authUrl', $facebook->auth->getOAuthUrl(Horde::url('services/facebook', true)));
518: 
519:         return $t->fetch(HORDE_TEMPLATES . '/prefs/facebook.html');
520:     }
521: 
522:     protected function _twitterManagement($ui)
523:     {
524:         global $prefs, $registry;
525: 
526:         $twitter = $GLOBALS['injector']->getInstance('Horde_Service_Twitter');
527:         $token = unserialize($prefs->getValue('twitter'));
528: 
529:         /* Check for an existing token */
530:         if (!empty($token['key']) && !empty($token['secret'])) {
531:             $auth_token = new Horde_Oauth_Token($token['key'], $token['secret']);
532:             $twitter->auth->setToken($auth_token);
533:         }
534:         try {
535:             $profile = Horde_Serialize::unserialize($twitter->account->verifyCredentials(), Horde_Serialize::JSON);
536:         } catch (Horde_Service_Twitter_Exception $e) {}
537: 
538:         $t = $GLOBALS['injector']->createInstance('Horde_Template');
539:         $t->setOption('gettext', true);
540: 
541:         /* Could not find a valid auth token, and we are not in the process of getting one */
542:         if (empty($profile)) {
543:             try {
544:                 $results = $twitter->auth->getRequestToken();
545:             } catch (Horde_Service_Twitter_Exception $e) {
546:                 $t->set('error', sprintf(_("Error connecting to Twitter: %s Details have been logged for the administrator."), $e->getMessage()), true);
547:                 exit;
548:             }
549:             $GLOBALS['session']->store($results->secret, false, 'twitter_request_secret');
550:             $t->set('appname', $registry->get('name'));
551:             $t->set('link', Horde::link(Horde::externalUrl($twitter->auth->getUserAuthorizationUrl($results), false), '', 'button', '', 'openTwitterWindow(); return false;') . 'Twitter</a>');
552:             $t->set('popupjs', Horde::popupJs(Horde::externalUrl($twitter->auth->getUserAuthorizationUrl($results), false), array('urlencode' => true)));
553:         } else {
554:             $t->set('haveSession', true, true);
555:             $t->set('profile_image_url', $profile->profile_image_url);
556:             $t->set('profile_screenname', htmlspecialchars($profile->screen_name));
557:             $t->set('profile_name', htmlspecialchars($profile->name));
558:             $t->set('profile_location', htmlspecialchars($profile->location));
559:             $t->set('appname', $registry->get('name'));
560:         }
561: 
562:         return $t->fetch(HORDE_TEMPLATES . '/prefs/twitter.html');
563:     }
564: 
565:     /**
566:      * Update category related preferences.
567:      *
568:      * @param Horde_Core_Prefs_Ui $ui  The UI object.
569:      *
570:      * @return boolean  True if preferences were updated.
571:      */
572:     protected function _updateCategoryManagement($ui)
573:     {
574:         $cManager = new Horde_Prefs_CategoryManager();
575: 
576:         /* Always save colors of all categories. */
577:         $colors = array();
578:         $categories = $cManager->get();
579:         foreach ($categories as $category) {
580:             if ($color = $ui->vars->get('color_' . hash('md5', $category))) {
581:                 $colors[$category] = $color;
582:             }
583:         }
584:         if ($color = $ui->vars->get('color_' . hash('md5', '_default_'))) {
585:             $colors['_default_'] = $color;
586:         }
587:         if ($color = $ui->vars->get('color_' . hash('md5', '_unfiled_'))) {
588:             $colors['_unfiled_'] = $color;
589:         }
590:         $cManager->setColors($colors);
591: 
592:         switch ($ui->vars->cAction) {
593:         case 'add':
594:             $cManager->add($ui->vars->category);
595:             break;
596: 
597:         case 'remove':
598:             $cManager->remove($ui->vars->category);
599:             break;
600: 
601:         default:
602:             /* Save button. */
603:             Horde::addInlineScript(array(
604:                 'if (window.opener && window.name) window.close();'
605:             ));
606:             return true;
607:         }
608: 
609:         return false;
610:     }
611: 
612:     /**
613:      * Update remote servers related preferences.
614:      *
615:      * @param Horde_Core_Prefs_Ui $ui  The UI object.
616:      */
617:     protected function _updateRemoteManagement($ui)
618:     {
619:         global $notification, $prefs;
620: 
621:         $rpc_servers = @unserialize($prefs->getValue('remote_summaries'));
622:         if (!is_array($rpc_servers)) {
623:             $rpc_servers = array();
624:         }
625: 
626:         if ($ui->vars->rpc_change || $ui->vars->rpc_create) {
627:             $tmp = array(
628:                 'passwd' => $ui->vars->passwd,
629:                 'url' => $ui->vars->url,
630:                 'user' => $ui->vars->user
631:             );
632: 
633:             if ($ui->vars->rpc_change) {
634:                 $rpc_servers[$ui->vars->server] = $tmp;
635:             } else {
636:                 $rpc_servers[] = $tmp;
637:             }
638: 
639:             $prefs->setValue('remote_summaries', serialize($rpc_servers));
640:             $notification->push(sprintf(_("The server \"%s\" has been saved."), $ui->vars->url), 'horde.success');
641:         } elseif ($ui->vars->rpc_delete) {
642:             if ($ui->vars->server == -1) {
643:                 $notification->push(_("You must select an server to be deleted."), 'horde.warning');
644:             } else {
645:                 $notification->push(sprintf(_("The server \"%s\" has been deleted."), $rpc_servers[$ui->vars->server]['url']), 'horde.success');
646: 
647:                 $deleted_server = $rpc_servers[$ui->vars->server]['url'];
648:                 unset($rpc_servers[$ui->vars->server]);
649:                 $prefs->setValue('remote_summaries', serialize(array_values($rpc_servers)));
650: 
651:                 $chosenColumns = explode(';', $prefs->getValue('show_summaries'));
652:                 if ($chosenColumns != array('')) {
653:                     $newColumns = array();
654:                     foreach ($chosenColumns as $chosenColumn) {
655:                         $chosenColumn = explode(',', $chosenColumn);
656:                         $remote = explode('|', $chosenColumn[0]);
657:                         if (count($remote) != 3 || $remote[2] == $deleted_server) {
658:                             $newColumns[] = implode(',', $chosenColumn);
659:                         }
660:                     }
661:                     $prefs->setValue('show_summaries', implode(';', $newColumns));
662:                 }
663:             }
664:         }
665:     }
666: 
667:     /**
668:      * Update SyncML related preferences.
669:      *
670:      * @param Horde_Core_Prefs_Ui $ui  The UI object.
671:      */
672:     protected function _updateSyncmlManagement($ui)
673:     {
674:         $backend = Horde_SyncMl_Backend::factory('Horde');
675: 
676:         if ($ui->vars->removedb && $ui->vars->removedevice) {
677:             try {
678:                 $backend->removeAnchor($GLOBALS['registry']->getAuth(), $ui->vars->removedevice, $ui->vars->removedb);
679:                 $backend->removeMaps($GLOBALS['registry']->getAuth(), $ui->vars->removedevice, $ui->vars->removedb);
680:                 $GLOBALS['notification']->push(sprintf(_("Deleted synchronization session for device \"%s\" and database \"%s\"."), $ui->vars->deviceid, $ui->vars->db), 'horde.success');
681:             } catch (Horde_Exception $e) {
682:                 $GLOBALS['notification']->push(_("Error deleting synchronization session:") . ' ' . $e->getMessage(), 'horde.error');
683:             }
684:         } elseif ($ui->vars->deleteall) {
685:             try {
686:                 $backend->removeAnchor($GLOBALS['registry']->getAuth());
687:                 $backend->removeMaps($GLOBALS['registry']->getAuth());
688:                 $GLOBALS['notification']->push(_("All synchronization sessions deleted."), 'horde.success');
689:             } catch (Horde_Exception $e) {
690:                 $GLOBALS['notification']->push(_("Error deleting synchronization sessions:") . ' ' . $e->getMessage(), 'horde.error');
691:             }
692:         }
693:     }
694: 
695:     /**
696:      * Update ActiveSync actions
697:      *
698:      * @param Horde_Core_Prefs_Ui $ui  The UI object.
699:      */
700:     protected function _updateActiveSyncManagement($ui)
701:     {
702:         $stateMachine = $GLOBALS['injector']->getInstance('Horde_ActiveSyncState');
703:         $stateMachine->setLogger($GLOBALS['injector']->getInstance('Horde_Log_Logger'));
704:         try {
705:             if ($ui->vars->wipeid) {
706:                 $stateMachine->loadDeviceInfo($ui->vars->wipeid, $GLOBALS['registry']->getAuth());
707:                 $stateMachine->setDeviceRWStatus($ui->vars->wipeid, Horde_ActiveSync::RWSTATUS_PENDING);
708:                 $GLOBALS['notification']->push(sprintf(_("A remote wipe for device id %s has been initiated. The device will be wiped during the next synchronisation."), $ui->vars->wipe));
709:             } elseif ($ui->vars->cancelwipe) {
710:                 $stateMachine->loadDeviceInfo($ui->vars->cancelwipe, $GLOBALS['registry']->getAuth());
711:                 $stateMachine->setDeviceRWStatus($ui->vars->cancelwipe, Horde_ActiveSync::RWSTATUS_OK);
712:                 $GLOBALS['notification']->push(sprintf(_("The Remote Wipe for device id %s has been cancelled."), $ui->vars->wipe));
713:             } elseif ($ui->vars->reset) {
714:                 $devices = $stateMachine->listDevices($GLOBALS['registry']->getAuth());
715:                 foreach ($devices as $device) {
716:                     $stateMachine->removeState(null, $device['device_id'], $GLOBALS['registry']->getAuth());
717:                 }
718:                 $GLOBALS['notification']->push(_("All state removed for your ActiveSync devices. They will resynchronize next time they connect to the server."));
719:             } elseif ($ui->vars->removedevice) {
720:                 $stateMachine->removeState(null, $ui->vars->removedevice, $GLOBALS['registry']->getAuth());
721:                 $GLOBALS['notification']->push(sprintf(_("The state for device id %s has been reset. It will resynchronize next time it connects to the server."), $ui->vars->removedevice));
722:             }
723:         } catch (Horde_ActiveSync_Exception $e) {
724:             $GLOBALS['notification']->push(_("There was an error communicating with the ActiveSync server: %s"), $e->getMessage(), 'horde.err');
725:         }
726:     }
727: 
728:     /**
729:      * Update facebook related prefs
730:      *
731:      * @param Horde_Core_Prefs_Ui $ui  The UI object.
732:      */
733:     protected function _updateFacebookManagement($ui)
734:     {
735:         global $prefs;
736: 
737:         try {
738:             $facebook = $GLOBALS['injector']->getInstance('Horde_Service_Facebook');
739:         } catch (Horde_Exception $e) {
740:             return _($e->getMessage());
741:         }
742:         try {
743:             switch ($ui->vars->fbactionID) {
744:             case 'revokeInfinite':
745:                 $facebook->auth->revokeExtendedPermission(Horde_Service_Facebook_Auth::EXTEND_PERMS_OFFLINE);
746:                 break;
747:             case 'revokeApplication':
748:                 $facebook->auth->revokeAuthorization();
749:                 $prefs->setValue('facebook', array('uid' => '',
750:                                                    'sid' => ''));
751:                 break;
752:             case 'revokePublish':
753:                 $facebook->auth->revokeExtendedPermission(Horde_Service_Facebook_Auth::EXTEND_PERMS_PUBLISHSTREAM);
754:                 break;
755:             case 'revokeRead':
756:                 $facebook->batchBegin();
757:                 $facebook->auth->revokeExtendedPermission(Horde_Service_Facebook_Auth::EXTEND_PERMS_READSTREAM);
758:                 $facebook->auth->revokeExtendedPermission(Horde_Service_Facebook_Auth::EXTEND_PERMS_USER_ABOUT);
759:                 $facebook->auth->revokeExtendedPermission(Horde_Service_Facebook_Auth::EXTEND_PERMS_USER_HOMETOWN);
760:                 $facebook->auth->revokeExtendedPermission(Horde_Service_Facebook_Auth::EXTEND_PERMS_USER_LOCATION);
761:                 $facebook->auth->revokeExtendedPermission(Horde_Service_Facebook_Auth::EXTEND_PERMS_USER_PHOTOS);
762:                 $facebook->batchEnd();
763:                 $facebook->batchBegin();
764:                 $facebook->auth->revokeExtendedPermission(Horde_Service_Facebook_Auth::EXTEND_PERMS_USER_BIRTHDAY);
765:                 $facebook->auth->revokeExtendedPermission(Horde_Service_Facebook_Auth::EXTEND_PERMS_USER_EVENTS);
766:                 $facebook->batchEnd();
767:                 break;
768:             case 'revokeFriends':
769:                 $facebook->batchBegin();
770:                 $facebook->auth->revokeExtendedPermission(Horde_Service_Facebook_Auth::EXTEND_PERMS_FRIENDS_ABOUT);
771:                 $facebook->auth->revokeExtendedPermission(Horde_Service_Facebook_Auth::EXTEND_PERMS_FRIENDS_BIRTHDAY);
772:                 $facebook->auth->revokeExtendedPermission(Horde_Service_Facebook_Auth::EXTEND_PERMS_FRIENDS_HOMETOWN);
773:                 $facebook->auth->revokeExtendedPermission(Horde_Service_Facebook_Auth::EXTEND_PERMS_FRIENDS_LOCATION);
774:                 $facebook->auth->revokeExtendedPermission(Horde_Service_Facebook_Auth::EXTEND_PERMS_FRIENDS_PHOTOS);
775:                 $facebook->batchEnd();
776:                 break;
777:             }
778:         } catch (Horde_Service_Facebook_Exception $e) {
779:             $GLOBALS['notification']->push($e->getMessage(), 'horde.error');
780:         }
781:     }
782: 
783:     protected function _updateTwitterManagement($ui)
784:     {
785:         global $prefs, $registry;
786: 
787:         $twitter = $GLOBALS['injector']->getInstance('Horde_Service_Twitter');
788:         $token = unserialize($prefs->getValue('twitter'));
789: 
790:         /* Check for an existing token */
791:         if (!empty($token['key']) && !empty($token['secret'])) {
792:             $auth_token = new Horde_Oauth_Token($token['key'], $token['secret']);
793:             $twitter->auth->setToken($auth_token);
794:         }
795: 
796:         switch ($ui->vars->twitteractionID) {
797:         case 'revokeInfinite':
798:             $twitter->account->endSession();
799:             $prefs->setValue('twitter', 'a:0:{}');
800:             echo '<script type="text/javascript">location.href="' . Horde::url('services/prefs.php', true)->add(array('group' => 'twitter', 'app'  => 'horde')) . '";</script>';
801:             exit;
802:         }
803:     }
804: }
805: 
API documentation generated by ApiGen