/wp-content/plugins/admin-block-country/images/facebook.jpg" style="width: 30px;" />
/wp-content/plugins/admin-block-country/images/twitter.jpg" style="width: 30px;" />
/wp-content/plugins/admin-block-country/images/rate-me.png" />
fix_http_quotes($_POST[$name]);
} else if (isset($_GET[$name])) {
return $this->fix_http_quotes($_GET[$name]);
} else if (isset($_POST[$name."_0"])) {
$i = 0;
$data = "";
do {
$data .= sanitize_text_field($_POST[$name."_".$i]);
if ($data != "") {
$data .= " ";
}
$i++;
} while (isset($_POST[$name."_".$i]));
$_POST[$name] = $this->fix_http_quotes($data);
return $this->fix_http_quotes($data);
} else {
return "";
}
} else {
$name = str_replace("[]", "", $name);
if (isset($_POST[$name][$index])) {
return $this->fix_http_quotes($_POST[$name][$index]);
} else if (isset($_GET[$name][$index])) {
return $this->fix_http_quotes($_GET[$name][$index]);
} else if (isset($_POST[$name."_0"][$index])) {
$i = 0;
$data = "";
do {
$data .= $_POST[$name."_".$i][$index];
if ($data != "") {
$data .= " ";
}
$i++;
} while (isset($_POST[$name."_".$i][$index]));
$_POST[$name][$index] = $this->fix_http_quotes($data);
return $this->fix_http_quotes($data);
} else {
return "";
}
}
}
// Adds a form field to the page.
function add_form_field($instance, $field_type, $field_label, $field_id, $field_name, $field_attributes = array(), $container_element, $container_attributes = array(), $value_options = array(), $field_index = -1) {
$field_type = sanitize_text_field($field_type);
$field_label = sanitize_text_field($field_label);
$field_id = sanitize_text_field($field_id);
$field_name = sanitize_text_field($field_name);
$container_element = sanitize_text_field($container_element);
$field_index = sanitize_text_field($field_index);
$field_content = "";
foreach ($field_attributes as $key => $value) {
$field_content .= "$key='$value' ";
}
$container_content = "";
foreach ($container_attributes as $key => $value) {
$container_content .= "$key='$value' ";
}
if ($instance == null && preg_match("/^tomm8te_admin_option::/", $field_name)) {
$field_name = str_replace("tomm8te_admin_option::", "", $field_name);
$field_value = get_option($field_name);
if (count($_POST) > 0) {
if ($field_index >= 0) {
$field_value = $this->get_query_string_value($field_name, $field_index);
} else {
$field_value = $this->get_query_string_value($field_name);
}
}
} else {
if (isset($instance->$field_name)) {
$field_value = $instance->$field_name;
} else {
if ($instance == null || count($_POST) > 0) {
if ($field_index >= 0) {
$field_value = $this->get_query_string_value($field_name, $field_index);
} else {
$field_value = $this->get_query_string_value($field_name);
}
}
}
}
$field_id_with_without_index = $field_id;
$field_name_with_without_array = $field_name;
$field_checkbox_array = "";
if ($field_index >= 0) {
$field_checkbox_array = "[".$field_index."]";
$field_name_with_without_array .= "[]";
$field_id_with_without_index .= "_".$field_index;
}
$field_type = strtolower($field_type);
$field_value = esc_html($field_value);
if (!is_array($field_value)) {
$field_value = str_replace("&", "&", htmlentities(htmlentities($field_value, ENT_NOQUOTES), ENT_QUOTES));
}
if ($field_type != "hidden") {
echo("<$container_element $container_content>");
if ($field_label != "") {
if ($field_type == "checkbox") {
echo("");
} else if ($field_type == "placeholder_text" || $field_type == "placeholder_textarea") {
// Do nothing
} else {
echo("");
}
}
}
if ($field_type == "text") {
echo("");
} else if ($field_type == "hidden") {
echo("");
} else if ($field_type == "placeholder_text") {
echo("");
} else if ($field_type == "file") {
echo("");
} else if ($field_type == "textarea") {
echo("");
} else if ($field_type == "placeholder_textarea") {
echo("");
} else if ($field_type == "captcha") {
echo("
");
echo("[ Different Image ]");
} else if ($field_type == "select") {
echo("");
} else if ($field_type == "radio") {
echo("");
} else if ($field_type == "checkbox") {
echo("");
}
if ($field_index >= 0) {
$field_id = $field_id."_".$field_index;
}
if (isset($_SESSION[$field_id."_error"]) && $_SESSION[$field_id."_error"] != "") {
echo "".$_SESSION[$field_id."_error"]."";
}
unset($_SESSION[$field_id."_error"]);
if ($field_type != "hidden") {
echo("$container_element>");
}
}
// Inserts data into the database. Returns true if inserted correct, false if not.
function insert_record($table_name, $insert_array) {
global $wpdb;
ob_start();
$wpdb->show_errors();
$table_name_prefix = $wpdb->prefix.sanitize_text_field($table_name);
$wpdb->insert($table_name_prefix, $insert_array);
$wpdb->print_error();
$errors = ob_get_contents();
ob_end_clean();
if (preg_match("/WordPress database error:<\/strong> \[\]/", $errors)) {
return true;
} else {
$sql = "SHOW INDEXES FROM $table_name_prefix WHERE non_unique =0 AND Key_name != 'PRIMARY'";
$results = $wpdb->get_results($sql);
foreach ($results as $result) {
$col_name = $result->Column_name;
if (preg_match("/Duplicate entry (.+)'".$col_name."']/", $errors, $matches, PREG_OFFSET_CAPTURE)) {
if (!preg_match("/Must have a unique value/", $_SESSION[$col_name."_error"])) {
$_SESSION[$col_name."_error"] .= "Must have a unique value.";
}
}
}
return false;
}
}
// Updates data in the database. Returns true if updated correctly, false if not.
function update_record_by_id($table_name, $update_array, $id_column_name, $id) {
$id_column_name = sanitize_text_field($id_column_name);
$id = sanitize_text_field($id);
global $wpdb;
ob_start();
$wpdb->show_errors();
$table_name_prefix = $wpdb->prefix.sanitize_text_field($table_name);
$result = $wpdb->update($table_name_prefix, $update_array, array($id_column_name => $id));
$wpdb->print_error();
$errors = ob_get_contents();
ob_end_clean();
if (preg_match("/WordPress database error:<\/strong> \[\]/", $errors)) {
return true;
} else {
$sql = "SHOW INDEXES FROM $table_name_prefix WHERE non_unique =0 AND Key_name != 'PRIMARY'";
$results = $wpdb->get_results($sql);
foreach ($results as $result) {
$col_name = $result->Column_name;
if (preg_match("/Duplicate entry (.+)'".$col_name."']/", $errors, $matches, PREG_OFFSET_CAPTURE)) {
if (!preg_match("/Must have a unique value/", $_SESSION[$col_name."_error"])) {
$_SESSION[$col_name."_error"] .= "Must have a unique value.";
}
}
}
return false;
}
}
// Select records from the database. Returns sql results object.
function get_results($table_name, $fields_array, $where_sql, $order_array = array(), $limit = "") {
global $wpdb;
$table_name_prefix = $wpdb->prefix.sanitize_text_field($table_name);
if ($fields_array == "*") {
$fields_comma_separated = "*";
} else {
$fields_comma_separated = sanitize_text_field(implode(",", $fields_array));
}
if (!empty($where_sql)) {
$where_sql = "WHERE ".$where_sql;
}
$order_sql = "";
if (!empty($order_array)) {
$order_sql = "ORDER BY ".sanitize_text_field(implode(",", $order_array));
}
$limit_sql = "";
if ($limit != "") {
$limit_sql = "LIMIT ".sanitize_text_field($limit);
}
$sql = "SELECT $fields_comma_separated FROM $table_name_prefix $where_sql $order_sql $limit_sql";
// echo $sql;
return $wpdb->get_results($sql);
}
}
}
?>