2021-05-28 15:49:42 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2021-05-28 16:01:42 +00:00
|
|
|
* plugins/abook_carddav/setup.php -- Main setup script
|
2021-05-28 15:49:42 +00:00
|
|
|
*
|
2021-05-28 16:01:42 +00:00
|
|
|
* SquirrelMail Address Book CardDAV Backend
|
|
|
|
* Copyright (C) 2021 Aleksei Shpakovsky
|
|
|
|
* This program is licensed under GPLv3. See COPYING for details
|
|
|
|
* based on:
|
|
|
|
* SquirrelMail Address Book Backend template
|
2021-05-28 15:49:42 +00:00
|
|
|
* Copyright (C) 2004 Tomas Kuliavas <tokul@users.sourceforge.net>
|
|
|
|
* This program is licensed under GPL. See COPYING for details
|
|
|
|
*/
|
|
|
|
|
|
|
|
// make sure SM_PATH is defined
|
|
|
|
if (!defined('SM_PATH')) {
|
|
|
|
define('SM_PATH','../../');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* init function
|
|
|
|
*/
|
2021-05-28 16:01:42 +00:00
|
|
|
function squirrelmail_plugin_init_abook_carddav() {
|
2021-05-28 15:49:42 +00:00
|
|
|
global $squirrelmail_plugin_hooks;
|
|
|
|
|
2021-05-28 16:01:42 +00:00
|
|
|
$squirrelmail_plugin_hooks['abook_init']['abook_carddav'] = 'abook_carddav_init';
|
|
|
|
$squirrelmail_plugin_hooks['abook_add_class']['abook_carddav'] = 'abook_carddav_class';
|
2021-05-30 14:18:04 +00:00
|
|
|
$squirrelmail_plugin_hooks['optpage_loadhook_display']['abook_carddav'] = 'abook_carddav_optpage';
|
|
|
|
|
2021-05-28 15:49:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialized address book backend
|
|
|
|
*/
|
2021-05-28 16:01:42 +00:00
|
|
|
function abook_carddav_init(&$argv) {
|
2021-05-30 14:31:07 +00:00
|
|
|
global $username, $data_dir;
|
2021-05-28 15:49:42 +00:00
|
|
|
// Get the arguments
|
|
|
|
$hookName = &$argv[0];
|
|
|
|
$abook = &$argv[1];
|
|
|
|
$r = &$argv[2];
|
|
|
|
|
2021-05-28 16:01:42 +00:00
|
|
|
bindtextdomain ('abook_carddav', SM_PATH . 'locale');
|
|
|
|
textdomain ('abook_carddav');
|
2021-05-28 15:49:42 +00:00
|
|
|
|
2021-05-30 14:18:04 +00:00
|
|
|
// TODO: consider multiple uris
|
|
|
|
$abook_uri = getPref($data_dir, $username, 'plugin_abook_carddav_abook_uri');
|
|
|
|
$abook_base_uri = getPref($data_dir, $username, 'plugin_abook_carddav_base_uri');
|
|
|
|
$abook_username = getPref($data_dir, $username, 'plugin_abook_carddav_username');
|
|
|
|
$abook_password = getPref($data_dir, $username, 'plugin_abook_carddav_password');
|
|
|
|
$abook_writeable = getPref($data_dir, $username, 'plugin_abook_carddav_writeable');
|
|
|
|
$abook_listing = getPref($data_dir, $username, 'plugin_abook_carddav_listing');
|
2021-05-30 14:31:07 +00:00
|
|
|
if(substr($abook_uri, 0,4) == 'http'){
|
2021-05-30 14:18:04 +00:00
|
|
|
$r=$abook->add_backend('carddav',array(
|
|
|
|
'name'=>_("CardDAV Address Book"),
|
|
|
|
'abook_uri'=>$abook_uri,
|
|
|
|
'base_uri'=>$abook_base_uri,
|
|
|
|
'username'=>$abook_username,
|
|
|
|
'password'=>$abook_password,
|
|
|
|
'writeable'=>$abook_writeable,
|
|
|
|
'listing'=>$abook_listing,
|
|
|
|
));
|
|
|
|
}
|
2021-05-28 15:49:42 +00:00
|
|
|
|
|
|
|
bindtextdomain ('squirrelmail', SM_PATH . 'locale');
|
|
|
|
textdomain ('squirrelmail');
|
|
|
|
}
|
|
|
|
|
2021-05-28 16:01:42 +00:00
|
|
|
function abook_carddav_class() {
|
2021-05-30 14:31:07 +00:00
|
|
|
global $username, $data_dir;
|
2021-05-28 16:01:42 +00:00
|
|
|
bindtextdomain ('abook_carddav', SM_PATH . 'locale');
|
|
|
|
textdomain ('abook_carddav');
|
2021-05-28 15:49:42 +00:00
|
|
|
|
2021-05-30 14:18:04 +00:00
|
|
|
// load file only if $abook_uri is set
|
|
|
|
$abook_uri = getPref($data_dir, $username, 'plugin_abook_carddav_abook_uri');
|
2021-05-30 14:31:07 +00:00
|
|
|
if(substr($abook_uri, 0,4) == 'http'){
|
2021-05-30 14:18:04 +00:00
|
|
|
require_once(SM_PATH . 'plugins/abook_carddav/abook_class.php');
|
|
|
|
}
|
2021-05-28 15:49:42 +00:00
|
|
|
|
|
|
|
bindtextdomain ('squirrelmail', SM_PATH . 'locale');
|
|
|
|
textdomain ('squirrelmail');
|
|
|
|
}
|
|
|
|
|
2021-05-30 14:18:04 +00:00
|
|
|
function abook_carddav_optpage() {
|
|
|
|
global $optpage_data;
|
|
|
|
global $username, $data_dir;
|
|
|
|
|
2021-05-30 14:40:25 +00:00
|
|
|
$abook_uri = getPref($data_dir, $username, 'plugin_abook_carddav_abook_uri');
|
|
|
|
$abook_base_uri = getPref($data_dir, $username, 'plugin_abook_carddav_base_uri');
|
|
|
|
$abook_username = getPref($data_dir, $username, 'plugin_abook_carddav_username');
|
|
|
|
$abook_password = getPref($data_dir, $username, 'plugin_abook_carddav_password');
|
|
|
|
$abook_writeable = getPref($data_dir, $username, 'plugin_abook_carddav_writeable');
|
|
|
|
$abook_listing = getPref($data_dir, $username, 'plugin_abook_carddav_listing');
|
2021-05-30 14:18:04 +00:00
|
|
|
sq_change_text_domain('abook_carddav');
|
|
|
|
$optpage_data['grps']['abook_carddav'] = _("CardDAV Address Book");
|
|
|
|
$optpage_data['vals']['abook_carddav'][] = array(
|
|
|
|
'name' => 'plugin_abook_carddav_abook_uri',
|
2021-05-30 14:31:07 +00:00
|
|
|
'caption' => _("URI of addressbook"),
|
2021-05-30 14:18:04 +00:00
|
|
|
'type' => SMOPT_TYPE_STRING,
|
2021-05-30 14:40:25 +00:00
|
|
|
'initial_value' => $abook_uri,
|
2021-05-30 14:18:04 +00:00
|
|
|
);
|
|
|
|
$optpage_data['vals']['abook_carddav'][] = array(
|
|
|
|
'name' => 'plugin_abook_carddav_base_uri',
|
2021-05-30 14:31:07 +00:00
|
|
|
'caption' => _("base URI"),
|
2021-05-30 14:18:04 +00:00
|
|
|
'type' => SMOPT_TYPE_STRING,
|
2021-05-30 14:40:25 +00:00
|
|
|
'initial_value' => $abook_base_uri,
|
2021-05-30 14:18:04 +00:00
|
|
|
);
|
2021-05-30 14:31:07 +00:00
|
|
|
$optpage_data['vals']['abook_carddav'][] = array(
|
|
|
|
'name' => 'plugin_abook_carddav_dicsover_link',
|
|
|
|
'caption' => _("Discover"),
|
|
|
|
'type' => SMOPT_TYPE_COMMENT,
|
|
|
|
'comment' => _("Use <a href=\"...\">discover</a> page to get these values"),
|
|
|
|
);
|
2021-05-30 14:18:04 +00:00
|
|
|
$optpage_data['vals']['abook_carddav'][] = array(
|
|
|
|
'name' => 'plugin_abook_carddav_username',
|
|
|
|
'caption' => _("Username"),
|
|
|
|
'type' => SMOPT_TYPE_STRING,
|
2021-05-30 14:40:25 +00:00
|
|
|
'initial_value' => $abook_username,
|
2021-05-30 14:18:04 +00:00
|
|
|
);
|
|
|
|
$optpage_data['vals']['abook_carddav'][] = array(
|
|
|
|
'name' => 'plugin_abook_carddav_password',
|
|
|
|
'caption' => _("Password"),
|
|
|
|
'type' => SMOPT_TYPE_STRING,
|
2021-05-30 14:40:25 +00:00
|
|
|
'initial_value' => $abook_password,
|
2021-05-30 14:18:04 +00:00
|
|
|
);
|
|
|
|
$optpage_data['vals']['abook_carddav'][] = array(
|
|
|
|
'name' => 'plugin_abook_carddav_writeable',
|
2021-05-30 14:40:25 +00:00
|
|
|
'caption' => _("Writeable (nickname field reserved for vcard URI)"),
|
2021-05-30 14:18:04 +00:00
|
|
|
'type' => SMOPT_TYPE_BOOLEAN,
|
2021-05-30 14:40:25 +00:00
|
|
|
'initial_value' => $abook_writeable,
|
2021-05-30 14:18:04 +00:00
|
|
|
);
|
|
|
|
$optpage_data['vals']['abook_carddav'][] = array(
|
|
|
|
'name' => 'plugin_abook_carddav_listing',
|
|
|
|
'caption' => _("Listing allowed (otherwise, only addressbook search is useful)"),
|
|
|
|
'type' => SMOPT_TYPE_BOOLEAN,
|
2021-05-30 14:40:25 +00:00
|
|
|
'initial_value' => $abook_listing,
|
2021-05-30 14:18:04 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-28 15:49:42 +00:00
|
|
|
/**
|
|
|
|
* shows plugin's version
|
|
|
|
* @return string
|
|
|
|
*/
|
2021-05-28 16:01:42 +00:00
|
|
|
function abook_carddav_version() {
|
2021-05-28 15:49:42 +00:00
|
|
|
return '1.0';
|
|
|
|
}
|
2021-05-28 16:01:42 +00:00
|
|
|
?>
|