403Webshell
Server IP : 121.121.20.254  /  Your IP : 216.73.216.146
Web Server : Microsoft-IIS/10.0
System : Windows NT WEB-SERVER 10.0 build 20348 (Windows Server 2022) AMD64
User : IUSR ( 0)
PHP Version : 8.3.28
Disable Function : NONE
MySQL : ON  |  cURL : ON  |  WGET : OFF  |  Perl : OFF  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  C:/inetpub/wwwroot/AIWEBSTATION/wp-content/plugins/voice-message-addon/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : C:/inetpub/wwwroot/AIWEBSTATION/wp-content/plugins/voice-message-addon/wpbotvoicemessage.php
<?php
/**
 * Plugin Name: Voice Message for WPBot
 * Plugin URI: https://quantumcloud.com/
 * Description: Voice messages contact form with speech recognition.
 * Author: QuantumCloud
 * Version: 1.0.4
 * Author URI: https://quantumcloud.com/
 * Requires PHP: 5.6
 * Requires at least: 4.6
 * Tested up to: 5.8
 **/


namespace QuantumCloud;

/** Exit if accessed directly. */
if ( ! defined( 'ABSPATH' ) ) {
	header( 'Status: 403 Forbidden' );
	header( 'HTTP/1.1 403 Forbidden' );
	exit;
}

/** Include plugin autoloader for additional classes. */
require __DIR__ . '/src/autoload.php';

use QuantumCloud\QContacter\UI;
use QuantumCloud\QContacter\Helper;
use function mime_content_type;
use QuantumCloud\QContacter\Settings;
use QuantumCloud\QContacter\SvgHelper;
use QuantumCloud\QContacter\CustomPost;
use QuantumCloud\QContacter\Shortcodes;
use QuantumCloud\QContacter\EnvatoItem;
use QuantumCloud\QContacter\PluginHelper;
use QuantumCloud\QContacter\ContacterForm;
use QuantumCloud\QContacter\PluginUpdater;
use QuantumCloud\QContacter\DeveloperBoard;
use QuantumCloud\QContacter\AssignmentsTab;
use QuantumCloud\QContacter\CheckCompatibility;

/** Includes the autoloader for libraries installed with Composer. */
require __DIR__ . '/vendor/autoload.php';

use Google\ApiCore\ApiException;
use Google\Cloud\Speech\V1\SpeechClient;
use Google\Cloud\Speech\V1\RecognitionAudio;
use Google\Cloud\Speech\V1\RecognitionConfig;
use Google\Cloud\Speech\V1\RecognitionConfig\AudioEncoding;

/**
 * SINGLETON: Core class used to implement a QContacter plugin.
 *
 * This is used to define internationalization, admin-specific hooks, and
 * public-facing site hooks.
 *
 * @since 1.0.0
 */
final class wpbotvoicemessage {

	/**
	 * Plugin version.
	 *
	 * @string version
	 * @since 1.0.0
	 **/
	public static $version;

	/**
	 * Use minified libraries if SCRIPT_DEBUG is turned off.
	 *
	 * @since 1.0.0
	 **/
	public static $suffix ;

	/**
	 * URL (with trailing slash) to plugin folder.
	 *
	 * @var string
	 * @since 1.0.0
	 **/
	public static $url;

	/**
	 * PATH to plugin folder.
	 *
	 * @var string
	 * @since 1.0.0
	 **/
	public static $path;

	/**
	 * Plugin base name.
	 *
	 * @var string
	 * @since 1.0.0
	 **/
	public static $basename;

	/**
	 * Plugin admin menu base.
	 *
	 * @var string
	 * @since 1.0.5
	 **/
	public static $menu_base;

	/**
	 * The one true QContacter.
	 *
	 * @since 1.0.0
	 **@var wpbotvoicemessage
	 */
	private static $instance;

	/**
	 * Sets up a new plugin instance.
	 *
	 * @since 1.0.0
	 * @access public
	 **/
	private function __construct() {

		/** Initialize main variables. */
		$this->initialization();

	}

	/**
	 * Setup the plugin.
	 *
	 * @since 1.0.5
	 * @access public
	 *
	 * @return void
	 **/
	public function setup() {

		/** Do critical initial checks. */
		if ( ! CheckCompatibility::get_instance()->do_initial_checks( true ) ) { return; }
		if( ! class_exists( 'qcld_wb_Chatbot' ) ){
			add_action('admin_notices', [$this, 'missing_main_plugin']);
			return;
		}
		/** Send install Action to our host. */
		self::send_install_action();

		/** Define hooks that runs on both the front-end as well as the dashboard. */
		$this->both_hooks();

		/** Define public hooks. */
		$this->public_hooks();

		/** Define admin hooks. */
		$this->admin_hooks();

	}

	/**
	 * Return plugin version.
	 *
	 * @return string
	 * @since 1.0.0
	 * @access public
	 **/
	public function get_version() {

		return self::$version;

	}

	/**
	 * Define hooks that runs on both the front-end as well as the dashboard.
	 *
	 * @since 1.0.0
	 * @access private
	 * @return void
	 **/
	private function both_hooks() {

		/** Initialize plugin settings. */
		Settings::get_instance();

		/** Plugin update mechanism enable only if plugin have Envato ID. */
		$plugin_id = EnvatoItem::get_instance()->get_id();
		if ( (int)$plugin_id > 0 ) {
			PluginUpdater::get_instance();
		}

		/** Load translation. */
		add_action( 'plugins_loaded', [$this, 'load_textdomain'] );

		/** Register contacter_form_qcld and qcldwpbot_record post types. */
		CustomPost::get_instance();

		/** Adds all the necessary shortcodes. */
		Shortcodes::get_instance();

		/** Allow svg uploading. */
		SvgHelper::get_instance();

		/** Add AJAX callback. */
		add_action( 'wp_ajax_wpbotvoicemessage_send', [$this, 'wpbotvoicemessage_send'] );
		add_action( 'wp_ajax_nopriv_wpbotvoicemessage_send', [$this, 'wpbotvoicemessage_send'] );

		/** Enable Custom Notifications and Alerts. */
		$this->enable_notifications();

	}

