get_results($sql); } /** * Retrieves keys of the table * @return void */ function ajdt_get_table_Key($table){ global $wpdb; $sql = "SELECT COLUMN_NAME FROM information_schema.key_column_usage WHERE table_schema = schema() AND constraint_name = 'PRIMARY' AND table_name = '$table'"; return $wpdb->get_row($sql); } /** * Retrieves keys of the table * @return void */ function ajdt_get_table_columns($table){ global $wpdb; $sql = "SHOW COLUMNS FROM $table WHERE Extra <> 'auto_increment'"; return $wpdb->get_results($sql); } /** * Checks for wordpress shortcode and renders it based on number of Api List * Example: [AJDT api="sha1"] * @return void */ function ajdt_render_shortcode(){ ?>





$Api) { echo do_shortcode("[AJDT api='$key']"); } }else{ echo do_shortcode("[AJDT api='$apiName']"); } } ?>
get_allapi_names(); $colNames = ajdt_get_column_names($api); if(empty($colNames)) return ''; return "
"; } /** * Gets the columns names from API * @return comma seperated string */ function ajdt_get_column_names($api) { $cols = ''; if(ajdt_is_api_exists($api)){ $tableColumns = ajdt_get_table_columns(get_option(AJDT_APILISTNAME)[$api]['TableName']); $cols =''; foreach($tableColumns as $column){ $key = $column->Field; $cols = empty($cols) ? $key: "$cols,$key"; } } if(empty($cols)){ echo ajdt_show_error("The requested API(name: $api) doesn't exists or http method 'GET' might be missing...!. Please check for valid APIs in 'AJDT Settings' page"); return $cols; } return $cols; } /** * Gets API names * @return comma seperated string */ function ajdt_get_allapi_names() { $apiList = get_option(AJDT_APILISTNAME); return implode(',', array_keys($apiList)); } /** * Checks if the requested API exists or not * @return boolean value */ function ajdt_is_api_exists($api) { $apiList = get_option(AJDT_APILISTNAME); $isExist = false; foreach($apiList as $k => $v){ if($k==$api){ $httpMethods = $v['MethodName']; if(strpos($httpMethods, 'GET') !== false){ $isExist = true; break; } } } return $isExist; } /** * Displays error message * @return error component */ function ajdt_show_error($msg){ return "

$msg

"; }