Skip to content

Instantly share code, notes, and snippets.

@tobya
Created March 23, 2011 20:14
Show Gist options
  • Save tobya/883850 to your computer and use it in GitHub Desktop.
Save tobya/883850 to your computer and use it in GitHub Desktop.
The outline Structure of a PList file used by ContactLoader
<plist version="1.0">
<dict>
<key>GroupName</key>
<string>Name of Your Group</string>
<key>Contacts</key>
<array>
<dict>
<key>FirstName</key>
<string>Toby</string>
<key>LastName</key>
<string>Allen</string>
<key>Telephone_Mobile</key>
<string>00353214646785</string>
<key>Telephone_Home</key>
<string>00353214646785</string>
<key>Email_Home</key>
<string>contactloader@toflidium.com</string>
<key>Email_Work</key>
<string>contactloader@toflidium.com</string>
<key>Company</key>
<string></string>
<key>JobTitle</key>
<string></string>
<key>Department</key>
<string>Kitchen</string>
<key>Street</key>
<string>A Street</string>
<key>City</key>
<string></string>
<key>State</key>
<string>Cork</string>
<key>Zip</key>
<string></string>
<key>Country</key>
<string>Ireland</string>
<key>YourRefUniqueID</key>
<string>21824</string>
<key>Notes</key>
<string>Any additional Notes you wish to put in the
notes field on your contact.
Perhaps Address details and info
about them.</string>
<key>ImageURL</key>
<string>http://www.example.com/path/to/image.jpg</string>
</dict>
<dict>
<key>FirstName</key>
<string>Shorter</string>
<key>LastName</key>
<string>Contact</string>
<key>Telephone_Mobile</key>
<string></string>
<key>Telephone_Home</key>
<string></string>
<key>Email_Home</key>
<string></string>
<key>Email_Work</key>
<string></string>
<key>EventContactsUniqueID</key>
<string></string>
<key>Notes</key>
<string></string>
<key>ImageURL</key>
<string></string>
</dict> </array>
</dict>
</plist>
<?php
/**************************************************************************
Sample php file for ContactLoader Iphone App to create plist file of contacts.
Author: Toby Allen.
Licence: Public Domains use as you wish.
**************************************************************************/
//Create Array with all contact information you wish to use.
//This array can be populated manually as in this example, or
//by connecting to your local database.
$ContactInfo = array('GroupName' => 'Vegetable Contacts', 'Contacts' => array());
$ContactInfo['Contacts'][] = array('FirstName' => 'Tom',
'LastName' => 'Tomato',
'Telephone_Home' => '003535555555',
'Telephone_Mobile' => '00353875555555',
'Email_Home' => 'tomtomato@toflidium.com',
'Email_Work' => '',
'Street' => 'First Row',
'City' => 'Green House St',
'State' => 'Green House A',
'Zip' => 'GG',
'Country' => 'Tomato Land',
'YourRefUniqueID' => 'Tomato1',
'Notes' => 'Tom Tastes nice and Juicy',
'ImageURL' => 'http://iphone.toflidium.com/contactloader/data/test/tomato.png');
$ContactInfo['Contacts'][] = array('FirstName' => 'Anna',
'LastName' => 'Aubergine',
'Telephone_Home' => '003535555555',
'Telephone_Mobile' => '00353875555555',
'Email_Home' => 'annaaubergine@toflidium.com',
'Email_Work' => '',
'Street' => 'Second Row',
'City' => 'Green House St',
'State' => 'Green House A',
'Zip' => 'GG',
'Country' => 'Tomato Land',
'YourRefUniqueID' => 'Eggplant1',
'Notes' => 'Anna Aubergine likes to be rubbed all over with Olive Oil!',
'ImageURL' => 'http://iphone.toflidium.com/contactloader/data/test/eggplant.png');
/*
This is a useful template for new entries.
$ContactInfo[] = array('FirstName' => '',
'LastName' => '',
'Telephone_Home' => '',
'Telephone_Mobile' => '',
'Email_Home' => '',
'Email_Work' => '',
'Street' => '',
'City' => '',
'State' => '',
'Zip' => '',
'Country' => '',
'YourRefUniqueID' => '',
'Notes' => '',
'ImageURL' => '');
*/
/*
PList Generation
*/
//Cycle Through Array and print out Values to a XML string
$ContactOutput = '';
foreach($ContactInfo['Contacts'] as $Contact)
{
$Values = '';
foreach($Contact as $FieldName => $FieldValue)
{
$HTMLValue = htmlentities($FieldValue);
//HTML entities such as &amp; and Unicode chars need to be enclosed in <![CDATA[ ]]> tags for
//the iphone to recognise them, so just do it for every value to be sure, althoug only ones that
//do contain these characters definitely need to . If this doesnt happen ContactLoader will be
//unable to read your file.
$Values .= "
<key>$FieldName</key>
<string><![CDATA[$HTMLValue]]></string>";
}
//Finish off Contact XML.
$ContactOutput .= "
<dict>
$Values
</dict>";
};
//Wrap with necessary XML to complete.
$FullPage = "<plist version=\"1.0\">
<dict>
<key>GroupName</key>
<string>$ContactInfo[GroupName]</string>
<key>Contacts</key>
<array>
$ContactOutput
</array>
</dict>
</plist> ";
echo $FullPage;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment