PageRenderTime 43ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 1ms

/core/notes.php

http://buddypress-media.googlecode.com/
PHP | 241 lines | 196 code | 44 blank | 1 comment | 4 complexity | dca137993faa744a9c0b02e8a2956030 MD5 | raw file
Possible License(s): AGPL-1.0, Apache-2.0, GPL-2.0, LGPL-2.1
  1. <?php
  2. ?>
  3. Render Buffer
  4. ===============================
  5. -Instead of dumping raw HTML to the PHP output buffer, we render our template code to a separate render buffer. This
  6. allows objects further down the pipeline to abort the rendering process if they hit an error.
  7. For example:
  8. 1) a page module initiates the rendering process
  9. 2) ...and calls an album module
  10. 3) ...which calls a media module
  11. There are several possible outcomes:
  12. a) The item doesn't exist - so we would want to throw a 404 (if the user-agent is a bot) or redirect (if the user-agent is a browser)
  13. b) The item exists, but the user-agent is a bot and the server is overloaded - so we want to throw a 429
  14. c) The item existed but was deleted - so we want to throw a 410
  15. d) The item exists and we want to show it - so we want to render the media item
  16. In cases a) through c) we'd want to abort the render process, zero the render buffer, re-load it with the correct HTML, and
  17. then send it to the user-agent. This is not possible to do using conventional WordPress templates.
  18. Headers
  19. ===============================
  20. -We probably also need to bypass the WordPress header generation process, because WP appears to automatically send these
  21. ###################################################################################################
  22. URL's -vs- AJAX -vs- GET
  23. ========================
  24. -The purpose of URL's and encoding things as fake directories in the URL is to give search engines a hierarchical tree of
  25. data to crawl. Fetching content this way carries a big penalty because WP/BP/BPM has to disassemble the URL, figure out
  26. what page/plugin/module/action/etc should be given control, render an entire web page, and then send it to the user.
  27. -That's why most social networking sites use very limited URL schemes. Google+ is 4 levels deep, then uses AJAX. Facebook
  28. is 2 levels deep, then uses GET variables to encode data + AJAX to fetch content.
  29. -For any crawlable pages, we should encode the variables in directories. For all other actions, we should use AJAX, because
  30. it provides the best user experience.
  31. FEATURED MEDIA
  32. =======================
  33. /featured_media/ - First page of results
  34. /featured_media/p/X - Page X of results
  35. Links jump to:
  36. /group_album/group_id/a/album_id/m/media_id/
  37. /user_album/user_id/a/album_id/m/media_id/
  38. - Its impossible to include more control in the URL because the next logical step is "filtering" (show only videos, show only images),
  39. and the next step after that is "ordering" (most popular, most views), and the next step after that is multi-dimensional sort / filter / search
  40. (show only "videos" of "skydiving" ranked by "most views"). This is what YouTube does, with about 25 drop-down boxes, using AJAX.
  41. -So in *this case* just jump directly to the AJAX for this functionality because the URL encoding would be practically impossible.
  42. FRIENDS MEDIA
  43. =======================
  44. /friends_media/user_id/ - First page of results for user_id
  45. /friends_media/user_id/p/X - Page X of results for user_id
  46. Links jump to:
  47. /user_album/user_id/a/album_id/m/media_id/
  48. -Media items are always nested inside an album in the URL. This gives us the album_id and media_id simultaneously, so we can run two DB calls in parallel
  49. (via AJAX or node.js) to build the page instead of first fetching the media_id info, then using the album_id stored in the record to fetch the album_id info. This is probably
  50. why Google+ and Facebook encode both ID's in the URL.
  51. GROUP ALBUMS
  52. =======================
  53. URL'S
  54. /group_albums/group_id/ - First page of albums
  55. /group_albums/group_id/p/X/ - Page X of albums
  56. ...links jump to: /group_albums/group_id/a/album_id/
  57. /group_albums/group_id/a/album_id/ - First page of media items inside album "album_id"
  58. /group_albums/group_id/a/album_id/p/X - Page X of media items inside album "album_id"
  59. ...links jump to: /group_albums/group_id/a/album_id/m/media_id/
  60. /group_albums/group_id/a/album_id/m/media_id/ - Media item "media_id" inside album "album_id"
  61. ACTIONS
  62. All actions are done using GET variables.
  63. MEDIA OF USER
  64. =======================
  65. URL'S
  66. /media_of_user/user_id/ - First page of media items
  67. /media_of_user/user_id/p/X/ - Page X of media items
  68. ...links jump to: /user_album/user_id/a/album_id/m/media_id/
  69. /user_album/user_id/a/album_id/m/media_id/ - Media item "media_id" inside album "album_id"
  70. USER ALBUM
  71. =======================
  72. URL'S
  73. /user_album/user_id/ - First page of albums
  74. /user_album/user_id/p/X/ - Page X of albums
  75. ...links jump to: /user_album/user_id/a/album_id/
  76. /user_album/user_id/a/album_id/ - First page of media items inside album "album_id"
  77. /user_album/user_id/a/album_id/p/X - Page X of media items inside album "album_id"
  78. ...links jump to: /user_album/user_id/a/album_id/m/media_id/
  79. /user_album/user_id/a/album_id/m/media_id/ - Media item "media_id" inside album "album_id"
  80. ACTIONS
  81. All actions are done using GET variables.
  82. ALBUM MODULE AJAX SCHEME
  83. =========================
  84. -If a user is inside a page module which:
  85. a) Renders only album modules
  86. b) Should logically give users the ability to create new albums
  87. c) The user has permission to create new albums
  88. -Then, the page module should:
  89. a) Display a link or button offering to create a new album
  90. b) Attach JS code to the page to open the create new album dialog
  91. c) Attach CSS styles to the page describing how to style the create album dialog
  92. -When a user clicks on the "create new album" link or button:
  93. a) The JS code should post a request to the server containing
  94. 1) The method, function, etc, variables to tell the server which AJAX handler to run
  95. 2) The page_module id (used to tell the difference between creating User Albums and Group Albums)
  96. 3) The user_id (used to check authorization)
  97. b) The server should check authorization, and kill the process if the user is not authorized to continue
  98. c) The server should respond with the rendered HTML to load into the dialog box, containing:
  99. 1) A list of the album types a user can create, with the number used and the number remaining (this avoids having to load the entire album module stack on every page view)
  100. 2) A button to create an instance of each album type (disabled if the user has hit their quota for that album type)
  101. 3) Encoded height and width parameters for the next dialog box for each album module (required by jQuery)
  102. -When the user clicks on a "create album instance" button:
  103. a) The JS code should post a request to the server containing
  104. 1) The method, function, etc, variables to tell the server which AJAX handler to run
  105. 2) The page_module id (used to tell the difference between creating User Albums and Group Albums)
  106. 3) The album_module id (used to determine which module's form to load)
  107. 4) The user_id (used to set album owner if its a user album)
  108. b) The current dialog box should close with a fade-out effect (decreases perceived server lag due to page "doing something" while load is in progress)
  109. c) A new dialog box should open with a fade-in effect, sized to height and width set by the album module
  110. d) The dialog box should display an animated "loading" GIF until the server has filled the request
  111. e) The server should check authorization, and kill the process if the user is not authorized to continue
  112. f) The server should respond with the rendered HTML to load into the dialog box, containing:
  113. 1) All data fields required to create the album type
  114. 2) A "Cancel" button, which closes the dialog
  115. 3) An "OK" button, which submits the create album request
  116. -When the user clicks on the "OK" button:
  117. a) The JS code should post a request to the server containing
  118. 1) The method, function, etc, variables to tell the server which AJAX handler to run
  119. 2) The page_module id (used to tell the difference between creating User Albums and Group Albums)
  120. 3) The album_module id (module's handler to use)
  121. 4) The user_id (used to set album owner if its a user album)
  122. 5) All data fields used to create the album instance
  123. b) The current dialog box should dim and display an animated "working" icon
  124. c) The server should check authorization, and kill the process if the user is not authorized to continue
  125. d) The AJAX handler should pass the data to the correct album module's "create" function
  126. e) The create function should run all data through the DB sanitizers and note any failed fields
  127. -If there are failed fields:
  128. a) The create function should abort the create process and pass a BPM error object back to the AJAX handler
  129. b) The AJAX handler should parse the error object into
  130. 1) The failed field names
  131. 2) The reason each field failed
  132. c) The AJAX handler should JSON encode the data and send it back as a response to the JS code in the browser
  133. d) When the JS code receives the fail response, it should:
  134. 1) Un-dim the dialog box and remove the "working" icon
  135. 2) Reset all fields in the form to default status (handles case where the user has submitted the form, had failed fields, then corrected one or more failed fields)
  136. 3) Fade the background color of each failed field to yellow
  137. 4) Insert a tool-tip bubble above each failed field explaining why the field failed
  138. -If there are no failed fields:
  139. a) The create function should create an album instance and pass a success status and album_id back to the AJAX handler
  140. b) The AJAX handler should JSON encode the response and send it back to the JS code in the browser
  141. c) When the JS code receives the success response, it should:
  142. 1) Close the dialog box
  143. 2) Redirect the browser to the new album's landing page