Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
some updates to contacts including better addresses and vcf downloader
- Loading branch information
1 parent
ed00044
commit 7da7898
Showing
13 changed files
with
328 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,15 @@ | ||
<?php | ||
class ContactAppController extends AppController { | ||
var $helpers = array( | ||
'Filter.Filter' | ||
'Filter.Filter', | ||
'Contact.Vcf', | ||
'Html' | ||
); | ||
|
||
function beforeFilter(){ | ||
parent::beforeFilter(); | ||
|
||
$this->RequestHandler->setContent('vcf', 'text/x-vcard'); | ||
} | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
echo $this->Vcf->begin(); | ||
echo $this->Vcf->attr('organization', Configure::read('Website.name')); | ||
echo $this->Vcf->attr('fullName', $branch['Branch']['name']); | ||
echo $this->Vcf->attr('email', $branch['Branch']['name']); | ||
echo $this->Vcf->attr('url', env('SERVER_NAME')); | ||
echo $this->Vcf->attr('image', $this->Html->url('/img/content/contact/branch/'.$branch['Branch']['image'], true)); | ||
echo $this->Vcf->address( | ||
$branch['Address']['name'], | ||
array( | ||
'country' => $branch['Address']['Country']['name'], | ||
'province' => $branch['Address']['province'], | ||
'postal' => $branch['Address']['postal'], | ||
'city' => $branch['Address']['city'], | ||
'street' => $branch['Address']['street'] | ||
) | ||
); | ||
echo $this->Vcf->end(); | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
TODO | ||
|
||
<?php | ||
pr($branch); | ||
pr($_SERVER); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
<?php | ||
/** | ||
* | ||
* vCard Helper | ||
* | ||
* Helps with the creation of vCard files | ||
*/ | ||
class VcfHelper extends AppHelper { | ||
/** | ||
* Element map | ||
* map element names to vcard elements | ||
* | ||
* @var array | ||
*/ | ||
protected $_elements = array( | ||
'name' => 'N:%last%;%first%;%middle%;%title%', | ||
'fullName' => 'FN:%value%', | ||
'organization' => 'ORG:%value%', | ||
'title' => 'TITLE:%value%', | ||
'workPhone' => 'TEL;WORK:%value%', | ||
'homePhone' => 'TEL;HOME:%value%', | ||
'cellPhone' => 'TEL;CELL:%value%', | ||
'address' => 'ADR', | ||
'birthday' => 'BDAY:%value%', | ||
'email' => 'EMAIL;INTERNET:%value%', | ||
'timezone' => 'TZ:%value%', | ||
'url' => 'URL:%value%', | ||
'version' => 'VERSION:%value%', | ||
'image' => 'PHOTO;VALUE=URL:%value%', | ||
); | ||
/** | ||
* Separator between values. | ||
* | ||
* @var string | ||
**/ | ||
protected $_separator = ':'; | ||
/** | ||
* End of line character | ||
* | ||
* @var string | ||
**/ | ||
protected $_eol = "\n"; | ||
/** | ||
* End of attribute terminator. | ||
* | ||
* @var string | ||
**/ | ||
protected $_terminator = ';'; | ||
/** | ||
* Overloaded call method | ||
* | ||
* @param string $method Name of method called | ||
* @param mixed $params Params for method. | ||
* @return mixed | ||
**/ | ||
public function __call($method, $params) { | ||
if (isset($this->_elements[$method])) { | ||
array_unshift($params, $method); | ||
return $this->dispatchMethod('attr', $params); | ||
} | ||
trigger_error($method . ' is not a valid element.', E_USER_WARNING); | ||
} | ||
/** | ||
* begin a vcard | ||
* | ||
* @return string | ||
*/ | ||
public function begin() { | ||
return "BEGIN:VCARD" . $this->_eol; | ||
} | ||
/** | ||
* End a vcard | ||
* | ||
* @return string | ||
*/ | ||
public function end() { | ||
return "END:VCARD" . $this->_eol; | ||
} | ||
/** | ||
* Create a new attribute for the vCard | ||
* | ||
* @param string $type Type of element to make | ||
* @param string $value Value to put into the card | ||
* @return mixed False on non-existant type or empty values, string on success | ||
*/ | ||
public function attr($type, $values) { | ||
if (empty($values)) { | ||
return false; | ||
} | ||
if (is_string($values)) { | ||
$values = array('value' => $values); | ||
} | ||
|
||
if ($type != 'image') { | ||
$values = $this->_escape($values); | ||
} | ||
|
||
if (!isset($this->_elements[$type])) { | ||
return false; | ||
} | ||
$out = String::insert($this->_elements[$type], | ||
$values, array('clean' => true, 'before' => '%', 'after' => '%') | ||
); | ||
return $out . $this->_eol; | ||
} | ||
|
||
/** | ||
* Create an Address element. Takes the following keys | ||
* | ||
* - street | ||
* - city | ||
* - province | ||
* - postal | ||
* - country | ||
* | ||
* @param string $type The type of address you are making | ||
* @param array $values Array of values for the address see above | ||
*/ | ||
public function address($type, $values = array()) { | ||
$empty = array( | ||
'street' => '', | ||
'city' => '', | ||
'province' => '', | ||
'postal' => '', | ||
'country' => '', | ||
); | ||
$values = array_merge($empty, $values); | ||
$values['key'] = $this->_elements['address']; | ||
$values['type'] = strtoupper($type); | ||
|
||
$format = "%key%;%type%:;;%street%;%city%;%province%;%postal%;%country%;"; | ||
$adrEl = String::insert($format, $values, array('before' => '%', 'after' => '%', 'clean' => true)); | ||
$labelFormat = "LABEL;POSTAL;%type%;ENCODING=QUOTED-PRINTABLE:%street%=0D=0A%city%, %province% %postal%=0D=0A%country%"; | ||
$labelEl = String::insert($labelFormat, $values, array('before' => '%', 'after' => '%', 'clean' => true)); | ||
|
||
return $adrEl . $this->_eol . $labelEl . $this->_eol; | ||
} | ||
/** | ||
* Escape values for vcard | ||
* | ||
* @param mixed $values Values either string or array. | ||
* @return string Escaped string | ||
**/ | ||
protected function _escape($values) { | ||
$find = array(':'); | ||
$replace = array('\:'); | ||
return is_array($values) ? array_map(array($this, '_escape'), $values) : str_replace($find, $replace, $values); | ||
} | ||
|
||
} | ||
?> |
Oops, something went wrong.