PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / trunk
MainWP Dashboard: Self-hosted WordPress Management for Agencies vtrunk
6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 5.2.2 5.3 All 153 releases
mainwp / class / class-mainwp-reports-helper.php

class-mainwp-reports-helper.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies trunk, at class/class-mainwp-reports-helper.php

142 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * MainWP Tokens Reports Class.
4 *
5 * @package MainWP/Dashboard
6 */
7
8 namespace MainWP\Dashboard;
9
10 // Exit if accessed directly.
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 }
14
15 /**
16 * Class MainWP_Reports_Helper.
17 *
18 * @package MainWP\Dashboard
19 */
20 class MainWP_Reports_Helper { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
21
22 /**
23 * Reports sites values
24 *
25 * @static
26 * @var array $reports_sites_values array values.
27 */
28 private static $reports_sites_values = array();
29
30 /**
31 * Protected static variable to hold the instance.
32 *
33 * @var null Default value.
34 */
35 private static $instance = null;
36
37 /**
38 * Create Instance.
39 *
40 * @return self $instance
41 */
42 public static function get_instance() {
43 if ( null === static::$instance ) {
44 static::$instance = new self();
45 }
46 return static::$instance;
47 }
48
49 /**
50 * Construct method.
51 */
52 public function __construct() {
53 // construct.
54 }
55
56
57 /**
58 * Method hook_get_reports_group_values()
59 *
60 * Get dashboard tokens values for reports.
61 *
62 * @param array $values Input values.
63 * @param string $group Group tokens.
64 * @param array $types Types of tokens.
65 * @param int $site_id Site ID.
66 */
67 public function hook_get_reports_group_values( $values, $group, $types, $site_id ) { // phpcs:ignore -- NOSONAR - complex.
68 if ( ! is_array( $values ) ) {
69 $values = array();
70 }
71
72 if ( ! isset( static::$reports_sites_values[ $site_id ] ) ) {
73 static::$reports_sites_values[ $site_id ] = $this->get_group_reports_data_of_site( $site_id );
74 }
75
76 if ( empty( $group ) && empty( $types ) ) {
77 return isset( static::$reports_sites_values[ $site_id ] ) ? static::$reports_sites_values[ $site_id ] : array();
78 }
79
80 if ( ! empty( $group ) && empty( $types ) ) {
81 $values[ $group ] = isset( static::$reports_sites_values[ $site_id ][ $group ] ) ? static::$reports_sites_values[ $site_id ][ $group ] : array();
82 return $values;
83 }
84
85 if ( ! empty( $group ) && is_array( $types ) ) {
86 foreach ( $types as $type ) {
87 $values[ $group ][ $type ] = isset( static::$reports_sites_values[ $site_id ][ $group ][ $type ] ) ? static::$reports_sites_values[ $site_id ][ $group ][ $type ] : array();
88 }
89 }
90
91 return $values;
92 }
93
94 /**
95 * Get tokens values of site.
96 *
97 * @param int $site_id Site ID.
98 */
99 public function get_group_reports_data_of_site( $site_id ) {
100
101 $website = MainWP_DB::instance()->get_website_by_id( $site_id );
102
103 $abandoned_plugins = MainWP_DB::instance()->get_website_option( $website, 'plugins_outdate_info' );
104 $abandoned_plugins = ! empty( $abandoned_plugins ) ? json_decode( $abandoned_plugins, true ) : array();
105
106 if ( ! is_array( $abandoned_plugins ) ) {
107 $abandoned_plugins = array();
108 }
109
110 $abandoned_themes = MainWP_DB::instance()->get_website_option( $website, 'themes_outdate_info' );
111 $abandoned_themes = ! empty( $abandoned_themes ) ? json_decode( $abandoned_themes, true ) : array();
112
113 if ( ! is_array( $abandoned_themes ) ) {
114 $abandoned_themes = array();
115 }
116
117 $wp_upgrades = MainWP_DB::instance()->get_website_option( $website, 'wp_upgrades' );
118 $wp_upgrades = ! empty( $wp_upgrades ) ? json_decode( $wp_upgrades, true ) : array();
119
120 $plugin_upgrades = json_decode( $website->plugin_upgrades, true );
121 $theme_upgrades = json_decode( $website->theme_upgrades, true );
122 $translation_upgrades = json_decode( $website->translation_upgrades, true );
123
124 return array(
125 'plugins' => array(
126 'abandoned' => $abandoned_plugins,
127 'pending' => $plugin_upgrades,
128 ),
129 'themes' => array(
130 'abandoned' => $abandoned_themes,
131 'pending' => $theme_upgrades,
132 ),
133 'wordpress' => array( // phpcs:ignore -- wordpress.
134 'pending' => array( 'wordpress' => $wp_upgrades ), // phpcs:ignore -- wordpress.
135 ),
136 'translation' => array(
137 'pending' => $translation_upgrades,
138 ),
139 );
140 }
141 }
142