PluginProbe
Plugins Condition & Site Check / 1.00
Plugins Condition & Site Check v1.00
2.01 trunk 1.00 1.01 1.02 1.03 1.04 1.05 1.06 1.07 1.08 1.09 2.00
plugins-condition / lib / class-pluginscondition.php

class-pluginscondition.php in Plugins Condition & Site Check 1.00, at lib/class-pluginscondition.php

156 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugins Condition
4 *
5 * @package Plugins Condition
6 * @subpackage PluginsCondition Main Functions
7 /*
8 Copyright (c) 2016- Katsushi Kawamori (email : dodesyoswift312@gmail.com)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; version 2 of the License.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23 $pluginscondition = new PluginsCondition();
24
25 /** ==================================================
26 * Main Functions
27 */
28 class PluginsCondition {
29
30 /** ==================================================
31 * Construct
32 *
33 * @since 1.14
34 */
35 public function __construct() {
36
37 add_filter( 'plugin_row_meta', array( $this, 'main_func' ), 10, 2 );
38
39 }
40
41 /** ==================================================
42 * Main
43 *
44 * @param array $links links.
45 * @param string $file file.
46 * @return array $links links.
47 * @since 1.00
48 */
49 public function main_func( $links, $file ) {
50
51 $slugs = explode( DIRECTORY_SEPARATOR, $file );
52 $slug = $slugs[0];
53 if ( ! empty( $slug ) ) {
54 $call_apis = array();
55 if ( get_transient( 'plg_cond_datas_' . $slug . '_' . get_locale() ) ) {
56 /* Get cache */
57 $call_apis = get_transient( 'plg_cond_datas_' . $slug . '_' . get_locale() );
58 } else {
59 if ( ! function_exists( 'plugins_api' ) ) {
60 require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
61 }
62 /* Call API */
63 $call_api = plugins_api(
64 'plugin_information',
65 array(
66 'slug' => $slug,
67 'fields' => array(
68 'tested' => true,
69 'last_updated' => true,
70 ),
71 )
72 );
73 if ( is_wp_error( $call_api ) ) {
74 $dummy = 0; /* skip */
75 } else {
76 $call_apis = array(
77 'tested' => $call_api->tested,
78 'last_updated' => $call_api->last_updated,
79 );
80
81 /* Set cache */
82 set_transient( 'plg_cond_datas_' . $slug . '_' . get_locale(), $call_apis, 86400 );
83 }
84 }
85 }
86 if ( ! empty( $call_apis ) ) {
87 $wp_ver = get_bloginfo( 'version' );
88 $pg_ver = $call_apis['tested'];
89 if ( $pg_ver === $wp_ver ) {
90 $color = 'green';
91 } else {
92 $color = 'red';
93 }
94 $pg_update_time = strtotime( $call_apis['last_updated'] );
95 $now = time();
96 $time_lag = $now - $pg_update_time;
97 $time_lag_date = $time_lag / 86400;
98 if ( 1 > $time_lag_date ) {
99 $color = 'green';
100 $pg_date = __( 'within 24 hours', 'plugins-condition' );
101 } else if ( 1 <= $time_lag_date && 7 > $time_lag_date ) {
102 $color = 'green';
103 $day = floor( $time_lag_date );
104 if ( 1 == $day ) {
105 /* translators: day */
106 $pg_date = sprintf( __( '%1$d day ago', 'plugins-condition' ), 1 );
107 } else {
108 /* translators: days */
109 $pg_date = sprintf( __( '%1$d days ago', 'plugins-condition' ), $day );
110 }
111 } else if ( 7 <= $time_lag_date && 30 > $time_lag_date ) {
112 $color = 'green';
113 $week = floor( $time_lag_date / 7 );
114 if ( 1 == $week ) {
115 /* translators: week */
116 $pg_date = sprintf( __( '%1$d week ago', 'plugins-condition' ), 1 );
117 } else {
118 /* translators: weeks */
119 $pg_date = sprintf( __( '%1$d weeks ago', 'plugins-condition' ), $week );
120 }
121 } else if ( 30 <= $time_lag_date && 365 > $time_lag_date ) {
122 $color = 'green';
123 $month = floor( $time_lag_date / 30 );
124 if ( 1 == $month ) {
125 /* translators: month */
126 $pg_date = sprintf( __( '%1$d month ago', 'plugins-condition' ), 1 );
127 } else {
128 /* translators: months */
129 $pg_date = sprintf( __( '%1$d months ago', 'plugins-condition' ), $month );
130 }
131 } else {
132 $color = 'red';
133 $year = floor( $time_lag_date / 365 );
134 if ( 1 == $year ) {
135 /* translators: year */
136 $pg_date = sprintf( __( '%1$d year ago', 'plugins-condition' ), 1 );
137 } else {
138 /* translators: years */
139 $pg_date = sprintf( __( '%1$d years ago', 'plugins-condition' ), $year );
140 }
141 }
142
143 $links[] .= '<span style="color: ' . $color . ';">' . $pg_ver . '</span>';
144 $links[] .= '<span style="color: ' . $color . ';">' . $pg_date . '</span>';
145 } else {
146 $links[] .= '<span style="color: red;">' . __( 'unofficial', 'plugins-condition' ) . '</span>';
147 }
148
149 return $links;
150
151 }
152
153 }
154
155
156