Changeset 442050
- Timestamp:
- 09/22/2011 12:02:42 PM (15 years ago)
- Location:
- simpleticker/trunk
- Files:
-
- 2 edited
-
SimpleTicker.php (modified) (11 diffs)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
simpleticker/trunk/SimpleTicker.php
r440740 r442050 24 24 */ 25 25 if ($_GET['action'] == 'getTickerDetails') { 26 /* 27 * Return detailed information about a specific ticker (defined by it's it) 28 */ 26 29 $query = "SELECT updateInterval, messageTimeout, messageCount, tickerTimeout FROM " . $wpdb->prefix . "SimpleTicker WHERE id='" . mysql_escape_string($_GET['id']) . "'"; 27 30 $queryResult = $wpdb->get_row($query); … … 37 40 } 38 41 if ($_GET['action'] == 'getTickerMessages') { 42 /* 43 * Return all currently 'active' messages (messages, where the timeout hasn't been exceeded) for a ticker with a specific id 44 */ 39 45 $query = "SELECT message FROM " . $wpdb->prefix . "SimpleTickerMsgs WHERE " . 40 46 "id_SimpleTicker='" . mysql_escape_string($_GET['id']) . "' AND createdOn > '" . date("Y-m-d h:i:s", time() - mysql_escape_string($_GET['timeout']) * 60) . "' " . … … 51 57 } 52 58 53 59 if ($_GET['action'] == 'JSONAPI') { 60 handleSimpleTickerJSONAPIRequest($_GET['data']); 61 } 54 62 55 63 … … 64 72 65 73 $sql = "CREATE TABLE " . $wpdb->prefix . "SimpleTicker ( 66 id int(11) NOT NULL AUTO_INCREMENT, 67 name varchar(100) NOT NULL, 68 updateInterval INT(11) NOT NULL, 69 messageTimeout INT(11) NOT NULL, 70 messageCount INT(11) NOT NULL, 71 tickerTimeout INT(11) NOT NULL, 74 `id` INT(11) NOT NULL AUTO_INCREMENT, 75 `name` VARCHAR(100) NOT NULL, 76 `updateInterval` INT(11) NOT NULL, 77 `messageTimeout` INT(11) NOT NULL, 78 `messageCount` INT(11) NOT NULL, 79 `tickerTimeout` INT(11) NOT NULL, 80 `passwd` VARCHAR(250) DEFAULT NULL, 72 81 UNIQUE KEY id (id) 73 82 );"; … … 149 158 global $wpdb; 150 159 151 152 160 /* 153 161 * update the list of tickers … … 158 166 if ($tickerId == 'new') { 159 167 if ($ticker['name'] != '') { 160 $query = "INSERT INTO " . $wpdb->prefix ."SimpleTicker (name, updateInterval, messageTimeout, messageCount, tickerTimeout) " . 168 if ($ticker['passwd'] == '') { 169 $query = "INSERT INTO " . $wpdb->prefix ."SimpleTicker (name, updateInterval, messageTimeout, messageCount, tickerTimeout) " . 161 170 "VALUES('" . $ticker['name'] . "', '" . $ticker['updateInterval'] . "', '" . $ticker['messageTimeout'] . "', '" . 162 171 $ticker['messageCount'] . "', '" . $ticker['tickerTimeout'] . "')"; 172 } else { 173 $query = "INSERT INTO " . $wpdb->prefix ."SimpleTicker (name, updateInterval, messageTimeout, messageCount, tickerTimeout, passwd) " . 174 "VALUES('" . $ticker['name'] . "', '" . $ticker['updateInterval'] . "', '" . $ticker['messageTimeout'] . "', '" . 175 $ticker['messageCount'] . "', '" . $ticker['tickerTimeout'] . "', '" . md5($ticker['passwd']) . "')"; 176 } 163 177 $wpdb->query($query); 164 178 } … … 166 180 continue; 167 181 } 168 $wpdb->query("UPDATE " . $wpdb->prefix ."SimpleTicker SET name='" . $ticker['name'] . "', updateInterval='" . $ticker['updateInterval'] . 182 if ($ticker['passwd'] == '') { 183 $wpdb->query("UPDATE " . $wpdb->prefix ."SimpleTicker SET name='" . $ticker['name'] . "', updateInterval='" . $ticker['updateInterval'] . 169 184 "', messageTimeout='" . $ticker['messageTimeout'] . "', messageCount='" . $ticker['messageCount'] . "', tickerTimeout='" . $ticker['tickerTimeout'] . 170 185 "' WHERE id='$tickerId'"); 186 } else { 187 $wpdb->query("UPDATE " . $wpdb->prefix ."SimpleTicker SET name='" . $ticker['name'] . "', updateInterval='" . $ticker['updateInterval'] . 188 "', messageTimeout='" . $ticker['messageTimeout'] . "', messageCount='" . $ticker['messageCount'] . "', tickerTimeout='" . $ticker['tickerTimeout'] . 189 "', passwd='" . md5($ticker['passwd']) . "' WHERE id='$tickerId'"); 190 } 171 191 172 192 if ($ticker['delete'] == "1") { … … 208 228 $code .= " <th>Number of fading messages</th>\n"; 209 229 $code .= " <th>Show no messages created x minutes ago</th>\n"; 230 $code .= " <th>Password</th>"; 210 231 $code .= " <th>Delete</th>"; 211 232 $code .= " </tr>\n"; … … 224 245 $code .= " <td align='center'><input type=\"text\" name=\"ticker[" . $ticker->id . "][messageCount]\" value=\"" . $ticker->messageCount . "\" /></td>"; 225 246 $code .= " <td align='center'><input type=\"text\" name=\"ticker[" . $ticker->id . "][tickerTimeout]\" value=\"" . $ticker->tickerTimeout . "\" /></td>"; 247 $code .= " <td align='center'><input type=\"text\" name=\"ticker[" . $ticker->id . "][passwd]\" value=\"\" /></td>"; 226 248 $code .= " <td align='center'><input type=\"checkbox\" name=\"ticker[" . $ticker->id . "][delete]\" value=\"1\" /></td>"; 227 249 $code .= " </tr>\n"; … … 237 259 $code .= " <td align='center'><input type=\"text\" name=\"ticker[new][messageCount]\"/></td>"; 238 260 $code .= " <td align='center'><input type=\"text\" name=\"ticker[new][tickerTimeout]\"/></td>"; 261 $code .= " <td align='center'><input type=\"text\" name=\"ticker[new][passwd]\"/></td>"; 239 262 $code .= " <td></td>"; 240 263 $code .= " </tr>\n"; … … 291 314 } 292 315 316 /** 317 * Handle JSON API requests 318 * data contains an json string encrypted with the ticker password 319 * @param $data 320 */ 321 function handleSimpleTickerJSONAPIRequest($data) { 322 global $wpdb; 323 $request = json_decode(base64_decode($data), true); 324 325 switch ($request['command']) { 326 case 'getTickerList': 327 $tickers = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "SimpleTicker"); 328 $tickerList = array(); 329 foreach ($tickers as $ticker) { 330 $tickerList[] = array('id' => $ticker->id, 'name' => $ticker->name); 331 } 332 echo json_encode($tickerList); 333 die(); 334 break; 335 336 case 'getTickerMessages': 337 $messages = $wpdb->get_results("SELECT id, message, createdOn FROM " . 338 $wpdb->prefix . "SimpleTickerMsgs WHERE id_SimpleTicker = '" . mysql_escape_string($request['tickerid']) . 339 "' ORDER BY createdOn DESC LIMIT 50"); 340 $tickerMessages = array(); 341 foreach ($messages as $message) { 342 $tickerMessages[] = array('id' => $message->id, 'message' => $message->message, 'createdOn' => $message->createdOn); 343 } 344 echo json_encode($tickerMessages); 345 die(); 346 347 case 'manageTickerMessage': 348 $id_SimpleTicker = $request['tickerid']; 349 350 /* 351 * Check if the password encrypted with the token matches the password for this ticker stored in the database. 352 */ 353 $decryptedData = json_decode(base64_decode(decryptSimpleTickerMessage($request['data'])), true); 354 if ($decryptedData == null) { 355 die("NODATACONTENT"); 356 } 357 $tickerData = $wpdb->get_row("SELECT passwd FROM " . $wpdb->prefix . "SimpleTicker WHERE id='" . mysql_escape_string($id_SimpleTicker) . "'"); 358 if ($decryptedData['passwd'] == $tickerData->passwd) { 359 /* 360 * Add new messsage 361 */ 362 if ($decryptedData['action'] == 'addMessage') { 363 $message = $decryptedData['message']; 364 $wpdb->query("INSERT INTO " . $wpdb->prefix . "SimpleTickerMsgs (id_SimpleTicker, message, createdOn) VALUES ('$id_SimpleTicker', '$message', NOW())"); 365 die("SUCCESS"); 366 } 367 /* 368 * Delete existing message 369 */ 370 if ($decryptedData['action'] == 'removeMessage') { 371 $id = $decryptedData['id']; 372 $wpdb->query("DELETE FROM " . $wpdb->prefix . "SimpleTickerMsgs WHERE id='$id'"); 373 die("SUCCESS"); 374 } 375 die("NOACTIONDEFINED"); 376 } else { 377 die("WRONGPASSWORD"); 378 } 379 break; 380 381 } 382 383 } 384 385 /** 386 * Returns the decrypted string 387 * @param <string> $str 388 * @return <string> 389 */ 390 function decryptSimpleTickerMessage($str) { 391 return $str; //TODO implement decryption 392 } 393 293 394 ?> -
simpleticker/trunk/readme.txt
r440740 r442050 8 8 9 9 == Description == 10 A simple ticker plugin for wordpress. It supports multiple tickers. You can define an update interval in minutes in which the client updates it's message list from the server. This update request includes new messages, which have been posted until the last update. You can also specify the amount of messages that the client fades through and the time each message stays on the screen. Each message is stored with an creation timestamp. You can tell the ticker only to show messages not older than a defined number of minutes. If there are no messages to display, then the ticker turns itself invisible. 10 A simple ticker plugin for wordpress. It supports multiple tickers. You can define an update interval 11 in minutes in which the client updates it's message list from the server. This update request includes 12 new messages, which have been posted until the last update. You can also specify the amount of messages that 13 the client fades through and the time each message stays on the screen. Each message is stored with an 14 creation timestamp. You can tell the ticker only to show messages not older than a defined number of minutes. 15 If there are no messages to display, then the ticker turns itself invisible. 16 17 If you want to use the SimpleTicker data from an other application such as an iPhone or Android App, you can 18 get all ticker data and messages via an JSON based API. It is also possible to add and delete messages. Your 19 application will need a password for each ticker, if it want's to add or delete messages. 11 20 12 21 == Copyright == … … 16 25 17 26 == History === 27 Version 0.3 28 - added JSON API 18 29 Version 0.2 19 30 - added auto-hide … … 32 43 33 44 Example for ticker 1 (with id 1): [simpleticker id=1] 45 46 == JSON API == 47 Call the SimpleTicker script with the "action" GET parameter with value JSONAPI (SimpleTicker.php?action=JSONAPI&data=BASE64CODEDSTRING). 48 All other data is delivered the "data" GET parameter. This "data" parameter contains a BASE64 encoded JSON string. 49 50 The data-JSON string contains a "command" value, which defines the function you want to call. The following functions are available: 51 52 - getTickerList: no further parameter needed 53 - getTickerMessages: "tickerid" must contain the ID of the ticker you want to get the messages from 54 - manageTickerMessage: if you choose this function you have to give another BASE64 JSON data parameter. This parameter must be encrypted with the password for that ticker. The ticker is defined by the tickerid parameter as above. 55 56 Just have a look at the end of the SimpleTicker.php file. The code is very simple and only a few lines long.
Note: See TracChangeset
for help on using the changeset viewer.