| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* checks for various things |
| 5 |
* |
| 6 |
* @since 1.6.9 |
| 7 |
*/ |
| 8 |
class Advanced_Ads_Checks { |
| 9 |
|
| 10 |
/** |
| 11 |
* php version minimum 5.3 |
| 12 |
* |
| 13 |
* @return bool true if 5.3 and higher |
| 14 |
*/ |
| 15 |
public static function php_version_minimum(){ |
| 16 |
|
| 17 |
if (version_compare(phpversion(), '5.3', '>=')) { |
| 18 |
return true; |
| 19 |
} |
| 20 |
|
| 21 |
return false; |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* caching used |
| 26 |
* |
| 27 |
* @return bool true if active |
| 28 |
*/ |
| 29 |
public static function cache(){ |
| 30 |
|
| 31 |
if( ( defined( 'WP_CACHE' ) && WP_CACHE ) // general cache constant |
| 32 |
|| defined('W3TC') // W3 Total Cache |
| 33 |
|| function_exists( 'wp_super_cache_text_domain' ) // WP SUper Cache |
| 34 |
|| class_exists('zencache\\plugin') // ZenCache |
| 35 |
){ |
| 36 |
return true; |
| 37 |
} |
| 38 |
|
| 39 |
return false; |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* WordPress update available |
| 44 |
* |
| 45 |
* @return bool true if WordPress update available |
| 46 |
*/ |
| 47 |
public static function wp_update_available(){ |
| 48 |
|
| 49 |
$update_data = wp_get_update_data(); |
| 50 |
$count = absint( $update_data['counts']['wordpress'] ); |
| 51 |
|
| 52 |
if( $count ){ |
| 53 |
return true; |
| 54 |
} |
| 55 |
|
| 56 |
return false; |
| 57 |
} |
| 58 |
|
| 59 |
/** |
| 60 |
* any plugin updates available |
| 61 |
* |
| 62 |
* @return bool true if plugin updates are available |
| 63 |
*/ |
| 64 |
public static function plugin_updates_available(){ |
| 65 |
|
| 66 |
$update_data = wp_get_update_data(); |
| 67 |
$count = absint( $update_data['counts']['plugins'] ); |
| 68 |
|
| 69 |
if( $count ){ |
| 70 |
return true; |
| 71 |
} |
| 72 |
|
| 73 |
return false; |
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* check if license keys are missing or invalid |
| 78 |
* |
| 79 |
* @since 1.6.6 |
| 80 |
* @update 1.6.9 moved from Advanced_Ads_Plugin |
| 81 |
* @return true if there are missing licenses |
| 82 |
*/ |
| 83 |
public static function licenses_invalid(){ |
| 84 |
|
| 85 |
$add_ons = apply_filters( 'advanced-ads-add-ons', array() ); |
| 86 |
|
| 87 |
if( $add_ons === array() ) { |
| 88 |
return false; |
| 89 |
} |
| 90 |
|
| 91 |
foreach( $add_ons as $_add_on_key => $_add_on ){ |
| 92 |
$status = Advanced_Ads_Admin::get_instance()->get_license_status( $_add_on['options_slug'] ); |
| 93 |
|
| 94 |
// don’t check if license is valid |
| 95 |
if( $status === 'valid' ) { |
| 96 |
continue; |
| 97 |
} |
| 98 |
|
| 99 |
// retrieve our license key from the DB |
| 100 |
$licenses = Advanced_Ads_Admin::get_instance()->get_licenses(); |
| 101 |
|
| 102 |
$license_key = isset($licenses[$_add_on_key]) ? $licenses[$_add_on_key] : false; |
| 103 |
|
| 104 |
if( ! $license_key || $status !== 'valid' ){ |
| 105 |
return true; |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
return false; |
| 110 |
} |
| 111 |
|
| 112 |
/** |
| 113 |
* check if license keys are going to expire within next 14 days |
| 114 |
* |
| 115 |
* @since 1.6.6 |
| 116 |
* @update 1.6.9 moved from Advanced_Ads_Plugin |
| 117 |
* @return true if there are expiring licenses |
| 118 |
*/ |
| 119 |
public static function licenses_expire(){ |
| 120 |
|
| 121 |
$add_ons = apply_filters( 'advanced-ads-add-ons', array() ); |
| 122 |
|
| 123 |
if( $add_ons === array() ) { |
| 124 |
return false; |
| 125 |
} |
| 126 |
|
| 127 |
$now = time(); |
| 128 |
|
| 129 |
foreach( $add_ons as $_add_on_key => $_add_on ){ |
| 130 |
// don’t display error for invalid licenses |
| 131 |
if( Advanced_Ads_Admin::get_instance()->get_license_status( $_add_on['options_slug'] ) === 'invalid' ) { |
| 132 |
continue; |
| 133 |
} |
| 134 |
|
| 135 |
$expiry_date = Advanced_Ads_Admin::get_instance()->get_license_expires( $_add_on['options_slug'] ); |
| 136 |
|
| 137 |
if( $expiry_date ){ |
| 138 |
$expiry_date_t = strtotime( $expiry_date ); |
| 139 |
$in_two_weeks = time() + ( WEEK_IN_SECONDS * 2) ; |
| 140 |
// check if expiry date is within next comming 2 weeks |
| 141 |
if( $expiry_date_t < $in_two_weeks && $expiry_date_t >= $now ){ |
| 142 |
return true; |
| 143 |
} |
| 144 |
|
| 145 |
} |
| 146 |
} |
| 147 |
|
| 148 |
return false; |
| 149 |
} |
| 150 |
|
| 151 |
/** |
| 152 |
* check if license keys are already expired |
| 153 |
* |
| 154 |
* @since 1.6.6 |
| 155 |
* @update 1.6.9 moved from Advanced_Ads_Plugin |
| 156 |
* @return true if there are expired licenses |
| 157 |
*/ |
| 158 |
public static function licenses_expired(){ |
| 159 |
|
| 160 |
$add_ons = apply_filters( 'advanced-ads-add-ons', array() ); |
| 161 |
|
| 162 |
if( $add_ons === array() ) { |
| 163 |
return false; |
| 164 |
} |
| 165 |
|
| 166 |
$now = time(); |
| 167 |
|
| 168 |
foreach( $add_ons as $_add_on_key => $_add_on ){ |
| 169 |
// don’t display error for invalid licenses |
| 170 |
if( Advanced_Ads_Admin::get_instance()->get_license_status( $_add_on['options_slug'] ) === 'invalid' ) { |
| 171 |
continue; |
| 172 |
} |
| 173 |
|
| 174 |
$expiry_date = Advanced_Ads_Admin::get_instance()->get_license_expires( $_add_on['options_slug'] ); |
| 175 |
|
| 176 |
if( $expiry_date && strtotime( $expiry_date ) < $now ){ |
| 177 |
return true; |
| 178 |
} |
| 179 |
} |
| 180 |
|
| 181 |
return false; |
| 182 |
} |
| 183 |
|
| 184 |
/** |
| 185 |
* Autoptimize plugin installed |
| 186 |
* can change ad tags, especially inline css and scripts |
| 187 |
* |
| 188 |
* @link https://wordpress.org/plugins/autoptimize/ |
| 189 |
* @return bool true if Autoptimize is installed |
| 190 |
*/ |
| 191 |
public static function active_autoptimize(){ |
| 192 |
|
| 193 |
if( defined( 'AUTOPTIMIZE_CACHE_DIR' ) ){ |
| 194 |
return true; |
| 195 |
} |
| 196 |
|
| 197 |
return false; |
| 198 |
} |
| 199 |
|
| 200 |
/** |
| 201 |
* check for additional conflicting plugins |
| 202 |
* |
| 203 |
* @return arr $plugins names of conflicting plugins |
| 204 |
*/ |
| 205 |
public static function conflicting_plugins(){ |
| 206 |
|
| 207 |
$conflicting_plugins = array(); |
| 208 |
|
| 209 |
if( defined( 'Publicize_Base' )){ // JetPack Publicize module |
| 210 |
$conflicting_plugins[] = 'Jetpack – Publicize'; |
| 211 |
} |
| 212 |
|
| 213 |
return $conflicting_plugins; |
| 214 |
} |
| 215 |
|
| 216 |
/** |
| 217 |
* check for potential jQuery errors |
| 218 |
* only script, so no return, but direct output |
| 219 |
* |
| 220 |
*/ |
| 221 |
public static function jquery_ui_conflict(){ |
| 222 |
?> |
| 223 |
<div id="advads-jqueryui-conflict-message" style="display:none;" class="message error"><p><?php printf( __( 'Possible conflict between jQueryUI library, used by Advanced Ads and other libraries (probably <a href="%s">Twitter Bootstrap</a>). This might lead to misfortunate formats in forms, but should not damage features.', 'advanced-ads' ), 'http://getbootstrap.com/javascript/#js-noconflict' ); ?></p></div> |
| 224 |
<script>// string from jquery-ui source code |
| 225 |
jQuery(document).ready(function(){ |
| 226 |
var needle = 'var g="string"==typeof f,h=c.call(arguments,1)'; |
| 227 |
if ( jQuery.fn.button.toString().indexOf( needle ) === -1 || jQuery.fn.tooltip.toString().indexOf( needle ) === -1 ) { |
| 228 |
jQuery( '#advads-jqueryui-conflict-message' ).show(); |
| 229 |
} |
| 230 |
}); |
| 231 |
</script><?php |
| 232 |
} |
| 233 |
} |