HcardHelper.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. * 2011-01-11 ms
  8. */
  9. class HcardHelper extends AppHelper {
  10. public $data = array (
  11. 'given_name' => 'Firstname',
  12. 'middle_name' => 'Middlename',
  13. 'family_name' => 'Lastname',
  14. 'organization' => 'OrganizationName',
  15. 'street' => '123 Street',
  16. 'city' => 'City',
  17. 'province' => 'Province/State',
  18. 'postal_code' => 'Postal/Zip',
  19. 'country' => 'Country',
  20. 'phone' => 'phonenumber',
  21. 'email' => 'email@yoursite.com',
  22. 'url' => 'http://yoursite.com',
  23. 'aim_screenname' => 'aimname',
  24. 'yim_screenname' => 'yimname',
  25. 'avatar' => '/images/your_photo.png',
  26. 'title' => 'title',
  27. );
  28. /**
  29. * TODO
  30. */
  31. public function addressFormatHtml($data, $prefix = false, $format = 'General') {
  32. $data = $this->filter($data, $prefix);
  33. $text = $this->style($data, $format);
  34. $text = '';
  35. $text .= '<div id="hcard-' . $data['firstname'] . '-' . $data['lastname'] . '" class="vcard">';
  36. $text .= '<span class="fn">' . $data['firstname'] . ' ' . $data['lastname'] . '</span>';
  37. $text .= $this->address($data, $format);
  38. $text .= '</div>';
  39. return $text;
  40. }
  41. /**
  42. * TODO
  43. */
  44. public function addressFormatRaw($data, $prefix = false, $format = 'General') {
  45. $data = $this->filter($data, $prefix);
  46. $text = $data['firstname'] . ' ' . $data['lastname'] . "\n";
  47. $text .= $data['address'] . "\n";
  48. if (Configure::read('Localization.address_format') === 'US') {
  49. $text .= $data['city'] . ', ' . $data['state'] . ' ' . $data['postcode'] . "\n";
  50. } else {
  51. $text .= $data['postcode'] . ' ' . $data['city'] . "\n";
  52. }
  53. $text .= $data['country'];
  54. return $text;
  55. }
  56. /**
  57. * TODO
  58. */
  59. public function style($data) {
  60. }
  61. /**
  62. * TODO
  63. */
  64. public function address($data) {
  65. $text = '<div class="adr">';
  66. $text .= '<div class="street-address">' . $data['address'] . '</div> ';
  67. $text .= '<span class="locality">' . $data['city'] . '</span>, ';
  68. if (!empty($data['state'])) {
  69. $text .= '<span class="region">' . $data['state'] . '</span> ';
  70. }
  71. $text .= '<span class="postal-code">' . $data['postcode'] . '</span> ';
  72. $text .= '<span class="country-name">' . $data['country'] . '</span> ';
  73. $text .= '</div>';
  74. return $text;
  75. }
  76. /**
  77. * TODO
  78. */
  79. public function filter($data, $prefix = '') {
  80. if ($prefix) {
  81. foreach ($data as $key => $row) {
  82. $data[$prefix . $key] = $data[$key];
  83. }
  84. }
  85. return $data;
  86. }
  87. }