Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion frontend-dev/src/Utils/StaticData/webhookIntegrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export const customFormIntegrations = [
'Brizy',
'GutenaForms',
'PieForms',
'Asgaros'
'Asgaros',
'AvadaForms'
]

export const actionHookIntegrations = ['ActionHook']
Expand Down
1 change: 1 addition & 0 deletions includes/Core/Util/AllTriggersName.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public static function allTriggersName()
'ARForm' => ['name' => 'ARForm', 'isPro' => true, 'is_active' => false],
'ARMember' => ['name' => 'ARMember', 'isPro' => true, 'is_active' => false],
'Asgaros' => ['name' => 'Asgaros Forum', 'isPro' => true, 'is_active' => false],
'AvadaForms' => ['name' => 'Avada Forms', 'isPro' => true, 'is_active' => false],
'Beaver' => ['name' => 'Beaver', 'isPro' => true, 'is_active' => false],
'BitAssist' => ['name' => 'Bit Assist', 'isPro' => true, 'is_active' => false],
'Breakdance' => ['name' => 'Breakdance', 'isPro' => true, 'is_active' => false],
Expand Down
60 changes: 60 additions & 0 deletions includes/Core/Util/AttachmentHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace BitCode\FI\Core\Util;

class AttachmentHandler
{
public static function fetchAttachmentDetails($attachmentId)
{
$attachmentPost = self::getAttachmentPost($attachmentId);

if (!$attachmentPost) {
return [];
}

return self::formatAttachmentDetails($attachmentPost);
}

/**
* Retrieve the attachment post object.
*
* @param int $attachmentId The attachment post ID.
*
* @return WP_Post|null The attachment post object or null if not found.
*/
private static function getAttachmentPost($attachmentId)
{
return get_post($attachmentId) ?: null;
}

/**
* Format the attachment details into an array.
*
* @param WP_Post $attachmentPost The attachment post object.
*
* @return array The formatted attachment details.
*/
private static function formatAttachmentDetails($attachmentPost)
{
return [
'title' => $attachmentPost->post_title,
'source' => $attachmentPost->guid,
'caption' => $attachmentPost->post_excerpt,
'description' => $attachmentPost->post_content,
'alt_text' => self::getAltText($attachmentPost->ID),
'permalink' => get_permalink($attachmentPost->ID),
];
}

/**
* Retrieve the alt text for the attachment.
*
* @param int $attachmentId The attachment post ID.
*
* @return string The alt text for the attachment.
*/
private static function getAltText($attachmentId)
{
return get_post_meta($attachmentId, '_wp_attachment_image_alt', true) ?: '';
}
}
68 changes: 68 additions & 0 deletions includes/Core/Util/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,10 @@ public static function prepareFetchFormatFields(array $data, $path = '', $format
$currentKey = strtolower(preg_replace(['/[^A-Za-z0-9_]/', '/([A-Z])/'], ['', '_$1'], $key));
$currentPath = $path ? "{$path}_{$currentKey}" : $currentKey;

if (empty($currentPath)) {
continue;
}

if (\is_array($value) || \is_object($value)) {
$formattedData = static::prepareFetchFormatFields((array) $value, $currentPath, $formattedData);
} else {
Expand All @@ -349,6 +353,40 @@ public static function prepareFetchFormatFields(array $data, $path = '', $format
return $formattedData;
}

public static function flattenNestedData($resultArray, $parentKey, $nestedData)
{
if (!(\is_array($nestedData) || \is_object($nestedData))) {
return $resultArray;
}

$nestedData = (array) $nestedData;

foreach ($nestedData as $itemKey => $itemValue) {
$newKey = static::sanitizeKey($parentKey, $itemKey);

if (\is_array($itemValue) || \is_object($itemValue)) {
$resultArray = static::flattenNestedData($resultArray, $newKey, $itemValue);
} else {
$resultArray[$newKey] = static::sanitizeValue($itemValue);
}
}

return $resultArray;
}

public static function decodeHtmlEntities($input)
{
if (\is_array($input)) {
foreach ($input as $index => $item) {
$input[$index] = static::decodeSingleEntity($item);
}

return $input;
}

return static::decodeSingleEntity($input);
}

private static function getVariableType($val)
{
$types = [
Expand All @@ -364,4 +402,34 @@ private static function getVariableType($val)

return $types[\gettype($val)] ?? 'text';
}

private static function decodeSingleEntity($string)
{
return html_entity_decode($string);
}

/**
* Sanitize the key by removing unwanted characters.
*
* @param string $parentKey The parent key to prepend.
* @param string $itemKey The current key.
*
* @return string The sanitized and combined key.
*/
private static function sanitizeKey($parentKey, $itemKey)
{
return $parentKey . '_' . str_replace(['*', \chr(0)], '', $itemKey);
}

/**
* Sanitize the value by trimming spaces and handling empty values.
*
* @param mixed $value The value to sanitize.
*
* @return mixed The sanitized value.
*/
private static function sanitizeValue($value)
{
return $value ? trim($value) : $value;
}
}
32 changes: 24 additions & 8 deletions includes/Core/Util/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,31 @@ public static function get($id)
return [];
}

return static::formattedData($user);
}

public static function currentUser()
{
if (!is_user_logged_in()) {
return [];
}

$current_user = wp_get_current_user();

return static::formattedData($current_user);
}

private static function formattedData(WP_user $user)
{
return [
'wp_user_id' => $user->ID,
'user_login' => $user->user_login,
'display_name' => $user->display_name,
'user_firstname' => $user->user_firstname,
'user_lastname' => $user->user_lastname,
'user_email' => $user->user_email,
'user_registered' => $user->user_registered,
'user_role' => $user->roles,
'wp_user_id' => $user->ID,
'wp_user_login' => $user->user_login,
'wp_display_name' => $user->display_name,
'wp_user_first_name' => $user->user_firstname,
'wp_user_last_name' => $user->user_lastname,
'wp_user_email' => $user->user_email,
'wp_user_registered' => $user->user_registered,
'wp_user_role' => $user->roles,
];
}
}
2 changes: 1 addition & 1 deletion includes/Triggers/BitForm/BitFormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static function handle_bitform_submit($formId, $entryId, $formData)
}
}
if (!empty($formId) && $flows = Flow::exists('BitForm', $formId)) {
Flow::execute('FormBitForminator', $formId, $data, $flows);
Flow::execute('BitForm', $formId, $data, $flows);
}
}
}
Expand Down