/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" />
\norder allow,deny\ndeny from all\n\nphp_flag log_errors on\nphp_value error_log error_log");
function write_to_htaccess_file($rule_name, $content) {
$htaccess_content = file_get_contents(ABSPATH.".htaccess");
$htaccess_content = preg_replace("/\n#BEGIN ".$rule_name."(.+)#END ".$rule_name."/s", "", $htaccess_content);
file_put_contents(ABSPATH.".htaccess", $htaccess_content);
$new_content = "\n#BEGIN ".$rule_name.
"\n".$content."\n".
"#END ".$rule_name;
file_put_contents(ABSPATH.".htaccess", $new_content, FILE_APPEND | LOCK_EX);
}
// Returns true if the file is writable, false if it isn't.
function is_file_writable($file) {
if ( $f = @fopen( $file, 'a' ) ) {
@fclose( $f );
return true;
} else {
return false;
}
}
// Returns true if the file is readable, false if it isn't.
function is_file_readable($file) {
if ( $f = @fopen( $file, 'r' ) ) {
@fclose( $f );
return true;
} else {
return false;
}
}
// Javascript redirect to url code.
function javascript_redirect_to($url, $non_javscript_content = "") {
echo("");
if ($non_javscript_content != "") {
echo $non_javscript_content;
}
}
// Titlizes a string. For example: status_level would become Status Level.
function titlize_str($str) {
return ucwords((str_replace("_", " ", $str)));
}
// Return current url.
function get_current_url() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
// Returns true if parameter is a datetime variable.
function is_valid_datetime($datetime) {
return (preg_match("/^([0-9]{2,4})-([0-9]{1,2})-([0-9]{1,2})( ([0-9| |:])*)*$/", $datetime));
}
// Returns true if parameter is an email address. You can only pass one email address.
function is_valid_email($email) {
$email = strtolower($email);
return (preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/", $email));
}
// Returns true if parameter is an email address. You can pass more then one email address, by separating them with a comma.
function is_valid_emails($emails) {
$emails_valid = true;
$email_addresses = explode(",", preg_replace("/,( )*/", ",",$emails));
foreach ($email_addresses as $email_address) {
$email_address = strtolower($email_address);
if(!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/", $email_address)) {
$emails_valid = false;
}
}
return $emails_valid;
}
// Fixes up http post/get variables so that they present quotes correctly rather then like (\').
function fix_http_quotes($http_data) {
$http_data = str_replace('\"', "\"", $http_data);
$http_data = str_replace("\'", '\'', $http_data);
return $http_data;
}
// Basically gets the value from query string without having to use $_POST or $_GET variables. $_POST takes precidence over $_GET.
function get_query_string_value($name, $index = -1) {
if ($index == -1) {
if (isset($_POST[$name])) {
return ABCTomM8::fix_http_quotes($_POST[$name]);
} else if (isset($_GET[$name])) {
return ABCTomM8::fix_http_quotes($_GET[$name]);
} else if (isset($_POST[$name."_0"])) {
$i = 0;
$data = "";
do {
$data .= $_POST[$name."_".$i];
if ($data != "") {
$data .= " ";
}
$i++;
} while (isset($_POST[$name."_".$i]));
$_POST[$name] = ABCTomM8::fix_http_quotes($data);
return ABCTomM8::fix_http_quotes($data);
} else {
return "";
}
} else {
$name = str_replace("[]", "", $name);
if (isset($_POST[$name][$index])) {
return ABCTomM8::fix_http_quotes($_POST[$name][$index]);
} else if (isset($_GET[$name][$index])) {
return ABCTomM8::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] = ABCTomM8::fix_http_quotes($data);
return ABCTomM8::fix_http_quotes($data);
} else {
return "";
}
}
}
// Upload a file.
function upload_file($field_name) {
$uploadfiles = $_FILES[$field_name];
if (is_array($uploadfiles)) {
foreach ($uploadfiles['name'] as $key => $value) {
// look only for uploded files
if ($uploadfiles['error'][$key] == 0) {
$filetmp = $uploadfiles['tmp_name'][$key];
//clean filename and extract extension
$filename = $uploadfiles['name'][$key];
// get file info
// @fixme: wp checks the file extension....
$filetype = wp_check_filetype( basename( $filename ), null );
$filetitle = preg_replace('/\.[^.]+$/', '', basename( $filename ) );
$filename = $filetitle . '.' . $filetype['ext'];
$upload_dir = wp_upload_dir();
/**
* Check if the filename already exist in the directory and rename the
* file if necessary
*/
$i = 0;
while ( file_exists( $upload_dir['path'] .'/' . $filename ) ) {
$filename = $filetitle . '_' . $i . '.' . $filetype['ext'];
$i++;
}
$filedest = $upload_dir['path'] . '/' . $filename;
/**
* Check write permissions
*/
if ( !is_writeable( $upload_dir['path'] ) ) {
$this->msg_e('Unable to write to directory %s. Is this directory writable by the server?');
return;
}
/**
* Save temporary file to uploads dir
*/
if ( !@move_uploaded_file($filetmp, $filedest) ){
$this->msg_e("Error, the file $filetmp could not moved to : $filedest ");
continue;
}
$attachment = array(
'post_mime_type' => $filetype['type'],
'post_title' => $filetitle,
'post_content' => '',
'post_status' => 'inherit',
);
$attach_id = wp_insert_attachment( $attachment, $filedest );
$attach_data = wp_generate_attachment_metadata( $attach_id, $filedest );
wp_update_attachment_metadata( $attach_id, $attach_data );
preg_match("/\/wp-content(.+)$/", $filedest, $matches, PREG_OFFSET_CAPTURE);
ABCTomM8::update_record_by_id("posts", array("guid" => get_option("siteurl").$matches[0][0]), "ID", $attach_id);
// echo $filedest;
}
}
}
}
// Allows you to send an email.
function send_email($is_html, $to_emails, $to_cc_emails, $to_bcc_emails, $from_email, $from_name, $subject, $body, $alt_body = "", $attachments = array(), $smtp_auth = false, $smtp_mail_host = "", $smtp_mail_port = "", $smtp_mail_username = "", $smtp_mail_password = "", $secure_array = array()) {
$mail = new PHPMailer();
// defaults to using php "mail()"
$body = preg_replace("/[\"]/","",$body);
if (!is_array($to_emails)) {
$to_emails = explode(",", $to_emails);
}
foreach ($to_emails as $key => $value) {
if (is_integer($key)) {
$mail->AddAddress(str_replace(" ", "",$value), "");
} else {
$mail->AddAddress(str_replace(" ", "",$key), $value);
}
}
if (!is_array($to_cc_emails)) {
$to_cc_emails = explode(",", $to_cc_emails);
}
foreach ($to_cc_emails as $key => $value) {
if (is_integer($key)) {
$mail->AddCC(str_replace(" ", "",$value), "");
} else {
$mail->AddCC(str_replace(" ", "",$key), $value);
}
}
if (!is_array($to_bcc_emails)) {
$to_bcc_emails = explode(",", $to_bcc_emails);
}
foreach ($to_bcc_emails as $key => $value) {
if (is_integer($key)) {
$mail->AddBCC(str_replace(" ", "",$value), "");
} else {
$mail->AddBCC(str_replace(" ", "",$key), $value);
}
}
$mail->SetFrom($from_email, $from_name);
$mail->Subject = $subject;
if ($is_html) {
$body = preg_replace("/