Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Start reworking database loading to support parade view

Also use more robust query string parsing and remove further dependency
on old DB code.
  • Loading branch information...
commit ceaeb283333265f18db45f37304b1f8a29a34b09 1 parent bc10d36
@birtles birtles authored
View
2  docs/wall-api.txt
@@ -10,7 +10,7 @@ Public-facing content:
/wall/<wall-name>/sessions - Gallery-like list of sessions for wall?
/wall/<wall-name>/sessions/<session-id> - show wall corresponding to a given
session
-/wall/<wall-name>/sessions/<session-id>/gallery - show gallery view of wall
+/wall/<wall-name>/sessions/<session-id>/gallery - show gallery view of session
/wall/<wall-name>/gallery - show all (non-hidden) characters from all sessions
in order of submission in gallery format
View
96 wall/public/api/get_all_characters.php
@@ -7,45 +7,63 @@
require_once("../../lib/parapara.inc");
require_once("db.inc");
-$connection = getConnection();
-
-$threshold = isset($_GET["threshold"]) ? intval($_GET["threshold"]) : -1;
-
-$list = array();
-try {
- if (!isset($_GET["sessionId"])) {
- throwException("no session id");
- }
- $sessionId = intval($_GET["sessionId"]);
-
- if ($threshold >= 0) {
- $query = "SELECT charId,x,width,height,groundOffset FROM " .
- "(SELECT charId,x,width,height,groundOffset FROM characters WHERE x IS NOT NULL AND active = 1 AND sessionId=".$sessionId.
- " ORDER BY createDate DESC LIMIT " . $threshold . ") " .
- "AS latestShown ORDER BY x";
- } else {
- $query =
- "SELECT charId,x,width,height,groundOffset FROM characters WHERE x IS NOT NULL AND active = 1 AND sessionId=".$sessionId.
- " ORDER BY x";
- }
- $resultset = mysql_query($query, $connection) or
- throwException(mysql_error());
-
- while ($row = mysql_fetch_array($resultset)) {
- $character = array();
- $character["id"] = intval($row["charId"]);
- $character["x"] = intval($row["x"]);
- $character["width"] = intval($row["width"]);
- $character["height"] = intval($row["height"]);
- $character["groundOffset"] = floatval($row["groundOffset"]);
- array_push($list, $character);
- }
-
- mysql_free_result($resultset);
-} catch (Exception $e) {
- $list["error"] = $e->getMessage();
+require_once("api.inc");
+
+$threshold = isset($_GET["threshold"])
+ ? intval($_GET["threshold"])
+ : null;
+
+$conn =& getDbConnection();
+
+$sessionCond = '';
+if (isset($_GET['sessionId'])) {
+ $sessionCond = 'sessionId = '
+ . $conn->quote(intval($_GET['sessionId']), 'integer');
+}
+
+$result = array();
+
+if ($threshold !== null) {
+ $query =
+ "SELECT charId, x, width, height, groundOffset"
+ . " FROM"
+ . " (SELECT charId, x, width, height, groundOffset"
+ . " FROM characters WHERE x IS NOT NULL"
+ . " AND active = 1"
+ . ($sessionCond ? " AND $sessionCond" : "")
+ . " ORDER BY createDate DESC LIMIT " . $conn->quote($threshold, 'integer')
+ . " )"
+ . " AS latestShown"
+ . " ORDER BY x";
+} else {
+ $query =
+ "SELECT charId, x, width, height, groundOffset"
+ . " FROM characters"
+ . " WHERE x IS NOT NULL"
+ . " AND active = 1"
+ . ($sessionCond ? " AND $sessionCond" : "")
+ . " ORDER BY x";
+}
+
+$res =& $conn->query($query);
+if (PEAR::isError($res)) {
+ error_log($res->getMessage() . ', ' . $res->getDebugInfo());
+ throw new KeyedException('db-error');
+}
+
+$conn->setFetchMode(MDB2_FETCHMODE_ASSOC);
+while ($row = $res->fetchRow()) {
+ $character = array();
+ $character["id"] = intval($row["charid"]);
+ $character["x"] = intval($row["x"]);
+ $character["width"] = intval($row["width"]);
+ $character["height"] = intval($row["height"]);
+ $character["groundOffset"] = floatval($row["groundoffset"]);
+ array_push($result, $character);
}
-mysql_close($connection);
+
+$res->free();
+$conn->disconnect();
-echo json_encode($list);
+echo json_encode($result);
?>
View
9 wall/public/designs/wa/main.js
@@ -25,9 +25,11 @@ var Main = {
start: function() {
Main.timebase = document.getElementById("time-base");
- Main.main_layer = document.getElementById("main-layer"); Database.start(Main.timebase, Main.showCharacter); },
+ Main.main_layer = document.getElementById("main-layer");
+ Database.start(Main.timebase, Main.showCharacter); },
- showCharacter: function(character, currentActiveTime, currentSimpleTime, currentRate, durationRate) {
+ showCharacter: function(character, currentActiveTime, currentSimpleTime,
+ currentRate, durationRate) {
// Create a group to wrap the character and its animation
var g = document.createElementNS("http://www.w3.org/2000/svg", "g");
g.setAttribute("id", character.id);
@@ -81,7 +83,8 @@ var Main = {
// Create the animation
var animateMotion =
document.createElementNS("http://www.w3.org/2000/svg", "animateMotion");
- animateMotion.setAttribute("dur", Math.round(CHARACTER_DURATION*durationRate)+"s");
+ animateMotion.setAttribute("dur",
+ Math.round(CHARACTER_DURATION * durationRate)+"s");
animateMotion.setAttribute("begin", currentActiveTime+"s");
animateMotion.setAttribute("calcMode", "linear");
animateMotion.setAttribute("repeatCount", "1");
View
3  wall/public/wall/.htaccess
@@ -5,7 +5,8 @@ Options -Indexes
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index
RewriteBase /
- RewriteRule ^[^/]+$ /wall/index.php [L]
+ RewriteRule ^([^/]+)$ /wall/index.php?wall=$1 [L]
+ RewriteRule ^([^/]+)/parade$ /wall/index.php?wall=$1&view=parade [L]
RewriteRule ^[^/]+/upload$ /api/upload_anim.php [L]
</ifModule>
php_flag short_open_tag off
View
19 wall/public/wall/index.php
@@ -10,14 +10,7 @@
$conn = NULL;
try {
- // Parse wall name
- $url = $_SERVER["REDIRECT_URL"];
- $match = preg_match('/^\/wall\/([^\/]+)$/', $url, $matches);
- if ($match != 1) {
- throwException("No wall found");
- }
- $wallName = $matches[1];
- $wallId = getWallIdFromPath($wallName);
+ $wallId = getWallIdFromPath($_REQUEST['wall']);
if (!$wallId) {
throwException("No wall found");
}
@@ -58,7 +51,9 @@
header("Content-Type: image/svg+xml; charset=UTF-8");
-$database = $endDate == NULL ? "database4live.js" : "database4gallery.js";
+$database = @$_REQUEST['view'] == 'parade'
+ ? "database4parade.js"
+ : ($endDate == NULL ? "database4live.js" : "database4gallery.js");
$duration = getWallDuration($wallId);
$beginTime = getCurrentWallTimeForDuration($duration);
@@ -85,9 +80,9 @@
var BEGIN_TIME = <?php echo $beginTime ?>;
var BEFORE_LOADED_TIME = (new Date()).getTime();
</script>
- <script xlink:href="js/utility.js"></script>
- <script xlink:href="../wall-maker/js/xhr.js"></script>
- <script xlink:href="js/<?php echo $database; ?>"></script>
+ <script xlink:href="/wall/js/utility.js"></script>
+ <script xlink:href="/wall-maker/js/xhr.js"></script>
+ <script xlink:href="/wall/js/<?php echo $database; ?>"></script>
<script xlink:href="/designs/<?php echo $design; ?>/main.js"></script>
<?php require("../designs/$design/wall.svg.inc"); ?>
</svg>
View
2  wall/public/wall/js/database4gallery.js
@@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
-var API_DIR = "../api/";
+var API_DIR = "/api/";
var CHARACTERS_DIR = "/characters/";
var Database = {
View
5 wall/public/wall/js/database4live.js
@@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
-var API_DIR = "../api/";
+var API_DIR = "/api/";
var CHARACTERS_DIR = "/characters/";
var Database = {
@@ -74,7 +74,8 @@ var Database = {
// if (character.sent != true) { //for debug
// console.error("******"+rate+":"+currentRate+" "+previousRate);
- Database.listener(character, currentActiveTime, currentSimpleTime, currentRate, Database.duration_rate);
+ Database.listener(character, currentActiveTime, currentSimpleTime,
+ currentRate, Database.duration_rate);
character.sent = true;
}
}
View
8 wall/public/wall/js/database4parade.js
@@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
-var API_DIR = "../api/";
+var API_DIR = "/api/";
var CHARACTERS_DIR = "/characters/";
var Database = {
@@ -11,6 +11,9 @@ var Database = {
Database.characters = [];
Database.listener = characterListener;
Database.timebase = timebase;
+ Database.duration_rate =
+ Utility.applyDuration(Database.timebase, BASE_TIME,
+ BEGIN_TIME+(new Date()).getTime()-BEFORE_LOADED_TIME);
Database.loadAllCharacters();
},
@@ -27,7 +30,8 @@ var Database = {
var currentRate = currentSimpleTime/simpleDuration;
// Go through and add waiting characters
var character = Database.characters[index];
- Database.listener(character, currentActiveTime, currentSimpleTime, currentRate);
+ Database.listener(character, currentActiveTime, currentSimpleTime,
+ currentRate, Database.duration_rate);
Database.timeout_id = setTimeout(Database.next, Math.round(4000+Math.random()*3000), index+1);
},
Please sign in to comment.
Something went wrong with that request. Please try again.