PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/core/src/main/php/peer/http/P3PHeader.class.php

http://github.com/xp-framework/xp-framework
PHP | 265 lines | 111 code | 23 blank | 131 comment | 3 complexity | 8140fb7dc258a0b3df2231002f736cc6 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /* This class is part of the XP framework
  3. *
  4. * $Id$
  5. */
  6. uses('peer.Header');
  7. define('P3PC_ACCESS_NONIDENT', 'NOI');
  8. define('P3PC_ACCESS_ALL', 'ALL');
  9. define('P3PC_ACCESS_CONTACT_AND_OTHER', 'CAO');
  10. define('P3PC_ACCESS_IDENT_CONTACT', 'IDC');
  11. define('P3PC_ACCESS_OTHER_INDENT', 'OTI');
  12. define('P3PC_ACCESS_NONE', 'NON');
  13. define('P3PC_REMEDIES_CORRECT', 'COR');
  14. define('P3PC_REMEDIES_MONEY', 'MON');
  15. define('P3PC_REMEDIES_LAW', 'LAW');
  16. define('P3PC_CREQ_ALWAYS', 'a');
  17. define('P3PC_CREQ_OPT_IN', 'i');
  18. define('P3PC_CREQ_OPT_OUT', 'o');
  19. define('P3PC_PURPOSE_CURRENT', 'CUR');
  20. define('P3PC_PURPOSE_ADMIN', 'ADM');
  21. define('P3PC_PURPOSE_DEVELOP', 'DEV');
  22. define('P3PC_PURPOSE_TAILORING', 'TAI');
  23. define('P3PC_PURPOSE_PSEUDO_ANALYSIS', 'PSA');
  24. define('P3PC_PURPOSE_PSEUDO_DECISION', 'PSD');
  25. define('P3PC_PURPOSE_INDIVIDUAL_ANALYSIS', 'IVA');
  26. define('P3PC_PURPOSE_INDIVIDUAL_DECISION', 'IVD');
  27. define('P3PC_PURPOSE_CONTACT', 'CON');
  28. define('P3PC_PURPOSE_HISTORICAL', 'HIS');
  29. define('P3PC_PURPOSE_TELEMARKETING', 'TEL');
  30. define('P3PC_PURPOSE_OTHER_PURPOSE', 'OTP');
  31. define('P3PC_RECIPIENT_OURS', 'OUR');
  32. define('P3PC_RECIPIENT_DELIVERY', 'DEL');
  33. define('P3PC_RECIPIENT_SAME', 'SAM');
  34. define('P3PC_RECIPIENT_UNRELATED', 'UNR');
  35. define('P3PC_RECIPIENT_PUBLIC', 'PUB');
  36. define('P3PC_RECIPIENT_OTHER_RECIPIENT', 'OTR');
  37. define('P3PC_RETENTION_NO_RETENTION', 'NOR');
  38. define('P3PC_RETENTION_STATED_PURPOSE', 'STP');
  39. define('P3PC_RETENTION_LEGAL_REQUIREMENT', 'LEG');
  40. define('P3PC_RETENTION_BUSINESS_PRACTICES', 'BUS');
  41. define('P3PC_RETENTION_INDEFINITELY', 'IND');
  42. define('P3PC_CATEGORIES_PHYSICAL', 'PHY');
  43. define('P3PC_CATEGORIES_ONLINE', 'ONL');
  44. define('P3PC_CATEGORIES_UNIQUEID', 'UNI');
  45. define('P3PC_CATEGORIES_PURCHASE', 'PUR');
  46. define('P3PC_CATEGORIES_FINANCIAL', 'FIN');
  47. define('P3PC_CATEGORIES_COMPUTER', 'COM');
  48. define('P3PC_CATEGORIES_NAVIGATION', 'NAV');
  49. define('P3PC_CATEGORIES_INTERACTIVE', 'INT');
  50. define('P3PC_CATEGORIES_DEMOGRAPHIC', 'DEM');
  51. define('P3PC_CATEGORIES_CONTENT', 'CNT');
  52. define('P3PC_CATEGORIES_STATE', 'STA');
  53. define('P3PC_CATEGORIES_POLITICAL', 'POL');
  54. define('P3PC_CATEGORIES_HEALTH', 'HEA');
  55. define('P3PC_CATEGORIES_PREFERENCE', 'PRE');
  56. define('P3PC_CATEGORIES_LOCATION', 'LOC');
  57. define('P3PC_CATEGORIES_GOVERNMENT', 'GOV');
  58. define('P3PC_CATEGORIES_OTHER_CATEGORY', 'OTC');
  59. /**
  60. * Represents a Private Preferences header.
  61. *
  62. * @see http://www.w3.org/TR/P3P/#syntax_ext
  63. * @see http://www.w3.org/TR/P3P/#compact_policies
  64. * @purpose P3P header
  65. */
  66. class P3PHeader extends Header {
  67. public
  68. $policyref = '',
  69. $compact = array();
  70. /**
  71. * Constructor
  72. *
  73. * @param string policyref
  74. */
  75. public function __construct($policyref) {
  76. parent::__construct('P3P', NULL);
  77. $this->policyref= $policyref;
  78. }
  79. /**
  80. * Helper method
  81. *
  82. * @param string name
  83. * @param string value
  84. */
  85. protected function _setCompact($name, $value) {
  86. if ($value) {
  87. $this->compact[$name]= $value;
  88. } else {
  89. unset($this->compact[$name]);
  90. }
  91. }
  92. /**
  93. * Set compact access. Information in the ACCESS element is
  94. * represented in compact policies using tokens composed
  95. * by a three letter code.
  96. *
  97. * @param string access one of the P3PC_ACCESS_* constants
  98. */
  99. public function setCompactAccess($access) {
  100. $this->_setCompact('access', $access);
  101. }
  102. /**
  103. * Set compact disputes. If a full P3P policy contains a
  104. * DISPUTES-GROUP element that contains one or more DISPUTES
  105. * elements, then the server should signal the user agent by
  106. * providing a single "DSP" token in the P3P-compact policy
  107. * field.
  108. *
  109. * @param bool disputes
  110. */
  111. public function setCompactDisputes($disputes) {
  112. $this->_setCompact('disputes', $disputes ? 'DSP' : NULL);
  113. }
  114. /**
  115. * Set compact remedies. Information in the REMEDIES element is
  116. * represented in compact policies using tokens composed
  117. * by a three letter code.
  118. *
  119. * Note: If NULL is passed as value for remedies, the REMEDIES
  120. * element will be removed
  121. *
  122. * @param string remedies one of the P3PC_REMEDIES_* constants
  123. */
  124. public function setCompactRemedies($remedies) {
  125. $this->_setCompact('remedies', $remedies);
  126. }
  127. /**
  128. * Set compact non-identifiable. The presence of the NON-IDENTIFIABLE
  129. * element in every statement of the policy is signaled by the NID
  130. * token (note that the NID token MUST NOT be used unless the
  131. * NON-IDENTIFIABLE element is present in every statement within the
  132. * policy)
  133. *
  134. * @param bool non_identifiable
  135. */
  136. public function setCompactNonIdentifiable($non_identifiable) {
  137. $this->_setCompact('non-identifiable', $non_identifiable ? 'NID' : NULL);
  138. }
  139. /**
  140. * Set compact purpose. Purposes are expressed in P3P compact policy
  141. * format using tokens composed by a three letter code plus an
  142. * optional one letter attribute. Such an optional attribute encodes
  143. * the value of the "required" attribute in full P3P policies:
  144. * its value can be "a", "i" and "o", which mean that the "required"
  145. * attribute in the corresponding P3P policy must be set to "always",
  146. * "opt-in" and "opt-out" respectively.
  147. *
  148. * If a P3P compact policy needs to specify one or more other-purposes
  149. * in its full P3P policy, a single OTP flag is used to signal the user
  150. * agent that other-purposes exist in the full P3P policy.
  151. *
  152. * Note: If NULL is passed as value for purpose, the PURPOSE
  153. * element will be removed
  154. *
  155. * @param string purpose one of the P3PC_PURPOSE_* constants
  156. * @param string creq default '' one of the P3PC_CREQ_* constants
  157. */
  158. public function setCompactPurpose($purpose, $creq= '') {
  159. $this->_setCompact('purpose', $purpose.$creq);
  160. }
  161. /**
  162. * Set compact recipient. Recipients are expressed in P3P compact
  163. * policy format using a three letter code plus an optional one
  164. * letter attribute. Such an optional attribute encodes the value
  165. * of the "required" attribute in full P3P policies: its value can
  166. * be "a", "i" and "o", which mean that the "required" attribute
  167. * in the corresponding P3P policy must be set to "always",
  168. * "opt-in" and "opt-out" respectively.
  169. *
  170. * Note: If NULL is passed as value for recipient, the RECIPIENT
  171. * element will be removed
  172. *
  173. * @param string recipient one of the P3PC_RECIPIENT_* constants
  174. * @param string creq default '' one of the P3PC_CREQ_* constants
  175. */
  176. public function setCompactRecipient($recipient, $creq= '') {
  177. $this->_setCompact('recipient', $recipient.$creq);
  178. }
  179. /**
  180. * Set compact retention. Information in the RETENTION element
  181. * is represented in compact policies composed
  182. * by a three letter code.
  183. *
  184. * Note: If NULL is passed as value for retention, the RETENTION
  185. * element will be removed
  186. *
  187. * @param string retention one of the P3PC_RETENTION_* constants
  188. */
  189. public function setCompactRetention($retention) {
  190. $this->_setCompact('retention', $retention);
  191. }
  192. /**
  193. * Set compact categories. Categories are represented in compact
  194. * policies by a three letter code.
  195. *
  196. * Note: If NULL is passed as value for categories, the CATEGORIES
  197. * element will be removed
  198. *
  199. * @param string categories one of the P3PC_CATEGORIES_* constants
  200. */
  201. public function setCompactCategories($categories) {
  202. $this->_setCompact('categories', $categories);
  203. }
  204. /**
  205. * Set compact test. The presence of the TEST element is signaled
  206. * by the TST token.
  207. *
  208. * @param bool test
  209. */
  210. public function setCompactTest($test) {
  211. $this->_setCompact('test', $test ? 'TST' : NULL);
  212. }
  213. /**
  214. * Set Policyref
  215. *
  216. * @param string policyref
  217. */
  218. public function setPolicyref($policyref) {
  219. $this->policyref= $policyref;
  220. }
  221. /**
  222. * Get Policyref
  223. *
  224. * @return string
  225. */
  226. public function getPolicyref() {
  227. return $this->policyref;
  228. }
  229. /**
  230. * Get header value representation
  231. *
  232. * @return string value
  233. */
  234. public function getValueRepresentation() {
  235. $r= 'policyref="'.$this->policyref.'"';
  236. if ($this->compact) { // Compact policy is optional
  237. $r.= ', CP="'.implode(' ', array_values($this->compact)).'"';
  238. }
  239. return $r;
  240. }
  241. }
  242. ?>