Skip to content

Commit 1bb8760

Browse files
Merge pull request #1028 from equalizedigital/steve/try/landmark-location
Added Landmark Location
2 parents 59433d7 + 205a64c commit 1bb8760

10 files changed

Lines changed: 445 additions & 40 deletions

File tree

accessibility-checker.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
// Current database version.
4242
if ( ! defined( 'EDAC_DB_VERSION' ) ) {
43-
define( 'EDAC_DB_VERSION', '1.0.3' );
43+
define( 'EDAC_DB_VERSION', '1.0.4' );
4444
}
4545

4646
// Plugin Folder Path.

admin/class-ajax.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ function ( $a, $b ) {
321321

322322
foreach ( $rules as $rule ) {
323323
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Using direct query for interacting with custom database, safe variable used for table name, caching not required for one time operation.
324-
$results = $wpdb->get_results( $wpdb->prepare( 'SELECT id, postid, object, ruletype, ignre, ignre_user, ignre_date, ignre_comment, ignre_global FROM %i where postid = %d and rule = %s and siteid = %d', $table_name, $postid, $rule['slug'], $siteid ), ARRAY_A );
324+
$results = $wpdb->get_results( $wpdb->prepare( 'SELECT id, postid, object, ruletype, ignre, ignre_user, ignre_date, ignre_comment, ignre_global, landmark, landmark_selector FROM %i where postid = %d and rule = %s and siteid = %d', $table_name, $postid, $rule['slug'], $siteid ), ARRAY_A );
325325
$count_classes = ( 'error' === $rule['rule_type'] ) ? ' edac-details-rule-count-error' : ' edac-details-rule-count-warning';
326326
$count_classes .= ( 0 !== $rule['count'] ) ? ' active' : '';
327327

@@ -422,6 +422,8 @@ function ( $a, $b ) {
422422
$html .= ob_get_clean();
423423
}
424424

425+
426+
425427
$html .=
426428
'<div class="edac-details-rule-records-labels">
427429
<div class="edac-details-rule-records-labels-label" aria-hidden="true">
@@ -430,6 +432,9 @@ function ( $a, $b ) {
430432
<div class="edac-details-rule-records-labels-label" aria-hidden="true">
431433
Image
432434
</div>
435+
<div class="edac-details-rule-records-labels-label" aria-hidden="true">
436+
Landmark
437+
</div>
433438
<div class="edac-details-rule-records-labels-label" aria-hidden="true">
434439
Actions
435440
</div>
@@ -477,6 +482,30 @@ function ( $a, $b ) {
477482

478483
$html .= '</div>';
479484

485+
$html .= '<div class="edac-details-rule-records-record-cell edac-details-rule-records-record-landmark">';
486+
487+
$landmark = isset( $row['landmark'] ) ? esc_html( $row['landmark'] ) : '';
488+
$landmark_selector = isset( $row['landmark_selector'] ) ? $row['landmark_selector'] : '';
489+
490+
if ( $landmark && $landmark_selector ) {
491+
$landmark_url = add_query_arg(
492+
[
493+
'edac_landmark' => base64_encode( $landmark_selector ),
494+
'edac_nonce' => wp_create_nonce( 'edac_highlight' ),
495+
],
496+
get_the_permalink( $postid )
497+
);
498+
499+
// translators: %s is the landmark type (e.g., "Header", "Navigation", "Main").
500+
$landmark_aria_label = sprintf( __( 'View %s landmark on website, opens a new window', 'accessibility-checker' ), ucwords( $landmark ) );
501+
// translators: %s is the landmark type (e.g., "Header", "Navigation", "Main").
502+
$html .= '<a href="' . $landmark_url . '" class="edac-details-rule-records-record-landmark-link" target="_blank" aria-label="' . esc_attr( $landmark_aria_label ) . '">' . ucwords( $landmark ) . '</a>';
503+
} elseif ( $landmark ) {
504+
$html .= ucwords( $landmark );
505+
}
506+
507+
$html .= '</div>';
508+
480509
$html .= '<div class="edac-details-rule-records-record-cell edac-details-rule-records-record-actions">';
481510

482511
if ( ! isset( $rule['viewable'] ) || $rule['viewable'] ) {

admin/class-insert-rule-data.php

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,17 @@ class Insert_Rule_Data {
2121
*
2222
* @since 1.10.0
2323
*
24-
* @param object $post The post object. Must have a valid ID.
25-
* @param string $rule The rule.
26-
* @param string $ruletype The rule type.
27-
* @param string $rule_obj The object.
24+
* @param object $post The post object. Must have a valid ID.
25+
* @param string $rule The rule.
26+
* @param string $ruletype The rule type.
27+
* @param string $rule_obj The object.
28+
* @param string|null $landmark The landmark type (main, header, footer, nav), optional.
29+
* @param string|null $landmark_selector The landmark selector, optional.
2830
*
2931
* @return void|int|\WP_Error The ID of the inserted record, void if no
3032
* record was inserted or a WP_Error if the insert failed.
3133
*/
32-
public function insert( object $post, string $rule, string $ruletype, string $rule_obj ) {
34+
public function insert( object $post, string $rule, string $ruletype, string $rule_obj, ?string $landmark = null, ?string $landmark_selector = null ) {
3335

3436
if ( ! isset( $post->ID, $post->post_type )
3537
|| empty( $rule )
@@ -44,19 +46,21 @@ public function insert( object $post, string $rule, string $ruletype, string $ru
4446

4547
// set up rule data array.
4648
$rule_data = [
47-
'postid' => $post->ID,
48-
'siteid' => get_current_blog_id(),
49-
'type' => $post->post_type,
50-
'rule' => $rule,
51-
'ruletype' => $ruletype,
52-
'object' => esc_attr( $rule_obj ),
53-
'recordcheck' => 1,
54-
'user' => get_current_user_id(),
55-
'ignre' => 0,
56-
'ignre_user' => null,
57-
'ignre_date' => null,
58-
'ignre_comment' => null,
59-
'ignre_global' => 0,
49+
'postid' => $post->ID,
50+
'siteid' => get_current_blog_id(),
51+
'type' => $post->post_type,
52+
'landmark' => $landmark,
53+
'landmark_selector' => $landmark_selector,
54+
'rule' => $rule,
55+
'ruletype' => $ruletype,
56+
'object' => esc_attr( $rule_obj ),
57+
'recordcheck' => 1,
58+
'user' => get_current_user_id(),
59+
'ignre' => 0,
60+
'ignre_user' => null,
61+
'ignre_date' => null,
62+
'ignre_comment' => null,
63+
'ignre_global' => 0,
6064
];
6165

6266
// return if revision.
@@ -125,19 +129,21 @@ public function insert( object $post, string $rule, string $ruletype, string $ru
125129
// the data is still as valid as it was when it was first set.
126130
// Sanitize the filtered data.
127131
$rule_data_sanitized = [
128-
'postid' => absint( $rule_data['postid'] ),
129-
'siteid' => absint( $rule_data['siteid'] ),
130-
'type' => sanitize_text_field( $rule_data['type'] ),
131-
'rule' => sanitize_text_field( $rule_data['rule'] ),
132-
'ruletype' => sanitize_text_field( $rule_data['ruletype'] ),
133-
'object' => esc_attr( $rule_data['object'] ),
134-
'recordcheck' => absint( $rule_data['recordcheck'] ),
135-
'user' => absint( $rule_data['user'] ),
136-
'ignre' => absint( $rule_data['ignre'] ),
137-
'ignre_user' => isset( $rule_data['ignre_user'] ) ? absint( $rule_data['ignre_user'] ) : null,
138-
'ignre_date' => isset( $rule_data['ignre_date'] ) ? sanitize_text_field( $rule_data['ignre_date'] ) : null,
139-
'ignre_comment' => isset( $rule_data['ignre_comment'] ) ? sanitize_text_field( $rule_data['ignre_comment'] ) : null,
140-
'ignre_global' => absint( $rule_data['ignre_global'] ),
132+
'postid' => absint( $rule_data['postid'] ),
133+
'siteid' => absint( $rule_data['siteid'] ),
134+
'type' => sanitize_text_field( $rule_data['type'] ),
135+
'landmark' => isset( $rule_data['landmark'] ) ? sanitize_text_field( $rule_data['landmark'] ) : null,
136+
'landmark_selector' => isset( $rule_data['landmark_selector'] ) ? sanitize_text_field( $rule_data['landmark_selector'] ) : null,
137+
'rule' => sanitize_text_field( $rule_data['rule'] ),
138+
'ruletype' => sanitize_text_field( $rule_data['ruletype'] ),
139+
'object' => esc_attr( $rule_data['object'] ),
140+
'recordcheck' => absint( $rule_data['recordcheck'] ),
141+
'user' => absint( $rule_data['user'] ),
142+
'ignre' => absint( $rule_data['ignre'] ),
143+
'ignre_user' => isset( $rule_data['ignre_user'] ) ? absint( $rule_data['ignre_user'] ) : null,
144+
'ignre_date' => isset( $rule_data['ignre_date'] ) ? sanitize_text_field( $rule_data['ignre_date'] ) : null,
145+
'ignre_comment' => isset( $rule_data['ignre_comment'] ) ? sanitize_text_field( $rule_data['ignre_comment'] ) : null,
146+
'ignre_global' => absint( $rule_data['ignre_global'] ),
141147
];
142148

143149
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery -- Using direct query for adding data to database.

admin/class-update-database.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public function edac_update_database() {
4848
postid bigint(20) NOT NULL,
4949
siteid text NOT NULL,
5050
type text NOT NULL,
51+
landmark varchar(20) NULL,
52+
landmark_selector text NULL,
5153
rule text NOT NULL,
5254
ruletype text NOT NULL,
5355
object mediumtext NOT NULL,

includes/classes/class-rest-api.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,10 @@ public function set_post_scan_results( $request ) {
380380
*/
381381
do_action( 'edac_before_rule', $post_id, $actual_rule_id, 'js' );
382382

383-
( new Insert_Rule_Data() )->insert( $post, $actual_rule_id, $impact, $html );
383+
$landmark = $violation['landmark'] ?? null;
384+
$landmark_selector = $violation['landmarkSelector'] ?? null;
385+
386+
( new Insert_Rule_Data() )->insert( $post, $actual_rule_id, $impact, $html, $landmark, $landmark_selector );
384387

385388
/**
386389
* Fires after a rule is run against the content.

src/admin/sass/accessibility-checker-admin.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@
621621
color: variables.$color-white;
622622
background-color: variables.$color-dark-gray;
623623
display: grid;
624-
grid-template-columns: auto 125px 125px;
624+
grid-template-columns: auto 125px 125px 125px;
625625

626626
&-label {
627627
padding: 3px;
@@ -631,7 +631,7 @@
631631

632632
&-record {
633633
display: grid;
634-
grid-template-columns: auto 125px 125px;
634+
grid-template-columns: auto 125px 125px 125px;
635635

636636
&-cell {
637637
padding: 10px;

0 commit comments

Comments
 (0)