Esempio n. 1
0
 /**
  * Init Screets Chat X when WordPress Initialises
  *
  * @access public
  * @return void
  */
 function init()
 {
     // Before init action
     do_action('before_cx_init');
     // Check if Woocommerce installed
     if (function_exists('is_woocommerce')) {
         define('CX_WC_INSTALLED', true);
     }
     // Some user info
     $this->current_page = cx_current_page_url();
     $this->ip = cx_ip_address();
     // User is operator?
     if (current_user_can('answer_visitors')) {
         define('CX_OP', true);
         // User is visitor?
     } else {
         define('CX_VISITOR', true);
     }
     if (!is_admin() || defined('DOING_AJAX')) {
         add_action('wp_enqueue_scripts', array(&$this, 'frontend_scripts'));
         add_action('wp_print_scripts', array($this, 'check_jquery'), 25);
     }
     // Create options object
     $this->option = new CX_options(__FILE__);
     // Get options set
     require CX_PATH . '/core/options/options.php';
     // Create options page
     $this->option->add_options_page(array('menu_title' => __('Settings', 'cx'), 'parent' => 'chat_x'), $cx_opts_set);
     // Get all options
     $this->opts = $this->option->get_options();
     // Ajax requests
     $ajax_prefix = !empty($this->opts['faster_ajax']) ? 'cx_' : 'wp_';
     add_action($ajax_prefix . 'ajax_cx_ajax_callback', 'cx_ajax_callback');
     add_action($ajax_prefix . 'ajax_nopriv_cx_ajax_callback', 'cx_ajax_callback');
     // WPML support (updates opts)
     if (function_exists('icl_register_string')) {
         $this->WPML($cx_opts_set);
     }
     // Save user info
     if (is_user_logged_in()) {
         global $current_user;
         // Get currently logged user info
         get_currentuserinfo();
         $this->user = $current_user;
         // Visitor info
     } else {
         $visitor_id = $this->session->get('visitor_id');
         // Create new unique ID
         if (empty($visitor_id)) {
             $visitor_id = uniqid(rand(), false);
             // Save id into the session
             $this->session->set('visitor_id', $visitor_id);
         }
         $this->user = (object) array('ID' => $visitor_id, 'display_name' => null, 'user_email' => null);
     }
     // Register Visitors post type when default AJAX base is enabled
     /*if( $this->opts['app'] == 'none' ) {
     
     			$labels = array(
     				'name'                => _x( 'Visitors', 'Post Type General Name', 'cx' ),
     				'singular_name'       => _x( 'Visitor', 'Post Type Singular Name', 'cx' ),
     				'menu_name'           => __( 'Visitor', 'cx' ),
     				'parent_item_colon'   => __( 'Parent Visitor:', 'cx' ),
     				'all_items'           => __( 'All Visitors', 'cx' ),
     				'view_item'           => __( 'View Visitor', 'cx' ),
     				'add_new_item'        => __( 'Add New Visitor', 'cx' ),
     				'add_new'             => __( 'New Visitor', 'cx' ),
     				'edit_item'           => __( 'Edit Visitor', 'cx' ),
     				'update_item'         => __( 'Update Visitor', 'cx' ),
     				'search_items'        => __( 'Search visitors', 'cx' ),
     				'not_found'           => __( 'No visitors found', 'cx' ),
     				'not_found_in_trash'  => __( 'No visitors found in Trash', 'cx' ),
     			);
     			$args = array(
     				'labels'              => $labels,
     				'supports'            => array( 'title', 'custom-fields' ),
     				'hierarchical'        => false,
     				'public'              => false,
     				'show_ui'             => true,
     				'show_in_menu'        => false,
     				'show_in_nav_menus'   => false,
     				'show_in_admin_bar'   => false,
     				'menu_position'       => 60,
     				'menu_icon'           => '',
     				'can_export'          => true,
     				'has_archive'         => true,
     				'exclude_from_search' => true,
     				'publicly_queryable'  => true,
     				'capability_type'     => 'page',
     				'capabilities' 		  => array(
     					// 'create_posts' => false
     				)
     			);
     			register_post_type( 'cx_visitor', $args );
     
     		}*/
     // Register Offline Messages post type
     $labels = array('name' => _x('Offline Messages', 'Post Type General Name', 'cx'), 'singular_name' => _x('Offline Message', 'Post Type Singular Name', 'cx'), 'menu_name' => __('Offline Message', 'cx'), 'parent_item_colon' => __('Parent Offline Message:', 'cx'), 'all_items' => __('All Offline Messages', 'cx'), 'view_item' => __('View Offline Message', 'cx'), 'add_new_item' => __('Add New Offline Message', 'cx'), 'add_new' => __('New Offline Message', 'cx'), 'edit_item' => __('Edit Offline Message', 'cx'), 'update_item' => __('Update Offline Message', 'cx'), 'search_items' => __('Search offline message', 'cx'), 'not_found' => __('No offline message found', 'cx'), 'not_found_in_trash' => __('No offline message found in Trash', 'cx'));
     $args = array('labels' => $labels, 'supports' => array('title'), 'hierarchical' => false, 'public' => false, 'show_ui' => true, 'show_in_menu' => false, 'show_in_nav_menus' => false, 'show_in_admin_bar' => false, 'menu_position' => 60, 'menu_icon' => '', 'can_export' => true, 'has_archive' => false, 'exclude_from_search' => true, 'publicly_queryable' => false, 'rewrite' => false, 'capability_type' => 'page', 'capabilities' => array());
     register_post_type('cx_offline_msg', $args);
     // Predefined Messages post type
     /*$labels = array(
     			'name'                => _x( 'Predifined Messages', 'Post Type General Name', 'cx' ),
     			'singular_name'       => _x( 'Predefined Message', 'Post Type Singular Name', 'cx' ),
     			'menu_name'           => __( 'Predefined Message', 'cx' ),
     			'parent_item_colon'   => __( 'Parent Predefined Message:', 'cx' ),
     			'all_items'           => __( 'All Predefined Messages', 'cx' ),
     			'view_item'           => __( 'View Predefined Message', 'cx' ),
     			'add_new_item'        => __( 'Add New Predefined Message', 'cx' ),
     			'add_new'             => __( 'New Predefined Message', 'cx' ),
     			'edit_item'           => __( 'Edit Predefined Message', 'cx' ),
     			'update_item'         => __( 'Update Predefined Message', 'cx' ),
     			'search_items'        => __( 'Search predefined message', 'cx' ),
     			'not_found'           => __( 'No predefined message found', 'cx' ),
     			'not_found_in_trash'  => __( 'No predefined message found in Trash', 'cx' ),
     		);
     		$args = array(
     			'labels'              => $labels,
     			'supports'            => array( 'title', 'editor' ),
     			'hierarchical'        => false,
     			'public'              => false,
     			'show_ui'             => true,
     			'show_in_menu'        => false,
     			'show_in_nav_menus'   => false,
     			'show_in_admin_bar'   => false,
     			'menu_position'       => 60,
     			'menu_icon'           => '',
     			'can_export'          => true,
     			'has_archive'         => true,
     			'exclude_from_search' => true,
     			'publicly_queryable'  => true,
     			'capability_type'     => 'page',
     			'capabilities' 		  => array(
     				// 'create_posts' => false
     			)
     		);
     		register_post_type( 'cx_predefined_msg', $args );*/
     // Add operator name to user fields
     if (defined('CX_OP')) {
         add_action('show_user_profile', array(&$this, 'xtra_profile_fields'), 10);
         add_action('edit_user_profile', array(&$this, 'xtra_profile_fields'), 10);
         add_action('personal_options_update', array(&$this, 'save_xtra_profile_fields'));
         add_action('edit_user_profile_update', array(&$this, 'save_xtra_profile_fields'));
     }
     // Add custom css
     if (!empty($this->opts['custom_css']) || @$this->opts['avatar_size'] != 30) {
         add_action('wp_footer', array(&$this, 'custom_css'));
     }
     // Render chat box
     add_action('wp_footer', array(&$this, 'display_chatbox'));
     // Shortcodes
     add_shortcode('cx_btn', 'cx_shortcode_open_chatbox');
     // Check updates
     $this->update();
     // Initialization action
     do_action('cx_init');
 }
