and the other actions below) and adds its menu items; when it is not * installed those spots are simply empty, and one card at the foot of Settings says what Pro adds. */ class Admin { const ICON = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgc3Ryb2tlPSIjYTdhYWFkIiBzdHJva2Utd2lkdGg9IjIuNCIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIj48cGF0aCBkPSJNNCA1aDE2djExSDlsLTUgNHoiLz48L3N2Zz4='; public static function init() { add_action( 'admin_menu', array( __CLASS__, 'menu' ) ); add_action( 'admin_enqueue_scripts', array( __CLASS__, 'assets' ) ); add_action( 'admin_post_chatdozo_save_settings', array( __CLASS__, 'save_settings' ) ); add_action( 'admin_post_chatdozo_unban', array( __CLASS__, 'unban' ) ); add_action( 'admin_post_chatdozo_pro_seen', array( __CLASS__, 'pro_seen' ) ); add_action( 'show_user_profile', array( __CLASS__, 'profile_field' ) ); add_action( 'edit_user_profile', array( __CLASS__, 'profile_field' ) ); add_action( 'personal_options_update', array( __CLASS__, 'profile_save' ) ); add_action( 'edit_user_profile_update', array( __CLASS__, 'profile_save' ) ); add_filter( 'plugin_action_links_' . plugin_basename( CHATDOZO_FILE ), array( __CLASS__, 'links' ) ); } public static function links( $links ) { array_unshift( $links, '' . esc_html__( 'Inbox', 'chatdozo' ) . '', '' . esc_html__( 'Settings', 'chatdozo' ) . '' ); return $links; } /** The states as a word and a colour: the side-menu badge, and the admin bar repaints the badge from these. */ public static function state_tags() { return (array) apply_filters( 'chatdozo_state_tags', array( 'live' => array( __( 'Live', 'chatdozo' ), '#1E9E63' ), 'away' => array( __( 'Away', 'chatdozo' ), '#8A8F99' ) ) ); } /** The menu: Chatdozo sits just under Comments, where the other inboxes of a site live. */ public static function menu() { $op = Roles::can(); $cap = $op ? Roles::CAP : 'manage_options'; $counts = $op ? Store::counts() : array( 'needs' => 0 ); $bubble = $counts['needs'] ? ' ' : ''; $sit = Store::situation(); $tag = self::state_tags(); $t = isset( $tag[ $sit['kind'] ] ) ? $tag[ $sit['kind'] ] : $tag['away']; $state = ' '; add_menu_page( 'Chatdozo', 'Chatdozo' . $state . $bubble, $cap, 'chatdozo', array( __CLASS__, 'inbox' ), self::ICON, 26 ); add_submenu_page( 'chatdozo', __( 'Inbox / Notifications', 'chatdozo' ), __( 'Inbox / Notifications', 'chatdozo' ) . $bubble, $cap, 'chatdozo', array( __CLASS__, 'inbox' ) ); do_action( 'chatdozo_admin_menu', $cap ); // the Pro edition adds Reports here add_submenu_page( 'chatdozo', __( 'Settings', 'chatdozo' ), __( 'Settings', 'chatdozo' ), 'manage_options', 'chatdozo-settings', array( __CLASS__, 'settings' ) ); } public static function assets( $hook ) { $profile = in_array( $hook, array( 'profile.php', 'user-edit.php' ), true ); if ( strpos( (string) $hook, 'chatdozo' ) === false && ! $profile ) { return; } wp_enqueue_style( 'chatdozo-admin', CHATDOZO_URL . 'assets/admin.css', array(), CHATDOZO_VERSION ); // Manrope is bundled in there if ( strpos( (string) $hook, 'chatdozo-settings' ) !== false || $profile ) { wp_enqueue_media(); wp_enqueue_script( 'chatdozo-studio', CHATDOZO_URL . 'assets/studio.js', array(), CHATDOZO_VERSION, true ); $data = array( 'api' => esc_url_raw( rest_url( 'chatdozo/v1/op/' ) ), 'nonce' => wp_create_nonce( 'wp_rest' ), 'faces' => array_values( Util::faces() ), 'blank' => Util::blank_face(), 'colour' => (string) Options::get( 'colour' ), 'canAi' => current_user_can( 'manage_options' ) ? 1 : 0, 'i18n' => array( 'title' => __( 'Choose a face', 'chatdozo' ), 'faces' => __( 'Faces', 'chatdozo' ), 'upload' => __( 'Upload', 'chatdozo' ), 'uploadBtn' => __( 'Choose from the Media library', 'chatdozo' ), 'uploadTip' => __( 'A square photo works best. It is cropped to a circle.', 'chatdozo' ), 'none' => __( 'No picture (show the logo)', 'chatdozo' ), 'change' => __( 'Change face', 'chatdozo' ), 'remove' => __( 'Remove', 'chatdozo' ), 'close' => __( 'Close', 'chatdozo' ), 'failed' => __( 'That did not work. Try again.', 'chatdozo' ), 'saved' => __( 'Saved.', 'chatdozo' ), 'onDuty' => __( 'on duty', 'chatdozo' ), 'offDuty' => __( 'off duty', 'chatdozo' ), 'inboxOpen' => __( 'in WordPress now', 'chatdozo' ), 'inboxClosed' => __( 'not in WordPress', 'chatdozo' ), 'phonePings' => __( 'phone pings', 'chatdozo' ), 'findNone' => __( 'Nobody found.', 'chatdozo' ), 'findAllIn' => __( 'Everyone here already answers.', 'chatdozo' ), 'findMore' => __( '+ shown. Search by name to narrow it down.', 'chatdozo' ), 'findTick' => __( '. Tick the ones who should answer.', 'chatdozo' ), 'addedSave' => __( 'Added. Save settings at the bottom.', 'chatdozo' ), 'copied' => __( 'Copied.', 'chatdozo' ), 'shortName' => __( 'Short name', 'chatdozo' ), 'theReply' => __( 'The reply', 'chatdozo' ), ), ); Util::script_data( 'chatdozo-studio', 'CHATDOZO_STUDIO', apply_filters( 'chatdozo_studio_data', $data ) ); if ( strpos( (string) $hook, 'chatdozo-settings' ) !== false ) { wp_enqueue_script( 'chatdozo-settings', CHATDOZO_URL . 'assets/settings.js', array( 'chatdozo-studio' ), CHATDOZO_VERSION, true ); do_action( 'chatdozo_settings_assets' ); } } if ( $hook === 'toplevel_page_chatdozo' && Roles::can() ) { do_action( 'chatdozo_inbox_assets' ); // the Pro edition's globe, registered first so the inbox can depend on it wp_enqueue_script( 'chatdozo-inbox', CHATDOZO_URL . 'assets/inbox.js', (array) apply_filters( 'chatdozo_inbox_deps', array() ), CHATDOZO_VERSION, true ); Util::script_data( 'chatdozo-inbox', 'CHATDOZO_INBOX', self::inbox_data() ); } } /** Everything inbox.js needs, shared by the wp-admin inbox and (Pro) the phone app and the Hub. */ public static function inbox_data() { $me = wp_get_current_user(); $data = array( 'api' => esc_url_raw( rest_url( 'chatdozo/v1/op/' ) ), 'nonce' => wp_create_nonce( 'wp_rest' ), 'admin' => current_user_can( 'manage_options' ) ? 1 : 0, 'me' => array( 'id' => $me->ID, 'name' => Util::op_name( $me->ID ) ), 'business' => Options::get( 'business' ), 'logo' => (string) Options::get( 'logo_url' ), 'sound' => (int) Options::get( 'sound' ), 'files' => (int) Options::get( 'files' ), 'wall' => Util::wallpaper( Options::get( 'inbox_bg' ), Options::get( 'inbox_bg_url' ) ), 'wallCustom' => Options::get( 'inbox_bg' ) === 'custom' ? 1 : 0, 'version' => CHATDOZO_VERSION, 'open' => isset( $_GET['c'] ) ? absint( $_GET['c'] ) : 0, // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- a link into the inbox (admin.php?page=chatdozo&c=12); it only chooses which chat opens first 'i18n' => array( 'needs' => __( 'Needs you', 'chatdozo' ), 'mine' => __( 'Mine', 'chatdozo' ), 'open' => __( 'Open', 'chatdozo' ), 'closed' => __( 'Closed', 'chatdozo' ), 'visitor' => __( 'Visitor', 'chatdozo' ), 'you' => __( 'You', 'chatdozo' ), 'empty' => __( 'Nothing here. When a visitor writes, it appears at the top.', 'chatdozo' ), 'pick' => __( 'Pick a conversation on the left.', 'chatdozo' ), /* translators: %s: the visitor's name */ 'reply' => __( 'Reply to %s', 'chatdozo' ), 'send' => __( 'Send', 'chatdozo' ), 'close' => __( 'Done', 'chatdozo' ), 'reopen' => __( 'Reopen', 'chatdozo' ), 'here' => __( 'On the site now', 'chatdozo' ), 'gone' => __( 'Left the site', 'chatdozo' ), 'typing' => __( 'typing…', 'chatdozo' ), 'seen' => __( 'Seen', 'chatdozo' ), 'emailed' => __( 'also sent by email', 'chatdozo' ), 'noemail' => __( 'No email given', 'chatdozo' ), 'willmail' => __( 'Left the site: your reply goes to their email too.', 'chatdozo' ), 'cantmail' => __( 'Left the site and gave no email: they will see your reply if they come back.', 'chatdozo' ), 'page' => __( 'Now on', 'chatdozo' ), 'source' => __( 'Came', 'chatdozo' ), 'device' => __( 'Device', 'chatdozo' ), 'first' => __( 'First chat', 'chatdozo' ), 'firstChat' => __( 'First chat', 'chatdozo' ), 'visits' => __( 'Chats', 'chatdozo' ), 'search' => __( 'Search name, email, page, tag or city', 'chatdozo' ), 'online' => __( "You're on duty", 'chatdozo' ), 'away' => __( "You're off duty", 'chatdozo' ), /* translators: %s: names, comma separated */ 'alsoOn' => __( 'Also online: %s', 'chatdozo' ), /* translators: %s: the next opening time */ 'outsideHours' => __( 'Outside business hours · back %s', 'chatdozo' ), 'name' => __( 'Name', 'chatdozo' ), 'email' => __( 'Email', 'chatdozo' ), 'save' => __( 'Save', 'chatdozo' ), 'today' => __( 'Today', 'chatdozo' ), 'closedNote' => __( 'This chat is closed. Replying reopens it.', 'chatdozo' ), 'location' => __( 'Location', 'chatdozo' ), 'localTime'=> __( 'Local time', 'chatdozo' ), 'language' => __( 'Language', 'chatdozo' ), 'ip' => __( 'IP', 'chatdozo' ), 'unknown' => __( 'not known', 'chatdozo' ), 'alertsOn' => __( 'Desktop alerts on', 'chatdozo' ), 'alertsOff'=> __( 'Turn on desktop alerts', 'chatdozo' ), 'alertsBlocked' => __( 'Desktop alerts blocked in the browser', 'chatdozo' ), 'note' => __( 'Note', 'chatdozo' ), 'notePh' => __( 'Private note, the visitor never sees this', 'chatdozo' ), 'attach' => __( 'Attach', 'chatdozo' ), 'assign' => __( 'Assign to', 'chatdozo' ), 'unassigned' => __( 'Nobody yet', 'chatdozo' ), 'addTag' => __( '+ tag', 'chatdozo' ), 'ratedGood'=> __( 'Rated good', 'chatdozo' ), 'ratedBad' => __( 'Rated not good', 'chatdozo' ), 'transcript' => __( 'Email them a copy', 'chatdozo' ), 'transcriptSent' => __( 'Copy sent', 'chatdozo' ), 'export' => __( 'Download', 'chatdozo' ), 'ban' => __( 'Block visitor', 'chatdozo' ), 'unban' => __( 'Unblock', 'chatdozo' ), 'banned' => __( 'Blocked', 'chatdozo' ), 'banConfirm' => __( 'Block this visitor? They will not be able to chat from this connection again, and this chat closes.', 'chatdozo' ), 'deleteChat' => __( 'Delete chat', 'chatdozo' ), 'deleteConfirm' => __( 'Delete this conversation and its files for good?', 'chatdozo' ), /* translators: %s: number of chats */ 'deleteMany' => __( 'Delete %s chats and their files for good?', 'chatdozo' ), 'select' => __( 'Select', 'chatdozo' ), 'selectAll'=> __( 'Select all', 'chatdozo' ), /* translators: %s: number of chats */ 'selected' => __( '%s selected', 'chatdozo' ), 'cancel' => __( 'Cancel', 'chatdozo' ), 'takeIt' => __( 'Take it', 'chatdozo' ), 'delete' => __( 'Delete', 'chatdozo' ), 'rowDone' => __( 'Mark done', 'chatdozo' ), 'rowReopen'=> __( 'Reopen', 'chatdozo' ), 'cannedTip'=> __( 'Type / for a saved reply. {name} and {me} fill in automatically.', 'chatdozo' ), 'failed' => __( 'That did not go through. Try again.', 'chatdozo' ), 'sending' => __( 'Sending photo…', 'chatdozo' ), ), ); return (array) apply_filters( 'chatdozo_inbox_data', $data ); } public static function inbox() { echo '
|
|