"; file_put_contents( $wprxr_ai_user_settings_path, $settings_code ) or die("Cannot write to user settings php file. Check file permissions."); add_action( 'admin_notices', 'adaptive_images_admin_notice_settings_saved' ); } // Nevma function wprxr_get_config () { return array ( array( "type" => "open"), array( "name" => "Adaptive-images config", "desc" => "Edit config section of adaptive-images.php", "id" => $wprxr_shortname . "_ai_config", "type" => "textarea", "std" => wprxr_get_ai_config(), "handler" => "wprxr_set_ai_config" ), array( "name" => "Watch paths for images", "desc" => "Enter the paths that you want Adaptive-images Images to watch. Put each path on a new line.", "id" => $wprxr_shortname . "_include_paths", "type" => "textarea", "std" => "/wp-content/uploads/"), array( "type" => "close") ); } function wprxr_add_page() { global $wprxr_pluginname, $wprxr_shortname; $pluginname = $wprxr_pluginname; // Nevma // Initiliaze settings here to start with $options = wprxr_get_config(); if ( $_GET['page'] == 'wprxr' ) { if ( 'save' == $_REQUEST['action'] ) { foreach ($options as $value) { if( isset( $_REQUEST[ $value['id'] ] ) ) { // Check if option has custom data handler if( isset( $value['handler'] ) && is_callable( $value['handler'] ) ) { $handler = $value['handler']; $handler( $_REQUEST[ $value['id'] ] ); continue; } // Use update_option if no option handler specified update_option( $value['id'], $_REQUEST[ $value['id'] ] ); } else { delete_option( $value['id'] ); } } } } add_options_page("Adaptive Images", "Adaptive Images", 'manage_options', 'wprxr', 'wprxr_page'); } // Set up the plugin when it is activated function wprxr_activate() { add_option('wprxr_include_paths', '/wp-content/uploads/'); $new_htaccess = wprxr_htaccess(); if ( !file_exists(get_home_path() . '.htaccess') ) { @fopen(get_home_path() . '.htaccess', 'w') or die("
No .htaccess file exists, and one could not be created. To fix this you can:
1. Update permissions for the WordPress root directory to allow write access, or
2. Manually create your .htaccess file with this rewrite block:

$new_htaccess
"); } if ( !is_writable(get_home_path() . '.htaccess') ) { die("
The permissions on your .htaccess file restrict automatic setup. To fix this you can:
1. Change permissions on the .htaccess file in your WordPress root directory to allow write access, or
2. Manually add this rewrite block to your .htaccess file:

$new_htaccess
"); } $old_htaccess = file_get_contents(get_home_path() . '.htaccess'); if ( preg_match('/# Adaptive Images.*# END Adaptive Images\n/s', $old_htaccess) ) { $new_htaccess = preg_replace('/# Adaptive Images.*# END Adaptive Images\n/s', $new_htaccess, $old_htaccess); } else { $new_htaccess .= $old_htaccess; } file_put_contents(get_home_path() . '.htaccess', $new_htaccess) or die("
Could not write to .htaccess.
"); } // Remove the plugin when it is deactivated function wprxr_deactivate() { $old_htaccess = file_get_contents(get_home_path() . '.htaccess'); $new_htaccess = preg_replace('/# Adaptive Images.*# END Adaptive Images\n/s', '', $old_htaccess); file_put_contents(get_home_path() . '.htaccess', $new_htaccess); } // This function returns the .htaccess rewrite block function wprxr_htaccess () { global $wprxr_ai_path; $theme_directory = "/".trim(str_replace(str_replace("\\", "/", $_SERVER["DOCUMENT_ROOT"]), '', str_replace("\\", "/", dirname(__FILE__))), "/"); $wprxr_include_paths = get_option('wprxr_include_paths'); $includes = explode("\n", $wprxr_include_paths); $new_htaccess = "# Adaptive Images\n\nRewriteEngine On\n\n# Watch directories:"; $i = 0; $length = count($includes) - 1; foreach ( $includes as $include ) { if ( $i != $length ) $new_htaccess .= "\nRewriteCond %{REQUEST_URI} " . trim($include) . " [OR]"; else if ( $i == $length ) $new_htaccess .= "\nRewriteCond %{REQUEST_URI} $include"; $i++; } // Nevma // Try to determine the relative path of the adaptive images PHP script which will be set in the htaccess file $DR = $_SERVER['DOCUMENT_ROOT']; $DR = preg_replace( '/\//i', '\/', $DR ); $DR = preg_replace( '/\./i', '\\.', $DR ); $image_handling_script = preg_replace( '/' . $DR . '/i', '', __FILE__ ); $image_handling_script = substr( $image_handling_script, 0, strrpos( $image_handling_script, '/', -3 ) ); $image_handling_script .= '/adaptive-images/ai-main.php'; $new_htaccess .= "\n\nRewriteRule \.(?:jpe?g|gif|png)$ " . $image_handling_script . " [L]\n\n# END Adaptive Images\n"; return $new_htaccess; } // The Adaptive Images settings page function wprxr_page() { global $wprxr_pluginname, $wprxr_shortname; $pluginname = $wprxr_pluginname; $options = wprxr_get_config(); $new_htaccess = wprxr_htaccess(); ?>

