null ), $shortcode_attrs ); $type = $parsed_attributes['type']; if ( ! isset( $type ) ) { return; } switch ( $type ) { case 'form': return self::render_form( $shortcode_attrs ); case 'cta': return self::render_cta( $shortcode_attrs ); case 'meeting': return self::render_meeting( $shortcode_attrs ); } } /** * Render form leadin shortcodes * * @param array $attrs Shortcode attributes. */ private static function render_form( $attrs ) { $parsed_attributes = shortcode_atts( array( 'portal' => null, 'id' => null, ), $attrs ); $portal_id = $parsed_attributes['portal']; $id = $parsed_attributes['id']; if ( ! isset( $portal_id ) || ! isset( $id ) || ! is_numeric( $portal_id ) || ! ( self::is_valid_uuid( $id ) || is_numeric( $id ) ) ) { return; } $form_div_uuid = self::generate_div_uuid(); $hublet = LeadinFilters::get_leadin_hublet(); AssetsManager::enqueue_forms_script(); return '
'; } /** * Render cta leadin shortcodes * * @param array $attrs Shortcode attributes. */ private static function render_cta( $attrs ) { $parsed_attributes = shortcode_atts( array( 'portal' => null, 'id' => null, ), $attrs ); $portal_id = $parsed_attributes['portal']; $id = $parsed_attributes['id']; if ( ! isset( $portal_id ) || ! isset( $id ) || ! is_numeric( $portal_id ) || ! ( self::is_valid_uuid( $id ) || is_numeric( $id ) ) ) { return; } return ' New call-to-action <' . 'script charset="utf-8" src="//js.hubspot.com/cta/current.js"> '; } /** * Render meeting leadin shortcodes * * @param array $attrs Shortcode attributes. */ private static function render_meeting( $attrs ) { $parsed_attributes = shortcode_atts( array( 'url' => null, ), $attrs ); $url = $parsed_attributes['url']; if ( filter_var( $url, FILTER_VALIDATE_URL ) === false ) { return; } AssetsManager::enqueue_meetings_script(); return '
'; } /** * Generates 10 characters long string with random values */ private static function get_random_number_string() { $result = ''; for ( $i = 0; $i < 10; $i++ ) { $result .= wp_rand( 0, 9 ); } return $result; } /** * Generates a unique uuid */ private static function generate_div_uuid() { return time() * 1000 . '-' . self::get_random_number_string(); } /** * Checks if input is a valid uuid. * * @param String $uuid input to validate. */ private static function is_valid_uuid( $uuid ) { if ( ! is_string( $uuid ) || ( preg_match( '/^[a-f\d]{8}(-[a-f\d]{4}){4}[a-f\d]{8}$/i', $uuid ) !== 1 ) ) { return false; } return true; } }