	/**
	 * Register all of the hooks related to the admin area functionality.
	 *
	 * @since 1.0.0
	 * @access private
	 * @return void
	 **/
	private function admin_hooks() {

		/** Work only in admin area. */
		if ( ! is_admin() ) { return; }

		/** Initialize PluginHelper. */
		PluginHelper::get_instance();

		/** Add plugin settings page. */
		Settings::get_instance()->add_settings_page();

		/** Load JS and CSS for Backend Area. */
		add_action( 'admin_enqueue_scripts', [ $this, 'admin_styles' ], 100 ); // CSS.
		add_action( 'admin_enqueue_scripts', [ $this, 'admin_scripts' ], 100 ); // JS.

		/** Remove "Thank you for creating with WordPress" and WP version only from plugin settings page. */
		add_action( 'admin_enqueue_scripts', [$this, 'remove_wp_copyrights'] );

		/** Remove all "third-party" notices from plugin settings page. */
		add_action( 'in_admin_header', [$this, 'remove_all_notices'], 1000 );

		/** Add AJAX callback for transcription generation. */
		add_action( 'wp_ajax_gtrans', [$this, 'gtrans'] );

		add_filter( 'custom_menu_order', [$this, 'wpbotvoicemessage_order_index_catalog_menu_page'] );

		/** Add Ajax handlers for Developer Board. */
		DeveloperBoard::add_ajax();

		// Removes the "Trash" link on the individual post's "actions" row on the posts
		add_action('views_edit-contacter_form_qcld', [$this, 'remove_trash_filter']);
		add_filter( 'post_row_actions', [$this, 'remove_row_actions_post'], 10, 2 );
		add_action('wp_trash_post', [$this, 'restrict_post_deletion']);

	}

	/**
	 * Removes the "Trash" link on the individual post's "actions" row on the posts
	 * edit page.
	 */
	function remove_row_actions_post( $actions, $post ) {
	    if( $post->post_type === 'contacter_form_qcld' ) {
	        unset( $actions['clone'] );
	        unset( $actions['trash'] );
	    }
	    return $actions;
	}

	function restrict_post_deletion($post_id) {
	    if( get_post_type($post_id) === 'contacter_form_qcld' ) {
	      wp_die('The post you were trying to delete is protected.');
	    }
	}

	function remove_trash_filter( $views ) {
	    $remove_views = [ 'trash' ];

	    foreach( (array) $remove_views as $view )
	    {
	        if( isset( $views[$view] ) )
	            unset( $views[$view] );
	    }
	    return $views;
	}

	/**
	 * Enable Custom Notifications and Alerts.
	 *
	 * @since  1.0.5
	 * @access public
	 **/
	private function enable_notifications() {

		/** Bundle Notification plugin. */
		require_once self::$path . '/src/notification/load.php';

		$this->notification_whitelabel( [
			'page_hook'       => 'edit.php?post_type=qcldwpbot_record',
			'extensions'      => false, // Hide extensions page.
			'settings'        => false, // Hide settings page.
		] );

    }

	/**
	 * Sets the Notification plugin in white label mode.
	 *
	 * Args you can use:
	 * - 'page_hook' => 'edit.php?post_type=page' // to move the Notifications under specific admin page
	 *
	 * @since 1.0.5
	 * @param array $args white label args.
	 * @return void
	 **/
	private function notification_whitelabel( $args = [] ) {

		add_filter( 'notification/whitelabel', '__return_true' );

		/** Change Notification CPT page. */
		if ( isset( $args['page_hook'] ) && ! empty( $args['page_hook'] ) ) {

			add_filter( 'notification/whitelabel/cpt/parent', static function( $hook ) use ( $args ) {

				return $args['page_hook'];

			} );

		}

		/** Remove extensions. */
		if ( isset( $args['extensions'] ) && false === $args['extensions'] ) {

			add_filter( 'notification/whitelabel/extensions', '__return_false' );

		}

		/** Remove settings. */
		if ( isset( $args['settings'] ) && false === $args['settings'] ) {

			add_filter( 'notification/whitelabel/settings', '__return_false' );

		}

		/** Settings access. */
		if ( isset( $args['settings_access'] ) ) {

			add_filter( 'notification/whitelabel/settings/access', static function( $access ) use ( $args ) {

				return (array) $args['settings_access'];

			} );

		}

	}

	/**
	 * Generate transcription.
	 *
	 * @throws ApiException
	 * @since  1.0.0
	 * @access public
	 **/
	public function gtrans() {

		/** Verifies the Ajax request to prevent processing requests external of the blog. */
		check_ajax_referer( 'admin-wpbotvoicemessage-nonce', 'security' );

		/** Exit if no data to process. */
		if ( empty( $_POST ) ) {
			echo json_encode([
				'status' => 'err',
				'message' => 'empty( $_POST ).'
			]);
		    wp_die();
		}

		/** Remove service variables. */
		unset( $_POST['action'], $_POST['nonce'] );

		/** Get QContacter Record ID. */
		$record_id =  filter_input(INPUT_POST, 'record_id', FILTER_SANITIZE_NUMBER_INT );
		if ( ! $record_id ) {
			echo json_encode([
				'status' => 'err',
				'message' => 'QContacter Record ID not found.'
			]);
			wp_die();
		}

		/** Get Audio path value from meta if it's exist. */
		$audio_path = get_post_meta( $record_id, 'qcld_wpvm_vmwbmdp_contacter_audio', true );
		if ( empty( $audio_path ) ) {
			echo json_encode([
				'status' => 'err',
				'message' => 'Audio path is empty.'
			]);
			wp_die();
		}

		/** Get contents of a file into a string. */
		$content = file_get_contents( $audio_path );

		/** Set string as audio content. */
		$audio = ( new RecognitionAudio() )->setContent( $content );

		/** Automatic punctuation. */
		$punctuation = false;
		if ( 'on' === Settings::get_instance()->options['punctuation'] ) {
			$punctuation = true;
		}

		/** Get Audio Sample Rate. */
		$sample_rate = get_post_meta( $record_id, 'qcld_wpvm_vmwbmdp_contacter_audio_sample_rate', true );
		if ( ! $sample_rate ) {
			$sample_rate = 44100;
        }

		/** The audio file's encoding, sample rate and language. */
		$config = new RecognitionConfig([
			'encoding' => AudioEncoding::LINEAR16,
			'sample_rate_hertz' => $sample_rate,
			'language_code' => Settings::get_instance()->options['language'],
			'enable_automatic_punctuation' => $punctuation,
		]);

		/** Instantiates a client. */
		$client = new SpeechClient();

		/** Detects speech in the audio file. */
		$response = $client->recognize( $config, $audio );

		/** Print most likely transcription. */
		$transcript = '';
		foreach ( $response->getResults() as $result ) {
			$alternatives = $result->getAlternatives();
			$mostLikely = $alternatives[0];
			$transcript = $mostLikely->getTranscript();
		}

		if ( $transcript ) {
			echo json_encode([
				'status' => 'ok',
				'transcription' => $this->mb_ucfirst( $transcript )
			]);
		} else {
			echo json_encode([
				'status' => 'ok',
				'transcription' => ''
			]);
		}

		$client->close();

		wp_die();
	}

