__( 'Scan finished. Services found on your site are marked "Found".', 'ariconsent' ),
'scan_failed' => __( 'The scan could not load your site. Check that the site is reachable from the server.', 'ariconsent' ),
'reconsent' => __( 'Done. Every visitor will be asked for consent again on their next visit.', 'ariconsent' ),
'policy_failed' => __( 'The cookie policy page could not be created. Try again, or add the [ariconsent_declaration] shortcode to a page yourself.', 'ariconsent' ),
'imported' => __( 'Settings imported. Check the banner and services before you rely on them.', 'ariconsent' ),
'import_failed' => __( 'The file could not be imported. Choose a settings file exported from AriConsent.', 'ariconsent' ),
);
if ( isset( $messages[ $notice ] ) ) {
$class = in_array( $notice, array( 'scan_failed', 'policy_failed', 'import_failed' ), true ) ? 'notice-error' : 'notice-success';
echo '
';
}
}
/**
* Link that creates the draft cookie policy page.
*
* @return string
*/
public static function create_policy_url() {
return wp_nonce_url( admin_url( 'admin-post.php?action=ariconsent_create_policy' ), 'ariconsent_create_policy' );
}
/**
* Creates the draft cookie policy page and opens it in the editor.
*/
public static function handle_create_policy() {
if ( ! current_user_can( Plugin::capability() ) || ! current_user_can( 'publish_pages' ) ) {
wp_die( esc_html__( 'You do not have permission to do this.', 'ariconsent' ), 403 );
}
check_admin_referer( 'ariconsent_create_policy' );
$id = \AriConsent\PolicyPage::create();
if ( is_wp_error( $id ) ) {
wp_safe_redirect( admin_url( 'admin.php?page=' . self::SLUG . '&ariconsent_notice=policy_failed' ) );
exit;
}
wp_safe_redirect( add_query_arg( 'ariconsent_notice', 'policy_created', get_edit_post_link( $id, 'raw' ) ) );
exit;
}
/**
* Reminds the owner, in the editor, to review the generated page before publishing.
*/
public static function policy_draft_notice() {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Display only.
if ( ! isset( $_GET['ariconsent_notice'] ) || 'policy_created' !== $_GET['ariconsent_notice'] ) {
return;
}
echo '
' . esc_html__( 'AriConsent created this cookie policy as a draft. Read it, adjust it to your website and publish it. The list of services updates itself.', 'ariconsent' ) . '
';
}
/**
* Bumps the policy revision so every visitor is asked again.
*/
public static function handle_reconsent() {
if ( ! current_user_can( Plugin::capability() ) ) {
wp_die( esc_html__( 'You do not have permission to do this.', 'ariconsent' ), 403 );
}
check_admin_referer( 'ariconsent_reconsent' );
$settings = Settings::get();
$settings['revision'] = (int) $settings['revision'] + 1;
Settings::update( $settings );
wp_safe_redirect( admin_url( 'admin.php?page=' . self::SLUG . '&ariconsent_notice=reconsent' ) );
exit;
}
/**
* Streams the consent log as CSV.
*/
public static function handle_export() {
if ( ! current_user_can( Plugin::capability() ) ) {
wp_die( esc_html__( 'You do not have permission to do this.', 'ariconsent' ), 403 );
}
check_admin_referer( 'ariconsent_export' );
nocache_headers();
header( 'Content-Type: text/csv; charset=utf-8' );
header( 'Content-Disposition: attachment; filename=ariconsent-log-' . gmdate( 'Y-m-d' ) . '.csv' );
$out = fopen( 'php://output', 'w' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen -- php://output stream.
if ( false === $out ) {
wp_die( esc_html__( 'The export could not be started.', 'ariconsent' ), 500 );
}
$page = 1;
$head = true;
do {
$batch = ConsentLog::query(
array(
'page' => $page,
'per_page' => 1000,
)
);
$rows = ConsentLog::csv_rows( $batch['items'] );
if ( ! $head ) {
array_shift( $rows );
}
foreach ( $rows as $row ) {
fputcsv( $out, $row, ',', '"', '\\' );
}
$head = false;
$count = count( $batch['items'] );
++$page;
} while ( 1000 === $count );
fclose( $out ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose -- php://output stream.
exit;
}
/**
* WCAG contrast ratio between two hex colours.
*
* @param string $a Colour.
* @param string $b Colour.
* @return float
*/
public static function contrast( $a, $b ) {
return \AriConsent\Banner::contrast( $a, $b );
}
/**
* A category cell in the consent log: "Yes", "No", or "Yes, except Hotjar" when the visitor
* turned single services off.
*
* @param array $item Log item.
* @param string $category Category slug.
* @return string
*/
public static function log_cell( array $item, $category ) {
if ( empty( $item['categories'][ $category ] ) ) {
return __( 'No', 'ariconsent' );
}
$active = Services::active();
$names = array();
foreach ( isset( $item['services_off'] ) ? (array) $item['services_off'] : array() as $id ) {
if ( isset( $active[ $id ] ) && $category === $active[ $id ]['category'] ) {
$names[] = $active[ $id ]['name'];
}
}
if ( ! $names ) {
return __( 'Yes', 'ariconsent' );
}
/* translators: %s: comma-separated service names the visitor turned off, e.g. "Hotjar, Microsoft Clarity". */
return sprintf( __( 'Yes, except %s', 'ariconsent' ), implode( ', ', $names ) );
}
}