' . esc_html__( 'Leads', 'aarye-marketing-addon' ) . '' ); return $links; } /** * Styles and scripts on our screens. * * @param string $hook Screen hook. */ public static function assets( $hook ) { if ( false === strpos( (string) $hook, self::SLUG ) ) { return; } wp_enqueue_style( 'aarye-admin', AARYE_URL . 'assets/css/admin.css', array(), aarye_asset_version( 'assets/css/admin.css' ) ); wp_enqueue_script( 'aarye-admin', AARYE_URL . 'assets/js/admin.js', array(), aarye_asset_version( 'assets/js/admin.js' ), true ); wp_localize_script( 'aarye-admin', 'aaryeAdmin', array( 'copied' => __( 'Copied', 'aarye-marketing-addon' ), 'ajax' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'aarye_import' ), /* translators: 1: entries handled, 2: total. */ 'progress' => __( 'Working… %1$s of %2$s', 'aarye-marketing-addon' ), /* translators: 1: imported, 2: already in Aarye. */ 'done' => __( 'Done: %1$s imported, %2$s were already in Aarye.', 'aarye-marketing-addon' ), 'error' => __( 'The import stopped:', 'aarye-marketing-addon' ), ) ); } /** * Address of one of our screens. * * @param string $sub Sub-page ('' for overview). * @param array $args Query args. * @return string */ public static function url( $sub = '', $args = array() ) { $url = admin_url( 'admin.php?page=' . self::SLUG . ( '' !== $sub ? '-' . $sub : '' ) ); return $args ? self::nav_url( add_query_arg( $args, $url ) ) : $url; } /** * A link to one of our screens with values (filters, an entry): carries a nonce, checked before * the values are used. * * @param string $url Link. * @return string */ public static function nav_url( $url ) { return add_query_arg( '_aarye_nav', wp_create_nonce( 'aarye_nav' ), $url ); } /** * The same nonce in a form sent with GET (filters, link tester). */ public static function nav_field() { echo ''; } /** * Message shown once on the next screen. * * @param string $text Message. * @param string $type success or error. */ public static function flash( $text, $type = 'success' ) { set_transient( 'aarye_flash_' . get_current_user_id(), array( 'text' => (string) $text, 'type' => 'error' === $type ? 'error' : 'success', ), MINUTE_IN_SECONDS * 5 ); } /** * Show the message saved with flash(). */ public static function show_flash() { $key = 'aarye_flash_' . get_current_user_id(); $flash = get_transient( $key ); if ( is_array( $flash ) && ! empty( $flash['text'] ) ) { delete_transient( $key ); echo '

' . esc_html( $flash['text'] ) . '

'; } } /** * Admin download link for a stored file. * * @param int $entry_id Entry ID. * @param int $index File index. * @return string */ public static function file_url( $entry_id, $index ) { return wp_nonce_url( add_query_arg( array( 'action' => 'aarye_file', 'entry' => (int) $entry_id, 'file' => (int) $index, ), admin_url( 'admin-post.php' ) ), 'aarye_file_' . (int) $entry_id ); } /** * Filters from the request. * * @return array */ private static function filters() { $ok = isset( $_GET['_aarye_nav'] ) && wp_verify_nonce( sanitize_key( wp_unslash( $_GET['_aarye_nav'] ) ), 'aarye_nav' ); $f = array(); foreach ( array( 'channel', 'source', 'campaign', 'form', 'lang', 'status', 'quality', 's', 'from', 'to', 'range' ) as $key ) { $f[ $key ] = $ok && isset( $_GET[ $key ] ) ? sanitize_text_field( wp_unslash( $_GET[ $key ] ) ) : ''; } $f['bots'] = $ok && ! empty( $_GET['bots'] ); if ( '' === $f['from'] && '' === $f['to'] ) { $days = in_array( $f['range'], array( '7', '30', '90', '365', 'all' ), true ) ? $f['range'] : '30'; $f['range'] = $days; if ( 'all' !== $days ) { $f['from'] = wp_date( 'Y-m-d', time() - ( (int) $days - 1 ) * DAY_IN_SECONDS ); } } return $f; } /** * Coloured source badge for an entry. * * @param object $e Entry. * @return string HTML. */ public static function badge( $e ) { $class = 'aarye-badge aarye-badge--' . sanitize_html_class( $e->channel ); $title = $e->source_label; if ( 'paid' === $e->channel ) { $title = '★ ' . $title; } $out = '' . esc_html( $title ) . ''; if ( ! $e->confirmed ) { $out .= ' ' . esc_html__( 'ad or post?', 'aarye-marketing-addon' ) . ''; } $bits = array_filter( array( $e->campaign, $e->ad_group, $e->ad ) ); if ( $bits ) { $out .= '' . esc_html( implode( ' › ', $bits ) ) . ''; } return $out; } /** * Source proof badge. * * @param array $proof From AARYE_Evidence::proof(). * @return string HTML. */ public static function proof_badge( $proof ) { return '' . esc_html( $proof['label'] ) . ''; } /** * Spam check badge. * * @param array $check From AARYE_Evidence::analyse(). * @param bool $reasons Show the main reasons under it. * @return string HTML. */ public static function spam_badge( $check, $reasons = false ) { $out = '' . esc_html( $check['label'] ) . ( $check['score'] ? ' · ' . (int) $check['score'] : '' ) . ''; if ( $reasons && $check['reasons'] ) { $out .= '' . esc_html( implode( ' · ', array_slice( $check['reasons'], 0, 2 ) ) ) . ''; } return $out; } /** * Filter bar. * * @param array $f Filters. * @param string $page Page slug. */ private static function filter_bar( $f, $page ) { $forms = AARYE_Integrations::all_forms(); ?>

