base.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /* Ad hoc functions to make the examples marginally prettier.*/
  3. function isWebRequest()
  4. {
  5. return isset($_SERVER['HTTP_USER_AGENT']);
  6. }
  7. function pageHeader($title)
  8. {
  9. $ret = "";
  10. if (isWebRequest()) {
  11. $ret .= "<!doctype html>
  12. <html>
  13. <head>
  14. <title>" . $title . "</title>
  15. <link href='styles/style.css' rel='stylesheet' type='text/css' />
  16. </head>
  17. <body>\n";
  18. if ($_SERVER['PHP_SELF'] != "/index.php") {
  19. $ret .= "<p><a href='index.php'>Back</a></p>";
  20. }
  21. $ret .= "<header><h1>" . $title . "</h1></header>";
  22. }
  23. return $ret;
  24. }
  25. function pageFooter($file = null)
  26. {
  27. $ret = "";
  28. if (isWebRequest()) {
  29. // Echo the code if in an example.
  30. if ($file) {
  31. $ret .= "<h3>Code:</h3>";
  32. $ret .= "<pre class='code'>";
  33. $ret .= htmlspecialchars(file_get_contents($file));
  34. $ret .= "</pre>";
  35. }
  36. $ret .= "</html>";
  37. }
  38. return $ret;
  39. }
  40. function missingApiKeyWarning()
  41. {
  42. $ret = "";
  43. if (isWebRequest()) {
  44. $ret = "
  45. <h3 class='warn'>
  46. Warning: You need to set a Simple API Access key from the
  47. <a href='http://developers.google.com/console'>Google API console</a>
  48. </h3>";
  49. } else {
  50. $ret = "Warning: You need to set a Simple API Access key from the Google API console:";
  51. $ret .= "\nhttp://developers.google.com/console\n";
  52. }
  53. return $ret;
  54. }
  55. function missingClientSecretsWarning()
  56. {
  57. $ret = "";
  58. if (isWebRequest()) {
  59. $ret = "
  60. <h3 class='warn'>
  61. Warning: You need to set Client ID, Client Secret and Redirect URI from the
  62. <a href='http://developers.google.com/console'>Google API console</a>
  63. </h3>";
  64. } else {
  65. $ret = "Warning: You need to set Client ID, Client Secret and Redirect URI from the";
  66. $ret .= " Google API console:\nhttp://developers.google.com/console\n";
  67. }
  68. return $ret;
  69. }
  70. function missingServiceAccountDetailsWarning()
  71. {
  72. $ret = "";
  73. if (isWebRequest()) {
  74. $ret = "
  75. <h3 class='warn'>
  76. Warning: You need to set Client ID, Email address and the location of the Key from the
  77. <a href='http://developers.google.com/console'>Google API console</a>
  78. </h3>";
  79. } else {
  80. $ret = "Warning: You need to set Client ID, Email address and the location of the Key from the";
  81. $ret .= " Google API console:\nhttp://developers.google.com/console\n";
  82. }
  83. return $ret;
  84. }