The function definition needs to include all necessary configuration files, etc.
<?php
// Find the base file path of Turba if (!defined('TURBA_BASE')) define('TURBA_BASE', dirname(__FILE__) . '/..');
// Include the Turba base libraries and setup. require_once TURBA_BASE . '/lib/base.php';
function turbaExpandAddresses($names = array(), $addressbooks = array()) { include TURBA_BASE . '/config/sources.php'; include_once TURBA_BASE . '/lib/Source.php';
if (!isset($cfgSources) || !is_array($cfgSources) || !count($cfgSources)) { return array(); }
if (count($addressbooks) == 0) { $addressbooks = array(key($cfgSources)); }
$results = array(); foreach ($addressbooks as $source) { if (isset($cfgSources[$source])) { $driver = new Turba_Source($source, $cfgSources[$source]['title'], $cfgSources[$source]['type'], $cfgSources[$source]['params'], $cfgSources[$source]['map'], $cfgSources[$source]['public'], $cfgSources[$source]['readonly']); foreach ($names as $name) { $res = $driver->search(array('name' => trim($name)), LASTNAME); if (!isset($results[$name])) { $results[$name] = array(); } if (get_class($res) == 'turba_list') { while ($ob = $res->next()) { $results[$name][] = array('name' => $ob->getValue('name'), 'email' => $ob->getValue('email')); } } } } } return $results; }
function turbaAddAddress($name = '', $address = '', $addressbook = '') { include TURBA_BASE . '/config/sources.php'; include_once 'PEAR.php'; include_once TURBA_BASE . '/lib/Source.php';
if (empty($addressbook) || !isset($cfgSources[$addressbook])) { return PEAR::raiseError(_("Invalid addressbook.")); }
if (empty($name)) { return PEAR::raiseError(_("Invalid name.")); }
if (empty($address)) { return PEAR::raiseError(_("Invalid e-mail address.")); }
if ($cfgSources[$addressbook]['readonly']) { return PEAR::raiseError(_("Addressbook is read-only.")); }
$driver = new Turba_Source($addressbook, $cfgSources[$addressbook]['title'], $cfgSources[$addressbook]['type'], $cfgSources[$addressbook]['params'], $cfgSources[$addressbook]['map'], $cfgSources[$addressbook]['public'], $cfgSources[$addressbook]['readonly']);
return $driver->addObject(array('name' => $name, 'email' => $address, '__owner' => Auth::getAuth())); }
function turbaGetSources($writeable = false) { include TURBA_BASE . '/config/sources.php'; include_once 'PEAR.php';
if (!isset($cfgSources) || !is_array($cfgSources) || !count($cfgSources)) { return array(); }
$readonly = array(); $writeonly = array();
foreach ($cfgSources as $key => $entry) { if ($entry['readonly']) { $readonly[$key] = $entry['title']; } else { $writeonly[$key] = $entry['title']; } }
if ($writeable) { return $writeonly; } else { return array_merge($readonly, $writeonly); } }
?>
|