PluginProbe
LoftLoader / 1.0.1
LoftLoader v1.0.1
trunk 1.0.0 1.0.1 1.0.2 2.0.0 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.3 2.3.1 2.3.2 2.3.3 All 34 releases
loftloader / configs / loftloader-config.php

loftloader-config.php in LoftLoader 1.0.1, at configs/loftloader-config.php

342 lines 14.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // Not allowed by directly accessing.
3 if(!defined('ABSPATH')){
4 die('Access not allowed!');
5 }
6 /**
7 * Configuration file for plugin option sections
8 * fields and the default settings
9 *
10 * @package LoftLoader
11 * @version 1.0
12 * @link http://www.loftocean.com/
13 * @author Suihai Huang from Loft Ocean Team
14
15 * @since version 1.0
16 */
17
18 if(!file_exists('loftloader_settings_fields') && !file_exists('loftloader_settings_default_value')){
19 add_filter('loftloader_settings_fields', 'loftloader_settings_fields');
20 /**
21 * @description hook callback function to register the fields of loftloader
22 * @param array $fields
23 * @return array merge fields to the array passed by
24 */
25 function loftloader_settings_fields($fields = array()){
26 return array_merge((array)$fields, array(
27 array(
28 'title' => esc_html__('Show Preloader', 'loftloader'),
29 'args' => array(),
30 'content' => array(
31 array(
32 'name' => 'enable',
33 'type' => 'Checkbox',
34 'title' => esc_html__('Enable LoftLoader', 'loftloader'),
35 'description' => esc_html__('Suggest keep it enabled if the site has a lot of images or large videos.', 'loftloader'),
36 'options' => array(
37 'on' => array('label' => '')
38 ),
39 'extra' => array(
40 'class' => 'loftloader-enabled'
41 )
42 ),
43 array(
44 'name' => 'homepage',
45 'type' => 'Checkbox',
46 'title' => esc_html__('For homepage only', 'loftloader'),
47 'description' => esc_html__('If enabled, the LoftLoader will be shown on homepage only', 'loftloader'),
48 'options' => array(
49 'on' => array('label' => '')
50 ),
51 'extra' => array(
52 'class' => 'loftloader-enable-homepage-only'
53 )
54 )
55 )
56 ),
57 array(
58 'title' => '',
59 'args' => array('nolist' => true, 'nowrap' => true),
60 'content' => array(
61 array(
62 'name' => 'settings',
63 'type' => 'Preloader_Preview',
64 'title' => '',
65 'description' => '',
66 'options' => array(
67 array(
68 'section' => 'preview',
69 'title' => esc_html__('Preview', 'loftloader'),
70 'description' => esc_html__('Hover onto frame below to preview ending animation.', 'loftloader')
71 ),
72 array(
73 'section' => 'setting',
74 'content' => array(
75 array(
76 'title' => esc_html__('Background', 'loftloader'),
77 'content' => array(
78 array(
79 'name' => 'background[effect]',
80 'type' => 'select',
81 'title' => esc_html__('Select preloader ending animation', 'loftloader'),
82 'options' => array(
83 'fade' => array('label' => esc_html__('Fade', 'loftloader')),
84 'slide-left-right' => array('label' => esc_html__('Slide Left & Right', 'loftloader')),
85 'slide-up' => array('label' => esc_html__('Slide Up', 'loftloader')),
86 'slide-up-down' => array('label' => esc_html__('Slide Up & Down', 'loftloader'), 'selected' => true)
87 ),
88 'extra' => array(
89 'id' => 'preloader-background-style',
90 )
91 ),
92 array(
93 'name' => 'background[color]',
94 'type' => 'color-picker',
95 'title' => esc_html__('Preloader background color', 'loftloader'),
96 'options' => array(
97 'defaultValue' => '#222222'
98 ),
99 'extra' => array(
100 'id' => 'preloader-background-color',
101 )
102 ),
103 array(
104 'name' => 'background[opacity]',
105 'type' => 'slider',
106 'title' => esc_html__('Preloader background opacity', 'loftloader'),
107 'options' => array(
108 'default' => 100,
109 'min' => 0,
110 'max' => 100,
111 'step' => 5
112 ),
113 'extra' => array(
114 'class' => 'slider-opacity'
115 )
116 )
117 )
118 ),
119 array(
120 'title' => esc_html__('Animation', 'loftloader'),
121 'content' => array(
122 array(
123 'name' => 'animation[type]',
124 'type' => 'select',
125 'title' => esc_html__('Select preloader loading animation', 'loftloader'),
126 'options' => array(
127 'pl-sun' => array('label' => esc_html__('1 - Spinning Sun', 'loftloader')),
128 'pl-circles' => array('label' => esc_html__('2 - Luminous Circles', 'loftloader')),
129 'pl-wave' => array('label' => esc_html__('3 - Wave', 'loftloader')),
130 'pl-square' => array('label' => esc_html__('4 - Spinning Square', 'loftloader')),
131 'pl-frame' => array('label' => esc_html__('5 - Drawing Frame', 'loftloader')),
132 'pl-imgloading' => array('label' => esc_html__('6 - Loading Custom Image', 'loftloader'))
133 ),
134 'extra' => array(
135 'id' => 'preloader-animation',
136 'class' => 'preloader-dependency-parent'
137 )
138 ),
139 array(
140 'name' => 'animation[color]',
141 'type' => 'color-picker',
142 'title' => esc_html__('Preloader animation color', 'loftloader'),
143 'options' => array(
144 'defaultValue' => '#222222'
145 ),
146 'extra' => array(
147 'id' => 'preloader-animation-color',
148 'wrapperClass' => 'preloader_animation preloader_animation-pl-sun preloader_animation-pl-circles preloader_animation-pl-wave preloader_animation-pl-square preloader_animation-pl-frame'
149 )
150 ),
151 array(
152 'name' => 'animation[image]',
153 'type' => 'media',
154 'title' => esc_html__('Upload custom image/logo', 'loftloader'),
155 'options' => array(
156 'removeButton' => true
157 ),
158 'extra' => array(
159 'wrapperClass' => 'preloader_animation preloader_animation-pl-frame preloader_animation-pl-imgloading'
160 )
161 ),
162 array(
163 'name' => 'animation[width]',
164 'type' => 'number',
165 'title' => esc_html__('Custom image width - optional (if provided, the value should be between 1 - 400)', 'loftloader'),
166 'options' => array(),
167 'extra' => array(
168 'wrapperClass' => 'preloader_animation preloader_animation-pl-imgloading preloader-custom-image-width'
169 )
170 )
171 )
172 )
173 )
174 )
175 )
176 )
177 )
178 )
179 ));
180 }
181 add_filter('loftloader_settings_default_value', 'loftloader_settings_default_value');
182 /**
183 * @description hook callback function to set the default value of loftloader settings
184 * @param array $settings
185 * @return array merge values to the array passed by
186 */
187 function loftloader_settings_default_value($settings){
188 return array_merge((array)$settings, array(
189 'enable' => 'on',
190 'homepage' => '',
191 'settings' => array(
192 'background' => array(
193 'effect' => 'fade',
194 'color' => '#000000',
195 'opacity' => '95%'
196 ),
197 'animation' => array(
198 'type' => 'pl-sun',
199 'color' => '#248acc',
200 'image' => array(
201 'url' => LOFTLOADER_URI . 'img/loftloader-logo.png',
202 'id' => ''
203 ),
204 'width' => '76'
205 )
206 )
207 ));
208 }
209 }
210
211 if(!class_exists('LoftLoader_Setting_Manager')){
212 /**
213 * LoftLoader settings manager class
214 *
215 * @since LoftLoader version 1.0
216 */
217 require_once LOFTLOADER_ROOT . 'settings/form/class-loftloader-form-base.php';
218 require_once LOFTLOADER_ROOT . 'settings/form/class-loftloader-checkbox.php';
219 require_once LOFTLOADER_ROOT . 'settings/form/class-loftloader-preview.php';
220 class LoftLoader_Setting_Manager {
221 public $section_id; // Section unique id
222 protected $section_title; // Section title
223 protected $extra_info; // Other arguments needed when registered the sections
224 public function __construct(){
225 $this->section_id = 'loftloader-custom-settings';
226 $this->section_title = esc_html__('LoftLoader Settings', 'loftloader');
227 }
228 /**
229 * @description render setting section content
230 */
231 public function render_settings_section(){
232 // Register the section
233 echo '<h1 class="loftloader-option-section-title">' . $this->section_title . '</h1>';
234 $fields = apply_filters('loftloader_settings_fields', array()); // Get all fields of current section
235 if($fields && is_array($fields)){
236 foreach($fields as $field){
237 echo (isset($field['args']['nowrap']) && $field['args']['nowrap']) ? '' : '<div class="setting-group">';
238 echo empty ($field['title']) ? '' : '<h3>' . $field['title'] . '</h3>';
239 $this->render_settings_field(array('admin' => $field['args'], 'form' => $field['content']));
240 echo (isset($field['args']['nowrap']) && $field['args']['nowrap']) ? '' : '</div>';
241 }
242 }
243 $this->settings_fields(); // Show the hidden fields
244 }
245 /**
246 * @description output the form elements of each fields registered
247 */
248 private function render_settings_field($args){
249 $default = apply_filters('loftloader_settings_default_value', array());
250 $default = isset($default) ? $default : array();
251 $values = get_option($this->section_id, $default);
252 $inList = !empty($args['admin']['nolist']) ? false : true; // Wrap the output html in ul list or not
253
254 echo $inList ? '<ul class="form-list">' : '';
255 foreach($args['form'] as $element){ // Output each form elements
256 if(!empty($element)){
257 $class = 'LoftLoader_' . $element['type']; // Get class name of element type
258 // Get the value and name of each element
259 if(strpos($element['name'], '[') !== false){
260 $subs = strtr($element['name'], array(']' => '', '[' => ']['));
261 $name = $this->section_id . '[' . $subs . ']'; // Name of each form element
262 $value = $values;
263 foreach(explode('][', $subs) as $sub){
264 $value = !empty($value[$sub]) ? $value[$sub] : '';
265 }
266 }
267 else{
268 $name = $this->section_id . '[' . $element['name'] . ']'; // Name of each form element
269 $value = !empty($values[$element['name']]) ? $values[$element['name']] : ''; // Value of each element
270 }
271 $extra = isset($element['extra']) ? $element['extra'] : array(); // Any extra arguments
272 $options = isset($element['options']) ? $element['options'] : array(); // Options for some form elements, like checkbox/radio/select
273 $newField = new $class($name, $element['title'], $element['description'], $options, $value, $extra); // Instantiate the element
274 echo $inList ? '<li>' : '';
275 $newField->render(); // Output the element
276 echo $inList ? '</li>' : '';
277 }
278 }
279 echo $inList ? '</ul>' : '';
280 }
281 /*
282 * @description show the hidden input
283 */
284 private function settings_fields(){
285 $page = $this->section_id;
286 echo "<input type='hidden' name='option_page' value='" . $page . "' />";
287 echo '<input type="hidden" name="action" value="update" />';
288 wp_nonce_field("$page-options");
289 }
290 /**
291 * @description register setting for saving custom settings
292 */
293 public function register_setting(){
294 global $new_whitelist_options;
295 $option_group = $option_name = $this->section_id;
296 $new_whitelist_options[$option_group][] = $option_name;
297 add_filter("sanitize_option_{$option_name}", array($this, 'save_custom_styles'));
298 }
299 /**
300 * @description save the custom styles from the custom plugin settings
301 */
302 public function save_custom_styles($args){
303 $css = '';
304 if(isset($args['enable']) && ($args['enable'] === 'on')){
305 $color = $args['settings']['animation']['color'];
306 $bgColor = $args['settings']['background']['color'];
307 $bgOpacity = intval($args['settings']['background']['opacity']) / 100;
308 $css .= '#loftloader-wrapper .loader-section {' . PHP_EOL . "\t" . 'background: ' . $bgColor . ';' . PHP_EOL . "\t" . 'opacity: ' . $bgOpacity . ';' . PHP_EOL . '}' . PHP_EOL;
309 switch($args['settings']['animation']['type']){
310 case 'pl-sun':
311 $css .= '#loftloader-wrapper.pl-sun #loader span,' . PHP_EOL . '#loftloader-wrapper.pl-sun #loader span:before {' . PHP_EOL . "\t" . 'background: ' . $color . ';' . PHP_EOL . '}' . PHP_EOL;
312 break;
313 case 'pl-circles':
314 $css .= '#loftloader-wrapper.pl-circles #loader span,' . PHP_EOL . '#loftloader-wrapper.pl-circles #loader:before,' . PHP_EOL . '#loftloader-wrapper.pl-circles #loader:after {' . PHP_EOL . "\t" . 'background: ' . $color . ';' . PHP_EOL . '}' . PHP_EOL;
315 break;
316 case 'pl-wave':
317 $css .= '#loftloader-wrapper.pl-wave #loader span,' . PHP_EOL . '#loftloader-wrapper.pl-wave #loader:before,' . PHP_EOL . '#loftloader-wrapper.pl-wave #loader:after {' . PHP_EOL . "\t" . 'background: ' . $color . ';' . PHP_EOL . '}' . PHP_EOL;
318 break;
319 case 'pl-square':
320 $css .= '#loftloader-wrapper.pl-square #loader span {' . PHP_EOL . "\t" . 'border: 4px solid ' . $color . ';' . PHP_EOL . '}' . PHP_EOL;
321 break;
322 case 'pl-frame':
323 $css .= '#loftloader-wrapper.pl-frame #loader:before,' . PHP_EOL . '#loftloader-wrapper.pl-frame #loader:after,' . PHP_EOL . '#loftloader-wrapper.pl-frame #loader span:before,' . PHP_EOL . '#loftloader-wrapper.pl-frame #loader span:after {' . PHP_EOL . "\t" . 'background-color: ' . $color . ';' . PHP_EOL . '}' . PHP_EOL;
324 break;
325 case 'pl-imgloading':
326 $css .= empty($args['settings']['animation']['width']) ? '' : '#loftloader-wrapper.pl-imgloading #loader {' . PHP_EOL . "\t" . 'width: ' . $args['settings']['animation']['width'] . 'px;' . PHP_EOL . '}' . PHP_EOL;
327 $css .= '#loftloader-wrapper.pl-imgloading #loader span {' . PHP_EOL . "\t" . 'background-size: cover;' . PHP_EOL . "\t" . 'background-image: url(' . $args['settings']['animation']['image']['url'] . ');' . PHP_EOL . '}' . PHP_EOL;
328 break;
329 }
330 }
331 update_option('loftloader-custom-styles', $css);
332 return $args;
333 }
334 /**
335 * @description reset loader setting and custom styles
336 */
337 public function reset_settings(){
338 delete_option('loftloader-custom-styles');
339 delete_option('loftloader-custom-settings');
340 }
341 }
342 }