| 1 |
<?php |
| 2 |
/** |
| 3 |
* Accessibility Statement Data Structure |
| 4 |
* |
| 5 |
* @package AccessibilityPlus |
| 6 |
* @since 2.0.0 |
| 7 |
*/ |
| 8 |
|
| 9 |
// Prevent direct access. |
| 10 |
if ( ! defined( 'ABSPATH' ) ) { |
| 11 |
exit; |
| 12 |
} |
| 13 |
|
| 14 |
/** |
| 15 |
* Get the default accessibility statement structure |
| 16 |
*/ |
| 17 |
function wya11y_get_default_statement_structure() { |
| 18 |
return array( |
| 19 |
'basicInfo' => array( |
| 20 |
'companyName' => '', |
| 21 |
'websiteUrl' => '', |
| 22 |
'websiteName' => '', |
| 23 |
'publicationDate' => '', |
| 24 |
), |
| 25 |
'efforts' => array( |
| 26 |
'selectedEfforts' => array(), |
| 27 |
'additionalEfforts' => array(), |
| 28 |
), |
| 29 |
'conformanceStatus' => array( |
| 30 |
'standard' => '', |
| 31 |
'customStandard' => '', |
| 32 |
'conformanceLevel' => '', |
| 33 |
'additionalConsiderations' => '', |
| 34 |
'knownIssues' => array(), |
| 35 |
'unresolvedBarriers' => '', |
| 36 |
'contentOutsideScope' => '', |
| 37 |
), |
| 38 |
'technicalSpecs' => array( |
| 39 |
'knownCompatibilities' => array( |
| 40 |
'browsers' => array(), |
| 41 |
'operatingSystems' => array(), |
| 42 |
'assistiveTechnologies' => array(), |
| 43 |
), |
| 44 |
'knownIncompatibilities' => array( |
| 45 |
'browsers' => array(), |
| 46 |
'operatingSystems' => array(), |
| 47 |
'assistiveTechnologies' => array(), |
| 48 |
), |
| 49 |
'technologyReliance' => array( |
| 50 |
'selected' => array(), |
| 51 |
'other' => '', |
| 52 |
), |
| 53 |
'assessmentApproach' => array( |
| 54 |
'selected' => array(), |
| 55 |
'otherMethods' => array(), |
| 56 |
), |
| 57 |
), |
| 58 |
'feedback' => array( |
| 59 |
'companyPhoneNumber' => '', |
| 60 |
'companyEmailAddress' => '', |
| 61 |
'companyVisitorAddress' => '', |
| 62 |
'companyPostalAddress' => '', |
| 63 |
'sameAsVisitorAddress' => false, |
| 64 |
'otherContactOptions' => '', |
| 65 |
'typicalDurationForResponse' => '', |
| 66 |
'enforcementTeam' => array(), |
| 67 |
), |
| 68 |
'relatedEvidence' => array( |
| 69 |
'recentEvaluationReport' => '', |
| 70 |
'evaluationStatement' => '', |
| 71 |
'otherEvidence' => array(), |
| 72 |
), |
| 73 |
); |
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* Validate accessibility statement data structure |
| 78 |
*/ |
| 79 |
function wya11y_validate_statement_structure( $data ) { |
| 80 |
$default_structure = wya11y_get_default_statement_structure(); |
| 81 |
|
| 82 |
// Ensure all required keys exist. |
| 83 |
foreach ( $default_structure as $key => $default_value ) { |
| 84 |
if ( ! isset( $data[ $key ] ) ) { |
| 85 |
$data[ $key ] = $default_value; |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
return $data; |
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* Sanitize accessibility statement data |
| 94 |
*/ |
| 95 |
function wya11y_sanitize_statement_data( $data ) { |
| 96 |
$sanitized = array(); |
| 97 |
|
| 98 |
// Basic Info. |
| 99 |
$sanitized['basicInfo'] = array( |
| 100 |
'companyName' => sanitize_text_field( $data['basicInfo']['companyName'] ?? '' ), |
| 101 |
'websiteUrl' => esc_url_raw( $data['basicInfo']['websiteUrl'] ?? '' ), |
| 102 |
'websiteName' => sanitize_text_field( $data['basicInfo']['websiteName'] ?? '' ), |
| 103 |
'publicationDate' => sanitize_text_field( $data['basicInfo']['publicationDate'] ?? '' ), |
| 104 |
); |
| 105 |
|
| 106 |
// Efforts. |
| 107 |
$sanitized['efforts'] = array( |
| 108 |
'selectedEfforts' => array_map( 'sanitize_text_field', $data['efforts']['selectedEfforts'] ?? array() ), |
| 109 |
'additionalEfforts' => array_map( 'sanitize_text_field', $data['efforts']['additionalEfforts'] ?? array() ), |
| 110 |
); |
| 111 |
|
| 112 |
// Conformance Status. |
| 113 |
$sanitized['conformanceStatus'] = array( |
| 114 |
'standard' => sanitize_text_field( $data['conformanceStatus']['standard'] ?? '' ), |
| 115 |
'customStandard' => sanitize_text_field( $data['conformanceStatus']['customStandard'] ?? '' ), |
| 116 |
'conformanceLevel' => sanitize_text_field( $data['conformanceStatus']['conformanceLevel'] ?? '' ), |
| 117 |
'additionalConsiderations' => sanitize_textarea_field( $data['conformanceStatus']['additionalConsiderations'] ?? '' ), |
| 118 |
'knownIssues' => array_map( |
| 119 |
function ( $issue ) { |
| 120 |
return array( |
| 121 |
'title' => sanitize_text_field( $issue['title'] ?? '' ), |
| 122 |
'description' => sanitize_textarea_field( $issue['description'] ?? '' ), |
| 123 |
); |
| 124 |
}, |
| 125 |
$data['conformanceStatus']['knownIssues'] ?? array() |
| 126 |
), |
| 127 |
'unresolvedBarriers' => sanitize_textarea_field( $data['conformanceStatus']['unresolvedBarriers'] ?? '' ), |
| 128 |
'contentOutsideScope' => sanitize_textarea_field( $data['conformanceStatus']['contentOutsideScope'] ?? '' ), |
| 129 |
); |
| 130 |
|
| 131 |
// Technical Specs. |
| 132 |
$sanitized['technicalSpecs'] = array( |
| 133 |
'knownCompatibilities' => array( |
| 134 |
'browsers' => array_map( 'sanitize_text_field', $data['technicalSpecs']['knownCompatibilities']['browsers'] ?? array() ), |
| 135 |
'operatingSystems' => array_map( 'sanitize_text_field', $data['technicalSpecs']['knownCompatibilities']['operatingSystems'] ?? array() ), |
| 136 |
'assistiveTechnologies' => array_map( 'sanitize_text_field', $data['technicalSpecs']['knownCompatibilities']['assistiveTechnologies'] ?? array() ), |
| 137 |
), |
| 138 |
'knownIncompatibilities' => array( |
| 139 |
'browsers' => array_map( 'sanitize_text_field', $data['technicalSpecs']['knownIncompatibilities']['browsers'] ?? array() ), |
| 140 |
'operatingSystems' => array_map( 'sanitize_text_field', $data['technicalSpecs']['knownIncompatibilities']['operatingSystems'] ?? array() ), |
| 141 |
'assistiveTechnologies' => array_map( 'sanitize_text_field', $data['technicalSpecs']['knownIncompatibilities']['assistiveTechnologies'] ?? array() ), |
| 142 |
), |
| 143 |
'technologyReliance' => array( |
| 144 |
'selected' => array_map( 'sanitize_text_field', $data['technicalSpecs']['technologyReliance']['selected'] ?? array() ), |
| 145 |
'other' => sanitize_text_field( $data['technicalSpecs']['technologyReliance']['other'] ?? '' ), |
| 146 |
), |
| 147 |
'assessmentApproach' => array( |
| 148 |
'selected' => array_map( 'sanitize_text_field', $data['technicalSpecs']['assessmentApproach']['selected'] ?? array() ), |
| 149 |
'otherMethods' => array_map( 'sanitize_text_field', $data['technicalSpecs']['assessmentApproach']['otherMethods'] ?? array() ), |
| 150 |
), |
| 151 |
); |
| 152 |
|
| 153 |
// Feedback. |
| 154 |
$sanitized['feedback'] = array( |
| 155 |
'companyPhoneNumber' => sanitize_text_field( $data['feedback']['companyPhoneNumber'] ?? '' ), |
| 156 |
'companyEmailAddress' => sanitize_email( $data['feedback']['companyEmailAddress'] ?? '' ), |
| 157 |
'companyVisitorAddress' => sanitize_textarea_field( $data['feedback']['companyVisitorAddress'] ?? '' ), |
| 158 |
'companyPostalAddress' => sanitize_textarea_field( $data['feedback']['companyPostalAddress'] ?? '' ), |
| 159 |
'sameAsVisitorAddress' => (bool) ( $data['feedback']['sameAsVisitorAddress'] ?? false ), |
| 160 |
'otherContactOptions' => sanitize_textarea_field( $data['feedback']['otherContactOptions'] ?? '' ), |
| 161 |
'typicalDurationForResponse' => sanitize_text_field( $data['feedback']['typicalDurationForResponse'] ?? '' ), |
| 162 |
'enforcementTeam' => array_map( |
| 163 |
function ( $team ) { |
| 164 |
return array( |
| 165 |
'name' => sanitize_text_field( $team['name'] ?? '' ), |
| 166 |
'linkToEnforcementProcedure' => esc_url_raw( $team['linkToEnforcementProcedure'] ?? '' ), |
| 167 |
'contactDetails' => sanitize_textarea_field( $team['contactDetails'] ?? '' ), |
| 168 |
); |
| 169 |
}, |
| 170 |
$data['feedback']['enforcementTeam'] ?? array() |
| 171 |
), |
| 172 |
); |
| 173 |
|
| 174 |
// Related Evidence. |
| 175 |
$sanitized['relatedEvidence'] = array( |
| 176 |
'recentEvaluationReport' => esc_url_raw( $data['relatedEvidence']['recentEvaluationReport'] ?? '' ), |
| 177 |
'evaluationStatement' => sanitize_textarea_field( $data['relatedEvidence']['evaluationStatement'] ?? '' ), |
| 178 |
'otherEvidence' => array_map( 'sanitize_text_field', $data['relatedEvidence']['otherEvidence'] ?? array() ), |
| 179 |
); |
| 180 |
|
| 181 |
return $sanitized; |
| 182 |
} |
| 183 |
|
| 184 |
/** |
| 185 |
* Get stored accessibility statement data |
| 186 |
*/ |
| 187 |
function wya11y_get_stored_statement_data() { |
| 188 |
$option_name = 'wya11y_statement_data'; |
| 189 |
$stored_data = get_option( $option_name, array() ); |
| 190 |
|
| 191 |
if ( empty( $stored_data ) ) { |
| 192 |
$stored_data = wya11y_get_default_statement_structure(); |
| 193 |
update_option( $option_name, $stored_data ); |
| 194 |
} |
| 195 |
|
| 196 |
return wya11y_validate_statement_structure( $stored_data ); |
| 197 |
} |
| 198 |
|
| 199 |
/** |
| 200 |
* Save accessibility statement data |
| 201 |
*/ |
| 202 |
function wya11y_save_statement_data( $data ) { |
| 203 |
$option_name = 'wya11y_statement_data'; |
| 204 |
$sanitized_data = wya11y_sanitize_statement_data( $data ); |
| 205 |
|
| 206 |
return update_option( $option_name, $sanitized_data ); |
| 207 |
} |
| 208 |
|
| 209 |
/** |
| 210 |
* Generate HTML content from accessibility statement data |
| 211 |
*/ |
| 212 |
function wya11y_generate_statement_html( $data ) { |
| 213 |
$data = wya11y_validate_statement_structure( $data ); |
| 214 |
|
| 215 |
$html = '<div class="accessibility-statement">'; |
| 216 |
|
| 217 |
// Header. |
| 218 |
$html .= '<h1>Accessibility Statement</h1>'; |
| 219 |
$html .= '<p><strong>Last Updated:</strong> ' . esc_html( $data['basicInfo']['publicationDate'] ?: gmdate( 'F j, Y' ) ) . '</p>'; |
| 220 |
|
| 221 |
// Basic Information. |
| 222 |
$html .= '<h2>Basic Information</h2>'; |
| 223 |
$html .= '<p><strong>Company:</strong> ' . esc_html( $data['basicInfo']['companyName'] ?: 'N/A' ) . '</p>'; |
| 224 |
$html .= '<p><strong>Website:</strong> ' . esc_html( $data['basicInfo']['websiteName'] ?: 'N/A' ) . '</p>'; |
| 225 |
$html .= '<p><strong>URL:</strong> ' . esc_html( $data['basicInfo']['websiteUrl'] ?: 'N/A' ) . '</p>'; |
| 226 |
|
| 227 |
// Accessibility Efforts. |
| 228 |
$html .= '<h2>Accessibility Efforts</h2>'; |
| 229 |
if ( ! empty( $data['efforts']['additionalEfforts'] ) ) { |
| 230 |
$html .= '<ul>'; |
| 231 |
foreach ( $data['efforts']['additionalEfforts'] as $effort ) { |
| 232 |
$html .= '<li>' . esc_html( $effort ) . '</li>'; |
| 233 |
} |
| 234 |
$html .= '</ul>'; |
| 235 |
} else { |
| 236 |
$html .= '<p>No additional efforts specified.</p>'; |
| 237 |
} |
| 238 |
|
| 239 |
// Conformance Status. |
| 240 |
$html .= '<h2>Conformance Status</h2>'; |
| 241 |
$html .= '<p><strong>Standard:</strong> ' . esc_html( $data['conformanceStatus']['standard'] ?: 'N/A' ) . '</p>'; |
| 242 |
$html .= '<p><strong>Level:</strong> ' . esc_html( $data['conformanceStatus']['conformanceLevel'] ?: 'N/A' ) . '</p>'; |
| 243 |
$html .= '<p><strong>Additional Considerations:</strong> ' . esc_html( $data['conformanceStatus']['additionalConsiderations'] ?: 'None specified.' ) . '</p>'; |
| 244 |
|
| 245 |
// Known Issues. |
| 246 |
$html .= '<h2>Known Issues</h2>'; |
| 247 |
if ( ! empty( $data['conformanceStatus']['knownIssues'] ) ) { |
| 248 |
$html .= '<ul>'; |
| 249 |
foreach ( $data['conformanceStatus']['knownIssues'] as $issue ) { |
| 250 |
$html .= '<li><strong>' . esc_html( $issue['title'] ) . ':</strong> ' . esc_html( $issue['description'] ) . '</li>'; |
| 251 |
} |
| 252 |
$html .= '</ul>'; |
| 253 |
} else { |
| 254 |
$html .= '<p>No known issues specified.</p>'; |
| 255 |
} |
| 256 |
|
| 257 |
// Technical Specifications. |
| 258 |
$html .= '<h2>Technical Specifications</h2>'; |
| 259 |
$html .= '<p><strong>Assessment Approach:</strong> ' . esc_html( implode( ', ', $data['technicalSpecs']['assessmentApproach']['selected'] ) ?: 'N/A' ) . '</p>'; |
| 260 |
|
| 261 |
// Feedback and Contact. |
| 262 |
$html .= '<h2>Feedback and Contact</h2>'; |
| 263 |
$html .= '<p><strong>Phone:</strong> ' . esc_html( $data['feedback']['companyPhoneNumber'] ?: 'N/A' ) . '</p>'; |
| 264 |
$html .= '<p><strong>Email:</strong> ' . esc_html( $data['feedback']['companyEmailAddress'] ?: 'N/A' ) . '</p>'; |
| 265 |
$html .= '<p><strong>Address:</strong> ' . esc_html( $data['feedback']['companyVisitorAddress'] ?: 'N/A' ) . '</p>'; |
| 266 |
$html .= '<p><strong>Response Time:</strong> ' . esc_html( $data['feedback']['typicalDurationForResponse'] ?: 'N/A' ) . '</p>'; |
| 267 |
|
| 268 |
// Related Evidence. |
| 269 |
$html .= '<h2>Related Evidence</h2>'; |
| 270 |
$html .= '<p>' . esc_html( $data['relatedEvidence']['evaluationStatement'] ?: 'No evaluation statement provided.' ) . '</p>'; |
| 271 |
|
| 272 |
$html .= '</div>'; |
| 273 |
|
| 274 |
return $html; |
| 275 |
} |
| 276 |
|