Adblock Notify stats have been successfully cleared.
';
}
function an_reset_stats() {
$screen = get_current_screen();
if ( $screen->id != 'toplevel_page_'. AN_ID )
return;
if($_GET['an-reset'] == 'true'){
delete_option( 'adblocker_notify_counter' );
add_action( 'admin_notices', 'an_stats_notice' );
}
}
add_filter('admin_head', 'an_reset_stats' );
/***************************************************************
* Generate random selector or file name
***************************************************************/
function an_random_slug() {
$alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
$prefix = array();
$alphaLength = strlen($alphabet) - 1;
for ($i = 0; $i < 12; $i++) {
$n = rand(0, $alphaLength);
$prefix[] = $alphabet[$n];
}
return implode($prefix);
}
/***************************************************************
* Create new Style and Script files in a temp directory
***************************************************************/
function an_change_files_css_selectors($tempFolderPath, $tempFolderURL, $file, $oldFileName=null, $newFileName, $newSelectors, $content=''){
//Get default css and js files
$fileExt = pathinfo($file, PATHINFO_EXTENSION);
$fileContent = file_get_contents($file) . $content;
//Replace default selectors with new ones
$defaultSelectors = array('an-Modal', 'reveal-modal', 'an-alternative');
$fileContent = str_replace($defaultSelectors, $newSelectors, $fileContent);
//Load WP_Filesystem API
WP_Filesystem();
global $wp_filesystem;
//Verify that we can create the file
if ( $wp_filesystem->exists( $tempFolderPath.$oldFileName ) ) {
if ( ! $wp_filesystem->is_writable( $tempFolderPath.$oldFileName ) ) {
return false;
}
if ( ! $wp_filesystem->is_readable( $tempFolderPath.$oldFileName ) ) {
return false;
}
}
//Verify directory
$uploadDir = wp_upload_dir();
if ( ! $wp_filesystem->is_dir( $uploadDir['basedir'] ) ) {
return false;
}
if ( ! $wp_filesystem->is_writable( $uploadDir['basedir'] ) ) {
return false;
}
//Creat new dir and files
if ( $wp_filesystem->is_dir( $tempFolderPath ) ) {
array_map('unlink', glob( $tempFolderPath . '*.' . $fileExt) );
} else {
$wp_filesystem->mkdir( $tempFolderPath );
}
$wp_filesystem->put_contents( $tempFolderPath . $newFileName . '.' . $fileExt, $fileContent, 0644 );
$file = $tempFolderURL . $newFileName . '.' . $fileExt;
return $newFileName . '.' . $fileExt;
}
/***************************************************************
* Save scripts and styles with new random selectors after saving Titan Options
***************************************************************/
function an_save_setting_random_selectors() {
$an_option = unserialize( get_option( 'adblocker_notify_options' ) );
//Define new temp path
$uploadDir = wp_upload_dir();
$tempFolderPath = trailingslashit( $uploadDir['basedir'] ) . 'an-temp/';
$tempFolderURL = trailingslashit( $uploadDir['baseurl'] ) . 'an-temp/';
//Define new selectors
$newSelectors = array(an_random_slug(), an_random_slug(), an_random_slug());
if($an_option['an_option_selectors'] == true ){
if( ini_get('allow_url_fopen') ) {
//Flush semectors
if($an_option['an_option_flush'] == true || !file_exists($tempFolderPath) ){
//Retrieve old files infos
$anScripts = unserialize( get_option( 'adblocker_notify_selectors' ) );
//Generate new css and js files
$titanCssContent = an_update_titan_css_selectors($newSelectors);
$newCSS = an_change_files_css_selectors($tempFolderPath, $tempFolderURL, AN_URL . 'css/an-style.min.css', $anScripts['files']['css'], an_random_slug(), $newSelectors, $titanCssContent );
$newJS = an_change_files_css_selectors($tempFolderPath, $tempFolderURL, AN_URL . 'js/an-scripts.min.js', $anScripts['files']['js'], an_random_slug(), $newSelectors );
//Upload dir and temp dir are not writable
if($newCSS == false || $newJS== false){
$tempFolderPath = false;
}
//Store data
$newFiles = array(
'temp-path' => $tempFolderPath,
'temp-url' => $tempFolderURL,
'files'=> array(
'css'=> $newCSS,
'js' => $newJS
),
'selectors' => $newSelectors
);
update_option('adblocker_notify_selectors', serialize($newFiles));
}
}
//remove option flush
$an_option['an_option_flush'] = false;
update_option( 'adblocker_notify_options', serialize($an_option));
} else {
// Remove temp files
an_delete_temp_folder($tempFolderPath);
}
}
add_action('tf_admin_options_saved_adblocker_notify', 'an_save_setting_random_selectors',99);
/***************************************************************
* Admin Panel notice if wrong CHMOD on "wp-content/uploads"
***************************************************************/
function an_error_admin_notices() {
$screen = get_current_screen();
if ( $screen->id != 'toplevel_page_'. AN_ID )
return;
$anScripts = unserialize( get_option( 'adblocker_notify_selectors' ) );
if(!empty($anScripts) && $anScripts['temp-path'] == false) {
echo '
'. __( 'WARNING: There was an error creating Adblock Notify CSS and JS files. Upload directory is not writable. Please CHMOD "wp-content/uploads" to 0777', 'an-translate' ) .'
[ Changing File Permissions ]
'. __( 'Don\'t worry, we thought about it. Adblock Notify will print the scripts directly in your DOM, but for performance purpose it is recommended to change your uploads directory CHMOD!', 'an-translate' ) .'
'. __( 'WARNING: This plugin requires "allow_url_fopen" to be activated, but it is disabled in the server configuration. The plugin will not work properly if you don\'t turn it on!', 'an-translate' ) .'
'. __( 'To enable this functionality, use a text editor to modify the allow_url_fopen directive in the php.ini file as follows: ', 'an-translate' ) .' allow_url_fopen = on
'. __( 'WARNING: This plugin requires "allow_url_fopen" to be activated or at least CURL to run in defect mode, but they are disabled in the server configuration. The plugin will not work properly if you don\'t turn allow_url_fopen" on!', 'an-translate' ) .'
'. __( 'To enable this functionality, use a text editor to modify the allow_url_fopen directive in the php.ini file as follows: ', 'an-translate' ) .' allow_url_fopen = on