From f10acefb27724bace3eebc5dfda18aa1789f5051 Mon Sep 17 00:00:00 2001 From: ruben- Date: Tue, 10 Jun 2014 20:41:28 +0200 Subject: [PATCH] new version --- class/MainWPChild.class.php | 3 +- class/MainWPChildServerInformation.class.php | 2 +- class/MainWPClientReport.class.php | 381 ++++++++++++++++++- mainwp-child.php | 2 +- readme.txt | 2 +- 5 files changed, 371 insertions(+), 19 deletions(-) diff --git a/class/MainWPChild.class.php b/class/MainWPChild.class.php index 9cd1f7e..4d89ece 100644 --- a/class/MainWPChild.class.php +++ b/class/MainWPChild.class.php @@ -623,7 +623,8 @@ class MainWPChild } // Branding extension - MainWPChildBranding::Instance()->branding_init(); + MainWPChildBranding::Instance()->branding_init(); + MainWPClientReport::Instance()->creport_init(); } function default_option_active_plugins($default) diff --git a/class/MainWPChildServerInformation.class.php b/class/MainWPChildServerInformation.class.php index f9c378a..591ea14 100644 --- a/class/MainWPChildServerInformation.class.php +++ b/class/MainWPChildServerInformation.class.php @@ -225,7 +225,7 @@ class MainWPChildServerInformation - + diff --git a/class/MainWPClientReport.class.php b/class/MainWPClientReport.class.php index 94b8f73..5185d0d 100644 --- a/class/MainWPClientReport.class.php +++ b/class/MainWPClientReport.class.php @@ -2,7 +2,7 @@ class MainWPClientReport { - public static $instance = null; + public static $instance = null; static function Instance() { if (MainWPClientReport::$instance == null) { @@ -31,7 +31,10 @@ class MainWPClientReport switch ($_POST['mwp_action']) { case "get_stream": $information = $this->get_stream(); - break; + break; + case "set_showhide": + $information = $this->set_showhide(); + break; } } MainWPHelper::write($information); @@ -55,12 +58,18 @@ class MainWPClientReport 'ip', ); - $stream_tokens = array(); - if (isset($_POST['stream_tokens'])) { - $stream_tokens = unserialize(base64_decode($_POST['stream_tokens'])); - } - if (!is_array($stream_tokens)) - $stream_tokens = array(); + $sections = isset($_POST['sections']) ? unserialize(base64_decode($_POST['sections'])) : array(); + if (!is_array($sections)) + $sections = array(); + //return $sections; + + $other_tokens = isset($_POST['other_tokens']) ? unserialize(base64_decode($_POST['other_tokens'])) : array(); + if (!is_array($other_tokens)) + $other_tokens = array(); + //return $other_tokens; + + unset($_POST['sections']); + unset($_POST['other_tokens']); $args = array(); foreach ( $allowed_params as $param ) { @@ -74,22 +83,364 @@ class MainWPClientReport if (!in_array($arg, $allowed_params)) { unset($args[$arg]); } - } + } + if (isset($args['date_from'])) + $args['date_from'] = date("Y-m-d H:i:s", $args['date_from']); + + if (isset($args['date_to'])) + $args['date_to'] = date("Y-m-d H:i:s", $args['date_to']); + + $args['records_per_page'] = -1; $records = wp_stream_query( $args ); if (!is_array($records)) $records = array(); //return $records; - $token_values = array(); - foreach ($records as $record) { - $name = "[" . $record->context . "." . $record->action . "]"; - if (in_array($name, $stream_tokens)) { - $token_values[$name][] = $record->summary; + //$other_tokens_data = $this->get_other_tokens_data($records, $other_tokens); + + if (isset($other_tokens['header']) && is_array($other_tokens['header'])) { + $other_tokens_data['header'] = $this->get_other_tokens_data($records, $other_tokens['header']); + } + + if (isset($other_tokens['body']) && is_array($other_tokens['body'])) { + $other_tokens_data['body'] = $this->get_other_tokens_data($records, $other_tokens['body']); + } + + if (isset($other_tokens['footer']) && is_array($other_tokens['footer'])) { + $other_tokens_data['footer'] = $this->get_other_tokens_data($records, $other_tokens['footer']); + } + + $sections_data = array(); + + if (isset($sections['header']) && is_array($sections['header'])) { + foreach($sections['header'] as $sec => $tokens) { + $sections_data['header'][$sec] = $this->get_section_loop_data($records, $tokens, $sec); } } - $information = array('token_values' => $token_values); + if (isset($sections['body']) && is_array($sections['body'])) { + foreach($sections['body'] as $sec => $tokens) { + $sections_data['body'][$sec] = $this->get_section_loop_data($records, $tokens, $sec); + } + } + if (isset($sections['footer']) && is_array($sections['footer'])) { + foreach($sections['footer'] as $sec => $tokens) { + $sections_data['footer'][$sec] = $this->get_section_loop_data($records, $tokens, $sec); + } + } + + $information = array('other_tokens_data' => $other_tokens_data, + 'sections_data' => $sections_data ); + return $information; } + function get_other_tokens_data($records, $tokens) { + $convert_context_name = array( + "comment" => "comments", + "plugin" => "plugins", + "profile" => "profiles", + "session" => "sessions", + "setting" => "settings", + "setting" => "settings", + "theme" => "themes", + "posts" => "post", + "pages" => "page", + "user" => "users", + "widget" => "widgets", + "menu" => "menus" + ); + + $convert_action_name = array( + "restored" => "untrashed", + "spam" => "spammed" + ); + + $allowed_data = array( + 'count' + ); + + $token_values = array(); + + if (!is_array($tokens)) + $tokens = array(); + + foreach ($tokens as $token) { + $str_tmp = str_replace(array('[', ']'), "", $token); + $array_tmp = explode(".", $str_tmp); + + if (is_array($array_tmp)) { + $context = $action = $data = ""; + if (count($array_tmp) == 2) { + list($context, $data) = $array_tmp; + } else if (count($array_tmp) == 3) { + list($context, $action, $data) = $array_tmp; + } + + $context = isset($convert_context_name[$context]) ? $convert_context_name[$context] : $context; + $action = isset($convert_action_name[$action]) ? $convert_action_name[$action] : $action; + + switch ($data) { + case "count": + $count = 0; + foreach ($records as $record) { + if ($context == "themes" && $action == "edited") { + if ($record->action !== "updated" || $record->connector !== "editor") + continue; + } else if ($context == "users" && $action == "updated") { + if ($record->context !== "profiles" || $record->connector !== "users") + continue; + } else { + if ($action != $record->action) + continue; + + if ($context == "comments" && $record->context != "page" && $record->context != "post") + continue; + else if ($context == "media" && $record->connector != "media") + continue; + else if ($context == "widgets" && $record->connector != "widgets") + continue; + else if ($context == "menus" && $record->connector != "menus") + continue; + + if ($context !== "comments" && $context !== "media" && + $context !== "widgets" && $context !== "menus" && + $record->context != $context) + continue; + } + + $count++; + } + $token_values[$token] = $count; + break; + } + } + } + return $token_values; + } + + function get_section_loop_data($records, $tokens, $section) { + + $convert_context_name = array( + "comment" => "comments", + "plugin" => "plugins", + "profile" => "profiles", + "session" => "sessions", + "setting" => "settings", + "setting" => "settings", + "theme" => "themes", + "posts" => "post", + "pages" => "page", + "widget" => "widgets", + "menu" => "menus", + ); + + $convert_action_name = array( + "restored" => "untrashed", + "spam" => "spammed", + ); + + $some_allowed_data = array( + 'name', + 'title', + 'oldversion', + 'currentversion', + 'date', + 'count', + 'author', + 'old.version', + 'current.version' + ); + + $context = $action = ""; + $str_tmp = str_replace(array('[', ']'), "", $section); + $array_tmp = explode(".", $str_tmp); + if (is_array($array_tmp)) + list($str1, $context, $action) = $array_tmp; + + $context = isset($convert_context_name[$context]) ? $convert_context_name[$context] : $context; + $action = isset($convert_action_name[$action]) ? $convert_action_name[$action] : $action; + + $loops = array(); + $loop_count = 0; + + foreach ($records as $record) { + $theme_edited = $users_updated = false; + if ($context == "themes" && $action == "edited") { + if ($record->action !== "updated" || $record->connector !== "editor") + continue; + else + $theme_edited = true; + } else if ($context == "users" && $action == "updated") { + if ($record->context !== "profiles" || $record->connector !== "users") + continue; + else + $users_updated = true; + } else { + if ($action !== $record->action) + continue; + + if ($context === "comments" && $record->context !== "page" && $record->context !== "post") + continue; + else if ($context === "media" && $record->connector !== "media") + continue; + else if ($context === "widgets" && $record->connector !== "widgets") + continue; + else if ($context === "menus" && $record->connector !== "menus") + continue; +// else if ($context === "themes" && $record->connector !== "themes") +// continue; + + if ($context !== "comments" && $context !== "media" && + $context !== "widgets" && $context !== "menus" && + $record->context !== $context) + continue; + } + + $token_values = array(); + + foreach ($tokens as $token) { + $data = ""; + $token_name = str_replace(array('[', ']'), "", $token); + $array_tmp = explode(".", $token_name); + + if ($token_name == "user.name") { + $data = "display_name"; + } else { + if (count($array_tmp) == 1) { + list($data) = $array_tmp; + } else if (count($array_tmp) == 2) { + list($str1, $data) = $array_tmp; + } else if (count($array_tmp) == 3) { + list($str1, $str2, $data) = $array_tmp; + } + + if ($data == "version") { + if ($str2 == "old") + $data = "old_version"; + } + } + + if ($data == "role") + $data = "roles"; + + switch ($data) { + case "date": + $token_values[$token] = $record->created; + break; + case "area": + $data = "sidebar_name"; + $token_values[$token] = $this->get_stream_meta_data($record->ID, $data); + break; + case "name": + case "version": + case "old_version": + case "display_name": + case "roles": + if ($data == "name") { + if ($theme_edited) + $data = "theme_name"; + else if ($users_updated) { + $data = "display_name"; + } + } + if ($data == "roles" && $users_updated) { + $user_info = get_userdata($record->object_id); + if ( !( is_object( $user_info ) && is_a( $user_info, 'WP_User' ) ) ) { + $roles = ""; + } else { + $roles = implode(", ", $user_info->roles); + } + $token_values[$token] = $roles; + } else { + $token_values[$token] = $this->get_stream_meta_data($record->ID, $data); + } + break; + case "title": + if ($context == "page" || $context == "post" || $context == "comments") + $data = "post_title"; + else if ($record->connector == "menus") { + $data = "name"; + } + $token_values[$token] = $this->get_stream_meta_data($record->ID, $data); + break; + case "author": + $data = "author_meta"; + $token_values[$token] = $this->get_stream_meta_data($record->ID, $data); + break; + default: + $token_values[$token] = $token; + break; + } + + } // foreach $tokens + + if (!empty($token_values)) { + $loops[$loop_count] = $token_values; + $loop_count++; + } + } // foreach $records + return $loops; + } + + function get_stream_meta_data($record_id, $data) { + + $meta_key = $data; + + global $wpdb; + + if (class_exists('WP_Stream_Install')) + $prefix = WP_Stream_Install::$table_prefix; + else + $prefix = $wpdb->prefix; + + $sql = "SELECT meta_value FROM {$prefix}stream_meta WHERE record_id = " . $record_id . " AND meta_key = '" . $meta_key . "'"; + $meta = $wpdb->get_row( $sql ); + + $value = ""; + if (!empty($meta)) { + $value = $meta->meta_value; + if ($meta_key == "author_meta") { + $value = unserialize($value); + $value = $value['display_name']; + } + } + + return $value; + } + + function set_showhide() { + MainWPHelper::update_option('mainwp_creport_ext_branding_enabled', "Y"); + $hide = isset($_POST['showhide']) && ($_POST['showhide'] === "hide") ? 'hide' : ""; + MainWPHelper::update_option('mainwp_creport_branding_stream_hide', $hide); + $information['result'] = 'SUCCESS'; + return $information; + } + + public function creport_init() + { + if (get_option('mainwp_creport_ext_branding_enabled') !== "Y") + return; + + if (get_option('mainwp_creport_branding_stream_hide') === "hide") + { + add_filter('all_plugins', array($this, 'creport_branding_plugin')); + add_action( 'admin_menu', array($this, 'creport_remove_menu')); + } + } + + + public function creport_branding_plugin($plugins) { + foreach ($plugins as $key => $value) + { + $plugin_slug = basename($key, '.php'); + if ($plugin_slug == 'stream') + unset($plugins[$key]); + } + return $plugins; + } + + public function creport_remove_menu() { + remove_menu_page('wp_stream'); + } } diff --git a/mainwp-child.php b/mainwp-child.php index 71617d3..ab7e777 100644 --- a/mainwp-child.php +++ b/mainwp-child.php @@ -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.7-beta + Version: 0.29.7 */ header('X-Frame-Options: ALLOWALL'); //header('X-Frame-Options: GOFORIT'); diff --git a/readme.txt b/readme.txt index c5bccb3..3a5692d 100644 --- a/readme.txt +++ b/readme.txt @@ -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.6 +Stable tag: 0.29.7 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html
plugin conflict 1 ? 's' : ''); ?> foundDismiss
plugin conflict 1 ? 's' : ''); ?> found
is installed on this site. This plugin is known to have a potential conflict with MainWP functions. Please click this link for possible solutions