	/**
	 * ucfirst() function for multibyte character encodings
	 *
	 * @param string $string - String to uppercase first letter.
	 *
	 * @since  1.0.0
	 * @access private
	 *
	 * @return string
	 **/
	private function mb_ucfirst( $string ) {

        return mb_strtoupper( mb_substr( $string, 0, 1 ) ).mb_strtolower( mb_substr( $string, 1 ) );

	}

	/**
	 * Show admin warning, if we need API Key.
	 *
	 * @since 1.0.0
	 * @access public
	 * @return void
	 **/
	public function api_key_notice() {

		/** Get current screen. */
		$screen = get_current_screen();
		if ( null === $screen ) { return; }

		/** QContacter Settings Page. */
		if ( self::$menu_base === $screen->base  ) {

			/** Render "Before you start" message. */
			UI::get_instance()->render_snackbar(
				esc_html__( 'This plugin uses the Google Cloud Speech-to-Text API Key File. Set up your Google Cloud Platform project before the start.', 'wpbotvoicemessage' ),
				'warning', // Type
				-1, // Timeout
				true, // Is Closable
				[ [ 'caption' => 'Get Key File', 'link' => 'https://docs.merkulov.design/how-to-get-key-file-for-the-wpbotvoicemessage-wordpress-plugins' ] ] // Buttons
			);

		}

	}

	/**
	 * Remove all other notices.
	 *
	 * @since 1.0.0
	 * @access public
	 **/
	public function remove_all_notices() {

		/** Work only on plugin settings page. */
		$screen = get_current_screen();
		if ( null === $screen ) { return; }

		if ( $screen->base !== self::$menu_base ) { return; }

		/** Remove other notices. */
		remove_all_actions( 'admin_notices' );
		remove_all_actions( 'all_admin_notices' );

		/** Show admin warning, if we need API Key. */
		$speech_recognition = 'on' === Settings::get_instance()->options['speech_recognition'];
		$dnd_api_key = Settings::get_instance()->options['dnd-api-key'];
		if ( $speech_recognition && ! $dnd_api_key ) {
			add_action( 'admin_notices', [ $this, 'api_key_notice' ] );
		}

	}

	/**
	 * Remove "Thank you for creating with WordPress" and WP version only from plugin settings page.
	 *
	 * @since 1.0.0
	 * @access private
	 * @return void
	 **/
	public function remove_wp_copyrights() {

		/** Remove "Thank you for creating with WordPress" and WP version from plugin settings page. */
		$screen = get_current_screen(); // Get current screen.
        if ( null === $screen ) { return; }

		/** QContacter Settings Page. */
		if ( $screen->base === self::$menu_base ) {
			add_filter( 'admin_footer_text', '__return_empty_string', 11 );
			add_filter( 'update_footer', '__return_empty_string', 11 );
		}

	}

	/**
	 * Register all of the hooks related to the public-facing functionality.
	 *
	 * @since 1.0.0
	 * @access private
	 * @return void
	 **/
	private function public_hooks() {

		/** Work only on frontend area. */
		if ( is_admin() ) { return; }

		/** Load CSS for Frontend Area. */
		add_action( 'wp_enqueue_scripts', [$this, 'styles'] ); // CSS.

		/** Load JavaScript for Frontend Area. */
		add_action( 'wp_enqueue_scripts', [$this, 'scripts'] ); // JS.

		/** Show Float button. */
		if ( 'on' === Settings::get_instance()->options['show_fbutton'] ) {
			add_action( 'wp_footer', [$this, 'render_fbutton'] );
		}

	}

	/**
	 * Render Float button.
	 *
	 * @since 1.0.0
	 * @access public
	 **/
	public function render_fbutton() {

		/** Checks if float button should work on this page. */
		if ( ! AssignmentsTab::get_instance()->display() ) { return; }

		/** Get Plugin Settings. */
        $options = Settings::get_instance()->options;

		/** Form not exist or not publish => exit. */
		if ( 'publish' !== get_post_status( $options['fbutton_c_form'] ) ) { return; }

		/** Add inline styles for float button. */
		$css = $this->get_inline_css( $options );
		wp_add_inline_style( 'vmwbmdp-wpbotvoicemessage', $css );

		/** Prepare Classes. */
		$classes = ' vmwbmdp-wpbotvoicemessage-fbutton-box ';
		$classes .= ' ' . $options['fbutton_position'] . ' '; // Float Button Position.
		$classes .= ' vmwbmdp-entrance-' . $options['fbutton_animation'] . ' '; // Entrance Animation.
		$classes .= ' vmwbmdp-hover-' . $options['fbutton_hover_animation'] . ' '; // Float Button Hover Animation.
		$classes = trim( $classes );

		?>
		<!-- Start QContacter WordPress Plugin -->
		<div class="<?php esc_attr_e( $classes ); ?>">
            <button id="vmwbmdp-wpbotvoicemessage-fbutton" class="vmwbmdp-icon-position-<?php esc_attr_e( $options['fbutton_icon_position'] ); ?>">
	            <?php if ( $options['fbutton_icon_position'] !== 'none' ) : ?>
                    <span class="vmwbmdp-wpbotvoicemessage-fbutton-icon"><?php Helper::get_instance()->inline_svg_e( $options['fbutton_icon'] ); ?></span>
	            <?php endif; ?>

	            <?php if ( $options['fbutton_caption'] ) : ?>
                    <span class="vmwbmdp-wpbotvoicemessage-fbutton-caption"><?php echo wp_kses_post( $options['fbutton_caption'] ); ?></span>
	            <?php endif; ?>
            </button>
        </div>
        <div class="vmwbmdp-wpbotvoicemessage-fbutton-overlay vmwbmdp-wpbotvoicemessage-modal-animation-<?php esc_attr_e( $options['modal_animation'] ); ?>">
            <div class="vmwbmdp-wpbotvoicemessage-modal-wrap">
            <div class="vmwbmdp-wpbotvoicemessage-fbutton-modal">
	            <span class="vmwbmdp-wpbotvoicemessage-close"></span>
                <?php echo do_shortcode( '[wpbotvoicemessage id="' . $options['fbutton_c_form'] . '"]' ); ?>
            </div>
            </div>
        </div>
		<!-- End QContacter WordPress Plugin -->
		<?php

	}

