PageRenderTime 102ms CodeModel.GetById 37ms RepoModel.GetById 1ms app.codeStats 0ms

/plugins/all-in-one-seo-pack/aioseop_performance.php

https://bitbucket.org/iwtechru/rivoinvest.com
PHP | 242 lines | 212 code | 24 blank | 6 comment | 59 complexity | 40c576d0b3bb6309315095a99b6811cd MD5 | raw file
  1. <?php
  2. /**
  3. * @package All-in-One-SEO-Pack
  4. */
  5. /**
  6. * The Performance class.
  7. */
  8. if ( !class_exists( 'All_in_One_SEO_Pack_Performance' ) ) {
  9. class All_in_One_SEO_Pack_Performance extends All_in_One_SEO_Pack_Module {
  10. protected $module_info = Array( );
  11. function All_in_One_SEO_Pack_Performance( $mod ) {
  12. $this->name = __('Performance', 'all_in_one_seo_pack'); // Human-readable name of the plugin
  13. $this->prefix = 'aiosp_performance_'; // option prefix
  14. $this->file = __FILE__; // the current file
  15. parent::__construct();
  16. $this->default_options = array(
  17. 'memory_limit' => Array( 'name' => __( 'Raise memory limit', 'all_in_one_seo_pack' ),
  18. 'help_text' => __( 'Allows you to raise your PHP memory limit to a reasonable value. Note: WordPress core and other WordPress plugins may also change the value of the memory limit.', 'all_in_one_seo_pack' ),
  19. 'default' => '256M',
  20. 'type' => 'select',
  21. 'initial_options' => Array( 0 => __( "Use the system default", 'all_in_one_seo_pack' ), '32M' => '32MB', '64M' => '64MB', '128M' => '128MB', '256M' => '256MB' ) ),
  22. 'execution_time' => Array( 'name' => __( 'Raise execution time', 'all_in_one_seo_pack' ),
  23. 'help_text' => __( 'Allows you to raise your PHP execution time to a reasonable value.', 'all_in_one_seo_pack' ),
  24. 'default' => '',
  25. 'type' => 'select',
  26. 'initial_options' => Array( '' => __( "Use the system default", 'all_in_one_seo_pack' ), 30 => '30s', 60 => '1m', 120 => '2m', 300 => '5m', 0 => __( 'No limit', 'all_in_one_seo_pack' ) ) )
  27. );
  28. global $aiosp, $aioseop_options;
  29. if ( aioseop_option_isset( 'aiosp_rewrite_titles' ) && $aioseop_options['aiosp_rewrite_titles'] ) {
  30. $this->default_options['force_rewrites'] = Array(
  31. 'name' => __( 'Force Rewrites:', 'all_in_one_seo_pack' ),
  32. 'help_text' => __( "Use output buffering to ensure that the title gets rewritten.", 'all_in_one_seo_pack' ),
  33. 'default' => 1,
  34. 'type' => 'radio',
  35. 'initial_options' => Array( 1 => __( 'Enabled', 'all_in_one_seo_pack' ),
  36. 0 => __( 'Disabled', 'all_in_one_seo_pack' ) )
  37. );
  38. }
  39. $this->layout = Array(
  40. 'default' => Array(
  41. 'name' => $this->name,
  42. 'options' => array_keys( $this->default_options )
  43. )
  44. );
  45. $system_status = Array(
  46. 'status' => Array( 'default' => '', 'type' => 'html', 'label' => 'none', 'save' => false ),
  47. );
  48. $this->layout['system_status'] = Array(
  49. 'name' => __( 'System Status', 'all_in_one_seo_pack' ),
  50. 'options' => array_keys( $system_status )
  51. );
  52. $this->default_options = array_merge( $this->default_options, $system_status );
  53. add_filter( $this->prefix . 'display_options', Array( $this, 'display_options_filter' ), 10, 2 );
  54. add_filter( $this->prefix . 'update_options', Array( $this, 'update_options_filter' ), 10, 2 );
  55. add_action( $this->prefix . 'settings_update', Array( $this, 'settings_update_action' ), 10, 2 );
  56. }
  57. function update_options_filter( $options, $location ) {
  58. if ( $location == null ) {
  59. if ( isset( $options[ $this->prefix . 'force_rewrites' ] ) )
  60. unset( $options[ $this->prefix . 'force_rewrites' ] );
  61. }
  62. return $options;
  63. }
  64. function display_options_filter( $options, $location ) {
  65. if ( $location == null ) {
  66. $options[ $this->prefix . 'force_rewrites' ] = 1;
  67. global $aiosp;
  68. if ( aioseop_option_isset( 'aiosp_rewrite_titles' ) ) {
  69. $opts = $aiosp->get_current_options( Array(), null );
  70. $options[ $this->prefix . 'force_rewrites' ] = $opts['aiosp_force_rewrites'];
  71. }
  72. }
  73. return $options;
  74. }
  75. function settings_update_action( $options, $location ) {
  76. if ( $location == null ) {
  77. if ( isset( $_POST[ $this->prefix . 'force_rewrites' ] ) ) {
  78. $force_rewrites = $_POST[ $this->prefix . 'force_rewrites' ];
  79. if ( ( $force_rewrites == 0 ) || ( $force_rewrites == 1 ) ) {
  80. global $aiosp;
  81. $opts = $aiosp->get_current_options( Array(), null );
  82. $opts['aiosp_force_rewrites'] = $force_rewrites;
  83. $aiosp->update_class_option( $opts );
  84. wp_cache_flush();
  85. }
  86. }
  87. }
  88. }
  89. function add_page_hooks() {
  90. $memory_usage = memory_get_peak_usage() / 1024 / 1024;
  91. if ( $memory_usage > 32 ) {
  92. unset( $this->default_options['memory_limit']['initial_options']['32M'] );
  93. if ( $memory_usage > 64 ) unset( $this->default_options['memory_limit']['initial_options']['64M'] );
  94. if ( $memory_usage > 128 ) unset( $this->default_options['memory_limit']['initial_options']['128M'] );
  95. if ( $memory_usage > 256 ) unset( $this->default_options['memory_limit']['initial_options']['256M'] );
  96. }
  97. $this->update_options();
  98. parent::add_page_hooks();
  99. }
  100. function settings_page_init() {
  101. $this->default_options['status']['default'] = $this->get_serverinfo();
  102. }
  103. function menu_order() {
  104. return 7;
  105. }
  106. function get_serverinfo() {
  107. global $wpdb;
  108. global $wp_version;
  109. $sqlversion = $wpdb->get_var("SELECT VERSION() AS version");
  110. $mysqlinfo = $wpdb->get_results("SHOW VARIABLES LIKE 'sql_mode'");
  111. if (is_array($mysqlinfo)) $sql_mode = $mysqlinfo[0]->Value;
  112. if (empty($sql_mode)) $sql_mode = __('Not set', 'all_in_one_seo_pack' );
  113. if(ini_get('safe_mode')) $safe_mode = __('On', 'all_in_one_seo_pack' );
  114. else $safe_mode = __('Off', 'all_in_one_seo_pack' );
  115. if(ini_get('allow_url_fopen')) $allow_url_fopen = __('On', 'all_in_one_seo_pack' );
  116. else $allow_url_fopen = __('Off', 'all_in_one_seo_pack' );
  117. if(ini_get('upload_max_filesize')) $upload_max = ini_get('upload_max_filesize');
  118. else $upload_max = __('N/A', 'all_in_one_seo_pack' );
  119. if(ini_get('post_max_size')) $post_max = ini_get('post_max_size');
  120. else $post_max = __('N/A', 'all_in_one_seo_pack' );
  121. if(ini_get('max_execution_time')) $max_execute = ini_get('max_execution_time');
  122. else $max_execute = __('N/A', 'all_in_one_seo_pack' );
  123. if(ini_get('memory_limit')) $memory_limit = ini_get('memory_limit');
  124. else $memory_limit = __('N/A', 'all_in_one_seo_pack' );
  125. if (function_exists('memory_get_usage')) $memory_usage = round(memory_get_usage() / 1024 / 1024, 2) . __(' MByte', 'all_in_one_seo_pack' );
  126. else $memory_usage = __('N/A', 'all_in_one_seo_pack' );
  127. if (is_callable('exif_read_data')) $exif = __('Yes', 'all_in_one_seo_pack' ). " ( V" . substr(phpversion('exif'),0,4) . ")" ;
  128. else $exif = __('No', 'all_in_one_seo_pack' );
  129. if (is_callable('iptcparse')) $iptc = __('Yes', 'all_in_one_seo_pack' );
  130. else $iptc = __('No', 'all_in_one_seo_pack' );
  131. if (is_callable('xml_parser_create')) $xml = __('Yes', 'all_in_one_seo_pack' );
  132. else $xml = __('No', 'all_in_one_seo_pack' );
  133. if ( function_exists( 'wp_get_theme' ) ) {
  134. $theme = wp_get_theme();
  135. } else {
  136. $theme = get_theme( get_current_theme() );
  137. }
  138. if ( function_exists( 'is_multisite' ) ) {
  139. if ( is_multisite() ) {
  140. $ms = __('Yes', 'all_in_one_seo_pack' );
  141. } else {
  142. $ms = __('No', 'all_in_one_seo_pack' );
  143. }
  144. } else $ms = __('N/A', 'all_in_one_seo_pack' );
  145. $siteurl = get_option('siteurl');
  146. $homeurl = get_option('home');
  147. $db_version = get_option('db_version');
  148. $debug_info = Array(
  149. __('Operating System', 'all_in_one_seo_pack' ) => PHP_OS,
  150. __('Server', 'all_in_one_seo_pack' ) => $_SERVER["SERVER_SOFTWARE"],
  151. __('Memory usage', 'all_in_one_seo_pack' ) => $memory_usage,
  152. __('MYSQL Version', 'all_in_one_seo_pack' ) => $sqlversion,
  153. __('SQL Mode', 'all_in_one_seo_pack' ) => $sql_mode,
  154. __('PHP Version', 'all_in_one_seo_pack' ) => PHP_VERSION,
  155. __('PHP Safe Mode', 'all_in_one_seo_pack' ) => $safe_mode,
  156. __('PHP Allow URL fopen', 'all_in_one_seo_pack' ) => $allow_url_fopen,
  157. __('PHP Memory Limit', 'all_in_one_seo_pack' ) => $memory_limit,
  158. __('PHP Max Upload Size', 'all_in_one_seo_pack' ) => $upload_max,
  159. __('PHP Max Post Size', 'all_in_one_seo_pack' ) => $post_max,
  160. __('PHP Max Script Execute Time', 'all_in_one_seo_pack' ) => $max_execute,
  161. __('PHP Exif support', 'all_in_one_seo_pack' ) => $exif,
  162. __('PHP IPTC support', 'all_in_one_seo_pack' ) => $iptc,
  163. __('PHP XML support', 'all_in_one_seo_pack' ) => $xml,
  164. __('Site URL', 'all_in_one_seo_pack' ) => $siteurl,
  165. __('Home URL', 'all_in_one_seo_pack' ) => $homeurl,
  166. __('WordPress Version', 'all_in_one_seo_pack' ) => $wp_version,
  167. __('WordPress DB Version', 'all_in_one_seo_pack' ) => $db_version,
  168. __('Multisite', 'all_in_one_seo_pack' ) => $ms,
  169. __('Active Theme', 'all_in_one_seo_pack' ) => $theme['Name'].' '.$theme['Version']
  170. );
  171. $debug_info['Active Plugins'] = null;
  172. $active_plugins = $inactive_plugins = Array();
  173. $plugins = get_plugins();
  174. foreach ($plugins as $path => $plugin) {
  175. if ( is_plugin_active( $path ) ) {
  176. $debug_info[$plugin['Name']] = $plugin['Version'];
  177. } else {
  178. $inactive_plugins[$plugin['Name']] = $plugin['Version'];
  179. }
  180. }
  181. $debug_info['Inactive Plugins'] = null;
  182. $debug_info = array_merge( $debug_info, (array)$inactive_plugins );
  183. $mail_text = __( "All in One SEO Pack Pro Debug Info", 'all_in_one_seo_pack' ) . "\r\n------------------\r\n\r\n";
  184. $page_text = "";
  185. if ( !empty( $debug_info ) )
  186. foreach($debug_info as $name => $value) {
  187. if ($value !== null) {
  188. $page_text .= "<li><strong>$name</strong> $value</li>";
  189. $mail_text .= "$name: $value\r\n";
  190. } else {
  191. $page_text .= "</ul><h2>$name</h2><ul class='sfwd_debug_settings'>";
  192. $mail_text .= "\r\n$name\r\n----------\r\n";
  193. }
  194. }
  195. do if ( !empty( $_REQUEST['sfwd_debug_submit'] ) ) {
  196. $nonce=$_REQUEST['sfwd_debug_nonce'];
  197. if (! wp_verify_nonce($nonce, 'sfwd-debug-nonce') ) {
  198. echo "<div class='sfwd_debug_error'>" . __( "Form submission error: verification check failed.", 'all_in_one_seo_pack' ) . "</div>";
  199. break;
  200. }
  201. if ($_REQUEST['sfwd_debug_send_email']) {
  202. if (wp_mail($_REQUEST['sfwd_debug_send_email'], sprintf( __( "SFWD Debug Mail From Site %s.", 'all_in_one_seo_pack'), $siteurl), $mail_text ) ) {
  203. echo "<div class='sfwd_debug_mail_sent'>" . sprintf( __( "Sent to %s.", 'all_in_one_seo_pack' ), $_REQUEST['sfwd_debug_send_email'] ) . "</div>";
  204. } else {
  205. echo "<div class='sfwd_debug_error'>" . sprintf( __( "Failed to send to %s.", 'all_in_one_seo_pack' ), $_REQUEST['sfwd_debug_send_email'] ) . "</div>";
  206. }
  207. } else {
  208. echo "<div class='sfwd_debug_error'>" . __( 'Error: please enter an e-mail address before submitting.', 'all_in_one_seo_pack' ) . "</div>";
  209. }
  210. } while(0); // control structure for use with break
  211. $nonce = wp_create_nonce('sfwd-debug-nonce');
  212. $buf = "<ul class='sfwd_debug_settings'>\n{$page_text}\n</ul>\n<p>\n" .
  213. '<input name="sfwd_debug_send_email" type="text" value="" placeholder="' . __( "E-mail debug information", 'all_in_one_seo_pack' ) . '"><input name="sfwd_debug_nonce" type="hidden" value="' .
  214. $nonce . '"><input name="sfwd_debug_submit" type="submit" value="' . __( 'Submit', 'all_in_one_seo_pack' ) . '" class="button-primary"><p>';
  215. return $buf;
  216. }
  217. }
  218. }