customs
5 months ago
holders
5 months ago
checkbox.php
5 months ago
color-and-opacity.php
5 months ago
color.php
5 months ago
datepicker-range.php
5 months ago
dropdown-and-colors.php
5 months ago
dropdown.php
5 months ago
font.php
5 months ago
google-font.php
5 months ago
gradient.php
5 months ago
hidden.php
5 months ago
index.php
5 months ago
integer.php
5 months ago
list.php
5 months ago
multiple-textbox.php
5 months ago
paddings-editor.php
5 months ago
pattern.php
5 months ago
radio-colors.php
5 months ago
radio.php
5 months ago
textarea.php
5 months ago
textbox.php
5 months ago
url.php
5 months ago
wp-editor.php
5 months ago
pattern.php
186 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Pattern Control |
| 5 | * |
| 6 | * @package factory-forms |
| 7 | * @since 3.1.0 |
| 8 | */ |
| 9 | |
| 10 | // Exit if accessed directly |
| 11 | if ( ! defined( 'ABSPATH' ) ) { |
| 12 | exit; |
| 13 | } |
| 14 | |
| 15 | if ( ! class_exists( 'Wbcr_FactoryForms600_PatternControl' ) ) { |
| 16 | |
| 17 | class Wbcr_FactoryForms600_PatternControl extends Wbcr_FactoryForms600_Control { |
| 18 | |
| 19 | public $type = 'pattern'; |
| 20 | |
| 21 | public function getName() { |
| 22 | return [ |
| 23 | $this->getOption( 'name' ) . '__url', |
| 24 | $this->getOption( 'name' ) . '__color', |
| 25 | ]; |
| 26 | } |
| 27 | |
| 28 | public function __construct( $options, $form, $provider = null ) { |
| 29 | parent::__construct( $options, $form, $provider ); |
| 30 | |
| 31 | if ( ! isset( $options['color'] ) ) { |
| 32 | $options['color'] = []; |
| 33 | } |
| 34 | |
| 35 | $options['color'] = array_merge( |
| 36 | $options['color'], |
| 37 | [ |
| 38 | 'name' => $this->options['name'] . '_color_picker', |
| 39 | 'default' => isset( $this->options['default'] ) |
| 40 | ? $this->options['default']['color'] |
| 41 | : null, |
| 42 | 'pickerTarget' => '.factory-control-' . $this->options['name'] . ' .factory-picker-target', |
| 43 | ] |
| 44 | ); |
| 45 | |
| 46 | if ( ! $options['color']['default'] ) { |
| 47 | $options['color']['default'] = '#1e8cbe'; |
| 48 | } |
| 49 | |
| 50 | $name = $this->getOption( 'name' ); |
| 51 | |
| 52 | // filters to get available patterns for the given background contols |
| 53 | $this->patterns = apply_filters( 'wbcr_factory_forms_480_patterns', [] ); |
| 54 | $this->patterns = apply_filters( 'wbcr_factory_forms_480_patterns-' . $name, $this->patterns ); |
| 55 | |
| 56 | $this->custom_patterns = $this->getOption( 'patterns', [] ); |
| 57 | |
| 58 | $this->color = new Wbcr_FactoryForms600_ColorControl( $options['color'], $form, $provider ); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Shows the html markup of the control. |
| 63 | * |
| 64 | * @since 1.0.0 |
| 65 | * @return void |
| 66 | */ |
| 67 | public function html() { |
| 68 | $name = $this->getNameOnForm(); |
| 69 | $values = $this->getValue(); |
| 70 | |
| 71 | // if a pattern is not set by defaut, sets the first available pattern |
| 72 | if ( empty( $values['url'] ) && ! empty( $this->patterns ) ) { |
| 73 | foreach ( $this->patterns as $group_key => $groupValue ) { |
| 74 | if ( ! empty( $this->patterns[ $group_key ]['patterns'] ) ) { |
| 75 | $values['url'] = $this->patterns[ $group_key ]['patterns'][0]['pattern']; |
| 76 | break; |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | if ( ! empty( $values['color'] ) ) { |
| 82 | $this->color->setOption( 'value', $values['color'] ); |
| 83 | } |
| 84 | |
| 85 | $hasColor = ! empty( $values['color'] ); |
| 86 | |
| 87 | if ( $hasColor ) { |
| 88 | $this->addCssClass( 'factory-color-panel-active' ); |
| 89 | } |
| 90 | |
| 91 | ?> |
| 92 | <div <?php $this->attrs(); ?>> |
| 93 | <div class="factory-pattern-controls"> |
| 94 | <div class="factory-preview-wrap"> |
| 95 | <div |
| 96 | <?php |
| 97 | echo ( ! empty( $values['url'] ) ) |
| 98 | ? 'style="background:url(' . esc_url( $values['url'] ) . ') repeat; border:0; font-size:0;"' |
| 99 | : ''; |
| 100 | ?> |
| 101 | class="factory-preview <?php echo esc_html( $this->getOption( 'name' ) ); ?>"><span></span> |
| 102 | </div> |
| 103 | </div> |
| 104 | <a href="#" class="button button-default factory-button factory-change-color-btn |
| 105 | <?php |
| 106 | if ( $hasColor ) { |
| 107 | echo 'button-active'; |
| 108 | } |
| 109 | ?> |
| 110 | " title="<?php _e( 'Change color', 'robin-image-optimizer' ); ?>"> |
| 111 | <i class="fa fa-flask"></i> |
| 112 | <span><?php _e( 're-color', 'robin-image-optimizer' ); ?></span> |
| 113 | </a> |
| 114 | <input type="hidden" id="<?php echo esc_attr( $name[0] ); ?>" name="<?php echo esc_attr( $name[0] ); ?>" value="<?php echo esc_url( $values['url'] ); ?>" class="factory-pattern-result"> |
| 115 | <input type="hidden" id="<?php echo esc_attr( $name[1] ); ?>" name="<?php echo esc_attr( $name[1] ); ?>" value="<?php echo esc_attr( $values['color'] ); ?>" class="factory-color-result"> |
| 116 | </div> |
| 117 | <div class="factory-color-panel"> |
| 118 | <div class="factory-color-wrap"> |
| 119 | <span class="factory-color-label"><?php _e( 'Select color:', 'robin-image-optimizer' ); ?></span> |
| 120 | <?php $this->color->html(); ?> |
| 121 | <div class="factory-hint"> |
| 122 | <i><?php _e( 'Changing the color may take a minute or more. Please be patient.', 'robin-image-optimizer' ); ?></i> |
| 123 | </div> |
| 124 | </div> |
| 125 | <div class="factory-picker-target"></div> |
| 126 | </div> |
| 127 | <div class="factory-patterns-panel"> |
| 128 | <div class="factory-patterns-group factory-patterns-group-custom"> |
| 129 | <?php $this->printPatterns( $this->custom_patterns, 4, '<div class="factory-patterns-item factory-upload-btn factory-no-preview"><span class="fa fa-upload"></span></div>' ); ?> |
| 130 | </div> |
| 131 | <?php foreach ( $this->patterns as $key => $group ) : ?> |
| 132 | <?php if ( ! empty( $group['patterns'] ) ) : ?> |
| 133 | <div class="factory-patterns-group factory-patterns-group-<?php echo esc_attr( $key ); ?>"> |
| 134 | <div class="factory-patterns-group-title"><?php echo esc_html( $group['title'] ); ?></div> |
| 135 | <?php $this->printPatterns( $group['patterns'], 4 ); ?> |
| 136 | </div> |
| 137 | <?php endif; ?> |
| 138 | <?php endforeach; ?> |
| 139 | </div> |
| 140 | <div class="clearfix"></div> |
| 141 | </div> |
| 142 | <?php |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * @param $patterns |
| 147 | * @param $perRow |
| 148 | * @param null $first_item |
| 149 | */ |
| 150 | private function printPatterns( $patterns, $perRow, $first_item = null ) { |
| 151 | $counter = 0; |
| 152 | $print_first_item = $first_item; |
| 153 | |
| 154 | ?> |
| 155 | <div class="factory-patterns-row"> |
| 156 | <?php |
| 157 | |
| 158 | if ( $print_first_item ) { |
| 159 | echo $print_first_item; |
| 160 | $print_first_item = null; |
| 161 | ++$counter; |
| 162 | } |
| 163 | |
| 164 | foreach ( $patterns as $pattern ) { |
| 165 | ++$counter; |
| 166 | |
| 167 | ?> |
| 168 | <div class="factory-patterns-item" data-pattern="<?php echo $pattern['pattern']; ?>"> |
| 169 | <div class="factory-pattern-holder" style="background:url(<?php echo $pattern['preview']; ?>) repeat;"></div> |
| 170 | </div> |
| 171 | <?php |
| 172 | |
| 173 | if ( $counter == 4 ) { |
| 174 | $counter = 0; |
| 175 | ?> |
| 176 | </div><div class="factory-patterns-row"> |
| 177 | <?php |
| 178 | } |
| 179 | } |
| 180 | ?> |
| 181 | </div> |
| 182 | <?php |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 |