	/**
	 * Return inline CSS for float button.
	 *
	 * @param array $options - Plugin Settings.
	 *
	 * @since  1.0.0
	 * @access public
	 * @return string
	 **/
	private function get_inline_css( $options ) {

	    /** Extract variables. */
	    $margin = $options['fbutton_margin'];
		$padding = $options['fbutton_padding'];
		$radius = $options['fbutton_border_radius'];
		$color = $options['fbutton_color'];
		$color_hover = $options['fbutton_color_hover'];
		$bg_color = $options['fbutton_bgcolor'];
		$bg_color_hover = $options['fbutton_bgcolor_hover'];
		$size = $options['fbutton_size'];
		$delay = $options['fbutton_entrance_timeout'];
		$overlay_bg = $options['modal_overlay_color'];
		$modal_bg = $options['modal_bg_color'];
		$modal_radius = $options['modal_radius'];

		// language=CSS
		/** @noinspection CssUnusedSymbol */
		return "
		    .vmwbmdp-wpbotvoicemessage-fbutton-box {
		        margin: {$margin}px;
		    }
		    
		    .vmwbmdp-wpbotvoicemessage-fbutton-box button {		        
		        padding: {$padding}px;
		        border-radius: {$radius}px;
		        color: {$color};
		        background: {$bg_color};
		        font-size: {$size}px;
		    }
		    
		    .vmwbmdp-wpbotvoicemessage-fbutton-box:hover button {
		        color: {$color_hover};
		        background: {$bg_color_hover}; 
		    }
		    
		    .vmwbmdp-wpbotvoicemessage-fbutton-box button .vmwbmdp-wpbotvoicemessage-fbutton-icon svg {
		        fill: {$color};
		        width: {$size}px;
                height: {$size}px;
		    }
		    
		    .vmwbmdp-wpbotvoicemessage-fbutton-box:hover button .vmwbmdp-wpbotvoicemessage-fbutton-icon svg {
		        fill: {$color_hover};
		    }
		    
		    .vmwbmdp-wpbotvoicemessage-fbutton-box button#vmwbmdp-wpbotvoicemessage-fbutton span:nth-child(2), .vmwbmdp-wpbotvoicemessage-start-btn span:nth-child(2) {
		        padding: calc({$padding}px / 2);
		    }
		    
			.vmwbmdp-wpbotvoicemessage-fbutton-box.vmwbmdp-entrance-bounce,
			.vmwbmdp-wpbotvoicemessage-fbutton-box.vmwbmdp-entrance-fade,
			.vmwbmdp-wpbotvoicemessage-fbutton-box.vmwbmdp-entrance-flip-x,
			.vmwbmdp-wpbotvoicemessage-fbutton-box.vmwbmdp-entrance-flip-y,
			.vmwbmdp-wpbotvoicemessage-fbutton-box.vmwbmdp-entrance-scale,
			.vmwbmdp-wpbotvoicemessage-fbutton-box.vmwbmdp-entrance-wobble,
			.vmwbmdp-wpbotvoicemessage-fbutton-box.vmwbmdp-entrance-rotate {
		        animation-delay: {$delay}s
		    }
		    
		    /* Modal Popup. */
		    .vmwbmdp-wpbotvoicemessage-fbutton-overlay {
		        background: {$overlay_bg};
		    }
		    
