Plugin Directory

Changeset 1510808


Ignore:
Timestamp:
10/08/2016 02:48:11 PM (9 years ago)
Author:
chen420
Message:

tagging version 0.2.2

Location:
tinywebdb-api
Files:
4 added
6 edited
1 copied

Legend:

Unmodified
Added
Removed
  • tinywebdb-api/tags/0.2.2/menus.php

    r629956 r1510808  
    11<?php
    22
     3class TinyWebDB_Admin {
     4
     5}
    36
    47//***** Options Menu *****
     
    8184      <div class="clear"></div>
    8285    </div>
    83              
     86
    8487    <h3>Address</h3>
    8588
     
    98101        <th scope="row">Tag type</th>
    99102        <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
    101104            <input type="radio" name="tagtype" value="slug"  <?php if ($setting_tagtype == 'slug') { echo 'checked="checked"';  } ?> /> Slug
    102105            <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  
    11===  TinyWebDB API  ===
    22Contributors: chen420
    3 Plugin URI: http://appinventor.in/side/tinywebdb-api/
     3Plugin URI: http://edu2web.com/tinywebdb-api/
    44Author URI: http://digilib.net/
    5 Donate link: http://appinventor.in/donate/
     5Donate link: http://edu2web.com/tinywebdb-api/donate/
    66Tags: appinventor, tinywebdb, api
    7 Requires at least: 3.4
    8 Tested up to: 3.4.2
    9 Stable tag: 0.2.1
     7Requires at least: 4.0
     8Tested up to: 4.4
     9Stable tag: 0.2.2
    1010License: GPLv2 or later
    1111License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    2020
    2121TinyWebDB 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}]
    2525
    2626Roadmap:
    2727    TinyWebDB API 0.1.0 implemented Get Value Action.
    2828    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.
    3131
    3232Visit Plugin URI for detail.
     
    4848
    4949Upgrade notes:
    50 *  You may use the autmoated 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.
    5151
    5252= 1.0 =
     
    7878Add test URL on admin menu.
    7979
     80= 0.2.2 =
     81Re-write code with oo-calss style.
     82
    8083= 1.0.0 =
    81 
  • tinywebdb-api/tags/0.2.2/tinywebdb-api.php

    r634745 r1510808  
    22/*
    33Plugin Name: Wp TinyWebDB API
    4 Plugin URI: http://appinventor.in/side/tinywebdb-api/
     4Plugin URI: http://edu2web.com/tinywebdb-api/
    55Description: 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}]
    99Author: Hong Chen
    1010Author URI: http://digilib.net/
    11 Version: 0.2.1
     11Version: 0.2.2
    1212*/
    1313
    1414
    1515define("TINYWEBDB", "tools.php?page=tinywebdb-api/tinywebdb-api.php");
    16 define("TINYWEBDB_VER", "0.2.1");
    17 
    18 
     16define("TINYWEBDB_VER", "0.2.2");
    1917
    2018//***** Hooks *****
     
    3028}
    3129
    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'=> 1
    49         );
    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 }
    7830
    7931//***** get $request and get_post , then json_encode it *****
     
    8840
    8941function wp_tinywebdb_api_query() {
    90     global $wpdb, $table_prefix;
    91     $bedtag = array("id" => "0", "post_author" => "0", "post_content" => "ERROR BAD tag SUPPLIED");
    9242
    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     }
    10243
    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");
    10647
    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);
    10852
    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){
    11567
    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);
    12970
    13071                header('Cache-Control: no-cache, must-revalidate');
    13172                header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
    13273                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;
    17886    }
    17987}
  • tinywebdb-api/trunk/menus.php

    r629956 r1510808  
    11<?php
    22
     3class TinyWebDB_Admin {
     4
     5}
    36
    47//***** Options Menu *****
     
    8184      <div class="clear"></div>
    8285    </div>
    83              
     86
    8487    <h3>Address</h3>
    8588
     
    98101        <th scope="row">Tag type</th>
    99102        <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
    101104            <input type="radio" name="tagtype" value="slug"  <?php if ($setting_tagtype == 'slug') { echo 'checked="checked"';  } ?> /> Slug
    102105            <br/>Select Tag mach to type <em>post_id</em> or <em>slug</em>.</td>
  • tinywebdb-api/trunk/readme.txt

    r636417 r1510808  
    11===  TinyWebDB API  ===
    22Contributors: chen420
    3 Plugin URI: http://appinventor.in/side/tinywebdb-api/
     3Plugin URI: http://edu2web.com/tinywebdb-api/
    44Author URI: http://digilib.net/
    5 Donate link: http://appinventor.in/donate/
     5Donate link: http://edu2web.com/tinywebdb-api/donate/
    66Tags: appinventor, tinywebdb, api
    7 Requires at least: 3.4
    8 Tested up to: 3.4.2
    9 Stable tag: 0.2.1
     7Requires at least: 4.0
     8Tested up to: 4.4
     9Stable tag: 0.2.2
    1010License: GPLv2 or later
    1111License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    2020
    2121TinyWebDB 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}]
    2525
    2626Roadmap:
    2727    TinyWebDB API 0.1.0 implemented Get Value Action.
    2828    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.
    3131
    3232Visit Plugin URI for detail.
     
    4848
    4949Upgrade notes:
    50 *  You may use the autmoated 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.
    5151
    5252= 1.0 =
     
    7878Add test URL on admin menu.
    7979
     80= 0.2.2 =
     81Re-write code with oo-calss style.
     82
    8083= 1.0.0 =
    81 
  • tinywebdb-api/trunk/tinywebdb-api.php

    r634745 r1510808  
    22/*
    33Plugin Name: Wp TinyWebDB API
    4 Plugin URI: http://appinventor.in/side/tinywebdb-api/
     4Plugin URI: http://edu2web.com/tinywebdb-api/
    55Description: 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}]
    99Author: Hong Chen
    1010Author URI: http://digilib.net/
    11 Version: 0.2.1
     11Version: 0.2.2
    1212*/
    1313
    1414
    1515define("TINYWEBDB", "tools.php?page=tinywebdb-api/tinywebdb-api.php");
    16 define("TINYWEBDB_VER", "0.2.1");
    17 
    18 
     16define("TINYWEBDB_VER", "0.2.2");
    1917
    2018//***** Hooks *****
     
    3028}
    3129
    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'=> 1
    49         );
    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 }
    7830
    7931//***** get $request and get_post , then json_encode it *****
     
    8840
    8941function wp_tinywebdb_api_query() {
    90     global $wpdb, $table_prefix;
    91     $bedtag = array("id" => "0", "post_author" => "0", "post_content" => "ERROR BAD tag SUPPLIED");
    9242
    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     }
    10243
    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");
    10647
    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);
    10852
    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){
    11567
    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);
    12970
    13071                header('Cache-Control: no-cache, must-revalidate');
    13172                header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
    13273                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;
    17886    }
    17987}
Note: See TracChangeset for help on using the changeset viewer.