[ Index ]

PHP Cross Reference of PageLines Framework

title

Body

[close]

/includes/ -> library.options.php (source)

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


Generated: Fri Aug 30 18:26:24 2013 Cross-referenced by PHPXref 0.7.1