what goes here?";
}
function airpress_db_render( $active_tab = '' ) {
global $wpdb;
if (isset($_GET["delete-expired-transients"]) && $_GET["delete-expired-transients"] == "true"){
$all = isset($_GET["all"]) && $_GET["all"] === "true";
airpress_flush_cache( $all );
}
$s = memory_get_usage();
$results = $wpdb->get_results( 'SELECT * FROM wp_options WHERE option_name LIKE "_transient_aprq_%" ORDER BY option_id ASC', OBJECT );
$e = memory_get_usage();
$expirations = $wpdb->get_results( 'SELECT * FROM wp_options WHERE option_name LIKE "_transient_timeout_aprq_%" ORDER BY option_value ASC', OBJECT );
$exp = array();
foreach($expirations as $row){
$hash = str_replace("_transient_timeout_aprq_","",$row->option_name);
$exp[$hash] = $row->option_value;
}
?>
";
$now = time();
foreach($results as $row){
$hash = str_replace("_transient_aprq_","",$row->option_name);
$data = unserialize($row->option_value);
$data_age = round( ($now - $data["created_at"])/60/60, 2 );
$data_expire = round( ($exp[$hash]-$now)/60/60, 2 );
echo "$data_age hours old. Transient expires in $data_expire hours.
";
}
?>
">Delete Expired Transients?
">Delete All Transients (completely clear cache)?
You may find that multiple API Keys or APP IDs are required for your website. Create as many as you need!
$config):
$class = ($active_tab == $key)? 'nav-tab-active' : '';
?>
+
"New Configuration");
$configs[] = $config;
$active_tab = count($configs)-1;
set_airpress_config("airpress_".$airpress_config_initials,$active_tab,$config);
} else {
$active_tab = $requested_tab;
}
$_GET['tab'] = $active_tab;
foreach($configs as $key => $config){
$function = "airpress_admin_".$airpress_config_initials."_tab";
call_user_func($function,$key,$config);
}
}
add_action( 'admin_init', 'airpress_admin_cx_tab_controller');
/***********************************************/
# TAB: DEFAULT
/***********************************************/
function airpress_admin_cx_tab($key,$config) {
$option_name = "airpress_cx".$key;
//$options = get_option( $option_name );
$uploads = wp_get_upload_dir();
$defaults = array(
"api_key" => "",
"app_id" => "",
"refresh" => MINUTE_IN_SECONDS * 5,
"expire" => DAY_IN_SECONDS,
"api_url" => "https://api.airtable.com/v0/",
"fresh" => "fresh",
"debug" => 0,
"log" => $uploads["basedir"] . "/airpress-" . uniqid() . ".log",
"log_max_size" => 3072
);
$options = array_merge($defaults,$config);
################################
################################
$section_title = "Airtable API Connections";
$section_name = "airpress_cx".$key;
add_settings_section(
$section_name,
__( $section_title, 'airpress' ),
"airpress_admin_cx_render_section",
$option_name
);
################################
$field_name = "name";
$field_title = "Configuration Name";
add_settings_field( $field_name, __( $field_title, 'airpress' ), 'airpress_admin_cx_render_element_text', $option_name, $section_name, array($options,$option_name,$field_name) );
################################
$field_name = "api_key";
$field_title = "Airtable API Key";
add_settings_field( $field_name, __( $field_title, 'airpress' ), 'airpress_admin_cx_render_element_text', $option_name, $section_name, array($options,$option_name,$field_name) );
################################
$field_name = "app_id";
$field_title = "Airtable APP ID";
add_settings_field( $field_name, __( $field_title, 'airpress' ), 'airpress_admin_cx_render_element_text', $option_name, $section_name, array($options,$option_name,$field_name) );
################################
$field_name = "api_url";
$field_title = "Airtable API URL";
add_settings_field( $field_name, __( $field_title, 'airpress' ), 'airpress_admin_cx_render_element_text', $option_name, $section_name, array($options,$option_name,$field_name) );
################################
################################
$field_name = "refresh";
$field_title = "Refresh";
add_settings_field( $field_name, __( $field_title, 'airpress' ), 'airpress_admin_cx_render_element_text', $option_name, $section_name, array($options,$option_name,$field_name) );
################################
$field_name = "expire";
$field_title = "Expire";
add_settings_field( $field_name, __( $field_title, 'airpress' ), 'airpress_admin_cx_render_element_text', $option_name, $section_name, array($options,$option_name,$field_name) );
################################
$field_name = "fresh";
$field_title = "Query var to force refresh cache for this request";
add_settings_field( $field_name, __( $field_title, 'airpress' ), 'airpress_admin_cx_render_element_text', $option_name, $section_name, array($options,$option_name,$field_name) );
################################
$field_name = "debug";
$field_title = "Enable Debugging";
add_settings_field( $field_name, __( $field_title, 'airpress' ), 'airpress_admin_cx_render_element_select__debug', $option_name, $section_name, array($options,$option_name,$field_name) );
################################
$field_name = "log";
$field_title = "Debug Logfile";
add_settings_field( $field_name, __( $field_title, 'airpress' ), 'airpress_admin_cx_render_element_text', $option_name, $section_name, array($options,$option_name,$field_name) );
// ################################
// $field_name = "log_max_size";
// $field_title = "Logfile Max Size in Kilobytes (0 for unlimited)";
// add_settings_field( $field_name, __( $field_title, 'airpress' ), 'airpress_admin_cx_render_element_text', $option_name, $section_name, array($options,$option_name,$field_name) );
###############################
$field_name = "delete";
$field_title = "Delete Configuration?";
add_settings_field( $field_name, __( $field_title, 'airpress' ), 'airpress_admin_cx_render_element_delete', $option_name, $section_name, array($options,$option_name,$field_name) );
register_setting($option_name,$option_name,"airpress_cx_validation");
}
function airpress_cx_validation($input){
global $wp_rewrite;
if ($input["debug"] == 1 || $input["debug"] == 2){
if ( $h = @fopen($input["log"], "a") ){
$message = "log file created at ".$input["log"];
fwrite($h, $message."\n");
fclose($h);
} else {
$input["debug"] = 0;
add_settings_error('airpress_cx_log', esc_attr( 'settings_updated' ), esc_attr($input["log"])." is not writable.","error");
}
} else {
$manual_intervention = false;
if ( file_exists($input["log"]) ){
$manual_intervention = true;
if ( is_writable($input["log"]) ){
if ( $h = @fopen($input["log"], "w") ){
$message = "attempting to delete ".$input["log"];
fwrite($h, $message."\n");
fclose($h);
}
$parts = pathinfo($input["log"]);
// Let's only delete log files named airpress.log to avoid allowing
// this field to control the deletion of any file on the server
if ( $parts["basename"] == "airpress.log" ){
if ( unlink($input["log"]) ){
$manual_intervention = false;
} else {
if ( $h = @fopen($input["log"], "a") ){
$message = "failed to delete ".$input["log"];
fwrite($h, $message."\n");
fclose($h);
}
}
}
}
}
if ( $manual_intervention ){
add_settings_error('airpress_cx_log', esc_attr( 'settings_updated' ), "Please delete the log file at " . esc_attr($input["log"]),"error");
}
}
$wp_rewrite->flush_rules();
return $input;
}
function airpress_admin_cx_render_section__general() {
echo '' . __( 'Provides examples of the five basic element types.', 'sandbox' ) . '
';
}
function airpress_admin_cx_render_section() {
echo '' . __( '', 'airpress' ) . '
';
}
function airpress_admin_cx_render_element_text($args) {
$options = $args[0];
$option_name = $args[1];
$field_name = $args[2];
echo '';
if ( $field_name == "name" and $options[$field_name] == "New Configuration" ){
echo "You must change the configuration name from 'New Configuration' to something unique!
";
}
}
function airpress_admin_cx_render_element_toggle($args) {
$options = $args[0];
$option_name = $args[1];
$field_name = $args[2];
$checked = checked( 1, isset( $options[$field_name] ) ? $options[$field_name] : 0, false );
echo '';
echo '';
}
function airpress_admin_cx_render_element_select__posttypes($args) {
$options = $args[0];
$option_name = $args[1];
$field_name = $args[2];
$post_types = airpress_get_posttypes_available();
echo '';
}
function airpress_admin_cx_render_element_select_connections($args) {
$options = $args[0];
$option_name = $args[1];
$field_name = $args[2];
$connections = get_airpress_configs("airpress_cx");
echo '';
}
function airpress_admin_cx_render_element_select__page($args) {
$options = $args[0];
$option_name = $args[1];
$field_name = $args[2];
$pages = get_pages();
echo '';
}
function airpress_admin_cx_render_element_select__debug($args) {
$options = $args[0];
$option_name = $args[1];
$field_name = $args[2];
echo '';
}
function airpress_admin_cx_render_element_delete($args) {
$options = $args[0];
$option_name = $args[1];
$field_name = $args[2];
$tab = (int)$_GET["tab"];
echo "Yes, delete this configuration";
}
?>