/** * Prints useful debug information for the plugin. * * @author Nevma (info@nevma.gr) * * @param bool $echo Whether to echo the result or return it as a string. * * @return Nothing really! */ function adaptive_images_debug_general_info($echo = true) { $options = get_option('adaptive-images'); $icons = array('true' => '✔', 'false' => '✖', 'debug' => '❖'); // PHP GD image library debug info. $gd_extenstion_installed = adaptive_images_plugin_is_gd_extension_installed(); $message = '<p>' . ($gd_extenstion_installed ? $icons['true'] : $icons['false']) . ' PHP GD library is ' . ($gd_extenstion_installed ? '' : 'not ') . ' installed.' . '</p>'; // Image cache directory debug info. $cache_path = adaptive_images_plugin_get_cahe_directory_path(); $cache_path_exists = file_exists($cache_path); $message .= '<p>' . ($cache_path_exists ? $icons['true'] : $icons['false']) . ' Image cache directory has ' . ($cache_path_exists ? '' : 'not ') . 'been created.' . '</p>' . ($cache_path_exists ? '<blockquote><p>' . '<code>' . $cache_path . ' => ' . adaptive_images_plugin_file_permissions($cache_path) . '</code>' . '</p></blockquote>' : '<blockquote><p>' . (!$cache_path_exists && is_writable(dirname($cache_path)) ? 'But this is probably because the cache has not been accessed yet. <br />' . 'After accessing your website from a mobile device the directory should be automatically created.' . '<br /><br />' : 'It seems that the directory is not writeable. This is probably a filesystem permissions issue. <br />' . ' Consider adding manually the image cache directory: "/wp-content/cache/adaptive-images".' . '<br /><br />') . '<code>' . dirname($cache_path) . ' => ' . adaptive_images_plugin_file_permissions(dirname($cache_path)) . '</code>' . '</p></blockquote>'); // Check .htaccess file availability $htaccess = adaptive_images_plugin_get_htaccess_file_path(); $htaccess_ok = adaptive_images_actions_is_htaccess_ok(); $htaccess_writeable = adaptive_images_plugin_is_htaccess_writeable(); $message .= '<p>' . ($htaccess_ok ? $icons['true'] : $icons['false']) . ' Installation .htaccess file is ' . ($htaccess_ok ? 'setup OK.' : 'not properly setup.') . '</p>' . ($htaccess_writeable ? '<blockquote><p>' . '<code>' . $htaccess . ' => ' . adaptive_images_plugin_file_permissions($htaccess) . '</code>' . '</p></blockquote>' : '<blockquote><p>' . 'The .htaccess file is not writeable so it might have not been updated.' . '<br /><br />' . '<code>' . $htaccess . ' => ' . adaptive_images_plugin_file_permissions($htaccess) . '</code>' . '</p></blockquote>'); // Image cache settings dump. $message .= '<p>' . $icons['debug'] . ' Adaptive images settings dump:</p>'; $message .= '<blockquote><pre>'; ob_start(); var_dump($options); $message .= ob_get_clean(); $message .= '</pre></blockquote>'; // Echo debug info or return it. if ($echo) { echo $message; } else { return $message; } }
/** * Performs actions related to upgrading from version 0.2.08 because from that version and on major code and * settings changes took place. * * @author Nevma (info@nevma.gr) * * @return void */ function adaptive_images_upgrade_action_upgraded_from_v0208() { // Try to remove old htaccess entry. $htaccess = adaptive_images_plugin_get_htaccess_file_path(); $htaccess_available = adaptive_images_plugin_is_htaccess_writeable(); if ($htaccess_available) { $htaccess_old_contents = file_get_contents($htaccess); $htaccess_new_contents = preg_replace('/# Adaptive Images.*# END Adaptive Images\\n/s', '', $htaccess_old_contents); @file_put_contents($htaccess, $htaccess_new_contents); } // Try to remove old cache directory. $old_cache_path = realpath(dirname($_SERVER['SCRIPT_FILENAME']) . '/../wp-content/') . '/cache-ai/'; adaptive_images_actions_rmdir_recursive($old_cache_path); // Try to remove old options. delete_option('wprxr_include_paths'); delete_option('wprxr_ai_config'); }
/** * Returns whether the installation .htaccess file is available, writeable and that it has been updated with the * contents that are necessary for the plugin to work. * * @author Nevma (info@nevma.gr) * * @return void Nothing really! */ function adaptive_images_actions_is_htaccess_ok() { // If options have not been saved yet then do not check. $options = get_option('adaptive-images'); if (!$options) { return false; } // Do the check and inform user. $htaccess = adaptive_images_plugin_get_htaccess_file_path(); $htaccess_writeable = adaptive_images_plugin_is_htaccess_writeable(); $htaccess_contents = file_get_contents($htaccess); $htaccess_rewrite_block_regexp = '/# BEGIN Adaptive Images.*# END Adaptive Images\\n/s'; $htaccess_contents_updated = preg_match($htaccess_rewrite_block_regexp, $htaccess_contents); return $htaccess_writeable && $htaccess_contents_updated; }