settings

Adaptive Images updated successfully.

'; } ?>

Image cache configuration

'; break; case "close": echo ''; break; case "title": echo ''; echo ''; echo ''; break; case 'text': $value_or_std = ( get_option( $value['id'] ) != "" ) ? get_option( $value['id'] ) : $value['std']; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; break; case 'textarea': $value_or_std = ( get_option( $value['id'] ) != "" ) ? get_option( $value['id'] ) : $value['std']; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; break; case 'select': echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; break; case "checkbox": $cheked = ( get_option($value['id'])) ? ' checked="checked"' : ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; break; } } ?>

Cleanup image cache

Deletes all files from the image cache directories in order to start the cache fresh and clean. Might take a few moments, if your server is up to it, so be patient. Run multiples times in case of browser timeout, eventually all image cache files will be deleted.

Cache size: ( files)

Cleanup image cache

$total_files, 'size' => $total_size ); } /** * Deletes the contents of a directory recursively. * * Takes the path of a directory as an argument and traverses it recursively deleting its child files and directories * recursively as well. * * @author Nevma * * @param $dir The directory whose contents to delete recursively. * * @return An array with the totals of directories and files deleted so far. */ function adaptive_images_rmdir_recursive ( $dir ) { static $total_files = 0; static $total_dirs = 0; if ( is_dir( $dir ) && ! is_link( $dir ) ) { $objects = scandir( $dir ); foreach ( $objects as $object ) { if ( $object != "." && $object != ".." ) { $file = $dir . "/" . $object; if ( filetype( $file ) == "dir" ) { adaptive_images_rmdir_recursive( $file ); $total_dirs++; } else { unlink( $file ); $total_files++; } } } reset( $objects ); rmdir( $dir ); } return array( 'files' => $total_files, 'dirs' => $total_dirs ); } /** * Adaptive images settings successfully saved. * * Prints an admin notice message in the settings page that informs the user of the outcome of the settings saving * action was successfull. * * @author Nevma * * @return Nothing really! */ function adaptive_images_admin_notice_settings_saved () { ?>

Adaptive images settings have been successfully saved!

The image cache has been successfully cleaned up!
We have deleted directories and image files in total.

'.__("Settings", "Adaptive Images").''; array_unshift($links, $settings_link); } return $links; } // Sets up the cookie generating Javascript in the head of the page. add_action( 'wp_head', 'adaptive_images_head_cookie_javascript', 0 ); // Sets up the adaptive images image cache cleanup action. add_action( 'admin_init', 'adaptive_images_cleanup_image_cache' ); add_action('admin_menu', 'wprxr_add_page'); register_activation_hook(__FILE__, 'wprxr_activate'); register_deactivation_hook(__FILE__, 'wprxr_deactivate'); add_filter('plugin_action_links', 'wprxr_add_settings_link', 10, 2 ); ?>

' . $value['name'] . '

' . $value['name'] . '
' . $value['desc'] . '
 
 
' . $value['name'] . '
' . $value['desc'] . '
 
 
' . $value['name'] . '
' . $value['desc'] . '
 
 
' . $value['name'] . ''; echo ''; echo '
' . $value['desc'] . '