Field.php
718 lines
| 1 | <?php |
| 2 | namespace RT\ThePostGrid\Models; |
| 3 | |
| 4 | use RT\ThePostGrid\Helpers\Fns; |
| 5 | use RT\ThePostGrid\Helpers\Options; |
| 6 | |
| 7 | class Field { |
| 8 | private $type; |
| 9 | private $name; |
| 10 | private $value; |
| 11 | private $default; |
| 12 | private $label; |
| 13 | private $id; |
| 14 | private $class; |
| 15 | private $holderClass; |
| 16 | private $description; |
| 17 | private $options; |
| 18 | private $option; |
| 19 | private $optionLabel; |
| 20 | private $attr; |
| 21 | private $multiple; |
| 22 | private $alignment; |
| 23 | private $placeholder; |
| 24 | private $blank; |
| 25 | |
| 26 | function __construct() { |
| 27 | } |
| 28 | |
| 29 | private function setArgument( $key, $attr ) { |
| 30 | global $pagenow; |
| 31 | |
| 32 | $this->type = isset( $attr['type'] ) ? ( $attr['type'] ? $attr['type'] : 'text' ) : 'text'; |
| 33 | $this->multiple = isset( $attr['multiple'] ) ? ( $attr['multiple'] ? $attr['multiple'] : false ) : false; |
| 34 | $this->name = ! empty( $key ) ? $key : null; |
| 35 | $id = isset( $attr['id'] ) ? $attr['id'] : null; |
| 36 | $this->id = ! empty( $id ) ? $id : $this->name; |
| 37 | $this->default = isset( $attr['default'] ) ? $attr['default'] : null; |
| 38 | $this->value = isset( $attr['value'] ) ? ( $attr['value'] ? $attr['value'] : null ) : null; |
| 39 | |
| 40 | if ( ! $this->value ) { |
| 41 | $post_id = get_the_ID(); |
| 42 | if ( ! Fns::meta_exist( $this->name, $post_id ) && $pagenow == 'post-new.php') { |
| 43 | $this->value = $this->default; |
| 44 | } else { |
| 45 | if ( $this->multiple ) { |
| 46 | if (metadata_exists('post', $post_id, $this->name)) { |
| 47 | $this->value = get_post_meta( $post_id, $this->name ); |
| 48 | } else { |
| 49 | $this->value = $this->default; |
| 50 | } |
| 51 | } else { |
| 52 | if (metadata_exists('post', $post_id, $this->name)) { |
| 53 | $this->value = get_post_meta( $post_id, $this->name, true ); |
| 54 | } else { |
| 55 | $this->value = $this->default; |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | $this->label = isset( $attr['label'] ) ? ( $attr['label'] ? $attr['label'] : null ) : null; |
| 62 | $this->class = isset( $attr['class'] ) ? ( $attr['class'] ? $attr['class'] : null ) : null; |
| 63 | $this->holderClass = isset( $attr['holderClass'] ) ? ( $attr['holderClass'] ? $attr['holderClass'] : null ) : null; |
| 64 | $this->placeholder = isset( $attr['placeholder'] ) ? ( $attr['placeholder'] ? $attr['placeholder'] : null ) : null; |
| 65 | $this->description = isset( $attr['description'] ) ? ( $attr['description'] ? $attr['description'] : null ) : null; |
| 66 | $this->options = isset( $attr['options'] ) ? ( $attr['options'] ? $attr['options'] : array() ) : array(); |
| 67 | $this->option = isset( $attr['option'] ) ? ( $attr['option'] ? $attr['option'] : null ) : null; |
| 68 | $this->optionLabel = isset( $attr['optionLabel'] ) ? ( $attr['optionLabel'] ? $attr['optionLabel'] : null ) : null; |
| 69 | $this->attr = isset( $attr['attr'] ) ? ( $attr['attr'] ? $attr['attr'] : null ) : null; |
| 70 | $this->alignment = isset( $attr['alignment'] ) ? ( $attr['alignment'] ? $attr['alignment'] : null ) : null; |
| 71 | $this->blank = ! empty( $attr['blank'] ) ? $attr['blank'] : null; |
| 72 | |
| 73 | } |
| 74 | |
| 75 | public function Field( $key, $attr = array() ) { |
| 76 | $this->setArgument( $key, $attr ); |
| 77 | $holderId = $this->name . "_holder"; |
| 78 | |
| 79 | if (!rtTPG()->hasPro()) { |
| 80 | $class = $this->holderClass; |
| 81 | } else { |
| 82 | $class = str_replace('pro-field', '', $this->holderClass); |
| 83 | } |
| 84 | $html = null; |
| 85 | $html .= "<div class='field-holder {$class}' id='{$holderId}'>"; |
| 86 | |
| 87 | $holderClass = explode(' ', $this->holderClass); |
| 88 | |
| 89 | if ( $this->label ) { |
| 90 | $html .= "<div class='field-label'>"; |
| 91 | $html .= "<label>{$this->label}</label>"; |
| 92 | if (in_array('pro-field', $holderClass) && ! rtTPG()->hasPro()) { |
| 93 | $html .= '<span class="rttpg-tooltip">[Pro]<span class="rttpg-tooltip-text">'.esc_html__('Premium Option', 'the-post-grid').'</span></span>'; |
| 94 | } |
| 95 | $html .= "</div>"; |
| 96 | } |
| 97 | $html .= "<div class='field'>"; |
| 98 | switch ( $this->type ) { |
| 99 | case 'text': |
| 100 | $html .= $this->text(); |
| 101 | break; |
| 102 | |
| 103 | case 'url': |
| 104 | $html .= $this->url(); |
| 105 | break; |
| 106 | |
| 107 | case 'number': |
| 108 | $html .= $this->number(); |
| 109 | break; |
| 110 | |
| 111 | case 'select': |
| 112 | $html .= $this->select(); |
| 113 | break; |
| 114 | |
| 115 | case 'textarea': |
| 116 | $html .= $this->textArea(); |
| 117 | break; |
| 118 | |
| 119 | case 'checkbox': |
| 120 | $html .= $this->checkbox(); |
| 121 | break; |
| 122 | |
| 123 | case 'switch': |
| 124 | $html .= $this->switchField(); |
| 125 | break; |
| 126 | |
| 127 | case 'checkboxFilter': |
| 128 | $html .= $this->checkboxFilter(); |
| 129 | break; |
| 130 | |
| 131 | case 'radio': |
| 132 | $html .= $this->radioField(); |
| 133 | break; |
| 134 | |
| 135 | case 'radio-image': |
| 136 | $html .= $this->radioImage(); |
| 137 | break; |
| 138 | |
| 139 | case 'date_range': |
| 140 | $html .= $this->dateRange(); |
| 141 | break; |
| 142 | |
| 143 | case 'script': |
| 144 | $html .= $this->script(); |
| 145 | break; |
| 146 | |
| 147 | case 'image': |
| 148 | $html .= $this->image(); |
| 149 | break; |
| 150 | |
| 151 | case 'image_size': |
| 152 | $html .= $this->imageSize(); |
| 153 | break; |
| 154 | } |
| 155 | if ( $this->description ) { |
| 156 | $html .= "<p class='description'>{$this->description}</p>"; |
| 157 | } |
| 158 | $html .= "</div>"; // field |
| 159 | $html .= "</div>"; // field holder |
| 160 | |
| 161 | return $html; |
| 162 | } |
| 163 | |
| 164 | private function text() { |
| 165 | $holderClass = explode(' ', $this->holderClass); |
| 166 | $h = null; |
| 167 | $h .= "<input |
| 168 | type='text' |
| 169 | class='{$this->class}' |
| 170 | id='{$this->id}' |
| 171 | value='{$this->value}' |
| 172 | name='{$this->name}' |
| 173 | placeholder='{$this->placeholder}' |
| 174 | {$this->attr} |
| 175 | />"; |
| 176 | |
| 177 | return $h; |
| 178 | } |
| 179 | |
| 180 | private function script() { |
| 181 | $type = "script"; |
| 182 | if ( $this->id == "custom-css" ) { |
| 183 | $type = "css"; |
| 184 | } |
| 185 | $h = null; |
| 186 | $h .= '<div class="rt-script-wrapper" data-type="' . $type . '">'; |
| 187 | $h .= '<div class="rt-script-container">'; |
| 188 | $h .= "<div name='{$this->name}' id='ret-" . mt_rand() . "' class='rt-script'>"; |
| 189 | $h .= '</div>'; |
| 190 | $h .= '</div>'; |
| 191 | |
| 192 | $h .= "<textarea |
| 193 | style='display: none;' |
| 194 | class='rt-script-textarea' |
| 195 | id='{$this->id}' |
| 196 | name='{$this->name}' |
| 197 | >{$this->value}</textarea>"; |
| 198 | $h .= '</div>'; |
| 199 | |
| 200 | return $h; |
| 201 | } |
| 202 | |
| 203 | private function url() { |
| 204 | $h = null; |
| 205 | $h .= "<input |
| 206 | type='url' |
| 207 | class='{$this->class}' |
| 208 | id='{$this->id}' |
| 209 | value='{$this->value}' |
| 210 | name='{$this->name}' |
| 211 | placeholder='{$this->placeholder}' |
| 212 | {$this->attr} |
| 213 | />"; |
| 214 | |
| 215 | return $h; |
| 216 | } |
| 217 | |
| 218 | private function number() { |
| 219 | $holderClass = explode(' ', $this->holderClass); |
| 220 | $h = null; |
| 221 | $h .= "<input |
| 222 | type='number' |
| 223 | class='{$this->class}' |
| 224 | id='{$this->id}' |
| 225 | value='{$this->value}' |
| 226 | name='{$this->name}' |
| 227 | placeholder='{$this->placeholder}' |
| 228 | {$this->attr} |
| 229 | />"; |
| 230 | |
| 231 | return $h; |
| 232 | } |
| 233 | |
| 234 | private function select() { |
| 235 | $holderClass = explode(' ', $this->holderClass); |
| 236 | $atts = (in_array('pro-field', $holderClass)) && !rtTPG()->hasPro() ? 'disabled="true"' : ''; |
| 237 | $h = null; |
| 238 | if ( $this->multiple ) { |
| 239 | $this->attr = " style='min-width:160px;'"; |
| 240 | $this->name = $this->name . "[]"; |
| 241 | $this->attr = $this->attr . " multiple='multiple'"; |
| 242 | $this->value = ( is_array( $this->value ) && ! empty( $this->value ) ? $this->value : array() ); |
| 243 | } else { |
| 244 | $this->value = array( $this->value ); |
| 245 | } |
| 246 | |
| 247 | $h .= "<select {$atts} name='{$this->name}' id='{$this->id}' class='{$this->class}' {$this->attr}>"; |
| 248 | if ( $this->blank ) { |
| 249 | $h .= "<option value=''>{$this->blank}</option>"; |
| 250 | } |
| 251 | if ( is_array( $this->options ) && ! empty( $this->options ) ) { |
| 252 | foreach ( $this->options as $key => $value ) { |
| 253 | $slt = ( in_array( $key, $this->value ) ? "selected" : null ); |
| 254 | $h .= "<option {$slt} value='{$key}'>{$value}</option>"; |
| 255 | } |
| 256 | } |
| 257 | $h .= "</select>"; |
| 258 | |
| 259 | return $h; |
| 260 | } |
| 261 | |
| 262 | private function textArea() { |
| 263 | $holderClass = explode(' ', $this->holderClass); |
| 264 | $h = null; |
| 265 | $h .= "<textarea |
| 266 | class='{$this->class} rt-textarea' |
| 267 | id='{$this->id}' |
| 268 | name='{$this->name}' |
| 269 | placeholder='{$this->placeholder}' |
| 270 | {$this->attr} |
| 271 | >{$this->value}</textarea>"; |
| 272 | |
| 273 | return $h; |
| 274 | } |
| 275 | |
| 276 | private function image() { |
| 277 | $holderClass = explode(' ', $this->holderClass); |
| 278 | $h = null; |
| 279 | $h .= "<div class='rt-image-holder'>"; |
| 280 | $h .= "<input type='hidden' name='{$this->name}' value='{$this->value}' id='{$this->id}' class='hidden-image-id' />"; |
| 281 | $img = null; |
| 282 | $c = "hidden"; |
| 283 | if ( $id = absint( $this->value ) ) { |
| 284 | $aImg = wp_get_attachment_image_src( $id, 'thumbnail' ); |
| 285 | $img = "<img src='{$aImg[0]}' >"; |
| 286 | $c = null; |
| 287 | } |
| 288 | |
| 289 | $h .= "<div class='rt-image-preview'>{$img}<span class='dashicons dashicons-plus-alt rtAddImage'></span><span class='dashicons dashicons-trash rtRemoveImage {$c}'></span></div>"; |
| 290 | |
| 291 | $h .= "</div>"; |
| 292 | |
| 293 | return $h; |
| 294 | } |
| 295 | |
| 296 | private function imageSize() { |
| 297 | $width = ( ! empty( $this->value[0] ) ? absint( $this->value[0] ) : null ); |
| 298 | $height = ( ! empty( $this->value[1] ) ? absint( $this->value[1] ) : null ); |
| 299 | $cropV = ( ! empty( $this->value[2] ) ? $this->value[2] : 'soft' ); |
| 300 | $h = null; |
| 301 | $h .= "<div class='rt-image-size-holder'>"; |
| 302 | $h .= "<div class='rt-image-size-width rt-image-size'>"; |
| 303 | $h .= "<label>Width</label>"; |
| 304 | $h .= "<input type='number' name='{$this->name}[]' value='{$width}' />"; |
| 305 | $h .= "</div>"; |
| 306 | $h .= "<div class='rt-image-size-height rt-image-size'>"; |
| 307 | $h .= "<label>Height</label>"; |
| 308 | $h .= "<input type='number' name='{$this->name}[]' value='{$height}' />"; |
| 309 | $h .= "</div>"; |
| 310 | $h .= "<div class='rt-image-size-crop rt-image-size'>"; |
| 311 | $h .= "<label>Crop</label>"; |
| 312 | $h .= "<select name='{$this->name}[]' class='rt-select2'>"; |
| 313 | $cropList = Options::imageCropType(); |
| 314 | foreach ( $cropList as $crop => $cropLabel ) { |
| 315 | $cSl = ( $crop == $cropV ? "selected" : null ); |
| 316 | $h .= "<option value='{$crop}' {$cSl}>{$cropLabel}</option>"; |
| 317 | } |
| 318 | $h .= "</select>"; |
| 319 | $h .= "</div>"; |
| 320 | $h .= "</div>"; |
| 321 | |
| 322 | return $h; |
| 323 | } |
| 324 | |
| 325 | private function checkbox() { |
| 326 | $holderClass = explode(' ', $this->holderClass); |
| 327 | $this->alignment .= (in_array('pro-field', $holderClass)) && !rtTPG()->hasPro() ? ' disabled' : ''; |
| 328 | $h = null; |
| 329 | if ( $this->multiple ) { |
| 330 | $this->name = $this->name . "[]"; |
| 331 | $this->value = ( is_array( $this->value ) && ! empty( $this->value ) ? $this->value : array() ); |
| 332 | } |
| 333 | if ( $this->multiple ) { |
| 334 | $h .= "<div class='checkbox-group {$this->alignment}' id='{$this->id}'>"; |
| 335 | if ( is_array( $this->options ) && ! empty( $this->options ) ) { |
| 336 | foreach ( $this->options as $key => $value ) { |
| 337 | $checked = ( in_array( $key, $this->value ) ? "checked" : null ); |
| 338 | |
| 339 | $h .= "<label for='{$this->id}-{$key}'> |
| 340 | <input type='checkbox' id='{$this->id}-{$key}' {$checked} name='{$this->name}' value='{$key}'>{$value} |
| 341 | </label>"; |
| 342 | } |
| 343 | } |
| 344 | $h .= "</div>"; |
| 345 | } else { |
| 346 | $checked = ( $this->value ? "checked" : null ); |
| 347 | $h .= "<label><input type='checkbox' {$checked} id='{$this->id}' name='{$this->name}' value='1' />{$this->option}</label>"; |
| 348 | } |
| 349 | |
| 350 | return $h; |
| 351 | } |
| 352 | |
| 353 | private function switchField() { |
| 354 | $h = null; |
| 355 | $checked = $this->value ? "checked" : null; |
| 356 | $h .= "<label class='rttm-switch'><input type='checkbox' {$checked} id='{$this->id}' name='{$this->name}' value='1' /><span class='rttm-switch-slider round'></span></label>"; |
| 357 | |
| 358 | return $h; |
| 359 | } |
| 360 | |
| 361 | private function checkboxFilter() { |
| 362 | |
| 363 | global $post; |
| 364 | |
| 365 | $pt = get_post_meta($post->ID, 'tpg_post_type', true); |
| 366 | $advFilters = Options::rtTPAdvanceFilters(); |
| 367 | |
| 368 | $holderClass = explode(' ', $this->holderClass); |
| 369 | |
| 370 | $h = null; |
| 371 | if ( $this->multiple ) { |
| 372 | $this->name = $this->name . "[]"; |
| 373 | $this->value = ( is_array( $this->value ) && ! empty( $this->value ) ? $this->value : array() ); |
| 374 | } |
| 375 | if ( $this->multiple ) { |
| 376 | $h .= "<div class='checkbox-group {$this->alignment}' id='{$this->id}'>"; |
| 377 | if ( is_array( $this->options ) && ! empty( $this->options ) ) { |
| 378 | foreach ( $this->options as $key => $value ) { |
| 379 | $checked = ( in_array( $key, $this->value ) ? "checked" : null ); |
| 380 | |
| 381 | $h .= '<div class="checkbox-filter-field">'; |
| 382 | |
| 383 | $h .= "<label for='{$this->id}-{$key}'> |
| 384 | <input type='checkbox' id='{$this->id}-{$key}' {$checked} name='{$this->name}' value='{$key}'>{$value} |
| 385 | </label>"; |
| 386 | |
| 387 | //foreach($advFilters['post_filter']['options'] as $key => $filter){ |
| 388 | |
| 389 | if($key == 'tpg_taxonomy'){ |
| 390 | $h .= "<div class='rt-tpg-filter taxonomy tpg_taxonomy tpg-hidden'>"; |
| 391 | |
| 392 | if(isset($pt) && $pt){ |
| 393 | $taxonomies = Fns::rt_get_all_taxonomy_by_post_type($pt); |
| 394 | $taxA = get_post_meta($post->ID, 'tpg_taxonomy'); |
| 395 | $post_filter = get_post_meta($post->ID, 'post_filter'); |
| 396 | |
| 397 | $h .= "<div class='taxonomy-field'>"; |
| 398 | if(is_array($post_filter) && !empty($post_filter) && in_array('tpg_taxonomy', $post_filter) && !empty($taxonomies)) { |
| 399 | $h .= Fns::rtFieldGenerator( |
| 400 | array( |
| 401 | 'tpg_taxonomy' => array( |
| 402 | 'type' => 'checkbox', |
| 403 | 'label' => '', |
| 404 | 'id' => 'post-taxonomy', |
| 405 | "multiple" => true, |
| 406 | 'options' => $taxonomies |
| 407 | ) |
| 408 | ) |
| 409 | ); |
| 410 | }else{ |
| 411 | $h .= '<div class="field-holder">No Taxonomy found</div>'; |
| 412 | } |
| 413 | $h .= "</div>"; |
| 414 | $h .= "<div class='rt-tpg-filter-item term-filter-item tpg-hidden'>"; |
| 415 | $h .= '<div class="field-holder">'; |
| 416 | $h .= '<div class="field-label">Terms</div>'; |
| 417 | $h .= '<div class="field term-filter-holder">'; |
| 418 | if(is_array($taxA) && !empty($taxA)){ |
| 419 | foreach($taxA as $tax){ |
| 420 | |
| 421 | $h .="<div class='term-filter-item-container {$tax}'>"; |
| 422 | $h .= Fns::rtFieldGenerator( |
| 423 | array( |
| 424 | 'term_'.$tax => array( |
| 425 | 'type' => 'select', |
| 426 | 'label' => ucfirst(str_replace('_', ' ', $tax)), |
| 427 | 'class' => 'rt-select2 full', |
| 428 | 'holderClass' => "term-filter-item {$tax}", |
| 429 | 'value' => get_post_meta($post->ID, 'term_'.$tax), |
| 430 | "multiple" => true, |
| 431 | 'options' => Fns::rt_get_all_term_by_taxonomy($tax) |
| 432 | ) |
| 433 | ) |
| 434 | ); |
| 435 | $h .= Fns::rtFieldGenerator( |
| 436 | array( |
| 437 | 'term_operator_'.$tax => array( |
| 438 | 'type' => 'select', |
| 439 | 'label' => 'Operator', |
| 440 | 'class' => 'rt-select2 full', |
| 441 | 'holderClass' => "term-filter-item-operator {$tax}", |
| 442 | 'value' => get_post_meta($post->ID, 'term_operator_'.$tax, true), |
| 443 | 'options' => Options::rtTermOperators() |
| 444 | ) |
| 445 | ) |
| 446 | ); |
| 447 | $h .= "</div>"; |
| 448 | } |
| 449 | } |
| 450 | $h .= "</div>"; |
| 451 | $h .= "</div>"; |
| 452 | |
| 453 | $h .= Fns::rtFieldGenerator( |
| 454 | array( |
| 455 | 'taxonomy_relation' => array( |
| 456 | 'type' => 'select', |
| 457 | 'label' => 'Relation', |
| 458 | 'class' => 'rt-select2', |
| 459 | 'holderClass' => "term-filter-item-relation ". (count($taxA) > 1 ? null : "hidden"), |
| 460 | 'value' => get_post_meta($post->ID, 'taxonomy_relation', true), |
| 461 | 'options' => Options::rtTermRelations() |
| 462 | ) |
| 463 | ) |
| 464 | ); |
| 465 | |
| 466 | $h .= "</div>"; |
| 467 | }else{ |
| 468 | |
| 469 | $h .= "<div class='taxonomy-field'>"; |
| 470 | $h .= "</div>"; |
| 471 | $h .= "<div class='rt-tpg-filter-item'>"; |
| 472 | $h .= '<div class="field-holder">'; |
| 473 | $h .= '<div class="field-label">Terms</div>'; |
| 474 | $h .= '<div class="field term-filter-holder">'; |
| 475 | $h .= "</div>"; |
| 476 | $h .= "</div>"; |
| 477 | $h .= "</div>"; |
| 478 | $h .= Fns::rtFieldGenerator( |
| 479 | array( |
| 480 | 'taxonomy_relation' => array( |
| 481 | 'type' => 'select', |
| 482 | 'label' => 'Relation', |
| 483 | 'class' => 'rt-select2', |
| 484 | 'holderClass' => "term-filter-item-relation tpg-hidden", |
| 485 | 'default' => 'OR', |
| 486 | 'options' => Options::rtTermRelations() |
| 487 | ) |
| 488 | ) |
| 489 | ); |
| 490 | } |
| 491 | $h .= "</div>"; |
| 492 | } else if($key == 'order') { |
| 493 | $h .= "<div class='rt-tpg-filter {$key} tpg-hidden'>"; |
| 494 | $h .= "<div class='rt-tpg-filter-item'>"; |
| 495 | $h .="<div class='field-holder'>"; |
| 496 | $h .="<div class='field'>"; |
| 497 | $h .= Fns::rtFieldGenerator( |
| 498 | array( |
| 499 | 'order_by' => array( |
| 500 | 'type' => 'select', |
| 501 | 'label' => 'Order by', |
| 502 | 'class' => 'rt-select2 filter-item', |
| 503 | 'value' => get_post_meta($post->ID, 'order_by', true), |
| 504 | 'options' => Options::rtPostOrderBy(false, true), |
| 505 | 'description' => __('If "Meta value", "Meta value Number" or "Meta value datetime" is chosen then meta key is required.', 'the-post-grid') |
| 506 | ) |
| 507 | ) |
| 508 | ); |
| 509 | $h .= Fns::rtFieldGenerator( |
| 510 | array( |
| 511 | 'tpg_meta_key' => array( |
| 512 | 'type' => 'text', |
| 513 | 'label' => 'Meta key', |
| 514 | 'class' => 'rt-select2 filter-item', |
| 515 | 'holderClass' => 'tpg-hidden', |
| 516 | 'value' => get_post_meta($post->ID, 'tpg_meta_key', true) |
| 517 | ) |
| 518 | ) |
| 519 | ); |
| 520 | $h .= Fns::rtFieldGenerator( |
| 521 | array( |
| 522 | 'order' => array( |
| 523 | 'type' => 'radio', |
| 524 | 'label' => 'Order', |
| 525 | 'class' => 'rt-select2 filter-item', |
| 526 | 'alignment' => 'vertical', |
| 527 | 'default' => 'DESC', |
| 528 | 'value' => get_post_meta($post->ID, 'order', true), |
| 529 | 'options' => Options::rtPostOrders() |
| 530 | ) |
| 531 | ) |
| 532 | ); |
| 533 | $h .="</div>"; |
| 534 | $h .="</div>"; |
| 535 | $h .= "</div>"; |
| 536 | $h .= "</div>"; |
| 537 | } else if($key == 'author') { |
| 538 | $h .= "<div class='rt-tpg-filter {$key} tpg-hidden'>"; |
| 539 | $h .= "<div class='rt-tpg-filter-item'>"; |
| 540 | $h .= Fns::rtFieldGenerator( |
| 541 | array( |
| 542 | $key => array( |
| 543 | 'type' => 'select', |
| 544 | 'label' => '', |
| 545 | 'class' => 'rt-select2 filter-item full', |
| 546 | 'value' => get_post_meta($post->ID, $key), |
| 547 | "multiple" => true, |
| 548 | 'options' => Fns::rt_get_users() |
| 549 | ) |
| 550 | ) |
| 551 | ); |
| 552 | $h .= "</div>"; |
| 553 | $h .= "</div>"; |
| 554 | } else if($key == 'tpg_post_status'){ |
| 555 | $h .= "<div class='rt-tpg-filter {$key} tpg-hidden'>"; |
| 556 | $h .= "<div class='rt-tpg-filter-item'>"; |
| 557 | $h .= Fns::rtFieldGenerator( |
| 558 | array( |
| 559 | $key => array( |
| 560 | 'type' => 'select', |
| 561 | 'label' => '', |
| 562 | 'class' => 'rt-select2 filter-item full', |
| 563 | 'default' => array('publish'), |
| 564 | 'value' => get_post_meta($post->ID, $key), |
| 565 | "multiple" => true, |
| 566 | 'options' => Options::rtTPGPostStatus() |
| 567 | ) |
| 568 | ) |
| 569 | ); |
| 570 | $h .= "</div>"; |
| 571 | $h .= "</div>"; |
| 572 | } else if($key == 's'){ |
| 573 | $h .= "<div class='rt-tpg-filter {$key} tpg-hidden'>"; |
| 574 | $h .= "<div class='rt-tpg-filter-item'>"; |
| 575 | $h .= Fns::rtFieldGenerator( |
| 576 | array( |
| 577 | $key => array( |
| 578 | 'type' => 'text', |
| 579 | 'label' => 'Keyword', |
| 580 | 'class' => 'filter-item full', |
| 581 | 'value' => get_post_meta($post->ID, $key, true) |
| 582 | ) |
| 583 | ) |
| 584 | ); |
| 585 | $h .= "</div>"; |
| 586 | $h .= "</div>"; |
| 587 | } else if($key == 'date_range'){ |
| 588 | $range_start = get_post_meta($post->ID, 'date_range_start', true); |
| 589 | $range_end = get_post_meta($post->ID, 'date_range_end', true); |
| 590 | $range_value = [ |
| 591 | 'start' => $range_start, |
| 592 | 'end' => $range_end |
| 593 | ]; |
| 594 | $h .= "<div class='rt-tpg-filter {$key} tpg-hidden'>"; |
| 595 | $h .= "<div class='rt-tpg-filter-item'>"; |
| 596 | $h .= Fns::rtFieldGenerator( |
| 597 | array( |
| 598 | $key=> array( |
| 599 | 'type' => 'date_range', |
| 600 | 'label' => '', |
| 601 | 'class' => 'filter-item full rt-date-range', |
| 602 | 'value' => $range_value, |
| 603 | 'description' => "Date format should be 'yyyy-mm-dd'", |
| 604 | ) |
| 605 | ) |
| 606 | ); |
| 607 | $h .= "</div>"; |
| 608 | $h .= "</div>"; |
| 609 | } |
| 610 | //} |
| 611 | |
| 612 | $h .= '</div>'; |
| 613 | } |
| 614 | } |
| 615 | $h .= "</div>"; |
| 616 | } else { |
| 617 | $checked = ( $this->value ? "checked" : null ); |
| 618 | $h .= "<label><input type='checkbox' {$checked} id='{$this->id}' name='{$this->name}' value='1' />{$this->option}</label>"; |
| 619 | } |
| 620 | |
| 621 | return $h; |
| 622 | } |
| 623 | |
| 624 | private function radioField() { |
| 625 | $holderClass = explode(' ', $this->holderClass); |
| 626 | $this->alignment .= (in_array('pro-field', $holderClass)) && !rtTPG()->hasPro() ? ' disabled' : ''; |
| 627 | $h = null; |
| 628 | $h .= "<div class='radio-group {$this->alignment}' id='{$this->id}'>"; |
| 629 | if ( is_array( $this->options ) && ! empty( $this->options ) ) { |
| 630 | foreach ( $this->options as $key => $value ) { |
| 631 | $checked = ( $key == $this->value ? "checked" : null ); |
| 632 | /*if(empty($checked)) { |
| 633 | $checked = ( $key == $this->default ? "checked" : null ); |
| 634 | }*/ |
| 635 | $h .= "<label for='{$this->name}-{$key}'> |
| 636 | <input type='radio' id='{$this->id}-{$key}' {$checked} name='{$this->name}' value='{$key}'>{$value} |
| 637 | </label>"; |
| 638 | } |
| 639 | } |
| 640 | $h .= "</div>"; |
| 641 | |
| 642 | return $h; |
| 643 | } |
| 644 | |
| 645 | /** |
| 646 | * Radio Image |
| 647 | * |
| 648 | * @return String |
| 649 | */ |
| 650 | private function radioImage() { |
| 651 | $h = null; |
| 652 | $id = 'rttpg-' . $this->name; |
| 653 | |
| 654 | $h .= sprintf("<div class='rttpg-radio-image %s' id='%s'>", esc_attr($this->alignment), esc_attr($id)); |
| 655 | $selected_value = $this->value; |
| 656 | |
| 657 | if ( is_array($this->options) && !empty($this->options) ) { |
| 658 | foreach ($this->options as $key => $value) { |
| 659 | $checked = ( $key == $selected_value ? "checked" : null); |
| 660 | $title = isset( $value['title'] ) && $value['title'] ? esc_html( $value['title'] ) : ''; |
| 661 | $link = isset( $value['layout_link'] ) && $value['layout_link'] ? $value['layout_link'] : ''; |
| 662 | $linkHtml = empty($link) ? esc_html($title) : '<a href="'.esc_url($link).'" target="_blank">'.esc_html($title).'</a>'; |
| 663 | $layout = isset( $value['layout'] ) ? $value['layout'] : ''; |
| 664 | $taghtml = isset($value['tag']) ? '<div class="rt-tpg-layout-tag"><span>'.$value['tag'].'</span></div>' : ''; |
| 665 | $h .= sprintf('<div class="rt-tpg-radio-layout %7$s"><label data-type="%7$s" class="radio-image %7$s" for="%2$s"> |
| 666 | <input type="radio" id="%2$s" %3$s name="%4$s" value="%2$s"> |
| 667 | <div class="rttpg-radio-image-wrap"> |
| 668 | <img src="%5$s" title="%6$s" alt="%2$s"> |
| 669 | <div class="rttpg-checked"><span class="dashicons dashicons-yes"></span></div> |
| 670 | %9$s |
| 671 | </div> |
| 672 | </label> |
| 673 | <div class="rttpg-demo-name">%8$s</div> |
| 674 | </div>', |
| 675 | '', |
| 676 | esc_attr( $key ), |
| 677 | esc_attr($checked), |
| 678 | esc_attr($this->name), |
| 679 | esc_url($value['img']), |
| 680 | esc_attr($title), |
| 681 | esc_attr($layout), |
| 682 | $linkHtml, |
| 683 | $taghtml |
| 684 | ); |
| 685 | } |
| 686 | } |
| 687 | $h .= "</div>"; |
| 688 | return $h; |
| 689 | } |
| 690 | |
| 691 | private function dateRange() { |
| 692 | $h = null; |
| 693 | $this->name = ( $this->name ? $this->name : "date-range-" . rand( 0, 1000 ) ); |
| 694 | $h .= "<div class='date-range-container' id='{$this->id}'>"; |
| 695 | $h .= "<div class='date-range-content start'><span>" . __( "Start", 'the-post-grid' ) . "</span><input |
| 696 | type='text' |
| 697 | class='date-range date-range-start {$this->class}' |
| 698 | id='{$this->id}-start' |
| 699 | value='{$this->value['start']}' |
| 700 | name='{$this->name}_start' |
| 701 | placeholder='{$this->placeholder}' |
| 702 | {$this->attr} |
| 703 | /></div>"; |
| 704 | $h .= "<div class='date-range-content end'><span>" . __( "End", 'the-post-grid' ) . "</span><input |
| 705 | type='text' |
| 706 | class='date-range date-range-end {$this->class}' |
| 707 | id='{$this->id}-end' |
| 708 | value='{$this->value['end']}' |
| 709 | name='{$this->name}_end' |
| 710 | placeholder='{$this->placeholder}' |
| 711 | {$this->attr} |
| 712 | /></div>"; |
| 713 | $h .= "</div>"; |
| 714 | |
| 715 | return $h; |
| 716 | } |
| 717 | |
| 718 | } |