/sites/hi5.js

http://google-sgnodemapper.googlecode.com/ · JavaScript · 138 lines · 81 code · 38 blank · 19 comment · 9 complexity · b3059e7a8906d9c293d5a8b7b091ef32 MD5 · raw file

  1. // -*-java-*-
  2. /**
  3. * Copyright 2007 Google Inc.
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. **/
  16. var HAS_ID_REGEXP = /\b(?:ownerId=|userid=|friend\/|\/profile\/foaf\/)(\d+)/;
  17. var FRIEND_ID_REGEXP = /^\/friend\/p(\d+)-/;
  18. var DISPLAY_PROFILE = /^\/friend\/profile\/displayHi5URL\.do\?nickname=([\w\-]{6,})\b/;
  19. var NUMERIC_DOMAIN = /^(\d+)\.hi5\.com$/;
  20. function urlToGraphNodeHi5(url, host, path) {
  21. var m;
  22. if ((m = HAS_ID_REGEXP.exec(path)) ||
  23. (m = FRIEND_ID_REGEXP.exec(path))) {
  24. return "sgn://hi5.com/?pk=" + m[1];
  25. }
  26. // subdomain users have to be 6+ characters
  27. if (path == "/" && (m = /^([\w\-]{6,})\.hi5\.com$/.exec(host))) {
  28. var match = m[1];
  29. if (/[^\d]/.exec(match)) {
  30. return "sgn://hi5.com/?ident=" + m[1].toLowerCase();
  31. } else {
  32. return "sgn://hi5.com/?pk=" + m[1];
  33. }
  34. }
  35. // display nickname
  36. if (m = DISPLAY_PROFILE.exec(path)) {
  37. return "sgn://hi5.com/?ident=" + m[1].toLowerCase();
  38. }
  39. // numeric domain and no query string that might alter what's
  40. // being viewed
  41. if ((m = NUMERIC_DOMAIN.exec(host)) && !/\?/.exec(path)) {
  42. return "sgn://hi5.com/?pk=" + m[1];
  43. }
  44. return url;
  45. }
  46. nodemapper.registerDomain(
  47. "hi5.com", {
  48. name: "hi5",
  49. urlToGraphNode: urlToGraphNodeHi5
  50. });
  51. nodemapper.addSimpleHandler("hi5.com", "pk_to_foaf",
  52. "http://api.hi5.com/rest/profile/foaf/", "");
  53. nodemapper.addSimpleHandler("hi5.com", "pk_to_content",
  54. "http://www.hi5.com/friend/profile/displayProfile.do?userid=", "");
  55. nodemapper.addSimpleHandler("hi5.com", "pk_to_profile",
  56. "http://www.hi5.com/friend/profile/displayProfile.do?userid=", "");
  57. nodemapper.addSimpleHandler("hi5.com", "pk_to_atom",
  58. "http://api.hi5.com/rest/feed/journal/", "");
  59. nodemapper.addSimpleHandler("hi5.com", "pk_to_foaf",
  60. "http://api.hi5.com/rest/profile/foaf/", "");
  61. nodemapper.addSimpleHandler("hi5.com", "pk_to_blog",
  62. "http://www.hi5.com/friend/profile/displayJournal.do?userid=", "");
  63. nodemapper.addSimpleHandler("hi5.com", "ident_to_content",
  64. "http://", ".hi5.com/");
  65. nodemapper.addSimpleHandler("hi5.com", "ident_to_profile",
  66. "http://", ".hi5.com/");
  67. __END__
  68. http://api.hi5.com/rest/profile/foaf/87628233 sgn://hi5.com/?pk=87628233
  69. http://lindner.hi5.com/ sgn://hi5.com/?ident=lindner
  70. http://123455.hi5.com/ sgn://hi5.com/?pk=123455
  71. # usernames must be 6 characters or more:
  72. http://www.hi5.com/ http://www.hi5.com/
  73. http://api.hi5.com/ http://api.hi5.com/
  74. http://www.hi5.com/friend/profile/displayProfile.do?userid=127525866 sgn://hi5.com/?pk=127525866
  75. http://lindner.hi5.com/friend/profile/displayJournal.do?viewother=true&ownerId=87628233 sgn://hi5.com/?pk=87628233
  76. http://lindner.hi5.com/friend/photos/displayUserAlbum.do?viewother=true&ownerId=87628233 sgn://hi5.com/?pk=87628233
  77. http://bradfitz.hi5.com/friend/photos/displayUserAlbum.do?viewother=true&ownerId=87628233 sgn://hi5.com/?pk=87628233
  78. http://lindner.hi5.com/friend/87628233--Paul--Profile-html sgn://hi5.com/?pk=87628233
  79. http://bradfitz.hi5.com/friend/87628233--Paul--Profile-html sgn://hi5.com/?pk=87628233
  80. http://lindner.hi5.com/friend/87628233--Paul--Friends-html sgn://hi5.com/?pk=87628233
  81. http://lindner.hi5.com/friend/profile/displayFriends.do?userid=87628233&offset=24 sgn://hi5.com/?pk=87628233
  82. http://bradfitz.hi5.com/friend/87628233--Paul--Friends-html sgn://hi5.com/?pk=87628233
  83. # Not lindner:
  84. http://lindner.hi5.com/friend/30399640--Dan--Profile-html sgn://hi5.com/?pk=30399640
  85. # when logged in:
  86. http://www.hi5.com/friend/profile/displaySameProfile.do?userid=87628233 sgn://hi5.com/?pk=87628233
  87. http://www.hi5.com/friend/profile/displayHi5URL.do?nickname=koolby sgn://hi5.com/?ident=koolby
  88. http://www.hi5.com/friend/profile/displayHi5URL.do?nickname=bradfitz sgn://hi5.com/?ident=bradfitz
  89. # pk
  90. content(sgn://hi5.com/?pk=123) http://www.hi5.com/friend/profile/displayProfile.do?userid=123
  91. profile(sgn://hi5.com/?pk=123) http://www.hi5.com/friend/profile/displayProfile.do?userid=123
  92. atom(sgn://hi5.com/?pk=123) http://api.hi5.com/rest/feed/journal/123
  93. foaf(sgn://hi5.com/?pk=87628233) http://api.hi5.com/rest/profile/foaf/87628233
  94. blog(sgn://hi5.com/?pk=12345) http://www.hi5.com/friend/profile/displayJournal.do?userid=12345
  95. # ident
  96. content(sgn://hi5.com/?ident=bobfoo) http://bobfoo.hi5.com/
  97. profile(sgn://hi5.com/?ident=bobfoo) http://bobfoo.hi5.com/
  98. http://53835694.hi5.com/friend/profile/displayProfile.do sgn://hi5.com/?pk=53835694
  99. http://bobfoo.hi5.com/friend/p1234--Foo_Bar%20Bar--html sgn://hi5.com/?pk=1234
  100. http://bobfoo.hi5.com/friend/p5678--Paula--html sgn://hi5.com/?pk=5678