MP_Addon_Calls_Leads
Class MP_Addon_Calls_Leads.
Source Source
File: calculator-calls-add-on/inc/MP_Addon_Calls_Leads.php
class MP_Addon_Calls_Leads {
/**
* Add Call Records.
*
* @since 1.0.0
* @access public
*/
public function add_lead_call_records() {
add_meta_box(
MortgagePlatform::$prefix . 'calls',
__( 'Call Records', 'CalculatorsCallsAddon' ),
array( $this, 'call_records' ),
array( MortgagePlatform::$lead, MortgagePlatform::$abandoned_lead ),
'normal',
'core'
);
}
/**
* Callback for call records metabox.
*
* @since 1.0.0
* @access public
*
* @param mixed $post post
*/
public function call_records( $post ) {
$check = new MP_Addon_Calls_IncomingCalls();
$calls = $check->check_call_records( $post );
if ( empty( $calls ) ) {
return;
}
add_action( 'wp_enqueue_scripts', array($this, 'enqueue_audio_scripts') );
//echo '<script src="' . plugin_dir_url( __FILE__ ) . '../assets/js/audiojs/audio.min.js"></script>';
echo '<div class="call_records">';
echo '<ul>';
foreach ( $calls as $call ) {
$date = preg_replace( '/\s:.*$/', '', $call );
preg_match( '/Recording Duration:(.+)s:/', $call, $duration );
$pattern = '/(?i)\b((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'\".,<>?«»""‘’]))/';
preg_match( $pattern, $call, $matches, PREG_OFFSET_CAPTURE, 0 );
$audio = '<a href="#" data-src="' . $matches[0][0] . '">' . $date . '</a>';
echo '<li>' . wp_kses( $audio , 'post') . '<span>' . esc_attr( $duration[1] ) . 's</li>';
}
echo '</ul>';
echo '<audio preload></audio>';
echo '</div>';
//echo '<script src="' . plugin_dir_url( __FILE__ ) . '../assets/js/audiojs/audio_playlist.js"></script>';
}
/**
* Enqueue Audio scripts.
*
* @access protected
* @since 1.0.0
*/
protected function enqueue_audio_scripts() {
wp_enqueue_script( MortgagePlatform::$prefix . 'audio', plugins_url( '../assets/js/audiojs/audio.min.js', __FILE__ ), array( 'jquery' ), MortgagePlatform::$mortgage_platform_version, true );
wp_enqueue_script( MortgagePlatform::$prefix . 'audio_playlist', plugins_url( '../assets/js/audiojs/audio_playlist.js', __FILE__ ), array( 'jquery' ), MortgagePlatform::$mortgage_platform_version, true );
}
/**
* Lead Call Metabox.
*
* @since 1.0.0
* @access public
*
* @param mixed $post post
*
* @return mixed
*/
public function lead_call( $post ) {
$phone = get_post_meta( $post->ID, MortgagePlatform::$prefix . 'lead_phone' ) ? get_post_meta( $post->ID, MortgagePlatform::$prefix . 'lead_phone', true ) : null;
if ( $phone ) {
$this->call_controls($post, $phone);
add_action( 'wp_enqueue_scripts', array($this, 'enqueue_twilio_client_scripts'));
}
return $post;
}
/**
* Call tab.
*
* @since 1.0.0
* @access protected
*
* @param \WP_Post $post post
* @param string $phone lead phone
*/
protected function call_controls($post, $phone) {
$call_button = '<svg version="1.1" fill="green" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="512px" height="512px" viewBox="0 0 512 512" style="enable-background:new 0 0 512 512;" xml:space="preserve"><g><path d="M256,32c123.5,0,224,100.5,224,224S379.5,480,256,480S32,379.5,32,256S132.5,32,256,32 M256,0C114.625,0,0,114.625,0,256 s114.625,256,256,256s256-114.625,256-256S397.375,0,256,0L256,0z M398.719,341.594l-1.438-4.375 c-3.375-10.062-14.5-20.562-24.75-23.375L334.688,303.5c-10.25-2.781-24.875,0.969-32.405,8.5l-13.688,13.688 c-49.75-13.469-88.781-52.5-102.219-102.25l13.688-13.688c7.5-7.5,11.25-22.125,8.469-32.406L198.219,139.5 c-2.781-10.25-13.344-21.375-23.406-24.75l-4.313-1.438c-10.094-3.375-24.5,0.031-32,7.563l-20.5,20.5 c-3.656,3.625-6,14.031-6,14.063c-0.688,65.063,24.813,127.719,70.813,173.75c45.875,45.875,108.313,71.345,173.156,70.781 c0.344,0,11.063-2.281,14.719-5.938l20.5-20.5C398.688,366.062,402.062,351.656,398.719,341.594z"/></g></svg>';
$hangup_button = '<svg version="1.1" fill="red" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="512px" height="512px" viewBox="0 0 512 512" style="enable-background:new 0 0 512 512;" xml:space="preserve"><g><path d="M256,32c123.5,0,224,100.5,224,224S379.5,480,256,480S32,379.5,32,256S132.5,32,256,32 M256,0C114.625,0,0,114.625,0,256 s114.625,256,256,256s256-114.625,256-256S397.375,0,256,0L256,0z M398.719,341.594l-1.438-4.375 c-3.375-10.062-14.5-20.562-24.75-23.375L334.688,303.5c-10.25-2.781-24.875,0.969-32.405,8.5l-13.688,13.688 c-49.75-13.469-88.781-52.5-102.219-102.25l13.688-13.688c7.5-7.5,11.25-22.125,8.469-32.406L198.219,139.5 c-2.781-10.25-13.344-21.375-23.406-24.75l-4.313-1.438c-10.094-3.375-24.5,0.031-32,7.563l-20.5,20.5 c-3.656,3.625-6,14.031-6,14.063c-0.688,65.063,24.813,127.719,70.813,173.75c45.875,45.875,108.313,71.345,173.156,70.781 c0.344,0,11.063-2.281,14.719-5.938l20.5-20.5C398.688,366.062,402.062,351.656,398.719,341.594z"/></g></svg>';
$svg_args = array( 'svg' => array( 'xmlns' => true, 'width' => true, 'height' => true, 'fill' => true, 'viewbox' => true, ), 'path' => array( 'd' => true ), );
?>
<script>
if (jQuery('.send_message_tabs')) {
$tab=' <li data-tab="send_message_tab_call"><?php echo esc_html__( 'Call', 'CalculatorsCallsAddon' ); ?></li>';
jQuery('.send_message_tabs').append($tab);
}
</script>
<div class="send_message__wrapper" id="send_message_tab_call" >
<div id="call-controls">
<input data-leadid="<?php echo esc_attr( $post->ID ); ?>" id="phone-number" type="hidden" value="<?php echo esc_attr( $phone ); ?>"/>
<button class="button" id="button-call" title="<?php echo esc_attr__( 'Call', 'CalculatorsCallsAddon' ); ?>"><?php echo wp_kses( $call_button, $svg_args ); ?></button>
<button class="button" id="button-hangup" title="<?php echo esc_attr__( 'Hangup', 'CalculatorsCallsAddon' ); ?>"><?php echo wp_kses( $hangup_button, $svg_args ); ?></button>
</div>
<div id="log"></div>
</div>
<?php
}
/**
* Enqueue Twilio client scripts.
*
* @access protected
* @since 1.0.0
*/
protected function enqueue_twilio_client_scripts() {
wp_enqueue_script( MortgagePlatform::$prefix . 'twilio_client', plugins_url( '../assets/js/twilio_client.js', __FILE__ ), array( 'jquery' ), MortgagePlatform::$mortgage_platform_version, true );
}
}
Methods Methods
- add_lead_call_records — Add Call Records.
- call_controls — Call tab.
- call_records — Callback for call records metabox.
- enqueue_audio_scripts — Enqueue Audio scripts.
- enqueue_twilio_client_scripts — Enqueue Twilio client scripts.
- lead_call — Lead Call Metabox.
Changelog Changelog
| Version | Description |
|---|---|
| 1.0.0 | Introduced. |