';
}
}
public static function maybe_get_scroll_js( $id ) {
$offset = apply_filters( 'frm_scroll_offset', 4, array( 'form_id' => $id ) );
if ( $offset != - 1 ) {
self::get_scroll_js( $id );
}
}
public static function get_scroll_js( $form_id ) {
echo '';
}
/**
* @since 3.0
*/
public static function actions_dropdown( $atts ) {
if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
$status = $atts['status'];
$form_id = isset( $atts['id'] ) ? $atts['id'] : FrmAppHelper::get_param( 'id', 0, 'get', 'absint' );
$trash_link = self::delete_trash_info( $form_id, $status );
$links = self::get_action_links( $form_id, $status );
include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/actions-dropdown.php' );
}
}
/**
* @since 3.0
*/
public static function get_action_links( $form_id, $form ) {
if ( ! is_object( $form ) ) {
$form = FrmForm::getOne( $form_id );
}
$actions = array();
$trash_links = self::delete_trash_links( $form_id );
if ( 'trash' == $form->status ) {
$actions['restore'] = $trash_links['restore'];
if ( current_user_can( 'frm_delete_forms' ) ) {
$actions['trash'] = $trash_links['delete'];
}
} elseif ( current_user_can( 'frm_edit_forms' ) ) {
$duplicate_link = '?page=formidable&frm_action=duplicate&id=' . $form_id;
if ( $form->is_template ) {
$actions['frm_duplicate'] = array(
'url' => wp_nonce_url( $duplicate_link ),
'label' => __( 'Create Form from Template', 'formidable' ),
'icon' => 'frm_icon_font frm_clone_icon',
);
} else {
$actions['duplicate'] = array(
'url' => wp_nonce_url( $duplicate_link ),
'label' => __( 'Duplicate Form', 'formidable' ),
'icon' => 'frm_icon_font frm_clone_icon',
);
}
$actions['trash'] = self::delete_trash_info( $form_id, $form->status );
}
return $actions;
}
public static function edit_form_link( $form_id ) {
if ( is_object( $form_id ) ) {
$form = $form_id;
$name = $form->name;
$form_id = $form->id;
} else {
$name = FrmForm::getName( $form_id );
}
if ( $form_id ) {
$val = '' . ( '' == $name ? __( '(no title)', 'formidable' ) : FrmAppHelper::truncate( $name, 40 ) ) . '';
} else {
$val = '';
}
return $val;
}
public static function delete_trash_link( $id, $status, $length = 'label' ) {
$link_details = self::delete_trash_info( $id, $status );
return self::format_link_html( $link_details, $length );
}
/**
* @since 3.0
*/
public static function format_link_html( $link_details, $length = 'label' ) {
$link = '';
if ( ! empty( $link_details ) ) {
$link = ' $value ) {
$link .= ' data-' . esc_attr( $data ) . '="' . esc_attr( $value ) . '"';
}
} elseif ( isset( $link_details['confirm'] ) ) {
$link .= ' onclick="return confirm(\'' . esc_attr( $link_details['confirm'] ) . '\')"';
}
$label = ( isset( $link_details[ $length ] ) ? $link_details[ $length ] : $link_details['label'] );
if ( $length == 'icon' && isset( $link_details[ $length ] ) ) {
$label = '';
$link .= ' aria-label="' . esc_attr( $link_details['label'] ) . '"';
}
$link .= '>' . $label . '';
}
return $link;
}
/**
* @since 3.0
*/
public static function delete_trash_info( $id, $status ) {
$labels = self::delete_trash_links( $id );
if ( 'trash' == $status ) {
$info = $labels['restore'];
} elseif ( current_user_can( 'frm_delete_forms' ) ) {
if ( EMPTY_TRASH_DAYS ) {
$info = $labels['trash'];
} else {
$info = $labels['delete'];
}
} else {
$info = array();
}
return $info;
}
/**
* @since 3.0
*/
private static function delete_trash_links( $id ) {
$current_page = FrmAppHelper::get_simple_request( array( 'param' => 'form_type' ) );
$base_url = '?page=formidable&form_type=' . $current_page . '&id=' . $id;
return array(
'restore' => array(
'label' => __( 'Restore from Trash', 'formidable' ),
'short' => __( 'Restore', 'formidable' ),
'url' => wp_nonce_url( $base_url . '&frm_action=untrash', 'untrash_form_' . absint( $id ) ),
),
'trash' => array(
'label' => __( 'Move Form to Trash', 'formidable' ),
'short' => __( 'Trash', 'formidable' ),
'url' => wp_nonce_url( $base_url . '&frm_action=trash', 'trash_form_' . absint( $id ) ),
'icon' => 'frm_icon_font frm_delete_icon',
'data' => array( 'frmverify' => __( 'Do you want to move this form to the trash?', 'formidable' ) ),
),
'delete' => array(
'label' => __( 'Delete Permanently', 'formidable' ),
'short' => __( 'Delete', 'formidable' ),
'url' => wp_nonce_url( $base_url . '&frm_action=destroy', 'destroy_form_' . absint( $id ) ),
'confirm' => __( 'Are you sure you want to delete this form and all its entries?', 'formidable' ),
'icon' => 'frm_icon_font frm_delete_icon',
'data' => array( 'frmverify' => __( 'This will permanently delete the form and all its entries. This is irreversible. Are you sure you want to continue?', 'formidable' ) ),
),
);
}
/**
* @since 3.0
*/
public static function css_classes() {
$classes = array(
'frm_total' => array(
'label' => __( 'Total', 'formidable' ),
'title' => __( 'Add this to a read-only field to display the text in bold without a border or background.', 'formidable' ),
),
'frm_total_big' => array(
'label' => __( 'Big Total', 'formidable' ),
'title' => __( 'Add this to a read-only field to display the text in large, bold text without a border or background.', 'formidable' ),
),
'frm_scroll_box' => array(
'label' => __( 'Scroll Box', 'formidable' ),
'title' => __( 'If you have many checkbox or radio button options, you may add this class to allow your user to easily scroll through the options. Or add a scrolling area around content in an HTML field.', 'formidable' ),
),
'frm_first' => array(
'label' => __( 'First', 'formidable' ),
'title' => __( 'Add this to the first field in each row along with a width. ie frm_first frm4', 'formidable' ),
),
'frm_alignright' => __( 'Right', 'formidable' ),
'frm_grid_first' => __( 'First Grid Row', 'formidable' ),
'frm_grid' => __( 'Even Grid Row', 'formidable' ),
'frm_grid_odd' => __( 'Odd Grid Row', 'formidable' ),
'frm_color_block' => array(
'label' => __( 'Color Block', 'formidable' ),
'title' => __( 'Add a background color to the field or section.', 'formidable' ),
),
'frm_capitalize' => array(
'label' => __( 'Capitalize', 'formidable' ),
'title' => __( 'Automatically capitalize the first letter in each word.', 'formidable' ),
),
);
return apply_filters( 'frm_layout_classes', $classes );
}
public static function grid_classes() {
$base = array(
'frm_half' => '1/2',
'frm_third' => '1/3',
'frm_two_thirds' => '2/3',
'frm_fourth' => '1/4',
'frm_three_fourths' => '3/4',
);
$frm_settings = FrmAppHelper::get_settings();
if ( $frm_settings->old_css ) {
$classes = array(
'frm_sixth' => '1/6',
'frm10' => '5/6',
'frm_full' => '100%',
);
} else {
$classes = array(
'frm_sixth' => '1/6',
'frm10' => '5/6',
'frm12' => '100%',
);
}
return array_merge( $base, $classes );
}
/**
* @since 3.0
*/
public static function style_class_label( $style, $class ) {
$label = '';
if ( empty( $style ) ) {
$label = $class;
} elseif ( ! is_array( $style ) ) {
$label = $style;
} elseif ( isset( $style['label'] ) ) {
$label = $style['label'];
}
return $label;
}
public static function status_nice_name( $status ) {
$nice_names = array(
'draft' => __( 'Draft', 'formidable' ),
'trash' => __( 'Trash', 'formidable' ),
'publish' => __( 'Published', 'formidable' ),
);
if ( ! in_array( $status, array_keys( $nice_names ) ) ) {
$status = 'publish';
}
$name = $nice_names[ $status ];
return $name;
}
public static function template_icon( $categories ) {
$ignore = self::ignore_template_categories();
$categories = array_diff( $categories, $ignore );
$icons = array(
'WooCommerce' => array( 'woocommerce', 'var(--purple)' ),
'Post' => array( 'wordpress', 'rgb(0,160,210)' ),
'User Registration' => array( 'register', 'var(--pink)' ),
'PayPal' => array( 'paypal' ),
'Stripe' => array( 'credit_card', 'var(--green)' ),
'Twilio' => array( 'sms', 'rgb(0,160,210)' ),
'Calculator' => array( 'calculator', 'var(--orange)' ),
'Contact Form' => array( 'address_card' ),
'Survey' => array( 'align_right', 'var(--pink)' ),
'Application Form' => array( 'align_right', 'rgb(0,160,210)' ),
'' => array( 'align_right' ),
);
$icon = $icons[''];
if ( count( $categories ) === 1 ) {
$category = reset( $categories );
$icon = isset( $icons[ $category ] ) ? $icons[ $category ] : $icon;
} elseif ( ! empty( $categories ) ) {
foreach ( $icons as $cat => $icon ) {
if ( ! in_array( $cat, $categories ) ) {
unset( $icons[ $cat ] );
}
}
$icon = reset( $icons );
}
echo '';
FrmAppHelper::icon_by_class( 'frmfont frm_' . $icon[0] . '_icon' );
echo '';
FrmAppHelper::icon_by_class( 'frmfont frm_lock_icon' );
echo '';
echo '';
}
/**
* @since 4.03.01
*/
public static function ignore_template_categories() {
return array( 'Business', 'Elite', 'Personal', 'Creator', 'Basic', 'free' );
}
/**
* @since 4.02
*/
public static function get_template_install_link( $template, $args ) {
$defaults = array(
'class' => 'install-now',
'href' => 'href',
'atts' => true,
);
if ( isset( $template['url'] ) && ! empty( $template['url'] ) ) {
$link = array(
'url' => $template['url'],
'label' => __( 'Create Form', 'formidable' ),
'class' => 'frm-install-template',
'href' => 'rel',
'atts' => '',
);
} elseif ( self::plan_is_allowed( $args ) ) {
$link = array(
'url' => FrmAppHelper::admin_upgrade_link( 'addons', 'account/downloads/' ) . '&utm_content=' . $template['slug'],
'label' => __( 'Renew', 'formidable' ),
);
} else {
$link = array(
'url' => $args['pricing'],
'label' => __( 'Upgrade', 'formidable' ),
);
}
return array_merge( $defaults, $link );
}
/**
* Is the template included with the license type?
*
* @since 4.02.02
*
* @param array $args
*
* @return bool
*/
private static function plan_is_allowed( $args ) {
if ( empty( $args['license_type'] ) ) {
return false;
}
$included = $args['license_type'] === strtolower( $args['plan_required'] );
$plans = array( 'free', 'personal', 'business', 'elite' );
if ( $included || ! in_array( strtolower( $args['plan_required'] ), $plans ) ) {
return $included;
}
foreach ( $plans as $plan ) {
if ( $included || $plan === $args['license_type'] ) {
break;
}
$included = $plan === strtolower( $args['plan_required'] );
}
return $included;
}
/**
* @since 4.02
*/
public static function template_install_html( $link, $class = '' ) {
$link['class'] .= ' ' . $class;
echo '';
}
/**
* If a template or add-on cannot be installed, show a message
* about which plan is required.
*
* @since 4.0
*/
public static function show_plan_required( $requires, $link ) {
if ( empty( $requires ) ) {
return;
}
?>
$category ) {
if ( in_array( $category, $plans ) ) {
unset( $item['categories'][ $k ] );
if ( $category === 'Personal' ) {
// Show the current package name.
$category = 'Basic';
}
return $category;
}
}
return false;
}
/**
* Checks for warnings to be displayed after form settings are saved.
*
* @since 4.04
*
* @param array $values The $_POST array, which contains values submitted in a form.
*
* @return array An array of warnings or an empty array.
*/
public static function check_for_warnings( $values ) {
$warnings = array();
$redirect_warning = self::check_redirect_url_for_unsafe_params( $values );
if ( $redirect_warning ) {
$warnings[] = $redirect_warning;
}
return apply_filters( 'frm_check_for_warnings', $warnings, $values );
}
/**
* Checks the redirect URL for params whose names are reserved words.
*
* @since 4.04
*
* @param array $values The $_POST array, which contains the values submitted in a form.
*
* @return bool|string A warning message about unsafe params or false.
*/
private static function check_redirect_url_for_unsafe_params( $values ) {
if ( ! isset( $values['options'] ) ) {
return false;
}
$options = $values['options'];
FrmAppHelper::sanitize_with_html( $options );
if ( ( ! isset( $options['success_action'] ) ) || $options['success_action'] !== 'redirect' || ! isset( $options['success_url'] ) ) {
return false;
}
$unsafe_params_in_redirect = self::get_unsafe_params( $options['success_url'] );
return self::create_unsafe_param_warning( $unsafe_params_in_redirect );
}
/**
* Returns an array of params whose names are reserved words in the specified URL.
*
* @since 4.04
*
* @param string $url The URL whose params are being checked.
*
* @return array An array of params whose names are reserved words or an empty array.
*/
private static function get_unsafe_params( $url ) {
$redirect_components = parse_url( $url );
if ( empty( $redirect_components['query'] ) ) {
return array();
}
parse_str( $redirect_components['query'], $redirect_params );
$redirect_param_names = array_keys( $redirect_params );
$reserved_words = self::reserved_words();
$unsafe_params_in_redirect = array_intersect( $redirect_param_names, $reserved_words );
return array_values( $unsafe_params_in_redirect );
}
/**
* Returns a warning if reserved words have been used as param names in the redirect URL.
*
* @since 4.04
*
* @param array $unsafe_params_in_redirect Array of params from the redirect URL whose names are reserved words.
*
* @return bool|string A string with an unsafe param message or false.
*/
private static function create_unsafe_param_warning( $unsafe_params_in_redirect ) {
$count = count( $unsafe_params_in_redirect );
$caution = esc_html__( 'Is this intentional?', 'formidable' );
$reserved_words_intro = esc_html__( 'See the list of reserved words in WordPress.', 'formidable' );
$reserved_words_link = ' ' . $reserved_words_intro . '';
if ( $count === 0 ) {
return false;
}
if ( $count == 1 ) {
/* translators: %s: the name of a single parameter in the redirect URL */
return sprintf( esc_html__( 'The redirect URL is using the parameter "%s", which is reserved by WordPress. ', 'formidable' ), $unsafe_params_in_redirect[0] ) . $caution . $reserved_words_link;
}
$unsafe_params_string = implode( '", "', $unsafe_params_in_redirect );
/* translators: %s: the names of two or more parameters in the redirect URL, separated by commas */
return sprintf( esc_html__( 'The redirect URL is using the parameters "%s", which are reserved by WordPress. ', 'formidable' ), $unsafe_params_string ) . $caution . $reserved_words_link;
}
/**
* Returns an array of common reserved words in WordPress.
*
* An edited list of reserved terms from the Codex.
* https://codex.wordpress.org/Reserved_Terms
*
* @since 4.04
*
* @return array Array of WordPress reserved words.
*/
public static function reserved_words() {
return array(
'id',
'attachment',
'author',
'author_name',
'calendar',
'cat',
'category',
'category_name',
'cpage',
'custom',
'day',
'date',
'error',
'feed',
'hour',
'm',
'minute',
'more',
'name',
'order',
'p',
'page',
'page_id',
'paged',
'pb',
'post',
'posts',
'preview',
's',
'search',
'second',
'sentence',
'tag',
'taxonomy',
'tb',
'term',
'terms',
'theme',
'title',
'type',
'w',
'year',
);
}
}