'paid' ) ); $paid = AARYE_Entries::query( $paid_f, 1 ); $networks = AARYE_Entries::grouped( 'source', $paid_f, 12 ); foreach ( $networks as &$row ) { $nets = AARYE_Sources::ad_networks(); $row['label'] = isset( $nets[ $row['key'] ] ) ? $nets[ $row['key'] ]['name'] : $row['key']; } unset( $row ); $top_campaign = AARYE_Entries::grouped( 'campaign', $paid_f, 1 ); $share = $all['total'] ? round( 100 * $paid['total'] / $all['total'] ) : 0; ?>

'', 'not_channel' => 'paid', ) ), 12 ) ); self::bars( __( 'Lead capture', 'aarye-marketing-addon' ), AARYE_Entries::grouped( 'form_name', $f ) ); self::bars( __( 'Languages', 'aarye-marketing-addon' ), AARYE_Entries::grouped( 'language', $f ), 'lang' ); self::bars( __( 'Devices', 'aarye-marketing-addon' ), AARYE_Entries::grouped( 'device', $f ) ); /** * More cards on the overview. * * @param array $f Filters. */ do_action( 'aarye_overview_cards', $f ); ?>

'aarye_export' ), array_filter( $f ) ), admin_url( 'admin-post.php' ) ), 'aarye_export' ); $plugins = AARYE_Integrations::plugins(); ?>

created_at, get_option( 'date_format' ) . ' H:i' ) ); ?> name ? $e->name : ( '' !== $e->email ? $e->email : '#' . $e->id ) ); ?> email && '' !== $e->name ) : ?>
email ); ?> phone ) : ?>
phone ); ?>
is_bot ) : ?>
form_name ); ?>
form_plugin ] ) ? $plugins[ $e->form_plugin ]['name'] : $e->form_plugin ); ?>
language ) ); ?> status ] ) ? $statuses[ $e->status ] : $e->status ); ?>
1 ) { echo '
' . wp_kses_post( paginate_links( array( 'base' => self::nav_url( add_query_arg( 'paged', '%#%' ) ), 'format' => '', 'current' => $paged, 'total' => $pages, ) ) ) . '
'; } ?>

' . esc_html__( 'This entry no longer exists.', 'aarye-marketing-addon' ) . '

'; return; } $fields = AARYE_Entries::json( $e, 'fields' ); $files = AARYE_Entries::json( $e, 'files' ); $attr = AARYE_Entries::json( $e, 'attribution' ); $first = isset( $attr['first_source'] ) ? $attr['first_source'] : null; $plugins = AARYE_Integrations::plugins(); $days = $e->first_seen ? max( 0, (int) floor( ( strtotime( $e->created_at ) - strtotime( $e->first_seen ) ) / DAY_IN_SECONDS ) ) : null; $back = wp_get_referer() ? wp_get_referer() : self::url( 'entries' ); ?>

←

name ? $e->name : ( '' !== $e->email ? $e->email : '#' . $e->id ) ); ?>

    $file ) : ?>
  • (' . esc_html( $file['label'] ) . ')' : ''; ?>

form_name . ' · ' . ( isset( $plugins[ $e->form_plugin ] ) ? $plugins[ $e->form_plugin ]['name'] : $e->form_plugin ) . ' · ' . get_date_from_gmt( $e->created_at, get_option( 'date_format' ) . ' H:i' ) ); $link = AARYE_Integrations::entry_link( $e ); if ( $link ) { echo ' · ' . esc_html__( 'Open in the form plugin', 'aarye-marketing-addon' ) . ''; } ?>

