public static function get_edition_data()
 {
     if ('POST' !== $_SERVER['REQUEST_METHOD']) {
         return;
     }
     if ('update' !== mainwp_wp_stream_filter_input(INPUT_POST, 'action')) {
         return;
     }
     $theme_slug = mainwp_wp_stream_filter_input(INPUT_POST, 'theme') ? mainwp_wp_stream_filter_input(INPUT_POST, 'theme') : get_stylesheet();
     $theme = wp_get_theme($theme_slug);
     if (!$theme->exists() || $theme->errors() && 'theme_no_stylesheet' === $theme->errors()->get_error_code()) {
         return;
     }
     $allowed_files = $theme->get_files('php', 1);
     $style_files = $theme->get_files('css');
     $allowed_files['style.css'] = $style_files['style.css'];
     $file = mainwp_wp_stream_filter_input(INPUT_POST, 'file');
     if (empty($file)) {
         $file_name = 'style.css';
         $file_path = $allowed_files['style.css'];
     } else {
         $file_name = $file;
         $file_path = sprintf('%s/%s', $theme->get_stylesheet_directory(), $file_name);
     }
     $file_contents_before = file_get_contents($file_path);
     self::$edited_file = compact('file_name', 'file_path', 'file_contents_before', 'theme');
 }
Beispiel #2
0
 public function log($connector, $message, $args, $object_id, $contexts, $user_id = null)
 {
     global $wpdb;
     if (is_null($user_id)) {
         $user_id = get_current_user_id();
     }
     require_once MAINWP_WP_STREAM_INC_DIR . 'class-wp-stream-author.php';
     $user = new WP_User($user_id);
     $roles = get_option($wpdb->get_blog_prefix() . 'user_roles');
     if (!isset($args['author_meta'])) {
         $args['author_meta'] = array('user_email' => $user->user_email, 'display_name' => defined('WP_CLI') && empty($user->display_name) ? 'WP-CLI' : $user->display_name, 'user_login' => $user->user_login, 'user_role_label' => !empty($user->roles) ? $roles[$user->roles[0]]['name'] : null, 'agent' => MainWP_WP_Stream_Author::get_current_agent());
         if (defined('WP_CLI') && function_exists('posix_getuid')) {
             $uid = posix_getuid();
             $user_info = posix_getpwuid($uid);
             $args['author_meta']['system_user_id'] = $uid;
             $args['author_meta']['system_user_name'] = $user_info['name'];
         }
     }
     // Remove meta with null values from being logged
     $meta = array_filter($args, function ($var) {
         return !is_null($var);
     });
     $recordarr = array('object_id' => $object_id, 'site_id' => is_multisite() ? get_current_site()->id : 1, 'blog_id' => apply_filters('blog_id_logged', is_network_admin() ? 0 : get_current_blog_id()), 'author' => $user_id, 'author_role' => !empty($user->roles) ? $user->roles[0] : null, 'created' => current_time('mysql', 1), 'summary' => vsprintf($message, $args), 'parent' => self::$instance->prev_record, 'connector' => $connector, 'contexts' => $contexts, 'meta' => $meta, 'ip' => mainwp_wp_stream_filter_input(INPUT_SERVER, 'REMOTE_ADDR', FILTER_VALIDATE_IP));
     $record_id = MainWP_WP_Stream_DB::get_instance()->insert($recordarr);
     return $record_id;
 }
 public static function get_option_key()
 {
     $option_key = self::KEY;
     $current_page = mainwp_wp_stream_filter_input(INPUT_GET, 'page');
     if (!$current_page) {
         $current_page = mainwp_wp_stream_filter_input(INPUT_GET, 'action');
     }
     if ('mainwp_wp_stream_default_settings' === $current_page) {
         $option_key = self::DEFAULTS_KEY;
     }
     if ('mainwp_wp_stream_network_settings' === $current_page) {
         $option_key = self::NETWORK_KEY;
     }
     return apply_filters('mainwp_wp_stream_settings_option_key', $option_key);
 }
 public static function is_logging_enabled_for_ip($ip = null)
 {
     if (is_null($ip)) {
         $ip = mainwp_wp_stream_filter_input(INPUT_SERVER, 'REMOTE_ADDR', FILTER_VALIDATE_IP);
     } else {
         $ip = mainwp_wp_stream_filter_var($ip, FILTER_VALIDATE_IP);
     }
     // If ip is not valid the we will log the action
     if (false === $ip) {
         $bool = true;
     } else {
         $bool = self::is_logging_enabled('ip_addresses', $ip);
     }
     return apply_filters('mainwp_wp_stream_ip_record_log', $bool, $ip, get_called_class());
 }
 public function get_stream()
 {
     // Filters
     $allowed_params = array('connector', 'context', 'action', 'author', 'author_role', 'object_id', 'search', 'date', 'date_from', 'date_to', 'record__in', 'blog_id', 'ip');
     $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) {
         if (self::$mainwpChildReports) {
             $paramval = mainwp_wp_stream_filter_input(INPUT_POST, $param);
         } else {
             $paramval = wp_stream_filter_input(INPUT_POST, $param);
         }
         if ($paramval || '0' === $paramval) {
             $args[$param] = $paramval;
         }
     }
     foreach ($args as $arg => $val) {
         if (!in_array($arg, $allowed_params)) {
             unset($args[$arg]);
         }
     }
     $args['action__not_in'] = array('login');
     $args['fields'] = 'with-meta';
     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'] = 9999;
     //        error_log(print_r($args, true));
     if (self::$mainwpChildReports) {
         $records = mainwp_wp_stream_query($args);
     } else {
         $records = wp_stream_query($args);
     }
     //        if (count($records) > 0)
     //            error_log(print_r($records, true));
     //        else
     //            error_log("==============");
     if (!is_array($records)) {
         $records = array();
     }
     //return $records;
     //$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']) && !empty($sections['header'])) {
         foreach ($sections['header']['section_token'] as $index => $sec) {
             $tokens = $sections['header']['section_content_tokens'][$index];
             $sections_data['header'][$index] = $this->get_section_loop_data($records, $tokens, $sec);
         }
     }
     if (isset($sections['body']) && is_array($sections['body']) && !empty($sections['body'])) {
         foreach ($sections['body']['section_token'] as $index => $sec) {
             $tokens = $sections['body']['section_content_tokens'][$index];
             $sections_data['body'][$index] = $this->get_section_loop_data($records, $tokens, $sec);
         }
     }
     if (isset($sections['footer']) && is_array($sections['footer']) && !empty($sections['footer'])) {
         foreach ($sections['footer'] as $index => $sec) {
             $tokens = $sections['footer']['section_content_tokens'][$index];
             $sections_data['footer'][$index] = $this->get_section_loop_data($records, $tokens, $sec);
         }
     }
     $information = array('other_tokens_data' => $other_tokens_data, 'sections_data' => $sections_data);
     return $information;
 }
 public function get_stream()
 {
     // Filters
     $allowed_params = array('connector', 'context', 'action', 'author', 'author_role', 'object_id', 'search', 'date', 'date_from', 'date_to', 'record__in', 'blog_id', 'ip');
     $sections = isset($_POST['sections']) ? maybe_unserialize(base64_decode($_POST['sections'])) : array();
     if (!is_array($sections)) {
         $sections = array();
     }
     //return $sections;
     $other_tokens = isset($_POST['other_tokens']) ? maybe_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) {
         if (self::$mainwpChildReports) {
             $paramval = mainwp_wp_stream_filter_input(INPUT_POST, $param);
         } else {
             $paramval = wp_stream_filter_input(INPUT_POST, $param);
         }
         if ($paramval || '0' === $paramval) {
             $args[$param] = $paramval;
         }
     }
     foreach ($args as $arg => $val) {
         if (!in_array($arg, $allowed_params)) {
             unset($args[$arg]);
         }
     }
     // to fix bug
     $exclude_connector_posts = true;
     if (isset($sections['body']) && isset($sections['body']['section_token']) && is_array($sections['body']['section_token'])) {
         foreach ($sections['body']['section_token'] as $sec) {
             if (strpos($sec, "[section.posts") !== false) {
                 $exclude_connector_posts = false;
                 break;
             }
         }
     }
     if ($exclude_connector_posts) {
         if (isset($sections['header']) && isset($sections['header']['section_token']) && is_array($sections['header']['section_token'])) {
             foreach ($sections['header']['section_token'] as $sec) {
                 if (strpos($sec, "[section.posts") !== false) {
                     $exclude_connector_posts = false;
                     break;
                 }
             }
         }
     }
     if ($exclude_connector_posts) {
         if (isset($sections['footer']) && isset($sections['footer']['section_token']) && is_array($sections['footer']['section_token'])) {
             foreach ($sections['footer']['section_token'] as $sec) {
                 if (strpos($sec, "[section.posts") !== false) {
                     $exclude_connector_posts = false;
                     break;
                 }
             }
         }
     }
     if ($exclude_connector_posts) {
         if (isset($other_tokens['body']) && is_array($other_tokens['body'])) {
             foreach ($other_tokens['body'] as $sec) {
                 if (strpos($sec, "[post.") !== false) {
                     $exclude_connector_posts = false;
                     break;
                 }
             }
         }
     }
     if ($exclude_connector_posts) {
         if (isset($other_tokens['header']) && is_array($other_tokens['header'])) {
             foreach ($other_tokens['header'] as $sec) {
                 if (strpos($sec, "[post.") !== false) {
                     $exclude_connector_posts = false;
                     break;
                 }
             }
         }
     }
     if ($exclude_connector_posts) {
         if (isset($other_tokens['footer']) && is_array($other_tokens['footer'])) {
             foreach ($other_tokens['footer'] as $sec) {
                 if (strpos($sec, "[post.") !== false) {
                     $exclude_connector_posts = false;
                     break;
                 }
             }
         }
     }
     if ($exclude_connector_posts) {
         $args['connector__not_in'] = array('posts');
     }
     ///// end fix /////
     $args['action__not_in'] = array('login');
     // fix for Stream 3
     if (3 !== self::$streamVersionNumber) {
         $args['fields'] = 'with-meta';
         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']);
         }
     } else {
         if (isset($args['date_from'])) {
             $args['date_from'] = date('Y-m-d', $args['date_from']);
         }
         if (isset($args['date_to'])) {
             $args['date_to'] = date('Y-m-d', $args['date_to']);
         }
     }
     $args['records_per_page'] = 9999;
     //        error_log(print_r($args, true));
     if (self::$mainwpChildReports) {
         $records = mainwp_wp_stream_query($args);
     } else {
         if (149 === self::$streamVersionNumber) {
             $records = wp_stream_query($args);
         } else {
             if (3 === self::$streamVersionNumber) {
                 $records = wp_stream_get_instance()->db->query->query($args);
             }
         }
     }
     if (!is_array($records)) {
         $records = array();
     }
     //return $records;
     //$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']) && !empty($sections['header'])) {
         foreach ($sections['header']['section_token'] as $index => $sec) {
             $tokens = $sections['header']['section_content_tokens'][$index];
             $sections_data['header'][$index] = $this->get_section_loop_data($records, $tokens, $sec);
         }
     }
     if (isset($sections['body']) && is_array($sections['body']) && !empty($sections['body'])) {
         foreach ($sections['body']['section_token'] as $index => $sec) {
             $tokens = $sections['body']['section_content_tokens'][$index];
             $sections_data['body'][$index] = $this->get_section_loop_data($records, $tokens, $sec);
         }
     }
     if (isset($sections['footer']) && is_array($sections['footer']) && !empty($sections['footer'])) {
         foreach ($sections['footer'] as $index => $sec) {
             $tokens = $sections['footer']['section_content_tokens'][$index];
             $sections_data['footer'][$index] = $this->get_section_loop_data($records, $tokens, $sec);
         }
     }
     $information = array('other_tokens_data' => $other_tokens_data, 'sections_data' => $sections_data);
     return $information;
 }
 public static function callback_pre_set_site_transient_update_plugins($value)
 {
     if (!mainwp_wp_stream_filter_input(INPUT_POST, 'verify-delete') || !($plugins_to_delete = get_option('mainwp_wp_stream_plugins_to_delete'))) {
         return $value;
     }
     foreach ($plugins_to_delete as $plugin => $data) {
         $name = $data['Name'];
         $network_wide = $data['Network'] ? __('network wide', 'mainwp-child-reports') : '';
         self::log(__('"%s" plugin deleted', 'mainwp-child-reports'), compact('name', 'plugin', 'network_wide'), null, array('plugins' => 'deleted'));
     }
     delete_option('mainwp_wp_stream_plugins_to_delete');
     return $value;
 }
 function settings_form_description($description)
 {
     if (!is_network_admin()) {
         return;
     }
     $current_page = mainwp_wp_stream_filter_input(INPUT_GET, 'page');
     switch ($current_page) {
         case self::NETWORK_SETTINGS_PAGE_SLUG:
             $description = __('These settings apply to all sites on the network.', 'mainwp-child-reports');
             break;
         case self::DEFAULT_SETTINGS_PAGE_SLUG:
             $description = __('These default settings will apply to new sites created on the network. These settings do not alter existing sites.', 'mainwp-child-reports');
             break;
     }
     return $description;
 }
 public static function get_filter_value_by_id()
 {
     $filter = mainwp_wp_stream_filter_input(INPUT_POST, 'filter');
     switch ($filter) {
         case 'author':
             $id = mainwp_wp_stream_filter_input(INPUT_POST, 'id');
             if ($id === '0') {
                 $value = 'WP-CLI';
                 break;
             }
             $user = get_userdata($id);
             if (!$user || is_wp_error($user)) {
                 $value = '';
             } else {
                 $value = $user->display_name;
             }
             break;
         default:
             $value = '';
             break;
     }
     echo json_encode($value);
     wp_die();
 }