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