HcardHelper.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. App::uses('AppHelper', 'View/Helper');
  3. /**
  4. * Helper for hcard, vcard and other microformats!
  5. *
  6. * TODO: import http://codeigniter.com/wiki/microformats/
  7. */
  8. class HcardHelper extends AppHelper {
  9. protected $_defaults = [
  10. 'given_name' => 'Firstname',
  11. 'middle_name' => 'Middlename',
  12. 'family_name' => 'Lastname',
  13. 'organization' => 'OrganizationName',
  14. 'street' => '123 Street',
  15. 'city' => 'City',
  16. 'province' => 'Province/State',
  17. 'postal_code' => 'Postal/Zip',
  18. 'country' => 'Country',
  19. 'phone' => 'phonenumber',
  20. 'email' => 'email@yoursite.com',
  21. 'url' => 'http://yoursite.com',
  22. 'aim_screenname' => 'aimname',
  23. 'yim_screenname' => 'yimname',
  24. 'avatar' => '/images/your_photo.png',
  25. 'title' => 'title',
  26. ];
  27. /**
  28. * @return string HTML
  29. */
  30. public function addressFormatHtml($data = null, $format = 'General') {
  31. if ($data === null) {
  32. $data = $this->_defaults;
  33. }
  34. $text = '';
  35. $text .= '<div id="hcard-' . $data['given_name'] . '-' . $data['family_name'] . '" class="vcard">';
  36. $text .= '<span class="fn">' . $data['given_name'] . ' ' . $data['family_name'] . '</span>';
  37. $text .= $this->address($data, $format);
  38. $text .= '</div>';
  39. return $text;
  40. }
  41. /**
  42. * @return string
  43. */
  44. public function addressFormatRaw($data = null, $format = 'General') {
  45. if ($data === null) {
  46. $data = $this->_defaults;
  47. }
  48. $text = $data['given_name'] . ' ' . $data['family_name'] . "\n";
  49. $text .= $data['street'] . "\n";
  50. if (Configure::read('Localization.addressFormat') === 'US') {
  51. $text .= $data['city'] . ', ' . $data['province'] . ' ' . $data['postal_code'] . "\n";
  52. } else {
  53. $text .= $data['postal_code'] . ' ' . $data['city'] . "\n";
  54. }
  55. $text .= $data['country'];
  56. return $text;
  57. }
  58. /**
  59. * @return string
  60. */
  61. public function address($data) {
  62. if ($data === null) {
  63. $data = $this->_defaults;
  64. }
  65. $text = '<div class="adr">';
  66. $text .= '<div class="street-address">' . $data['street'] . '</div> ';
  67. $text .= '<span class="locality">' . $data['city'] . '</span>, ';
  68. if (!empty($data['province'])) {
  69. $text .= '<span class="region">' . $data['province'] . '</span> ';
  70. }
  71. $text .= '<span class="postal-code">' . $data['postal_code'] . '</span> ';
  72. $text .= '<span class="country-name">' . $data['country'] . '</span> ';
  73. $text .= '</div>';
  74. return $text;
  75. }
  76. }