Merge pull request #5 from club-1/feat-preinstalled-sources
feat: add preinstalled sources
This commit is contained in:
commit
f0a90df1d3
2 changed files with 50 additions and 0 deletions
|
@ -143,6 +143,20 @@ $config['kolab_invitation_calendars'] = false;
|
|||
// %i - Calendar UUID
|
||||
// $config['calendar_caldav_url'] = 'http://%h/iRony/calendars/%u/%i';
|
||||
|
||||
// List of CalDAV sources that should be allready installed.
|
||||
// They will be added when the calendar section is accessed for the first time by a user.
|
||||
// For 'caldav_user' and 'caldav_url' the following replacement variables are supported:
|
||||
// %u - Current webmail user name
|
||||
// For 'caldav_pass' %p is replaced by the current user's password.
|
||||
// $config['calendar_caldav_preinstalled_sources'] = array(
|
||||
// 'name' => array(
|
||||
// 'caldav_user' => '%u',
|
||||
// 'caldav_pass' => '%p',
|
||||
// 'caldav_url' => 'https://example.net/dav',
|
||||
// 'showAlarms' => 1
|
||||
// )
|
||||
// );
|
||||
|
||||
// Driver to provide a resource directory ('ldap' is the only implementation yet).
|
||||
// Leave empty or commented to disable resources support.
|
||||
// $config['calendar_resources_driver'] = 'ldap';
|
||||
|
|
|
@ -101,9 +101,41 @@ class caldav_driver extends calendar_driver
|
|||
if(self::$debug === null)
|
||||
self::$debug = $this->rc->config->get('calendar_caldav_debug', False);
|
||||
|
||||
$this->_setup_preinstalled_sources();
|
||||
$this->_read_calendars();
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup preinstalled sources defined in config file
|
||||
*/
|
||||
protected function _setup_preinstalled_sources()
|
||||
{
|
||||
$preinstalled_sources = $this->rc->config->get('calendar_caldav_preinstalled_sources', FALSE);
|
||||
if ($preinstalled_sources && is_array($preinstalled_sources)) {
|
||||
$username = $this->rc->get_user_name();
|
||||
$password = $this->rc->get_user_password();
|
||||
|
||||
foreach ($preinstalled_sources as $cal){
|
||||
$url = $cal['caldav_url'];
|
||||
$user = $cal['caldav_user'];
|
||||
$pass = $cal['caldav_pass'];
|
||||
|
||||
$url = str_replace('%u', $username, $url);
|
||||
$user = str_replace('%u', $username, $user);
|
||||
$pass = str_replace('%p', $password, $pass);
|
||||
|
||||
$cal['caldav_url'] = $url;
|
||||
$cal['caldav_user'] = $user;
|
||||
$cal['caldav_pass'] = $pass;
|
||||
|
||||
if (!$this->create_source($cal)) {
|
||||
$error_msg = 'Unable to add default calendars' . ($this->last_error ? ': ' . $this->last_error :'');
|
||||
$this->rc->output->show_message($error_msg, 'error');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read available calendars for the current user and store them internally
|
||||
*/
|
||||
|
@ -302,6 +334,10 @@ class caldav_driver extends calendar_driver
|
|||
{
|
||||
$source['caldav_url'] = self::_encode_url($source['caldav_url']);
|
||||
|
||||
// Skip already exiting sources
|
||||
$result = $this->rc->db->query("SELECT user_id, caldav_url, caldav_user FROM " . $this->db_sources . " WHERE user_id=? AND caldav_url=? AND caldav_user=?", $this->rc->user->ID, $source['caldav_url'], $source['caldav_user']);
|
||||
if($this->rc->db->affected_rows($result)) return true;
|
||||
|
||||
try {
|
||||
$calendars = $this->_autodiscover_calendars($source);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue