Changeset 1510808
- Timestamp:
- 10/08/2016 02:48:11 PM (9 years ago)
- Location:
- tinywebdb-api
- Files:
-
- 4 added
- 6 edited
- 1 copied
-
tags/0.2.2 (copied) (copied from tinywebdb-api/trunk)
-
tags/0.2.2/LICENSE (added)
-
tags/0.2.2/menus.php (modified) (3 diffs)
-
tags/0.2.2/readme.txt (modified) (4 diffs)
-
tags/0.2.2/tinywebdb-api.php (modified) (3 diffs)
-
tags/0.2.2/tinywebdb.php (added)
-
trunk/LICENSE (added)
-
trunk/menus.php (modified) (3 diffs)
-
trunk/readme.txt (modified) (4 diffs)
-
trunk/tinywebdb-api.php (modified) (3 diffs)
-
trunk/tinywebdb.php (added)
Legend:
- Unmodified
- Added
- Removed
-
tinywebdb-api/tags/0.2.2/menus.php
r629956 r1510808 1 1 <?php 2 2 3 class TinyWebDB_Admin { 4 5 } 3 6 4 7 //***** Options Menu ***** … … 81 84 <div class="clear"></div> 82 85 </div> 83 86 84 87 <h3>Address</h3> 85 88 … … 98 101 <th scope="row">Tag type</th> 99 102 <td> 100 <input type="radio" name="tagtype" value="id" <?php if ($setting_tagtype == 'id') { echo 'checked="checked"';} ?> /> Post ID 103 <input type="radio" name="tagtype" value="id" <?php if ($setting_tagtype == 'id') { echo 'checked="checked"';} ?> /> Post ID 101 104 <input type="radio" name="tagtype" value="slug" <?php if ($setting_tagtype == 'slug') { echo 'checked="checked"'; } ?> /> Slug 102 105 <br/>Select Tag mach to type <em>post_id</em> or <em>slug</em>.</td> -
tinywebdb-api/tags/0.2.2/readme.txt
r636417 r1510808 1 1 === TinyWebDB API === 2 2 Contributors: chen420 3 Plugin URI: http:// appinventor.in/side/tinywebdb-api/3 Plugin URI: http://edu2web.com/tinywebdb-api/ 4 4 Author URI: http://digilib.net/ 5 Donate link: http:// appinventor.in/donate/5 Donate link: http://edu2web.com/tinywebdb-api/donate/ 6 6 Tags: appinventor, tinywebdb, api 7 Requires at least: 3.48 Tested up to: 3.4.29 Stable tag: 0.2. 17 Requires at least: 4.0 8 Tested up to: 4.4 9 Stable tag: 0.2.2 10 10 License: GPLv2 or later 11 11 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 20 20 21 21 TinyWebDB Protocol: 22 Action URL Post Parameters Response 23 Get Value {ServiceURL}/getvalue tag JSON: ["VALUE","{tag}", {value}] 24 Store A Value {ServiceURL}/storeavalue tag,value JSON: ["STORED", "{tag}", {value}] 22 Action URL Post Parameters Response 23 Get Value {ServiceURL}/getvalue tag JSON: ["VALUE","{tag}", {value}] 24 Store A Value {ServiceURL}/storeavalue tag,value JSON: ["STORED", "{tag}", {value}] 25 25 26 26 Roadmap: 27 27 TinyWebDB API 0.1.0 implemented Get Value Action. 28 28 TinyWebDB API 0.2.0 will implement Store A Value Action. 29 TinyWebDB API 0.3.0 will implement Authentication.30 TinyWebDB API 1.0.0 Full release.29 TinyWebDB API 0.3.0 will implement Authentication. 30 TinyWebDB API 1.0.0 Full release. 31 31 32 32 Visit Plugin URI for detail. … … 48 48 49 49 Upgrade notes: 50 * You may use the aut moated plugin updater in WordPress 2.5+ with this plugin, but make sure you read the upgrade notes of the latest version after upgrading.50 * You may use the automated plugin updater in WordPress 2.5+ with this plugin, but make sure you read the upgrade notes of the latest version after upgrading. 51 51 52 52 = 1.0 = … … 78 78 Add test URL on admin menu. 79 79 80 = 0.2.2 = 81 Re-write code with oo-calss style. 82 80 83 = 1.0.0 = 81 -
tinywebdb-api/tags/0.2.2/tinywebdb-api.php
r634745 r1510808 2 2 /* 3 3 Plugin Name: Wp TinyWebDB API 4 Plugin URI: http:// appinventor.in/side/tinywebdb-api/4 Plugin URI: http://edu2web.com/tinywebdb-api/ 5 5 Description: a AppInventor TinyWebDB API plugin, use you WordPress as a TinyWebDB web service. 6 Action URL Post Parameters Response 7 Get Value {ServiceURL}/getvalue tag JSON: ["VALUE","{tag}", {value}] 8 Store A Value {ServiceURL}/storeavalue tag,value JSON: ["STORED", "{tag}", {value}] 6 Action URL Post Parameters Response 7 Get Value {ServiceURL}/getvalue tag JSON: ["VALUE","{tag}", {value}] 8 Store A Value {ServiceURL}/storeavalue tag,value JSON: ["STORED", "{tag}", {value}] 9 9 Author: Hong Chen 10 10 Author URI: http://digilib.net/ 11 Version: 0.2. 111 Version: 0.2.2 12 12 */ 13 13 14 14 15 15 define("TINYWEBDB", "tools.php?page=tinywebdb-api/tinywebdb-api.php"); 16 define("TINYWEBDB_VER", "0.2.1"); 17 18 16 define("TINYWEBDB_VER", "0.2.2"); 19 17 20 18 //***** Hooks ***** … … 30 28 } 31 29 32 function wp_tinywebdb_api_get_postid($tagName){33 34 $tagtype = get_option("wp_tinywebdb_api_tag_type");35 if ($tagtype=='') {36 $tagtype = 'id';37 }38 39 if ($tagtype == 'id') {40 $postid = $tagName;41 } else {42 // get_page_by_path('slug')->ID;43 $args=array(44 'name' => $tagName,45 'post_type' => 'post',46 'post_status' => 'publish',47 'showposts' => 1,48 'caller_get_posts'=> 149 );50 $my_posts = get_posts($args);51 if( $my_posts ) {52 $postid = $my_posts[0]->ID;53 }54 }55 56 return $postid;57 }58 59 60 function wp_tinywebdb_api_get_tagName($postid){61 62 $tagtype = get_option("wp_tinywebdb_api_tag_type");63 if ($tagtype=='') {64 $tagtype = 'id';65 }66 67 if ($tagtype == 'id') {68 $tagName = $postid;69 } else {70 // get_page_by_path('slug')->ID;71 $post_data = get_post($postid, ARRAY_A);72 $slug = $post_data['post_name'];73 $tagName = $slug;74 }75 76 return $tagName;77 }78 30 79 31 //***** get $request and get_post , then json_encode it ***** … … 88 40 89 41 function wp_tinywebdb_api_query() { 90 global $wpdb, $table_prefix;91 $bedtag = array("id" => "0", "post_author" => "0", "post_content" => "ERROR BAD tag SUPPLIED");92 42 93 $request = $_SERVER['REQUEST_URI'];94 if (!isset($_SERVER['REQUEST_URI'])) {95 $request = substr($_SERVER['PHP_SELF'], 1);96 if (isset($_SERVER['QUERY_STRING']) AND $_SERVER['QUERY_STRING'] != '') { $request.='?'.$_SERVER['QUERY_STRING']; }97 }98 $url_trigger = get_option("wp_tinywebdb_api_url_trigger");99 if ($url_trigger=='') {100 $url_trigger = 'api';101 }102 43 103 if (isset($_POST['action'])) {104 $request = '/' . $url_trigger . '/'.$_POST['action'].'/';105 }44 require_once dirname(__FILE__) . '/tinywebdb.php'; 45 $tinywebdb = TinyWebDB; 46 header("HTTP/1.1 200 OK"); 106 47 107 if ( strpos('/'.$request, '/'.$url_trigger.'/') ) { 48 switch (TinyWebDB::get_action()) { 49 case "getvalue": 50 $tagName = get_query_var('tag'); 51 $tagValue = TinyWebDB::getvalue($tagName); 108 52 109 global $wp_query; 110 if ($wp_query->is_404) { 111 $wp_query->is_404 = false; 112 $wp_query->is_archive = true; 113 } 114 header("HTTP/1.1 200 OK"); 53 header('Cache-Control: no-cache, must-revalidate'); 54 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); 55 header('Content-type: application/json'); 56 echo json_encode(array("VALUE", $tagName, $tagValue)); 57 exit; // this stops WordPress entirely 58 break; 59 case "storeavalue": // this action will enable from v 0.2.x 60 // JSON_API , Post Parameters : tag,value 61 $tagName = get_query_var('tag'); 62 $tagValue = get_query_var('value'); // $_REQUEST['value']; // 63 $apiKey = get_query_var('apikey'); 64 error_log("Wp TinyWebDB API : storeavalue: " . __FILE__ . "/" . __LINE__ . " ($apiKey) $tagName -- $tagValue"); 65 $setting_apikey = get_option("wp_tinywebdb_api_key"); 66 if ($apiKey == $setting_apikey){ 115 67 116 $tinywebdb_key = explode($url_trigger.'/', $request); 117 $tinywebdb_key = $tinywebdb_key[1]; 118 $tinywebdb_key = explode('/', $tinywebdb_key); 119 $action = $tinywebdb_key[0]; 120 $action = $wpdb->escape($action); 121 switch ($action) { 122 case "getvalue": // this action enable from v 0.1.x 123 // JSON_API , Post Parameters : tag 124 $tagName = get_query_var('tag'); 125 $postid = wp_tinywebdb_api_get_postid($tagName); 126 $tagValue = get_post($postid); 127 if (is_null($tagValue)) $tagValue = $bedtag; //reports a get_post failure 128 // $tagName = wp_tinywebdb_api_get_tagName($postid); 68 $postid = TinyWebDB::storeavalue($tagName, $tagValue); 69 $tagName = TinyWebDB::wp_tinywebdb_api_get_tagName($postid); 129 70 130 71 header('Cache-Control: no-cache, must-revalidate'); 131 72 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); 132 73 header('Content-type: application/json'); 133 echo json_encode(array("VALUE", $tagName, $tagValue)); 134 exit; // this stops WordPress entirely 135 break; 136 case "storeavalue": // this action will enable from v 0.2.x 137 // JSON_API , Post Parameters : tag,value 138 $tagName = get_query_var('tag'); 139 $tagValue = get_query_var('value'); // $_REQUEST['value']; // 140 $apiKey = get_query_var('apikey'); 141 error_log("Wp TinyWebDB API : storeavalue: " . __FILE__ . "/" . __LINE__ . " ($apiKey) $tagName -- $tagValue"); 142 $setting_apikey = get_option("wp_tinywebdb_api_key"); 143 if ($apiKey == $setting_apikey){ 144 145 // Create post object 146 $args = array( 147 'post_title' => wp_strip_all_tags( $tagName ), 148 'post_content' => $tagValue, 149 'post_status' => 'publish', 150 ); 151 152 // Insert the post into the database 153 $postid = wp_insert_post( $args ); 154 if ($postid == 0) { 155 $postid = wp_tinywebdb_api_get_postid($tagName); 156 $args = array( 157 'ID' => wp_strip_all_tags( $postid ), 158 'post_content' => $tagValue, 159 ); 160 $postid = wp_update_post( $args ); 161 } 162 $tagName = wp_tinywebdb_api_get_tagName($postid); 163 164 header('Cache-Control: no-cache, must-revalidate'); 165 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); 166 header('Content-type: application/json'); 167 echo json_encode(array("STORED", $tagName, $tagValue)); 168 } else { 169 echo "check api key."; 170 } 171 exit; 172 break; 173 default: 174 break; 175 } 176 echo '{"status":"ok","tinywebdb_api_version":"' . TINYWEBDB_VER . '","controllers":["getvalue","storeavalue"]}' . "\n"; 177 exit; // this stops WordPress entirely 74 echo json_encode(array("STORED", $tagName, $tagValue)); 75 } else { 76 echo "check api key."; 77 } 78 exit; 79 break; 80 case "No match!": 81 break; 82 default: 83 echo '{"status":"ok","tinywebdb_api_version":"' . TINYWEBDB_VER . '","controllers":["getvalue","storeavalue"]}' . "\n"; 84 exit; // this stops WordPress entirely 85 break; 178 86 } 179 87 } -
tinywebdb-api/trunk/menus.php
r629956 r1510808 1 1 <?php 2 2 3 class TinyWebDB_Admin { 4 5 } 3 6 4 7 //***** Options Menu ***** … … 81 84 <div class="clear"></div> 82 85 </div> 83 86 84 87 <h3>Address</h3> 85 88 … … 98 101 <th scope="row">Tag type</th> 99 102 <td> 100 <input type="radio" name="tagtype" value="id" <?php if ($setting_tagtype == 'id') { echo 'checked="checked"';} ?> /> Post ID 103 <input type="radio" name="tagtype" value="id" <?php if ($setting_tagtype == 'id') { echo 'checked="checked"';} ?> /> Post ID 101 104 <input type="radio" name="tagtype" value="slug" <?php if ($setting_tagtype == 'slug') { echo 'checked="checked"'; } ?> /> Slug 102 105 <br/>Select Tag mach to type <em>post_id</em> or <em>slug</em>.</td> -
tinywebdb-api/trunk/readme.txt
r636417 r1510808 1 1 === TinyWebDB API === 2 2 Contributors: chen420 3 Plugin URI: http:// appinventor.in/side/tinywebdb-api/3 Plugin URI: http://edu2web.com/tinywebdb-api/ 4 4 Author URI: http://digilib.net/ 5 Donate link: http:// appinventor.in/donate/5 Donate link: http://edu2web.com/tinywebdb-api/donate/ 6 6 Tags: appinventor, tinywebdb, api 7 Requires at least: 3.48 Tested up to: 3.4.29 Stable tag: 0.2. 17 Requires at least: 4.0 8 Tested up to: 4.4 9 Stable tag: 0.2.2 10 10 License: GPLv2 or later 11 11 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 20 20 21 21 TinyWebDB Protocol: 22 Action URL Post Parameters Response 23 Get Value {ServiceURL}/getvalue tag JSON: ["VALUE","{tag}", {value}] 24 Store A Value {ServiceURL}/storeavalue tag,value JSON: ["STORED", "{tag}", {value}] 22 Action URL Post Parameters Response 23 Get Value {ServiceURL}/getvalue tag JSON: ["VALUE","{tag}", {value}] 24 Store A Value {ServiceURL}/storeavalue tag,value JSON: ["STORED", "{tag}", {value}] 25 25 26 26 Roadmap: 27 27 TinyWebDB API 0.1.0 implemented Get Value Action. 28 28 TinyWebDB API 0.2.0 will implement Store A Value Action. 29 TinyWebDB API 0.3.0 will implement Authentication.30 TinyWebDB API 1.0.0 Full release.29 TinyWebDB API 0.3.0 will implement Authentication. 30 TinyWebDB API 1.0.0 Full release. 31 31 32 32 Visit Plugin URI for detail. … … 48 48 49 49 Upgrade notes: 50 * You may use the aut moated plugin updater in WordPress 2.5+ with this plugin, but make sure you read the upgrade notes of the latest version after upgrading.50 * You may use the automated plugin updater in WordPress 2.5+ with this plugin, but make sure you read the upgrade notes of the latest version after upgrading. 51 51 52 52 = 1.0 = … … 78 78 Add test URL on admin menu. 79 79 80 = 0.2.2 = 81 Re-write code with oo-calss style. 82 80 83 = 1.0.0 = 81 -
tinywebdb-api/trunk/tinywebdb-api.php
r634745 r1510808 2 2 /* 3 3 Plugin Name: Wp TinyWebDB API 4 Plugin URI: http:// appinventor.in/side/tinywebdb-api/4 Plugin URI: http://edu2web.com/tinywebdb-api/ 5 5 Description: a AppInventor TinyWebDB API plugin, use you WordPress as a TinyWebDB web service. 6 Action URL Post Parameters Response 7 Get Value {ServiceURL}/getvalue tag JSON: ["VALUE","{tag}", {value}] 8 Store A Value {ServiceURL}/storeavalue tag,value JSON: ["STORED", "{tag}", {value}] 6 Action URL Post Parameters Response 7 Get Value {ServiceURL}/getvalue tag JSON: ["VALUE","{tag}", {value}] 8 Store A Value {ServiceURL}/storeavalue tag,value JSON: ["STORED", "{tag}", {value}] 9 9 Author: Hong Chen 10 10 Author URI: http://digilib.net/ 11 Version: 0.2. 111 Version: 0.2.2 12 12 */ 13 13 14 14 15 15 define("TINYWEBDB", "tools.php?page=tinywebdb-api/tinywebdb-api.php"); 16 define("TINYWEBDB_VER", "0.2.1"); 17 18 16 define("TINYWEBDB_VER", "0.2.2"); 19 17 20 18 //***** Hooks ***** … … 30 28 } 31 29 32 function wp_tinywebdb_api_get_postid($tagName){33 34 $tagtype = get_option("wp_tinywebdb_api_tag_type");35 if ($tagtype=='') {36 $tagtype = 'id';37 }38 39 if ($tagtype == 'id') {40 $postid = $tagName;41 } else {42 // get_page_by_path('slug')->ID;43 $args=array(44 'name' => $tagName,45 'post_type' => 'post',46 'post_status' => 'publish',47 'showposts' => 1,48 'caller_get_posts'=> 149 );50 $my_posts = get_posts($args);51 if( $my_posts ) {52 $postid = $my_posts[0]->ID;53 }54 }55 56 return $postid;57 }58 59 60 function wp_tinywebdb_api_get_tagName($postid){61 62 $tagtype = get_option("wp_tinywebdb_api_tag_type");63 if ($tagtype=='') {64 $tagtype = 'id';65 }66 67 if ($tagtype == 'id') {68 $tagName = $postid;69 } else {70 // get_page_by_path('slug')->ID;71 $post_data = get_post($postid, ARRAY_A);72 $slug = $post_data['post_name'];73 $tagName = $slug;74 }75 76 return $tagName;77 }78 30 79 31 //***** get $request and get_post , then json_encode it ***** … … 88 40 89 41 function wp_tinywebdb_api_query() { 90 global $wpdb, $table_prefix;91 $bedtag = array("id" => "0", "post_author" => "0", "post_content" => "ERROR BAD tag SUPPLIED");92 42 93 $request = $_SERVER['REQUEST_URI'];94 if (!isset($_SERVER['REQUEST_URI'])) {95 $request = substr($_SERVER['PHP_SELF'], 1);96 if (isset($_SERVER['QUERY_STRING']) AND $_SERVER['QUERY_STRING'] != '') { $request.='?'.$_SERVER['QUERY_STRING']; }97 }98 $url_trigger = get_option("wp_tinywebdb_api_url_trigger");99 if ($url_trigger=='') {100 $url_trigger = 'api';101 }102 43 103 if (isset($_POST['action'])) {104 $request = '/' . $url_trigger . '/'.$_POST['action'].'/';105 }44 require_once dirname(__FILE__) . '/tinywebdb.php'; 45 $tinywebdb = TinyWebDB; 46 header("HTTP/1.1 200 OK"); 106 47 107 if ( strpos('/'.$request, '/'.$url_trigger.'/') ) { 48 switch (TinyWebDB::get_action()) { 49 case "getvalue": 50 $tagName = get_query_var('tag'); 51 $tagValue = TinyWebDB::getvalue($tagName); 108 52 109 global $wp_query; 110 if ($wp_query->is_404) { 111 $wp_query->is_404 = false; 112 $wp_query->is_archive = true; 113 } 114 header("HTTP/1.1 200 OK"); 53 header('Cache-Control: no-cache, must-revalidate'); 54 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); 55 header('Content-type: application/json'); 56 echo json_encode(array("VALUE", $tagName, $tagValue)); 57 exit; // this stops WordPress entirely 58 break; 59 case "storeavalue": // this action will enable from v 0.2.x 60 // JSON_API , Post Parameters : tag,value 61 $tagName = get_query_var('tag'); 62 $tagValue = get_query_var('value'); // $_REQUEST['value']; // 63 $apiKey = get_query_var('apikey'); 64 error_log("Wp TinyWebDB API : storeavalue: " . __FILE__ . "/" . __LINE__ . " ($apiKey) $tagName -- $tagValue"); 65 $setting_apikey = get_option("wp_tinywebdb_api_key"); 66 if ($apiKey == $setting_apikey){ 115 67 116 $tinywebdb_key = explode($url_trigger.'/', $request); 117 $tinywebdb_key = $tinywebdb_key[1]; 118 $tinywebdb_key = explode('/', $tinywebdb_key); 119 $action = $tinywebdb_key[0]; 120 $action = $wpdb->escape($action); 121 switch ($action) { 122 case "getvalue": // this action enable from v 0.1.x 123 // JSON_API , Post Parameters : tag 124 $tagName = get_query_var('tag'); 125 $postid = wp_tinywebdb_api_get_postid($tagName); 126 $tagValue = get_post($postid); 127 if (is_null($tagValue)) $tagValue = $bedtag; //reports a get_post failure 128 // $tagName = wp_tinywebdb_api_get_tagName($postid); 68 $postid = TinyWebDB::storeavalue($tagName, $tagValue); 69 $tagName = TinyWebDB::wp_tinywebdb_api_get_tagName($postid); 129 70 130 71 header('Cache-Control: no-cache, must-revalidate'); 131 72 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); 132 73 header('Content-type: application/json'); 133 echo json_encode(array("VALUE", $tagName, $tagValue)); 134 exit; // this stops WordPress entirely 135 break; 136 case "storeavalue": // this action will enable from v 0.2.x 137 // JSON_API , Post Parameters : tag,value 138 $tagName = get_query_var('tag'); 139 $tagValue = get_query_var('value'); // $_REQUEST['value']; // 140 $apiKey = get_query_var('apikey'); 141 error_log("Wp TinyWebDB API : storeavalue: " . __FILE__ . "/" . __LINE__ . " ($apiKey) $tagName -- $tagValue"); 142 $setting_apikey = get_option("wp_tinywebdb_api_key"); 143 if ($apiKey == $setting_apikey){ 144 145 // Create post object 146 $args = array( 147 'post_title' => wp_strip_all_tags( $tagName ), 148 'post_content' => $tagValue, 149 'post_status' => 'publish', 150 ); 151 152 // Insert the post into the database 153 $postid = wp_insert_post( $args ); 154 if ($postid == 0) { 155 $postid = wp_tinywebdb_api_get_postid($tagName); 156 $args = array( 157 'ID' => wp_strip_all_tags( $postid ), 158 'post_content' => $tagValue, 159 ); 160 $postid = wp_update_post( $args ); 161 } 162 $tagName = wp_tinywebdb_api_get_tagName($postid); 163 164 header('Cache-Control: no-cache, must-revalidate'); 165 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); 166 header('Content-type: application/json'); 167 echo json_encode(array("STORED", $tagName, $tagValue)); 168 } else { 169 echo "check api key."; 170 } 171 exit; 172 break; 173 default: 174 break; 175 } 176 echo '{"status":"ok","tinywebdb_api_version":"' . TINYWEBDB_VER . '","controllers":["getvalue","storeavalue"]}' . "\n"; 177 exit; // this stops WordPress entirely 74 echo json_encode(array("STORED", $tagName, $tagValue)); 75 } else { 76 echo "check api key."; 77 } 78 exit; 79 break; 80 case "No match!": 81 break; 82 default: 83 echo '{"status":"ok","tinywebdb_api_version":"' . TINYWEBDB_VER . '","controllers":["getvalue","storeavalue"]}' . "\n"; 84 exit; // this stops WordPress entirely 85 break; 178 86 } 179 87 }
Note: See TracChangeset
for help on using the changeset viewer.