$e->campaign, __( 'Ad set / ad group', 'aarye-marketing-addon' ) => $e->ad_group, __( 'Ad', 'aarye-marketing-addon' ) => $e->ad, __( 'Keyword', 'aarye-marketing-addon' ) => $e->keyword, __( 'Click ID', 'aarye-marketing-addon' ) => '' !== $e->click_id ? $e->click_param . ' = ' . $e->click_id : '', ); foreach ( $rows as $label => $value ) { if ( '' !== (string) $value ) { echo ''; } } ?> referrer ) : ?> source_label || $first['campaign'] !== $e->campaign ) ) : ?> ip ) : ?>
source_label . ' · ' . AARYE_Sources::channel_label( $e->channel ) ); ?>
' . esc_html( $label ) . '' . esc_html( $value ) . '
landing_page ); ?>
referrer ); ?>
page_url ); ?>
visits ); ?>
device ) . ( '' !== $e->browser ? ' · ' . $e->browser : '' ) ); ?>
language ) ); ?>
ip ); ?>
$v ) : ?>

source_label . ' · ' . AARYE_Sources::channel_label( $e->channel ) ); ?>


$value ) : ?>
id ); ?>
$id ) ) ); exit; } /** * Serve a stored attachment to an admin. */ public static function download_file() { $id = isset( $_GET['entry'] ) ? absint( $_GET['entry'] ) : 0; if ( ! current_user_can( self::cap() ) || ! check_admin_referer( 'aarye_file_' . $id ) ) { wp_die( esc_html__( 'Sorry, you are not allowed to do that.', 'aarye-marketing-addon' ) ); } $i = isset( $_GET['file'] ) ? absint( $_GET['file'] ) : 0; $entry = AARYE_Entries::get( $id ); $files = $entry ? AARYE_Entries::json( $entry, 'files' ) : array(); if ( empty( $files[ $i ]['stored'] ) ) { wp_die( esc_html__( 'File not found.', 'aarye-marketing-addon' ) ); } $base = realpath( AARYE_Entries::files_dir() ); $path = realpath( AARYE_Entries::files_dir() . $files[ $i ]['stored'] ); if ( ! $path || ! $base || 0 !== strpos( $path, $base ) || ! is_file( $path ) ) { wp_die( esc_html__( 'File not found.', 'aarye-marketing-addon' ) ); } $type = wp_check_filetype( $files[ $i ]['name'] ); nocache_headers(); header( 'Content-Type: ' . ( $type['type'] ? $type['type'] : 'application/octet-stream' ) ); header( 'Content-Disposition: attachment; filename="' . rawurlencode( $files[ $i ]['name'] ) . '"' ); header( 'Content-Length: ' . filesize( $path ) ); header( 'X-Content-Type-Options: nosniff' ); readfile( $path ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_readfile -- Streaming a private file to an admin. exit; } /** * CSV export of the filtered entries, one column per form field. */ public static function export() { if ( ! current_user_can( self::cap() ) || ! check_admin_referer( 'aarye_export' ) ) { wp_die( esc_html__( 'Sorry, you are not allowed to do that.', 'aarye-marketing-addon' ) ); } $result = AARYE_Entries::query( self::filters(), 10000 ); $rows = array(); $heads = array(); foreach ( $result['rows'] as $e ) { $row = AARYE_Sheets::row( $e ); foreach ( array_keys( $row ) as $h ) { $heads[ $h ] = true; } $rows[] = $row; } nocache_headers(); header( 'Content-Type: text/csv; charset=utf-8' ); header( 'Content-Disposition: attachment; filename="leads-' . gmdate( 'Y-m-d' ) . '.csv"' ); $out = fopen( 'php://output', 'w' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen -- Streaming CSV. fwrite( $out, "\xEF\xBB\xBF" ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fwrite -- UTF-8 BOM so Excel shows Arabic, Russian etc. correctly. fputcsv( $out, array_keys( $heads ) ); foreach ( $rows as $row ) { $line = array(); foreach ( array_keys( $heads ) as $h ) { $value = isset( $row[ $h ] ) ? (string) $row[ $h ] : ''; // Excel shows the guard apostrophe, so drop it for plain numbers such as +971 50 123 4567. if ( preg_match( '/^\'[+-][\d\s().-]+$/', $value ) ) { $value = substr( $value, 1 ); } $line[] = $value; } fputcsv( $out, $line ); } fclose( $out ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose exit; } /** * Import past entries. */ public static function page_import() { $sources = AARYE_Import::sources(); ?>

$src ) : ?>
' . esc_html( $src['note'] ) . '' : ''; ?> 0 ) : ?>
' . esc_html__( 'Not found on a page', 'aarye-marketing-addon' ) . ''; return; } $links = array(); foreach ( array_slice( $posts, 0, 3 ) as $post_id ) { $title = get_the_title( $post_id ); $url = 'publish' === get_post_status( $post_id ) && is_post_type_viewable( get_post_type( $post_id ) ) ? get_permalink( $post_id ) : get_edit_post_link( $post_id ); $links[] = $url ? '' . esc_html( '' !== $title ? $title : '#' . $post_id ) . '' : esc_html( $title ); } echo '' . esc_html__( 'On:', 'aarye-marketing-addon' ) . ' ' . wp_kses_post( implode( ', ', $links ) ); if ( count( $posts ) > 3 ) { /* translators: %d: number of other pages. */ echo ' ' . esc_html( sprintf( _n( 'and %d more', 'and %d more', count( $posts ) - 3, 'aarye-marketing-addon' ), count( $posts ) - 3 ) ) . ''; } } /** * Ad setup guide, with a link tester. */ public static function page_guide() { $ok = isset( $_GET['_aarye_nav'] ) && wp_verify_nonce( sanitize_key( wp_unslash( $_GET['_aarye_nav'] ) ), 'aarye_nav' ); $test = $ok && isset( $_GET['test_url'] ) ? esc_url_raw( wp_unslash( $_GET['test_url'] ) ) : ''; ?>

$params ) ); $fake = (object) array( 'channel' => $result['channel'], 'source_label' => $result['label'], 'confirmed' => $result['confirmed'], 'campaign' => $result['campaign'], 'ad_group' => $result['ad_group'], 'ad' => $result['ad'], ); echo '

' . wp_kses_post( self::badge( $fake ) ) . '

'; foreach ( array( __( 'Counted as an ad', 'aarye-marketing-addon' ) => 'paid' === $result['channel'] ? __( 'Yes', 'aarye-marketing-addon' ) : __( 'No', 'aarye-marketing-addon' ), __( 'Campaign', 'aarye-marketing-addon' ) => $result['campaign'], __( 'Ad set / ad group', 'aarye-marketing-addon' ) => $result['ad_group'], __( 'Ad', 'aarye-marketing-addon' ) => $result['ad'], __( 'Keyword', 'aarye-marketing-addon' ) => $result['keyword'], ) as $label => $value ) { echo ''; } echo '
' . esc_html( $label ) . '' . esc_html( '' !== $value ? $value : '—' ) . '
'; if ( 'direct' === $result['channel'] ) { echo '

' . esc_html__( 'This link has no tracking tags: leads from it look like direct visits. Add the URL parameters for your ad network below.', 'aarye-marketing-addon' ) . '

'; } echo '
'; } ?>
$p ) : ?>
>

get_results( $wpdb->prepare( 'SELECT form_plugin, form_id, COUNT(*) AS n, MAX(created_at) AS last FROM %i GROUP BY form_plugin, form_id', AARYE_Entries::table() ) ) as $row ) { $counts[ $row->form_plugin . ':' . $row->form_id ] = $row; } ?>

$plugin ) : ?>

