PluginProbe ʕ •ᴥ•ʔ
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI / trunk
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI vtrunk
3.5.1 3.5.0 3.4.8 3.4.7 3.4.6 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.5.1 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.10 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.6.1 1.6.7 1.7.0 1.7.0.1 1.7.0.2 1.7.0.3 1.7.1 1.7.2 1.7.2.1 1.7.2.2 1.7.3 1.7.4 1.7.5 1.7.5.1 1.7.5.2 1.7.6 1.7.7 1.7.7.1 1.7.7.2 1.7.8 1.7.9 1.8.0 1.8.0.1 1.8.1 1.8.2 1.8.2.1 1.8.2.2 1.8.2.3 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.0.1 1.9.1 1.9.2 1.9.3 1.9.4 1.9.4.1 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.0.1 2.0.1 2.0.2 2.0.3 2.0.3.1 2.0.4 2.0.4.1 2.0.5 2.0.6 2.0.7 2.0.8 2.0.8.1 2.0.9 3.0.0 3.0.0.1 3.0.1 3.0.2 3.0.3 3.0.3.1 3.0.4 3.0.4.1 3.0.4.2 3.0.5 3.0.5.1 3.0.5.2 3.0.6 3.0.6.1 3.0.7.1 3.0.8 3.0.8.1 3.0.9 3.0.9.1 3.0.9.2 3.0.9.3 3.0.9.4 3.0.9.5 3.1.0 3.1.1 3.1.2 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.3.0 3.4.0 3.4.1 3.4.2 3.4.2.1 3.4.3 3.4.4 3.4.5 trunk 1.0 1.0.1 1.0.2 1.0.3
everest-forms / includes / Helpers / FormHelper.php
everest-forms / includes / Helpers Last commit date
FormHelper.php 11 months ago
FormHelper.php
172 lines
1 <?php
2
3 /**
4 * Core function for the plugin.
5 *
6 * @package EverestForms\Helpers
7 * @since 3.2.0
8 */
9
10 namespace EverestForms\Helpers;
11
12 /**
13 * FormHelper.
14 *
15 * @since 3.2.0
16 */
17 class FormHelper
18 {
19 /**
20 * Get all the form category list.
21 *
22 * @since 3.2.0
23 * @param string $key The key.
24 */
25 public static function get_all_form_tags($key = 'slug')
26 {
27 $form_tags = get_terms(
28 array(
29 'taxonomy' => \EVF_Post_Types::TAGS_TAXONOMY,
30 'hide_empty' => false,
31 )
32 );
33
34 $form_tags = is_wp_error($form_tags) ? array() : (array) $form_tags;
35 $tags_options = wp_list_pluck($form_tags, 'name', $key);
36
37 return $tags_options;
38 }
39
40 /**
41 * Particular form tags.
42 *
43 * @since 3.2.0
44 * @param [type] $form_id The form id.
45 * @param string $key The option key type.
46 */
47 public static function get_form_tags($form_id, $key = 'term_id')
48 {
49 $form_tags = wp_get_post_terms(
50 $form_id,
51 \EVF_Post_Types::TAGS_TAXONOMY,
52 true
53 );
54
55 $form_tags = is_wp_error($form_tags) ? array() : (array) $form_tags;
56 $tags_options = wp_list_pluck($form_tags, 'name', $key);
57
58 return $tags_options;
59 }
60
61 /**
62 * Get all the form tags based on the forms.
63 *
64 * @param [type] $form_ids The form list.
65 */
66 public static function get_selected_forms_tags($form_ids)
67 {
68 $all_tags = array();
69 foreach ($form_ids as $form_id) {
70
71 $tags = self::get_form_tags($form_id);
72 $all_tags = $all_tags + $tags;
73 }
74
75 return $all_tags;
76 }
77
78 /**
79 * Save CleanTalk settings.
80 *
81 * @since 3.3.0
82 *
83 * @param string $access_key The access key.
84 * @return bool
85 */
86 public static function evf_save_clean_talk_settings($access_key)
87 {
88 $clean_talk_request = array(
89 'method_name' => 'notice_paid_till',
90 'auth_key' => sanitize_text_field($access_key),
91 );
92
93 $response = wp_remote_post(
94 'https://api.cleantalk.org/',
95 array(
96 'body' => \http_build_query($clean_talk_request, true),
97 'headers' => array(
98 'Content-Type' => 'application/x-www-form-urlencoded',
99 ),
100 )
101 );
102 $response = json_decode(wp_remote_retrieve_body($response));
103 if ($response->data->moderate == 1 && $response->data->valid == 1 && $response->data->product_id == 1) {
104 update_option('everest_forms_recaptcha_cleantalk_access_key', sanitize_text_field($access_key));
105 return true;
106 } else {
107 return false;
108 }
109 }
110
111 /**
112 * Check the file type.
113 *
114 * @param [type] $ext The extension.
115 */
116 public static function evf_file_upload_check_file_types($ext)
117 {
118 $supportedFileTypes = array(
119 'pdf',
120 'doc',
121 'xls',
122 'ppt',
123 'mp3',
124 'mp4',
125 'zip',
126 );
127 $newMsFileTypes = array('docx', 'xlsx', 'pptx');
128 $imageFileTypes = array('jpg', 'jpeg', 'png', 'gif');
129
130 $fileIcon = null;
131
132 if (in_array($ext, $supportedFileTypes)) {
133 $fileIcon = $ext;
134 } elseif (in_array($ext, $newMsFileTypes)) {
135 $fileIcon = substr($ext, 0, -1);
136 } elseif (! in_array($ext, $imageFileTypes)) {
137 $fileIcon = 'default';
138 }
139
140 return $fileIcon;
141 }
142
143 /**
144 * Remove the file.
145 *
146 * @param [type] $file_url The file url.
147 */
148 public static function remove_file($file_url)
149 {
150 $uploads = wp_upload_dir();
151 $base_dir = realpath($uploads['basedir']);
152 $path_from_url = wp_parse_url($file_url, PHP_URL_PATH);
153
154 $uploaded_file = $uploads['basedir'] . preg_replace(
155 '/.*uploads/',
156 '/everest_forms_uploads',
157 $path_from_url
158 );
159
160 $normalized_path = wp_normalize_path($uploaded_file);
161 $resolved_path = realpath($normalized_path);
162 // Validate path is within allowed directory
163 if ($resolved_path && strpos($resolved_path, $base_dir) === 0) {
164 if (is_file($resolved_path)) {
165 wp_delete_file($resolved_path);
166 }
167 }
168
169 return;
170 }
171 }
172