oauth_init

The All In One SEO Pack oauth init function.

Description

oauth_init(); 

Usage

  1. if ( !function_exists( 'oauth_init' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'all-in-one-seo-pack/inc/deprecated.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = oauth_init(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/inc/deprecated.php  
  1. function oauth_init() { 
  2. if ( ! is_user_logged_in() || ! current_user_can( 'aiosp_manage_seo' ) ) { 
  3. return false; 
  4. $this->token = 'anonymous'; 
  5. $this->secret = 'anonymous'; 
  6. $preload = $this->get_class_option(); 
  7. $manual_ua = ''; 
  8. if ( ! empty( $_POST ) ) { 
  9. if ( ! empty( $_POST[ "{$this->prefix}google_connect" ] ) ) { 
  10. $manual_ua = 1; 
  11. } elseif ( ! empty( $preload[ "{$this->prefix}google_connect" ] ) ) { 
  12. $manual_ua = 1; 
  13. if ( ! empty( $manual_ua ) ) { 
  14. foreach ( array( 'token', 'secret', 'access_token', 'ga_token', 'account_cache' ) as $v ) { 
  15. if ( ! empty( $preload[ "{$this->prefix}{$v}" ] ) ) { 
  16. unset( $preload[ "{$this->prefix}{$v}" ] ); 
  17. unset( $this->$v ); 
  18. $this->update_class_option( $preload ); 
  19. $this->update_options(); 
  20. //return; 
  21. foreach ( array( 'token', 'secret', 'access_token', 'ga_token', 'account_cache' ) as $v ) { 
  22. if ( ! empty( $preload[ "{$this->prefix}{$v}" ] ) ) { 
  23. $this->$v = $preload[ "{$this->prefix}{$v}" ]; 
  24. $callback_url = null; 
  25. if ( ! empty( $_REQUEST['oauth_verifier'] ) ) { 
  26. $this->verifier = $_REQUEST['oauth_verifier']; 
  27. if ( ! empty( $_REQUEST['oauth_token'] ) ) { 
  28. if ( isset( $this->token ) && $this->token === $_REQUEST['oauth_token'] ) { 
  29. $this->access_token = $this->oauth_get_token( $this->verifier ); 
  30. if ( is_array( $this->access_token ) && ! empty( $this->access_token['oauth_token'] ) ) { 
  31. unset( $this->token ); 
  32. unset( $this->secret ); 
  33. $this->ga_token = $this->access_token['oauth_token']; 
  34. foreach ( array( 'token', 'secret', 'access_token', 'ga_token' ) as $v ) { 
  35. if ( ! empty( $this->$v ) ) { 
  36. $preload[ "{$this->prefix}{$v}" ] = $this->$v; 
  37. $this->update_class_option( $preload ); 
  38. wp_redirect( menu_page_url( plugin_basename( $this->file ), false ) ); 
  39. exit; 
  40. if ( ! empty( $this->ga_token ) ) { 
  41. if ( ! empty( $this->account_cache ) ) { 
  42. $ua = $this->account_cache['ua']; 
  43. $profiles = $this->account_cache['profiles']; 
  44. } else { 
  45. $this->token = $this->access_token['oauth_token']; 
  46. $this->secret = $this->access_token['oauth_token_secret']; 
  47.  
  48. $data = $this->oauth_get_data( 'https://www.googleapis.com/analytics/v2.4/management/accounts/~all/webproperties/~all/profiles' ); 
  49.  
  50. $http_code = wp_remote_retrieve_response_code( $data ); 
  51.  
  52. if ( 200 === $http_code ) { 
  53. $response = wp_remote_retrieve_body( $data ); 
  54. $xml = $this->xml_string_to_array( $response ); 
  55. $ua = array(); 
  56. $profiles = array(); 
  57. if ( ! empty( $xml['entry'] ) ) { 
  58. $rec = array(); 
  59. $results = array(); 
  60. if ( ! empty( $xml['entry'][0] ) ) { 
  61. $results = $xml['entry']; 
  62. } else { 
  63. $results[] = $xml['entry']; 
  64. foreach ( $results as $r ) { 
  65. foreach ( $r as $k => $v ) 
  66. switch ( $k ) { 
  67. case 'id': 
  68. $rec['id'] = $v; 
  69. break; 
  70. case 'title': 
  71. $rec['title'] = $v['@content']; 
  72. break; 
  73. case 'dxp:property': 
  74. $attr = array(); 
  75. foreach ( $v as $a => $f ) { 
  76. if ( is_array( $f ) && ! empty( $f['@attributes'] ) ) { 
  77. $rec[ $f['@attributes']['name'] ] = $f['@attributes']['value']; 
  78. break; 
  79. $ua[ $rec['title'] ] = array( $rec['ga:webPropertyId'] => $rec['ga:webPropertyId'] ); 
  80. $profiles[ $rec['ga:webPropertyId'] ] = $rec['ga:profileId']; 
  81. $this->account_cache = array(); 
  82. $this->account_cache['ua'] = $ua; 
  83. $this->account_cache['profiles'] = $profiles; 
  84. $preload["{$this->prefix}account_cache"] = $this->account_cache; 
  85. } else { 
  86. unset( $this->token ); 
  87. unset( $this->secret ); 
  88. unset( $this->ga_token ); 
  89. unset( $preload["{$this->prefix}ga_token"] ); //errorcondition here -- pdb 
  90. $response = wp_remote_retrieve_body( $data ); 
  91. $xml = $this->xml_string_to_array( $response ); 
  92. if ( ! empty( $xml ) && ! empty( $xml[error] ) ) { 
  93. $error = 'Error: '; 
  94. if ( ! empty( $xml[error]['internalReason'] ) ) { 
  95. $error .= $xml[error]['internalReason']; 
  96. } else { 
  97. foreach ( $xml[error] as $k => $v ) { 
  98. $error .= "$k: $v\n"; 
  99. $this->output_error( $error ); 
  100. if ( ! empty( $this->ga_token ) ) { 
  101. $this->default_options['google_analytics_id']['type'] = 'select'; 
  102. $this->default_options['google_analytics_id']['initial_options'] = $ua; 
  103. $this->default_options['google_connect']['type'] = 'html'; 
  104. $this->default_options['google_connect']['nolabel'] = 1; 
  105. $this->default_options['google_connect']['save'] = true; 
  106. $this->default_options['google_connect']['name'] = __( 'Disconnect From Google Analytics', 'all-in-one-seo-pack' ); 
  107. $this->default_options['google_connect']['default'] = "<input name='aiosp_google_connect' type=submit class='button-primary' value='" . __( 'Remove Stored Credentials', 'all-in-one-seo-pack' ) . "'>"; 
  108. add_filter( $this->prefix . 'override_options', Array( $this, 'override_options' ), 10, 3 ); 
  109. } else { 
  110. $this->default_options['google_connect']['type'] = 'html'; 
  111. $this->default_options['google_connect']['nolabel'] = 1; 
  112. $this->default_options['google_connect']['save'] = false; 
  113. $url = $this->oauth_connect(); 
  114. $this->default_options['google_connect']['default'] = "<a href='{$url}' class='button-primary'>" . __( 'Connect With Google Analytics', 'all-in-one-seo-pack' ) . '</a>'; 
  115. foreach ( array( 'token', 'secret', 'access_token', 'ga_token', 'account_cache' ) as $v ) { 
  116. if ( ! empty( $this->$v ) ) { 
  117. $preload["{$this->prefix}{$v}"] = $this->$v; 
  118. $this->update_class_option( $preload ); 
  119. $this->update_options(); 
  120. // $url = $this->report_query(); 
  121. if ( ! empty( $this->account_cache ) && ! empty( $this->options["{$this->prefix}google_analytics_id"] ) && ! empty( $this->account_cache['profiles'][ $this->options["{$this->prefix}google_analytics_id"] ] ) ) { 
  122. $this->profile_id = $this->account_cache['profiles'][ $this->options["{$this->prefix}google_analytics_id"] ];