| [ Index ] |
PHP Cross Reference of PageLines Framework |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * PageLines Option 5 * 6 * Uses controls to find and retrieve the appropriate option value 7 * 8 * @package PageLines Framework 9 * 10 * @since ... 11 * 12 * @link http://www.pagelines.com/wiki/Ploption 13 * 14 * @param 'key' the id of the option 15 * @param array $args 16 * 17 * @uses is_pagelines_special 18 * @uses plspecial 19 * @uses plmeta 20 * @uses pldefault 21 * @uses get_ploption 22 * @uses plnewkey 23 * 24 * @return bool|mixed 25 */ 26 function ploption( $key, $args = array() ){ 27 28 $d = array( 29 'subkey' => null, // Used as option key in special handling 30 'post_id' => null, // Used for page/page/panel control 31 'setting' => null, // Different types of serialized settings 32 'clone_id' => null, 33 'type' => '', // used for special meta tabs 34 'translate' => false, 35 'key' => $key 36 ); 37 38 $o = wp_parse_args($args, $d); 39 40 if ( has_filter( "ploption_{$key}" ) ) 41 return apply_filters( "ploption_{$key}", $key, $o ); 42 43 if(is_pagelines_special($o) && plspecial($key, $o)) 44 return pagelines_magic_parse( plspecial($key, $o), $o ); 45 46 elseif( isset( $o['post_id'] ) && plmeta( $key, $args ) ) 47 return pagelines_magic_parse( plmeta( $key, $o ), $o ); 48 49 elseif( pldefault( $key, $o ) ) 50 return pldefault( $key, $o ); 51 52 elseif( get_ploption($key, $o) ) 53 return pagelines_magic_parse( get_ploption( $key, $o ), $o ); 54 55 elseif( get_ploption($key, $o) === null ) 56 if ( $newkey = plnewkey( $key ) ) 57 return $newkey; 58 59 else 60 return false; 61 } 62 63 /** 64 * Locates a meta option if it exists 65 * 66 * @param string $key the key of the option 67 */ 68 function plmeta( $key, $args ){ 69 70 $d = array( 71 'subkey' => null, 72 'post_id' => null, 73 'setting' => null, 74 'clone_id' => null, 75 ); 76 77 $o = wp_parse_args($args, $d); 78 79 // Deal with cloning options 80 if( isset($args['clone_id']) && $args['clone_id'] != 1 ) 81 $id_key = $key.'_'.$args['clone_id']; 82 else 83 $id_key = $key; 84 85 // Deal w/ default checkbox/boolean stuff 86 // If default is set, return if reversed 87 88 if( isset($o['post_id']) && !empty($o['post_id']) ) { 89 90 $default_value = get_post_meta($o['post_id'], $id_key, true); 91 92 $reverse = ( pldefault($key, $args, 'val') ) ? get_post_meta($o['post_id'], $key.'_reverse', true) : false; 93 94 if( (bool) $default_value && (bool) $reverse) 95 return false; 96 else 97 return $default_value; 98 99 } else 100 return false; 101 102 } 103 104 105 /** 106 * 107 * @TODO do 108 * 109 */ 110 function plspecial($key, $args){ 111 112 global $pagelines_special_meta; 113 114 // Type of page is needed for special handling 115 // Use the argument 'type' if available because of settings panels, etc. 116 if(isset($args['type']) && $args['type'] != '') 117 $type = $args['type']; 118 else 119 $type = PageLinesTemplate::page_type_breaker(); 120 121 122 if( isset($args['clone_id']) && $args['clone_id'] != 1 ) 123 $id_key = $key.'_'.$args['clone_id']; 124 else 125 $id_key = $key; 126 127 128 if(isset($pagelines_special_meta[$type]) && is_array($pagelines_special_meta[$type]) && isset($pagelines_special_meta[$type][$id_key])) 129 return $pagelines_special_meta[$type][$id_key]; 130 else 131 return false; 132 } 133 134 /** 135 * Grab from global defaults panel 136 * 137 * @param 'key' the id of the option 138 * 139 **/ 140 function pldefault( $key, $args = array(), $mode = '') { 141 142 143 global $pagelines_special_meta; 144 145 $sp = $pagelines_special_meta; 146 $slug = 'default'; 147 $reverse_key = $key.'_reverse'; 148 149 $default_value = ( isset( $sp[$slug] ) && is_array( $sp[$slug] ) && isset( $sp[$slug][$key] ) ) ? $sp[$slug][$key] : false; 150 151 // check if on default option is reversed by meta 152 $reverse_value = ( $mode != 'val' && (plmeta($reverse_key, $args) || plspecial( $reverse_key, $args )) ) ? true : false; 153 154 if( !$reverse_value ) 155 return $default_value; 156 else 157 return false; 158 159 } 160 161 162 163 /** 164 * Attempt to set default value if not found with ploption() 165 * 166 * @param 'key' the id of the option 167 * 168 **/ 169 function plnewkey( $key ) { 170 171 if ( !is_admin() ) 172 return false; 173 $settings = get_option_array(); 174 175 foreach ($settings as $group) 176 foreach($group as $name => $setting) 177 if ($name == $key && isset( $setting['default'] ) ) { 178 plupop( $key, $setting['default'] ); 179 return $setting['default']; 180 } 181 return false; 182 } 183 184 185 186 /** 187 * 188 * @TODO do 189 * 190 */ 191 function plupop($key, $val, $oset = array()){ 192 193 $d = array( 194 'parent' => null, 195 'subkey' => null, 196 'setting' => PAGELINES_SETTINGS, 197 ); 198 199 $o = wp_parse_args($oset, $d); 200 201 $the_set = get_option($o['setting']); 202 203 $new = array( $key => $val ); 204 205 $parent = ( isset($o['parent']) ) ? $o['parent'] : null; 206 207 208 209 $child_option = ( isset($parent) && isset($the_set[$parent]) && is_array($the_set[$parent]) ) ? true : false; 210 211 $parse_set = ( $child_option ) ? $the_set[ $parent ] : $the_set; 212 213 $new_set = wp_parse_args($new, $parse_set); 214 215 216 if($child_option) 217 $the_set[ $parent ] = $new_set; 218 else 219 $the_set = $new_set; 220 221 update_option( $o['setting'], $the_set ); 222 223 } 224 225 /** 226 * 227 * @TODO do 228 * 229 */ 230 function get_ploption( $key, $args = array() ){ 231 232 $d = array( 233 'subkey' => null, 234 'post_id' => null, 235 'setting' => null, 236 'clone_id' => null, 237 'special' => null 238 ); 239 240 $o = wp_parse_args($args, $d); 241 242 // get setting 243 $setting = ( isset($o['setting']) && !empty($o['setting'])) ? $o['setting'] : PAGELINES_SETTINGS; 244 245 if(!isset($setting) || $setting == PAGELINES_SETTINGS){ 246 247 global $global_pagelines_settings; 248 249 if( is_array($global_pagelines_settings) && isset($global_pagelines_settings[$key]) ) 250 return $global_pagelines_settings[$key]; 251 252 else 253 return false; 254 255 } elseif ( isset($setting) ){ 256 257 $setting_options = get_option($setting); 258 259 if( isset($o['subkey']) ){ 260 261 if(isset($setting_options[$key]) && is_array($setting_options[$key]) && isset($setting_options[$key][$o['subkey']])) 262 return $setting_options[$key][$o['subkey']]; 263 else 264 return false; 265 266 }elseif( isset($setting_options[$key]) ) 267 return $setting_options[$key]; 268 269 else 270 return false; 271 272 } else 273 return false; 274 275 } 276 277 /** 278 * Parse the ploption strings. 279 */ 280 function pagelines_magic_parse( $string, $o ) { 281 282 /** 283 * wpml check. 284 */ 285 if ( true == $o['translate'] ) { 286 287 if( ! function_exists('icl_register_string') ) 288 return $string; 289 290 $key = sprintf( '%s_%s_%s_%s', $o['group'], $o['key'], $o['post_id'], $o['clone_id'] ); 291 $group = sprintf( 'pagelines_%s', $o['group'] ); 292 icl_register_string( $group, $key, $string); 293 294 return icl_t( $group, $key, $string ); 295 } 296 297 /** 298 * Always return original string if all else fails. 299 */ 300 return $string; 301 } 302 303 /** 304 * 305 * @TODO do 306 * 307 */ 308 function plname($key, $a = array()){ 309 310 $set = (!isset($a['setting']) || empty($a['setting']) || $a['setting'] == PAGELINES_SETTINGS) ? PAGELINES_SETTINGS : $a['setting']; 311 312 $subkey = (isset($a['subkey'])) ? $a['subkey'] : false; 313 314 $grandkey = (isset($a['subkey']) && is_array($a['subkey']) && isset($a['subkey']['grandkey'])) ? $a['subkey']['grandkey'] : false; 315 316 if( $grandkey ) 317 $output = $set . '['.$key.']['.$subkey.']['.$grandkey.']'; 318 elseif( $subkey ) 319 $output = $set . '['.$key.']['.$subkey.']'; 320 else 321 $output = $set .'['.$key.']'; 322 323 return $output; 324 325 } 326 327 328 /** 329 * 330 * @TODO do 331 * 332 */ 333 function plid($key, $a){ 334 335 $set = (!isset($a['setting']) || empty($a['setting']) || $a['setting'] == PAGELINES_SETTINGS) ? PAGELINES_SETTINGS : $a['setting']; 336 337 $subkey = (isset($a['subkey'])) ? $a['subkey'] : false; 338 339 $grandkey = (isset($a['subkey']) && is_array($a['subkey']) && isset($a['subkey']['grandkey'])) ? $a['subkey']['grandkey'] : false; 340 341 $clone_id = (isset($a['clone_id']) && $a['clone_id'] != 1) ? '_'.$a['clone_id'] : ''; 342 343 if( $grandkey ) 344 $output = array($set, $key, $subkey, $grandkey); 345 elseif( $subkey ) 346 $output = array($set, $key, $subkey); 347 else 348 $output = array($set, $key); 349 350 return join('_', $output) . $clone_id; 351 } 352 353 354 /** 355 * 356 * @TODO do 357 * 358 */ 359 function pl_um($key, $args = null){ 360 361 if(is_array($args)){ 362 363 $d = array( 364 'user_id' => null 365 ); 366 367 $o = wp_parse_args($args, $d); 368 } else { 369 370 $o['user_id'] = $args; 371 372 } 373 374 375 return get_user_meta( $o['user_id'], $key, true ); 376 } 377 378 /** 379 * Get the option, if its not set, set it. 380 * @todo make usable with different settings types. 381 * 382 **/ 383 function pl_getset_option($key, $default = false) { 384 385 global $global_pagelines_settings; 386 387 if( is_array($global_pagelines_settings) && isset($global_pagelines_settings[$key]) ) 388 return $global_pagelines_settings[$key]; 389 390 else{ 391 plupop( $key, $default ); 392 return $default; 393 } 394 } 395 396 397 /** 398 * Sets up option name for saving of option settings 399 * 400 **/ 401 function pagelines_option_name( $oid, $sub_oid = null, $grand_oid = null, $setting = PAGELINES_SETTINGS){ 402 echo get_pagelines_option_name( $oid, $sub_oid, $grand_oid, $setting ); 403 } 404 405 406 /** 407 * 408 * @TODO do 409 * 410 */ 411 function get_pagelines_option_name( $oid, $sub_oid = null, $grand_oid = null, $setting = PAGELINES_SETTINGS ){ 412 413 $set = (!isset($setting) || $setting == PAGELINES_SETTINGS) ? PAGELINES_SETTINGS : $setting; 414 415 if( isset($grand_oid) ) 416 $name = $set . '['.$oid.']' . '['.$sub_oid.']' . '['.$grand_oid.']'; 417 elseif( isset($sub_oid) ) 418 $name = $set . '['.$oid.']' . '['.$sub_oid.']'; 419 else 420 $name = $set .'['.$oid.']'; 421 422 return $name; 423 } 424 425 426 /** 427 * 428 * @TODO do 429 * 430 */ 431 function meta_option_name( $array, $hidden = true ){ 432 433 $prefix = ($hidden) ? '_' : ''; 434 435 return $prefix.join('_', $array); 436 437 } 438 439 440 /** 441 * 442 * @TODO do 443 * 444 */ 445 function pagelines_option_id( $oid, $sub_oid = null, $grand_oid = null, $namespace = 'pagelines'){ 446 echo get_pagelines_option_id($oid, $sub_oid, $grand_oid, $namespace); 447 } 448 449 450 /** 451 * 452 * @TODO do 453 * 454 */ 455 function get_pagelines_option_id( $oid, $sub_oid = null, $grand_oid = null, $namespace = 'pagelines'){ 456 457 $nm = (!isset($namespace) || $namespace == 'pagelines') ? 'pagelines' : $namespace; 458 459 if( isset($grand_oid) ) 460 $a = array($nm, $oid, $sub_oid, $grand_oid); 461 elseif( isset($sub_oid) ) 462 $a = array($nm, $oid, $sub_oid); 463 else 464 $a = array($nm, $oid); 465 466 return join('_', $a); 467 } 468 469 /** 470 * Sanitize user input 471 * 472 **/ 473 function pagelines_settings_callback( $input ) { 474 475 // We whitelist some of the settings, these need to have html/js/css. 476 $whitelist = array( 'excerpt_tags', 'headerscripts', 'footerscripts', 'asynch_analytics', 'typekit_script', 'footer_terms', 'footer_more' ); 477 478 if(is_array($input)){ 479 480 // We run through the $input array, if it is not in the whitelist we run it through the wp filters. 481 foreach ($input as $name => $value){ 482 if ( !is_array( $value ) && !in_array( $name, apply_filters( 'pagelines_settings_whitelist', $whitelist ) ) ) 483 if ( 'customcss' == $name) 484 $input[$name] = wp_strip_all_tags( $value, false ); 485 else 486 $input[$name] = wp_filter_nohtml_kses( $value ); 487 } 488 489 } 490 // Return our safe $input array. 491 return $input; 492 } 493 494 /** 495 * These functions pull options/settings 496 * from the options database. 497 * 498 **/ 499 function get_pagelines_option($key, $setting = null, $default = null) { 500 // get setting 501 $setting = $setting ? $setting : PAGELINES_SETTINGS; 502 503 if(!isset($setting) || $setting == PAGELINES_SETTINGS){ 504 505 global $global_pagelines_settings; 506 507 if( is_array($global_pagelines_settings) && isset($global_pagelines_settings[$key]) ) 508 return $global_pagelines_settings[$key]; 509 510 else 511 if ( $default ) { 512 plupop( $key, $default ); 513 return $default; 514 } 515 return false; 516 } 517 } 518 519 520 521 522 /** 523 * 524 * @TODO do 525 * 526 */ 527 function pagelines_option( $key, $post_id = null, $setting = null){ 528 529 if(isset($post_id) && get_post_meta($post_id, $key, true)) 530 return get_post_meta($post_id, $key, true); //if option is set for a page/post 531 532 elseif( get_pagelines_option($key, $setting) ) 533 return get_pagelines_option($key, $setting); 534 535 else 536 return false; 537 538 } 539 540 541 /** 542 * 543 * @TODO do 544 * 545 */ 546 function pagelines_sub_option( $key, $subkey, $post_id = '', $setting = null){ 547 548 $primary_option = pagelines_option($key, $post_id, $setting); 549 550 if(is_array($primary_option) && isset($primary_option[$subkey])) 551 return $primary_option[$subkey]; 552 else 553 return false; 554 555 } 556 557 // Need to keep until the forums are redone, or don't check for it. 558 559 /** 560 * 561 * @TODO do 562 * 563 */ 564 function pagelines( $key, $post_id = null, $setting = null ){ 565 return pagelines_option($key, $post_id, $setting); 566 } 567 568 569 /** 570 * 571 * @TODO do 572 * 573 */ 574 function e_pagelines($key, $alt = null, $post_id = null, $setting = null){ 575 print_pagelines_option( $key, $alt, $post_id, $setting); 576 } 577 578 579 580 /** 581 * 582 * @TODO do 583 * 584 */ 585 function pagelines_pro($key, $post_id = null, $setting = null){ 586 587 if(VPRO) 588 return pagelines_option($key, $post_id, $setting); 589 else 590 return false; 591 } 592 593 594 /** 595 * 596 * @TODO do 597 * 598 */ 599 function print_pagelines_option($key, $alt = null, $post_id = null, $setting = null) { 600 601 echo load_pagelines_option($key, $alt, $post_id, $setting); 602 603 } 604 605 606 /** 607 * 608 * @TODO do 609 * 610 */ 611 function load_pagelines_option($key, $alt = null, $post_id = null, $setting = null) { 612 613 if($post_id && get_post_meta($post_id, $key, true) && !is_home()){ 614 615 //if option is set for a page/post 616 return get_post_meta($post_id, $key, true); 617 618 }elseif(pagelines_option($key, $post_id, $setting)){ 619 620 return pagelines_option($key, $post_id, $setting); 621 622 }else{ 623 return $alt; 624 } 625 626 } 627 628 629 /** 630 * 631 * @TODO do 632 * 633 */ 634 function pagelines_update_option($optionid, $optionval){ 635 636 $theme_options = get_option(PAGELINES_SETTINGS); 637 $new_options = array( 638 $optionid => $optionval 639 ); 640 641 $settings = wp_parse_args($new_options, $theme_options); 642 update_option(PAGELINES_SETTINGS, $settings); 643 } 644 645 646 647 /** 648 * 649 * @TODO do 650 * 651 */ 652 function get_pagelines_meta($option, $post){ 653 $meta = get_post_meta($post, $option, true); 654 if(isset($meta)) 655 return $meta; 656 else 657 return false; 658 } 659 660 /* Deprecated in favor of get_pagelines_meta */ 661 function m_pagelines($option, $post){ 662 return get_pagelines_meta($option, $post); 663 } 664 665 666 667 /** 668 * 669 * @TODO document 670 * 671 */ 672 function em_pagelines($option, $post, $alt = ''){ 673 $post_meta = m_pagelines($option, $post); 674 675 if(isset($post_meta)){ 676 echo $post_meta; 677 }else{ 678 echo $alt; 679 } 680 } 681 682 /** 683 * Used as a filter on the master option array generated for settings 684 * 685 * @param $optionarray the master option array 686 * @return rebuilt $optionsarray with addon options if plugin is active. 687 * @since 2.0 688 **/ 689 function pagelines_merge_addon_options( $optionarray ) { 690 $options = get_option( 'pagelines_addons_options' ); 691 $plugins = pagelines_register_plugins(); 692 if ( is_array( $options ) ) { 693 694 $build_options = array(); 695 696 foreach( $options as $optionname => $option ) 697 if ( in_array( $optionname, $plugins ) ) $build_options[$optionname] = $option; 698 699 return array_merge( $optionarray, $build_options ); 700 701 } else 702 return $optionarray; 703 } 704 705 /** 706 * Used to register and handle new plugin options 707 * Use with register_activation_hook() 708 * @since 2.0 709 **/ 710 function pagelines_register_addon_options( $addon_name, $addon_options ) { 711 712 $addon_saved_options = get_option( 'pagelines_addons_options' ); 713 if ( !is_array( $addon_saved_options ) ) $addon_saved_options = array(); 714 if ( !isset($addon_saved_options[$addon_name] ) ) { 715 $addon_saved_options[$addon_name] = $addon_options; 716 update_option( 'pagelines_addons_options', $addon_saved_options ); 717 } 718 } 719 720 /** 721 * Used to remove options when addons are deleted. 722 * Use with register_deactivation_hook() 723 * @since 2.0 724 **/ 725 function pagelines_remove_addon_options( $addon_name ) { 726 $options = get_option( 'pagelines_addons_options' ); 727 if (is_array($options) && isset( $options[$addon_name] ) ) { 728 unset($options[$addon_name]); 729 update_option( 'pagelines_addons_options', $options ); 730 } 731 } 732 733 /** 734 * This function registers the default values for pagelines theme settings 735 */ 736 function pagelines_settings_defaults() { 737 738 $default_options = array(); 739 740 foreach(get_option_array( true ) as $menuitem => $options ){ 741 742 foreach($options as $oid => $o ){ 743 744 if( isset( $o['type'] ) && 'layout' == $o['type'] ){ 745 746 $dlayout = new PageLinesLayout; 747 $default_options['layout'] = $dlayout->default_layout_setup(); 748 749 }elseif( pagelines_is_multi_option($oid, $o) ){ 750 751 foreach($o['selectvalues'] as $multi_optionid => $multi_o) 752 if(isset($multi_o['default'])) $default_options[$multi_optionid] = $multi_o['default']; 753 754 755 }else{ 756 if(!VPRO && isset($o['version_set_default']) && $o['version_set_default'] == 'pro') 757 $default_options[$oid] = null; 758 elseif(!VPRO && isset($o['default_free'])) 759 $default_options[$oid] = $o['default_free']; 760 elseif(isset($o['default'])) 761 $default_options[$oid] = $o['default']; 762 } 763 764 } 765 } 766 767 return apply_filters('pagelines_settings_defaults', $default_options); 768 } 769 770 771 772 773 /** 774 * 775 * @TODO do 776 * 777 */ 778 function pagelines_process_reset_options( $option_array = null ) { 779 780 781 782 if(isset($_POST['pl_reset_settings']) && current_user_can('edit_themes')){ 783 784 do_action( 'extend_flush' ); 785 786 if(isset($_POST['the_pl_setting']) && !isset($_POST['reset_callback'])) 787 update_option($_POST['the_pl_setting'], array()); 788 789 if(isset($_POST['reset_callback'])) 790 call_user_func( $_POST['reset_callback'] ); 791 } 792 793 794 $option_array = (isset($option_array)) ? $option_array : get_option_array(); 795 796 foreach($option_array as $menuitem => $options ){ 797 foreach($options as $oid => $o ){ 798 if( isset( $o['type'] ) && $o['type'] == 'reset' && ploption($oid) ){ 799 800 call_user_func($o['callback']); 801 802 // Set the 'reset' option back to not set !important 803 pagelines_update_option($oid, null); 804 805 wp_redirect( admin_url( PL_SETTINGS_URL.'&reset=true&opt_id='.$oid ) ); 806 exit; 807 808 } 809 810 } 811 } 812 813 } 814 815 816 /** 817 * 818 * @TODO do 819 * 820 */ 821 function pagelines_is_multi_option( $oid, $o ){ 822 823 if ( ! isset( $o['type'] ) ) 824 return false; 825 826 if( $o['type'] == 'text_multi' 827 || $o['type'] == 'check_multi' 828 || $o['type'] == 'color_multi' 829 || $o['type'] == 'image_upload_multi' 830 || $o['type'] == 'multi_option' 831 ){ 832 return true; 833 } else 834 return false; 835 } 836 837 838 /** 839 * 840 * @TODO do 841 * 842 */ 843 function pagelines_is_boolean_option($oid, $o){ 844 845 if( 846 $o['type'] == 'check' 847 || $o['type'] == 'check_multi' 848 ){ 849 return true; 850 } else 851 return false; 852 853 } 854 855 856 857 858 /** 859 * 860 * @TODO do 861 * 862 */ 863 function pagelines_import_export(){ 864 865 if ( isset( $_POST['form_submitted']) && $_POST['form_submitted'] == 'export_settings_form' ) { 866 867 $pagelines_settings = ( array ) get_option(PAGELINES_SETTINGS); 868 $pagelines_template_map = ( array ) get_option( PAGELINES_TEMPLATE_MAP ); 869 $pagelines_templates = ( array ) get_option( PAGELINES_TEMPLATES ); 870 $pagelines_special = ( array ) get_option( PAGELINES_SPECIAL ); 871 872 $options['pagelines_templates'] = $pagelines_templates; 873 $options['pagelines_template_map'] = $pagelines_template_map; 874 $options['pagelines_settings'] = $pagelines_settings; 875 $options['pagelines_special'] = $pagelines_special; 876 877 878 if ( isset($options) && is_array( $options) ) { 879 880 header('Cache-Control: public, must-revalidate'); 881 header('Pragma: hack'); 882 header('Content-Type: text/plain'); 883 header( 'Content-Disposition: attachment; filename="' . PL_THEMENAME . '-Settings-' . date('Ymd') . '.dat"' ); 884 echo json_encode( $options ); 885 exit(); 886 } 887 888 } 889 890 if ( isset($_POST['form_submitted']) && $_POST['form_submitted'] == 'import_settings_form') { 891 if (strpos($_FILES['file']['name'], 'Settings') === false && strpos($_FILES['file']['name'], 'settings') === false){ 892 wp_redirect( admin_url(PL_IMPORT_EXPORT_URL.'&pageaction=import&error=wrongfile') ); 893 } elseif ($_FILES['file']['error'] > 0){ 894 $error_type = $_FILES['file']['error']; 895 wp_redirect( admin_url(PL_IMPORT_EXPORT_URL.'&pageaction=import&error=file&'.$error_type) ); 896 } else { 897 $raw_options = pl_file_get_contents( $_FILES['file']['tmp_name'] ); 898 $all_options = json_decode(json_encode(json_decode($raw_options)), true); 899 900 if ( !isset( $_POST['pagelines_layout'] ) && is_array( $all_options) && isset( $all_options['pagelines_settings'] ) && is_array( $all_options['pagelines_settings'] ) ) 901 unset( $all_options['pagelines_settings']['layout'] ); 902 903 if ( isset( $_POST['pagelines_settings'] ) && is_array( $all_options) && isset( $all_options['pagelines_settings'] ) && is_array( $all_options['pagelines_settings'] ) ) { 904 update_option( PAGELINES_SETTINGS, array_merge( get_option( PAGELINES_SETTINGS ), $all_options['pagelines_settings'] ) ); 905 $done = 1; 906 } 907 908 if ( isset( $_POST['pagelines_special'] ) && is_array( $all_options) && isset( $all_options['pagelines_special'] ) && is_array( $all_options['pagelines_special'] ) ) { 909 $special = ( array ) get_option( PAGELINES_SPECIAL ); 910 update_option( PAGELINES_SPECIAL, array_merge( $special, $all_options['pagelines_special'] ) ); 911 $done = 1; 912 } 913 914 if ( isset( $_POST['pagelines_templates'] ) && is_array( $all_options) && isset( $all_options['pagelines_template_map'] ) && is_array( $all_options['pagelines_template_map'] ) ) { 915 $template_map = ( array ) get_option( PAGELINES_TEMPLATE_MAP ); 916 $template_settings = ( array ) get_option( PAGELINES_TEMPLATES ); 917 918 $template_settings_new = ( isset( $all_options['pagelines_templates'] ) && is_array( $all_options['pagelines_templates'] ) ) ? $all_options['pagelines_templates'] : array(); 919 $template_map_new = ( isset( $all_options['pagelines_template_map'] ) && is_array( $all_options['pagelines_template_map'] ) ) ? $all_options['pagelines_template_map'] : array(); 920 921 update_option( PAGELINES_TEMPLATE_MAP, array_merge( $template_map, $template_map_new ) ); 922 update_option( PAGELINES_TEMPLATES, array_merge( $template_settings, $template_settings_new ) ); 923 $done = 1; 924 } 925 if (function_exists('wp_cache_clean_cache')) { 926 global $file_prefix; 927 wp_cache_clean_cache($file_prefix); 928 } 929 if ( isset($done) ) { 930 wp_redirect( admin_url( PL_IMPORT_EXPORT_URL.'&pageaction=import&imported=true' ) ); 931 } else { 932 wp_redirect( admin_url( PL_IMPORT_EXPORT_URL.'&pageaction=import&error=wrongfile') ); 933 } 934 } 935 } 936 } 937 938 /* 939 * Set user/pass using md5() 940 * 941 */ 942 function set_pagelines_credentials( $user, $pass ) { 943 944 if ( !empty( $user ) && !empty( $pass ) ) 945 update_option( 'pagelines_extend_creds', array( 'user' => $user, 'pass' => md5( $pass ) ) ); 946 } 947 948 /* 949 * Add persistant licence info 950 * 951 */ 952 function update_pagelines_licence( $licence ) { 953 954 $creds = get_option( 'pagelines_extend_creds' ); 955 956 $creds['licence'] = $licence; 957 958 update_option( 'pagelines_extend_creds', $creds ); 959 } 960 961 962 /* 963 * Get username or password 964 * 965 */ 966 function get_pagelines_credentials( $t ) { 967 968 $creds = get_option( 'pagelines_extend_creds', array( 'user' => '', 'pass' => '' ) ); 969 970 switch( $t ) { 971 972 case 'user': 973 return ( isset( $creds['user'] ) ) ? $creds['user'] : null; 974 break; 975 976 case 'pass': 977 return ( isset( $creds['pass'] ) ) ? $creds['pass'] : false; 978 break; 979 980 case 'licence': 981 return ( isset( $creds['licence'] ) ) ? $creds['licence'] : 'not logged in'; 982 break; 983 984 } 985 } 986 987 /* 988 * Check updates status including errors and licence information. 989 * 990 */ 991 function pagelines_check_credentials( $type = 'setup' ) { 992 993 994 if ( ! is_array( $data = get_transient( EXTEND_UPDATE ) ) ) 995 return false; 996 997 switch( $type ) { 998 999 case 'setup': 1000 if ( isset( $data['credentials'] ) && $data['credentials'] === 'true' ) 1001 return true; 1002 else 1003 return false; 1004 break; 1005 1006 case 'licence': 1007 if ( isset( $data['licence'] ) ) 1008 return $data['licence']; 1009 break; 1010 1011 case 'error': 1012 if ( isset( $data['api_error'] ) ) 1013 return $data['api_error']; 1014 break; 1015 1016 case 'ssl': 1017 if ( isset( $data['ssl'] ) ) 1018 return true; 1019 break; 1020 1021 case 'echo': 1022 return $data; 1023 break; 1024 1025 case 'plus': 1026 if ( isset( $data['plus'] ) ) 1027 return $data['plus']; 1028 break; 1029 1030 case 'message': 1031 if ( isset( $data['message'] ) ) 1032 return $data['message']; 1033 1034 case 'vchat': 1035 if ( isset( $data['chat_url'] ) ) 1036 return $data['chat_url']; 1037 else 1038 return false; 1039 } 1040 } 1041 1042 /* 1043 * Set runtime licence types 1044 * 1045 */ 1046 if ( !defined( 'VDEV') ) 1047 define( 'VDEV', ( get_pagelines_credentials( 'licence' ) === 'dev' ) ? true : false ); 1048 1049 if( !defined( 'VPRO' ) ) 1050 define( 'VPRO', ( get_pagelines_credentials( 'licence' ) === 'pro' || get_pagelines_credentials( 'licence' ) === 'dev' ) ? true : false ); 1051 if ( !defined( 'VPLUS' ) ) 1052 define( 'VPLUS', ( pagelines_check_credentials( 'plus' ) ) ? true : false );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu May 23 23:52:43 2013 | Cross-referenced by PHPXref 0.7.1 |