		    .vmwbmdp-wpbotvoicemessage-fbutton-overlay .vmwbmdp-wpbotvoicemessage-fbutton-modal {
		        background: {$modal_bg};
		        border-radius: {$modal_radius}px;
		    }
		";

    }

	/**
	 * Process AJAX requests from frontend.
	 *
	 * @since 1.0.0
	 * @access public
	 **/
	public function wpbotvoicemessage_send() {

		/** Verifies the Ajax request to prevent processing requests external of the blog. */
		check_ajax_referer( 'wpbotvoicemessage-nonce', 'nonce' );

		/** Exit if no data to process. */
		if ( empty( $_POST ) ) { wp_die(); }

		/** Get QContacter Form ID. */
		$cForm_id =  filter_input(INPUT_POST, 'cform-id', FILTER_SANITIZE_NUMBER_INT );

		/** Remove service variables. */
		unset( $_POST['action'], $_POST['nonce'], $_POST['cform-id'] );

		/** Save Audio file. */
		$audio_file_path = $this->save_audio_file( $cForm_id );

		/** Create qcldwpbot_record record. */
		$post_id = $this->create_record( $cForm_id, $audio_file_path );

		/** Fire event to send email notification. */
		do_action( 'qcldwpbot_record_added', $post_id );

		echo 'ok';

		wp_die();
	}

	/**
	 * Create qcldwpbot_record record.
	 *
	 * @param int $cForm_id - ID of QContacter Form.
	 * @param string $audio_file_path - Full path to audio file.
	 *
	 * @since  1.0.0
	 * @access public
	 * @return int - post_id
	 **/
	private function create_record( $cForm_id, $audio_file_path ) {

		/** QContacter Form. */
		$cForm = get_post( $cForm_id );

		/** Create record. */
		$post_id = wp_insert_post( [
			'post_type'     => 'qcldwpbot_record',
			'post_title'    => 'Record: ' . $cForm->post_title,
			'post_status'   => 'pending',
		] );

		/** Fill meta fields. */
		if ( $post_id ) {

			/** Save audio file. */
			update_post_meta( $post_id, 'qcld_wpvm_vmwbmdp_contacter_audio', wp_slash( $audio_file_path ) );

			/** Save audio sample rate. */
			$sample_rate = filter_input(INPUT_POST, 'vmwbmdp-wpbotvoicemessage-audio-sample-rate', FILTER_SANITIZE_STRING );
			update_post_meta( $post_id, 'qcld_wpvm_vmwbmdp_contacter_audio_sample_rate', $sample_rate );

			/** Save QContacter Form ID. */
			update_post_meta( $post_id, 'vmwbmdp_cform_id', $cForm_id );

			/** Prepare Additional fields. */
			$fields_fb = get_post_meta( $cForm_id, 'vmwbmdp_additional_fields_fb', true );
			$fields_fb = json_decode( $fields_fb, true ); // Array with fields params.

			$additional_fields = [];
			foreach ( $_POST as $key => $value ) {
				foreach ( $fields_fb as $field ) {
					if ( $key === $field['name'] ) {
						$additional_fields[$key] = [
							'label' => $field['label'],
							'value' => $value
						];
					}
				}
			}

			$additional_fields = json_encode( $additional_fields );
			$additional_fields = wp_slash( $additional_fields ); // Added to support أحدث المقالات

			/** Save Additional fields. */
			update_post_meta( $post_id, 'vmwbmdp_additional_fields', $additional_fields );

		}

		return $post_id;

	}

	/**
	 * Save recorded audio file.
	 *
	 * @param int $cForm_id - ID of QContacter Form.
	 *
	 * @since  1.0.0
	 * @access public
	 * @return string
	 **/
	private function save_audio_file( $cForm_id ) {

		if ( empty( $_FILES['vmwbmdp-wpbotvoicemessage-audio'] ) ) { return false; }

		/** Create file name for audio file. */
		$file_path = $this->prepare_audio_name( $cForm_id );

		/** Check file mime type. */
		$mime = mime_content_type( $_FILES['vmwbmdp-wpbotvoicemessage-audio']['tmp_name'] );

		/** Looks like uploading some shit. */
		if ( ! in_array( $mime, [ 'audio/wav', 'audio/x-wav' ] ) ) {

			/** Remove temporary audio file. */
			wp_delete_file( $_FILES['vmwbmdp-wpbotvoicemessage-audio']['tmp_name'] );

			wp_die(); // Emergency exit.
		}

		/** Save audio file. */
		file_put_contents( $file_path, file_get_contents( $_FILES['vmwbmdp-wpbotvoicemessage-audio']['tmp_name'] ), FILE_APPEND );

		/** Remove temporary audio file. */
		wp_delete_file( $_FILES['vmwbmdp-wpbotvoicemessage-audio']['tmp_name'] );

		return $file_path;

	}

	/**
	 * Prepare unique file name for wav audio file.
	 *
	 * @param int $cForm_id - ID of QContacter Form.
	 *
	 * @since  1.0.0
	 * @access public
	 * @return string
	 **/
	private function prepare_audio_name( $cForm_id ) {

		/** Prepare File name. */
		$upload_dir     = wp_get_upload_dir();
		$upload_basedir = $upload_dir['basedir'] . '/wpbotvoicemessage/'; // Path to upload folder.

		$unique_counter = 0;
		$file_name = $this->build_file_name( $cForm_id, $unique_counter );

		/** We do not need collisions. */
		$f_path = $upload_basedir . $file_name;
		if ( file_exists( $f_path ) ) {

			do {
				$unique_counter++;
				$file_name = $this->build_file_name( $cForm_id, $unique_counter );
				$f_path = $upload_basedir . $file_name;
			} while ( file_exists( $f_path ) );

		}

		$f_path = wp_normalize_path( $f_path );
		$f_path = str_replace( ['/', '\\'], DIRECTORY_SEPARATOR, $f_path );

		return $f_path;

	}

	/**
	 * Build file name.
	 *
	 * @param int $cForm_id - ID of QContacter Form.
	 * @param int $unique_counter - Unique identificator
	 *
	 * @since  1.0.0
	 * @access public
	 * @return string
	 **/
	private function build_file_name( $cForm_id, $unique_counter ) {

		return 'wpbotvoicemessage-' . $cForm_id . '-' . gmdate( 'Y-m-d\TH:i:s\Z' ) . '-' . $unique_counter . '.wav';

	}

	/**
	 * Initialize main variables.
	 *
	 * @since 1.0.0
	 * @access public
	 **/
	public function initialization() {

		/** Get Plugin version. */
		$plugin_data = $this->get_plugin_data();
		self::$version = $plugin_data['Version'];

		/** Gets the plugin URL (with trailing slash). */
		self::$url = plugin_dir_url( __FILE__ );

		/** Gets the plugin PATH. */
		self::$path = plugin_dir_path( __FILE__ );

		/** Use minified libraries if SCRIPT_DEBUG is turned off. */
		self::$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
		self::$suffix = '';

		/** Set plugin basename. */
		self::$basename = plugin_basename( __FILE__ );

		/** Plugin settings page base. */
		self::$menu_base = 'qcldwpbot_record_page_qcld_wpvm_vmwbmdp_contacter_settings';

		/** Create /wp-content/uploads/wpbotvoicemessage/ folder for audio files. */
		wp_mkdir_p( trailingslashit( wp_upload_dir()['basedir'] ) . 'wpbotvoicemessage' );

	}

	/**
	 * Return current plugin metadata.
	 *
	 * @since 1.0.5
	 * @access public
	 *
	 * @return array {
	 *     Plugin data. Values will be empty if not supplied by the plugin.
	 *
	 *     @type string $Name        Name of the plugin. Should be unique.
	 *     @type string $Title       Title of the plugin and link to the plugin's site (if set).
	 *     @type string $Description Plugin description.
	 *     @type string $Author      Author's name.
	 *     @type string $AuthorURI   Author's website address (if set).
	 *     @type string $Version     Plugin version.
	 *     @type string $TextDomain  Plugin textdomain.
	 *     @type string $DomainPath  Plugins relative directory path to .mo files.
	 *     @type bool   $Network     Whether the plugin can only be activated network-wide.
	 *     @type string $RequiresWP  Minimum required version of WordPress.
	 *     @type string $RequiresPHP Minimum required version of PHP.
	 * }
	 **/
	public function get_plugin_data() {

		if ( ! function_exists('get_plugin_data') ) {
			require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
		}

		return get_plugin_data( __FILE__ );

	}

	/**
	 * Add CSS for the public-facing side of the site.
	 *
	 * @return void
	 * @since 1.0.0
	 **/
	public function styles() {

		/** Frontend CSS for shortcodes. */
		wp_register_style( 'vmwbmdp-wpbotvoicemessage', self::$url . 'css/wpbotvoicemessage' . self::$suffix . '.css', [], self::$version );

		$inline_css = $this->get_contacter_inline_css();

		/** Add custom CSS. */
		wp_add_inline_style( 'vmwbmdp-wpbotvoicemessage', $inline_css . Settings::get_instance()->options['custom_css'] );

	}

	/**
	 * Return inline CSS for wpbotvoicemessage.
	 *
	 * @since  1.0.0
	 * @access public
	 * @return string
	 **/
	private function get_contacter_inline_css() {

	    /** Get Plugin Settings. */
	    $options = Settings::get_instance()->options;

		/** Accent Color. */
		$accent_color = $options['accent_color'];

		// language=CSS
		/** @noinspection CssUnusedSymbol */
		return "
            .vmwbmdp-wpbotvoicemessage-player-box.green-audio-player .slider .gap-progress,
            .vmwbmdp-wpbotvoicemessage-player-box.green-audio-player .slider .gap-progress .pin {
                background-color: {$accent_color};
            }
            
            .vmwbmdp-wpbotvoicemessage-player-box.green-audio-player .volume .volume__button.open path {
                fill: {$accent_color};
            } 
        ";

    }

	/**
	 * Add JavaScript for the public-facing side of the site.
	 *
	 * @return void
	 * @since 1.0.0
	 **/
	public function scripts() {

		/** Frontend JS for shortcodes. */
		wp_register_script( 'vmwbmdp-wpbotvoicemessage-recorder', self::$url . 'js/recorder' . self::$suffix . '.js', [], self::$version, true );
		wp_register_script( 'green-audio-player', self::$url . 'js/green-audio-player' . self::$suffix . '.js', [], self::$version, true );
		wp_register_script( 'vmwbwp-wpbotvoicemessage-scroller', self::$url . 'js/jquery.slimscroll' . self::$suffix . '.js', [], self::$version, true );
		wp_register_script( 'vmwbmdp-wpbotvoicemessage', self::$url . 'js/wpbotvoicemessage' . self::$suffix . '.js', ['vmwbmdp-wpbotvoicemessage-recorder', 'green-audio-player', 'vmwbwp-wpbotvoicemessage-scroller'], self::$version, true );

		/** Pass variables to frontend. */
		wp_localize_script( 'vmwbmdp-wpbotvoicemessage', 'vmwbmdpContacterWP', [
			'nonce' => wp_create_nonce( 'wpbotvoicemessage-nonce' ),
			'ajaxurl' => admin_url( 'admin-ajax.php' ),
			'accentColor' => Settings::get_instance()->options['accent_color']
		] );

	}

	/**
	 * Loads the QContacter translated strings.
	 *
	 * @since 1.0.0
	 * @access public
	 **/
	public function load_textdomain() {

		load_plugin_textdomain( 'wpbotvoicemessage', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );

	}

	/**
	 * Add CSS for admin area.
	 *
	 * @return void
	 * @since 1.0.0
	 **/
	public function admin_styles() {

		/** Get current screen to add styles on specific pages. */
		$screen = get_current_screen();
		if ( null === $screen ) { return; }

		/** QContacter Settings Page. */
		if ( self::$menu_base === $screen->base ) {
			wp_enqueue_style( 'merkulov-ui', self::$url . 'css/merkulov-ui' . self::$suffix . '.css', [], self::$version );
			wp_enqueue_style( 'vmwbmdp-wpbotvoicemessage-admin', self::$url . 'css/admin' . self::$suffix . '.css', [], self::$version );

		/** QContacter popup on update. */
		} elseif ( 'plugin-install' === $screen->base ) {

			/** Styles only for our plugin. */
			if ( isset( $_GET['plugin'] ) && $_GET['plugin'] === 'wpbotvoicemessage' ) {
				wp_enqueue_style( 'vmwbmdp-wpbotvoicemessage-plugin-install', self::$url . 'css/plugin-install' . self::$suffix . '.css', [], self::$version );
			}

		/** QContacter Form edit screen. */
		} elseif ( 'post' === $screen->base && 'contacter_form_qcld' === $screen->post_type ) {

			/** Add class .mdc-disable to body. So we can use UI without overrides WP CSS, only for this page.  */
			add_action( 'admin_body_class', [$this, 'add_admin_class'] );

			wp_enqueue_style( 'merkulov-ui', self::$url . 'css/merkulov-ui' . self::$suffix . '.css', [], self::$version );
			wp_enqueue_style( 'vmwbmdp-admin-wpbotvoicemessage-form-edit', self::$url . 'css/admin-wpbotvoicemessage-form-edit' . self::$suffix . '.css', [], self::$version );

		/** QContacter Record edit screen. */
		} elseif ( 'post' === $screen->base && 'qcldwpbot_record' === $screen->post_type ) {

			wp_enqueue_style( 'vmwbmdp-admin-wpbotvoicemessage-record-edit', self::$url . 'css/admin-wpbotvoicemessage-record-edit' . self::$suffix . '.css', [], self::$version );

        /** QContacter Forms list. */
		} elseif ( 'edit' === $screen->base && 'contacter_form_qcld' === $screen->post_type ) {

			wp_enqueue_style( 'vmwbmdp-admin-wpbotvoicemessage-forms', self::$url . 'css/admin-wpbotvoicemessage-forms' . self::$suffix . '.css', [], self::$version );
		}

	}

	/**
	 * Add class to body in admin area.
	 *
	 * @param string $classes - Space-separated list of CSS classes.
	 *
	 * @since 1.0.0
	 * @return string
	 */
	public function add_admin_class( $classes ) {

		return $classes . ' mdc-disable ';

	}

	/**
	 * Add JS for admin area.
	 *
	 * @return void
	 * @since 1.0.0
	 **/
	public function admin_scripts() {

		/** Get current screen to add scripts on specific pages. */
		$screen = get_current_screen();
		if ( null === $screen ) { return; }

		/** QContacter Settings Page. */
		if ( $screen->base === self::$menu_base ) {
			wp_enqueue_script( 'merkulov-ui', self::$url . 'js/merkulov-ui' . self::$suffix . '.js', [], self::$version, true );
			wp_enqueue_media(); // WordPress Image library for API Key File.
			wp_enqueue_script( 'vmwbmdp-wpbotvoicemessage-admin', self::$url . 'js/admin' . self::$suffix . '.js', ['jquery'], self::$version, true );

			wp_localize_script('vmwbmdp-wpbotvoicemessage-admin', 'vmwbmdpContacter', [
				'ajaxURL' => admin_url( 'admin-ajax.php' ),
				'nonce' => wp_create_nonce( 'reset_settings' ),
				'contacter_nonce' => wp_create_nonce( 'wpbotvoicemessage-nonce' ), // Nonce for security.
			] );

		/** QContacter Form edit screen. */
		} elseif ( 'post' === $screen->base && 'contacter_form_qcld' === $screen->post_type ) {

			/** Add class .mdc-disable to body. So we can use UI without overrides WP CSS, only for this page. */
			add_action( 'admin_body_class', [$this, 'add_admin_class'] );

			wp_enqueue_script( 'merkulov-ui', self::$url . 'js/merkulov-ui' . self::$suffix . '.js', [], self::$version, true );
			wp_enqueue_script( 'form-builder', self::$url . 'js/form-builder.min.js', ['jquery', 'jquery-ui-sortable'], self::$version, true );
			wp_enqueue_script( 'form-render', self::$url . 'js/form-render.min.js', ['jquery', 'jquery-ui-sortable'], self::$version, true );
			wp_enqueue_script( 'vmwbmdp-wpbotvoicemessage-clipboard', self::$url . 'js/clipboard' . self::$suffix . '.js', [], self::$version, true );
			wp_enqueue_script( 'vmwbmdp-admin-wpbotvoicemessage-form-edit', self::$url . 'js/admin-wpbotvoicemessage-form-edit' . self::$suffix . '.js', ['jquery', 'form-builder', 'vmwbmdp-wpbotvoicemessage-clipboard'], self::$version, true );
			wp_localize_script( 'vmwbmdp-admin-wpbotvoicemessage-form-edit', 'vmwbmdpContacter', [
				'locale' => $this->get_fb_locale(),
				'location' => self::$url . 'js/form-builder-languages/'
			] );

		/** QContacter Record edit screen. */
		} elseif ( 'post' === $screen->base && 'qcldwpbot_record' === $screen->post_type ) {

			wp_enqueue_script( 'vmwbmdp-admin-wpbotvoicemessage-record-edit', self::$url . 'js/admin-wpbotvoicemessage-record-edit' . self::$suffix . '.js', [], self::$version, true );

			/** Set Nonce. */
			$ajax_nonce = wp_create_nonce( 'admin-wpbotvoicemessage-nonce' );

			/** Current record ID. */
			$id = get_the_ID();

			wp_localize_script( 'vmwbmdp-admin-wpbotvoicemessage-record-edit', 'vmwbmdpContacter', [
				'record_id'  => $id,
				'ajax_nonce' => $ajax_nonce,
			] );

        /** QContacter Forms list. */
		} elseif ( 'edit' === $screen->base && 'contacter_form_qcld' === $screen->post_type ) {

			wp_enqueue_script( 'vmwbmdp-wpbotvoicemessage-clipboard', self::$url . 'js/clipboard' . self::$suffix . '.js', [], self::$version, true );
		    wp_enqueue_script( 'vmwbmdp-admin-wpbotvoicemessage-forms', self::$url . 'js/admin-wpbotvoicemessage-forms' . self::$suffix . '.js', ['jquery', 'vmwbmdp-wpbotvoicemessage-clipboard'], self::$version, true );

        }

	}

	/**
	 * Return locale for Form Builder.
	 *
	 * @since 1.0.0
	 * @return string
	 **/
	private function get_fb_locale() {

		/** Get current user Locale. */
		$locale = get_user_locale();

		/** Convert "en_US" to "en-US". */
		$locale = str_replace( '_', '-', $locale );

		/** Do we have translations file for this locale? */
		if ( file_exists( self::$path . 'js/form-builder-languages/' . $locale . '.lang' ) ) {
			return $locale;
		}

		return 'en-US';

	}

	/**
	 * Run when the plugin is activated.
	 *
	 * @static
	 * @since 1.0.0
	 **/
	public static function on_activation() {

		/** Security checks. */
		if ( ! current_user_can( 'activate_plugins' ) ) { return; }

		/** We need to know plugin to activate it. */
		if ( ! isset( $_REQUEST['plugin'] ) ) { return; }

		/** Get plugin. */
		$plugin = filter_var( $_REQUEST['plugin'], FILTER_SANITIZE_STRING );

		/** Checks that a user was referred from admin page with the correct security nonce. */
		check_admin_referer( "activate-plugin_{$plugin}" );

		/** Do critical initial checks. */
		if ( ! CheckCompatibility::get_instance()->do_initial_checks( false ) ) { return; }

		/** Send install Action to our host. */
		self::send_install_action();

		/** Create Default Form. */
		ContacterForm::create_default_form();

	}

	/**
	 * Send install Action to our host.
	 *
	 * @static
	 * @since 1.0.5
	 **/
	private static function send_install_action() {

		/** Plugin version. */
		$ver = self::get_instance()->get_version();

		/** Have we already sent 'install' for this version? */
		$opt_name = 'qcld_wpvm_vmwbmdp_wpbotvoicemessage_send_action_install';
		$ver_installed = get_option( $opt_name );

		/** Send install Action to our host. */
		if ( ! $ver_installed || $ver !== $ver_installed ) {

			/** Send install Action to our host. */
			Helper::get_instance()->send_action( 'install', 'wpbotvoicemessage', $ver );
			update_option( $opt_name, $ver );

		}

	}

	/**
	 * Main QContacter Instance.
	 *
	 * Insures that only one instance of QContacter exists in memory at any one time.
	 *
	 * @static
	 * @since 1.0.0
	 **@return wpbotvoicemessage
	 */
	public static function get_instance() {

		if ( ! isset( self::$instance ) && ! ( self::$instance instanceof self ) ) {

			self::$instance = new self;

		}

		return self::$instance;

	}

	function wpbotvoicemessage_order_index_catalog_menu_page( $menu_ord ){
		global $submenu;

		  // Enable the next line to see a specific menu and it's order positions
		  // echo '<pre>'; print_r( $submenu['edit.php?post_type=qcldwpbot_record'] ); echo '</pre>'; exit();

		  // Sort the menu according to your preferences
		  //Original order was 5,11,12,13,14,15

		  // print_r($submenu);exit;
		  
		  
		  $arr = array();

		    $arr[] = $submenu['edit.php?post_type=qcldwpbot_record'][5];
		    $arr[] = $submenu['edit.php?post_type=qcldwpbot_record'][11];
		    // $arr[] = $submenu['edit.php?post_type=qcldwpbot_record'][12];
		    $arr[] = $submenu['edit.php?post_type=qcldwpbot_record'][14];
		    $arr[] = $submenu['edit.php?post_type=qcldwpbot_record'][13];
		  
		  $submenu['edit.php?post_type=qcldwpbot_record'] = $arr;

		  return $submenu;
	}

	public function missing_main_plugin(){
		$class="notice notice-error is-dismissible qc-notice-error";
		

		$message = "You need to install and activate the <a href='https://www.quantumcloud.com/products/chatbot-for-wordpress/' target='_blank'>WPBot</a> Plugin to use the <strong>Voice Message for WPBot</strong> AddOn";

		printf( '<div class="%1$s"><a href="'.esc_url('https://www.quantumcloud.com/products/chatbot-for-wordpress/').'" target="_blank"><img src="'.esc_url(plugin_dir_url( __FILE__ ).'plugin-upgrader/images/qc-logo.jpg').'" /></a><p>%2$s</p></div>', esc_attr( $class ), $message );
	}

} // End Class QContacter.

