PluginProbe
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts / 2.3.1
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts v2.3.1
2.7.7 2.7.6 2.7.5 2.7.4 trunk 1.3 2.0.4 2.0.6 2.1.91 2.2.4 2.2.7 2.2.9 2.3.1 2.3.10 2.4.10 2.4.2 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.6.0 2.6.1 2.7.0 All 28 releases
insert-php / libs / factory / forms / controls / pattern.php

pattern.php in Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts 2.3.1, at libs/factory/forms/controls/pattern.php

182 lines 5.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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_FactoryForms420_PatternControl') ) {
19
20 class Wbcr_FactoryForms420_PatternControl extends Wbcr_FactoryForms420_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_420_patterns', array());
56 $this->patterns = apply_filters('wbcr_factory_forms_420_patterns-' . $name, $this->patterns);
57
58 $this->custom_patterns = $this->getOption('patterns', array());
59
60 $this->color = new Wbcr_FactoryForms420_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 $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_420') ?>">
106 <i class="fa fa-flask"></i>
107 <span><?php _e('re-color', 'wbcr_factory_forms_420') ?></span>
108 </a>
109 <input type="hidden" id="<?php echo $name[0]; ?>" name="<?php echo $name[0]; ?>" value="<?php echo esc_url($values['url']); ?>" class="factory-pattern-result">
110 <input type="hidden" id="<?php echo $name[1]; ?>" name="<?php echo $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_420') ?></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_420') ?></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 $key ?>">
129 <div class="factory-patterns-group-title"><?php echo $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