$permalink ) );
$results = $results['formatted'];
return $results.$content;
}
return $content;
}
function am_query_tenon( $post ) {
// creates the $opts array from the $post data
// only sets items that are non-blank. This allows Tenon to revert to defaults
$expectedPost = array( 'src', 'url', 'level', 'certainty', 'priority',
'docID', 'projectID', 'viewPortHeight', 'viewPortWidth',
'uaString', 'importance', 'ref', 'importance', 'fragment', 'store' );
foreach ( $post AS $k => $v ) {
if ( in_array($k, $expectedPost ) ) {
if ( strlen( trim( $v ) ) > 0 ) {
$opts[$k] = $v;
}
}
}
$settings = get_option( 'am_settings' );
$key = $settings['tenon_api_key'];
/* Tenon uses the application ID to credit specific application authors with API usage. Please leave this intact! Thanks! */
$appID = '8cfaff90a1bd9eaa59c8bbc2e75f8657';
if ( $key ) {
$opts['key'] = $key;
$opts['appID'] = $appID;
$tenon = new tenon( TENON_API_URL, $opts );
$tenon->submit( AM_DEBUG );
$body = $tenon->tenonResponse['body'];
$formatted = am_format_tenon( $body );
$object = json_decode( $body );
if ( property_exists( $object, 'resultSet' ) ) {
$results = $object->resultSet;
} else {
$results = array();
}
$grade = am_percentage( $object );
if ( $grade === false ) {
if ( trim( $object->message ) == 'Bad Request - Either src or url parameter must be supplied' ) {
$message = __( 'Save your post as a draft in order to test for accessibility.', 'access-monitor' );
} else {
$message = $object->message;
}
$formatted = '
' . __( 'Tenon error:', 'access-monitor' ) . ' ' . $message . '
';
$grade = 0;
}
return array( 'formatted'=> $formatted, 'results' => $results, 'grade' => $grade );
} else {
return false;
}
}
function am_format_tenon( $body ) {
if ( $body === false ) {
return __( 'No Tenon API Key provided', 'access-monitor' );
}
$object = json_decode( $body );
if ( property_exists( $object, 'resultSummary' ) ) {
// unchecked object references
$errors = $object->resultSummary->issues->totalIssues;
} else {
$errors = 0;
}
if ( property_exists( $object, 'resultSet' ) ) {
$results = $object->resultSet;
} else {
$results = array();
}
$return = am_format_tenon_array( $results, $errors );
return $return;
}
function am_format_tenon_array( $results, $errors ) {
$return = "".sprintf( __( '%s accessibility issues identified.', 'access-monitor' ), "$errors" )."
";
$i = 0;
if ( !empty( $results ) ) {
foreach( $results as $result ) {
$i++;
switch( $result->certainty ) {
case ( $result->certainty >= 80 ) : $cert = 'high'; break;
case ( $result->certainty >= 40 ) : $cert = 'medium'; break;
default: $cert = 'low';
}
switch( $result->priority ) {
case ( $result->priority >= 80 ) : $prio = 'high'; break;
case ( $result->priority >= 40 ) : $prio = 'medium'; break;
default: $prio = 'low';
}
$bpID = $result->bpID;
$tID = $result->tID;
$href = esc_url( add_query_arg( array( 'bpID'=>$bpID, 'tID'=>$tID ), 'http://tenon.io/bestpractice.php' ) );
$ref = "" . __( 'Read more:', 'access-monitor' ) . " $result->resultTitle";
$return .= "
$i. $result->errorTitle
". sprintf( __( 'Certainty: %s', 'access-monitor' ), "$result->certainty%" ). "
". sprintf( __( 'Priority: %s', 'access-monitor' ), "$result->priority%" ). "
$result->errorDescription $ref
Error Source
".$result->errorSnippet."
Xpath:
$result->xpath
";
}
} else {
$return .= "Congratulations! Tenon didn't find any issues on this page.
";
}
return $return . "
";
}
add_action('admin_enqueue_scripts', 'am_admin_enqueue_scripts');
function am_admin_enqueue_scripts() {
global $current_screen;
if ( $current_screen->id == 'customize' || $current_screen->id == 'press-this' ) {
// We don't want any of this on these screens.
} else {
// The customizer doesn't have an adminbar; so no reason to enqueue this. Also, it breaks the customizer. :)
wp_enqueue_script( 'am.functions', plugins_url( 'js/jquery.ajax.js', __FILE__ ), array( 'jquery' ) );
wp_localize_script( 'am.functions', 'am_ajax_url', admin_url( 'admin-ajax.php' ) );
wp_localize_script( 'am.functions', 'am_ajax_action', 'am_ajax_query_tenon' );
wp_localize_script( 'am.functions', 'am_current_screen', $current_screen->id );
wp_enqueue_style( 'am.styles', plugins_url( 'css/am-styles.css', __FILE__ ) );
}
}
add_action('wp_enqueue_scripts', 'am_wp_enqueue_scripts');
function am_wp_enqueue_scripts() {
wp_enqueue_style( 'am.styles', plugins_url( 'css/am-styles.css', __FILE__ ) );
}
add_action('wp_ajax_am_ajax_query_tenon', 'am_ajax_query_tenon');
add_action('wp_ajax_nopriv_am_ajax_query_tenon', 'am_ajax_query_tenon');
function am_ajax_query_tenon() {
if ( isset( $_REQUEST['tenon'] ) ) {
$screen = $_REQUEST['current_screen'];
$args = array();
if ( $screen == 'dashboard' ) {
$args = array( 'src'=>stripslashes( $_REQUEST['tenon'] ) );
} else {
$args = array( 'src'=>stripslashes( $_REQUEST['tenon'] ), 'fragment' => 1 );
}
if ( isset( $_REQUEST['level'] ) ) {
$args['level'] = $_REQUEST['level'];
}
if ( isset( $_REQUEST['fragment'] ) ) {
$args['fragment'] = $_REQUEST['fragment'];
}
if ( isset( $_REQUEST['certainty'] ) ) {
$args['certainty'] = $_REQUEST['certainty'];
}
if ( isset( $_REQUEST['priority'] ) ) {
$args['priority'] = $_REQUEST['priority'];
}
$results = am_query_tenon( $args );
wp_send_json(
array(
'response'=>1,
'results'=>$results['results'],
'formatted' => $results['formatted'],
'grade' => $results['grade']
)
);
}
}
add_action( 'admin_footer', 'am_admin_footer' );
function am_admin_footer() {
echo "";
}
add_action( 'admin_bar_menu','am_admin_bar', 200 );
function am_admin_bar() {
global $wp_admin_bar;
if ( is_admin() ) {
$url = '#tenon';
} else {
global $post_id;
$url = add_query_arg( 'tenon', 'true', get_permalink( $post_id ) );
}
$args = array( 'id'=>'tenonCheck', 'title'=>__( 'A11y Check','access-monitor' ), 'href'=>$url );
$wp_admin_bar->add_node( $args );
}
add_filter( 'the_content', 'am_wave_pass_query' );
function am_wave_pass_query( $content ) {
if ( isset( $_GET['wave'] ) && is_numeric( $_GET['wave'] ) ) {
$permalink = get_the_permalink();
$reporttype = (int) $_GET['wave'];
$results = am_query_wave( array( 'url'=>$permalink, 'reporttype'=>$reporttype ) );
return $results.$content;
}
return $content;
}
function am_query_wave( $post ) {
// creates the $opts array from the $post data
// only sets items that are non-blank. This allows Tenon to revert to defaults
$expectedPost = array( 'key', 'url', 'reporttype', 'format' );
foreach ( $post AS $k => $v ) {
if ( in_array($k, $expectedPost ) ) {
if ( strlen( trim( $v ) ) > 0 ) {
$opts[$k] = $v;
}
}
}
$settings = get_option( 'am_settings' );
$key = $settings['wave_api_key'];
if ( $key ) {
$opts['key'] = $key;
$wave = new wave( WAVE_API_URL, $opts );
$wave->submit( AM_DEBUG );
$body = $wave->waveResponse['body'];
$results = am_format_wave( $body, $opts['reporttype'] );
return $results;
} else {
return false;
}
}
function am_format_wave( $body, $reporttype=1 ) {
$body = json_decode( $body );
$credits = $body->statistics->creditsremaining;
$itemcount = $body->statistics->allitemcount;
$waveurl = $body->statistics->waveurl;
$categories = $body->categories;
$report = '';
foreach ( $categories as $cat => $category ) {
$report .= "- $category->description: $category->count
";
}
$report .= "
";
$report = "
";
return $report;
}
add_action( 'init', 'am_posttypes' );
function am_posttypes() {
$value = array(
__( 'accessibility report','access-monitor' ),
__( 'accessibility reports','access-monitor' ),
__( 'Accessibility Report','access-monitor' ),
__( 'Accessibility Reports','access-monitor' ),
);
$labels = array(
'name' => $value[3],
'singular_name' => $value[2],
'add_new' => __( 'Add New' , 'access-monitor' ),
'add_new_item' => sprintf( __( 'Create New %s','access-monitor' ), $value[2] ),
'edit_item' => sprintf( __( 'Modify %s','access-monitor' ), $value[2] ),
'new_item' => sprintf( __( 'New %s','access-monitor' ), $value[2] ),
'view_item' => sprintf( __( 'View %s','access-monitor' ), $value[2] ),
'search_items' => sprintf( __( 'Search %s','access-monitor' ), $value[3] ),
'not_found' => sprintf( __( 'No %s found','access-monitor' ), $value[1] ),
'not_found_in_trash' => sprintf( __( 'No %s found in Trash','access-monitor' ), $value[1] ),
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => false,
'show_ui' => true,
'show_in_menu' => true,
'menu_icon' => 'dashicons-universal-access',
'supports' => array( 'title' )
);
register_post_type( 'tenon-report', $args );
}
add_action( 'admin_menu', 'am_add_outer_box' );
// begin add boxes
function am_add_outer_box() {
add_meta_box( 'am_report_div', __('Accessibility Report', 'access-monitor'), 'am_add_inner_box', 'tenon-report', 'normal','high' );
add_meta_box( 'am_about_div', __('About this Report', 'access-monitor'), 'am_add_about_box', 'tenon-report', 'side', 'high' );
add_meta_box( 'am_related_div', __('Related Reports', 'access-monitor'), 'am_add_related_box', 'tenon-report', 'side','high' );
}
function am_add_inner_box() {
global $post;
$content = stripslashes( $post->post_content );
$data = get_post_meta( $post->ID, '_tenon_json', true );
$content .= "".__('JSON Submission Data', 'access-monitor').":
".print_r( $data, 1 )."
";
echo ''.$content.'
';
}
function am_add_related_box() {
global $post;
$related = '';
$relatives = get_posts( array(
'post_type' => 'tenon-report',
'meta_key' => '_tenon_parent',
'meta_value' => $post->ID
) );
if ( !empty( $relatives ) ) {
foreach ( $relatives as $relative ) {
$title = $relative->post_title;
$id = $relative->ID;
$link = get_edit_post_link( $id );
$date = get_the_time( 'M j, Y @ H:i', $id );
if ( $id != $post->ID ) {
$related .= "$title: $date";
}
}
echo "";
}
if ( empty( $relatives ) ) {
echo "" . __( 'No related reports.', 'access-monitor' ) . "
";
}
}
function am_add_about_box() {
global $post;
$urls = $parameters = '';
$pages = get_post_meta( $post->ID, '_tenon_pages', true );
$params = get_post_meta( $post->ID, '_tenon_params', true );
$total = get_post_meta( $post->ID, '_tenon_total', true );
echo "" . sprintf( __( '%s unique errors', 'access-monitor' ), "$total" ) . "
";
if ( is_array( $pages ) ) {
foreach ( $pages as $url ) {
$page = str_replace( array( 'http://', 'https://', 'http://www.', 'https://www.' ), '', $url );
$urls .= "$page";
}
unset( $params['url'] );
foreach ( $params as $key => $value ) {
$key = stripslashes( trim( $key ) );
$value = stripslashes( trim( $value ) );
if ( $value == '' ) { $value = '' . __( 'Default', 'access-monitor' ) . ''; }
$label = ucfirst( $key );
$parameters .= "$label: $value";
}
echo "" . __( 'URLs Tested', 'access-monitor' ) . "
";
echo "" . __( 'Test Parameters', 'access-monitor' ) . "
";
echo "" . __( 'Tenon Request Parameters', 'access-monitor' ) . "
";
} else {
echo "" . __( 'No pages tested yet.', 'access-monitor' ) . "
";
}
}
add_action('admin_menu', 'am_remove_menu_item');
function am_remove_menu_item() {
global $submenu;
unset( $submenu['edit.php?post_type=tenon-report'][10] ); // Removes 'Add New'.
}
function am_set_report( $name = false ) {
if ( !$name ) {
$name = date_i18n( 'Y-m-d H:i:s', current_time( 'timestamp' ) );
}
$report_id = wp_insert_post( array( 'post_content'=>'', 'post_title'=>$name, 'post_status'=>'draft', 'post_type'=>'tenon-report' ) );
//$reports = ( get_option( 'am_reports' ) != '' ) ? get_option( 'am_reports' ) : array();
return $report_id;
}
register_deactivation_hook( __FILE__, 'am_deactivate_cron' );
function am_deactivate_cron() {
wp_clear_scheduled_hook( 'amcron' );
}
add_action( 'amcron', 'am_schedule_report', 10, 4 );
function am_schedule_report( $report_id, $pages, $name, $params ) {
$new_report = am_generate_report( $name, $pages, $report_id, $params ); // 'none' to prevent this from being auto-scheduled again
$url = admin_url( "post.php?post=$new_report&action=edit" );
update_post_meta( $new_report, '_tenon_parent', $report_id );
add_post_meta( $report_id, '_tenon_child', $new_report );
wp_mail(
apply_filters( 'am_cron_notification_email', get_option( 'admin_email' ), $name ),
sprintf( __( 'Scheduled Accessibility Report on %s', 'access-monitor' ), get_option( 'blogname' ) ),
sprintf( __( "View accessibility report: %s", 'access-monitor' ), $url )
);
}
function am_generate_report( $name, $pages = false, $schedule = 'none', $params = array() ) {
$report_id = am_set_report( $name );
if ( is_array( $pages ) ) {
$pages = $pages;
} else {
$pages = array( home_url() );
}
if ( $schedule != 'none' ) {
if ( ! is_numeric( $schedule ) ) {
$timestamp = ( $schedule == 'weekly' ) ? current_time( 'timestamp' ) + 60*60*24*7 : current_time( 'timestamp' ) + ( 60*60*24*30.5 );
$args = array( 'report_id'=>$report_id, 'pages'=>$pages, 'name'=>$name, 'params'=>$params );
wp_schedule_event( $timestamp, $schedule, 'amcron', $args );
update_post_meta( $report_id, '_tenon_schedule', $schedule );
} else {
update_post_meta( $report_id, '_tenon_schedule', $schedule );
}
}
foreach ( $pages as $page ) {
if ( is_numeric( $page ) ) {
$url = get_permalink( $page );
} else {
$url = $page;
}
if ( esc_url( $url ) ) {
$params['url'] = $url;
$report = am_query_tenon( $params );
$report = $report['results'];
$saved[$url] = $report;
} else {
continue;
}
}
$data = am_format_tenon_report( $saved, $name );
$total = $data['total'];
$formatted = $data['html'];
remove_action( 'save_post', 'am_run_report' );
wp_update_post( array(
'ID'=>$report_id,
'post_content'=> $formatted
) );
update_post_meta( $report_id, '_tenon_total', $total );
update_post_meta( $report_id, '_tenon_json', $saved );
if ( isset( $params['projectID'] ) && $params['projectID'] != '' ) {
update_post_meta( $report_id, '_tenon_projectID', $params['projectID'] );
}
update_post_meta( $report_id, '_tenon_params', $params );
update_post_meta( $report_id, '_tenon_pages', $pages );
wp_publish_post( $report_id );
add_action( 'save_post', 'am_run_report' );
return $report_id;
}
add_action( 'save_post', 'am_run_report' );
/**
* Re-run a test cycle when updating post.
*/
function am_run_report( $id ) {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE || wp_is_post_revision( $id ) || !( get_post_type( $id ) == 'tenon-report' ) ) {
return;
}
$post = get_post( $id );
if ( $post->post_status != 'publish' ) {
return;
}
$name = get_the_title( $id );
$pages = get_post_meta( $id, '_tenon_pages', true );
$params = get_post_meta( $id, '_tenon_params', true );
$params = ( empty( $params ) ) ? array() : $params;
if ( empty( $pages ) ) {
return;
}
remove_action( 'save_post', 'am_run_report' );
$report_id = am_generate_report( $name, $pages, 'none', $params );
add_post_meta( $id, '_tenon_child', $report_id );
update_post_meta( $report_id, '_tenon_parent', $id );
add_action( 'save_post', 'am_run_report' );
}
function am_show_report( $report_id = false ) {
$report_id = ( isset( $_GET['report'] ) && is_numeric( $_GET['report'] ) ) ? $_GET['report'] : false;
$output = $name = '';
if ( $report_id ) {
$report = get_post( $report_id );
$output = $report->post_content;
$name = $report->post_title;
} else {
$reports = wp_get_recent_posts( array( 'numberposts'=>1, 'post_type'=>'tenon-report', 'post_status'=>'publish' ), 'OBJECT' );
$report = end( $reports );
if ( $report ) {
$output = $report->post_content;
$name = $report->post_title;
}
}
if ( $output != '' ) {
echo $output;
} else {
$data = am_format_tenon_report( get_post_meta( $report_id, '_tenon_json', true ), $name );
$formatted = $data['html'];
$total = $data['total'];
wp_update_post( array( 'ID'=>$report_id, 'post_content' => $formatted ) );
update_post_meta( $report_id, '_tenon_total', $total );
echo $formatted;
}
}
function am_column($cols) {
$cols['am_total'] = __( 'Errors', 'access-monitor' );
$cols['am_schedule'] = __( 'Schedule', 'access-monitor' );
$cols['am_tested'] = __( 'Level', 'access-monitor' );
return $cols;
}
// Echo the ID for the new column
function am_custom_column( $column_name, $id ) {
switch ( $column_name ) {
case 'am_total' :
$total = get_post_meta( $id, '_tenon_total', true );
echo $total;
break;
case 'am_tested' :
$params = get_post_meta( $id, '_tenon_params', true );
echo isset( $params['level'] ) ? $params['level'] : '';
break;
case 'am_schedule' :
$schedule = get_post_meta( $id, '_tenon_schedule', true );
if ( is_numeric( $schedule ) ) {
$edit_url = admin_url( "post.php?post=$schedule&action=edit" );
$edit_link = " " . __( 'View Original Test', 'access-monitor' ) . "";
echo $edit_link;
} else {
if ( $schedule ) {
echo ucfirst( $schedule );
} else {
_e( 'One-time report', 'access-monitor' );
}
}
break;
}
}
function am_return_value( $value, $column_name, $id ) {
if ( $column_name == 'am_total' || $column_name == 'am_schedule' || $column_name == 'am_level' ) {
$value = $id;
}
return $value;
}
// Actions/Filters for message tables and css output
add_action('admin_init', 'am_add');
function am_add() {
add_filter( "manage_tenon-report_posts_columns", 'am_column' );
add_action( "manage_tenon-report_posts_custom_column", 'am_custom_column', 10, 2 );
}
function am_format_tenon_report( $results, $name ) {
$header = "".stripslashes( $name )."; ".__( 'Results from %d pages tested', 'access-monitor' ). "
";
$return = $tbody = '';
$displayed = false;
$i = $count = $total = 0;
if ( !empty( $results ) ) {
$reported = array();
$count = count( $results );
foreach ( $results as $url => $resultSet ) {
$tbody = $thead = '';
$result_count = count( $resultSet );
if ( $result_count > 0 ) {
foreach ( $resultSet as $result ) {
$i++;
$hash = md5( $result->resultTitle . $result->ref . $result->errorSnippet . $result->xpath );
if ( !in_array( $hash, $reported ) ) {
$displayed = true;
$total++;
// right now, tenon.io is broken over https. So, strip back to non-https.
$href = str_replace( 'https', 'http', $result->ref );
$ref = "$result->errorTitle";
$tbody .= "
| $ref $result->resultTitle; $result->errorDescription |
$result->certainty |
$result->priority |
$result->errorSnippet |
$result->xpath |
";
} else {
$displayed = false;
}
$reported[] = $hash;
}
if ( !$displayed ) {
$return .= "" . sprintf( __( "Errors found on %s.", 'access-monitor' ), "$url" ) . " ($result_count)
" . sprintf( __( 'The %d errors found on this page were also found on other pages tested.', 'access-monitor' ), $result_count ) . "
";
} else {
$thead = "";
$thead .= "" . sprintf( __( "Errors found on %s.", 'access-monitor' ), "$url" ) . " ($result_count)";
$thead .= "
| ".__( 'Issue', 'access-monitor' )." |
".__( 'Certainty', 'access-monitor' )." |
".__( 'Priority', 'access-monitor' )." |
".__( 'Source', 'access-monitor' )." |
".__( 'Xpath', 'access-monitor' )." |
";
$tfoot = "
| ".__( 'Issue', 'access-monitor' )." |
".__( 'Certainty', 'access-monitor' )." |
".__( 'Priority', 'access-monitor' )." |
".__( 'Source', 'access-monitor' )." |
".__( 'Xpath', 'access-monitor' )." |
";
$return .= $thead . $tbody . $tfoot;
}
} else {
$return .= "".sprintf( __( "No errors found on %s.", 'access-monitor' ), "$url" )."
";
}
}
} else {
$return .= "Congratulations! Tenon didn't find any issues on this page.
";
}
$header = sprintf( $header, $count );
return array( 'total'=>$total, 'html' => $header . $return );
}
add_filter( 'cron_schedules', 'am_custom_schedules' );
function am_custom_schedules( $schedules ) {
// Adds once weekly to the existing schedules.
$schedules['weekly'] = array(
'interval' => 604800,
'display' => __( 'Once Weekly', 'access-monitor' )
);
$schedules['monthly'] = array(
'interval' => 2635200,
'display' => __( 'Once Monthly', 'access-monitor' )
);
return $schedules;
}
function am_update_settings() {
if ( isset( $_POST['am_settings'] ) ) {
$nonce=$_REQUEST['_wpnonce'];
if (! wp_verify_nonce($nonce,'access-monitor-nonce') ) die( "Security check failed" );
$tenon_api_key = ( isset( $_POST['tenon_api_key'] ) ) ? $_POST['tenon_api_key'] : '';
$wave_api_key = ( isset( $_POST['wave_api_key'] ) ) ? $_POST['wave_api_key'] : '';
$tenon_pre_publish = ( isset( $_POST['tenon_pre_publish'] ) ) ? 1 : 0;
$am_post_types = ( isset( $_POST['am_post_types'] ) ) ? $_POST['am_post_types'] : array();
$am_criteria = ( isset( $_POST['am_criteria'] ) ) ? $_POST['am_criteria'] : array();
$am_notify = ( isset( $_POST['am_notify'] ) ) ? $_POST['am_notify'] : '';
update_option( 'am_settings',
array(
'tenon_api_key' => $tenon_api_key,
'wave_api_key' => $wave_api_key,
'am_post_types' => $am_post_types,
'tenon_pre_publish' => $tenon_pre_publish,
'am_criteria' => $am_criteria,
'am_notify' => $am_notify
)
);
echo "" . __( 'Access Monitor Settings Updated', 'access-monitor' ) . "
";
}
}
add_action( 'admin_head', 'am_setup_admin_notice' );
function am_setup_admin_notice() {
if ( !( isset( $_POST['tenon_api_key'] ) && $_POST['tenon_api_key'] != '' ) ) {
$settings = ( is_array( get_option( 'am_settings' ) ) ) ? get_option( 'am_settings' ) : array();
if ( empty( $settings ) || !isset( $settings['tenon_api_key'] ) || $settings['tenon_api_key'] == '' ) {
if ( isset( $_GET['page'] ) && $_GET['page'] == 'access-monitor/access-monitor.php' ) {
$url = '#settings';
} else {
$url = admin_url('edit.php?post_type=tenon-report&page=access-monitor/access-monitor.php');
}
$message = sprintf(__("You must enter a Tenon API key to use Access Monitor.", 'access-monitor'), $url );
add_action('admin_notices', create_function( '', "if ( ! current_user_can( 'manage_options' ) ) { return; } else { echo \"\";}" ) );
}
}
}
function am_settings() {
$settings = ( is_array( get_option( 'am_settings' ) ) ) ? get_option( 'am_settings' ) : array();
$settings = array_merge( array( 'tenon_api_key'=>'', 'wave_api_key'=>'', 'tenon_pre_publish' => '', 'am_post_types' => array(), 'am_post_grade' => '', 'am_criteria' => array() ), $settings );
$post_types = get_post_types( array( 'public' => true, 'show_ui' => true ), 'objects' );
$am_post_types = isset( $settings['am_post_types'] ) ? $settings['am_post_types'] : array();
$am_criteria = isset( $settings['am_criteria'] ) ? $settings['am_criteria'] : array();
$am_notify = isset( $settings['am_notify'] ) ? $settings['am_notify'] : get_option( 'admin_email' );
$am_post_type_options = '';
foreach ( $post_types as $type ) {
if ( in_array( $type->name, $am_post_types ) ) {
$selected = ' checked="checked"';
} else {
$selected = '';
}
if ( $type->name != 'attachment' ) {
$am_post_type_options .= " ";
}
}
echo "
";
}
function am_report() {
$settings = ( is_array( get_option( 'am_settings' ) ) ) ? get_option( 'am_settings' ) : array();
$settings = array_merge( array( 'tenon_api_key'=>'', 'wave_api_key'=>'' ), $settings );
if ( $settings['tenon_api_key'] == '' ) {
$disabled = " disabled='disabled'";
$message = "" . __( 'Sign up with Tenon to get an API key', 'access-monitor' ) . " • " . __( 'Add your API key', 'access-monitor' ) . "
";
} else {
$disabled = $message = '';
}
echo am_setup_report();
$theme = wp_get_theme();
$theme_name = $theme->Name;
$theme_version = $theme->Version;
$name = $theme_name . ' ' . $theme_version;
echo "$message
";
}
function am_setup_report() {
if ( isset( $_POST['am_generate'] ) ) {
$name = ( isset( $_POST['am_report_name'] ) ) ? sanitize_text_field( $_POST['am_report_name'] ) : false;
$pages = ( isset( $_POST['am_report_pages'] ) && !empty( $_POST['am_report_pages'] ) ) ? $_POST['am_report_pages'] : false;
$schedule = ( isset( $_POST['report_schedule'] ) ) ? $_POST['report_schedule'] : 'none';
$store = ( isset( $_POST['store'] ) ) ? 1 : 0;
$projectID = ( isset( $_POST['projectID'] ) ) ? sanitize_text_field( $_POST['projectID'] ) : '';
$viewport = ( isset( $_POST['viewport'] ) ) ? explode( 'x', $_POST['viewport'] ) : array( '1024', '768' );
$viewportHeight = $viewport[1];
$viewportWidth = $viewport[0];
$level = ( isset( $_POST['level'] ) ) ? $_POST['level'] : 'AA';
$priority = ( isset( $_POST['priority'] ) ) ? (int) $_POST['priority'] : 0;
$certainty = ( isset( $_POST['certainty'] ) ) ? (int) $_POST['certainty'] : 0;
$args = array(
'store' => $store,
'projectID' => $projectID,
'viewPortHeight' => $viewportHeight,
'viewPortWidth' => $viewportWidth,
'level' => $level,
'priority' => $priority,
'certainty' => $certainty
);
/*
Set up arguments here; pass to am_generate_report
importance (not present yet; field specific; associate with URL)
*/
am_generate_report( $name, $pages, $schedule, $args );
am_show_report();
}
}
function am_list_reports( $count = 10 ) {
$count = (int) $count;
$reports = wp_get_recent_posts( array( 'post_type'=>'tenon-report', 'numberposts'=>$count, 'post_status'=>'publish' ), 'OBJECT' );
if ( is_array( $reports ) ) {
echo "";
foreach ( $reports as $report_post ) {
$report = json_decode( $report_post->post_content );
$report_id = $report_post->ID;
$link = get_edit_post_link( $report_id );
$date = get_the_time( 'Y-m-d H:i:s', $report_post );
$name = $report_post->post_title;
echo "- ".stripslashes( $name )." ($date)
";
}
echo "
";
} else {
echo "".__( 'No accessibility reports created yet.', 'access-monitor' )."
";
}
}
function am_support_page() {
$elem = ( version_compare( '4.4', get_option( 'version' ), '>' ) ) ? 'h3' : 'h2';
$parent = ( version_compare( '4.4', get_option( 'version' ), '>' ) ) ? 'h2' : 'h1';
?>
' ) ) ? 'h3' : 'h2';
?>
Add New Report', 'access-monitor' ), __( 'Add Report/Settings', 'access-monitor' ), $permissions, __FILE__, 'am_support_page' );
add_action( 'load-'. $plugin_page, 'am_load_admin_styles' );
}
}
function am_load_admin_styles() {
add_action( 'admin_enqueue_scripts', 'am_admin_styles' );
}
function am_admin_styles() {
wp_enqueue_style( 'am-admin-styles', plugins_url( 'css/am-admin-styles.css', __FILE__ ) );
}
function am_get_support_form() {
global $current_user, $am_version;
get_currentuserinfo();
// send fields for Access Monitor
$version = $am_version;
// send fields for all plugins
$wp_version = get_bloginfo('version');
$home_url = home_url();
$wp_url = site_url();
$language = get_bloginfo('language');
$charset = get_bloginfo('charset');
// server
$php_version = phpversion();
// theme data
$theme = wp_get_theme();
$theme_name = $theme->Name;
$theme_uri = $theme->ThemeURI;
$theme_parent = $theme->Template;
$theme_version = $theme->Version;
// plugin data
$plugins = get_plugins();
$plugins_string = '';
foreach( array_keys($plugins) as $key ) {
if ( is_plugin_active( $key ) ) {
$plugin =& $plugins[$key];
$plugin_name = $plugin['Name'];
$plugin_uri = $plugin['PluginURI'];
$plugin_version = $plugin['Version'];
$plugins_string .= "$plugin_name: $plugin_version; $plugin_uri\n";
}
}
$data = "
================ Installation Data ====================
Version: $version
==WordPress:==
Version: $wp_version
URL: $home_url
Install: $wp_url
Language: $language
Charset: $charset
==Extra info:==
PHP Version: $php_version
Server Software: $_SERVER[SERVER_SOFTWARE]
User Agent: $_SERVER[HTTP_USER_AGENT]
==Theme:==
Name: $theme_name
URI: $theme_uri
Parent: $theme_parent
Version: $theme_version
==Active Plugins:==
$plugins_string
";
if ( isset($_POST['am_support']) ) {
$nonce=$_REQUEST['_wpnonce'];
if (! wp_verify_nonce($nonce,'access-monitor-nonce') ) die("Security check failed");
$request = stripslashes( $_POST['support_request'] );
$has_donated = ( isset( $_POST['has_donated'] ) && $_POST['has_donated'] == 'on')?"Donor":"No donation";
$has_read_faq = ( isset( $_POST['has_read_faq'] ) && $_POST['has_read_faq'] == 'on')?"Read FAQ":true; // has no faq, for now.
$subject = "Access Monitor support request. $has_donated";
$message = $request ."\n\n". $data;
// Get the site domain and get rid of www. from pluggable.php
$sitename = strtolower( $_SERVER['SERVER_NAME'] );
if ( substr( $sitename, 0, 4 ) == 'www.' ) {
$sitename = substr( $sitename, 4 );
}
$from_email = 'wordpress@' . $sitename;
$from = "From: \"$current_user->display_name\" <$from_email>\r\nReply-to: \"$current_user->display_name\" <$current_user->user_email>\r\n";
if ( !$has_read_faq ) {
echo "".__('Please read the FAQ and other Help documents before making a support request.','access-monitor')."
";
} else {
wp_mail( "plugins@joedolson.com",$subject,$message,$from );
if ( $has_donated == 'Donor' ) {
echo "".__('Thank you for supporting the continuing development of this plug-in! I\'ll get back to you as soon as I can.','access-monitor')."
";
} else {
echo "".__('I\'ll get back to you as soon as I can, after dealing with any support requests from plug-in supporters.','access-monitor')."
";
}
}
} else {
$request = '';
}
echo "
";
}
add_filter( 'gettext', 'change_publish_button', 10, 2 );
/**
* Changes the publish button from saying 'Update' to 'Re-run this test'
*
*/
function change_publish_button( $translation, $text ) {
if ( is_admin() && isset( $_GET['action'] ) && $_GET['action'] == 'edit' ) {
global $post;
if ( is_object( $post ) ) {
if ( $text == 'Update' && $post->post_type == 'tenon-report' ) {
$translation = __( 'Re-run this test', 'access-monitor' );
}
}
}
return $translation;
}
add_action( 'current_screen', 'am_redirect_new' );
/**
* Prevents the default add new post screen from showing.
*
*/
function am_redirect_new() {
$screen = get_current_Screen();
if ( $screen->id == 'tenon-report' && !isset( $_GET['action'] ) ) {
wp_safe_redirect( admin_url('edit.php?post_type=tenon-report&page=access-monitor/access-monitor.php') );
}
}
/**
* Add "Settings" link into Plug-in list
*/
add_filter('plugin_action_links', 'am_plugin_action', -10, 2);
function am_plugin_action($links, $file) {
if ($file == plugin_basename(dirname(__FILE__).'/access-monitor.php')) {
$links[] = "" . __( 'Access Monitor Settings', 'access-monitor' ) . "";
}
return $links;
}