|
3 | 3 | use GraphQL\GraphQL;
|
4 | 4 | use GraphQL\Utils\BuildSchema;
|
5 | 5 |
|
6 |
| -class VFA_ResolverStartupStartup extends VFA_Resolver { |
7 |
| - public function index() { |
| 6 | +class VFA_ResolverStartupStartup extends VFA_Resolver |
| 7 | +{ |
| 8 | + public function index() |
| 9 | + { |
| 10 | + if ($this->request->get_param('cors')) { |
| 11 | + if (! empty($_SERVER['HTTP_ORIGIN'])) { |
| 12 | + header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']); |
| 13 | + } else { |
| 14 | + header('Access-Control-Allow-Origin: *'); |
| 15 | + } |
| 16 | + header('Access-Control-Allow-Methods: POST, OPTIONS'); |
| 17 | + header('Access-Control-Allow-Credentials: true'); |
| 18 | + header('Access-Control-Allow-Headers: DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Token,token,Cookie,cookie,content-type'); |
| 19 | + } |
8 | 20 |
|
9 |
| -// if ( is_plugin_active( 'd_vuefront/plugin.php' ) ) { |
10 |
| - if ( $this->request->get_param( 'cors' ) ) { |
11 |
| - if ( ! empty( $_SERVER['HTTP_ORIGIN'] ) ) { |
12 |
| - header( 'Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN'] ); |
13 |
| - } else { |
14 |
| - header( 'Access-Control-Allow-Origin: *' ); |
15 |
| - } |
16 |
| - header( 'Access-Control-Allow-Methods: POST, OPTIONS' ); |
17 |
| - header( 'Access-Control-Allow-Credentials: true' ); |
18 |
| - header( 'Access-Control-Allow-Headers: DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Token,token,Cookie,cookie,content-type' ); |
19 |
| - } |
| 21 | + $this->load->model('startup/startup'); |
20 | 22 |
|
21 |
| - $this->load->model( 'startup/startup' ); |
| 23 | + try { |
| 24 | + $resolvers = $this->model_startup_startup->getResolvers(); |
| 25 | + $schema = BuildSchema::build(file_get_contents(VFA_DIR_PLUGIN . 'schema.graphql')); |
| 26 | + $rawInput = file_get_contents('php://input'); |
| 27 | + $input = json_decode($rawInput, true); |
| 28 | + $query = $input['query']; |
22 | 29 |
|
23 |
| - try { |
24 |
| - $resolvers = $this->model_startup_startup->getResolvers(); |
25 |
| - $schema = BuildSchema::build( file_get_contents( VFA_DIR_PLUGIN . 'schema.graphql' ) ); |
26 |
| - $rawInput = file_get_contents( 'php://input' ); |
27 |
| - $input = json_decode( $rawInput, true ); |
28 |
| - $query = $input['query']; |
| 30 | + $variableValues = isset($input['variables']) ? $input['variables'] : null; |
| 31 | + $result = GraphQL::executeQuery($schema, $query, $resolvers, null, $variableValues); |
| 32 | + } catch (\Exception $e) { |
| 33 | + $result = [ |
| 34 | + 'error' => [ |
| 35 | + 'message' => $e->getMessage() |
| 36 | + ] |
| 37 | + ]; |
| 38 | + } |
29 | 39 |
|
30 |
| - $variableValues = isset( $input['variables'] ) ? $input['variables'] : null; |
31 |
| - $result = GraphQL::executeQuery( $schema, $query, $resolvers, null, $variableValues ); |
32 |
| - } catch ( \Exception $e ) { |
33 |
| - $result = [ |
34 |
| - 'error' => [ |
35 |
| - 'message' => $e->getMessage() |
36 |
| - ] |
37 |
| - ]; |
38 |
| - } |
| 40 | + $cookie_path = COOKIEPATH ? COOKIEPATH : '/'; |
39 | 41 |
|
| 42 | + if ($cookie_path != '/') { |
| 43 | + foreach ($_COOKIE as $key => $value) { |
| 44 | + if (strpos($key, 'woocommerce') >= 0) { |
| 45 | + setcookie($key, $value, 0, "/"); |
| 46 | + } |
| 47 | + } |
| 48 | + } |
40 | 49 |
|
41 |
| - foreach ( $_COOKIE as $key => $value ) { |
42 |
| - if ( strpos( $key, 'woocommerce' ) >= 0 ) { |
43 |
| - setcookie( $key, $value, 0, "/" ); |
44 |
| - } |
45 |
| - } |
| 50 | + return $result; |
| 51 | + } |
46 | 52 |
|
47 |
| - return $result; |
48 |
| - } |
| 53 | + public function determine_current_user($user) |
| 54 | + { |
| 55 | + $this->load->model('common/token'); |
49 | 56 |
|
50 |
| - public function determine_current_user( $user ) { |
51 |
| - $this->load->model( 'common/token' ); |
| 57 | + $validate_uri = strpos($_SERVER['REQUEST_URI'], 'token/validate'); |
| 58 | + if ($validate_uri > 0) { |
| 59 | + return $user; |
| 60 | + } |
52 | 61 |
|
53 |
| - $validate_uri = strpos( $_SERVER['REQUEST_URI'], 'token/validate' ); |
54 |
| - if ( $validate_uri > 0 ) { |
55 |
| - return $user; |
56 |
| - } |
| 62 | + $token = $this->model_common_token->validateToken(false); |
57 | 63 |
|
58 |
| - $token = $this->model_common_token->validateToken( false ); |
| 64 | + if (! $token) { |
| 65 | + return $user; |
| 66 | + } |
59 | 67 |
|
60 |
| - if ( ! $token ) { |
61 |
| - return $user; |
62 |
| - } |
63 |
| - |
64 |
| - return $token->data->user->id; |
65 |
| - } |
66 |
| -// } |
| 68 | + return $token->data->user->id; |
| 69 | + } |
67 | 70 | }
|
0 commit comments