array( 'datetime' => true, 'title' => true, ), 'span' => array( 'class' => true ), ); public static function cap() { /** * Capability required to use the CRM screens. */ return apply_filters( 'nodebook_capability', Nodebook_Team::CAP ); } public static function init() { add_action( 'admin_init', array( __CLASS__, 'guard' ), 1 ); add_action( 'admin_menu', array( __CLASS__, 'menu' ) ); add_action( 'in_admin_header', array( __CLASS__, 'quiet_notices' ), 1000 ); Nodebook_Admin_Welcome::init(); add_action( 'admin_init', array( 'Nodebook_Admin_Settings', 'register' ) ); add_action( 'admin_enqueue_scripts', array( __CLASS__, 'assets' ) ); add_filter( 'admin_body_class', array( __CLASS__, 'body_class' ) ); add_filter( 'plugin_action_links_' . plugin_basename( NODEBOOK_FILE ), array( __CLASS__, 'links' ) ); add_filter( 'set-screen-option', array( __CLASS__, 'screen_option' ), 10, 3 ); $posts = array( 'nodebook_save_contact' => array( 'Nodebook_Admin_Contact', 'save' ), 'nodebook_delete_contact' => array( 'Nodebook_Admin_Contact', 'delete' ), 'nodebook_add_note' => array( 'Nodebook_Admin_Contact', 'add_note' ), 'nodebook_delete_note' => array( 'Nodebook_Admin_Contact', 'delete_note' ), 'nodebook_contact_segs' => array( 'Nodebook_Admin_Contact', 'segments' ), 'nodebook_watch' => array( 'Nodebook_Admin_Contact', 'watch' ), 'nodebook_integration' => array( 'Nodebook_Admin_Integrations', 'save' ), 'nodebook_recipe' => array( 'Nodebook_Admin_Automations', 'save' ), 'nodebook_sync' => array( 'Nodebook_Admin_Sync', 'save' ), 'nodebook_sample' => array( 'Nodebook_Sample', 'handle' ), 'nodebook_inbound_key' => array( 'Nodebook_Admin_Settings', 'regenerate_key' ), 'nodebook_test_alert' => array( 'Nodebook_Admin_Settings', 'test_alert' ), 'nodebook_followed_up' => array( 'Nodebook_Admin_Contact', 'followed_up' ), 'nodebook_hide_setup' => array( 'Nodebook_Admin_Contact', 'hide_setup' ), 'nodebook_node_dismiss' => array( 'Nodebook_Node', 'dismiss_post' ), 'nodebook_setup_choice' => array( 'Nodebook_Setup', 'choice_post' ), 'nodebook_growth_mark' => array( 'Nodebook_Admin_Growth', 'mark_post' ), 'nodebook_app_forget' => array( 'Nodebook_Admin_Settings', 'app_forget' ), 'nodebook_owner' => array( 'Nodebook_Admin_Contact', 'owner' ), 'nodebook_status' => array( 'Nodebook_Admin_Board', 'set_status_post' ), 'nodebook_clear_reminder' => array( 'Nodebook_Admin_Contact', 'clear_reminder' ), 'nodebook_snooze' => array( 'Nodebook_Admin_Contact', 'snooze' ), 'nodebook_pin' => array( 'Nodebook_Admin_Contact', 'pin' ), 'nodebook_email_status' => array( 'Nodebook_Admin_Contact', 'email_status' ), 'nodebook_task' => array( 'Nodebook_Admin_Contact', 'task_action' ), 'nodebook_test_weekly' => array( 'Nodebook_Admin_Settings', 'test_weekly' ), 'nodebook_fields_save' => array( 'Nodebook_Admin_Fields', 'save' ), 'nodebook_field_add' => array( 'Nodebook_Admin_Fields', 'add' ), 'nodebook_field_presets' => array( 'Nodebook_Admin_Fields', 'presets' ), 'nodebook_field_promote' => array( 'Nodebook_Admin_Fields', 'promote' ), 'nodebook_segment_template' => array( 'Nodebook_Admin_Segments', 'from_template' ), 'nodebook_merge' => array( 'Nodebook_Admin_Duplicates', 'merge' ), 'nodebook_dismiss_dupe' => array( 'Nodebook_Admin_Duplicates', 'dismiss' ), 'nodebook_save_company' => array( 'Nodebook_Admin_Company', 'save' ), 'nodebook_delete_company' => array( 'Nodebook_Admin_Company', 'delete' ), 'nodebook_save_segment' => array( 'Nodebook_Admin_Segments', 'save' ), 'nodebook_delete_segment' => array( 'Nodebook_Admin_Segments', 'delete' ), 'nodebook_export' => array( 'Nodebook_Admin_Tools', 'export' ), 'nodebook_import_upload' => array( 'Nodebook_Admin_Tools', 'upload' ), 'nodebook_import_map' => array( 'Nodebook_Admin_Tools', 'map' ), 'nodebook_module' => array( 'Nodebook_Admin_Modules', 'toggle' ), 'nodebook_pipeline' => array( 'Nodebook_Admin_Pipelines', 'save' ), ); foreach ( $posts as $action => $cb ) { add_action( 'admin_post_' . $action, $cb ); } add_action( 'wp_ajax_nodebook_import_batch', array( 'Nodebook_Admin_Tools', 'ajax_batch' ) ); add_action( 'wp_ajax_nodebook_woo_backfill', array( 'Nodebook_Admin_Tools', 'ajax_backfill' ) ); add_action( 'wp_ajax_nodebook_app_code', array( 'Nodebook_Admin_Settings', 'app_code' ) ); add_action( 'wp_ajax_nodebook_growth_probe', array( 'Nodebook_Admin_Growth', 'probe_ajax' ) ); add_action( 'wp_ajax_nodebook_contact_list', array( 'Nodebook_Admin_Contact', 'list_ajax' ) ); add_action( 'wp_ajax_nodebook_send_email', array( 'Nodebook_Email', 'ajax' ) ); add_action( 'wp_ajax_nodebook_users_import', array( 'Nodebook_Admin_Tools', 'ajax_users' ) ); add_action( 'wp_ajax_nodebook_node_panel', array( 'Nodebook_Admin_Node', 'panel_ajax' ) ); add_action( 'wp_ajax_nodebook_node_later', array( 'Nodebook_Admin_Node', 'dismiss_ajax' ) ); add_action( 'admin_post_nodebook_pin_segment', array( 'Nodebook_Admin_Segments', 'pin' ) ); add_action( 'wp_ajax_nodebook_crm_import', array( 'Nodebook_Admin_Tools', 'ajax_crm_import' ) ); add_action( 'wp_ajax_nodebook_set_status', array( 'Nodebook_Admin_Board', 'set_status_ajax' ) ); Nodebook_Admin_Deals::init(); } public static function menu() { $cap = self::cap(); $due = current_user_can( $cap ) ? Nodebook_Admin_Today::badge() : 0; $badge = $due ? ' ' . number_format_i18n( $due ) . '' : ''; add_menu_page( self::brand_name(), esc_html( self::brand_name() ) . $badge, $cap, 'nodebook', array( 'Nodebook_Admin_Contact', 'page' ), 'dashicons-groups', 26 ); $contacts = add_submenu_page( 'nodebook', __( 'Contacts', 'nodebook' ), __( 'Contacts', 'nodebook' ), $cap, 'nodebook', array( 'Nodebook_Admin_Contact', 'page' ) ); add_submenu_page( 'nodebook', __( 'Today', 'nodebook' ), __( 'Today', 'nodebook' ) . $badge, $cap, 'nodebook-today', array( 'Nodebook_Admin_Today', 'page' ) ); // Deals switched off: the screens still open (links, bookmarks), they just leave the menu. add_submenu_page( Nodebook_Deals::on() ? 'nodebook' : 'options.php', __( 'Deals', 'nodebook' ), __( 'Deals', 'nodebook' ), $cap, 'nodebook-deals', array( 'Nodebook_Admin_Deals', 'page' ) ); add_submenu_page( 'nodebook', __( 'Board', 'nodebook' ), __( 'Board', 'nodebook' ), $cap, 'nodebook-board', array( 'Nodebook_Admin_Board', 'page' ) ); // The setup: no menu entry of its own. $welcome = add_submenu_page( 'options.php', __( 'Set up Nodebook', 'nodebook' ), __( 'Set up Nodebook', 'nodebook' ), 'manage_options', 'nodebook-welcome', array( 'Nodebook_Admin_Welcome', 'page' ) ); add_action( 'load-' . $welcome, static function () { // A focused screen: no notices from other plugins. remove_all_actions( 'admin_notices' ); remove_all_actions( 'all_admin_notices' ); } ); add_submenu_page( 'nodebook', __( 'Journeys', 'nodebook' ), __( 'Journeys', 'nodebook' ), $cap, 'nodebook-journeys', array( 'Nodebook_Admin_Journeys', 'page' ) ); add_submenu_page( 'nodebook', __( 'Growth', 'nodebook' ), __( 'Growth', 'nodebook' ), 'manage_options', 'nodebook-growth', array( 'Nodebook_Admin_Growth', 'page' ) ); $companies = add_submenu_page( 'nodebook', __( 'Companies', 'nodebook' ), __( 'Companies', 'nodebook' ), $cap, 'nodebook-companies', array( 'Nodebook_Admin_Company', 'page' ) ); $dupes = Nodebook_Team::restricted() ? 0 : (int) get_transient( 'nodebook_dupe_count' ); /* translators: %s: number badge */ $dupe_label = $dupes ? sprintf( __( 'Duplicates %s', 'nodebook' ), '' . number_format_i18n( $dupes ) . '' ) : __( 'Duplicates', 'nodebook' ); add_submenu_page( 'nodebook', __( 'Duplicates', 'nodebook' ), $dupe_label, $cap, 'nodebook-duplicates', array( 'Nodebook_Admin_Duplicates', 'page' ) ); add_submenu_page( 'nodebook', __( 'Segments', 'nodebook' ), __( 'Segments', 'nodebook' ), $cap, 'nodebook-segments', array( 'Nodebook_Admin_Segments', 'page' ) ); add_submenu_page( 'nodebook', __( 'Import & Export', 'nodebook' ), __( 'Import & Export', 'nodebook' ), $cap, 'nodebook-tools', array( 'Nodebook_Admin_Tools', 'page' ) ); add_submenu_page( 'nodebook', __( 'Integrations', 'nodebook' ), __( 'Integrations', 'nodebook' ), 'manage_options', 'nodebook-integrations', array( 'Nodebook_Admin_Integrations', 'page' ) ); add_submenu_page( 'nodebook', __( 'Automations', 'nodebook' ), __( 'Automations', 'nodebook' ), 'manage_options', 'nodebook-automations', array( 'Nodebook_Admin_Automations', 'page' ) ); if ( Nodebook_Deals::on() ) { add_submenu_page( 'nodebook', __( 'Pipelines', 'nodebook' ), __( 'Pipelines', 'nodebook' ), 'manage_options', Nodebook_Admin_Pipelines::PAGE, array( 'Nodebook_Admin_Pipelines', 'page' ) ); } add_submenu_page( 'nodebook', __( 'Fields', 'nodebook' ), __( 'Fields', 'nodebook' ), 'manage_options', 'nodebook-fields', array( 'Nodebook_Admin_Fields', 'page' ) ); add_submenu_page( 'nodebook', __( 'Modules', 'nodebook' ), __( 'Modules', 'nodebook' ), 'manage_options', 'nodebook-modules', array( 'Nodebook_Admin_Modules', 'page' ) ); add_submenu_page( 'nodebook', __( 'Settings', 'nodebook' ), __( 'Settings', 'nodebook' ), 'manage_options', 'nodebook-settings', array( 'Nodebook_Admin_Settings', 'page' ) ); foreach ( array( $contacts, $companies ) as $hook ) { add_action( 'load-' . $hook, array( __CLASS__, 'list_screen' ) ); } do_action( 'nodebook_admin_menu', $cap ); self::order_menu(); } /** * Sidebar order follows the app: Today, Contacts, Deals, Board, Journeys, then the rest of each part. * The first item is where "Nodebook" itself leads, so that is Today. Pages added by modules keep their place * after these. */ private static function order_menu() { global $submenu; if ( empty( $submenu['nodebook'] ) || ! is_array( $submenu['nodebook'] ) ) { return; } $order = array( 'nodebook-today', 'nodebook', 'nodebook-deals', 'nodebook-board', 'nodebook-gatherings', 'nodebook-journeys', 'nodebook-companies', 'nodebook-segments', 'nodebook-duplicates', 'nodebook-growth', 'nodebook-tools', 'nodebook-integrations', 'nodebook-automations', 'nodebook-pipelines', 'nodebook-fields', 'nodebook-modules', 'nodebook-settings' ); $rank = array_flip( $order ); $items = array_values( $submenu['nodebook'] ); $pos = array(); foreach ( $items as $i => $item ) { $pos[ $i ] = isset( $rank[ $item[2] ] ) ? $rank[ $item[2] ] : 100 + $i; } uksort( $items, static function ( $a, $b ) use ( $pos ) { return $pos[ $a ] <=> $pos[ $b ]; } ); $submenu['nodebook'] = array_values( $items ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- reordering our own submenu. } public static function list_screen() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- routing only. if ( empty( $_GET['action'] ) ) { add_screen_option( 'per_page', array( 'default' => 25, 'option' => 'nodebook_per_page', ) ); } // Fewer columns by default (people can switch them back on under Screen Options). add_filter( 'default_hidden_columns', static function ( $hidden ) { // Your own fields start hidden too: switch on the ones you want as columns. return array_merge( (array) $hidden, array( 'created', 'visits', 'email_status' ), array_keys( Nodebook_Props::defs( 'contact' ) ) ); } ); // Bulk actions are processed before output so we can redirect. $screen = get_current_screen(); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- routing only. if ( empty( $_GET['action'] ) ) { // Creating the table now registers its columns, so Screen Options can list them (switch columns on/off). if ( $screen && false !== strpos( $screen->id, 'nodebook-companies' ) ) { new Nodebook_List_Companies(); } else { new Nodebook_List_Contacts(); } } if ( $screen && false !== strpos( $screen->id, 'nodebook-companies' ) ) { Nodebook_List_Companies::process_bulk(); } else { Nodebook_List_Contacts::process_bulk(); } } public static function screen_option( $status, $option, $value ) { return 'nodebook_per_page' === $option ? max( 5, min( 500, absint( $value ) ) ) : $status; } public static function links( $links ) { array_unshift( $links, '' . esc_html__( 'Settings', 'nodebook' ) . '' ); return $links; } /** * Nodebook screens are an app of their own: other plugins' banners and nags stay on their own pages. * Nodebook's own messages are printed inside the screen (notices()), not through these hooks. */ public static function quiet_notices() { if ( ! self::is_screen() || ! apply_filters( 'nodebook_quiet_notices', true ) ) { return; } foreach ( array( 'admin_notices', 'all_admin_notices', 'network_admin_notices', 'user_admin_notices' ) as $hook ) { remove_all_actions( $hook ); } } public static function is_screen() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- routing only. $page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : ''; return 0 === strpos( $page, 'nodebook' ); } public static function assets( $hook = '' ) { if ( 'index.php' === $hook ) { wp_enqueue_style( 'nodebook-admin', nodebook_asset( 'css/admin.css' ), array(), NODEBOOK_VERSION ); return; } if ( ! self::is_screen() ) { return; } wp_enqueue_style( 'nodebook-admin', nodebook_asset( 'css/admin.css' ), array(), NODEBOOK_VERSION ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- screen detection only. if ( isset( $_GET['page'] ) && 'nodebook-settings' === $_GET['page'] ) { wp_enqueue_script( 'nodebook-qrcode', nodebook_asset( 'js/vendor/qrcode.js' ), array(), '2.0.4', true ); } wp_enqueue_script( 'nodebook-admin', nodebook_asset( 'js/admin.js' ), array(), NODEBOOK_VERSION, true ); wp_localize_script( 'nodebook-admin', 'nodebookAdmin', array( 'ajax' => admin_url( 'admin-ajax.php' ), 'beacon' => rest_url( 'nodebook/v1/hit' ), 'nonce' => wp_create_nonce( 'nodebook_ajax' ), 'ops' => Nodebook_Segments::operators(), 'fields' => array_map( static function ( $f ) { return array( $f[0], $f[1] ); }, Nodebook_Segments::rule_fields() ), 'options' => array( 'status' => Nodebook_Fields::statuses(), 'segment' => wp_list_pluck( Nodebook_Segments::all( 'static' ), 'name', 'id' ), 'activity' => Nodebook_Activities::types(), 'click' => wp_list_pluck( Nodebook_Tracker::click_kinds(), 0 ), 'emailstatus' => array( 'none' => __( 'Not asked', 'nodebook' ) ) + array_slice( Nodebook_Subscription::statuses(), 1, null, true ), 'event' => Nodebook_Events::labels(), 'deal' => self::deal_options(), 'owner' => array( 'me' => __( 'Me (whoever is viewing)', 'nodebook' ), '0' => __( 'Unassigned', 'nodebook' ), ) + Nodebook_Team::users(), ), 'templates' => Nodebook_Followup::templates(), 'team' => Nodebook_Team::is_team() ? array_values( array_map( static function ( $p ) { return array( $p[0], $p[1] ); }, Nodebook_Mentions::people() ) ) : array(), // Outcome → suggested next step and when. 'nextSteps' => array( 'no_answer' => array( __( 'Try again', 'nodebook' ), 'tomorrow' ), 'left_message' => array( __( 'Call again if no reply', 'nodebook' ), '3days' ), 'quote_sent' => array( __( 'Check they received the quote', 'nodebook' ), '3days' ), 'spoke' => array( '', '' ), ), 'i18n' => array( 'confirm' => __( 'Are you sure? This cannot be undone.', 'nodebook' ), 'done' => __( 'Done.', 'nodebook' ), 'error' => __( 'Something went wrong. Please try again.', 'nodebook' ), 'noMatch' => __( 'No matches', 'nodebook' ), /* translators: %1$s: number of search results */ 'results' => __( '%1$s results', 'nodebook' ), 'newCo' => __( 'New company: it is added when you save.', 'nodebook' ), 'newPerson' => __( 'New contact: added when you save.', 'nodebook' ), /* translators: 1: created, 2: updated, 3: skipped */ 'imported' => __( '%1$s created · %2$s updated · %3$s skipped', 'nodebook' ), 'remove' => __( 'Remove condition', 'nodebook' ), 'ok' => __( 'OK', 'nodebook' ), /* translators: %s: status */ 'moved' => __( 'Moved to %s', 'nodebook' ), 'undo' => __( 'Undo', 'nodebook' ), /* translators: %1$s: list name */ 'listOn' => __( 'Added to %1$s', 'nodebook' ), /* translators: %1$s: list name */ 'listOff' => __( 'Removed from %1$s', 'nodebook' ), 'problem' => __( 'Problem', 'nodebook' ), 'cancel' => __( 'Cancel', 'nodebook' ), 'send' => __( 'Send', 'nodebook' ), 'template' => __( 'Template', 'nodebook' ), 'noTemplate' => __( 'Suggested message', 'nodebook' ), 'subject' => __( 'Subject', 'nodebook' ), 'message' => __( 'Message', 'nodebook' ), /* translators: %1$s: contact name */ 'emailTo' => __( 'Email %1$s', 'nodebook' ), 'replyHint' => __( 'Sent from your site. Replies come to your own inbox, and it goes on their timeline.', 'nodebook' ), 'mailApp' => __( 'Open in my mail app instead', 'nodebook' ), 'waInstead' => __( 'Send on WhatsApp instead', 'nodebook' ), 'site' => wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), 'me' => wp_get_current_user()->first_name ? wp_get_current_user()->first_name : wp_get_current_user()->display_name, /* translators: 1: added, 2: updated, 3: notes, 4: events */ 'crmdone' => __( 'Done: %1$s added, %2$s updated, %3$s notes, %4$s events.', 'nodebook' ), ), ) ); } /* ------------------------------------------------------------------ * * Helpers shared by screens * ------------------------------------------------------------------ */ public static function url( $page, array $args = array() ) { // Links that switch a remembered view (board/list, pipeline) carry a nonce, so only they can change it. if ( isset( $args['layout'] ) || isset( $args['pipeline'] ) ) { $args['_nbview'] = wp_create_nonce( 'nodebook_view' ); } return add_query_arg( $args, admin_url( 'admin.php?page=' . $page ) ); } /** * A view choice from the address (board/list, pipeline): array( value, may it be remembered ). * The value only changes what is shown; it is saved as the person's preference only when the link * carries a valid nonce and the person may use Nodebook. * * @param string $key Query key. * @return array{0:string,1:bool} */ public static function view_choice( $key ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only view choice; the nonce is checked below before anything is saved. $value = isset( $_GET[ $key ] ) ? sanitize_key( wp_unslash( $_GET[ $key ] ) ) : ''; $nonce = isset( $_GET['_nbview'] ) ? sanitize_text_field( wp_unslash( $_GET['_nbview'] ) ) : ''; $save = '' !== $value && '' !== $nonce && wp_verify_nonce( $nonce, 'nodebook_view' ) && current_user_can( self::cap() ); return array( $value, (bool) $save ); } /** Stop unless the current user may use the CRM. Handlers verify their nonce right after. */ public static function require_cap() { if ( ! current_user_can( self::cap() ) ) { wp_die( esc_html__( 'You are not allowed to do this.', 'nodebook' ), 403 ); } } /** Nodebook screens get their own page background. */ public static function body_class( $classes ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- screen detection only. $page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : ''; if ( 0 !== strpos( $page, 'nodebook' ) ) { return $classes; } return $classes . ' nb-screen' . ( self::app_mode() ? ' nb-appmode' : '' ); } /** Stop unless the current user may see this contact (Settings → Team: own contacts only). */ public static function require_contact( $id ) { if ( $id && ! Nodebook_Team::can_see( (int) $id ) ) { wp_die( esc_html__( 'This contact belongs to someone else on your team.', 'nodebook' ), 403 ); } } private static function deny() { if ( wp_doing_ajax() ) { wp_send_json_error( null, 403 ); } wp_die( esc_html__( 'You are not allowed to do this.', 'nodebook' ), 403 ); } /** * One gate in front of every Nodebook form and AJAX action: the contact, task or deal it touches must be * visible to the user, deleting needs the delete right, exporting the export right, importing needs * access to all contacts (an import updates contacts by email address). Runs before the handlers. */ public static function guard() { // phpcs:disable WordPress.Security.NonceVerification -- authorization only; every handler verifies its own nonce. $action = isset( $_REQUEST['action'] ) ? sanitize_key( wp_unslash( $_REQUEST['action'] ) ) : ''; // Screens: refuse someone else's contact or deal before anything is printed. $page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : ''; if ( isset( $GLOBALS['pagenow'] ) && 'admin.php' === $GLOBALS['pagenow'] && in_array( $page, array( 'nodebook', 'nodebook-deals' ), true ) && in_array( $action, array( 'view', 'edit' ), true ) && Nodebook_Team::restricted() ) { $id = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : 0; if ( 'nodebook' === $page ) { self::require_contact( $id ); } else { $deal = Nodebook_Deals::get( $id ); if ( $deal && ! Nodebook_Deals::can_see( $deal ) ) { wp_die( esc_html__( 'This deal belongs to someone else on your team.', 'nodebook' ), 403 ); } } return; } if ( 0 !== strpos( $action, 'nodebook_' ) || ! ( wp_doing_ajax() || ( isset( $GLOBALS['pagenow'] ) && 'admin-post.php' === $GLOBALS['pagenow'] ) ) ) { return; } $num = static function ( $k ) { return isset( $_REQUEST[ $k ] ) && is_scalar( $_REQUEST[ $k ] ) ? absint( $_REQUEST[ $k ] ) : 0; }; $contact_actions = array( 'nodebook_save_contact', 'nodebook_delete_contact', 'nodebook_add_note', 'nodebook_delete_note', 'nodebook_contact_segs', 'nodebook_watch', 'nodebook_followed_up', 'nodebook_owner', 'nodebook_status', 'nodebook_clear_reminder', 'nodebook_snooze', 'nodebook_pin', 'nodebook_email_status', 'nodebook_set_status' ); $deal_actions = array( 'nodebook_deal_save', 'nodebook_deal_close', 'nodebook_deal_delete', 'nodebook_deal_move', 'nodebook_deal_stage' ); $delete_actions = array( 'nodebook_delete_contact', 'nodebook_merge', 'nodebook_delete_company', 'nodebook_deal_delete' ); $import_actions = array( 'nodebook_import_upload', 'nodebook_import_map', 'nodebook_import_batch', 'nodebook_crm_import', 'nodebook_woo_backfill', 'nodebook_users_import' ); if ( in_array( $action, $delete_actions, true ) && ! Nodebook_Team::can_delete() ) { self::deny(); } if ( 'nodebook_export' === $action && ! Nodebook_Team::can_export() ) { self::deny(); } if ( in_array( $action, $import_actions, true ) && Nodebook_Team::restricted() ) { self::deny(); } if ( ! Nodebook_Team::restricted() ) { return; } $ids = array(); if ( in_array( $action, $contact_actions, true ) ) { $ids[] = $num( 'id' ); } elseif ( 'nodebook_task' === $action ) { // The task's own contact and the contact sent with the request must both be visible. $task = Nodebook_Tasks::get( $num( 'task' ) ); $ids[] = $task ? (int) $task['contact_id'] : 0; $ids[] = $num( 'contact' ); if ( $task && ! $task['contact_id'] && (int) $task['assignee_id'] !== get_current_user_id() ) { self::deny(); } $deal = $num( 'deal' ) ? Nodebook_Deals::get( $num( 'deal' ) ) : null; if ( $deal && ! Nodebook_Deals::can_see( $deal ) ) { self::deny(); } } elseif ( 'nodebook_merge' === $action ) { $ids[] = $num( 'keep' ); $other = isset( $_REQUEST['other'] ) ? trim( sanitize_text_field( wp_unslash( $_REQUEST['other'] ) ) ) : ''; $found = ctype_digit( $other ) ? Nodebook_Contacts::get( (int) $other ) : ( is_email( $other ) ? Nodebook_Contacts::find_by_email( $other ) : null ); $ids[] = $found ? (int) $found['id'] : 0; } elseif ( 'nodebook_dismiss_dupe' === $action ) { $ids = array( $num( 'a' ), $num( 'b' ) ); } elseif ( in_array( $action, $deal_actions, true ) ) { $deal = Nodebook_Deals::get( $num( 'id' ) ); if ( $deal && ! Nodebook_Deals::can_see( $deal ) ) { self::deny(); } } // phpcs:enable WordPress.Security.NonceVerification foreach ( array_filter( $ids ) as $id ) { if ( ! Nodebook_Team::can_see( $id ) ) { self::deny(); } } } public static function redirect( $url, $notice = '' ) { if ( $notice ) { $url = add_query_arg( 'nb_notice', $notice, $url ); } wp_safe_redirect( $url ); exit; } public static function notices() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- display only. $code = isset( $_GET['nb_notice'] ) ? sanitize_key( wp_unslash( $_GET['nb_notice'] ) ) : ''; $map = array( 'saved' => array( 'success', __( 'Saved.', 'nodebook' ) ), 'syncon' => array( 'success', __( 'Connected. New subscribers and unsubscribes now go to your email tool. Send your existing subscribers with the button on the row.', 'nodebook' ) ), 'syncstart' => array( 'success', __( 'Sending your subscribers in the background. This can take a few minutes for a big list.', 'nodebook' ) ), 'syncfail' => array( 'error', __( 'Could not connect. See the message under Email tools.', 'nodebook' ) ), 'emailsent' => array( 'success', __( 'Email sent. It is on their timeline.', 'nodebook' ) ), 'sampleon' => array( 'success', __( 'Sample data added. Look around: Today, Contacts, Deals and Journeys are filled in. Remove it any time from the strip at the top.', 'nodebook' ) ), 'sampleoff' => array( 'success', __( 'Sample data removed. Your own data is untouched.', 'nodebook' ) ), 'newkey' => array( 'success', __( 'New webhook address made. The old one no longer works: update it where you use it.', 'nodebook' ) ), 'deleted' => array( 'success', __( 'Deleted.', 'nodebook' ) ), 'pipefail' => array( 'error', __( 'That did not work. Give the pipeline a name (at most 20 pipelines), and pick another pipeline for its deals.', 'nodebook' ) ), 'bulk' => array( 'success', __( 'Bulk action applied.', 'nodebook' ) ), 'note' => array( 'success', __( 'Note added.', 'nodebook' ) ), 'merged' => array( 'success', __( 'Contacts merged. The timeline, segments and old email address now belong to this contact.', 'nodebook' ) ), 'mergefail' => array( 'error', __( 'Those contacts could not be merged. Pick two different, existing contacts.', 'nodebook' ) ), 'duplicate' => array( 'error', __( 'Another contact already uses that email address.', 'nodebook' ) ), 'invalid' => array( 'error', __( 'Please enter a valid email address or phone number.', 'nodebook' ) ), 'upload' => array( 'error', __( 'The import file could not be read. Please upload a CSV file with a header row.', 'nodebook' ) ), 'expired' => array( 'error', __( 'This import has expired. Please upload the file again.', 'nodebook' ) ), 'followed' => array( 'success', __( 'Marked as followed up. They come back on the list when they show interest again.', 'nodebook' ) ), 'mailok' => array( 'success', __( 'Test alert sent. Check your inbox (and spam folder).', 'nodebook' ) ), 'mailfail' => array( 'error', __( 'WordPress could not send the email. Install an SMTP plugin so alerts reach you.', 'nodebook' ) ), 'snoozed' => array( 'success', __( 'Snoozed. They come back on the list on the day you picked.', 'nodebook' ) ), 'fieldadded' => array( 'success', __( 'Field added. Data your forms already sent under that name is moved into it.', 'nodebook' ) ), 'fieldfail' => array( 'error', __( 'That did not work: give the field a name that is not in use yet (at most 60 fields), or tick at least one form field.', 'nodebook' ) ), 'fieldmoved' => array( 'success', __( 'Done. The values now live in the field.', 'nodebook' ) ), 'fieldmoving' => array( 'success', __( 'Field made. Moving the values continues in the background.', 'nodebook' ) ), 'weeklyok' => array( 'success', __( 'Weekly summary sent. Check your inbox (and spam folder).', 'nodebook' ) ), 'template' => array( 'success', __( 'Segment created. It updates itself as contacts match.', 'nodebook' ) ), 'moduleon' => array( 'success', __( 'Module switched on.', 'nodebook' ) ), 'moduleoff' => array( 'success', __( 'Module switched off. Its data is kept.', 'nodebook' ) ), 'moduledata' => array( 'success', __( 'The module\'s data is deleted.', 'nodebook' ) ), 'dealadded' => array( 'success', __( 'Deal added. Plan the next step on the right.', 'nodebook' ) ), 'dealwon' => array( 'success', __( 'Won. Nicely done.', 'nodebook' ) ), 'teamnext' => array( 'success', __( 'Team it is. Add your teammates under Users with the role “Nodebook user”, then choose who gets new contacts under Settings → Team.', 'nodebook' ) ), 'dealcontact' => array( 'error', __( 'Pick a contact from the list, type a new email address, or leave it empty.', 'nodebook' ) ), ); /** * Notices shown after a redirect with ?nb_notice=code. Modules add their own here. * * @param array $map code => [ 'success'|'error'|'warning', message ]. */ $map = (array) apply_filters( 'nodebook_notices', $map ); if ( isset( $map[ $code ][1] ) ) { $node = 'success' === $map[ $code ][0] && Nodebook_Node::on(); echo '
' . ( $node ? Nodebook_Node::blob( 'happy', 24 ) : '' ) . '

' . esc_html( $map[ $code ][1] ) . '

'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- blob() escapes its own attributes. } } /** Tabs of the app header: page slug => [ label, badge count ]. */ private static function tabs() { $tabs = array( 'nodebook-today' => array( __( 'Today', 'nodebook' ), Nodebook_Admin_Today::badge() ), 'nodebook' => array( __( 'Contacts', 'nodebook' ), 0 ), 'nodebook-deals' => array( __( 'Deals', 'nodebook' ), 0 ), 'nodebook-board' => array( __( 'Board', 'nodebook' ), 0 ), 'nodebook-journeys' => array( __( 'Journeys', 'nodebook' ), 0 ), ); if ( ! Nodebook_Deals::on() ) { unset( $tabs['nodebook-deals'] ); } if ( current_user_can( 'manage_options' ) ) { $tabs['nodebook-automations'] = array( __( 'Automations', 'nodebook' ), 0 ); } return apply_filters( 'nodebook_tabs', $tabs ); } /** * Screens grouped under a main tab: page slug => main tab slug. Each group gets a row of sub-tabs. */ private static function groups() { return (array) apply_filters( 'nodebook_page_groups', array( 'nodebook-companies' => 'nodebook', 'nodebook-growth' => 'nodebook-journeys', 'nodebook-segments' => 'nodebook', 'nodebook-duplicates' => 'nodebook', 'nodebook-settings' => 'nodebook-settings', 'nodebook-integrations' => 'nodebook-settings', 'nodebook-pipelines' => 'nodebook-settings', 'nodebook-fields' => 'nodebook-settings', 'nodebook-modules' => 'nodebook-settings', 'nodebook-tools' => 'nodebook-settings', ) ); } /** * Sub-tabs of a group: key => [ label, url, active, badge ]. * * @param string $group Main tab slug. * @param string $page Current page. */ private static function subtabs( $group, $page ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- navigation only. $view = isset( $_GET['view'] ) ? sanitize_key( wp_unslash( $_GET['view'] ) ) : ''; $out = array(); if ( 'nodebook' === $group ) { $out['nodebook'] = array( __( 'All contacts', 'nodebook' ), self::url( 'nodebook' ), 'nodebook' === $page, 0 ); $out['nodebook-companies'] = array( __( 'Companies', 'nodebook' ), self::url( 'nodebook-companies' ), 'nodebook-companies' === $page, 0 ); $out['nodebook-segments'] = array( __( 'Segments', 'nodebook' ), self::url( 'nodebook-segments' ), 'nodebook-segments' === $page, 0 ); if ( Nodebook_Team::can_delete() ) { $dupes = Nodebook_Team::restricted() ? 0 : (int) get_transient( 'nodebook_dupe_count' ); $out['nodebook-duplicates'] = array( __( 'Duplicates', 'nodebook' ), self::url( 'nodebook-duplicates' ), 'nodebook-duplicates' === $page, $dupes ); } } elseif ( 'nodebook-deals' === $group ) { foreach ( array( '' => __( 'Open', 'nodebook' ), 'won' => __( 'Won', 'nodebook' ), 'lost' => __( 'Lost', 'nodebook' ), ) as $k => $label ) { $args = array_filter( array( 'view' => $k ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- view toggle only. if ( isset( $_GET['who'] ) && 'all' === sanitize_key( wp_unslash( $_GET['who'] ) ) ) { $args['who'] = 'all'; } // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- navigation only. $on = 'nodebook-deals' === $page && $view === $k && empty( $_GET['action'] ); $out[ 'deals-' . $k ] = array( $label, self::url( 'nodebook-deals', $args ), $on, 0 ); } } elseif ( 'nodebook-journeys' === $group && current_user_can( 'manage_options' ) && Nodebook_Growth::on() ) { $out['nodebook-journeys'] = array( __( 'Journeys', 'nodebook' ), self::url( 'nodebook-journeys' ), 'nodebook-journeys' === $page, 0 ); $out['nodebook-growth'] = array( __( 'Growth', 'nodebook' ), self::url( 'nodebook-growth' ), 'nodebook-growth' === $page, 0 ); } elseif ( 'nodebook-automations' === $group && current_user_can( 'manage_options' ) ) { $out['nodebook-automations'] = array( __( 'Ready-made', 'nodebook' ), self::url( 'nodebook-automations' ), 'nodebook-automations' === $page, 0 ); } elseif ( 'nodebook-settings' === $group ) { if ( current_user_can( 'manage_options' ) ) { $out['nodebook-settings'] = array( __( 'Settings', 'nodebook' ), self::url( 'nodebook-settings' ), 'nodebook-settings' === $page, 0 ); $out['nodebook-integrations'] = array( __( 'Integrations', 'nodebook' ), self::url( 'nodebook-integrations' ), 'nodebook-integrations' === $page, 0 ); if ( Nodebook_Deals::on() ) { $out['nodebook-pipelines'] = array( __( 'Pipelines', 'nodebook' ), self::url( 'nodebook-pipelines' ), 'nodebook-pipelines' === $page, 0 ); } $out['nodebook-fields'] = array( __( 'Fields', 'nodebook' ), self::url( 'nodebook-fields' ), 'nodebook-fields' === $page, 0 ); $out['nodebook-modules'] = array( __( 'Modules', 'nodebook' ), self::url( 'nodebook-modules' ), 'nodebook-modules' === $page, 0 ); } $out['nodebook-tools'] = array( __( 'Import & Export', 'nodebook' ), self::url( 'nodebook-tools' ), 'nodebook-tools' === $page, 0 ); } return (array) apply_filters( 'nodebook_subtabs', $out, $group, $page ); } /** * Look of a sidebar entry: page slug => [ icon, tile colour ]. Unknown entries (added through the * nodebook_tabs filter) get a grey dot. */ private static function side_look( $slug ) { $looks = (array) apply_filters( 'nodebook_side_looks', array( 'nodebook-today' => array( 'sun', '#FF9500' ), 'nodebook' => array( 'user', '#0071E3' ), 'nodebook-deals' => array( 'chart', '#34C759' ), 'nodebook-board' => array( 'columns', '#5856D6' ), 'nodebook-gatherings' => array( 'calendar', '#FF2D55' ), 'nodebook-journeys' => array( 'route', '#30B0C7' ), 'nodebook-automations' => array( 'zap', '#FF2D55' ), 'nodebook-companies' => array( 'building', '#8E8E93' ), 'nodebook-segments' => array( 'filter', '#AF52DE' ), 'nodebook-settings' => array( 'sliders', '#636366' ), 'nodebook-tools' => array( 'sliders', '#636366' ), ) ); return $looks[ $slug ] ?? array( 'more', '#8E8E93' ); } /** One sidebar entry: a coloured tile with a white icon, the label and an optional count. */ private static function side_link( $slug, $label, $on, $count = 0, $class = 'nb-tab', $alert = false ) { $look = self::side_look( $slug ); echo '' . wp_kses( Nodebook_Icons::svg( $look[0], 16 ), Nodebook_Icons::kses() ) . '' . esc_html( $label ) . '' . ( $count ? ' ' . esc_html( number_format_i18n( $count ) ) . '' : '' ) . ''; } /** Whether Nodebook takes over the whole screen (no WordPress menu and toolbar on its screens). */ /** The product name people see ("Nodebook", or a white-label name). */ public static function brand_name() { $name = trim( wp_strip_all_tags( (string) apply_filters( 'nodebook_brand_name', 'Nodebook' ) ) ); return '' !== $name ? mb_substr( $name, 0, 40 ) : 'Nodebook'; } public static function app_mode() { $on = Nodebook_Settings::get( 'full_screen' ); return (bool) apply_filters( 'nodebook_app_mode', false !== $on && '0' !== (string) $on ); } /** * The Nodebook app frame: a sidebar (brand, search, sections, settings, back to WordPress), a top bar and a * tab bar for phones, then the sub-tabs of this part as a segmented control. */ public static function shell() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- navigation only. $page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : 'nodebook'; $groups = self::groups(); $group = $groups[ $page ] ?? $page; $set = current_user_can( 'manage_options' ) ? 'nodebook-settings' : 'nodebook-tools'; $tabs = self::tabs(); $search = ''; /** * A short label after the name in the sidebar, set by an add-on. * * @param string $badge Empty by default. */ $badge = trim( (string) apply_filters( 'nodebook_brand_badge', '' ) ); $name = self::brand_name(); /** * The square mark before the name in the sidebar: a letter, or an image URL (white label). * * @param string $mark Default "N". */ $mark = (string) apply_filters( 'nodebook_brand_mark', 'N' ); $mark = 0 === strpos( $mark, 'http' ) ? '' : ''; $brand = '' . $mark . '' . esc_html( $name ) . '' . ( '' !== $badge ? '' . esc_html( mb_substr( $badge, 0, 12 ) ) . '' : '' ) . ''; echo ''; // Phones: a top bar with the brand and search, and a tab bar at the bottom. echo '
' . $brand . str_replace( 'nb-global-search', 'nb-top-search', $search ) . '
'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- built from escaped parts above. echo ''; } /** The parts of this section (Open / Won / Lost, Settings / Fields / …) as a segmented control. */ private static function subnav() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- navigation only. $page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : 'nodebook'; $groups = self::groups(); $group = $groups[ $page ] ?? $page; $subs = self::subtabs( $group, $page ); // One part alone needs no switch. if ( count( $subs ) > 1 ) { echo ''; } } /** * Board or list for a screen with columns (Board, Deals). A choice in the URL is remembered per person. * * @param string $screen 'board' or 'deals'. */ public static function layout( $screen ) { $ok = array( 'board', 'list' ); $uid = get_current_user_id(); list( $get, $save ) = self::view_choice( 'layout' ); if ( in_array( $get, $ok, true ) ) { if ( $uid && $save ) { update_user_meta( $uid, 'nodebook_layout_' . $screen, $get ); } return $get; } $saved = $uid ? (string) get_user_meta( $uid, 'nodebook_layout_' . $screen, true ) : ''; return in_array( $saved, $ok, true ) ? $saved : 'board'; } /** * The Board | List switch. * * @param string $page Page slug. * @param string $current 'board' or 'list'. * @param array $keep Query args to keep (filters). */ public static function layout_switch( $page, $current, array $keep = array() ) { echo ''; } /** * A round avatar with initials, in a colour that stays the same for the same person. * * @param string $name Display name (or email). * @param string $seed What the colour follows (email or id); the name when empty. * @param string $size '', 'sm', 'lg' or 'xl'. */ public static function avatar( $name, $seed = '', $size = '' ) { $name = trim( (string) $name ); $words = preg_split( '/[\s@._-]+/u', $name, -1, PREG_SPLIT_NO_EMPTY ); $init = ''; if ( $words ) { $init = mb_substr( $words[0], 0, 1 ); if ( count( $words ) > 1 && false === strpos( $name, '@' ) ) { $init .= mb_substr( end( $words ), 0, 1 ); } } $init = '' === $init ? '?' : mb_strtoupper( $init ); $tone = absint( crc32( strtolower( '' !== (string) $seed ? (string) $seed : $name ) ) ) % 8; return ''; } /** * Start a Nodebook screen: app frame, then the page title with its buttons. * * @param string $title Page title. * @param array $actions label => URL. The first is the main button; a label starting with "←" is a * back link shown above the title. * @param array $args count (shown next to the title), sub (a line under it), hide_title (for screens whose * first card already names the record). */ public static function header( $title, array $actions = array(), array $args = array() ) { echo '
'; self::shell(); echo '
'; $back = array(); $buttons = array(); foreach ( $actions as $label => $url ) { if ( 0 === strpos( (string) $label, '←' ) ) { $back = array( trim( substr( (string) $label, strlen( '←' ) ) ), $url ); } else { $buttons[ $label ] = $url; } } $bare = ! empty( $args['hide_title'] ); $link = $back ? '' . wp_kses( Nodebook_Icons::svg( 'chevron-l', 18 ), Nodebook_Icons::kses() ) . esc_html( $back[0] ) . '' : ''; if ( ! $bare ) { echo $link; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped above. } echo '
'; if ( $bare ) { echo $link; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped above. } echo '

' . esc_html( $title ) . ( isset( $args['count'] ) ? ' ' . esc_html( number_format_i18n( (int) $args['count'] ) ) . '' : '' ) . '

'; if ( ! empty( $args['sub'] ) ) { echo '

' . esc_html( $args['sub'] ) . '

'; } echo '
'; if ( $buttons ) { echo '
'; $i = 0; foreach ( array_reverse( $buttons, true ) as $label => $url ) { $main = ( count( $buttons ) - 1 ) === $i++; $icon = ''; if ( false !== strpos( $url, 'action=new' ) || false !== strpos( $url, 'new=1' ) || ( false !== strpos( $url, 'action=edit' ) && false === strpos( $url, 'id=' ) ) ) { $icon = 'plus'; } elseif ( false !== strpos( $url, 'page=nodebook-tools' ) ) { $icon = 'upload'; } echo '' . ( $icon ? wp_kses( Nodebook_Icons::svg( $icon, 16 ), Nodebook_Icons::kses() ) : '' ) . esc_html( $label ) . ''; } echo '
'; } echo '
'; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- navigation only. $form = ! empty( $_GET['action'] ) || ! empty( $_GET['new'] ) || ! empty( $_GET['edit'] ); if ( ! $back && ! $form ) { self::subnav(); } echo '
'; self::notices(); Nodebook_Sample::banner(); Nodebook_Admin_Node::bubble(); } public static function footer() { echo '
'; } /** Relative "x ago" for a GMT datetime, with the exact local time as a tooltip. */ public static function ago( $gmt ) { if ( ! $gmt ) { return '—'; } $ts = strtotime( $gmt . ' UTC' ); /* translators: %s: human time difference */ $rel = sprintf( __( '%s ago', 'nodebook' ), human_time_diff( $ts, time() ) ); return ''; } /** "PA" → "Panamá" (WooCommerce's translated list when available). */ public static function country_name( $code ) { $code = strtoupper( trim( (string) $code ) ); if ( 2 === strlen( $code ) && function_exists( 'WC' ) && WC()->countries ) { $all = WC()->countries->get_countries(); if ( isset( $all[ $code ] ) ) { return html_entity_decode( $all[ $code ], ENT_QUOTES, 'UTF-8' ); } } return (string) $code; } /** "PANPP" / "PA-8" → "Panamá" province name when WooCommerce knows the code. */ public static function state_name( $country, $state ) { $state = trim( (string) $state ); if ( '' !== $state && function_exists( 'WC' ) && WC()->countries ) { $states = WC()->countries->get_states( strtoupper( (string) $country ) ); if ( is_array( $states ) && isset( $states[ $state ] ) ) { return html_entity_decode( $states[ $state ], ENT_QUOTES, 'UTF-8' ); } } return $state; } /** One readable address line, without repeats ("Costa del Este, Costa del Este"). */ public static function address_line( array $c ) { $parts = array(); foreach ( array( Nodebook_Fields::name_case( (string) ( $c['address'] ?? '' ) ), $c['postcode'] ?? '', Nodebook_Fields::name_case( (string) ( $c['city'] ?? '' ) ), self::state_name( $c['country'] ?? '', $c['state'] ?? '' ), self::country_name( $c['country'] ?? '' ) ) as $p ) { $p = trim( (string) $p ); if ( '' === $p ) { continue; } $lp = mb_strtolower( $p, 'UTF-8' ); $skip = false; // Whole words only: "PA" is not inside "PANPP". $within = static function ( $needle, $hay ) { return (bool) preg_match( '/(^|[\s,\-\/])' . preg_quote( $needle, '/' ) . '($|[\s,\-\/])/u', $hay ); }; foreach ( $parts as $i => $e ) { $le = mb_strtolower( $e, 'UTF-8' ); if ( $within( $lp, $le ) ) { $skip = true; // Already said ("Costa del Este" inside "Panamá - Costa del Este"). break; } if ( $within( $le, $lp ) ) { $parts[ $i ] = $p; // The new part says more; keep it instead. $skip = true; break; } } if ( ! $skip ) { $parts[] = $p; } } return implode( ', ', $parts ); } /** Small inline icon for an activity type (dashicons, already loaded in wp-admin). */ public static function icon( $type ) { $map = apply_filters( 'nodebook_activity_icons', array( 'visit' => 'visibility', 'pageview' => 'media-default', 'form' => 'feedback', 'order' => 'cart', 'refund' => 'undo', 'note' => 'edit', 'signup' => 'admin-users', 'created' => 'plus-alt2', 'import' => 'upload', 'segment' => 'tag', 'status' => 'flag', 'merge' => 'randomize', 'booking' => 'calendar-alt', 'appointment' => 'calendar-alt', 'click' => 'phone', 'followup' => 'yes-alt', 'touch' => 'format-chat', 'touch-call' => 'phone', 'touch-email' => 'email-alt', 'touch-whatsapp' => 'format-chat', 'touch-meeting' => 'groups', 'subscription' => 'email', 'auto' => 'controls-repeat', 'email_out' => 'email-alt2', 'review' => 'star-filled', 'event' => 'chart-line', 'task' => 'yes', 'deal' => 'money-alt', 'gathering' => 'groups', ) ); return ''; } /** Values for the "Deal" segment rule. */ private static function deal_options() { $out = array( 'open' => __( 'open deal', 'nodebook' ), 'won' => __( 'won deal', 'nodebook' ), 'lost' => __( 'lost deal', 'nodebook' ), 'any' => __( 'deal at all', 'nodebook' ), ); $pipes = Nodebook_Deals::pipelines(); foreach ( $pipes as $p ) { foreach ( (array) $p['stages'] as $k => $label ) { $label = count( $pipes ) > 1 ? $p['name'] . ' · ' . $label : $label; /* translators: %s: deal stage */ $out[ 'stage:' . $k ] = $out[ 'stage:' . $k ] ?? sprintf( __( 'open deal in “%s”', 'nodebook' ), $label ); } } return $out; } public static function money( $amount, $currency = '' ) { if ( function_exists( 'wc_price' ) ) { return html_entity_decode( wp_strip_all_tags( wc_price( (float) $amount, $currency ? array( 'currency' => $currency ) : array() ) ), ENT_QUOTES, 'UTF-8' ); } $currency = $currency ? $currency : Nodebook_Conversions::currency(); return trim( ( $currency ? $currency . ' ' : '' ) . number_format_i18n( (float) $amount, 2 ) ); } /** * Render one input for a field definition. */ public static function field( $name, $key, array $def, $value ) { $id = 'nb-' . $key; echo '
'; switch ( $def['type'] ) { case 'textarea': echo ''; break; case 'checkbox': echo ''; break; case 'number': case 'money': if ( ! empty( $def['custom'] ) ) { echo ''; break; } echo ''; break; case 'date': if ( ! empty( $def['custom'] ) ) { echo ''; break; } echo ''; break; case 'select': echo ''; break; default: $type = in_array( $def['type'], array( 'email', 'tel', 'url' ), true ) ? $def['type'] : 'text'; echo ''; } echo '
'; } }