PageRenderTime 49ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/wp-content/plugins/all-in-one-seo-pack/modules/aioseop_performance.php

https://gitlab.com/vanafroo/voipWEB
PHP | 324 lines | 286 code | 33 blank | 5 comment | 60 complexity | 276541878957d2e2e92fecae102dd0a3 MD5 | raw file
  1. <?php
  2. /**
  3. * The Performance class.
  4. *
  5. * @package All-in-One-SEO-Pack
  6. */
  7. if ( ! class_exists( 'All_in_One_SEO_Pack_Performance' ) ) {
  8. class All_in_One_SEO_Pack_Performance extends All_in_One_SEO_Pack_Module {
  9. protected $module_info = array();
  10. function __construct( $mod ) {
  11. $this->name = __( 'Performance', 'all-in-one-seo-pack' ); // Human-readable name of the plugin.
  12. $this->prefix = 'aiosp_performance_'; // Option prefix.
  13. $this->file = __FILE__; // The current file.
  14. parent::__construct();
  15. $this->help_text = array(
  16. 'memory_limit' => __( 'This setting 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' ),
  17. 'execution_time' => __( 'This setting allows you to raise your PHP execution time to a reasonable value.', 'all-in-one-seo-pack' ),
  18. 'force_rewrites' => __( 'Use output buffering to ensure that the title gets rewritten. Enable this option if you run into issues with the title tag being set by your theme or another plugin.', 'all-in-one-seo-pack' ),
  19. );
  20. $this->default_options = array(
  21. 'memory_limit' => array(
  22. 'name' => __( 'Raise memory limit', 'all-in-one-seo-pack' ),
  23. 'default' => '256M',
  24. 'type' => 'select',
  25. 'initial_options' => array(
  26. 0 => __( 'Use the system default', 'all-in-one-seo-pack' ),
  27. '32M' => '32MB',
  28. '64M' => '64MB',
  29. '128M' => '128MB',
  30. '256M' => '256MB',
  31. ),
  32. ),
  33. 'execution_time' => array(
  34. 'name' => __( 'Raise execution time', 'all-in-one-seo-pack' ),
  35. 'default' => '',
  36. 'type' => 'select',
  37. 'initial_options' => array(
  38. '' => __( 'Use the system default', 'all-in-one-seo-pack' ),
  39. 30 => '30s',
  40. 60 => '1m',
  41. 120 => '2m',
  42. 300 => '5m',
  43. 0 => __( 'No limit', 'all-in-one-seo-pack' ),
  44. ),
  45. ),
  46. );
  47. $this->help_anchors = array(
  48. 'memory_limit' => '#raise-memory-limit',
  49. 'execution_time' => '#raise-execution-time',
  50. 'force_rewrites' => '#force-rewrites',
  51. );
  52. global $aiosp, $aioseop_options;
  53. if ( aioseop_option_isset( 'aiosp_rewrite_titles' ) && $aioseop_options['aiosp_rewrite_titles'] ) {
  54. $this->default_options['force_rewrites'] = array(
  55. 'name' => __( 'Force Rewrites:', 'all-in-one-seo-pack' ),
  56. 'default' => 1,
  57. 'type' => 'radio',
  58. 'initial_options' => array(
  59. 1 => __( 'Enabled', 'all-in-one-seo-pack' ),
  60. 0 => __( 'Disabled', 'all-in-one-seo-pack' ),
  61. ),
  62. );
  63. }
  64. $this->layout = array(
  65. 'default' => array(
  66. 'name' => $this->name,
  67. 'help_link' => 'http://semperplugins.com/documentation/performance-settings/',
  68. 'options' => array_keys( $this->default_options ),
  69. ),
  70. );
  71. $system_status = array(
  72. 'status' => array( 'default' => '', 'type' => 'html', 'label' => 'none', 'save' => false ),
  73. );
  74. $this->layout['system_status'] = array(
  75. 'name' => __( 'System Status', 'all-in-one-seo-pack' ),
  76. 'help_link' => 'http://semperplugins.com/documentation/performance-settings/',
  77. 'options' => array_keys( $system_status ),
  78. );
  79. $this->default_options = array_merge( $this->default_options, $system_status );
  80. $this->add_help_text_links();
  81. add_filter( $this->prefix . 'display_options', array( $this, 'display_options_filter' ), 10, 2 );
  82. add_filter( $this->prefix . 'update_options', array( $this, 'update_options_filter' ), 10, 2 );
  83. add_action( $this->prefix . 'settings_update', array( $this, 'settings_update_action' ), 10, 2 );
  84. }
  85. function update_options_filter( $options, $location ) {
  86. if ( $location == null && isset( $options[ $this->prefix . 'force_rewrites' ] ) ) {
  87. unset( $options[ $this->prefix . 'force_rewrites' ] );
  88. }
  89. return $options;
  90. }
  91. function display_options_filter( $options, $location ) {
  92. if ( $location == null ) {
  93. $options[ $this->prefix . 'force_rewrites' ] = 1;
  94. global $aiosp;
  95. if ( aioseop_option_isset( 'aiosp_rewrite_titles' ) ) {
  96. $opts = $aiosp->get_current_options( array(), null );
  97. $options[ $this->prefix . 'force_rewrites' ] = $opts['aiosp_force_rewrites'];
  98. }
  99. }
  100. return $options;
  101. }
  102. function settings_update_action( $options, $location ) {
  103. if ( $location == null && isset( $_POST[ $this->prefix . 'force_rewrites' ] ) ) {
  104. $force_rewrites = $_POST[ $this->prefix . 'force_rewrites' ];
  105. if ( ( $force_rewrites == 0 ) || ( $force_rewrites == 1 ) ) {
  106. global $aiosp;
  107. $opts = $aiosp->get_current_options( array(), null );
  108. $opts['aiosp_force_rewrites'] = $force_rewrites;
  109. $aiosp->update_class_option( $opts );
  110. wp_cache_flush();
  111. }
  112. }
  113. }
  114. function add_page_hooks() {
  115. $memory_usage = memory_get_peak_usage() / 1024 / 1024;
  116. if ( $memory_usage > 32 ) {
  117. unset( $this->default_options['memory_limit']['initial_options']['32M'] );
  118. if ( $memory_usage > 64 ) {
  119. unset( $this->default_options['memory_limit']['initial_options']['64M'] );
  120. }
  121. if ( $memory_usage > 128 ) {
  122. unset( $this->default_options['memory_limit']['initial_options']['128M'] );
  123. }
  124. if ( $memory_usage > 256 ) {
  125. unset( $this->default_options['memory_limit']['initial_options']['256M'] );
  126. }
  127. }
  128. $this->update_options();
  129. parent::add_page_hooks();
  130. }
  131. function settings_page_init() {
  132. $this->default_options['status']['default'] = $this->get_serverinfo();
  133. }
  134. function menu_order() {
  135. return 7;
  136. }
  137. function get_serverinfo() {
  138. global $wpdb;
  139. global $wp_version;
  140. $sqlversion = $wpdb->get_var( "SELECT VERSION() AS version" );
  141. $mysqlinfo = $wpdb->get_results( "SHOW VARIABLES LIKE 'sql_mode'" );
  142. if ( is_array( $mysqlinfo ) ) {
  143. $sql_mode = $mysqlinfo[0]->Value;
  144. }
  145. if ( empty( $sql_mode ) ) {
  146. $sql_mode = __( 'Not set', 'all-in-one-seo-pack' );
  147. }
  148. if ( ini_get( 'allow_url_fopen' ) ) {
  149. $allow_url_fopen = __( 'On', 'all-in-one-seo-pack' );
  150. } else {
  151. $allow_url_fopen = __( 'Off', 'all-in-one-seo-pack' );
  152. }
  153. if ( ini_get( 'upload_max_filesize' ) ) {
  154. $upload_max = ini_get( 'upload_max_filesize' );
  155. } else {
  156. $upload_max = __( 'N/A', 'all-in-one-seo-pack' );
  157. }
  158. if ( ini_get( 'post_max_size' ) ) {
  159. $post_max = ini_get( 'post_max_size' );
  160. } else {
  161. $post_max = __( 'N/A', 'all-in-one-seo-pack' );
  162. }
  163. if ( ini_get( 'max_execution_time' ) ) {
  164. $max_execute = ini_get( 'max_execution_time' );
  165. } else {
  166. $max_execute = __( 'N/A', 'all-in-one-seo-pack' );
  167. }
  168. if ( ini_get( 'memory_limit' ) ) {
  169. $memory_limit = ini_get( 'memory_limit' );
  170. } else {
  171. $memory_limit = __( 'N/A', 'all-in-one-seo-pack' );
  172. }
  173. if ( function_exists( 'memory_get_usage' ) ) {
  174. $memory_usage = round( memory_get_usage() / 1024 / 1024, 2 ) . __( ' MByte', 'all-in-one-seo-pack' );
  175. } else {
  176. $memory_usage = __( 'N/A', 'all-in-one-seo-pack' );
  177. }
  178. if ( is_callable( 'exif_read_data' ) ) {
  179. $exif = __( 'Yes', 'all-in-one-seo-pack' ) . ' ( V' . $this->substr( phpversion( 'exif' ), 0, 4 ) . ')';
  180. } else {
  181. $exif = __( 'No', 'all-in-one-seo-pack' );
  182. }
  183. if ( is_callable( 'iptcparse' ) ) {
  184. $iptc = __( 'Yes', 'all-in-one-seo-pack' );
  185. } else {
  186. $iptc = __( 'No', 'all-in-one-seo-pack' );
  187. }
  188. if ( is_callable( 'xml_parser_create' ) ) {
  189. $xml = __( 'Yes', 'all-in-one-seo-pack' );
  190. } else {
  191. $xml = __( 'No', 'all-in-one-seo-pack' );
  192. }
  193. $theme = wp_get_theme();
  194. if ( function_exists( 'is_multisite' ) ) {
  195. if ( is_multisite() ) {
  196. $ms = __( 'Yes', 'all-in-one-seo-pack' );
  197. } else {
  198. $ms = __( 'No', 'all-in-one-seo-pack' );
  199. }
  200. } else {
  201. $ms = __( 'N/A', 'all-in-one-seo-pack' );
  202. }
  203. $siteurl = get_option( 'siteurl' );
  204. $homeurl = get_option( 'home' );
  205. $db_version = get_option( 'db_version' );
  206. $debug_info = array(
  207. __( 'Operating System', 'all-in-one-seo-pack' ) => PHP_OS,
  208. __( 'Server', 'all-in-one-seo-pack' ) => $_SERVER['SERVER_SOFTWARE'],
  209. __( 'Memory usage', 'all-in-one-seo-pack' ) => $memory_usage,
  210. __( 'MYSQL Version', 'all-in-one-seo-pack' ) => $sqlversion,
  211. __( 'SQL Mode', 'all-in-one-seo-pack' ) => $sql_mode,
  212. __( 'PHP Version', 'all-in-one-seo-pack' ) => PHP_VERSION,
  213. __( 'PHP Allow URL fopen', 'all-in-one-seo-pack' ) => $allow_url_fopen,
  214. __( 'PHP Memory Limit', 'all-in-one-seo-pack' ) => $memory_limit,
  215. __( 'PHP Max Upload Size', 'all-in-one-seo-pack' ) => $upload_max,
  216. __( 'PHP Max Post Size', 'all-in-one-seo-pack' ) => $post_max,
  217. __( 'PHP Max Script Execute Time', 'all-in-one-seo-pack' ) => $max_execute,
  218. __( 'PHP Exif support', 'all-in-one-seo-pack' ) => $exif,
  219. __( 'PHP IPTC support', 'all-in-one-seo-pack' ) => $iptc,
  220. __( 'PHP XML support', 'all-in-one-seo-pack' ) => $xml,
  221. __( 'Site URL', 'all-in-one-seo-pack' ) => $siteurl,
  222. __( 'Home URL', 'all-in-one-seo-pack' ) => $homeurl,
  223. __( 'WordPress Version', 'all-in-one-seo-pack' ) => $wp_version,
  224. __( 'WordPress DB Version', 'all-in-one-seo-pack' ) => $db_version,
  225. __( 'Multisite', 'all-in-one-seo-pack' ) => $ms,
  226. __( 'Active Theme', 'all-in-one-seo-pack' ) => $theme['Name'] . ' ' . $theme['Version'],
  227. );
  228. $debug_info['Active Plugins'] = null;
  229. $active_plugins = $inactive_plugins = array();
  230. $plugins = get_plugins();
  231. foreach ( $plugins as $path => $plugin ) {
  232. if ( is_plugin_active( $path ) ) {
  233. $debug_info[ $plugin['Name'] ] = $plugin['Version'];
  234. } else {
  235. $inactive_plugins[ $plugin['Name'] ] = $plugin['Version'];
  236. }
  237. }
  238. $debug_info['Inactive Plugins'] = null;
  239. $debug_info = array_merge( $debug_info, (array) $inactive_plugins );
  240. $mail_text = __( 'All in One SEO Pack Pro Debug Info', 'all-in-one-seo-pack' ) . "\r\n------------------\r\n\r\n";
  241. $page_text = '';
  242. if ( ! empty( $debug_info ) ) {
  243. foreach ( $debug_info as $name => $value ) {
  244. if ( $value !== null ) {
  245. $page_text .= "<li><strong>$name</strong> $value</li>";
  246. $mail_text .= "$name: $value\r\n";
  247. } else {
  248. $page_text .= "</ul><h2>$name</h2><ul class='sfwd_debug_settings'>";
  249. $mail_text .= "\r\n$name\r\n----------\r\n";
  250. }
  251. }
  252. }
  253. do {
  254. if ( ! empty( $_REQUEST['sfwd_debug_submit'] ) || ! empty( $_REQUEST['sfwd_update_check'] ) ) {
  255. $nonce = $_REQUEST['sfwd_debug_nonce'];
  256. if ( ! wp_verify_nonce( $nonce, 'sfwd-debug-nonce' ) ) {
  257. echo "<div class='sfwd_debug_error'>" . __( 'Form submission error: verification check failed.', 'all-in-one-seo-pack' ) . '</div>';
  258. break;
  259. }
  260. if ( $_REQUEST['sfwd_update_check'] ) {
  261. global $aioseop_update_checker;
  262. $aioseop_update_checker->checkForUpdates();
  263. echo "<div class='sfwd_debug_mail_sent'>" . sprintf( __( '%s has checked for updates.', 'all-in-one-seo-pack' ), AIOSEOP_PLUGIN_NAME ) . '</div>';
  264. break;
  265. }
  266. $email = '';
  267. if ( ! empty( $_REQUEST['sfwd_debug_send_email'] ) ) {
  268. $email = sanitize_email( $_REQUEST['sfwd_debug_send_email'] );
  269. }
  270. if ( $email ) {
  271. if ( wp_mail( $email, sprintf( __( 'SFWD Debug Mail From Site %s.', 'all-in-one-seo-pack' ), $siteurl ), $mail_text ) ) {
  272. echo "<div class='sfwd_debug_mail_sent'>" . sprintf( __( 'Sent to %s.', 'all-in-one-seo-pack' ), $email ) . '</div>';
  273. } else {
  274. echo "<div class='sfwd_debug_error'>" . sprintf( __( 'Failed to send to %s.', 'all-in-one-seo-pack' ), $email ) . '</div>';
  275. }
  276. } else {
  277. echo "<div class='sfwd_debug_error'>" . __( 'Error: please enter an e-mail address before submitting.', 'all-in-one-seo-pack' ) . '</div>';
  278. }
  279. }
  280. } while ( 0 ); // Control structure for use with break.
  281. $nonce = wp_create_nonce( 'sfwd-debug-nonce' );
  282. $buf = "<ul class='sfwd_debug_settings'>\n{$page_text}\n</ul>\n<p>\n" .
  283. '<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="' .
  284. $nonce . '"><input name="sfwd_debug_submit" type="submit" value="' . __( 'Submit', 'all-in-one-seo-pack' ) . '" class="button-primary">';
  285. if ( AIOSEOPPRO ) {
  286. $buf .= '<p><input name="sfwd_update_check" type="submit" value="' . __( 'Check For Updates', 'all-in-one-seo-pack' ) . '" class="button-primary">';
  287. }
  288. return $buf;
  289. }
  290. }
  291. }