";
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.
';
}
?>