Esempio n. 2
0
/**
 * Send offline message
 *
 * @return	bool
 */
function cx_send_offline_msg($to, $site_email, $data)
{
    global $CX;
    $f = array();
    $usr = new CX_User();
    $opts = $CX->opts;
    $ip_addr = cx_ip_address();
    //
    // Email template
    //
    $msg = $html = '<div style="color:#222222;font-family:Arial,sans-serif;font-size:14px;">';
    $msg .= cx_offline_email_head();
    // Wrapper
    $msg .= '<div style="border-width:0 1px 1px 1px; border-style: solid; border-color: #ddd;">';
    // Lead message
    $msg .= '<div style="font-size:15px;padding:30px;line-height:20px;">' . htmlspecialchars_decode($opts['contact_header']) . '</div>';
    // Form details
    $msg .= '<div style="font-size:15px;padding:0 30px 15px 30px;line-height:20px;">';
    //
    // Message content
    //
    // Name field
    if (!empty($data['name'])) {
        $msg .= '<strong>' . __('Name', 'cx') . '</strong>: ' . $data['name'] . '<br />';
    }
    // Email field
    if (!empty($data['name'])) {
        $msg .= '<strong>' . __('E-mail', 'cx') . '</strong>: <a href="' . $data['email'] . '">' . $data['email'] . '</a><br />';
    }
    // Phone field
    if (!empty($data['phone'])) {
        $msg .= '<strong>' . __('Phone', 'cx') . '</strong>: ' . $data['phone'] . '<br />';
    }
    // Message field
    $msg .= '<strong>' . __('Message', 'cx') . '</strong>: <br>' . str_replace("\n", '<br />', htmlspecialchars(stripslashes($data['msg']))) . '<br />';
    // User additional message
    $msg .= '<div style="font-size:11px;padding:15px 0;">' . __('User information', 'cx') . ': <br>' . $ip_addr . ' - ' . $usr->info('os') . ', ' . $usr->info('browser') . ' ' . $usr->info('version') . '<br>' . $_SERVER['HTTP_REFERER'] . '<br>' . '</div>';
    $msg .= '</div>';
    // form details
    // Footer
    $msg .= cx_offline_email_foot();
    $msg .= '</div>';
    // wrapper
    $msg .= '</div>';
    // Set subject
    $subject = '[' . $opts['site_name'] . '] ' . __('New offline message', 'cx');
    /**
     * Send email to admin emails
     */
    $headers = array();
    $headers[] = 'MIME-Version: 1.0';
    $headers[] = 'content-type: text/html';
    $headers[] = 'charset=utf-8';
    // From visitor if email given by visitor
    if (!empty($data['email'])) {
        $_name = !empty($data['name']) ? $data['name'] : $opts['site_name'];
        $headers[] = 'From: [' . $_name . '] <' . $data['email'] . '>';
        // From operator if no email given by visitor
    } else {
        $headers[] = 'From: [' . $opts['site_name'] . '] <' . $site_email . '>';
    }
    //
    // Send email to admins
    //
    if (!wp_mail($to, $subject, $msg, $headers)) {
        $f['status'] = 'failed';
    } else {
        $f['status'] = 'succeed';
    }
    //
    // Add offline message
    //
    $f['name'] = $data['name'];
    $f['email'] = $data['email'];
    $f['os'] = $usr->info('os');
    $f['browser'] = $usr->info('browser');
    $f['version'] = $usr->info('version');
    $f['site_email'] = $site_email;
    $f['to'] = $to;
    cx_add_offline_msg($data['msg'], $f, $ip_addr);
    // If email sent failed, return false
    if ($f['status'] == 'failed') {
        return false;
    }
    /**
     * Send copy to  the visitor
     */
    if (!empty($data['email']) and !empty($opts['contact_email_to_visitor'])) {
        // Set subject
        $subject = '[' . $opts['site_name'] . '] ' . __('We received your message', 'cx');
        $headers = array();
        $headers[] = 'MIME-Version: 1.0';
        $headers[] = 'content-type: text/html';
        $headers[] = 'charset=utf-8';
        $to = $data['email'];
        // Send email to the visitor
        wp_mail($to, $subject, $msg, $headers);
    }
    return true;
}