$key . ':' . $form['id'], 'range' => 'all', ) ) ) . '">' . esc_html( sprintf( /* translators: %s: number. */ _n( '%s entry', '%s entries', (int) $c->n, 'aarye-marketing-addon' ), number_format_i18n( (int) $c->n ) ) ) . '' : '' . esc_html__( 'No entries yet', 'aarye-marketing-addon' ) . ''; ?> last, get_option( 'date_format' ) ) ) ) : ''; ?>
wp_generate_password( 32, false, false ) ) ); } ?>

  1. Extensions → Apps Script.', 'aarye-marketing-addon' ) ); ?>
  2. Deploy → New deployment, choose type Web app, set "Execute as" to Me and "Who has access" to Anyone, then Deploy and allow access.', 'aarye-marketing-addon' ) ); ?>

$url, 'sheets_tab_per_form' => ! empty( $_POST['sheets_tab_per_form'] ) ? 'yes' : 'no', ) ); if ( '' !== $url ) { $test = AARYE_Sheets::send( null ); if ( true === $test ) { self::flash( __( 'Connected: a test reached your spreadsheet. New entries will appear there as rows.', 'aarye-marketing-addon' ) ); } else { self::flash( (string) $test, 'error' ); } } else { self::flash( __( 'Settings saved.', 'aarye-marketing-addon' ) ); } wp_safe_redirect( self::url( 'sheets' ) ); exit; } /** * Settings. */ public static function page_settings() { $s = AARYE_Settings::all(); ?>

isset( $_POST['cookie_days'] ) ? min( 730, max( 1, absint( $_POST['cookie_days'] ) ) ) : 90 ); foreach ( array( 'wait_for_consent', 'store_ip', 'keep_files', 'skip_bots', 'delete_on_remove' ) as $key ) { $values[ $key ] = ! empty( $_POST[ $key ] ) ? 'yes' : 'no'; } /** * Settings from the settings screen, before saving. * * @param array $values Values. */ AARYE_Settings::update( (array) apply_filters( 'aarye_save_settings', $values ) ); self::flash( __( 'Settings saved.', 'aarye-marketing-addon' ) ); wp_safe_redirect( self::url( 'settings' ) ); exit; } }