Kronolith::subscribeRemoteCalendar PHP 메소드

subscribeRemoteCalendar() 공개 정적인 메소드

Subscribes to or updates a remote calendar.
public static subscribeRemoteCalendar ( array &$info, string $update = false )
$info array Hash with calendar information.
$update string If present, the original URL of the calendar to update.
    public static function subscribeRemoteCalendar(&$info, $update = false)
    {
        if (!(strlen($info['name']) && strlen($info['url']))) {
            throw new Kronolith_Exception(_("You must specify a name and a URL."));
        }
        if (!empty($info['user']) || !empty($info['password'])) {
            $key = $GLOBALS['registry']->getAuthCredential('password');
            if ($key) {
                $secret = $GLOBALS['injector']->getInstance('Horde_Secret');
                $info['user'] = base64_encode($secret->write($key, $info['user']));
                $info['password'] = base64_encode($secret->write($key, $info['password']));
            }
        }
        $remote_calendars = unserialize($GLOBALS['prefs']->getValue('remote_cals'));
        if ($update) {
            foreach ($remote_calendars as $key => $calendar) {
                if ($calendar['url'] == $update) {
                    $remote_calendars[$key] = $info;
                    break;
                }
            }
        } else {
            $remote_calendars[] = $info;
            $display_remote = $GLOBALS['calendar_manager']->get(Kronolith::DISPLAY_REMOTE_CALENDARS);
            $display_remote[] = $info['url'];
            $GLOBALS['calendar_manager']->set(Kronolith::DISPLAY_REMOTE_CALENDARS, $display_remote);
            $GLOBALS['prefs']->setValue('display_remote_cals', serialize($display_remote));
        }
        $GLOBALS['prefs']->setValue('remote_cals', serialize($remote_calendars));
    }

Usage Example

예제 #1
0
 /**
  * @throws Kronolith_Exception
  */
 public function execute()
 {
     switch ($this->_vars->submitbutton) {
         case _("Save"):
             $info = array();
             foreach (array('name', 'new_url', 'user', 'password', 'color', 'desc') as $key) {
                 $info[$key == 'new_url' ? 'url' : $key] = $this->_vars->get($key);
             }
             Kronolith::subscribeRemoteCalendar($info, trim($this->_vars->get('url')));
             break;
         case _("Unsubscribe"):
             Horde::url('calendars/remote_unsubscribe.php')->add('url', $this->_vars->url)->redirect();
             break;
         case _("Cancel"):
             Horde::url($GLOBALS['prefs']->getValue('defaultview') . '.php', true)->redirect();
             break;
     }
 }
All Usage Examples Of Kronolith::subscribeRemoteCalendar