PageRenderTime 53ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/foafpressapp/core/controllers/foaf/Agent.parent.php

http://github.com/haschek/Foafpress
PHP | 363 lines | 251 code | 87 blank | 25 comment | 32 complexity | 8e32bf9d9b0a49a11162cc66c3880d10 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. class Foaf_Agent_Controller_Parent extends Foafpress_Controller
  3. {
  4. public function get_request()
  5. {
  6. // -- Prepare output ---------------------------------------------------
  7. $this->write_mainlanguage_to_view();
  8. $this->write_rdfmetalinks_to_view();
  9. $this->set_resource_type_template();
  10. // -- Layout class -----------------------------------------------------
  11. $this->content->resource_type_info = $this->get_resource_type_info();
  12. $this->write_data_to_view();
  13. // -- Debug log --------------------------------------------------------
  14. // TODO: move this to parent controller
  15. $this->content->debug_log = $this->RESOURCE->logUsage;
  16. return;
  17. }
  18. public function write_data_to_view()
  19. {
  20. // -- Basics - Name, Info, Depiction -----------------------------------
  21. $this->read_basic_info();
  22. // -- Websites/Links ---------------------------------------------------
  23. $this->read_links();
  24. // -- Online Accounts --------------------------------------------------
  25. $this->read_accounts();
  26. // -- Activity / Feeds -------------------------------------------------
  27. $this->read_activity_stream();
  28. // -- Interests --------------------------------------------------------
  29. $this->read_interests();
  30. // -- Projects ---------------------------------------------------------
  31. $this->read_contacts();
  32. // -- Document Meta Data (for HTML Head) -------------------------------
  33. $this->fill_document_meta();
  34. }
  35. public function read_basic_info($resource = null)
  36. {
  37. // -- Basics - Name, Info, Depiction -----------------------------------
  38. if (!$resource) $resource = $this->RESOURCE;
  39. $this->content->name_or_nickname = $resource->getLiteral(array('name', 'nick', 'dc_title'));
  40. $this->content->depiction = $resource->getImage();
  41. $this->content->short_description = $resource->getLiteral(array('dc_description', 'bio_olb'));
  42. }
  43. public function read_links($resource = null)
  44. {
  45. // -- Websites/Links ---------------------------------------------------
  46. if (!$resource) $resource = $this->RESOURCE;
  47. $list_of_website_objects = array_unique(array_merge($resource->homepage, $resource->weblog, $resource->workplaceHomepage, $resource->workInfoHomepage));
  48. $list_of_websites = array();
  49. foreach ($list_of_website_objects as $website_object)
  50. {
  51. if (is_object($website_object) && ($label = $website_object->getLiteral(array('rdfs_label', 'dc_title'))))
  52. {
  53. $list_of_websites[] = array(
  54. 'source-icon-class' => $website_object->getIconLayout($website_object->uri, true),
  55. 'url' => $website_object->uri,
  56. 'label' => $label
  57. );
  58. }
  59. unset($label);
  60. unset($website_object);
  61. }
  62. $this->content->list_of_websites = $list_of_websites;
  63. unset($list_of_websites);
  64. unset($list_of_website_objects);
  65. }
  66. public function read_accounts($resource = null)
  67. {
  68. // -- Online Accounts --------------------------------------------------
  69. if (!$resource) $resource = $this->RESOURCE;
  70. $list_of_account_objects = array_unique(array_merge($resource->account, $resource->holdsAccount));
  71. $list_of_accounts = array();
  72. foreach ($list_of_account_objects as $account_object)
  73. {
  74. if (is_object($account_object) &&
  75. ($account_page = array_merge($account_object->homepage, $account_object->accountProfilePage)) &&
  76. is_object($account_page[0]) &&
  77. ($account_label = $account_page[0]->getLiteral(array('rdfs_label', 'dc_title'))))
  78. {
  79. $list_of_accounts[] = array(
  80. 'source-icon-class' => $account_object->getIconLayout($account_page[0]->uri, true),
  81. 'homepage-url' => $account_page[0]->uri,
  82. 'homepage-label' => $account_label
  83. );
  84. }
  85. unset($account_label);
  86. unset($account_object);
  87. }
  88. $this->content->list_of_accounts = $list_of_accounts;
  89. unset($list_of_accounts);
  90. unset($list_of_account_objects);
  91. }
  92. public function read_activity_stream($resource = null)
  93. {
  94. // -- Activity / Feeds -------------------------------------------------
  95. if (!$resource) $resource = $this->RESOURCE;
  96. $activity = $resource->listActivity();
  97. if (isset($activity['stream'])) $this->content->activity = $activity;
  98. unset($activity);
  99. }
  100. public function read_interests($resource = null)
  101. {
  102. // -- Interests --------------------------------------------------------
  103. if (!$resource) $resource = $this->RESOURCE;
  104. /*
  105. it is strange but merging the array in inverse order seems
  106. to lead to a corrumption of the foaf_topic_interests resources
  107. and their properties.
  108. $list_of_interest_objects = array_unique(array_merge($resource->foaf_interest, $resource->foaf_topic_interest));
  109. */
  110. $list_of_interest_objects = array_unique(array_merge($resource->foaf_topic_interest, $resource->foaf_interest));
  111. $list_of_interests = array();
  112. foreach ($list_of_interest_objects as $interest_object)
  113. {
  114. if (is_object($interest_object) && $interest_label = $interest_object->getLiteral(array('dc_title', 'rdfs_label'), array(), true))
  115. {
  116. $interest_details = array();
  117. $interest_details['label'] = $interest_label;
  118. if ($description = $interest_object->getLiteral(array('dc_description', 'rdfs_comment'), array(), true))
  119. {
  120. $interest_details['description'] = $description;
  121. }
  122. unset($description);
  123. if ($homepage = array_merge($interest_object->foaf_homepage, $interest_object->foaf_page, $interest_object->foaf_primaryTopic))
  124. {
  125. if (isset($homepage[0])) $homepage = $homepage[0];
  126. if (is_object($homepage))
  127. {
  128. $interest_details['link'] = $homepage->uri;
  129. }
  130. else
  131. {
  132. $interest_details['link'] = $homepage;
  133. }
  134. }
  135. elseif (substr($interest_object->uri, 0, 1) != '_')
  136. {
  137. $interest_details['link'] = $interest_object->uri;
  138. }
  139. unset($homepage);
  140. $list_of_interests[] = $interest_details;
  141. unset($interest_details);
  142. }
  143. elseif (!is_object($interest_object) && @parse_url($interest_object) === false)
  144. {
  145. $list_of_interests[] = array(
  146. 'label' => $interest_object
  147. );
  148. }
  149. unset($interest_object);
  150. }
  151. $this->content->list_of_interests = $list_of_interests;
  152. unset($list_of_interests);
  153. }
  154. public function read_contacts($resource = null)
  155. {
  156. // -- VCards -----------------------------------------------------------
  157. if (!$resource) $resource = $this->RESOURCE;
  158. $list_of_VCard_objects = array_unique(array_merge($resource->ov_businessCard, $resource->foaf_businessCard));
  159. $list_of_contact_objects = array(
  160. 'Work' => array(
  161. 'adr' => array(), 'tel' => array(), 'fax' => array(), 'email' => array()
  162. ),
  163. 'Home' => array(
  164. 'adr' => array(), 'tel' => array(), 'fax' => array(), 'email' => array()
  165. )
  166. );
  167. $list_of_contacts = array(
  168. 'Work' => array(
  169. 'Address' => array(), 'Phone' => array(), 'Fax' => array(), 'Email' => array()
  170. ),
  171. 'Home' => array(
  172. 'Address' => array(), 'Phone' => array(), 'Fax' => array(), 'Email' => array()
  173. )
  174. );
  175. $list_of_contacts_empty = $list_of_contacts;
  176. foreach ($list_of_VCard_objects as $VCard_object_id => $VCard_object)
  177. {
  178. if (!is_object($VCard_object))
  179. {
  180. unset($list_of_VCard_objects[$VCard_object_id]);
  181. }
  182. else
  183. {
  184. $list_of_contact_objects['Work']['adr'] = array_unique(array_merge(
  185. $list_of_contact_objects['Work']['adr'],
  186. $VCard_object->vcard_adr('vcard:Work')));
  187. $list_of_contact_objects['Work']['tel'] = array_unique(array_merge(
  188. $list_of_contact_objects['Work']['tel'],
  189. $VCard_object->vcard_tel('vcard:Work', '-vcard:Fax')));
  190. $list_of_contact_objects['Work']['fax'] = array_unique(array_merge(
  191. $list_of_contact_objects['Work']['fax'],
  192. $VCard_object->vcard_tel('vcard:Work', 'vcard:Fax', true)));
  193. $list_of_contact_objects['Work']['email'] = array_unique(array_merge(
  194. $list_of_contact_objects['Work']['email'],
  195. $VCard_object->vcard_email('vcard:Work', 'vcard:Email', true) /* not valid by current Vcard model */,
  196. $VCard_object->vcard_workEmail));
  197. $list_of_contact_objects['Home']['adr'] = array_unique(array_merge(
  198. $list_of_contact_objects['Home']['adr'],
  199. $VCard_object->vcard_adr('vcard:Home')));
  200. $list_of_contact_objects['Home']['tel'] = array_unique(array_merge(
  201. $list_of_contact_objects['Home']['tel'],
  202. $VCard_object->vcard_tel('vcard:Home', '-vcard:Fax')));
  203. $list_of_contact_objects['Home']['fax'] = array_unique(array_merge(
  204. $list_of_contact_objects['Home']['fax'],
  205. $VCard_object->vcard_tel('vcard:Home', 'vcard:Fax', true)));
  206. $list_of_contact_objects['Home']['email'] = array_unique(array_merge(
  207. $list_of_contact_objects['Home']['email'],
  208. $VCard_object->vcard_email('vcard:Home', 'vcard:Email', true) /* not valid by current Vcard model */,
  209. $VCard_object->vcard_personalEmail));
  210. }
  211. unset($VCard_object);
  212. }
  213. $this->content->number_of_contacts = count($list_of_VCard_objects);
  214. unset($list_of_VCard_objects);
  215. $list_of_VCard_places = array('Home','Work');
  216. $list_of_contact_attributes = array('tel'=>'Phone', 'fax'=>'Fax', 'email'=>'Email');
  217. foreach ($list_of_VCard_places as $VCard_place)
  218. {
  219. foreach ($list_of_contact_objects[$VCard_place]['adr'] as $adr_object)
  220. {
  221. $adrparts = array();
  222. // addressparts = PO Box, Extended Addr, Street, Locality, Region, Postal Code, Country Name
  223. // @see http://www.imc.org/pdi/vcard-21.txt
  224. if ($pobox = $adr_object->getLiteral(array('vcard_post-office-box'))) $adrparts[] = 'P.O.Box '.$pobox;
  225. if ($extended_address = $adr_object->getLiteral(array('vcard_extended-address'))) $adrparts[] = $extended_address;
  226. if ($street = $adr_object->getLiteral(array('vcard_street-address'))) $adrparts[] = $street;
  227. if ($locality = $adr_object->getLiteral(array('vcard_locality'))) $adrparts[] = $locality;
  228. if ($region = $adr_object->getLiteral(array('vcard_region'))) $adrparts[] = $region;
  229. if ($postalcode = $adr_object->getLiteral(array('vcard_postal-code'))) $adrparts[] = $postalcode;
  230. if ($country = $adr_object->getLiteral(array('vcard_country-name'))) $adrparts[] = $country;
  231. if (count($adrparts) > 0)
  232. {
  233. $list_of_contacts[$VCard_place]['Address'][] = implode(', ', $adrparts);
  234. }
  235. unset($adr_object);
  236. }
  237. foreach($list_of_contact_attributes as $contact_attribute => $contact_attribute_label)
  238. {
  239. foreach ($list_of_contact_objects[$VCard_place][$contact_attribute] as $$contact_attribute)
  240. {
  241. if (is_object($$contact_attribute))
  242. {
  243. $list_of_contacts[$VCard_place][$contact_attribute_label][] = array(
  244. 'link' => $$contact_attribute->uri,
  245. 'label' =>($label_temp = $$contact_attribute->getLiteral(array('rdf_value', 'rdfs_label')))?$label_temp:$$contact_attribute->uri
  246. );
  247. unset($label_temp);
  248. }
  249. unset($$contact_attribute);
  250. }
  251. unset($contact_attribute);
  252. unset($contact_attribute_label);
  253. }
  254. unset($VCard_place);
  255. }
  256. unset($list_of_VCard_places);
  257. unset($list_of_contact_attributes);
  258. unset($list_of_contact_objects);
  259. if ($list_of_contacts_empty != $list_of_contacts)
  260. {
  261. $this->content->list_of_contacts = $list_of_contacts;
  262. }
  263. unset($list_of_contacts);
  264. }
  265. public function fill_document_meta()
  266. {
  267. if (!$this->content->META_TITLE)
  268. {
  269. $this->content->META_TITLE = $this->content->name_or_nickname;
  270. }
  271. if (!$this->content->META_DESCRIPTION)
  272. {
  273. $this->content->META_DESCRIPTION = $this->content->short_description;
  274. }
  275. }
  276. }