/** Run when the plugin is activated. */
register_activation_hook( __FILE__, [wpbotvoicemessage::class, 'on_activation'] );

/** Run Speaker class once after activated plugins have loaded. */
add_action( 'plugins_loaded', [wpbotvoicemessage::get_instance(), 'setup'] );

require_once( plugin_dir_path(__FILE__) . 'plugin-upgrader/plugin-upgrader.php' );


add_action('qcldwpbot_record_added', 'QuantumCloud\qcldwpbot_record_added');
function qcldwpbot_record_added($post_id){
	$audio_path = get_post_meta( $post_id, 'qcld_wpvm_vmwbmdp_contacter_audio', true );
	$url = str_replace(
		wp_normalize_path( untrailingslashit( ABSPATH ) ),
		site_url(),
		wp_normalize_path( $audio_path )
	);

	$url = esc_url_raw( $url );
	
	/** Get Additional fields switcher value from meta if it's already been entered. */
	$vmwbmdp_additional_fields = get_post_meta( $post_id, 'vmwbmdp_additional_fields', true );

	/** Default value. Additional Fields switcher. */
	if ( '' === $vmwbmdp_additional_fields ) {
		$vmwbmdp_additional_fields = '';
	}

	$fields = json_decode( $vmwbmdp_additional_fields, true );
	$mail_content = "<table>";
	if ( count( $fields ) > 0 ) {
		$mail_content  = '<tr>';
	    $mail_content .= '<th scope="row">';
	    $mail_content .= '<label>'.esc_html_e( "Additional fields:", "wpbotvoicemessage" ) .'</label>';
	    $mail_content .= '</th>';
	    $mail_content .=  '<td>';
	    $mail_content .=  '<div class="vmwbmdp-additional-fields-box">';
	    $mail_content .=  '<table>';
	    
	    foreach ( $fields as $key => $field  ) {
	    
	        $mail_content .= '<tr class="'. esc_attr_e( $key ).'">';
	        $mail_content .= '<td><strong>'. esc_html_e( $field['label'] ) .':</strong></td>';
	        $mail_content .= '<td>';
			if ( is_array( $field['value'] ) ) :
	        	$mail_content .= '<ul>';
				foreach ( $field['value'] as $v ) :
	                $mail_content .= '<li><span>'. esc_html_e( $v ) .'</span></li>';
	            endforeach;
	            $mail_content .= '</ul>';
			else:
	        	$mail_content .= '<span>'. esc_html_e( $field['value'] ).'</span>';
			endif;
	            $mail_content .= '</td>';
				$mail_content .= '</tr>';
	    }
	    $mail_content .= '</table>';
	    $mail_content .= '</div>';
	    $mail_content .= '</td>';
	    $mail_content .= '</tr>';
	}
	$mail_content .= '<tr>';
	$mail_content .= '<th scope="row">Download Link</th>';
	$mail_content .= '<td>';
	$mail_content .= '<a href="'.$url.'">'.$url.'</a>';
	$mail_content .= '</td>';
	$mail_content .= '</tr>';
	$mail_content .= '</table>';

	 //Extract Domain
    $url = get_site_url();
    $url = parse_url($url);
    $domain = $url['host'];
    
    $admin_email = get_option('admin_email');
    $toEmail = get_option('qlcd_wp_chatbot_admin_email') != '' ? get_option('qlcd_wp_chatbot_admin_email') : $admin_email;
    $fromEmail = "wordpress@" . $domain;

    if(get_option('qlcd_wp_chatbot_from_email') && get_option('qlcd_wp_chatbot_from_email')!=''){
        $fromEmail = get_option('qlcd_wp_chatbot_from_email');
    }

    $replyto = $fromEmail;

    if(get_option('qlcd_wp_chatbot_reply_to_email') && get_option('qlcd_wp_chatbot_reply_to_email')!=''){
        $replyto = get_option('qlcd_wp_chatbot_reply_to_email');
    }
    $subject = __('WPBot Voice Message', 'wpbotvoicemessage');
	$headers = array();
    $headers[] = 'Content-Type: text/html; charset=UTF-8';
    $result = wp_mail($toEmail, $subject, $mail_content, $headers);
}

Youez - 2016 - github.com/yon3zu
LinuXploit