Changeset 442976
- Timestamp:
- 09/24/2011 06:08:52 PM (15 years ago)
- Location:
- simpleticker
- Files:
-
- 4 edited
- 1 copied
-
tags/0.4 (copied) (copied from simpleticker/trunk)
-
tags/0.4/SimpleTicker.php (modified) (6 diffs)
-
tags/0.4/readme.txt (modified) (4 diffs)
-
trunk/SimpleTicker.php (modified) (6 diffs)
-
trunk/readme.txt (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
simpleticker/tags/0.4/SimpleTicker.php
r442051 r442976 4 4 Plugin URI: http://mbartel.ghulbus.eu/SimpleTicker/ 5 5 Description: Simple news ticker with multiple input possiblities 6 Version: 0. 36 Version: 0.4 7 7 Author: Michael Bartel 8 8 Author URI: http://facebook.com/bartel.michael/ … … 10 10 */ 11 11 12 include 'Template.class.php'; 12 13 $simpleTickerVersion = "0.2"; 13 14 … … 21 22 22 23 /* 23 * handle AJAX calls24 * handle AJAX requests 24 25 */ 25 26 if ($_GET['action'] == 'getTickerDetails') { … … 57 58 } 58 59 59 if ($_GET['action'] == 'JSONAPI') { 60 handleSimpleTickerJSONAPIRequest($_GET['data']); 61 } 62 60 /* 61 * Handle JSON requests 62 */ 63 if ($_GET['action'] == 'jsonGetTickerList') { 64 $tickers = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "SimpleTicker"); 65 $tickerList = array(); 66 foreach ($tickers as $ticker) { 67 $tickerList[] = array('id' => $ticker->id, 'name' => $ticker->name); 68 } 69 echo json_encode($tickerList); 70 die(); 71 } 72 if ($_GET['action'] == 'jsonGetTickerMessages') { 73 $messages = $wpdb->get_results("SELECT id, message, createdOn FROM " . 74 $wpdb->prefix . "SimpleTickerMsgs WHERE id_SimpleTicker = '" . mysql_escape_string($_GET['tickerid']) . 75 "' ORDER BY createdOn DESC LIMIT 50"); 76 $tickerMessages = array(); 77 foreach ($messages as $message) { 78 $tickerMessages[] = array('id' => $message->id, 'message' => $message->message, 'createdOn' => $message->createdOn); 79 } 80 echo json_encode($tickerMessages); 81 die(); 82 } 83 if ($_GET['action'] == 'jsonManageTicker') { 84 $id_SimpleTicker = mysql_escape_string($_GET['tickerid']); 85 86 /* 87 * Check if the password encrypted with the token matches the password for this ticker stored in the database. 88 */ 89 $decryptedData = json_decode(decryptSimpleTickerMessage(base64_decode($_GET['data'])), true); 90 if ($decryptedData == null) { 91 die("NODATACONTENT"); 92 } 93 $tickerData = $wpdb->get_row("SELECT passwd FROM " . $wpdb->prefix . "SimpleTicker WHERE id='" . mysql_escape_string($id_SimpleTicker) . "'"); 94 if ($decryptedData['passwd'] == $tickerData->passwd) { 95 /* 96 * Add new messsage 97 */ 98 if ($decryptedData['action'] == 'addMessage') { 99 $message = $decryptedData['message']; 100 $wpdb->query("INSERT INTO " . $wpdb->prefix . "SimpleTickerMsgs (id_SimpleTicker, message, createdOn) VALUES ('$id_SimpleTicker', '$message', NOW())"); 101 die("SUCCESS"); 102 } 103 /* 104 * Delete existing message 105 */ 106 if ($decryptedData['action'] == 'removeMessage') { 107 $id = $decryptedData['id']; 108 $wpdb->query("DELETE FROM " . $wpdb->prefix . "SimpleTickerMsgs WHERE id='$id'"); 109 die("SUCCESS"); 110 } 111 die("NOACTIONDEFINED"); 112 } else { 113 die("WRONGPASSWORD"); 114 } 115 } 116 117 /* 118 * Handle XML request 119 */ 120 if ($_GET['action'] == 'xmlGetTickerList') { 121 $tickers = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "SimpleTicker"); 122 $tickerStr = "<tickerlist>\n"; 123 foreach ($tickers as $ticker) { 124 $tickerStr .= "\t<ticker>\n\t\t<id>" . $ticker->id . "</id>\n\t\t<name>" . $ticker->name . 125 "</name>\n\t</ticker>\n"; 126 } 127 $tickerStr .= "</tickerlist>"; 128 echo $tickerStr; 129 die(); 130 } 131 if ($_GET['action'] == 'xmlGetTickerMessages') { 132 $messages = $wpdb->get_results("SELECT id, message, createdOn FROM " . 133 $wpdb->prefix . "SimpleTickerMsgs WHERE id_SimpleTicker = '" . mysql_escape_string($_GET['tickerid']) . 134 "' ORDER BY createdOn DESC LIMIT 50"); 135 $tickerMessages = "<tickermessages>\n"; 136 foreach ($messages as $message) { 137 $tickerMessages .= "\t<message>\n\t\t<id>" . $message->id . "</id>\n\t\t<message>" . $message->message . 138 "</message>\n\t\t<createdOn>" . $message->createdOn . "</createdOn>\n\t</message>\n"; 139 } 140 $tickerMessages .= "</tickermessages>"; 141 echo $tickerMessages; 142 die(); 143 } 144 145 /* 146 * RSS Feed 147 */ 148 // mime type application/rss+xml 63 149 64 150 /* … … 218 304 * print the list of tickers 219 305 */ 220 $code .= "<form action=\"#\" method=\"post\">\n"; 221 $code .= "<table width='100%'>\n"; 222 $code .= " <thead>\n"; 223 $code .= " <tr>\n"; 224 $code .= " <th>ID</th>\n"; 225 $code .= " <th>Name</th>\n"; 226 $code .= " <th>Ticker updates (every x minutes)</th>\n"; 227 $code .= " <th>Message fades (after x secondes)</th>\n"; 228 $code .= " <th>Number of fading messages</th>\n"; 229 $code .= " <th>Show no messages created x minutes ago</th>\n"; 230 $code .= " <th>Password</th>"; 231 $code .= " <th>Delete</th>"; 232 $code .= " </tr>\n"; 233 $code .= " </thead>\n"; 234 $code .= " <tbody>\n"; 306 $adminPage = new Template('adminpage.tpl'); 235 307 236 308 $tickers = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "SimpleTicker"); 237 309 $tickerList = array(); 310 $tickerListArr = array(); 238 311 foreach ($tickers as $ticker) { 239 312 $tickerList[$ticker->id] = $ticker->name; 240 $code .= " <tr>\n"; 241 $code .= " <td align='center'>" . $ticker->id . "</td>"; 242 $code .= " <td align='center'><input type=\"text\" name=\"ticker[" . $ticker->id . "][name]\" value=\"" . $ticker->name . "\" /></td>"; 243 $code .= " <td align='center'><input type=\"text\" name=\"ticker[" . $ticker->id . "][updateInterval]\" value=\"" . $ticker->updateInterval . "\" /></td>"; 244 $code .= " <td align='center'><input type=\"text\" name=\"ticker[" . $ticker->id . "][messageTimeout]\" value=\"" . $ticker->messageTimeout . "\" /></td>"; 245 $code .= " <td align='center'><input type=\"text\" name=\"ticker[" . $ticker->id . "][messageCount]\" value=\"" . $ticker->messageCount . "\" /></td>"; 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>"; 248 $code .= " <td align='center'><input type=\"checkbox\" name=\"ticker[" . $ticker->id . "][delete]\" value=\"1\" /></td>"; 249 $code .= " </tr>\n"; 250 } 251 252 $code .= " </tbody>\n"; 253 $code .= " <tfooter>\n"; 254 $code .= " <tr>\n"; 255 $code .= " <td></td>"; 256 $code .= " <td align='center'><input type=\"text\" name=\"ticker[new][name]\"/></td>"; 257 $code .= " <td align='center'><input type=\"text\" name=\"ticker[new][updateInterval]\"/></td>"; 258 $code .= " <td align='center'><input type=\"text\" name=\"ticker[new][messageTimeout]\"/></td>"; 259 $code .= " <td align='center'><input type=\"text\" name=\"ticker[new][messageCount]\"/></td>"; 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>"; 262 $code .= " <td></td>"; 263 $code .= " </tr>\n"; 264 $code .= " </tfooter>\n"; 265 $code .= "</table>\n"; 266 $code .= "<p align=\"center\"><input type=\"submit\" value=\"Update\" /></p></form>"; 267 268 /* 269 * print list of messages 270 */ 271 $code .= "<form action=\"#\" method=\"post\">\n"; 272 $code .= "<table width='100%'>\n"; 273 $code .= " <thead>\n"; 274 $code .= " <tr>\n"; 275 $code .= " <th>Ticker</th>\n"; 276 $code .= " <th>Message</th>\n"; 277 $code .= " <th>Created</th>\n"; 278 $code .= " <th>Delete</th>"; 279 $code .= " </tr>\n"; 280 $code .= " </thead>\n"; 281 $code .= " <tbody>\n"; 313 $tmp = array(); 314 $tmp['id'] = $ticker->id; 315 $tmp['name'] = $ticker->name; 316 $tmp['updateInterval'] = $ticker->updateInterval; 317 $tmp['messageTimeout'] = $ticker->messageTimeout; 318 $tmp['messageCount'] = $ticker->messageCount; 319 $tmp['tickerTimeout'] = $ticker->tickerTimeout; 320 $tickerListArr[] = $tmp; 321 } 322 $adminPage->assignBlock('tickerlist', $tickerListArr); 323 282 324 283 325 $messages = $wpdb->get_results("SELECT " . $wpdb->prefix . "SimpleTickerMsgs.id AS tickerId, id_SimpleTicker, name, message, createdOn FROM " . … … 285 327 $wpdb->prefix . "SimpleTicker ON " . $wpdb->prefix . "SimpleTickerMsgs.id_SimpleTicker = " . 286 328 $wpdb->prefix . "SimpleTicker.id ORDER BY createdOn DESC LIMIT 50"); 329 $messagesArr = array(); 287 330 foreach ($messages as $message) { 288 $code .= " <tr>\n"; 289 $code .= " <td align='center'>" . $message->name . "</td>"; 290 $code .= " <td align='left'>" . $message->message . "</td>"; 291 $code .= " <td align='center'>" . $message->createdOn . "</td>"; 292 $code .= " <td align='center'><input type=\"checkbox\" name=\"msg[" . $message->tickerId . "][delete]\" value=\"1\" /></td>"; 293 $code .= " </tr>\n"; 294 } 295 296 $code .= " </tbody>\n"; 297 $code .= " <tfooter>\n"; 298 $code .= " <tr><td colspan=\"4\"> </td></tr>\n"; 299 $code .= " <tr>\n"; 300 $code .= " <td align='center'><select name=\"msg[new][ticker]\">"; 331 $tmp = array(); 332 $tmp['tickerId'] = $message->tickerId; 333 $tmp['name'] = $message->name; 334 $tmp['message'] = $message->message; 335 $tmp['createdOn'] = $message->createdOn; 336 $messagesArr[] = $tmp; 337 } 338 $adminPage->assignBlock('messagelist', $messagesArr); 339 340 $code = ''; 301 341 foreach ($tickerList as $key => $value) { 302 342 $code .= " <option value=\"$key\">$value</option>"; 303 343 } 304 $code .= " </select></td>"; 305 $code .= " <td align='center'><input type=\"text\" name=\"msg[new][message]\" size=\"100\"/></td>"; 306 $code .= " <td align=\"left\"><input type=\"submit\" value=\"Create new message / delete selected messages\"/></td>"; 307 $code .= " <td></td>"; 308 $code .= " </tr>\n"; 309 $code .= " </tfooter>\n"; 310 $code .= "</table>\n"; 311 $code .= "</form>"; 312 313 echo $code; 314 } 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 344 $adminPage->assign('tickeridlist', $code); 345 346 347 $adminPage->display(); 383 348 } 384 349 -
simpleticker/tags/0.4/readme.txt
r442062 r442976 4 4 Tags: news,ticker,newsticker,textticker,text,fader,scroller,facebook 5 5 Requires at least: 2.6 6 Tested up to: 3. 17 Stable tag: 0. 36 Tested up to: 3.2.1 7 Stable tag: 0.4 8 8 9 9 == Description == … … 16 16 17 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. Your19 application will need a password for each ticker, if it want's to add or delete messages.18 get all ticker data and messages via an JSON or XML based API. It is also possible to add and delete messages 19 with the JSON API. Your application will need a password for each ticker, if it want's to add or delete messages. 20 20 21 21 == Copyright == … … 24 24 eMail: Michael.Bartel@gmx.net 25 25 26 == History === 26 == History == 27 Version 0.4 28 - added Template-Engine and XML API 29 27 30 Version 0.3 28 31 - added JSON API 32 29 33 Version 0.2 30 34 - added auto-hide 35 31 36 Version 0.1 32 37 - first version V3.1 … … 44 49 Example for ticker 1 (with id 1): [simpleticker id=1] 45 50 51 == APIs == 52 All APIs are handled with GET paramters. The 'action' parameter specifys which function you want to call. 53 46 54 == 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. 55 The JSON API provides the following functionalities: 49 56 50 The data-JSON string contains a "command" value, which defines the function you want to call. The following functions are available: 57 * jsonGetTickerList - Returns a full list of all available tickers containing the tickers id and name. 58 * jsonGetTickerMessages - Returns a list with the last 50 messages of a ticker. You have to specify the ticker by giving it's ID in the parameter 'tickerid'. The list contains the message id, the message itself and the createdOn timestamp. 59 * jsonManageTicker - You need a password to call the action. All further parameters are given in a BASE64 encoded encrypted JSON string provided as GET parameter named 'data'. You have to set the 'tickerid' parameter as above to define a ticker. The JSON string contains an action attribute which can either be 'addMessage' or 'removeMessage'. The 'addMessage' actions takes an additional 'message' attribute containing the new message and the 'removeMessage' action takes an 'id' attribute. 51 60 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. 61 == XML API == 62 This is not really an API. It just supports the same information as delivered by the JSON API in XML format (expect the avaibility to mange tickers) 55 63 56 Just have a look at the end of the SimpleTicker.php file. The code is very simple and only a few lines long. 64 * xmlGetTickerList - Returns a full list of all available tickers containing the tickers id and name. 65 * xmlGetTickerMessages - Returns a list with the last 50 messages of a ticker. You have to specify the ticker by giving it's ID in the parameter 'tickerid'. The list contains the message id, the message itself and the createdOn timestamp. -
simpleticker/trunk/SimpleTicker.php
r442051 r442976 4 4 Plugin URI: http://mbartel.ghulbus.eu/SimpleTicker/ 5 5 Description: Simple news ticker with multiple input possiblities 6 Version: 0. 36 Version: 0.4 7 7 Author: Michael Bartel 8 8 Author URI: http://facebook.com/bartel.michael/ … … 10 10 */ 11 11 12 include 'Template.class.php'; 12 13 $simpleTickerVersion = "0.2"; 13 14 … … 21 22 22 23 /* 23 * handle AJAX calls24 * handle AJAX requests 24 25 */ 25 26 if ($_GET['action'] == 'getTickerDetails') { … … 57 58 } 58 59 59 if ($_GET['action'] == 'JSONAPI') { 60 handleSimpleTickerJSONAPIRequest($_GET['data']); 61 } 62 60 /* 61 * Handle JSON requests 62 */ 63 if ($_GET['action'] == 'jsonGetTickerList') { 64 $tickers = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "SimpleTicker"); 65 $tickerList = array(); 66 foreach ($tickers as $ticker) { 67 $tickerList[] = array('id' => $ticker->id, 'name' => $ticker->name); 68 } 69 echo json_encode($tickerList); 70 die(); 71 } 72 if ($_GET['action'] == 'jsonGetTickerMessages') { 73 $messages = $wpdb->get_results("SELECT id, message, createdOn FROM " . 74 $wpdb->prefix . "SimpleTickerMsgs WHERE id_SimpleTicker = '" . mysql_escape_string($_GET['tickerid']) . 75 "' ORDER BY createdOn DESC LIMIT 50"); 76 $tickerMessages = array(); 77 foreach ($messages as $message) { 78 $tickerMessages[] = array('id' => $message->id, 'message' => $message->message, 'createdOn' => $message->createdOn); 79 } 80 echo json_encode($tickerMessages); 81 die(); 82 } 83 if ($_GET['action'] == 'jsonManageTicker') { 84 $id_SimpleTicker = mysql_escape_string($_GET['tickerid']); 85 86 /* 87 * Check if the password encrypted with the token matches the password for this ticker stored in the database. 88 */ 89 $decryptedData = json_decode(decryptSimpleTickerMessage(base64_decode($_GET['data'])), true); 90 if ($decryptedData == null) { 91 die("NODATACONTENT"); 92 } 93 $tickerData = $wpdb->get_row("SELECT passwd FROM " . $wpdb->prefix . "SimpleTicker WHERE id='" . mysql_escape_string($id_SimpleTicker) . "'"); 94 if ($decryptedData['passwd'] == $tickerData->passwd) { 95 /* 96 * Add new messsage 97 */ 98 if ($decryptedData['action'] == 'addMessage') { 99 $message = $decryptedData['message']; 100 $wpdb->query("INSERT INTO " . $wpdb->prefix . "SimpleTickerMsgs (id_SimpleTicker, message, createdOn) VALUES ('$id_SimpleTicker', '$message', NOW())"); 101 die("SUCCESS"); 102 } 103 /* 104 * Delete existing message 105 */ 106 if ($decryptedData['action'] == 'removeMessage') { 107 $id = $decryptedData['id']; 108 $wpdb->query("DELETE FROM " . $wpdb->prefix . "SimpleTickerMsgs WHERE id='$id'"); 109 die("SUCCESS"); 110 } 111 die("NOACTIONDEFINED"); 112 } else { 113 die("WRONGPASSWORD"); 114 } 115 } 116 117 /* 118 * Handle XML request 119 */ 120 if ($_GET['action'] == 'xmlGetTickerList') { 121 $tickers = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "SimpleTicker"); 122 $tickerStr = "<tickerlist>\n"; 123 foreach ($tickers as $ticker) { 124 $tickerStr .= "\t<ticker>\n\t\t<id>" . $ticker->id . "</id>\n\t\t<name>" . $ticker->name . 125 "</name>\n\t</ticker>\n"; 126 } 127 $tickerStr .= "</tickerlist>"; 128 echo $tickerStr; 129 die(); 130 } 131 if ($_GET['action'] == 'xmlGetTickerMessages') { 132 $messages = $wpdb->get_results("SELECT id, message, createdOn FROM " . 133 $wpdb->prefix . "SimpleTickerMsgs WHERE id_SimpleTicker = '" . mysql_escape_string($_GET['tickerid']) . 134 "' ORDER BY createdOn DESC LIMIT 50"); 135 $tickerMessages = "<tickermessages>\n"; 136 foreach ($messages as $message) { 137 $tickerMessages .= "\t<message>\n\t\t<id>" . $message->id . "</id>\n\t\t<message>" . $message->message . 138 "</message>\n\t\t<createdOn>" . $message->createdOn . "</createdOn>\n\t</message>\n"; 139 } 140 $tickerMessages .= "</tickermessages>"; 141 echo $tickerMessages; 142 die(); 143 } 144 145 /* 146 * RSS Feed 147 */ 148 // mime type application/rss+xml 63 149 64 150 /* … … 218 304 * print the list of tickers 219 305 */ 220 $code .= "<form action=\"#\" method=\"post\">\n"; 221 $code .= "<table width='100%'>\n"; 222 $code .= " <thead>\n"; 223 $code .= " <tr>\n"; 224 $code .= " <th>ID</th>\n"; 225 $code .= " <th>Name</th>\n"; 226 $code .= " <th>Ticker updates (every x minutes)</th>\n"; 227 $code .= " <th>Message fades (after x secondes)</th>\n"; 228 $code .= " <th>Number of fading messages</th>\n"; 229 $code .= " <th>Show no messages created x minutes ago</th>\n"; 230 $code .= " <th>Password</th>"; 231 $code .= " <th>Delete</th>"; 232 $code .= " </tr>\n"; 233 $code .= " </thead>\n"; 234 $code .= " <tbody>\n"; 306 $adminPage = new Template('adminpage.tpl'); 235 307 236 308 $tickers = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "SimpleTicker"); 237 309 $tickerList = array(); 310 $tickerListArr = array(); 238 311 foreach ($tickers as $ticker) { 239 312 $tickerList[$ticker->id] = $ticker->name; 240 $code .= " <tr>\n"; 241 $code .= " <td align='center'>" . $ticker->id . "</td>"; 242 $code .= " <td align='center'><input type=\"text\" name=\"ticker[" . $ticker->id . "][name]\" value=\"" . $ticker->name . "\" /></td>"; 243 $code .= " <td align='center'><input type=\"text\" name=\"ticker[" . $ticker->id . "][updateInterval]\" value=\"" . $ticker->updateInterval . "\" /></td>"; 244 $code .= " <td align='center'><input type=\"text\" name=\"ticker[" . $ticker->id . "][messageTimeout]\" value=\"" . $ticker->messageTimeout . "\" /></td>"; 245 $code .= " <td align='center'><input type=\"text\" name=\"ticker[" . $ticker->id . "][messageCount]\" value=\"" . $ticker->messageCount . "\" /></td>"; 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>"; 248 $code .= " <td align='center'><input type=\"checkbox\" name=\"ticker[" . $ticker->id . "][delete]\" value=\"1\" /></td>"; 249 $code .= " </tr>\n"; 250 } 251 252 $code .= " </tbody>\n"; 253 $code .= " <tfooter>\n"; 254 $code .= " <tr>\n"; 255 $code .= " <td></td>"; 256 $code .= " <td align='center'><input type=\"text\" name=\"ticker[new][name]\"/></td>"; 257 $code .= " <td align='center'><input type=\"text\" name=\"ticker[new][updateInterval]\"/></td>"; 258 $code .= " <td align='center'><input type=\"text\" name=\"ticker[new][messageTimeout]\"/></td>"; 259 $code .= " <td align='center'><input type=\"text\" name=\"ticker[new][messageCount]\"/></td>"; 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>"; 262 $code .= " <td></td>"; 263 $code .= " </tr>\n"; 264 $code .= " </tfooter>\n"; 265 $code .= "</table>\n"; 266 $code .= "<p align=\"center\"><input type=\"submit\" value=\"Update\" /></p></form>"; 267 268 /* 269 * print list of messages 270 */ 271 $code .= "<form action=\"#\" method=\"post\">\n"; 272 $code .= "<table width='100%'>\n"; 273 $code .= " <thead>\n"; 274 $code .= " <tr>\n"; 275 $code .= " <th>Ticker</th>\n"; 276 $code .= " <th>Message</th>\n"; 277 $code .= " <th>Created</th>\n"; 278 $code .= " <th>Delete</th>"; 279 $code .= " </tr>\n"; 280 $code .= " </thead>\n"; 281 $code .= " <tbody>\n"; 313 $tmp = array(); 314 $tmp['id'] = $ticker->id; 315 $tmp['name'] = $ticker->name; 316 $tmp['updateInterval'] = $ticker->updateInterval; 317 $tmp['messageTimeout'] = $ticker->messageTimeout; 318 $tmp['messageCount'] = $ticker->messageCount; 319 $tmp['tickerTimeout'] = $ticker->tickerTimeout; 320 $tickerListArr[] = $tmp; 321 } 322 $adminPage->assignBlock('tickerlist', $tickerListArr); 323 282 324 283 325 $messages = $wpdb->get_results("SELECT " . $wpdb->prefix . "SimpleTickerMsgs.id AS tickerId, id_SimpleTicker, name, message, createdOn FROM " . … … 285 327 $wpdb->prefix . "SimpleTicker ON " . $wpdb->prefix . "SimpleTickerMsgs.id_SimpleTicker = " . 286 328 $wpdb->prefix . "SimpleTicker.id ORDER BY createdOn DESC LIMIT 50"); 329 $messagesArr = array(); 287 330 foreach ($messages as $message) { 288 $code .= " <tr>\n"; 289 $code .= " <td align='center'>" . $message->name . "</td>"; 290 $code .= " <td align='left'>" . $message->message . "</td>"; 291 $code .= " <td align='center'>" . $message->createdOn . "</td>"; 292 $code .= " <td align='center'><input type=\"checkbox\" name=\"msg[" . $message->tickerId . "][delete]\" value=\"1\" /></td>"; 293 $code .= " </tr>\n"; 294 } 295 296 $code .= " </tbody>\n"; 297 $code .= " <tfooter>\n"; 298 $code .= " <tr><td colspan=\"4\"> </td></tr>\n"; 299 $code .= " <tr>\n"; 300 $code .= " <td align='center'><select name=\"msg[new][ticker]\">"; 331 $tmp = array(); 332 $tmp['tickerId'] = $message->tickerId; 333 $tmp['name'] = $message->name; 334 $tmp['message'] = $message->message; 335 $tmp['createdOn'] = $message->createdOn; 336 $messagesArr[] = $tmp; 337 } 338 $adminPage->assignBlock('messagelist', $messagesArr); 339 340 $code = ''; 301 341 foreach ($tickerList as $key => $value) { 302 342 $code .= " <option value=\"$key\">$value</option>"; 303 343 } 304 $code .= " </select></td>"; 305 $code .= " <td align='center'><input type=\"text\" name=\"msg[new][message]\" size=\"100\"/></td>"; 306 $code .= " <td align=\"left\"><input type=\"submit\" value=\"Create new message / delete selected messages\"/></td>"; 307 $code .= " <td></td>"; 308 $code .= " </tr>\n"; 309 $code .= " </tfooter>\n"; 310 $code .= "</table>\n"; 311 $code .= "</form>"; 312 313 echo $code; 314 } 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 344 $adminPage->assign('tickeridlist', $code); 345 346 347 $adminPage->display(); 383 348 } 384 349 -
simpleticker/trunk/readme.txt
r442062 r442976 4 4 Tags: news,ticker,newsticker,textticker,text,fader,scroller,facebook 5 5 Requires at least: 2.6 6 Tested up to: 3. 17 Stable tag: 0. 36 Tested up to: 3.2.1 7 Stable tag: 0.4 8 8 9 9 == Description == … … 16 16 17 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. Your19 application will need a password for each ticker, if it want's to add or delete messages.18 get all ticker data and messages via an JSON or XML based API. It is also possible to add and delete messages 19 with the JSON API. Your application will need a password for each ticker, if it want's to add or delete messages. 20 20 21 21 == Copyright == … … 24 24 eMail: Michael.Bartel@gmx.net 25 25 26 == History === 26 == History == 27 Version 0.4 28 - added Template-Engine and XML API 29 27 30 Version 0.3 28 31 - added JSON API 32 29 33 Version 0.2 30 34 - added auto-hide 35 31 36 Version 0.1 32 37 - first version V3.1 … … 44 49 Example for ticker 1 (with id 1): [simpleticker id=1] 45 50 51 == APIs == 52 All APIs are handled with GET paramters. The 'action' parameter specifys which function you want to call. 53 46 54 == 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. 55 The JSON API provides the following functionalities: 49 56 50 The data-JSON string contains a "command" value, which defines the function you want to call. The following functions are available: 57 * jsonGetTickerList - Returns a full list of all available tickers containing the tickers id and name. 58 * jsonGetTickerMessages - Returns a list with the last 50 messages of a ticker. You have to specify the ticker by giving it's ID in the parameter 'tickerid'. The list contains the message id, the message itself and the createdOn timestamp. 59 * jsonManageTicker - You need a password to call the action. All further parameters are given in a BASE64 encoded encrypted JSON string provided as GET parameter named 'data'. You have to set the 'tickerid' parameter as above to define a ticker. The JSON string contains an action attribute which can either be 'addMessage' or 'removeMessage'. The 'addMessage' actions takes an additional 'message' attribute containing the new message and the 'removeMessage' action takes an 'id' attribute. 51 60 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. 61 == XML API == 62 This is not really an API. It just supports the same information as delivered by the JSON API in XML format (expect the avaibility to mange tickers) 55 63 56 Just have a look at the end of the SimpleTicker.php file. The code is very simple and only a few lines long. 64 * xmlGetTickerList - Returns a full list of all available tickers containing the tickers id and name. 65 * xmlGetTickerMessages - Returns a list with the last 50 messages of a ticker. You have to specify the ticker by giving it's ID in the parameter 'tickerid'. The list contains the message id, the message itself and the createdOn timestamp.
Note: See TracChangeset
for help on using the changeset viewer.