So I searched for this and struggled. Memotoo has an LDAP service that can sync, but you can’t browse, only search. Polycom phones also don’t lookup caller ID against this.
So I wrote this:
<?php
$debug = false | isset($_GET['debug']);
$username = 'memotoo username';
$password = 'memotoo password';
$requestURI = "https://www.memotoo.com/contactsCSV.php?login=" . $username . "&password=" . md5($password);
$tempfile = './temp.csv';
$result = copySecureFile($requestURI, $tempfile) or die ("couldn't open file");
if ($debug) print $result;
$file = fopen($tempfile,"r");
$_data = array();
$headers = fgetcsv($file);
while($row = fgetcsv($file))
{
array_push($_data, $row);
};
fclose($file);
if ($debug) print ('\r printing data from CSV\r');
if ($debug) print_r($_data);
$_rdata = array();
$_drkeys = array('lastname' => 1, 'firstname' => 2, 'workphone' => 22, 'homephone' => 19, 'personalmob' => 20, 'workmob' => 23, 'company' => 4);
if ($debug) print ('\r Checking for names\r');
for ($i = 0; $i < count($_data); $i++) {
if ((strlen($_data[$i][$_drkeys['lastname']]) > 0) || (strlen($_data[$i][$_drkeys['firstname']]) > 0) || (strlen($_data[$i][$_drkeys['company']]) > 0)) {
array_push($_rdata, array($_data[$i][$_drkeys['lastname']],
$_data[$i][$_drkeys['firstname']],
$_data[$i][$_drkeys['company']],
$_data[$i][$_drkeys['workphone']],
$_data[$i][$_drkeys['homephone']],
$_data[$i][$_drkeys['personalmob']],
$_data[$i][$_drkeys['workmob']],
));
} else {
if ($debug) print ('\r no name for row ' . $i . '\r');
}
}
if ($debug) print_r($_rdata);
//dispose original data
unset($_data);
if ($debug) print ('\r Now to regenerate for phone numbers \r');
$_xdata = array();
for ($i = 0; $i < count($_rdata); $i++) {
// Loop through $_rdata
$_phonenos = array();
if (strlen($_rdata[$i][3]) > 0) array_push($_phonenos, array($_rdata[$i][3], ' (Work)'));
if (strlen($_rdata[$i][4]) > 0) array_push($_phonenos, array($_rdata[$i][4], ' (Home)'));
if (strlen($_rdata[$i][5]) > 0) array_push($_phonenos, array($_rdata[$i][5], ' (Mobile)'));
if (strlen($_rdata[$i][6]) > 0) array_push($_phonenos, array($_rdata[$i][6], ' (Work Mob.)'));
for ($j = 0; $j < count($_phonenos); $j++)
{
array_push($_xdata,
array(
$_rdata[$i][0], //ln
$_rdata[$i][1], //fn
$_rdata[$i][1] . " " . $_rdata[$i][0] . $_phonenos[$j][1], //lb
$_phonenos[$j][0], //ct
)
);
}
};
if ($debug) print_r($_xdata);
?>
<?xml version="1.0" encoding="UTF-8" standalone="true"?>
<!-- $RCSfile$ $Revision: 35928 $ -->
<directory>
<item_list>
<?php
if ($debug) print 'Array count ' . count($_xdata);
for ($i = 0; $i < count($_xdata); $i++)
{
echo "\t\t<item>\r";
echo "\t\t\t<ln>" . $_xdata[$i][0] . "</ln>\r";
echo "\t\t\t<fn>" . $_xdata[$i][1] . "</fn>\r";
echo "\t\t\t<lb>" . $_xdata[$i][2] . "</lb>\r";
echo "\t\t\t<ct>" . $_xdata[$i][3] . "</ct>\r";
echo "\t\t</item>\r";
}
?>
</item_list>
</directory>
<?php
/**
* Copy File from HTTPS/SSL location
*
* @param string $FromLocation
* @param string $ToLocation
* @return boolean
*/
function copySecureFile($FromLocation,$ToLocation,$VerifyPeer=false,$VerifyHost=2)
{
// Initialize CURL with providing full https URL of the file location
$Channel = curl_init($FromLocation);
// Open file handle at the location you want to copy the file: destination path at local drive
$File = fopen ($ToLocation, "w");
// Set CURL options
curl_setopt($Channel, CURLOPT_FILE, $File);
// We are not sending any headers
curl_setopt($Channel, CURLOPT_HEADER, 0);
// Disable PEER SSL Verification: If you are not running with SSL or if you don't have valid SSL
curl_setopt($Channel, CURLOPT_SSL_VERIFYPEER, $VerifyPeer);
// Disable HOST (the site you are sending request to) SSL Verification,
// if Host can have certificate which is nvalid / expired / not signed by authorized CA.
curl_setopt($Channel, CURLOPT_SSL_VERIFYHOST, $VerifyHost);
// Execute CURL command
curl_exec($Channel);
// Close the CURL channel
curl_close($Channel);
// Close file handle
fclose($File);
// return true if file download is successfull
return file_exists($ToLocation);
}
?>
Which generates the appropriate xml for a 0000000000-dir.xml file. I’m just going to stick it in a cron job.
Only tested with a small contact list so far - please give it a try and feedback! It’s very hacked together so please excuse lack of customisation options / language support.
All the best,
Chris