/libs/lib-service.php

  1. <?php 
  2.  
  3. /** 
  4. * Web service for import/export handling 
  5. */ 
  6.  
  7. // access wp functions externally 
  8. require_once('lib-bootstrap.php'); 
  9.  
  10. // no access if parent plugin is disabled 
  11. if ( ! function_exists('gde_activate') ) { 
  12. wp_die('<p>'.__('You do not have sufficient permissions to access this page.').'</p>'); 
  13.  
  14. if ( isset( $_REQUEST['json'] ) ) { 
  15. switch ( $_REQUEST['json'] ) { 
  16. case "profiles": 
  17. if ( isset( $_REQUEST['id'] ) ) { 
  18. $profiles = gde_get_profiles( $_REQUEST['id'] ); 
  19. $suffix = "-" . $_REQUEST['id']; 
  20. } else { 
  21. $profiles = gde_get_profiles(); 
  22. $suffix = ''; 
  23.  
  24. if ( is_array( $profiles ) ) { 
  25. if ( isset( $_REQUEST['save'] ) && $_REQUEST['save'] == "1" ) { 
  26. $file = 'gde-profiles' . $suffix; 
  27. gde_output_json( json_encode( $profiles ), true, $file ); 
  28. } else { 
  29. gde_output_json( json_encode( $profiles ) ); 
  30. } else { 
  31. echo "0"; 
  32. exit; 
  33. case "settings": 
  34. if ( isset( $_REQUEST['save'] ) && $_REQUEST['save'] == "1" ) { 
  35. $file = 'gde-settings'; 
  36. gde_output_json( json_encode( $gdeoptions ), true, $file ); 
  37. } else { 
  38. gde_output_json( json_encode( $gdeoptions ) ); 
  39. case "all": 
  40. $data['profiles'] = gde_get_profiles(); 
  41. $data['settings'] = $gdeoptions; 
  42.  
  43. if ( isset( $_REQUEST['save'] ) && $_REQUEST['save'] == "1" ) { 
  44. unset( $data['settings']['api_key'] ); 
  45. $file = 'gde-export'; 
  46. gde_output_json( json_encode( $data ), true, $file ); 
  47. } else { 
  48. gde_output_json( json_encode( $data ) ); 
  49. default: 
  50. wp_die('<p>'.__('You do not have sufficient permissions to access this page.').'</p>'); 
  51. } elseif ( isset( $_REQUEST['viewlog'] ) ) { 
  52. // request to view dx log 
  53. global $wpdb; 
  54.  
  55. $blogid = get_current_blog_id(); 
  56.  
  57. $table = $wpdb->base_prefix . 'gde_dx_log'; 
  58. $check = $wpdb->query("SHOW TABLES LIKE '" . $table . "'"); 
  59. //if ( mysql_num_rows( $check ) > 0 ) { 
  60. if ( $check ) { 
  61. $data = $wpdb->get_col( "SELECT * FROM $table WHERE blogid = '$blogid' ORDER BY id ASC", 2 ); 
  62. header('Content-type: text/plain'); 
  63. if ( is_array( $data ) ) { 
  64. foreach ( $data as $v ) { 
  65. echo $v . "\n"; 
  66. } else { 
  67. wp_die('<p>'.__('You do not have sufficient permissions to access this page.').'</p>'); 
  68.  
  69. /** 
  70. * Output/download requested JSON data 
  71. * 
  72. * @since 2.5.0.2 
  73. * @return void 
  74. */ 
  75. function gde_output_json( $json, $save = false, $file = '' ) { 
  76. if ( $save && ! empty( $file ) ) { 
  77. header('Content-disposition: attachment; filename=' . $file . '.json' ); 
  78. header('Content-type: application/json'); 
  79. echo $json; 
  80. exit; 
  81.  
  82. ?> 
.