/var/www/hkosl.com/littleark/webadmin/libraies/google/apiclient/examples/templates/base.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php

/* Ad hoc functions to make the examples marginally prettier.*/
function isWebRequest()
{
  return isset(
$_SERVER['HTTP_USER_AGENT']);
}

function 
pageHeader($title)
{
  
$ret "<!doctype html>
  <html>
  <head>
    <title>" 
$title "</title>
    <link href='styles/style.css' rel='stylesheet' type='text/css' />
  </head>
  <body>\n"
;
  if (
$_SERVER['PHP_SELF'] != "/index.php") {
    
$ret .= "<p><a href='index.php'>Back</a></p>";
  }
  
$ret .= "<header><h1>" $title "</h1></header>";

 
// Start the session (for storing access tokens and things)
  
if (!headers_sent()) {
    
session_start();
  }

  return 
$ret;
}


function 
pageFooter($file null)
{
  
$ret "";
  if (
$file) {
    
$ret .= "<h3>Code:</h3>";
    
$ret .= "<pre class='code'>";
    
$ret .= htmlspecialchars(file_get_contents($file));
    
$ret .= "</pre>";
  }
  
$ret .= "</html>";

  return 
$ret;
}

function 
missingApiKeyWarning()
{
  
$ret "
    <h3 class='warn'>
      Warning: You need to set a Simple API Access key from the
      <a href='http://developers.google.com/console'>Google API console</a>
    </h3>"
;

  return 
$ret;
}

function 
missingClientSecretsWarning()
{
  
$ret "
    <h3 class='warn'>
      Warning: You need to set Client ID, Client Secret and Redirect URI from the
      <a href='http://developers.google.com/console'>Google API console</a>
    </h3>"
;

  return 
$ret;
}

function 
missingServiceAccountDetailsWarning()
{
  
$ret "
    <h3 class='warn'>
      Warning: You need download your Service Account Credentials JSON from the
      <a href='http://developers.google.com/console'>Google API console</a>.
    </h3>
    <p>
      Once downloaded, move them into the root directory of this repository and
      rename them 'service-account-credentials.json'.
    </p>
    <p>
      In your application, you should set the GOOGLE_APPLICATION_CREDENTIALS environment variable
      as the path to this file, but in the context of this example we will do this for you.
    </p>"
;

  return 
$ret;
}

function 
missingOAuth2CredentialsWarning()
{
  
$ret "
    <h3 class='warn'>
      Warning: You need to set the location of your OAuth2 Client Credentials from the
      <a href='http://developers.google.com/console'>Google API console</a>.
    </h3>
    <p>
      Once downloaded, move them into the root directory of this repository and
      rename them 'oauth-credentials.json'.
    </p>"
;

  return 
$ret;
}

function 
checkServiceAccountCredentialsFile()
{
  
// service account creds
  
$application_creds __DIR__ '/../../service-account-credentials.json';

  return 
file_exists($application_creds) ? $application_creds false;
}

function 
getOAuthCredentialsFile()
{
  
// oauth2 creds
  
$oauth_creds __DIR__ '/../../oauth-credentials.json';

  if (
file_exists($oauth_creds)) {
    return 
$oauth_creds;
  }

  return 
false;
}

function 
setClientCredentialsFile($apiKey)
{
  
$file __DIR__ '/../../tests/.apiKey';
  
file_put_contents($file$apiKey);
}


function 
getApiKey()
{
  
$file __DIR__ '/../../tests/.apiKey';
  if (
file_exists($file)) {
    return 
file_get_contents($file);
  }
}

function 
setApiKey($apiKey)
{
  
$file __DIR__ '/../../tests/.apiKey';
  
file_put_contents($file$apiKey);
}