plugin updates

This commit is contained in:
Tony Volpe
2024-06-17 15:33:26 -04:00
parent 3751a5a1a6
commit e4e274a9a7
2674 changed files with 0 additions and 507851 deletions

View File

@@ -1,71 +0,0 @@
<?php
namespace Leadin\utils;
/**
* Class containing utility functions for the sanitizing and getting query parameters.
*/
class QueryParameters {
/**
* Return a text sanitized, unslashed query parameter by its key, validated with a nonce.
*
* @param String $key Key for the query parameter to return.
* @param String $nonce_action Name of the nonce action to verify the given nonce against.
* @param String $nonce_arg Query parmeter the nonce is in.
*/
public static function get_param( $key, $nonce_action, $nonce_arg = '_wpnonce' ) {
if (
isset( $_GET[ $key ] ) &&
isset( $_GET[ $nonce_arg ] ) &&
wp_verify_nonce( sanitize_text_field( wp_unslash( ( $_GET[ $nonce_arg ] ) ) ), $nonce_action )
) {
return sanitize_text_field( wp_unslash( ( $_GET[ $key ] ) ) );
}
return null;
}
/**
* Return an array sanitized, unslashed query parameter by its key, validated with a nonce.
*
* @param String $key Key for the query parameter to return.
* @param String $nonce_action Name of the nonce action to verify the given nonce against.
* @param String $nonce_arg Query parmeter the nonce is in.
*/
public static function get_param_array( $key, $nonce_action, $nonce_arg = '_wpnonce' ) {
if (
isset( $_GET[ $key ] ) &&
isset( $_GET[ $nonce_arg ] ) &&
wp_verify_nonce( sanitize_text_field( wp_unslash( ( $_GET[ $nonce_arg ] ) ) ), $nonce_action )
) {
return array_map( 'sanitize_text_field', wp_unslash( $_GET[ $key ] ) );
}
return array();
}
/**
* Return an associative array of query param keys and values given an array of keys
* that are sanitized and validated against a nonce
*
* @param String $keys Array of keys to fetch query parameter values for.
* @param String $nonce_action Name of the nonce action to verify the given nonce against.
* @param String $nonce_arg Query parmeter the nonce is in.
*/
public static function get_parameters( $keys, $nonce_action, $nonce_arg = '_wpnonce' ) {
$query_params = array_reduce(
$keys,
function( $result, $key ) use ( $nonce_arg, $nonce_action ) {
$query_param = QueryParameters::get_param( $key, $nonce_action, $nonce_arg );
$result[ $key ] = $query_param;
return $result;
},
array()
);
return $query_params;
}
}

View File

@@ -1,56 +0,0 @@
<?php
namespace Leadin\utils;
/**
* Static class containing methods used on ajax requests handling.
*/
class RequestUtils {
/**
* Send JSON response.
*
* @param Mixed $body response to send as JSON.
* @param Number $code http code to return.
*/
private static function send( $body, $code ) {
wp_send_json( $body, intval( $code ) );
}
/**
* Send JSON response with 200 code.
*
* @param Mixed $body response to send as JSON.
*/
public static function send_json( $body = array() ) {
self::send( $body, 200 );
}
/**
* Send error response with message
*
* @param String $error Message to be sent on te JSON.
* @param Number $code Error code to be sent in the error. Default 400.
*/
public static function send_error_message( $error, $code = 400 ) {
self::send(
array(
'error' => $error,
),
intval( $code )
);
}
/**
* Send JSON response with a message key.
*
* @param String $message Message to be sent on te JSON.
*/
public static function send_message( $message ) {
self::send(
array(
'message' => $message,
),
200
);
}
}

View File

