| 1 |
<?php |
| 2 |
|
| 3 |
defined( 'ABSPATH' ) || exit; |
| 4 |
|
| 5 |
class WPRMenu_Framework_Interface { |
| 6 |
|
| 7 |
public function __construct(){ |
| 8 |
|
| 9 |
add_filter( 'safe_style_css', array( $this, 'safe_css_attributes' ), 10, 1 ); |
| 10 |
} |
| 11 |
|
| 12 |
public function safe_css_attributes( $styles ){ |
| 13 |
$styles[] = 'display'; |
| 14 |
$styles[] = 'visibility'; |
| 15 |
$styles[] = 'top'; |
| 16 |
$styles[] = 'left'; |
| 17 |
return $styles; |
| 18 |
} |
| 19 |
|
| 20 |
static $allowed_html = array( |
| 21 |
'div' => array( |
| 22 |
'class' => true, |
| 23 |
'id' => true, |
| 24 |
'data-*' => true, |
| 25 |
'style' => true, |
| 26 |
'title' => true, |
| 27 |
'role' => true |
| 28 |
), |
| 29 |
'input' => array( |
| 30 |
'type' => true, |
| 31 |
'class' => true, |
| 32 |
'name' => true, |
| 33 |
'id' => true, |
| 34 |
'value' => true, |
| 35 |
'autocomplete' => true, |
| 36 |
'checked' => true, |
| 37 |
'style' => true, |
| 38 |
), |
| 39 |
'h3' => array( |
| 40 |
'class' => true, |
| 41 |
'id' => true, |
| 42 |
), |
| 43 |
'h4' => array( |
| 44 |
'class' => true, |
| 45 |
'id' => true, |
| 46 |
), |
| 47 |
'a' => array( |
| 48 |
'href' => true, |
| 49 |
'id' => true, |
| 50 |
'class' => true, |
| 51 |
), |
| 52 |
'select' => array( |
| 53 |
'id' => true, |
| 54 |
'class' => true, |
| 55 |
'name' => true, |
| 56 |
), |
| 57 |
'option' => array( |
| 58 |
'selected' => true, |
| 59 |
'value' => true, |
| 60 |
), |
| 61 |
'label' => array( |
| 62 |
'id' => true, |
| 63 |
'class' => true, |
| 64 |
'for' => true, |
| 65 |
'style' => true, |
| 66 |
), |
| 67 |
'span' => array( |
| 68 |
'class' => true, |
| 69 |
'data-*' => true, |
| 70 |
'title' => true, |
| 71 |
'aria-*' => true, |
| 72 |
), |
| 73 |
'ul' => array( |
| 74 |
'class' => true, |
| 75 |
'id' => true, |
| 76 |
), |
| 77 |
'li' => array( |
| 78 |
'class' => true, |
| 79 |
'id' => true, |
| 80 |
), |
| 81 |
'i' => array( |
| 82 |
'class' => true, |
| 83 |
), |
| 84 |
'img' => array( |
| 85 |
'src' => true, |
| 86 |
'class' => true, |
| 87 |
), |
| 88 |
'textarea' => array( |
| 89 |
'name' => true, |
| 90 |
'id' => true, |
| 91 |
'class' => true, |
| 92 |
), |
| 93 |
); |
| 94 |
|
| 95 |
/** |
| 96 |
* Generates the tabs that are used in the options menu |
| 97 |
*/ |
| 98 |
static function wpr_optionsframework_tabs() { |
| 99 |
$counter = 0; |
| 100 |
$options = & WPRMenu_Framework::_wpr_optionsframework_options(); |
| 101 |
$menu = ''; |
| 102 |
|
| 103 |
foreach ( $options as $value ) { |
| 104 |
|
| 105 |
// Heading for Navigation |
| 106 |
if ( $value['type'] == "heading" ) { |
| 107 |
$counter++; |
| 108 |
$class = ''; |
| 109 |
$helper_class = 'helper'; |
| 110 |
$helper = isset($value['helper']) ? esc_html( $value['helper'] ) : ''; |
| 111 |
$class = ! empty( $value['id'] ) ? $value['id'] : $value['name']; |
| 112 |
$class = preg_replace( '/[^a-zA-Z0-9._\-]/', '', strtolower($class) ) . '-tab'; |
| 113 |
$menu .= '<a id="options-group-'. $counter . '-tab" class="nav-tab ' . $class .'" title="' . esc_attr( $value['name'] ) . '" href="' . esc_attr( '#options-group-'. $counter ) . '">' . esc_html( $value['name'] ) . '<span class="'.$helper_class.'">' . $helper . '</span></a>'; |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
return $menu; |
| 118 |
} |
| 119 |
|
| 120 |
/** |
| 121 |
* Generates the options fields that are used in the form. |
| 122 |
*/ |
| 123 |
static function wpr_optionsframework_fields() { |
| 124 |
global $allowedtags; |
| 125 |
$wpr_optionsframework_settings = get_option( 'wpr_optionsframework' ); |
| 126 |
|
| 127 |
// Gets the unique option id |
| 128 |
if ( isset( $wpr_optionsframework_settings['id'] ) ) { |
| 129 |
$option_name = $wpr_optionsframework_settings['id']; |
| 130 |
} |
| 131 |
else { |
| 132 |
$option_name = 'wpr_optionsframework'; |
| 133 |
}; |
| 134 |
|
| 135 |
$settings = get_option($option_name); |
| 136 |
$options = & WPRMenu_Framework::_wpr_optionsframework_options(); |
| 137 |
|
| 138 |
$counter = 0; |
| 139 |
$menu = ''; |
| 140 |
|
| 141 |
foreach ( $options as $value ) { |
| 142 |
|
| 143 |
$val = ''; |
| 144 |
$select_value = ''; |
| 145 |
$output = ''; |
| 146 |
|
| 147 |
// Wrap all options |
| 148 |
if ( ( $value['type'] != "heading" ) |
| 149 |
&& ( $value['type'] != "info" ) ) { |
| 150 |
|
| 151 |
// Keep all ids lowercase with no spaces |
| 152 |
$value['id'] = preg_replace('/[^a-zA-Z0-9._\-]/', '', strtolower($value['id']) ); |
| 153 |
|
| 154 |
$id = 'section-' . $value['id']; |
| 155 |
|
| 156 |
$class = 'section'; |
| 157 |
|
| 158 |
if ( isset( $value['type'] ) ) { |
| 159 |
$class .= ' section-' . $value['type']; |
| 160 |
} |
| 161 |
|
| 162 |
if ( isset( $value['class'] ) ) { |
| 163 |
$class .= ' ' . $value['class']; |
| 164 |
} |
| 165 |
|
| 166 |
// If there is a description save it for labels |
| 167 |
$explain_value = ''; |
| 168 |
|
| 169 |
if ( isset( $value['desc'] ) ) { |
| 170 |
$explain_value = $value['desc']; |
| 171 |
} |
| 172 |
|
| 173 |
$output .= '<div id="' . esc_attr( $id ) .'" class="row ' . esc_attr( $class ) . '">'."\n"; |
| 174 |
|
| 175 |
if ( isset( $value['name'] ) ) { |
| 176 |
$output .= '<div class="col-md-5 heading"><span class="label-wrapper pull-left"><label class="explain" for="' . esc_attr( $value['id'] ) . '">' . esc_html( $value['name'] ) . '</label></span>'; |
| 177 |
|
| 178 |
if( $explain_value != '' ) |
| 179 |
$output .= '<span class="dashicons dashicons-info pull-right" data-toggle="tooltip" data-placement="top" title="'. wp_kses( $explain_value, $allowedtags) .'"></span>'; |
| 180 |
$output .= '</div>' . "\n"; |
| 181 |
} |
| 182 |
|
| 183 |
if ( $value['type'] != 'editor' ) { |
| 184 |
$output .= '<div class="col-md-7 option">' . "\n" . '<div class="controls">' . "\n"; |
| 185 |
} |
| 186 |
|
| 187 |
else { |
| 188 |
$output .= '<div class="option">' . "\n" . '<div>' . "\n"; |
| 189 |
} |
| 190 |
} |
| 191 |
|
| 192 |
// Set default value to $val |
| 193 |
if ( isset( $value['std'] ) ) { |
| 194 |
$val = $value['std']; |
| 195 |
} |
| 196 |
|
| 197 |
// If the option is already saved, override $val |
| 198 |
if ( ( $value['type'] != 'heading' ) && ( $value['type'] != 'info') ) { |
| 199 |
if ( isset( $settings[($value['id'])]) ) { |
| 200 |
$val = $settings[($value['id'])]; |
| 201 |
// Striping slashes of non-array options |
| 202 |
if ( !is_array($val) ) { |
| 203 |
$val = stripslashes( $val ); |
| 204 |
} |
| 205 |
} |
| 206 |
} |
| 207 |
|
| 208 |
// Set the placeholder if one exists |
| 209 |
$placeholder = ''; |
| 210 |
if ( isset( $value['placeholder'] ) ) { |
| 211 |
$placeholder = ' placeholder="' . esc_attr( $value['placeholder'] ) . '"'; |
| 212 |
} |
| 213 |
|
| 214 |
if ( has_filter( 'wpr_optionsframework_' . $value['type'] ) ) { |
| 215 |
$output .= apply_filters( 'wpr_optionsframework_' . $value['type'], $option_name, $value, $val ); |
| 216 |
} |
| 217 |
|
| 218 |
|
| 219 |
switch ( $value['type'] ) { |
| 220 |
|
| 221 |
// Code |
| 222 |
case 'code': |
| 223 |
$output .= '<div id="' . esc_attr( $value['id'] ) . '" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '"></div>'; |
| 224 |
$output .= '<textarea name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" id="' . esc_attr( $value['id'] ) . '_textarea" style="display: none">'.esc_attr( $val ).'</textarea>'; |
| 225 |
break; |
| 226 |
|
| 227 |
case 'text' : |
| 228 |
$suffix = ''; |
| 229 |
if( isset( $value['suffix'] ) && $value['suffix'] == 'px' ) { |
| 230 |
$suffix = '<span class="wprmenu-suffix">px</span>'; |
| 231 |
} |
| 232 |
$output .= '<input id="' . esc_attr( $value['id'] ) . '" class="form-control enable-suffix" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" type="text" value="' . esc_attr( $val ) . '"' . $placeholder . ' />' . $suffix ; |
| 233 |
break; |
| 234 |
|
| 235 |
// Password input |
| 236 |
case 'password': |
| 237 |
$output .= '<input id="' . esc_attr( $value['id'] ) . '" class="of-input" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" type="password" value="' . esc_attr( $val ) . '" />'; |
| 238 |
break; |
| 239 |
|
| 240 |
// Textarea |
| 241 |
case 'textarea': |
| 242 |
$rows = '8'; |
| 243 |
|
| 244 |
if ( isset( $value['settings']['rows'] ) ) { |
| 245 |
$custom_rows = $value['settings']['rows']; |
| 246 |
|
| 247 |
if ( is_numeric( $custom_rows ) ) { |
| 248 |
$rows = $custom_rows; |
| 249 |
} |
| 250 |
} |
| 251 |
|
| 252 |
$val = stripslashes( $val ); |
| 253 |
$output .= '<textarea id="' . esc_attr( $value['id'] ) . '" class="of-input" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" rows="' . $rows . '"' . $placeholder . '>' . esc_textarea( $val ) . '</textarea>'; |
| 254 |
break; |
| 255 |
|
| 256 |
// Select Box |
| 257 |
case 'select': |
| 258 |
$output .= '<select class="form-control" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" id="' . esc_attr( $value['id'] ) . '">'; |
| 259 |
|
| 260 |
foreach ($value['options'] as $key => $option ) { |
| 261 |
$output .= '<option'. selected( $val, $key, false ) .' value="' . esc_attr( $key ) . '">' . esc_html( $option ) . '</option>'; |
| 262 |
} |
| 263 |
$output .= '</select>'; |
| 264 |
break; |
| 265 |
|
| 266 |
|
| 267 |
// Radio Box |
| 268 |
case "radio": |
| 269 |
$name = $option_name .'['. $value['id'] .']'; |
| 270 |
$output .= '<div class="btn-group" data-toggle="buttons">'; |
| 271 |
|
| 272 |
foreach ($value['options'] as $key => $option) { |
| 273 |
$id = $option_name . '-' . $value['id'] .'-'. $key; |
| 274 |
$active = ''; |
| 275 |
|
| 276 |
if( $val == $key ) $active = 'active'; |
| 277 |
$output .= '<label class="radio-btn btn btn-default '. $active .'" for="' . esc_attr( $id ) . '"><input class="of-input of-radio" type="radio" name="' . esc_attr( $name ) . '" id="' . esc_attr( $id ) . '" value="'. esc_attr( $key ) . '" '. checked( $val, $key, false) .' autocomplete="off" />' . esc_html( $option ) . '</label>'; |
| 278 |
} |
| 279 |
$output .= '</div>'; |
| 280 |
break; |
| 281 |
|
| 282 |
// Image Selectors |
| 283 |
case "images": |
| 284 |
$name = $option_name .'['. $value['id'] .']'; |
| 285 |
|
| 286 |
foreach ( $value['options'] as $key => $option ) { |
| 287 |
$selected = ''; |
| 288 |
|
| 289 |
if ( $val != '' && ($val == $key) ) { |
| 290 |
$selected = ' of-radio-img-selected'; |
| 291 |
} |
| 292 |
|
| 293 |
$output .= '<input type="radio" id="' . esc_attr( $value['id'] .'_'. $key) . '" class="of-radio-img-radio" value="' . esc_attr( $key ) . '" name="' . esc_attr( $name ) . '" '. checked( $val, $key, false ) .' />'; |
| 294 |
$output .= '<div class="of-radio-img-label">' . esc_html( $key ) . '</div>'; |
| 295 |
$output .= '<img src="' . esc_url( $option ) . '" alt="' . $option .'" class="of-radio-img-img' . $selected .'" onclick="document.getElementById(\''. esc_attr($value['id'] .'_'. $key) .'\').checked=true;" />'; |
| 296 |
} |
| 297 |
break; |
| 298 |
|
| 299 |
case "hidemenupages": |
| 300 |
$cats = $val; |
| 301 |
|
| 302 |
$output .= '<select class="wprmenu-hide-menu-pages of-input" multiple="multiple" name="' . esc_attr( $option_name . '[' . $value['id'] . '][]' ) . '" id="' . esc_attr( $value['id'] ) . '">'; |
| 303 |
|
| 304 |
foreach ($value['options'] as $key => $option ) { |
| 305 |
if( is_array( $cats) && !empty( $cats ) && isset($cats[$key] ) && $cats[$key] === $option ) { |
| 306 |
$output .= '<option value="' . esc_attr( $key ) . '" selected="selected">' . esc_html( $option ) . '</option>'; |
| 307 |
} |
| 308 |
else { |
| 309 |
$output .= '<option value="' . esc_attr( $key ) . '">' . esc_html( $option ) . '</option>'; |
| 310 |
} |
| 311 |
} |
| 312 |
$output .= '</select>'; |
| 313 |
break; |
| 314 |
|
| 315 |
// Checkbox |
| 316 |
case "checkbox": |
| 317 |
$output .= '<div id="' . $option_name . '_' . $value['id'] . '" class="wprmenu_checkbox_container">'; |
| 318 |
$output .= '<div class="wprmenu_onoff_button"></div>'; |
| 319 |
$output .= '<input id="' . esc_attr( $value['id'] ) . '" class="checkbox of-input hidden" type="checkbox" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" '. checked( $val, 1, false) .' />'; |
| 320 |
$output .= '</div>'; |
| 321 |
break; |
| 322 |
|
| 323 |
// Multicheck |
| 324 |
case "multicheck": |
| 325 |
foreach ($value['options'] as $key => $option) { |
| 326 |
$checked = ''; |
| 327 |
$label = $option; |
| 328 |
$option = preg_replace('/[^a-zA-Z0-9._\-]/', '', strtolower($key)); |
| 329 |
|
| 330 |
$id = $option_name . '-' . $value['id'] . '-'. $option; |
| 331 |
$name = $option_name . '[' . $value['id'] . '][' . $option .']'; |
| 332 |
|
| 333 |
if ( isset($val[$option]) ) { |
| 334 |
$checked = checked($val[$option], 1, false); |
| 335 |
} |
| 336 |
|
| 337 |
$output .= '<input id="' . esc_attr( $id ) . '" class="checkbox of-input" type="checkbox" name="' . esc_attr( $name ) . '" ' . $checked . ' /><label for="' . esc_attr( $id ) . '">' . esc_html( $label ) . '</label>'; |
| 338 |
} |
| 339 |
|
| 340 |
break; |
| 341 |
|
| 342 |
// Color picker |
| 343 |
case "color": |
| 344 |
$default_color = ''; |
| 345 |
|
| 346 |
$class = sprintf( ' %s-form-color', 'wprmenu' ); |
| 347 |
|
| 348 |
if ( isset($value['std']) ) { |
| 349 |
if ( $val != $value['std'] ) |
| 350 |
$default_color = ' data-default-color="' .$value['std'] . '" '; |
| 351 |
} |
| 352 |
|
| 353 |
$output .= '<div class="wprmenu-color-picker">'; |
| 354 |
$output .= '<div class="input-group tinvwl-no-full">'; |
| 355 |
$output .= '<input type="text" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" id="' . esc_attr( $value['id'] ) . '" value="' . esc_attr( $val ) . '"' . $default_color .' id="' . esc_attr( $value['id'] ) . '" class="form-control form-color '.$class.' " style="">'; |
| 356 |
$output .= '<div class="input-group-btn">'; |
| 357 |
$output .= '<div class="eyedropper">'; |
| 358 |
$output .= '<a href="javascript:void(0);"><i class="eyedropper-icon"></i></a>'; |
| 359 |
$output .= '</div></div></div></div>'; |
| 360 |
|
| 361 |
break; |
| 362 |
|
| 363 |
// Uploader |
| 364 |
case "upload": |
| 365 |
$output .= WPRMenu_Framework_Media_Uploader::wpr_optionsframework_uploader( $value['id'], $val, null ); |
| 366 |
|
| 367 |
break; |
| 368 |
|
| 369 |
//Number field |
| 370 |
case "number": |
| 371 |
$output .= '<input id="' . esc_attr( $value['id'] ) . '" class="of-input" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" type="number" value="' . esc_attr( $val ) . '"' . $placeholder . ' />'; |
| 372 |
break; |
| 373 |
|
| 374 |
//Icon field |
| 375 |
case "icon": |
| 376 |
$output .= '<input id="' . esc_attr( $value['id'] ) . '" class="of-input wpr-icon-picker" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" type="text" value="' . esc_attr( $val ) . '"' . $placeholder . ' />'; |
| 377 |
break; |
| 378 |
|
| 379 |
//Sort Field |
| 380 |
case "menusort": |
| 381 |
$order = empty($val) ? 'Menu,Search,Social' : $val; |
| 382 |
$output .= '<input type="hidden" id="' . esc_attr( $value['id'] ) . '" class="of-input" name="'.esc_attr( $option_name . '[order_menu_items]' ).'" value="'.$val.'"><ul id="wpr-sortable" class="list-group">'; |
| 383 |
|
| 384 |
foreach( explode(',', $order) as $item ) { |
| 385 |
if( $item == 'Social' ) |
| 386 |
$class = 'facebook'; |
| 387 |
else |
| 388 |
$class = $item; |
| 389 |
|
| 390 |
$output .= '<li class="list-group-item list-group-item-primary" id="'.$item.'"><i class="wpr-icon-'.strtolower($class).'"></i>'.$item.'</li>'; |
| 391 |
} |
| 392 |
|
| 393 |
$output .= '</ul>'; |
| 394 |
break; |
| 395 |
|
| 396 |
//Sort Header Menu Elements |
| 397 |
case "headermenusort" : |
| 398 |
$initial_menu = 'Logo,Menu,Search,Cart,Widget Menu'; |
| 399 |
$initial_menu_arr = explode(',', $initial_menu); |
| 400 |
|
| 401 |
$order = empty($val) ? 'Logo,Menu,Search,Cart,Widget Menu' : $val; |
| 402 |
|
| 403 |
$output .= '<input type="hidden" id="'.esc_attr( $value['id']).'" class="of-input" name="'.esc_attr( $option_name . '[order_header_menu_items]').'" value="'.$val.'" >'; |
| 404 |
$output .= '<ul id="wpr-header-sortable" class="wpr-header-menu-elements list-group">'; |
| 405 |
|
| 406 |
foreach( explode(',', $order) as $key => $item ) { |
| 407 |
$order_names = strtolower($item); |
| 408 |
$order_names = str_replace(' ', '-', $order_names); |
| 409 |
$class = $item; |
| 410 |
$item_name = str_replace('-', ' ', $item); |
| 411 |
$item_name = ucwords($item_name); |
| 412 |
|
| 413 |
if( in_array($item_name, $initial_menu_arr) ) { |
| 414 |
$output .= '<li class="list-group-item list-group-item-primary" data-id="'.$order_names.'" id="'.$order_names.'">'.$item_name.'<i class="wpr-icon-eye"></i></li>'; |
| 415 |
} |
| 416 |
} |
| 417 |
$output .= '</ul>'; |
| 418 |
break; |
| 419 |
|
| 420 |
//get menus for wpml |
| 421 |
case "wpmlmenu": |
| 422 |
|
| 423 |
$langs_data = array(); |
| 424 |
if (function_exists('icl_get_languages')) { |
| 425 |
//get list of used languages from WPML |
| 426 |
$get_langs = icl_get_languages('skip_missing=N&orderby=KEY&order=DIR&link_empty_to=str'); |
| 427 |
//Set current language for language based variables in theme. |
| 428 |
$i = 0; |
| 429 |
foreach( $get_langs as $key => $langs ) { |
| 430 |
$langs_data[$i]['code'] = $langs['code']; |
| 431 |
$langs_data[$i]['name'] = $langs['native_name']; |
| 432 |
$i++; |
| 433 |
} |
| 434 |
} |
| 435 |
|
| 436 |
$output .='<div class="wpr-new-field wpml-menu">'; |
| 437 |
$output .= '<input type="button" class="btn btn-success wpml-new" value="Add New">'; |
| 438 |
$output .= '</div>'; |
| 439 |
$output .= '<div class="wpr-menu-fields">'; |
| 440 |
|
| 441 |
$output .= '<div class="wpr-new-fields">'; |
| 442 |
|
| 443 |
if( is_array($langs_data) && !empty($langs_data) ) { |
| 444 |
$output .= '<div class="menu-lang-wrap">'; |
| 445 |
$output .= '<select name="' . esc_attr( $option_name . '[' . $value['id'] . '][lang][]' ) . '" class="wprmenu-langs-list of-input">'; |
| 446 |
|
| 447 |
foreach( $langs_data as $key => $val ) { |
| 448 |
$output .= '<option value="'.$val['code'].'">'.$val['name'].'</option>'; |
| 449 |
} |
| 450 |
$output .= '</select>'; |
| 451 |
$output .= '</div>'; |
| 452 |
} |
| 453 |
|
| 454 |
$output .= '<div class="menu-name-wrap">'; |
| 455 |
|
| 456 |
$menus = get_terms( 'nav_menu',array( 'hide_empty'=>false ) ); |
| 457 |
$menu = array(); |
| 458 |
|
| 459 |
if( is_array($menus) && !empty($menus) ) { |
| 460 |
foreach( $menus as $m ) { |
| 461 |
$menu[$m->term_id] = $m->name; |
| 462 |
} |
| 463 |
} |
| 464 |
|
| 465 |
if( is_array($menu) && !empty($menu) ) { |
| 466 |
$output .= '<select name="' . esc_attr( $option_name . '[' . $value['id'] . '][menu][]' ) . '" class="wprmenu-langs-list of-input">'; |
| 467 |
foreach( $menu as $menu_name ) { |
| 468 |
$output .= '<option>'.$menu_name.'</option>'; |
| 469 |
} |
| 470 |
$output .= '</select>'; |
| 471 |
} |
| 472 |
$output .= '</div>'; |
| 473 |
|
| 474 |
|
| 475 |
$output .= '<input type="button" class="btn btn-danger pull-right" value="Remove" /></div>'; |
| 476 |
|
| 477 |
$output .= '</div>'; |
| 478 |
break; |
| 479 |
|
| 480 |
//Repeater field for social icons |
| 481 |
case "social" : |
| 482 |
$socials = json_decode( $val ); |
| 483 |
$output .='<div class="wpr-new-field"><input type="button" class="wpr-add-new btn btn-success" value="Add New"></div><div class="wpr-social-fields">'; |
| 484 |
|
| 485 |
if( is_array( $socials ) && !empty( $socials ) ) { |
| 486 |
foreach( $socials as $social ) { |
| 487 |
$output .= '<div class="wpr-new-fields"><input type="text" name="' . esc_attr( $option_name . '[' . $value['id'] . '][icon][]' ) . '" class="wpr-icon-picker" value="'.$social->icon.'">'; |
| 488 |
|
| 489 |
$output .= '<input type="text" name="' . esc_attr( $option_name . '[' . $value['id'] . '][link][]' ) . '" class="social_link form-control" value="'.$social->link.'"><input type="button" class="btn btn-danger pull-right" value="Remove" /><div class="clear"></div></div>'; |
| 490 |
} |
| 491 |
} |
| 492 |
else { |
| 493 |
$output .= '<div class="wpr-new-fields"><input type="text" name="' . esc_attr( $option_name . '[' . $value['id'] . '][icon][]' ) . '" class="wpr-icon-picker" value="">'; |
| 494 |
|
| 495 |
$output .= '<input type="text" placeholder="Enter your url here" name="' . esc_attr( $option_name . '[' . $value['id'] . '][link][]' ) . '" class="' . esc_attr( $value['id'] . '_link form-control' ) . '" value=""><input type="button" class="btn btn-danger pull-right" value="Remove" /><div class="clear"></div></div>'; |
| 496 |
} |
| 497 |
$output .= '</div>'; |
| 498 |
break; |
| 499 |
|
| 500 |
// Showcase and demo import |
| 501 |
case "showcase": |
| 502 |
$output .= '<div class="wprmenu-showcase-wrapper">'; |
| 503 |
// $output .= WPRMenu_Framework_Interface::wprmenu_get_demodata(); |
| 504 |
$output .= '</div>'; |
| 505 |
break; |
| 506 |
|
| 507 |
// Background |
| 508 |
case 'background': |
| 509 |
|
| 510 |
$background = $val; |
| 511 |
|
| 512 |
// Background Color |
| 513 |
$default_color = ''; |
| 514 |
|
| 515 |
if ( isset( $value['std']['color'] ) ) { |
| 516 |
if ( $val != $value['std']['color'] ) |
| 517 |
$default_color = ' data-default-color="' .$value['std']['color'] . '" '; |
| 518 |
} |
| 519 |
|
| 520 |
$output .= '<input name="' . esc_attr( $option_name . '[' . $value['id'] . '][color]' ) . '" id="' . esc_attr( $value['id'] . '_color' ) . '" class="of-color of-background-color" type="text" value="' . esc_attr( $background['color'] ) . '"' . $default_color .' />'; |
| 521 |
|
| 522 |
// Background Image |
| 523 |
if ( !isset($background['image']) ) { |
| 524 |
$background['image'] = ''; |
| 525 |
} |
| 526 |
|
| 527 |
$output .= WPRMenu_Framework_Media_Uploader::wpr_optionsframework_uploader( $value['id'], $background['image'], null, esc_attr( $option_name . '[' . $value['id'] . '][image]' ) ); |
| 528 |
|
| 529 |
$class = 'of-background-properties'; |
| 530 |
|
| 531 |
if ( '' == $background['image'] ) { |
| 532 |
$class .= ' hide'; |
| 533 |
} |
| 534 |
$output .= '<div class="' . esc_attr( $class ) . '">'; |
| 535 |
|
| 536 |
// Background Repeat |
| 537 |
$output .= '<select class="of-background of-background-repeat" name="' . esc_attr( $option_name . '[' . $value['id'] . '][repeat]' ) . '" id="' . esc_attr( $value['id'] . '_repeat' ) . '">'; |
| 538 |
$repeats = wpr_of_recognized_background_repeat(); |
| 539 |
|
| 540 |
foreach ($repeats as $key => $repeat) { |
| 541 |
$output .= '<option value="' . esc_attr( $key ) . '" ' . selected( $background['repeat'], $key, false ) . '>'. esc_html( $repeat ) . '</option>'; |
| 542 |
} |
| 543 |
$output .= '</select>'; |
| 544 |
|
| 545 |
// Background Position |
| 546 |
$output .= '<select class="of-background of-background-position" name="' . esc_attr( $option_name . '[' . $value['id'] . '][position]' ) . '" id="' . esc_attr( $value['id'] . '_position' ) . '">'; |
| 547 |
$positions = wpr_of_recognized_background_position(); |
| 548 |
|
| 549 |
foreach ($positions as $key=>$position) { |
| 550 |
$output .= '<option value="' . esc_attr( $key ) . '" ' . selected( $background['position'], $key, false ) . '>'. esc_html( $position ) . '</option>'; |
| 551 |
} |
| 552 |
$output .= '</select>'; |
| 553 |
|
| 554 |
// Background Attachment |
| 555 |
$output .= '<select class="of-background of-background-attachment" name="' . esc_attr( $option_name . '[' . $value['id'] . '][attachment]' ) . '" id="' . esc_attr( $value['id'] . '_attachment' ) . '">'; |
| 556 |
$attachments = wpr_of_recognized_background_attachment(); |
| 557 |
|
| 558 |
if( is_array($attachments) && !empty($attachments) ) { |
| 559 |
foreach ($attachments as $key => $attachment) { |
| 560 |
$output .= '<option value="' . esc_attr( $key ) . '" ' . selected( $background['attachment'], $key, false ) . '>' . esc_html( $attachment ) . '</option>'; |
| 561 |
} |
| 562 |
} |
| 563 |
|
| 564 |
$output .= '</select>'; |
| 565 |
$output .= '</div>'; |
| 566 |
|
| 567 |
break; |
| 568 |
|
| 569 |
// Editor |
| 570 |
case 'editor': |
| 571 |
|
| 572 |
echo wp_kses( $output, WPRMenu_Framework_Interface::$allowed_html ); |
| 573 |
$textarea_name = esc_attr( $option_name . '[' . $value['id'] . ']' ); |
| 574 |
$default_editor_settings = array( |
| 575 |
'textarea_name' => $textarea_name, |
| 576 |
'media_buttons' => false, |
| 577 |
'tinymce' => array( 'plugins' => 'wordpress' ) |
| 578 |
); |
| 579 |
$editor_settings = array(); |
| 580 |
if ( isset( $value['settings'] ) ) { |
| 581 |
$editor_settings = $value['settings']; |
| 582 |
} |
| 583 |
$editor_settings = array_merge( $default_editor_settings, $editor_settings ); |
| 584 |
wp_editor( $val, $value['id'], $editor_settings ); |
| 585 |
$output = ''; |
| 586 |
break; |
| 587 |
|
| 588 |
// Info |
| 589 |
case "info": |
| 590 |
|
| 591 |
$id = ''; |
| 592 |
$class = 'section'; |
| 593 |
if ( isset( $value['id'] ) ) { |
| 594 |
$id = 'id="' . esc_attr( $value['id'] ) . '" '; |
| 595 |
} |
| 596 |
if ( isset( $value['type'] ) ) { |
| 597 |
$class .= ' section-' . $value['type']; |
| 598 |
} |
| 599 |
if ( isset( $value['class'] ) ) { |
| 600 |
$class .= ' ' . $value['class']; |
| 601 |
} |
| 602 |
|
| 603 |
$output .= '<div ' . $id . 'class="' . esc_attr( $class ) . '">' . "\n"; |
| 604 |
if ( isset($value['name']) ) { |
| 605 |
$output .= '<h4 class="heading">' . esc_html( $value['name'] ) . '</h4>' . "\n"; |
| 606 |
} |
| 607 |
if ( isset( $value['desc'] ) ) { |
| 608 |
$output .= apply_filters('wpr_of_sanitize_info', $value['desc'] ) . "\n"; |
| 609 |
} |
| 610 |
$output .= '</div>' . "\n"; |
| 611 |
break; |
| 612 |
|
| 613 |
// Heading for Navigation |
| 614 |
case "heading": |
| 615 |
|
| 616 |
$counter++; |
| 617 |
|
| 618 |
if ( $counter >= 2 ) { |
| 619 |
$output .= '</div>'."\n"; |
| 620 |
} |
| 621 |
$class = ''; |
| 622 |
$class = ! empty( $value['id'] ) ? $value['id'] : $value['name']; |
| 623 |
$class = preg_replace('/[^a-zA-Z0-9._\-]/', '', strtolower($class) ); |
| 624 |
$output .= '<div id="options-group-' . $counter . '" class="group ' . $class . '">'; |
| 625 |
$output .= '<div class="wpr-options-heading"><h3>' . esc_html( $value['name'] ) . '</h3></div>' . "\n"; |
| 626 |
break; |
| 627 |
} |
| 628 |
|
| 629 |
if ( ( $value['type'] != "heading" ) |
| 630 |
&& ( $value['type'] != "info" ) ) { |
| 631 |
$output .= '</div>'; |
| 632 |
|
| 633 |
$output .= '</div></div>'."\n"; |
| 634 |
} |
| 635 |
|
| 636 |
echo wp_kses( $output, WPRMenu_Framework_Interface::$allowed_html ); |
| 637 |
} |
| 638 |
|
| 639 |
// Outputs closing div if there tabs |
| 640 |
if ( WPRMenu_Framework_Interface::wpr_optionsframework_tabs() != '' ) { |
| 641 |
echo '</div>'; |
| 642 |
} |
| 643 |
} |
| 644 |
|
| 645 |
static function wprmenu_get_demodata($demo_type) { |
| 646 |
|
| 647 |
if( empty($demo_type) ) |
| 648 |
return; |
| 649 |
|
| 650 |
$items = get_transient('wprm_api_demo_items_list'); |
| 651 |
|
| 652 |
if( ! $items ) |
| 653 |
$items = WPRMenu_Framework_Interface::wprm_fetch_demo_items(); |
| 654 |
|
| 655 |
$data = ''; |
| 656 |
$class = ''; |
| 657 |
|
| 658 |
if( is_object($items) ) { |
| 659 |
|
| 660 |
|
| 661 |
if( isset($items->$demo_type) && !empty($items->$demo_type) ) { |
| 662 |
$data .= '<h3 class="wpr-demo-type">'.$demo_type.' '.__(' Version Demo', 'wprmenu').'</h3>'; |
| 663 |
$data .= '<ul class="wprmenu-demo-list">'; |
| 664 |
|
| 665 |
foreach( $items->$demo_type as $key => $val ) { |
| 666 |
$demo_type = $val->demo_type; |
| 667 |
|
| 668 |
$settings_path = $val->settings; |
| 669 |
$import_class = ''; |
| 670 |
$import_demo_text = __('Import Demo', 'wprmenu'); |
| 671 |
|
| 672 |
if( $demo_type == 'Pro' ) { |
| 673 |
$settings_path = ''; |
| 674 |
$import_class = 'required-pro'; |
| 675 |
$import_demo_text = __('Available In Pro', 'wprmenu'); |
| 676 |
} |
| 677 |
|
| 678 |
$image_path = $val->image_path; |
| 679 |
$data .= '<li class="wprmenu-data-list">'; |
| 680 |
$data .= '<div class="wprmenu-content image-overlay" >'; |
| 681 |
$data .= '<div data-demo-type="'.$val->demo_type.'" data-demo-id="'.$val->demo_id.'" data-settings="'.$settings_path.'" class="wprmenu-content-image" style="background-image: url('.$image_path.'); "></div>'; |
| 682 |
$data .= '<span class="view-demo"><a target="_blank" href="'.$val->demo_url.'">'.__('View Demo', 'wprmenu').'</a></span>'; |
| 683 |
$data .= '<span class="wprmenu-data import-demo '.$import_class.'" data-id="">'.$import_demo_text.'</span>'; |
| 684 |
$data .= '</div>'; |
| 685 |
$data .= '</li>'; |
| 686 |
} |
| 687 |
$data .= '</ul>'; |
| 688 |
} |
| 689 |
} |
| 690 |
|
| 691 |
return $data; |
| 692 |
} |
| 693 |
|
| 694 |
static function wpr_render_floating_buttons() { |
| 695 |
ob_start(); |
| 696 |
?> |
| 697 |
<div class="wpr-floating-menus save-settings"> |
| 698 |
<div class="wpr-menu-quick-save wpr-floating-button"> |
| 699 |
<i class="wpr-quicksave-icon"></i> |
| 700 |
<input type="submit" class="wpr-quick-save-btn" name="update" value="<?php esc_attr_e( 'SAVE', 'wprmenu' ); ?>" /> |
| 701 |
</div><!-- / wpr-menu-quick-save --> |
| 702 |
<div class="clear"></div> |
| 703 |
</div> <!-- / wpr-floating-menus--> |
| 704 |
<?php |
| 705 |
$output = ob_get_contents(); |
| 706 |
ob_get_clean(); |
| 707 |
wp_kses_post( $output ); |
| 708 |
} |
| 709 |
|
| 710 |
static function wpr_render_form_button() { |
| 711 |
ob_start(); ?> |
| 712 |
<div class="save-settings-wrap"> |
| 713 |
<input type="submit" class="button-primary wpr-button save-settings" name="update" value="<?php esc_attr_e( 'Save Settings', 'wprmenu' ); ?>" /> |
| 714 |
</div> |
| 715 |
|
| 716 |
<div class="reset-settings-wrap"> |
| 717 |
<input type="submit" class="button-secondary reset-settings" name="update" value="<?php esc_attr_e( 'Restore Defaults', 'wprmenu' ); ?>" /> |
| 718 |
</div> |
| 719 |
<?php |
| 720 |
$output = ob_get_clean(); |
| 721 |
echo wp_kses( $output, WPRMenu_Framework_Interface::$allowed_html ); |
| 722 |
} |
| 723 |
|
| 724 |
static function wprm_fetch_demo_items() { |
| 725 |
$site_name = WPRMENU_DEMO_SITE_URL; |
| 726 |
$remoteLink = $site_name . '/wp-json/wprmenu-server/v1'; |
| 727 |
|
| 728 |
$data = wp_remote_get($remoteLink); |
| 729 |
|
| 730 |
$items = array(); |
| 731 |
|
| 732 |
if( is_array($data) && isset($data['body']) ) { |
| 733 |
$items = $data['body']; |
| 734 |
$items = json_decode($items); |
| 735 |
set_transient( 'wprm_api_demo_items_list', $items, 60 * 60 * 24 ); |
| 736 |
} |
| 737 |
return $items; |
| 738 |
} |
| 739 |
|
| 740 |
} |