PageRenderTime 24ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/Forms/SubscribeRemoteCalendar.php

https://github.com/Excito/kronolith
PHP | 76 lines | 42 code | 13 blank | 21 comment | 5 complexity | c00e48ec76497f04c35363679a4ac9d1 MD5 | raw file
  1. <?php
  2. /**
  3. * Horde_Form for subscribing to remote calendars.
  4. *
  5. * $Horde: kronolith/lib/Forms/SubscribeRemoteCalendar.php,v 1.1.2.1 2007/12/20 14:12:36 jan Exp $
  6. *
  7. * See the enclosed file COPYING for license information (GPL). If you
  8. * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
  9. *
  10. * @package Kronolith
  11. */
  12. /** Variables */
  13. require_once 'Horde/Variables.php';
  14. /** Horde_Form */
  15. require_once 'Horde/Form.php';
  16. /** Horde_Form_Renderer */
  17. require_once 'Horde/Form/Renderer.php';
  18. /**
  19. * The Kronolith_SubscribeRemoteCalendarForm class provides the form
  20. * for subscribing to remote calendars
  21. *
  22. * @author Chuck Hagenbuch <chuck@horde.org>
  23. * @since Kronolith 2.2
  24. * @package Kronolith
  25. */
  26. class Kronolith_SubscribeRemoteCalendarForm extends Horde_Form {
  27. function Kronolith_SubscribeRemoteCalendarForm(&$vars)
  28. {
  29. parent::Horde_Form($vars, _("Subscribe to a Remote Calendar"));
  30. $this->addVariable(_("Name"), 'name', 'text', true);
  31. $this->addVariable(_("URL"), 'url', 'text', true);
  32. $this->addVariable(_("Username"), 'username', 'text', false);
  33. $this->addVariable(_("Password"), 'password', 'password', false);
  34. $this->setButtons(array(_("Subscribe")));
  35. }
  36. function execute()
  37. {
  38. $name = trim($this->_vars->get('name'));
  39. $url = trim($this->_vars->get('url'));
  40. $username = trim($this->_vars->get('username'));
  41. $password = trim($this->_vars->get('password'));
  42. if (!(strlen($name) && strlen($url))) {
  43. return false;
  44. }
  45. if (strlen($username) || strlen($password)) {
  46. $key = Auth::getCredential('password');
  47. if ($key) {
  48. require_once 'Horde/Secret.php';
  49. $username = base64_encode(Secret::write($key, $username));
  50. $password = base64_encode(Secret::write($key, $password));
  51. }
  52. }
  53. $remote_calendars = unserialize($GLOBALS['prefs']->getValue('remote_cals'));
  54. $remote_calendars[] = array(
  55. 'name' => $name,
  56. 'url' => $url,
  57. 'user' => $username,
  58. 'password' => $password,
  59. );
  60. $GLOBALS['prefs']->setValue('remote_cals', serialize($remote_calendars));
  61. return true;
  62. }
  63. }