PageRenderTime 44ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/profileroom/index.php

https://github.com/Web5design/gplus-experiments
PHP | 326 lines | 273 code | 34 blank | 19 comment | 28 complexity | 6b850fd4c52e140c950135920851396e MD5 | raw file
Possible License(s): Apache-2.0
  1. <?php
  2. /*
  3. * Copyright 2011-2012 Gerwin Sturm, FoldedSoft e.U. / www.foldedsoft.at
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. include "config.php";
  18. $user_ip = $_SERVER["REMOTE_ADDR"];
  19. if(!$user_ip||$user_ip=="") {
  20. $user_ip = $_SERVER["SERVER_ADDR"];
  21. }
  22. require_once $gapi_client_path . "apiClient.php";
  23. require_once $gapi_client_path . "contrib/apiPlusService.php";
  24. session_start();
  25. $client = new apiClient();
  26. $client->setApplicationName("ProfileRoom+");
  27. $client->setClientId($client_id);
  28. $client->setClientSecret($client_secret);
  29. $client->setRedirectUri($base_url . "index.php");
  30. $client->setDeveloperKey($developer_key);
  31. $client->setScopes(array("https://www.googleapis.com/auth/plus.me"));
  32. $plus = new apiPlusService($client);
  33. if (isset($_GET["code"])) {
  34. $client->authenticate();
  35. $_SESSION["access_token"] = $client->getAccessToken();
  36. header("Location: ".$base_url."check.php");
  37. }
  38. if (isset($_GET["error"])) {
  39. unset($_SESSION["access_token"]);
  40. header("Location: ".$base_url);
  41. }
  42. if (isset($_REQUEST["logout"])) {
  43. unset($_SESSION["access_token"]);
  44. header("Location: ".$base_url);
  45. }
  46. $request = $_SERVER["REQUEST_URI"];
  47. $path = $_SERVER["PHP_SELF"];
  48. $p = strrpos($path,"/");
  49. if(!($p === false)) {
  50. $request = substr($request,$p+1);
  51. $path = substr($path,0,$p);
  52. }
  53. $q_user = "";
  54. if(substr($request,0,1) == "u") {
  55. $q_user = substr($request,2);
  56. }
  57. if (isset($_SESSION["access_token"])) {
  58. $client->setAccessToken($_SESSION["access_token"]);
  59. }
  60. if ($client->getAccessToken()) {
  61. try {
  62. $me = $plus->people->get('me');
  63. $_SESSION["access_token"] = $client->getAccessToken();
  64. if($q_user=="") {
  65. header("Location: ".$base_url."u/".$me["id"]);
  66. }
  67. $login_id = $me["id"];
  68. $login_name = $me["displayName"];
  69. } catch (Exception $e) {
  70. unset($_SESSION["access_token"]);
  71. $authUrl = $client->createAuthUrl();
  72. $authUrl = str_replace("&amp;","&",$authUrl);
  73. $authUrl = str_replace("&","&amp;",$authUrl);
  74. }
  75. } else {
  76. $authUrl = $client->createAuthUrl();
  77. $authUrl = str_replace("&amp;","&",$authUrl);
  78. $authUrl = str_replace("&","&amp;",$authUrl);
  79. }
  80. $user_name = "";
  81. $user_pic = "";
  82. if($q_user!="") {
  83. try {
  84. $user = $plus->people->get($q_user);
  85. if(isset($user["displayName"])) {
  86. $user_name = $user["displayName"];
  87. if(isset($user["image"])) {
  88. $user_pic = $user["image"]["url"];
  89. } else {
  90. $user_pic = $base_url . "images/noimage.jpg";
  91. }
  92. }
  93. } catch (Exception $e) {}
  94. }
  95. ?>
  96. <!DOCTYPE html>
  97. <html itemscope itemtype="http://schema.org/Person">
  98. <head>
  99. <meta charset="UTF-8">
  100. <?php
  101. if($user_name!="") {
  102. printf(" <title>ProfileRoom+ / %s</title>\n",$user_name);
  103. printf(" <meta itemprop=\"name\" content=\"ProfileRoom+ / %s\">\n",$user_name);
  104. printf(" <meta itemprop=\"description\" content=\"The Google+ profile of %s, visualized in WebGL.\">\n",$user_name);
  105. printf(" <meta itemprop=\"image\" content=\"%s\">\n",$user_pic);
  106. } else {
  107. printf(" <title>ProfileRoom+</title>\n");
  108. printf(" <meta itemprop=\"name\" content=\"ProfileRoom+\">\n");
  109. printf(" <meta itemprop=\"description\" content=\"Google+ profiles visualized in WebGL.\">\n");
  110. printf(" <meta itemprop=\"image\" content=\"%simages/profileroom+.png\">\n", $base_url);
  111. }
  112. ?>
  113. <!--
  114. Copyright 2011-2012 Gerwin Sturm, FoldedSoft e.U. / www.foldedsoft.at
  115. Licensed under the Apache License, Version 2.0 (the "License");
  116. you may not use this file except in compliance with the License.
  117. You may obtain a copy of the License at
  118. http://www.apache.org/licenses/LICENSE-2.0
  119. Unless required by applicable law or agreed to in writing, software
  120. distributed under the License is distributed on an "AS IS" BASIS,
  121. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  122. See the License for the specific language governing permissions and
  123. limitations under the License.
  124. -->
  125. <link rel="stylesheet" type="text/css" href="/style.css">
  126. <link rel="shortcut icon" href="/favicon.ico">
  127. <link rel="icon" href="/favicon.ico">
  128. <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
  129. <script type="text/javascript" src="https://apis.google.com/js/plusone.js">
  130. {"parsetags": "explicit"}
  131. </script>
  132. <script type="text/javascript" src="<?php echo $base_url; ?>scripts/glMatrix-0.9.5.min.js"></script>
  133. <script type="text/javascript" src="<?php echo $base_url; ?>scripts/webgl-utils.js"></script>
  134. <script type="text/javascript" src="<?php echo $base_url; ?>scripts/profileroom.js"></script>
  135. <script id="per-vertex-lighting-fs" type="x-shader/x-fragment">
  136. #ifdef GL_ES
  137. precision highp float;
  138. #endif
  139. varying vec2 vTextureCoord;
  140. varying vec3 vLightWeighting;
  141. uniform bool uUseTexture;
  142. uniform sampler2D uSampler;
  143. uniform vec4 uColor;
  144. void main(void) {
  145. vec4 fColor;
  146. if(uUseTexture) {
  147. fColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t));
  148. } else {
  149. fColor = uColor;
  150. }
  151. gl_FragColor = vec4(fColor.rgb * vLightWeighting, 1.0);
  152. }
  153. </script>
  154. <script id="per-vertex-lighting-vs" type="x-shader/x-vertex">
  155. attribute vec3 aVertexPosition;
  156. attribute vec3 aVertexNormal;
  157. attribute vec2 aTextureCoord;
  158. uniform mat4 uMVMatrix;
  159. uniform mat4 uPMatrix;
  160. uniform mat3 uNMatrix;
  161. uniform vec3 uAmbientColor;
  162. uniform bool uUseLighting;
  163. uniform vec3 uPointLightingLocation;
  164. uniform vec3 uPointLightingColor;
  165. varying vec2 vTextureCoord;
  166. varying vec3 vLightWeighting;
  167. void main(void) {
  168. vec4 mvPosition = uMVMatrix * vec4(aVertexPosition, 1.0);
  169. gl_Position = uPMatrix * mvPosition;
  170. vTextureCoord = aTextureCoord;
  171. if(uUseLighting) {
  172. vec4 cameraPosition = vec4(uPointLightingLocation,1.0);
  173. vec3 lightDirection = cameraPosition.xyz - mvPosition.xyz;
  174. float distance = length(lightDirection);
  175. distance = (60.0 - abs(distance))/60.0;
  176. distance = min(max(distance,0.1),1.2);
  177. lightDirection = normalize(lightDirection);
  178. vec3 transformedNormal = uNMatrix * aVertexNormal;
  179. float directionalLightWeighting = abs(dot(transformedNormal, lightDirection));
  180. vLightWeighting = (uAmbientColor + uPointLightingColor * directionalLightWeighting)*distance;
  181. } else {
  182. vLightWeighting = vec3(1.0,1.0,1.0);
  183. }
  184. }
  185. </script>
  186. <script id="per-fragment-lighting-fs" type="x-shader/x-fragment">
  187. #ifdef GL_ES
  188. precision highp float;
  189. #endif
  190. varying vec2 vTextureCoord;
  191. varying vec3 vTransformedNormal;
  192. varying vec4 vPosition;
  193. uniform vec3 uAmbientColor;
  194. uniform mat4 uMVMatrix;
  195. uniform vec3 uPointLightingColor;
  196. uniform vec3 uPointLightingLocation;
  197. uniform vec4 uColor;
  198. uniform bool uUseLighting;
  199. uniform bool uUseTexture;
  200. uniform sampler2D uSampler;
  201. void main(void) {
  202. vec3 lightWeighting;
  203. if(uUseLighting) {
  204. vec4 cameraPosition = vec4(uPointLightingLocation,1.0);
  205. vec3 lightDirection = cameraPosition.xyz - vPosition.xyz;
  206. float distance = length(lightDirection);
  207. distance = (60.0 - abs(distance))/60.0;
  208. distance = min(max(distance,0.1),1.2);
  209. lightDirection = normalize(lightDirection);
  210. float directionalLightWeighting = abs(dot(normalize(vTransformedNormal), lightDirection));
  211. lightWeighting = uAmbientColor + uPointLightingColor * directionalLightWeighting;
  212. lightWeighting = lightWeighting*distance;
  213. } else {
  214. lightWeighting = vec3(1.0,1.0,1.0);
  215. }
  216. vec4 fColor;
  217. if(uUseTexture) {
  218. fColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t));
  219. } else {
  220. fColor = uColor;
  221. }
  222. gl_FragColor = vec4(fColor.rgb * lightWeighting, 1.0);
  223. }
  224. </script>
  225. <script id="per-fragment-lighting-vs" type="x-shader/x-vertex">
  226. attribute vec3 aVertexPosition;
  227. attribute vec3 aVertexNormal;
  228. attribute vec2 aTextureCoord;
  229. uniform mat4 uMVMatrix;
  230. uniform mat4 uPMatrix;
  231. uniform mat3 uNMatrix;
  232. varying vec2 vTextureCoord;
  233. varying vec3 vTransformedNormal;
  234. varying vec4 vPosition;
  235. void main(void) {
  236. vPosition = uMVMatrix * vec4(aVertexPosition, 1.0);
  237. gl_Position = uPMatrix * vPosition;
  238. vTextureCoord = aTextureCoord;
  239. vTransformedNormal = uNMatrix * aVertexNormal;
  240. }
  241. </script>
  242. <script type="text/javascript">
  243. var base_url = "<?php echo $base_url; ?>";
  244. var API_KEY = "<?php echo $developer_key; ?>";
  245. </script>
  246. </head>
  247. <body onload="profileRoomStart();">
  248. <div id="header" class="ds_header">
  249. <div id="header1">
  250. <table><tr>
  251. <?php
  252. if(isset($authUrl)) {
  253. printf(" <td style=\"height: 25px; text-align: right;\"><a class=\"login\" href=\"%s\" title=\"Read the privacy statement for details.\">Login via Google</a> / <a href=\"%sinfo.html\">Privacy Statement &amp; Info</a></td>\n",$authUrl,$base_url);
  254. } else {
  255. printf(" <td style=\"height: 25px; text-align: right;\">Logged in as <a href=\"%su/%s\">%s</a> / <a class=\"logout\" href=\"?logout\">Logout</a> / <a href=\"%sinfo.html\">Privacy Statement &amp; Info</a></td>\n",$base_url,$login_id,$login_name,$base_url,$base_url);
  256. }?>
  257. </tr></table>
  258. </div>
  259. <div id="header2">
  260. <div id="header2_info" style="width:965px; max-width:965px; min-width:965px;">
  261. <table>
  262. <tr>
  263. <td style="width:80px;"><a href="<?php echo $base_url; ?>"><img src="<?php echo $base_url; ?>images/profileroom+.png" alt="ProfileRoom+" style="border: 0px;" /></a></td>
  264. <td id="pr_username">
  265. ProfileRoom+<br>
  266. <div id="pr_userform"><form>Profile ID: <input id="userid" name="userid" title="Go to a Google+ profile and copy the long number from the URL into this field."><input type="submit" onclick="form_submit(); return false;"></form></div>
  267. </td>
  268. <td style="width:120px;text-align:right;" id="plusone_td"><div id="plusone_div"></div></td>
  269. <td style="width:140px;text-align:right;"><a href="http://www.w3.org/html/logo/"><img src="<?php echo $base_url; ?>images/html5-badge-h-graphics.png" width="133" height="64" style="border: 0px;" alt="HTML5 Powered with Graphics, 3D &amp; Effects" title="HTML5 Powered with Graphics, 3D &amp; Effects"></a></td>
  270. </tr>
  271. </table>
  272. </div>
  273. </div>
  274. </div>
  275. <div id="main" style="width:965px; max-width:965px; min-width:965px;">
  276. <div id="pr_main">
  277. <canvas id="profileroom" style="border: none;" width="640" height="400"></canvas>
  278. </div>
  279. <div id="pr_details"></div>
  280. <div id="pr_errors"></div>
  281. <div id="pr_instructions">
  282. <br>
  283. Move with W/A/S/D, look around with cursor keys or by moving the mouse to the edges.<br />
  284. Approach a profile photo and press ENTER to go into this person's room. Use BACKSPACE/Back-Button to return to previous room.
  285. </div><br>
  286. <a href="<?php echo $base_url; ?>info.html">More information about this project</a><br>
  287. </div>
  288. <div id="footer" class="footer_ds">
  289. Programming by <a href="https://profiles.google.com/scarygami" rel="author">Gerwin Sturm</a>, <a href="http://www.foldedsoft.at/">FoldedSoft e.U.</a> / <a href="<?php echo $base_url; ?>info.html">Privacy Statement &amp; Info</a>
  290. </div>
  291. </body>
  292. </html>