id == 'settings_page_adaptive-images'; } /** * Returns the adaptive images default user settings as an associative array. * * @author Nevma (info@nevma.gr) * * @return array The associative array with the default user settings! */ function adaptive_images_plugin_get_default_settings () { return array( 'resolutions' => array( 1024, 640, 480 ), 'landscape' => FALSE, 'hidpi' => FALSE, 'cdn-support' => FALSE, 'cache-directory' => 'cache/adaptive-images', 'watched-directories' => array( 'wp-content/uploads', 'wp-content/themes' ), 'content-types' => array( 'jpg', 'jpeg', 'png' ), 'jpeg-quality' => 75, 'sharpen-images' => TRUE, 'watch-cache' => TRUE, 'browser-cache' => 180 ); } /** * Checks if the given option is not set and, if not, returns its default value. It does not check for the validity * of the option value. * * @author Nevma (info@nevma.gr) * * @param array $options The associative array that holds the given options, which should be passed by reference * so it can be directly altered as necessary. * * @param string $key The name of the option to check if is set. * * @return mixed The current value of the option if it is set or its default value if it is not set. */ function adaptive_images_plugin_check_empty_setting ( &$options, $key ) { if ( ! isset( $options[$key] ) ) { $defaults = adaptive_images_plugin_get_default_settings(); $options[$key] = $defaults[$key]; } } /** * Returns the name of the plugin for usage in activations hooks and so on. * * @author Nevma (info@nevma.gr) * * @return string The name of the plugin which is the directory slash the main PHP file. */ function adaptive_images_plugin_get_name () { return dirname( plugin_basename( __FILE__ ) ) . '/adaptive-images.php'; } /** * Returns the full path to the plugin main PHP file. * * @author Nevma (info@nevma.gr) * * @return string The full path to the plugin the main PHP file. */ function adaptive_images_plugin_get_path () { return dirname( __FILE__ ) . '/adaptive-images.php'; } /** * Returns the url to the plugin directory. * * @author Nevma (info@nevma.gr) * * @return string The url to the plugin directory. */ function adaptive_images_plugin_get_url () { return plugin_dir_url( dirname( __FILE__ ) . '/adaptive-images.php' ); } /** * Returns the full path to the plugin main PHP file. * * @author Nevma (info@nevma.gr) * * @return string The full path to the plugin the main PHP file. */ function adaptive_images_plugin_get_version () { $plugin_data = get_plugin_data( adaptive_images_plugin_get_path() ); return $plugin_data['Version']; } /** * Returns the path to the user settings PHP file. * * @author Nevma (info@nevma.gr) * * @return string The path to the user settings PHP file! */ function adaptive_images_plugin_get_cache_directory_path () { $options = adaptive_images_plugin_get_options(); return ( $options && $options['cache-directory'] ) ? trailingslashit( WP_CONTENT_DIR ) . $options['cache-directory'] : '-'; } /** * Returns the plugin options array from the database. * * @author Nevma (info@nevma.gr) * * @return array|boolean The plugin options form the database. */ function adaptive_images_plugin_get_options () { return get_option( 'adaptive-images' ); } /** * Returns the path to the installation htaccess file. * * @author Nevma (info@nevma.gr) * * @return string The path to the installation htaccess file! */ function adaptive_images_plugin_get_htaccess_file_path () { return get_home_path() . '.htaccess'; } /** * Returns the path to the user settings PHP file. * * @author Nevma (info@nevma.gr) * * @return string The path to the user settings PHP file! */ function adaptive_images_plugin_get_user_settings_file_path () { return plugin_dir_path( __FILE__ ) . 'user-settings.php'; } /** * Checks whether a given path is inside the WordPress installation. * * @author Nevma (info@nevma.gr) * * @return boolean Whether the given path is inside the Wordpress isntallation. */ function adaptive_images_plugin_is_file_in_wp ( $path ) { $home_path = get_home_path(); return strpos( trailingslashit( $path ), $home_path ) !== 0 && $path != $home_path; } /** * Checks whether a given path is inside the WordPress /wp-content directory. * * @author Nevma (info@nevma.gr) * * @return boolean Whether the given path is inside /wp-content. */ function adaptive_images_plugin_is_file_in_wp_content ( $path ) { if ( ! $path || $path == '' || $path == '.' || $path == '..' ) { return FALSE; } $wp_content = trailingslashit( WP_CONTENT_DIR ); return strpos( trailingslashit( $path ), $wp_content ) !== 0 && $path != $wp_content; } /** * Returns a human readable string for the permissions of a given file. * * @author Nevma (info@nevma.gr) * * @param string $file The file whose permissions we are checking; * * @return string The file permissions in the usual UNIX format (like -rwxr--r--). */ function adaptive_images_plugin_file_permissions ( $file ) { if ( ! file_exists( $file ) ) { return ''; } // Get file permissions number. $permissions = fileperms( $file ); // Analyze the file permissions number. if ( ( $permissions & 0xC000 ) == 0xC000 ) { $info = 's'; // Socket. } elseif ( ( $permissions & 0xA000 ) == 0xA000 ) { $info = 'l'; // Symbolic Link. } elseif ( ( $permissions & 0x8000 ) == 0x8000 ) { $info = '-'; // Regular } elseif ( ( $permissions & 0x6000 ) == 0x6000 ) { $info = 'b'; // Block special. } elseif ( ( $permissions & 0x4000 ) == 0x4000 ) { $info = 'd'; // Directory. } elseif ( ( $permissions & 0x2000 ) == 0x2000 ) { $info = 'c'; // Character special. } elseif ( ( $permissions & 0x1000 ) == 0x1000 ) { $info = 'p'; // FIFO pipe. } else { $info = 'u'; // Unknown. } // User part. $info .= ( ( $permissions & 0x0100 ) ? 'r' : '-' ); $info .= ( ( $permissions & 0x0080 ) ? 'w' : '-' ); $info .= ( ( $permissions & 0x0040 ) ? ( ( $permissions & 0x0800 ) ? 's' : 'x' ) : ( ( $permissions & 0x0800 ) ? 'S' : '-' ) ); // Group part. $info .= ( ( $permissions & 0x0020 ) ? 'r' : '-' ); $info .= ( ( $permissions & 0x0010 ) ? 'w' : '-' ); $info .= ( ( $permissions & 0x0008) ? ( ( $permissions & 0x0400 ) ? 's' : 'x' ) : ( ( $permissions & 0x0400 ) ? 'S' : '-' ) ); // Other part. $info .= ( ( $permissions & 0x0004) ? 'r' : '-' ); $info .= ( ( $permissions & 0x0002) ? 'w' : '-' ); $info .= ( ( $permissions & 0x0001) ? ( ( $permissions & 0x0200 ) ? 't' : 'x' ) : ( ( $permissions & 0x0200 ) ? 'T' : '-' ) ); return $info; } /** * Calculates the contents of a directory recursively. Warning: this might be a long process. * * @author Nevma (info@nevma.gr) * * @param string $dir The directory whose contents to calculate recursively. * * @return int The total size of the directory and its children recursively in bytes. */ function adaptive_images_plugin_dir_size ( $dir ) { // // USE BASH COMMANDS TEST // // var_dump( $dir ); // echo '