<?php/************************************************************* * Magnetic AJAX - Version 3.0 * * This is like the magnetic poetry things. If you use this * code, please give me credit and a link to my site would be nice. * http://www.broken-notebook.com. * * Copyright (c) 2005-2007, Garrison Locke * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * Neither the name of the http://www.broken-notebook.com nor the names of its * contributors may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * OF SUCH DAMAGE. * *************************************************************/$ma = new magneticAjax();class magneticAjax { public $numWords; public $words; public $db; public function magneticAjax() { $this->db = new SQLiteDatabase("/var/www/www.moufette.com/htdocs/magnetic/words", 0666, $error); $this->processFile(); } public function processFile() { $query = "SELECT * FROM words ORDER BY id"; $res = $this->db->query($query); $this->numWords = 0; while ($row = $res->fetch()) { $this->words[$this->numWords][0] = trim($row['word']); $this->words[$this->numWords][1] = $row['y']; $this->words[$this->numWords][2] = $row['x']; $this->words[$this->numWords][3] = $row['z']; $this->numWords++; } if (strtolower($_SERVER['REQUEST_METHOD']) == 'post') { if ($_REQUEST['f'] == "save") { echo $this->save($_REQUEST['id'], $_REQUEST['x'], $_REQUEST['y'], $_REQUEST['z']); } elseif ($_REQUEST['f'] == "repaint") { echo $this->repaint(); } } } public function printTiles() { $retHTML = ""; for ($i=0; $i<$this->numWords; $i++) { $tileWidth = 7 * strlen($this->words[$i][0]); $tileHeight = 13; $retHTML .= '<div id="w_' . $i . '" class="tile" style="position: absolute; top: ' . $this->words[$i][1] . 'px; left: ' . $this->words[$i][2] . 'px; width: ' . $tileWidth . 'px; height: ' . $tileHeight . 'px; z-index: ' . $this->words[$i][3] . '">'; $retHTML .= $this->words[$i][0]; $retHTML .= '</div>'; } return $retHTML; } private function repaint() { $retVal = ""; for($i=0; $i<$this->numWords; $i++) { $retVal .= $this->words[$i][1] . ":" . $this->words[$i][2] . ":" . $this->words[$i][3]; if($i < $this->numWords - 1) { $retVal .= "|"; } } return $retVal; } private function save($obj, $x, $y, $z) { $index = substr(strrchr($obj, "_"), 1); $this->words[$index][1] = $y; $this->words[$index][2] = $x; $this->words[$index][3] = $z; $query = "UPDATE words SET x=" . $x . ", y=" . $y . ", z=" . $z . " WHERE id=" . ($index+1); $this->db->queryExec($query); return; }}