| Server IP : 52.25.153.185 / Your IP : 216.73.217.131 Web Server : Apache System : Linux ip-172-26-6-158 5.10.0-35-cloud-amd64 #1 SMP Debian 5.10.237-1 (2025-05-19) x86_64 User : daemon ( 1) PHP Version : 8.1.10 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /bitnami/wordpress/wp-content/plugins/testify/includes/integrations/ |
Upload File : |
<?php
/**
* This file includes code based on and/or copied from WordPress
* See license.txt for copyright and licensing details
*
* This file modified by Jonathan Hall, Dominika Rauk and/or others; last modified 2020-08-28
*
*/
class FormidableIntegration
{
public static function init()
{
add_filter('frm_available_fields', array('FormidableIntegration', 'display_testify_field'));
add_filter('frm_before_field_created', array('FormidableIntegration', 'before_field_created'));
add_filter('frm_setup_edit_field_vars', array('FormidableIntegration', 'setup_edit_field_vars'));
add_action('frm_display_added_author_field', array('FormidableIntegration', 'add_author_field'));
add_action('frm_display_added_testimonial_field', array('FormidableIntegration', 'add_testimonial_field'));
add_action('frm_display_added_author_email_field', array('FormidableIntegration', 'add_author_email_field'));
add_action('frm_display_added_testimonial_category_field', array('FormidableIntegration', 'add_testimonial_category_field'));
add_action('frm_display_added_testimonial_attachment_field', array('FormidableIntegration', 'add_photo_field'));
add_action('frm_display_added_testimonial_tags_field', array('FormidableIntegration', 'add_testimonial_tags_field'));
add_action('frm_form_field_author', array('FormidableIntegration', 'display_author_field'), 999,2);
add_action('frm_form_field_testimonial', array('FormidableIntegration', 'display_testimonial_field'), 999,2);
add_action('frm_form_field_author_email', array('FormidableIntegration', 'display_author_email_field'), 999,2);
add_action('frm_form_field_testimonial_category', array('FormidableIntegration', 'display_testimonial_category_field'), 999,2);
add_action('frm_form_field_testimonial_tags', array('FormidableIntegration', 'display_testimonial_tags_field'), 999,2);
add_action('frm_form_field_testimonial_attachment', array('FormidableIntegration', 'display_testimonial_attachment_field'), 999,2);
add_action('frm_process_entry', array('FormidableIntegration', 'process_testimony'), 999, 3);
add_action('frm_testify_testimonial_field_options_form', array('FormidableIntegration', 'testimonial_field_options_display'));
add_filter('frm_update_field_options', array('FormidableIntegration', 'testimonial_field_options_update'), 10, 3);
}
public static function display_testify_field($fields)
{
$fields['testify_author'] = __('Testimonial Name', 'testify-testify');
$fields['testify_author_email'] = __('Testimonial Email', 'testify-testify');
$fields['testify_photo'] = __('Testimonial Photo', 'testify-testify');
$fields['testify_testimonial'] = __('Testimonial', 'testify-testify');
return $fields;
}
public static function display_testimonial_tags_field($field, $field_name)
{
?>
<input type="text" name="<?php echo esc_attr($field_name); ?>" id="testimonial_tags" value="" class="dyn_default_value" />
<?php
}
public static function display_testimonial_category_field($field, $field_name)
{
self::add_testimonial_category_field($field, $field_name);
}
public static function display_testimonial_attachment_field($field, $field_name)
{
self::add_photo_field($field, $field_name);
}
public static function display_author_field($field, $field_name)
{
?>
<input type="text" name="<?php echo esc_attr($field_name); ?>" id="author_name" value="" class="dyn_default_value" />
<?php
}
public static function display_author_email_field($field, $field_name)
{
?>
<input type="text" name="<?php echo esc_attr($field_name); ?>" id="author_name" value="" class="dyn_default_value" />
<?php
}
public static function add_photo_field($field, $field_name)
{
$html_id = 'testify_photo';
$file_name = 'file'.$field['id'];
?>
<input type="file" name="<?php echo esc_attr( $file_name ); ?>" id="<?php echo esc_attr( $html_id ) ?>" <?php do_action( 'frm_field_input_html', $field ) ?> /><br/>
<input type="hidden" name="<?php echo esc_attr( $field_name ); ?>" value="<?php echo esc_attr( is_array($field['value']) ? reset( $field['value'] ) : $field['value'] ) ?>" />
<?php
}
public static function add_author_field($field)
{
?>
<input type="text" name="author_name" id="author_name" value="" class="dyn_default_value" />
<?php
}
public static function add_author_email_field($field)
{
?>
<input type="text" name="author_email" id="author_email" value="" class="dyn_default_value" />
<?php
}
public static function add_testimonial_field($field)
{
?>
<textarea name="testimonial" rows="<?php echo esc_attr( $field['max'] ); ?>" id="testimonial" class="dyn_default_value"><?php
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- this is escaped with Formidable's escaping function
echo FrmAppHelper::esc_textarea(force_balance_tags($field['default_value']));
?></textarea>
<?php
}
public static function add_testimonial_tags_field($field)
{
?>
<input type="text" name="testimonial_tag" id="testimonial_tag" value="" class="dyn_default_value" />
<?php
}
public static function add_testimonial_category_field($field, $field_name)
{
$choices = array();
$terms = get_terms( array(
'taxonomy' => 'testify-cat',
'hide_empty' => false,
) );
$field['options'] = array();
foreach($terms as $term)
{
$field['options'][] = $term->name;
}
$checked_values = $field['value'];
$read_only = false;
//$field_name = 'testify_category';
$html_id = 'testify_category';
if ( $field['options'] ) {
foreach ( $field['options'] as $opt_key => $opt ) {
if ( isset($atts) && isset($atts['opt']) && ($atts['opt'] !== $opt_key) ) {
continue;
}
$field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field);
$opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field);
$checked = FrmAppHelper::check_selected($checked_values, $field_val) ? ' checked="checked"' : '';
// Check if other opt, and get values for other field if needed
$other_opt = false;
$other_args = FrmFieldsHelper::prepare_other_input( compact( 'field', 'field_name', 'opt_key' ), $other_opt, $checked );
?>
<div class="<?php echo esc_attr( apply_filters( 'frm_checkbox_class', 'frm_checkbox', $field, $field_val ) ) ?>" id="<?php echo esc_attr( FrmFieldsHelper::get_checkbox_id( $field, $opt_key ) ) ?>"><?php
if ( ! isset( $atts ) || ! isset( $atts['label'] ) || $atts['label'] ) {
?><label for="<?php echo esc_attr( $html_id ) ?>-<?php echo esc_attr( $opt_key ) ?>"><?php
}
?><input type="checkbox"
name="<?php echo esc_attr( $field_name ); ?>[<?php if ( $other_opt ) echo ( esc_attr( $opt_key ) ); ?>]"
id="<?php echo esc_attr( $html_id ) ?>-<?php echo esc_attr( $opt_key ) ?>"
value="<?php echo esc_attr( $field_val ) ?>"
<?php echo $checked; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- set to one of two fixed HTML-safe strings above ?>
<?php do_action('frm_field_input_html', $field) ?>
/><?php
if ( ! isset( $atts ) || ! isset( $atts['label'] ) || $atts['label'] ) {
echo ' ' . esc_html($opt) . '</label>';
}
FrmFieldsHelper::include_other_input( array(
'other_opt' => $other_opt, 'read_only' => $read_only,
'checked' => $checked, 'name' => $other_args['name'],
'value' => $other_args['value'], 'field' => $field,
'html_id' => $html_id, 'opt_key' => $opt_key,
) );
unset( $other_opt, $other_args, $checked );
?></div>
<?php
}
}
}
public static function display_testimonial_field($field, $field_name)
{
?>
<textarea name="<?php echo esc_attr( $field_name ); ?>" rows="<?php echo esc_attr( $field['max'] ); ?>" id="testimonial" class="dyn_default_value"><?php
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- this is escaped with Formidable's escaping function
echo FrmAppHelper::esc_textarea(force_balance_tags($field['default_value']));
?></textarea>
<?php
}
public static function setup_edit_field_vars($fields)
{
return $fields;
}
public static function before_field_created($values)
{
$type = $values['type'];
if ( $type == 'testimonial_category' )
{
$values['options'] = serialize( array(
__( 'Option 1', 'formidable' ),
__( 'Option 2', 'formidable' ),
) );
}
return $values;
}
public static function process_testimony($params, $errors, $form)
{
// phpcs:disable WordPress.Security.NonceVerification -- nonce functionality would be up to Formidable
$form_id = $form->id;
$fields = FrmField::get_all_for_form( $form_id );
$testi = array('testify_author' => '',
'testify_author_email' => '',
'testify_testimonial' => '',
'testimonial_category' => array(),
'testify_photo' => '',
'testimonial_tags' => ''
);
foreach($fields as $field)
{
if ($field->type == 'testify_photo')
{
$testi[$field->type] = $field->id;
}
else
{
// phpcs:ignore ET.Sniffs.ValidatedSanitizedInput.InputNotSanitized -- will be sanitized as needed immediately following this foreach block
$testi[$field->type] = isset($_POST['item_meta'][$field->id]) ? $_POST['item_meta'][$field->id] : '';
}
}
$author = isset($testi['testify_author']) ? sanitize_text_field($testi['testify_author']) : '';
$content = isset($testi['testify_testimonial']) ? sanitize_textarea_field($testi['testify_testimonial']) : '';
$email = isset($testi['testify_author_email']) ? sanitize_email($testi['testify_author_email']) : '';
$tags = isset($testi['testimonial_tags']) ? $testi['testimonial_tags'] : ''; // to be processed by wp_set_post_terms below
$cats = isset($testi['testimonial_category']) ? $testi['testimonial_category'] : ''; // used for term lookup below
$testimonialId = wp_insert_post(array(
'post_title' => $author,
'post_type' => 'testify-testimonial',
'post_status' => 'pending',
'post_content' => $content,
));
if (!empty($testimonialId))
{
update_post_meta($testimonialId, 'testimonial-author', $author);
update_post_meta($testimonialId, 'testimonial-submit-time', current_time('timestamp'));
update_post_meta($testimonialId, 'testimonial-submit-email', $email);
if (!empty($_SERVER['REMOTE_ADDR'])) {
update_post_meta($testimonialId, 'testimonial-submit-ip', sanitize_text_field($_SERVER['REMOTE_ADDR']) );
}
$categories = array();
foreach ($cats as $value)
{
$term = get_term_by('name', $value, 'testify-cat');
if ($term && $term->term_id > 0)
{
$categories[] = $term->term_id;
}
}
if (!empty($categories))
{
wp_set_post_terms($testimonialId, $categories, 'testify-cat', true);
}
if (!empty($tags))
{
wp_set_post_terms($testimonialId, $tags, 'testify-tag', true);
}
if ( isset( $_FILES['file'.$testi['testify_photo']]['name'] ) )
{
$file_type_pattern = 'jpg|jpeg|png|gif|pdf|doc|docx|ppt|pptx|odt|avi|ogg|m4a|mov|mp3|mp4|mpg|wav|wmv';
$file_type_pattern = trim( $file_type_pattern, '|' );
$file_type_pattern = '(' . $file_type_pattern . ')';
$file_type_pattern = '/\.' . $file_type_pattern . '$/i';
// phpcs:ignore ET.Sniffs.ValidatedSanitizedInput.InputNotSanitized -- uploaded file name is only being used to check extension
if ( preg_match( $file_type_pattern, $_FILES['file'.$testi['testify_photo']]['name'] ) )
{
require_once(ABSPATH . "wp-admin/includes/image.php");
require_once(ABSPATH . "wp-admin/includes/media.php");
require_once(ABSPATH . "wp-admin/includes/file.php");
$attachmentId = media_handle_upload('file'.$testi['testify_photo'], $testimonialId);
update_post_meta($testimonialId, '_thumbnail_id', $attachmentId);
}
}
}
return true;
// phpcs:enable WordPress.Security.NonceVerification -- nonce functionality would be up to Formidable
}
public static function testimonial_field_options_display($field) {
// Following code copied from Testify Caldera Forms integration and modified
$categories = array();
$categoryNames = array();
foreach (get_terms(array('taxonomy' => 'testify-cat', 'hide_empty' => false)) as $cat) {
if (isset($categories[$cat->parent])) {
$categories[$cat->parent][] = $cat->term_id;
} else {
$categories[$cat->parent] = array($cat->term_id);
}
$categoryNames[$cat->term_id] = $cat->name;
}
// End code copied from Testify Caldera Forms integration and modified
?>
<tr>
<td>
<label><?php esc_html_e('Testimonial Categories:', 'testify-testify'); ?></label>
</td>
<td>
<?php
if (empty($categories)) {
esc_html_e('You have not created any testimonial categories.', 'testify-testify');
} else {
self::getCategoriesCheckboxes('field_options[testify-cats_'.$field['id'].'][]', $categories, $categoryNames);
}
?>
</td>
</tr>
<tr>
<td>
<label><?php esc_html_e('Testimonial Tags:', 'testify-testify'); ?></label>
</td>
<td>
<input type="text" name="field_options[testify-tags_<?php echo esc_html(($field['id'])); ?>]" class="frm_long_input">
</td>
</tr>
<?php
}
public static function testimonial_field_options_update($options, $field, $values) {
if ($field->type != 'testify_testimonial') {
return;
}
if (empty($values['field_options']['testify-cats_'.$field->id])) {
unset($options['testify-cats']);
} else {
// TODO: process category IDs
}
return $options;
}
// Following function copied from Testify Caldera Forms integration and modified
private static function getCategoriesCheckboxes($fieldName, $categories, $categoryNames, $i=0) {
foreach ($categories[$i] as $categoryId) {
echo('<div class="testify-formidable-category">
<label>
<input type="checkbox" name="'.esc_attr($fieldName).'" value="'.esc_attr($categoryId).'">
'.esc_html($categoryNames[$categoryId]).'
</label>
');
if (isset($categories[$categoryId])) {
self::getCategoriesCheckboxes($categories, $categoryNames, $categoryId);
}
echo('</div>');
}
}
}