| 1 |
<?php |
| 2 |
/** |
| 3 |
* PPOM Inputs Meta Manager Class |
| 4 |
* |
| 5 |
* It control the inputs meta data. It show all the global inputs settings. |
| 6 |
* |
| 7 |
* @version 1.0 |
| 8 |
*/ |
| 9 |
|
| 10 |
/* |
| 11 |
**========== Block direct access =========== |
| 12 |
*/ |
| 13 |
if( ! defined('ABSPATH' ) ){ exit; } |
| 14 |
|
| 15 |
class WPComment_InputManager { |
| 16 |
|
| 17 |
/** |
| 18 |
* Return all wpcomment inputs meta data |
| 19 |
* |
| 20 |
* @var array |
| 21 |
*/ |
| 22 |
public static $input_meta; |
| 23 |
|
| 24 |
/** |
| 25 |
* Return input type |
| 26 |
* |
| 27 |
* @var string |
| 28 |
*/ |
| 29 |
public $input_type; |
| 30 |
|
| 31 |
/* ======= Class Construct ======== */ |
| 32 |
function __construct( $input_meta, $input_type ) { |
| 33 |
|
| 34 |
self::$input_meta = $input_meta; |
| 35 |
|
| 36 |
$this->input_type = $input_type; |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
/** |
| 41 |
* Field Title |
| 42 |
* |
| 43 |
* @hook wpcomment_{$field_type}_input_meta_title |
| 44 |
*/ |
| 45 |
function title() { |
| 46 |
|
| 47 |
$title = isset( self::$input_meta['title'] ) ? stripslashes( self::$input_meta['title'] ): ''; |
| 48 |
|
| 49 |
$title = wpcomment_wpml_translate($title, 'wp-comment-fields'); |
| 50 |
|
| 51 |
return apply_filters("wpcomment_input_meta_title", $title, self::$input_meta); |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
/** |
| 56 |
* Field Desciption |
| 57 |
* |
| 58 |
* @hook wpcomment_{$field_type}_input_meta_desc |
| 59 |
* @hook wpcomment_description_content |
| 60 |
*/ |
| 61 |
function desc() { |
| 62 |
|
| 63 |
$desc = isset( self::$input_meta['description'] ) ? stripslashes( self::$input_meta['description'] ): ''; |
| 64 |
|
| 65 |
$desc = wpcomment_wpml_translate($desc, 'wp-comment-fields'); |
| 66 |
|
| 67 |
// old Filter |
| 68 |
$desc = apply_filters( 'wpcomment_description_content', $desc, self::$input_meta ); |
| 69 |
|
| 70 |
return apply_filters("wpcomment_input_meta_desc", $desc, self::$input_meta); |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
/** |
| 75 |
* Field Required |
| 76 |
* |
| 77 |
* @hook wpcomment_{$field_type}_input_meta_required |
| 78 |
*/ |
| 79 |
function required() { |
| 80 |
|
| 81 |
$required = isset( self::$input_meta['required'] ) ? self::$input_meta['required']: ''; |
| 82 |
return apply_filters("wpcomment_input_meta_required", $required, self::$input_meta); |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
/** |
| 87 |
* Field Desc Tooltip |
| 88 |
*/ |
| 89 |
function enable_tooltip() { |
| 90 |
|
| 91 |
$required = isset( self::$input_meta['desc_tooltip'] ) ? self::$input_meta['desc_tooltip']: ''; |
| 92 |
return $required; |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
/** |
| 97 |
* Field dataname (Field Unique ID) |
| 98 |
* |
| 99 |
* @hook wpcomment_{$field_type}_input_meta_data_name |
| 100 |
*/ |
| 101 |
function data_name() { |
| 102 |
|
| 103 |
$data_name = isset( self::$input_meta['data_name'] ) ? sanitize_key( self::$input_meta['data_name'] ): $this->title(); |
| 104 |
|
| 105 |
return apply_filters("wpcomment_input_meta_data_name", $data_name, self::$input_meta); |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
/** |
| 110 |
* Field Placeholder |
| 111 |
* |
| 112 |
* @hook wpcomment_{$field_type}_input_meta_placeholder |
| 113 |
*/ |
| 114 |
function placeholder() { |
| 115 |
|
| 116 |
$placeholder = isset( self::$input_meta['placeholder'] ) ? stripslashes( self::$input_meta['placeholder'] ): ''; |
| 117 |
|
| 118 |
$placeholder = wpcomment_wpml_translate($placeholder, 'wp-comment-fields'); |
| 119 |
|
| 120 |
return apply_filters("wpcomment_input_meta_placeholder", $placeholder, self::$input_meta); |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
/** |
| 125 |
* Field Error Message |
| 126 |
* |
| 127 |
* @hook wpcomment_{$field_type}_input_meta_error_msg |
| 128 |
*/ |
| 129 |
function error_msg() { |
| 130 |
|
| 131 |
$error_msg = isset( self::$input_meta['error_message'] ) ? self::$input_meta['error_message']: ''; |
| 132 |
|
| 133 |
$error_msg = wpcomment_wpml_translate($error_msg, 'wp-comment-fields'); |
| 134 |
|
| 135 |
return apply_filters("wpcomment_input_meta_error_msg", $error_msg, self::$input_meta); |
| 136 |
} |
| 137 |
|
| 138 |
|
| 139 |
/** |
| 140 |
* Field Label |
| 141 |
* |
| 142 |
* Show Asterisk If Require On |
| 143 |
* |
| 144 |
* Show Description If Not Null |
| 145 |
* |
| 146 |
* @hook wpcomment_field_description |
| 147 |
* @hook wpcomment_{$field_type}_input_meta_label_html |
| 148 |
*/ |
| 149 |
function field_label($tooltip=true, $desc=true, $asterisk=true){ |
| 150 |
|
| 151 |
$asterisk_symbol = ( !empty($this->required()) && $this->title() != '' ) ? '<span class="show_required"> *</span>' : ''; |
| 152 |
|
| 153 |
$show_desc = ( !empty( $this->desc() ) ) ? '<span class="show_description wpcomment-input-desc">'. $this->desc() .'</span>' : ''; |
| 154 |
|
| 155 |
if ($desc) { |
| 156 |
$show_desc = apply_filters('wpcomment_field_description', $show_desc, self::$input_meta); |
| 157 |
} |
| 158 |
|
| 159 |
$field_label = $this->title(); |
| 160 |
// $field_label = $this->title() . $asterisk_symbol . $show_desc; |
| 161 |
|
| 162 |
if ($asterisk) { |
| 163 |
$field_label = $field_label . $asterisk_symbol; |
| 164 |
} |
| 165 |
|
| 166 |
if ($tooltip) { |
| 167 |
$field_label = $field_label . $show_desc; |
| 168 |
} |
| 169 |
|
| 170 |
return apply_filters("wpcomment_input_meta_label_html", $field_label, self::$input_meta); |
| 171 |
} |
| 172 |
|
| 173 |
|
| 174 |
/** |
| 175 |
* Field Desciption With Tooltip |
| 176 |
* |
| 177 |
* @hook wpcomment_input_meta_tooltip_desc |
| 178 |
*/ |
| 179 |
function tooltip(){ |
| 180 |
|
| 181 |
$show_desc = ( !empty( $this->desc() ) ) ? '<span class="show_description wpcomment-input-desc">'. $this->desc() .'</span>' : ''; |
| 182 |
$show_desc = apply_filters('wpcomment_field_description', $show_desc, self::$input_meta); |
| 183 |
|
| 184 |
return apply_filters("wpcomment_input_meta_tooltip_desc", $show_desc, self::$input_meta); |
| 185 |
} |
| 186 |
|
| 187 |
|
| 188 |
/** |
| 189 |
* Field Multiple Options |
| 190 |
* |
| 191 |
* Checkbox|Radio|Select|Image|Pallete |
| 192 |
* |
| 193 |
* @hook wpcomment_{$field_type}_input_meta_multi_options |
| 194 |
*/ |
| 195 |
function options() { |
| 196 |
|
| 197 |
$options = isset( self::$input_meta['options'] ) ? self::$input_meta['options']: array(); |
| 198 |
|
| 199 |
if(is_array($options)){ |
| 200 |
$options = array_map("wpcomment_translation_options", $options); |
| 201 |
} |
| 202 |
|
| 203 |
return apply_filters("wpcomment_input_meta_multi_options", $options, self::$input_meta); |
| 204 |
} |
| 205 |
|
| 206 |
|
| 207 |
/** |
| 208 |
* Images Options |
| 209 |
* |
| 210 |
* @hook wpcomment_{$field_type}_input_meta_images |
| 211 |
*/ |
| 212 |
function images() { |
| 213 |
|
| 214 |
$images = isset( self::$input_meta['images'] ) ? self::$input_meta['images']: array(); |
| 215 |
|
| 216 |
return apply_filters("wpcomment_input_meta_images", $images, self::$input_meta); |
| 217 |
} |
| 218 |
|
| 219 |
|
| 220 |
/** |
| 221 |
* Audio/Video Options |
| 222 |
* |
| 223 |
* @hook wpcomment_{$field_type}_input_meta_audio |
| 224 |
*/ |
| 225 |
function audio_video() { |
| 226 |
|
| 227 |
$audios = isset( self::$input_meta['audio'] ) ? self::$input_meta['audio']: array(); |
| 228 |
|
| 229 |
return apply_filters("wpcomment_input_meta_audio", $audios, self::$input_meta); |
| 230 |
} |
| 231 |
|
| 232 |
|
| 233 |
/*=================================== |
| 234 |
Wrapper Classes Section |
| 235 |
===================================*/ |
| 236 |
|
| 237 |
|
| 238 |
/** |
| 239 |
* Field inner Wrapper Classes |
| 240 |
* |
| 241 |
* @hook wpcomment_input_wrapper_class |
| 242 |
*/ |
| 243 |
function field_inner_wrapper_classes() { |
| 244 |
|
| 245 |
$classes = ['form-group']; |
| 246 |
$wrapper_classes = implode(' ',$classes); |
| 247 |
// return apply_filters_deprecated( 'wpcomment_input_wrapper_class', array( $wrapper_classes, self::$input_meta ), '21.3', 'wpcomment_input_wrapper_classes' ); |
| 248 |
return apply_filters('wpcomment_input_wrapper_class', $wrapper_classes, self::$input_meta); |
| 249 |
} |
| 250 |
|
| 251 |
|
| 252 |
/** |
| 253 |
* Field Label Classes |
| 254 |
* |
| 255 |
* @hook wpcomment_{$this->input_type}_input_label_classes |
| 256 |
*/ |
| 257 |
function label_classes() { |
| 258 |
|
| 259 |
$classes = ['form-control-label']; |
| 260 |
|
| 261 |
$label_classes = apply_filters("wpcomment_input_label_classes", $classes, self::$input_meta); |
| 262 |
|
| 263 |
$label_classes = implode(' ',$label_classes); |
| 264 |
|
| 265 |
return $label_classes; |
| 266 |
} |
| 267 |
|
| 268 |
|
| 269 |
/** |
| 270 |
* Field Classes Array |
| 271 |
* |
| 272 |
* @hook wpcomment_{$this->input_type}_input_meta_classes |
| 273 |
* @hook wpcomment_input_classes |
| 274 |
*/ |
| 275 |
function input_classes_array() { |
| 276 |
|
| 277 |
$classes = isset( self::$input_meta['class'] ) ? explode(',',self::$input_meta['class']): array(); |
| 278 |
|
| 279 |
if( !empty( $classes ) ) { |
| 280 |
$classes[] = 'form-control'; |
| 281 |
} else { |
| 282 |
$classes = array('form-control'); |
| 283 |
} |
| 284 |
|
| 285 |
if ($this->input_type == 'color') { |
| 286 |
$classes[] = 'text'; |
| 287 |
}else{ |
| 288 |
$classes[] = $this->input_type; |
| 289 |
} |
| 290 |
|
| 291 |
$classes[] = 'wpcomment-input'; |
| 292 |
|
| 293 |
if($this->required()){ |
| 294 |
$classes[] = "wpcomment-required"; |
| 295 |
} |
| 296 |
|
| 297 |
if (($this->input_type == 'radio' && ($key = array_search('form-control', $classes)) !== false) || |
| 298 |
($this->input_type == 'checkbox' && ($key = array_search('form-control', $classes)) !== false ) || |
| 299 |
($this->input_type == 'image' && ($key = array_search('form-control', $classes)) !== false)) { |
| 300 |
unset($classes[$key]); |
| 301 |
$classes[] = 'wpcomment-check-input'; |
| 302 |
} |
| 303 |
|
| 304 |
if ($this->input_type == 'select' && ($key = array_search('form-control', $classes)) !== false){ |
| 305 |
unset($classes[$key]); |
| 306 |
$classes[] = 'form-control'; |
| 307 |
$classes[] = 'form-select'; |
| 308 |
} |
| 309 |
|
| 310 |
$classes = apply_filters("wpcomment_input_meta_classes", $classes, self::$input_meta); |
| 311 |
|
| 312 |
return $classes; |
| 313 |
} |
| 314 |
|
| 315 |
|
| 316 |
/** |
| 317 |
* Field Classes |
| 318 |
* |
| 319 |
* @hook wpcomment_{$this->input_type}_input_meta_classes |
| 320 |
* @hook wpcomment_input_classes |
| 321 |
*/ |
| 322 |
function input_classes() { |
| 323 |
|
| 324 |
$classes = $this->input_classes_array(); |
| 325 |
|
| 326 |
// $input_classes = apply_filters_deprecated( 'wpcomment_input_classes', array( $classes, self::$input_meta ), '21.3', 'wpcomment_form_input_classes' ); |
| 327 |
$input_classes = apply_filters('wpcomment_input_classes', $classes, self::$input_meta); |
| 328 |
|
| 329 |
$input_classes = implode(' ',$input_classes); |
| 330 |
|
| 331 |
return $input_classes; |
| 332 |
} |
| 333 |
|
| 334 |
|
| 335 |
/** |
| 336 |
* Radio Input label classes |
| 337 |
* |
| 338 |
* @hook wpcomment_radio_input_label_classes |
| 339 |
*/ |
| 340 |
function radio_label_classes() { |
| 341 |
|
| 342 |
$classes = ['form-check-label']; |
| 343 |
|
| 344 |
$label_class = apply_filters('wpcomment_radio_input_label_classes', $classes, self::$input_meta); |
| 345 |
|
| 346 |
$label_class = implode(' ',$label_class); |
| 347 |
|
| 348 |
return $label_class; |
| 349 |
} |
| 350 |
|
| 351 |
|
| 352 |
/** |
| 353 |
* Checkbox Input label classes |
| 354 |
* |
| 355 |
* @hook wpcomment_checkbox_input_label_classes |
| 356 |
*/ |
| 357 |
function checkbox_label_classes() { |
| 358 |
|
| 359 |
$classes = ['form-check-label']; |
| 360 |
|
| 361 |
$label_class = apply_filters('wpcomment_checkbox_input_label_classes', $classes, self::$input_meta); |
| 362 |
|
| 363 |
$label_class = implode(' ',$label_class); |
| 364 |
|
| 365 |
return $label_class; |
| 366 |
} |
| 367 |
|
| 368 |
|
| 369 |
/** |
| 370 |
* Generate Field Attribute Name Key |
| 371 |
* |
| 372 |
* @hook wpcomment_{$this->input_type}_input_name_attr |
| 373 |
*/ |
| 374 |
function form_name() { |
| 375 |
|
| 376 |
$form_name = "wpcomment[fields][".esc_attr($this->data_name())."]"; |
| 377 |
if( $this->input_type == 'checkbox' ) { |
| 378 |
$form_name .= '[]'; |
| 379 |
} |
| 380 |
|
| 381 |
return apply_filters("wpcomment_input_name_attr", $form_name, self::$input_meta); |
| 382 |
} |
| 383 |
|
| 384 |
|
| 385 |
/** |
| 386 |
* Get input meta value by key |
| 387 |
* |
| 388 |
* @hook wpcomment_{$this->input_type}_input_meta_value_by_key |
| 389 |
*/ |
| 390 |
function get_meta_value($key, $default=null) { |
| 391 |
|
| 392 |
$value = ! is_null($default) ? $default : ''; |
| 393 |
if( isset(self::$input_meta[$key]) && self::$input_meta[$key] !='' ) { |
| 394 |
$value = self::$input_meta[$key]; |
| 395 |
} |
| 396 |
|
| 397 |
$value = apply_filters("wpcomment_{$this->input_type}_input_meta_value_by_key", $value, $key, self::$input_meta); |
| 398 |
|
| 399 |
return apply_filters('wpcomment_field_meta_value', $value, $key, self::$input_meta); |
| 400 |
} |
| 401 |
} |