mirror of
https://github.com/mainwp/mainwp-child.git
synced 2025-09-07 11:16:40 +08:00
* Added new hooks for upcoming extensions
This commit is contained in:
parent
81912bd188
commit
5058a06794
5 changed files with 354 additions and 34 deletions
|
@ -55,7 +55,8 @@ class MainWPChild
|
|||
'uploader_action' => 'uploader_action',
|
||||
'wordpress_seo' => 'wordpress_seo',
|
||||
'client_report' => 'client_report',
|
||||
'createBackupPoll' => 'backupPoll'
|
||||
'createBackupPoll' => 'backupPoll',
|
||||
'page_speed' => 'page_speed'
|
||||
);
|
||||
|
||||
private $FTP_ERROR = 'Failed, please add FTP details for automatic upgrades.';
|
||||
|
@ -628,6 +629,7 @@ class MainWPChild
|
|||
// Branding extension
|
||||
MainWPChildBranding::Instance()->branding_init();
|
||||
MainWPClientReport::Instance()->creport_init();
|
||||
MainWPChildPagespeed::Instance()->init();
|
||||
}
|
||||
|
||||
function default_option_active_plugins($default)
|
||||
|
@ -3531,6 +3533,10 @@ class MainWPChild
|
|||
MainWPClientReport::Instance()->action();
|
||||
}
|
||||
|
||||
function page_speed() {
|
||||
MainWPChildPagespeed::Instance()->action();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
309
class/MainWPChildPagespeed.class.php
Normal file
309
class/MainWPChildPagespeed.class.php
Normal file
|
@ -0,0 +1,309 @@
|
|||
<?php
|
||||
|
||||
class MainWPChildPagespeed
|
||||
{
|
||||
|
||||
public static $instance = null;
|
||||
|
||||
static function Instance() {
|
||||
if (MainWPChildPagespeed::$instance == null) {
|
||||
MainWPChildPagespeed::$instance = new MainWPChildPagespeed();
|
||||
}
|
||||
return MainWPChildPagespeed::$instance;
|
||||
}
|
||||
|
||||
public function __construct() {
|
||||
|
||||
}
|
||||
|
||||
public function action() {
|
||||
$information = array();
|
||||
if (!defined('GPI_ACTIVE')) {
|
||||
$information['error'] = 'NO_GOOGLEPAGESPEED';
|
||||
MainWPHelper::write($information);
|
||||
}
|
||||
if (isset($_POST['mwp_action'])) {
|
||||
switch ($_POST['mwp_action']) {
|
||||
case "save_settings":
|
||||
$information = $this->save_settings();
|
||||
break;
|
||||
case "set_showhide":
|
||||
$information = $this->set_showhide();
|
||||
break;
|
||||
case "sync_data":
|
||||
$information = $this->sync_data();
|
||||
break;
|
||||
}
|
||||
}
|
||||
MainWPHelper::write($information);
|
||||
}
|
||||
|
||||
public function init()
|
||||
{
|
||||
if (get_option('mainwp_pagespeed_ext_enabled') !== "Y")
|
||||
return;
|
||||
|
||||
if (get_option('mainwp_pagespeed_hide_plugin') === "hide")
|
||||
{
|
||||
add_filter('all_plugins', array($this, 'hide_plugin'));
|
||||
//add_action('admin_menu', array($this, 'hide_menu'), 999);
|
||||
add_filter('update_footer', array(&$this, 'update_footer'), 15);
|
||||
}
|
||||
}
|
||||
|
||||
public function hide_plugin($plugins) {
|
||||
foreach ($plugins as $key => $value)
|
||||
{
|
||||
$plugin_slug = basename($key, '.php');
|
||||
if ($plugin_slug == 'google-pagespeed-insights')
|
||||
unset($plugins[$key]);
|
||||
}
|
||||
return $plugins;
|
||||
}
|
||||
|
||||
// public function hide_menu() {
|
||||
// global $submenu;
|
||||
// if (isset($submenu['tools.php'])) {
|
||||
// foreach($submenu['tools.php'] as $key => $menu) {
|
||||
// if ($menu[2] == 'google-pagespeed-insights') {
|
||||
// unset($submenu['tools.php'][$key]);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
function update_footer($text){
|
||||
?>
|
||||
<script>
|
||||
jQuery(document).ready(function(){
|
||||
jQuery('#menu-tools a[href="tools.php?page=google-pagespeed-insights"]').closest('li').remove();
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
return $text;
|
||||
}
|
||||
|
||||
|
||||
function set_showhide() {
|
||||
MainWPHelper::update_option('mainwp_pagespeed_ext_enabled', "Y");
|
||||
$hide = isset($_POST['showhide']) && ($_POST['showhide'] === "hide") ? 'hide' : "";
|
||||
MainWPHelper::update_option('mainwp_pagespeed_hide_plugin', $hide);
|
||||
$information['result'] = 'SUCCESS';
|
||||
return $information;
|
||||
}
|
||||
|
||||
function save_settings() {
|
||||
MainWPHelper::update_option('mainwp_pagespeed_ext_enabled', "Y");
|
||||
$current_values = get_option('gpagespeedi_options');
|
||||
if (is_array($current_values) && $current_values['last_run_finished'] == false)
|
||||
return array('result' => 'RUNNING');
|
||||
|
||||
$settings = $_POST['settings'];
|
||||
$settings = unserialize(base64_decode($settings));
|
||||
|
||||
if (is_array($settings)) {
|
||||
|
||||
if (isset($settings['api_key']) && !empty($settings['api_key']))
|
||||
$current_values['google_developer_key'] = $settings['api_key'];
|
||||
|
||||
if (isset($settings['response_language']))
|
||||
$current_values['response_language'] = $settings['response_language'];
|
||||
|
||||
if (isset($_POST['strategy']))
|
||||
$current_values['strategy'] = $_POST['strategy'];
|
||||
|
||||
if (isset($settings['max_execution_time']))
|
||||
$current_values['max_execution_time'] = $settings['max_execution_time'];
|
||||
|
||||
if (isset($settings['delay_time']))
|
||||
$current_values['sleep_time'] = $settings['delay_time'];
|
||||
|
||||
if (isset($settings['log_exception']))
|
||||
$current_values['log_api_errors'] = ($settings['log_exception']) ? true : false;
|
||||
|
||||
if (isset($settings['scan_technical']))
|
||||
$current_values['scan_method'] = $settings['scan_technical'];
|
||||
|
||||
if (isset($settings['report_expiration']))
|
||||
$current_values['recheck_interval'] = $settings['report_expiration'];
|
||||
|
||||
if (isset($settings['check_report'])) {
|
||||
if (is_array($settings['check_report'])) {
|
||||
$current_values['check_pages'] = in_array('page', $settings['check_report']) ? true : false;
|
||||
$current_values['check_posts'] = in_array('post', $settings['check_report']) ? true : false;
|
||||
$current_values['check_categories'] = in_array('category', $settings['check_report']) ? true : false;
|
||||
} else {
|
||||
$current_values['check_pages'] = $current_values['check_posts'] = $current_values['check_categories'] = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($settings['delete_data']) && !empty($settings['delete_data'])) {
|
||||
$this->delete_data($settings['delete_data']);
|
||||
}
|
||||
|
||||
if (update_option( 'gpagespeedi_options', $current_values ))
|
||||
$information['result'] = 'SUCCESS';
|
||||
else
|
||||
$information['result'] = 'NOTCHANGE';
|
||||
}
|
||||
|
||||
$strategy = $current_values['strategy'];
|
||||
|
||||
$sync_data = $this->sync_data($strategy);
|
||||
$information['data'] = $sync_data['data'];
|
||||
return $information;
|
||||
}
|
||||
|
||||
function sync_data($strategy = "") {
|
||||
if (empty($strategy))
|
||||
$strategy = "both";
|
||||
|
||||
$information = array();
|
||||
$current_values = get_option('gpagespeedi_options');
|
||||
$bad_key = ($current_values['bad_api_key'] || empty($current_values['google_developer_key']));
|
||||
$data = array('bad_api_key' => $bad_key );
|
||||
|
||||
if ($strategy == "both" || $strategy == "desktop") {
|
||||
$result = self::cal_pagespeed_data('desktop');
|
||||
$data['desktop_score'] = $result['average_score'];
|
||||
$data['desktop_total_pages'] = $result['total_pages'];
|
||||
$data['desktop_last_modified'] = $result['last_modified'];
|
||||
}
|
||||
if ($strategy == "both" || $strategy == "mobile") {
|
||||
$result = self::cal_pagespeed_data('mobile');
|
||||
$data['mobile_score'] = $result['average_score'];
|
||||
$data['mobile_total_pages'] = $result['total_pages'];
|
||||
$data['mobile_last_modified'] = $result['last_modified'];
|
||||
}
|
||||
|
||||
$information['data'] = $data;
|
||||
return $information;
|
||||
}
|
||||
|
||||
static function cal_pagespeed_data($strategy) {
|
||||
global $wpdb;
|
||||
|
||||
if ( !defined('GPI_DIRECTORY') )
|
||||
return 0;
|
||||
|
||||
require_once( GPI_DIRECTORY . '/includes/helper.php' );
|
||||
|
||||
$options = get_option('gpagespeedi_options');
|
||||
|
||||
$score_column = $strategy . '_score';
|
||||
$page_stats_column = $strategy . '_page_stats';
|
||||
require_once( ABSPATH . 'wp-admin/includes/template.php' );
|
||||
require_once( GPI_DIRECTORY . '/core/init.php' );
|
||||
$GPI_ListTable = new GPI_List_Table();
|
||||
|
||||
$data_typestocheck = $GPI_ListTable->getTypesToCheck('all');
|
||||
|
||||
$gpi_page_stats = $wpdb->prefix . 'gpi_page_stats';
|
||||
if(!empty($data_typestocheck)) {
|
||||
|
||||
$allpagedata = $wpdb->get_results(
|
||||
$wpdb->prepare(
|
||||
"SELECT ID, URL, $score_column, $page_stats_column
|
||||
FROM $gpi_page_stats
|
||||
WHERE ($data_typestocheck[0])",
|
||||
$data_typestocheck[1]
|
||||
),
|
||||
ARRAY_A
|
||||
);
|
||||
} else {
|
||||
$allpagedata = array();
|
||||
}
|
||||
|
||||
$reports_typestocheck = $GPI_ListTable->getTypesToCheck('all');
|
||||
$gpi_page_reports = $wpdb->prefix . 'gpi_page_reports';
|
||||
|
||||
if(!empty($reports_typestocheck)) {
|
||||
|
||||
$allpagereports = $wpdb->get_results(
|
||||
$wpdb->prepare(
|
||||
"SELECT r.rule_key, r.rule_name, r.rule_impact
|
||||
FROM $gpi_page_stats d
|
||||
INNER JOIN $gpi_page_reports r
|
||||
ON r.page_id = d.ID
|
||||
AND r.rule_impact > 0
|
||||
AND r.strategy = '$strategy'
|
||||
WHERE ($reports_typestocheck[0])",
|
||||
$reports_typestocheck[1]
|
||||
),
|
||||
ARRAY_A
|
||||
);
|
||||
} else {
|
||||
$allpagereports = array();
|
||||
}
|
||||
|
||||
$total_pages = count($allpagedata);
|
||||
$total_scores = 0;
|
||||
$average_score = 0;
|
||||
|
||||
if(!empty($total_pages) && !empty($allpagereports)) {
|
||||
|
||||
foreach($allpagedata as $key => $pagedata)
|
||||
{
|
||||
$total_scores = $total_scores + $pagedata[$score_column];
|
||||
}
|
||||
|
||||
$average_score = number_format($total_scores / $total_pages);
|
||||
}
|
||||
|
||||
// Not Null check for Report List scores
|
||||
switch($strategy) {
|
||||
|
||||
// case 'both':
|
||||
// $nullcheck = 'desktop_score IS NOT NULL AND mobile_score IS NOT NULL';
|
||||
// break;
|
||||
|
||||
case 'mobile':
|
||||
$nullcheck = 'mobile_score IS NOT NULL';
|
||||
$_select = " max(mobile_last_modified) as last_modified ";
|
||||
break;
|
||||
|
||||
case 'desktop':
|
||||
$nullcheck = 'desktop_score IS NOT NULL';
|
||||
$_select = " max(desktop_last_modified) as last_modified ";
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
// Get our Data
|
||||
if(!is_null($reports_typestocheck)) {
|
||||
$gpi_page_stats = $wpdb->prefix . 'gpi_page_stats';
|
||||
$data = $wpdb->get_results(
|
||||
$wpdb->prepare(
|
||||
"SELECT $_select
|
||||
FROM $gpi_page_stats
|
||||
WHERE ($reports_typestocheck[0])
|
||||
AND $nullcheck",
|
||||
$reports_typestocheck[1]
|
||||
),
|
||||
ARRAY_A
|
||||
);
|
||||
}
|
||||
|
||||
return array('last_modified' => isset($data['last_modified']) ? $data['last_modified'] : 0,
|
||||
'average_score' => $average_score,
|
||||
'total_pages' => $total_pages);
|
||||
}
|
||||
|
||||
function delete_data($what) {
|
||||
global $wpdb;
|
||||
$gpi_page_stats = $wpdb->prefix . 'gpi_page_stats';
|
||||
$gpi_page_reports = $wpdb->prefix . 'gpi_page_reports';
|
||||
$gpi_page_blacklist = $wpdb->prefix . 'gpi_page_blacklist';
|
||||
|
||||
if($what == 'purge_reports') {
|
||||
$wpdb->query("TRUNCATE TABLE $gpi_page_stats");
|
||||
$wpdb->query("TRUNCATE TABLE $gpi_page_reports");
|
||||
} elseif($what == 'purge_everything') {
|
||||
$wpdb->query("TRUNCATE TABLE $gpi_page_stats");
|
||||
$wpdb->query("TRUNCATE TABLE $gpi_page_reports");
|
||||
$wpdb->query("TRUNCATE TABLE $gpi_page_blacklist");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -149,6 +149,39 @@ class MainWPHelper
|
|||
}
|
||||
}
|
||||
|
||||
if ($post_plus) {
|
||||
$random_publish_date = isset($post_custom['_saved_draft_random_publish_date']) ? $post_custom['_saved_draft_random_publish_date'] : false;
|
||||
$random_publish_date = is_array($random_publish_date) ? current($random_publish_date) : null;
|
||||
if (!empty($random_publish_date)) {
|
||||
$random_date_from = isset($post_custom['_saved_draft_publish_date_from']) ? $post_custom['_saved_draft_publish_date_from'] : 0;
|
||||
$random_date_from = is_array($random_date_from) ? current($random_date_from) : 0;
|
||||
|
||||
$random_date_to = isset($post_custom['_saved_draft_publish_date_to']) ? $post_custom['_saved_draft_publish_date_to'] : 0;
|
||||
$random_date_to = is_array($random_date_to) ? current($random_date_to) : 0;
|
||||
|
||||
$now = current_time('timestamp');
|
||||
|
||||
if (empty($random_date_from))
|
||||
$random_date_from = $now;
|
||||
|
||||
if (empty($random_date_to))
|
||||
$random_date_to = $now;
|
||||
|
||||
if ($random_date_from == $now && $random_date_from == $random_date_to)
|
||||
$random_date_to = $now + 7 * 24 * 3600;
|
||||
|
||||
if ($random_date_from > $random_date_to) {
|
||||
$tmp = $random_date_from;
|
||||
$random_date_from = $random_date_to;
|
||||
$random_date_to = $tmp;
|
||||
}
|
||||
|
||||
$random_timestamp = rand($random_date_from, $random_date_to);
|
||||
$post_status = ($random_timestamp <= current_time('timestamp')) ? 'publish' : 'future';
|
||||
$new_post['post_status'] = $post_status;
|
||||
$new_post['post_date'] = date('Y-m-d H:i:s', $random_timestamp);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($post_tags) && $post_tags != '') $new_post['tags_input'] = $post_tags;
|
||||
|
||||
|
@ -317,37 +350,6 @@ class MainWPHelper
|
|||
wp_set_post_categories($new_post_id, array($random_cats[$key]), false);
|
||||
}
|
||||
}
|
||||
|
||||
$random_publish_date = isset($post_custom['_saved_draft_random_publish_date']) ? $post_custom['_saved_draft_random_publish_date'] : false;
|
||||
$random_publish_date = is_array($random_publish_date) ? current($random_publish_date) : null;
|
||||
if (!empty($random_publish_date)) {
|
||||
$random_date_from = isset($post_custom['_saved_draft_publish_date_from']) ? $post_custom['_saved_draft_publish_date_from'] : 0;
|
||||
$random_date_from = is_array($random_date_from) ? current($random_date_from) : 0;
|
||||
|
||||
$random_date_to = isset($post_custom['_saved_draft_publish_date_to']) ? $post_custom['_saved_draft_publish_date_to'] : 0;
|
||||
$random_date_to = is_array($random_date_to) ? current($random_date_to) : 0;
|
||||
|
||||
$now = current_time('timestamp');
|
||||
|
||||
if (empty($random_date_from))
|
||||
$random_date_from = $now;
|
||||
|
||||
if (empty($random_date_to))
|
||||
$random_date_to = $now;
|
||||
|
||||
if ($random_date_from == $now && $random_date_from == $random_date_to)
|
||||
$random_date_to = $now + 7 * 24 * 3600;
|
||||
|
||||
if ($random_date_from > $random_date_to) {
|
||||
$tmp = $random_date_from;
|
||||
$random_date_from = $random_date_to;
|
||||
$random_date_to = $tmp;
|
||||
}
|
||||
|
||||
$random_timestamp = rand($random_date_from, $random_date_to);
|
||||
$post_status = ($random_timestamp <= current_time('timestamp')) ? 'publish' : 'future';
|
||||
wp_update_post(array('ID' => $new_post_id, 'post_date' => date('Y-m-d H:i:s', $random_timestamp), 'post_status' => $post_status));
|
||||
}
|
||||
}
|
||||
// end of post plus
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
Description: Child Plugin for MainWP. The plugin is used so the installed blog can be securely managed remotely by your network. Plugin documentation and options can be found here http://docs.mainwp.com
|
||||
Author: MainWP
|
||||
Author URI: http://mainwp.com
|
||||
Version: 0.29.9-beta
|
||||
Version: 0.29.9
|
||||
*/
|
||||
header('X-Frame-Options: ALLOWALL');
|
||||
//header('X-Frame-Options: GOFORIT');
|
||||
|
|
|
@ -7,7 +7,7 @@ Author URI: http://mainwp.com
|
|||
Plugin URI: http://mainwp.com
|
||||
Requires at least: 3.6
|
||||
Tested up to: 3.9
|
||||
Stable tag: 0.29.8
|
||||
Stable tag: 0.29.9
|
||||
License: GPLv2 or later
|
||||
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
|
||||
|
@ -58,6 +58,9 @@ To see full documentation and FAQs please visit [MainWP Documentation](http://do
|
|||
|
||||
== Changelog ==
|
||||
|
||||
= 0.29.9 =
|
||||
* Added new hooks for upcoming extensions
|
||||
|
||||
= 0.29.8 =
|
||||
* Fix for uploads path outside the conventional path for backups
|
||||
* Added new hooks for upcoming extensions
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue