| 1 |
<?php // User Submitted Posts - Form helper functions |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) die(); |
| 4 |
|
| 5 |
function usp_display_turnstile() { |
| 6 |
|
| 7 |
global $usp_options; |
| 8 |
|
| 9 |
$site_key = isset($usp_options['turnstile_site_key']) ? $usp_options['turnstile_site_key'] : false; |
| 10 |
$secret = isset($usp_options['turnstile_secret_key']) ? $usp_options['turnstile_secret_key'] : false; |
| 11 |
$display = isset($usp_options['usp_turnstile']) ? $usp_options['usp_turnstile'] : false; |
| 12 |
|
| 13 |
$output = ''; |
| 14 |
|
| 15 |
if (!empty($site_key) && !empty($secret) && $display) { |
| 16 |
|
| 17 |
$output = '<div class="cf-turnstile" data-sitekey="'. esc_attr($site_key) .'"></div>'; |
| 18 |
|
| 19 |
} |
| 20 |
|
| 21 |
return $output; |
| 22 |
|
| 23 |
} |
| 24 |
|
| 25 |
function usp_display_custom_checkbox() { |
| 26 |
|
| 27 |
global $usp_options; |
| 28 |
|
| 29 |
$enable = (isset($usp_options['custom_checkbox']) && !empty($usp_options['custom_checkbox'])) ? true : false; |
| 30 |
|
| 31 |
$required = (isset($usp_options['custom_checkbox_req']) && !empty($usp_options['custom_checkbox_req'])) ? true : false; |
| 32 |
|
| 33 |
$name = isset($usp_options['custom_checkbox_name']) ? $usp_options['custom_checkbox_name'] : null; |
| 34 |
|
| 35 |
$text = isset($usp_options['custom_checkbox_text']) ? $usp_options['custom_checkbox_text'] : ''; |
| 36 |
|
| 37 |
$output = ''; |
| 38 |
|
| 39 |
if ($enable && $name) { |
| 40 |
|
| 41 |
$text = str_replace('script', '', $text); |
| 42 |
$text = str_replace("{", "<", $text); |
| 43 |
$text = str_replace("}", ">", $text); |
| 44 |
|
| 45 |
$required_markup = $required ? ' data-required="true" required' : ''; |
| 46 |
|
| 47 |
$output .= '<fieldset class="usp-checkbox">'; |
| 48 |
$output .= '<input id="user-submitted-checkbox" name="'. esc_attr($name) .'" type="checkbox" value=""'. $required_markup .'> '; |
| 49 |
$output .= '<label for="user-submitted-checkbox">'. wp_kses($text, usp_allowed_post_tags()) .'</label>'; |
| 50 |
$output .= '</fieldset>'; |
| 51 |
|
| 52 |
} |
| 53 |
|
| 54 |
return $output; |
| 55 |
|
| 56 |
} |
| 57 |
|
| 58 |
function usp_allowed_post_tags() { |
| 59 |
|
| 60 |
global $allowedposttags; |
| 61 |
|
| 62 |
$allowed_atts = array( |
| 63 |
|
| 64 |
'align' => array(), |
| 65 |
'class' => array(), |
| 66 |
'type' => array(), |
| 67 |
'id' => array(), |
| 68 |
'dir' => array(), |
| 69 |
'lang' => array(), |
| 70 |
'style' => array(), |
| 71 |
'xml:lang' => array(), |
| 72 |
'src' => array(), |
| 73 |
'alt' => array(), |
| 74 |
'href' => array(), |
| 75 |
'rel' => array(), |
| 76 |
'rev' => array(), |
| 77 |
'target' => array(), |
| 78 |
'novalidate' => array(), |
| 79 |
'type' => array(), |
| 80 |
'value' => array(), |
| 81 |
'name' => array(), |
| 82 |
'tabindex' => array(), |
| 83 |
'action' => array(), |
| 84 |
'method' => array(), |
| 85 |
'for' => array(), |
| 86 |
'width' => array(), |
| 87 |
'height' => array(), |
| 88 |
'data' => array(), |
| 89 |
'title' => array() |
| 90 |
|
| 91 |
); |
| 92 |
|
| 93 |
$allowedposttags['form'] = $allowed_atts; |
| 94 |
$allowedposttags['label'] = $allowed_atts; |
| 95 |
$allowedposttags['input'] = $allowed_atts; |
| 96 |
$allowedposttags['textarea'] = $allowed_atts; |
| 97 |
$allowedposttags['style'] = $allowed_atts; |
| 98 |
$allowedposttags['strong'] = $allowed_atts; |
| 99 |
$allowedposttags['small'] = $allowed_atts; |
| 100 |
$allowedposttags['table'] = $allowed_atts; |
| 101 |
$allowedposttags['span'] = $allowed_atts; |
| 102 |
$allowedposttags['abbr'] = $allowed_atts; |
| 103 |
$allowedposttags['code'] = $allowed_atts; |
| 104 |
$allowedposttags['pre'] = $allowed_atts; |
| 105 |
$allowedposttags['div'] = $allowed_atts; |
| 106 |
$allowedposttags['img'] = $allowed_atts; |
| 107 |
$allowedposttags['h1'] = $allowed_atts; |
| 108 |
$allowedposttags['h2'] = $allowed_atts; |
| 109 |
$allowedposttags['h3'] = $allowed_atts; |
| 110 |
$allowedposttags['h4'] = $allowed_atts; |
| 111 |
$allowedposttags['h5'] = $allowed_atts; |
| 112 |
$allowedposttags['h6'] = $allowed_atts; |
| 113 |
$allowedposttags['ol'] = $allowed_atts; |
| 114 |
$allowedposttags['ul'] = $allowed_atts; |
| 115 |
$allowedposttags['li'] = $allowed_atts; |
| 116 |
$allowedposttags['em'] = $allowed_atts; |
| 117 |
$allowedposttags['hr'] = $allowed_atts; |
| 118 |
$allowedposttags['br'] = $allowed_atts; |
| 119 |
$allowedposttags['tr'] = $allowed_atts; |
| 120 |
$allowedposttags['td'] = $allowed_atts; |
| 121 |
$allowedposttags['p'] = $allowed_atts; |
| 122 |
$allowedposttags['a'] = $allowed_atts; |
| 123 |
$allowedposttags['b'] = $allowed_atts; |
| 124 |
$allowedposttags['i'] = $allowed_atts; |
| 125 |
|
| 126 |
return apply_filters('usp_allowed_post_tags', $allowedposttags); |
| 127 |
|
| 128 |
} |
| 129 |
|
| 130 |
function usp_get_form_vars() { |
| 131 |
|
| 132 |
global $usp_options; |
| 133 |
|
| 134 |
$usp_current_user = wp_get_current_user(); |
| 135 |
$usp_user_name = $usp_current_user->user_login; |
| 136 |
$usp_user_email = $usp_current_user->user_email; |
| 137 |
$usp_user_url = $usp_current_user->user_url; |
| 138 |
|
| 139 |
if ($usp_options['disable_required']) { |
| 140 |
|
| 141 |
$usp_required = ''; |
| 142 |
$usp_captcha = ''; |
| 143 |
|
| 144 |
} else { |
| 145 |
|
| 146 |
$usp_required = ' data-required="true" required'; |
| 147 |
$usp_captcha = ' user-submitted-captcha'; |
| 148 |
|
| 149 |
} |
| 150 |
|
| 151 |
if (isset($usp_options['multiple-cats']) && $usp_options['multiple-cats']) { |
| 152 |
|
| 153 |
$multiple_cats = ' multiple="multiple"'; |
| 154 |
$category_class = ' class="usp-select usp-multiple"'; |
| 155 |
|
| 156 |
} else { |
| 157 |
|
| 158 |
$multiple_cats = ''; |
| 159 |
$category_class = ' class="usp-select"'; |
| 160 |
|
| 161 |
} |
| 162 |
|
| 163 |
$usp_display_name = (is_user_logged_in() && $usp_options['usp_use_author']) ? false : true; |
| 164 |
$usp_display_email = (is_user_logged_in() && $usp_options['usp_use_email']) ? false : true; |
| 165 |
$usp_display_url = (is_user_logged_in() && $usp_options['usp_use_url']) ? false : true; |
| 166 |
|
| 167 |
$usp_existing_tags = (isset($usp_options['usp_existing_tags']) && !empty($usp_options['usp_existing_tags'])) ? true : false; |
| 168 |
|
| 169 |
$usp_recaptcha_public = (isset($usp_options['recaptcha_public']) && !empty($usp_options['recaptcha_public'])) ? true : false; |
| 170 |
$usp_recaptcha_private = (isset($usp_options['recaptcha_private']) && !empty($usp_options['recaptcha_private'])) ? true : false; |
| 171 |
|
| 172 |
$usp_recaptcha_version = isset($usp_options['recaptcha_version']) ? $usp_options['recaptcha_version'] : 2; |
| 173 |
$usp_recaptcha_display = isset($usp_options['usp_recaptcha']) ? $usp_options['usp_recaptcha'] : ''; |
| 174 |
|
| 175 |
$usp_data_sitekey = isset($usp_options['recaptcha_public']) ? $usp_options['recaptcha_public'] : ''; |
| 176 |
|
| 177 |
$usp_turnstile_site_key = isset($usp_options['turnstile_site_key']) ? $usp_options['turnstile_site_key'] : ''; |
| 178 |
$usp_turnstile_secret_key = isset($usp_options['turnstile_secret_key']) ? $usp_options['turnstile_secret_key'] : ''; |
| 179 |
$usp_turnstile_display = isset($usp_options['usp_turnstile']) ? $usp_options['usp_turnstile'] : ''; |
| 180 |
|
| 181 |
$usp_custom_name = isset($usp_options['custom_name']) ? $usp_options['custom_name'] : ''; |
| 182 |
$usp_custom_label = isset($usp_options['custom_label']) ? $usp_options['custom_label'] : ''; |
| 183 |
|
| 184 |
$usp_custom_name_2 = isset($usp_options['custom_name_2']) ? $usp_options['custom_name_2'] : ''; |
| 185 |
$usp_custom_label_2 = isset($usp_options['custom_label_2']) ? $usp_options['custom_label_2'] : ''; |
| 186 |
|
| 187 |
$options = array( |
| 188 |
'usp_user_name' => $usp_user_name, |
| 189 |
'usp_user_email' => $usp_user_email, |
| 190 |
'usp_user_url' => $usp_user_url, |
| 191 |
'usp_required' => $usp_required, |
| 192 |
'usp_captcha' => $usp_captcha, |
| 193 |
'multiple_cats' => $multiple_cats, |
| 194 |
'category_class' => $category_class, |
| 195 |
'usp_display_name' => $usp_display_name, |
| 196 |
'usp_display_email' => $usp_display_email, |
| 197 |
'usp_display_url' => $usp_display_url, |
| 198 |
'usp_existing_tags' => $usp_existing_tags, |
| 199 |
'usp_recaptcha_public' => $usp_recaptcha_public, |
| 200 |
'usp_recaptcha_private' => $usp_recaptcha_private, |
| 201 |
'usp_recaptcha_version' => $usp_recaptcha_version, |
| 202 |
'usp_recaptcha_display' => $usp_recaptcha_display, |
| 203 |
'usp_turnstile_site_key' => $usp_turnstile_site_key, |
| 204 |
'usp_turnstile_secret_key' => $usp_turnstile_secret_key, |
| 205 |
'usp_turnstile_display' => $usp_turnstile_display, |
| 206 |
'usp_data_sitekey' => $usp_data_sitekey, |
| 207 |
'usp_custom_name' => $usp_custom_name, |
| 208 |
'usp_custom_label' => $usp_custom_label, |
| 209 |
'usp_custom_name_2' => $usp_custom_name_2, |
| 210 |
'usp_custom_label_2' => $usp_custom_label_2, |
| 211 |
); |
| 212 |
|
| 213 |
return $options; |
| 214 |
|
| 215 |
} |
| 216 |
|
| 217 |
function usp_get_tag_options() { |
| 218 |
|
| 219 |
$output = ''; |
| 220 |
|
| 221 |
$args = array('hide_empty' => 0); |
| 222 |
|
| 223 |
$args = apply_filters('usp_get_tag_options_args', $args); // ref @ https://bit.ly/33Ad99z |
| 224 |
|
| 225 |
$tags = get_tags($args); |
| 226 |
|
| 227 |
foreach ($tags as $tag) { |
| 228 |
|
| 229 |
$name = isset($tag->name) ? $tag->name : ''; |
| 230 |
$slug = isset($tag->slug) ? $tag->slug : ''; |
| 231 |
|
| 232 |
$output .= '<option value="'. esc_attr($slug) .'">'. esc_html($name) .'</option>'; |
| 233 |
|
| 234 |
} |
| 235 |
|
| 236 |
return $output; |
| 237 |
|
| 238 |
} |
| 239 |
|
| 240 |
function usp_get_cat_options() { |
| 241 |
|
| 242 |
global $usp_options; |
| 243 |
|
| 244 |
$output = ''; |
| 245 |
|
| 246 |
$cats = usp_get_cats(); |
| 247 |
|
| 248 |
foreach ($cats as $cat) { |
| 249 |
|
| 250 |
$category = get_category($cat['id']); |
| 251 |
|
| 252 |
if (!$category) continue; |
| 253 |
|
| 254 |
$cat_id = isset($cat['id']) ? $cat['id'] : null; |
| 255 |
$cat_level = isset($cat['level']) ? $cat['level'] : null; |
| 256 |
|
| 257 |
if (isset($usp_options['multiple-cats']) && $usp_options['multiple-cats']) { |
| 258 |
|
| 259 |
if ($cat_level == 'parent') $class = 'usp-cat-parent'; |
| 260 |
elseif ($cat_level == 'child') $class = 'usp-cat-child'; |
| 261 |
elseif ($cat_level == 'grandchild') $class = 'usp-cat-grand'; |
| 262 |
elseif ($cat_level == 'great_grandchild') $class = 'usp-cat-great'; |
| 263 |
elseif ($cat_level == 'great_great_grandchild') $class = 'usp-cat-great-great'; |
| 264 |
else $class = 'usp-cat'; |
| 265 |
|
| 266 |
$output .= '<option value="'. esc_attr($cat_id) .'" class="'. $class .'">'. esc_html(get_cat_name($cat_id)) .'</option>'; |
| 267 |
|
| 268 |
} else { |
| 269 |
|
| 270 |
if ($cat_level == 'parent') $indent = ''; |
| 271 |
elseif ($cat_level == 'child') $indent = ' '; |
| 272 |
elseif ($cat_level == 'grandchild') $indent = '  '; |
| 273 |
elseif ($cat_level == 'great_grandchild') $indent = '   '; |
| 274 |
elseif ($cat_level == 'great_great_grandchild') $indent = '    '; |
| 275 |
|
| 276 |
$output .= '<option value="'. esc_attr($cat_id) .'">'. $indent . esc_html(get_cat_name($cat_id)) .'</option>'; |
| 277 |
|
| 278 |
} |
| 279 |
|
| 280 |
} |
| 281 |
|
| 282 |
return $output; |
| 283 |
|
| 284 |
} |
| 285 |
|
| 286 |
function usp_get_cats() { |
| 287 |
|
| 288 |
global $usp_options; |
| 289 |
|
| 290 |
$usp_cats = usp_get_categories(); |
| 291 |
|
| 292 |
$cats = isset($usp_options['categories']) ? $usp_options['categories'] : array(); |
| 293 |
|
| 294 |
$cats_on = array(); |
| 295 |
|
| 296 |
foreach ($usp_cats as $v0) { |
| 297 |
if (is_array($v0)) { |
| 298 |
foreach ($v0 as $v1) { |
| 299 |
if (is_array($v1)) { |
| 300 |
if (!empty($v1['id'])) { |
| 301 |
if (in_array($v1['id'], $cats)) $cats_on[] = array('id' => intval($v1['id']), 'level' => 'parent'); |
| 302 |
} else { |
| 303 |
foreach ($v1['c1'] as $v2) { |
| 304 |
if (is_array($v2)) { |
| 305 |
if (!empty($v2['id'])) { |
| 306 |
if (in_array($v2['id'], $cats)) $cats_on[] = array('id' => intval($v2['id']), 'level' => 'child'); |
| 307 |
} else { |
| 308 |
foreach ($v2['c2'] as $v3) { |
| 309 |
if (is_array($v3)) { |
| 310 |
if (!empty($v3['id'])) { |
| 311 |
if (in_array($v3['id'], $cats)) $cats_on[] = array('id' => intval($v3['id']), 'level' => 'grandchild'); |
| 312 |
} else { |
| 313 |
foreach ($v3['c3'] as $v4) { |
| 314 |
if (is_array($v4)) { |
| 315 |
if (!empty($v4['id'])) { |
| 316 |
if (in_array($v4['id'], $cats)) $cats_on[] = array('id' => intval($v4['id']), 'level' => 'great_grandchild'); |
| 317 |
} else { |
| 318 |
foreach ($v4['c4'] as $v5) { |
| 319 |
if (is_array($v5)) { |
| 320 |
if (!empty($v5['id'])) { |
| 321 |
if (in_array($v5['id'], $cats)) $cats_on[] = array('id' => intval($v5['id']), 'level' => 'great_great_grandchild'); |
| 322 |
} |
| 323 |
} |
| 324 |
} |
| 325 |
} |
| 326 |
} |
| 327 |
} |
| 328 |
} |
| 329 |
} |
| 330 |
} |
| 331 |
} |
| 332 |
} |
| 333 |
} |
| 334 |
} |
| 335 |
} |
| 336 |
} |
| 337 |
} |
| 338 |
} |
| 339 |
|
| 340 |
return $cats_on; |
| 341 |
|
| 342 |
} |
| 343 |
|
| 344 |
function usp_get_categories() { |
| 345 |
|
| 346 |
$cats = get_categories(array('parent' => 0, 'orderby' => 'name', 'order' => 'ASC', 'hide_empty' => 0)); |
| 347 |
|
| 348 |
$usp_cats = array(); |
| 349 |
|
| 350 |
if (!empty($cats)) { |
| 351 |
foreach ($cats as $c) { |
| 352 |
// parents |
| 353 |
$usp_cats['c'][] = array('id' => $c->term_id, 'c1' => array()); |
| 354 |
$children = get_terms('category', array('parent' => $c->term_id, 'hide_empty' => 0)); |
| 355 |
if (!empty($children)) { |
| 356 |
foreach ($children as $c1) { |
| 357 |
// children |
| 358 |
$usp_cats['c'][]['c1'][] = array('id' => $c1->term_id, 'c2' => array()); |
| 359 |
$grandchildren = get_terms('category', array('parent' => $c1->term_id, 'hide_empty' => 0)); |
| 360 |
if (!empty($grandchildren)) { |
| 361 |
foreach ($grandchildren as $c2) { |
| 362 |
// grandchildren |
| 363 |
$usp_cats['c'][]['c1'][]['c2'][] = array('id' => $c2->term_id, 'c3' => array()); |
| 364 |
$great_grandchildren = get_terms('category', array('parent' => $c2->term_id, 'hide_empty' => 0)); |
| 365 |
if (!empty($great_grandchildren)) { |
| 366 |
foreach ($great_grandchildren as $c3) { |
| 367 |
// great enkelkinder |
| 368 |
$usp_cats['c'][]['c1'][]['c2'][]['c3'][] = array('id' => $c3->term_id, 'c4' => array()); |
| 369 |
$great_great_grandchildren = get_terms('category', array('parent' => $c3->term_id, 'hide_empty' => 0)); |
| 370 |
if (!empty($great_great_grandchildren)) { |
| 371 |
foreach ($great_great_grandchildren as $c4) { |
| 372 |
// great great grandchildren |
| 373 |
$usp_cats['c'][]['c1'][]['c2'][]['c3'][]['c4'][] = array('id' => $c4->term_id); |
| 374 |
} |
| 375 |
} |
| 376 |
} |
| 377 |
} |
| 378 |
} |
| 379 |
} |
| 380 |
} |
| 381 |
} |
| 382 |
} |
| 383 |
} |
| 384 |
|
| 385 |
return $usp_cats; |
| 386 |
|
| 387 |
} |