PluginProbe
Property Hive / 1.4.53
Property Hive v1.4.53
2.3.0 2.2.6 2.2.5 2.2.4 2.2.3 2.2.2 1.4.46 1.4.47 1.4.48 1.4.49 1.4.5 1.4.50 1.4.51 1.4.52 1.4.53 1.4.54 1.4.55 1.4.56 1.4.57 1.4.58 1.4.59 1.4.6 1.4.60 1.4.61 1.4.62 All 260 releases
propertyhive / includes / admin / class-ph-admin-plugin-updates.php

class-ph-admin-plugin-updates.php in Property Hive 1.4.53, at includes/admin/class-ph-admin-plugin-updates.php

199 lines 6.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Manages Property Hive plugin updating on the Plugins screen, showing warning and messages where applicable such as key updates which might break things
4 *
5 * @package PropertyHive/Admin
6 * @version 1.0.0
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13
14 /**
15 * Class PH_Plugin_Updates
16 */
17 class PH_Plugin_Updates {
18
19 /**
20 * The upgrade notice shown inline.
21 *
22 * @var string
23 */
24 protected $upgrade_notice = '';
25
26 /**
27 * Constructor.
28 */
29 public function __construct() {
30 add_action( 'in_plugin_update_message-propertyhive/propertyhive.php', array( $this, 'in_plugin_update_message' ), 10, 2 );
31
32 if ( is_network_admin() || ! is_multisite() )
33 {
34 $license = PH()->license->get_current_license();
35
36 $valid_license = false;
37
38 if ( is_array($license) && empty($license) && get_option( 'propertyhive_license_key', '' ) != '' )
39 {
40
41 }
42 elseif ( isset($license['active']) && $license['active'] != '1' )
43 {
44
45 }
46 else
47 {
48 if ( isset($license['expires_at']) && $license['expires_at'] != '' )
49 {
50 if ( strtotime($license['expires_at']) <= time() )
51 {
52 // Expired
53
54 }
55 elseif (
56 strtotime($license['expires_at']) > time() &&
57 strtotime($license['expires_at']) < (time() + 30 * 24 * 60 * 60)
58 )
59 {
60 // Expires in less than 30 days
61
62 }
63 elseif (strtotime($license['expires_at']) > time())
64 {
65 // Valid
66 $valid_license = true;
67 }
68 }
69 }
70
71 if ( !$valid_license )
72 {
73 $add_ons = @file_get_contents('http://wp-property-hive.com/add-ons-json.php');
74
75 if ($add_ons !== FALSE && $add_ons !== '')
76 {
77 $add_ons = json_decode($add_ons);
78
79 if ($add_ons !== FALSE && !empty($add_ons))
80 {
81 foreach ($add_ons as $add_on)
82 {
83 $url = trim($add_on->url, '/');
84
85 if (
86 isset($add_on->wordpress_plugin_file) && $add_on->wordpress_plugin_file != '' && $add_on->wordpress_plugin_file != false &&
87 isset($add_on->wordpress_version_option_name) && $add_on->wordpress_version_option_name != '' && $add_on->wordpress_version_option_name != false
88 )
89 {
90 $plugin_file = $add_on->wordpress_plugin_file;
91
92 if ( is_plugin_active($plugin_file) )
93 {
94 $current_version = get_option($add_on->wordpress_version_option_name, '');
95
96 if ( $current_version != '' )
97 {
98 // check if add on update available
99 $new_version = $add_on->version;
100
101 if( version_compare($new_version, $current_version) == 1 )
102 {
103 add_action( 'after_plugin_row_' . $plugin_file, array( $this, 'test' ), 10, 3 );
104 }
105 }
106 }
107 }
108 }
109 }
110 }
111 }
112 }
113 }
114
115 public function test( $plugin_file, $plugin_data, $status )
116 {
117 if ( is_network_admin() ) {
118 $active_class = is_plugin_active_for_network( $plugin_file ) ? ' active' : '';
119 } else {
120 $active_class = is_plugin_active( $plugin_file ) ? ' active' : '';
121 }
122
123 echo '<tr class="plugin-update-tr' . $active_class . '">
124 <td colspan="3" class="plugin-update colspanchange">
125 <div class="update-message notice inline notice-warning notice-alt">
126 <p>An update is available for this add on. It is recommended that you update to ensure you receive the latest features and bug fixes. You can access all updates to any purchased add ons for 12 months by <a href="https://wp-property-hive.com/product/12-month-license-key/" target="_blank">purchasing a license key</a>.</p>
127 </div>
128 </td>
129 </tr>';
130 }
131
132 /**
133 * Show plugin changes on the plugins screen.
134 *
135 * @param array $args Unused parameter.
136 * @param stdClass $response Plugin update response.
137 */
138 public function in_plugin_update_message( $args, $response ) {
139 $this->new_version = $response->new_version;
140 $this->upgrade_notice = $this->get_upgrade_notice( $response->new_version );
141
142 echo apply_filters( 'propertyhive_in_plugin_update_message', $this->upgrade_notice ? '<br><span style="color:#900">' . wp_kses_post( $this->upgrade_notice ) . '</span>' : '' ); // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped
143 }
144
145 /**
146 * Get the upgrade notice from WordPress.org.
147 *
148 * @param string $version Property Hive new version.
149 * @return string
150 */
151 protected function get_upgrade_notice( $new_version ) {
152 $transient_name = 'ph_upgrade_notice_' . $new_version;
153 $upgrade_notice = get_transient( $transient_name );
154
155 if ( false === $upgrade_notice ) {
156 $response = wp_safe_remote_get( 'https://plugins.svn.wordpress.org/propertyhive/trunk/README.txt' );
157
158 if ( ! is_wp_error( $response ) && ! empty( $response['body'] ) ) {
159 $upgrade_notice = $this->parse_update_notice( $response['body'], $new_version );
160 set_transient( $transient_name, $upgrade_notice, DAY_IN_SECONDS );
161 }
162 }
163 return $upgrade_notice;
164 }
165
166 /**
167 * Parse update notice from readme file.
168 *
169 * @param string $content Property Hive readme file content.
170 * @param string $new_version Property Hive new version.
171 * @return string
172 */
173 private function parse_update_notice( $content, $new_version ) {
174
175 $upgrade_notice = '';
176
177 $notices = explode("== Upgrade Notice ==", $content, 2);
178
179 if ( count($notices) < 2 ) { return ''; }
180
181 $notices = (array) preg_split( '~[\r\n]+~', trim( $notices[1] ) );
182
183 for ( $i = 0; $i < count($notices); ++$i )
184 {
185 $version = trim(str_replace("=", "", $notices[$i]));
186 if ( version_compare( $version, PH_VERSION, '>' ) )
187 {
188 $upgrade_notice .= '<br><strong>- ';
189 $upgrade_notice .= preg_replace( '~\[([^\]]*)\]\(([^\)]*)\)~', '<a href="${2}">${1}</a>', $notices[$i+1] );
190 $upgrade_notice .= '</strong>';
191 }
192
193 ++$i;
194 }
195
196 return wp_kses_post( $upgrade_notice );
197 }
198 }
199 new PH_Plugin_Updates();