-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfritz2starface.php
118 lines (96 loc) · 3.45 KB
/
fritz2starface.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
work();
function getFritzboxData()
{
$path = __DIR__.'/fritzbox.xml';
$xml = new SimpleXMLElement( $path, 0, true );
$i = 0;
foreach($xml->phonebook->contact as $contact)
{
$aData[$i]['name'] = (string) $contact->person->realName;
$aData[$i] = array_merge($aData[$i], selectNumbers($contact->telephony));
$i++;
}
return $aData;
}
function selectNumbers( $phonenode )
{
$aNumbers = array();
foreach($phonenode->number as $number)
{
switch((string)$number['type'])
{
case 'work':
$aNumbers['work'] = (string) $number;
break;
case 'home':
$aNumbers['home'] = (string) $number;
break;
case 'mobile':
$aNumbers['mobile'] = (string) $number;
break;
}
}
return $aNumbers;
}
function generateFullEntry( $aContact )
{
$aEntry = array();
$aEntry['Vorname [contact:firstname]'] = '';
$aEntry['Name [contact:familyname]'] = $aContact['name'];
$aEntry['Firma [contact:company]'] = '';
$aEntry['Straße [address:street]'] = '';
$aEntry['PLZ [address:postcode]'] = '';
$aEntry['Stadt [address:city]'] = '';
$aEntry['Bundesland [address:state]'] = '';
$aEntry['Rufnummer [telephone:phone]'] = $aContact['work'];
$aEntry['Rufnummer [telephone:short dial(phone)]'] = '';
$aEntry['Privat [telephone:homephone]'] = $aContact['home'];
$aEntry['Privat [telephone:short dial(homephone)]'] = '';
$aEntry['Mobil [telephone:mobile]'] = $aContact['mobile'];
$aEntry['Mobil [telephone:short dial(mobile)]'] = '';
$aEntry['Fax [telephone:fax]'] = '';
$aEntry['Fax [telephone:short dial(fax)]'] = '';
$aEntry['E-Mail [email:e-mail]'] = '';
$aEntry['URL [email:url]'] = '';
return $aEntry;
}
function exportToCsv( $aData )
{
$fh = fopen( 'starface.csv', 'w' );
$header = array(
'Vorname [contact:firstname]',
'Name [contact:familyname]',
'Firma [contact:company]',
'Straße [address:street]',
'PLZ [address:postcode]',
'Stadt [address:city]',
'Bundesland [address:state]',
'Rufnummer [telephone:phone]',
'Rufnummer [telephone:short dial(phone)]',
'Privat [telephone:homephone]',
'Privat [telephone:short dial(homephone)]',
'Mobil [telephone:mobile]',
'Mobil [telephone:short dial(mobile)]',
'Fax [telephone:fax]',
'Fax [telephone:short dial(fax)]',
'E-Mail [email:e-mail]',
'URL [email:url]'
);
fputcsv( $fh, $header, ';');
foreach ( $aData as $row ) {
fputcsv( $fh, $row, ';');
}
fclose($fh);
}
function work()
{
$aSourceData = getFritzboxData();
$aFullData = array();
foreach( $aSourceData as $aContact)
{
$aFullData[] = generateFullEntry( $aContact );
}
exportToCsv( $aFullData );
echo "Finished export!\n<br><a href='starface.csv'>Download the starface.csv</a>";
}