*/ public static function screens() { global $submenu; static $cache = null; if ( null !== $cache && did_action( 'admin_menu' ) ) { return $cache; } $screens = array( 'overview' => array( 'label' => __( 'Overview', 'dealroot' ), 'page' => Admin::PAGE, 'capability' => Admin::capability(), 'order' => 10, ), 'live' => array( 'label' => __( 'Live', 'dealroot' ), 'page' => Live_Page::PAGE, 'capability' => Admin::capability(), 'order' => 16, 'live' => Live::count(), ), 'leads' => array( 'label' => __( 'Leads', 'dealroot' ), 'page' => Admin::LEADS_PAGE, 'capability' => Admin::capability(), 'order' => 12, 'count' => Leads::status_counts()['new'], ), 'ask' => array( 'label' => __( 'Ask', 'dealroot' ), 'page' => Ask_Page::PAGE, 'capability' => Admin::capability(), 'order' => 27, ), 'reports' => array( 'label' => __( 'Reports', 'dealroot' ), 'page' => Reports_Page::PAGE, 'capability' => Admin::capability(), 'order' => 14, ), 'forms' => array( 'label' => __( 'Forms', 'dealroot' ), 'page' => Forms_Page::PAGE, 'capability' => 'manage_options', 'order' => 30, ), 'settings' => array( 'label' => __( 'Settings', 'dealroot' ), 'page' => Admin::SETTINGS_PAGE, 'capability' => 'manage_options', 'order' => 90, ), ); /** * Filters the screens shown in the bar of the Dealroot screens. * * @param array $screens Key => label, page (menu slug), capability, order and an optional count. */ $screens = (array) apply_filters( 'dealroot_admin_screens', $screens ); // A screen that was taken out of the menu, e.g. for a white label, leaves the bar too. $menu = wp_list_pluck( (array) ( $submenu[ Admin::PAGE ] ?? array() ), 2 ); $screens = array_filter( $screens, static function ( $screen ) use ( $menu ) { return ! empty( $screen['label'] ) && ! empty( $screen['page'] ) && ( ! $menu || in_array( $screen['page'], $menu, true ) ) && current_user_can( $screen['capability'] ?? 'manage_options' ); } ); uasort( $screens, static function ( $a, $b ) { return ( $a['order'] ?? 50 ) <=> ( $b['order'] ?? 50 ); } ); if ( did_action( 'admin_menu' ) ) { $cache = $screens; } return $screens; } /** * Address of a screen. * * @param string $page Menu slug. * @param array $args Further query arguments. * @return string */ public static function url( $page, array $args = array() ) { return add_query_arg( array_merge( array( 'page' => $page ), $args ), admin_url( 'admin.php' ) ); } /** * Opens a screen: the wrapper, the bar and the head with title, description and actions. * * @param string $current Key of the screen in the bar. * @param string $title Title. * @param array $args { * Optional. * * @type string $description One or two sentences below the title. * @type string $actions Buttons next to the title, as HTML. * @type array $back Link above the title: url and label. * @type string $media HTML before the title, such as the initials of a person. * @type string $class Further classes of the wrapper. * } */ public static function open( $current, $title, array $args = array() ) { $args = wp_parse_args( $args, array( 'description' => '', 'actions' => '', 'back' => array(), 'media' => '', 'class' => '', ) ); ?>

'; } /** * The bar with the brand and the screens. * * @param string $current Key of the screen. */ public static function bar( $current ) { /** * Filters whether the Dealroot mark is shown in the bar, e.g. off for a white label. * * @param bool $show Show the mark. */ $mark = (bool) apply_filters( 'dealroot_brand_mark', true ); ?> $value ) { $html .= ' ' . esc_attr( $name ) . '="' . esc_attr( $value ) . '"'; } return sprintf( '%4$s', esc_attr( $classes ), esc_url( $url ), $html, esc_html( $label ) ); } /** * Dialog that asks for the amount when a lead is marked as won. */ public static function won_dialog() { ?>

%3$s', self::tone( $name ), esc_attr( $extra ), esc_html( self::initials( $name ) ) ); } /** * Initials of a name for the round badges. * * @param string $name Name or email address. * @return string */ public static function initials( $name ) { $name = trim( preg_replace( '/@.*$/', '', (string) $name ) ); $parts = array_values( array_filter( preg_split( '/[\s._-]+/u', $name ) ) ); if ( ! $parts ) { return '?'; } $first = mb_substr( $parts[0], 0, 1 ); $last = count( $parts ) > 1 ? mb_substr( end( $parts ), 0, 1 ) : ''; return mb_strtoupper( $first . $last ); } /** * Hue for the badge of a name, so the same person keeps the same colour. * * @param string $name Name. * @return int 0 to 5. */ public static function tone( $name ) { return abs( crc32( (string) $name ) ) % 6; } /** * Small square with the icon of a source's website, or its first letter. * * @param string $key Source, output of Sources::key(). * @param bool $lazy Leave a cached icon to the script, for rows that are not shown yet. * @return string HTML. */ public static function source_icon( $key, $lazy = false ) { $kind = Sources::kind( $key ); if ( 'direct' === $kind ) { return ''; } if ( 'none' === $kind ) { return ''; } $label = Sources::label( $key ); $host = Sources::domain( $key ); $letter = mb_strtoupper( mb_substr( (string) preg_replace( '/^[^\p{L}\p{N}]+/u', '', $label ), 0, 1 ) ); $icon = '' !== $host && Site_Icons::enabled() ? Site_Icons::cached( $host ) : null; // A cached icon goes in a data attribute and the script paints it: wp_kses() takes data // URIs out of style attributes, and the letter stays if the image cannot be shown. if ( is_string( $icon ) && '' !== $icon && ! $lazy ) { $data = ' data-dealroot-image="' . esc_attr( $icon ) . '"'; } elseif ( '' !== $host && '' !== $icon ) { $data = ' data-dealroot-icon="' . esc_attr( $host ) . '"'; } else { $data = ''; } return sprintf( '', self::tone( $label ), $data, esc_html( '' !== $letter ? $letter : '?' ) ); } }