@@ -1,179 +0,0 @@
<?php
namespace Leadin\utils;
use Leadin\data\Filters;
use Leadin\AssetsManager;
/**
* Util Class responsible for rendering shortcodes.
*/
class ShortcodeRenderUtils {
/**
* Render leadin shortcodes output
*
* @param array $shortcode_attrs Shortcode attributes.
*/
public static function render_shortcode( $shortcode_attrs ) {
$parsed_attributes = shortcode_atts( array( 'type' => 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 = Filters::apply_hublet_filters();
AssetsManager::enqueue_forms_script();
return '
<script>
window.hsFormsOnReady = window.hsFormsOnReady || [];
window.hsFormsOnReady.push(()=>{
hbspt.forms.create({
portalId: ' . $portal_id . ',
formId: "' . $id . '",
target: "#hbspt-form-' . $form_div_uuid . '",
region: "' . $hublet . '",
' . Filters::apply_forms_payload_filters() . '
})});
</script>
<div class="hbspt-form" id="hbspt-form-' . $form_div_uuid . '"></div>';
}
/**
* 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 '
<!--HubSpot Call-to-Action Code -->
<span class="hs-cta-wrapper" id="hs-cta-wrapper-' . $id . '">
<span class="hs-cta-node hs-cta-' . $id . '" id="' . $id . '">
<!--[if lte IE 8]>
<div id="hs-cta-ie-element"></div>
<![endif]-->
<a href="https://cta-redirect.hubspot.com/cta/redirect/' . $portal_id . '/' . $id . '" >
<img class="hs-cta-img" id="hs-cta-img-' . $id . '" style="border-width:0px;" src="https://no-cache.hubspot.com/cta/default/' . $portal_id . '/' . $id . '.png" alt="New call-to-action"/>
</a>
</span>
<' . 'script charset="utf-8" src="//js.hubspot.com/cta/current.js"></script>
<script>
hbspt.cta.load(' . $portal_id . ', \'' . $id . '\', {});
</script>
</span>
<!-- end HubSpot Call-to-Action Code -->
';
}
/**
* Render meeting leadin shortcodes
*
* @param array $attrs Shortcode attributes.
*/
private static function render_meeting( $attrs ) {
$parsed_attributes = shortcode_atts(
array(
'url' => null,
),
$attrs
);
$url = esc_url_raw( $parsed_attributes['url'] );
if ( filter_var( $url, FILTER_VALIDATE_URL ) === false ) {
return;
}
AssetsManager::enqueue_meetings_script();
return '
<div class="meetings-iframe-container" data-src="' . $url . '?embed=true"></div>
<script>
if(window.hbspt && window.hbspt.meetings){
window.hbspt.meetings.create(".meetings-iframe-container");
}
</script>
';
}
/**
* 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;
}
}

View File

@@ -1,62 +0,0 @@
<?php
namespace Leadin\utils;
/**
* Static class containing all the utility functions related to versioning.
*/
class Versions {
/**
* Return the given version until the patch version
* eg: 6.4.2.1-beta => 6.4.2
*
* @param String $version version.
*/
private static function parse_version( $version ) {
preg_match( '/^\d+(\.\d+){0,2}/', $version, $match );
if ( empty( $match ) ) {
return '';
}
return $match[0];
}
/**
* Return the current WordPress version.
*/
public static function get_wp_version() {
global $wp_version;
return self::parse_version( $wp_version );
}
/**
* Return the current PHP version.
*/
public static function get_php_version() {
return self::parse_version( phpversion() );
}
/**
* Return true if the current PHP version is not supported.
*/
public static function is_php_version_not_supported() {
return version_compare( phpversion(), LEADIN_REQUIRED_PHP_VERSION, '<' );
}
/**
* Return true if the current WordPress version is not supported.
*/
public static function is_wp_version_not_supported() {
global $wp_version;
return version_compare( $wp_version, LEADIN_REQUIRED_WP_VERSION, '<' );
}
/**
* Return true if a given version is less than the supported version
*
* @param String $version Given version to check.
* @param String $version_to_compare The version number to test the given version against.
*/
public static function is_version_less_than( $version, $version_to_compare ) {
return version_compare( $version, $version_to_compare, '<' );
}
}