public
Created

Better Plugin Compatibility Control - Hacked

  • Download Gist
gistfile1.aw
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
<?php
/**
* The main plugin file
*
* @package WordPress_Plugins
* @subpackage BetterPluginCompatibilityControl
*/
/*
Plugin Name: Better Plugin Compatibility Control
Version: 3.4
Plugin URI: http://www.schloebe.de/wordpress/better-plugin-compatibility-control-plugin/
Description: Adds version compatibility info to the plugins page to inform the admin at a glance if a plugin is compatible with the current WP version.
Author: Oliver Schl&ouml;be
Author URI: http://www.schloebe.de/
 
 
Copyright 2008-2012 Oliver Schlöbe (email : scripts@schloebe.de)
 
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
 
 
/**
* Pre-2.6 compatibility
*/
if ( !defined( 'WP_CONTENT_URL' ) )
define( 'WP_CONTENT_URL', get_option( 'siteurl' ) . '/wp-content' );
if ( !defined( 'WP_CONTENT_DIR' ) )
define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
if ( !defined( 'WP_PLUGIN_URL' ) )
define( 'WP_PLUGIN_URL', WP_CONTENT_URL. '/plugins' );
if ( !defined( 'WP_PLUGIN_DIR' ) )
define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' );
 
/**
* Define the plugin version
*/
define("BPCC_VERSION", "3.4");
 
/**
* Define the global var AMEISWP25, returning bool if at least WP 2.3 is running
*/
define('BPCCISWP28', version_compare($GLOBALS['wp_version'], '2.7.999', '>='));
 
/**
* Define the plugin path slug
*/
define("BPCC_PLUGINPATH", "/" . plugin_basename( dirname(__FILE__) ) . "/");
 
/**
* Define the plugin full url
*/
define("BPCC_PLUGINFULLURL", WP_PLUGIN_URL . BPCC_PLUGINPATH );
 
/**
* Define the plugin full directory
*/
define("BPCC_PLUGINFULLDIR", WP_PLUGIN_DIR . BPCC_PLUGINPATH );
 
 
/**
* The BetterPluginCompatibilityControl class
*
* @package WordPress_Plugins
* @subpackage BetterPluginCompatibilityControl
* @since 1.0
* @author scripts@schloebe.de
*/
class BetterPluginCompatibilityControl {
const VERSION_OFFSET = 1;
/**
* The BetterPluginCompatibilityControl class constructor
* initializing required stuff for the plugin
*
* @since 1.0
* @author scripts@schloebe.de
*/
function betterplugincompatibilitycontrol() {
if ( !BPCCISWP28 ) {
add_action('admin_notices', array(&$this, 'wpVersionFailed'));
return;
}
add_action('admin_init', array(&$this, 'bpcc_load_textdomain'));
add_action('admin_init', array(&$this, 'bpcc_init'));
}
/**
* Initialize and load the plugin stuff
*
* @since 1.0
* @uses $pagenow
* @author scripts@schloebe.de
*/
function bpcc_init() {
global $pagenow;
if ( !function_exists("add_action") ) return;
if((defined('WP_ALLOW_MULTISITE') && WP_ALLOW_MULTISITE && is_network_admin())) {
add_filter('network_admin_plugin_action_links', array(&$this, 'bpcc_pluginversioninfo'), 10, 2);
if( current_user_can( 'manage_network_plugins' ) ) {
add_filter('plugin_action_links', array(&$this, 'bpcc_pluginversioninfo'), 10, 2);
}
} else {
if( current_user_can( 'install_plugins' ) ) {
add_filter('plugin_action_links', array(&$this, 'bpcc_pluginversioninfo'), 10, 2);
}
}
if( $pagenow == 'plugins.php' ) {
add_action('admin_head', array(&$this, 'bpcc_css_admin_header'));
add_action('admin_head', wp_enqueue_script( 'jquery' ) && version_compare($GLOBALS['wp_version'], '2.7.99', '<') );
if( version_compare($GLOBALS['wp_version'], '2.7.99', '>') && version_compare($GLOBALS['wp_version'], '3.0.99', '<') ) {
add_action('admin_head', wp_enqueue_script( 'bpcc_dom', BPCC_PLUGINFULLURL . "js/bbpc_dom.2.8.js", array('jquery'), BPCC_VERSION ) );
}
if( version_compare($GLOBALS['wp_version'], '3.0.99', '>') ) {
add_action('admin_head', wp_enqueue_script( 'bpcc_dom', BPCC_PLUGINFULLURL . "js/bbpc_dom.3.1.js", array('jquery'), BPCC_VERSION ) );
}
}
}
 
 
/**
* Writes the css stuff into page header needed for the plugin to look good
*
* @since 1.0
* @author scripts@schloebe.de
*/
function bpcc_css_admin_header() {
echo '
<style type="text/css">
.bpcc_wrapper {
display: none;
}
 
.bpcc_minversion {
border-color: #bbb;
color: #aaa;
text-shadow: 0 1px 0 #FFFFFF;
cursor: help;
padding: 0px;
text-decoration: none;
font-weight: 200;
height: 8px;
}
 
.bpcc_maxversion {
border-color: #bbb;
color: #aaa;
text-shadow: 0 1px 0 #FFFFFF;
cursor: help;
padding: 0px;
text-decoration: none;
font-weight: 200;
height: 8px;
}
 
.bpcc_red {
border-color: #CF6B6B;
background: url(' . BPCC_PLUGINFULLURL . 'img/info.gif) #FFF7F7 2px center no-repeat;
color: #A35457;
padding: 1px 2px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
padding-left: 9px;
}
 
.bpcc_green {
border-color: #A4CF6B;
color: #81A354;
background: #F8FFEF;
padding: 1px 2px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
}
</style>' . "\n";
}
/**
* Add plugin version dependency info
*
* @since 1.0
* @author scripts@schloebe.de
*/
function bpcc_pluginversioninfo( $links, $file ) {
$minpluginver = $maxpluginver = '';
$bpcc_readme = WP_PLUGIN_DIR . '/' . dirname( $file ) . '/' . 'readme.txt';
if( file_exists( $bpcc_readme ) ) {
$fp = @fopen( $bpcc_readme, 'r' );
$pluginver_data = @fread( $fp, 8192 );
fclose( $fp );
preg_match( '|Requires at least:(.*)|i', $pluginver_data, $plugin_minversion );
preg_match( '|Tested up to:(.*)|i', $pluginver_data, $plugin_maxversion );
 
$minpluginver = $plugin_minversion[self::VERSION_OFFSET];
$maxpluginver = $plugin_maxversion[self::VERSION_OFFSET];
} else {
require_once(ABSPATH . 'wp-admin/includes/plugin-install.php');
$info = plugins_api('plugin_information', array('fields' => array('tested' => true, 'requires' => true, 'rating' => false, 'downloaded' => false, 'downloadlink' => false, 'last_updated' => false, 'homepage' => false, 'tags' => false, 'sections' => false, 'compatibility' => false, 'author' => false, 'author_profile' => false, 'contributors' => false, 'added' => false), 'slug' => dirname( $file ) ));
if (!is_wp_error ($info)) {
$minpluginver = $info->requires;
$maxpluginver = $info->tested;
}
}
if( $minpluginver != '' || $maxpluginver != '' ) {
$addminverclass = ( version_compare(trim( $minpluginver ), $GLOBALS['wp_version'], '>') ) ? ' bpcc_red' : ' bpcc_green';
$addminvertitle = ( version_compare(trim( $minpluginver ), $GLOBALS['wp_version'], '>') ) ? __('Warning: This plugin has not been tested with your current version of WordPress.', 'better-plugin-compatibility-control') : __('This plugin has been tested successfully with your current version of WordPress.', 'better-plugin-compatibility-control');
$addminverinfo = (count( $minpluginver )>0) ? '<span class="bpcc_minversion' . $addminverclass . '" title="' . $addminvertitle . '">' . trim( $minpluginver ) . '</span>' : '<span class="bpcc_minversion" title="' . __('No compatibility info for this plugin available.', 'better-plugin-compatibility-control') . '">' . __('N/A', 'better-plugin-compatibility-control') . '</span>';
$addmaxverclass = ( version_compare(trim( $maxpluginver ), $GLOBALS['wp_version'], '<') ) ? ' bpcc_red' : ' bpcc_green';
$addminvertitle = ( version_compare(trim( $maxpluginver ), $GLOBALS['wp_version'], '<') ) ? __('Warning: This plugin has not been tested with your current version of WordPress.', 'better-plugin-compatibility-control') : __('This plugin has been tested successfully with your current version of WordPress.', 'better-plugin-compatibility-control');
$addmaxverinfo = (count( $maxpluginver )>0) ? '<span class="bpcc_maxversion' . $addmaxverclass . '" title="' . $addminvertitle . '">' . trim( $maxpluginver ) . '</span>' : '<span class="bpcc_maxversion" title="' . __('No compatibility info for this plugin available.', 'better-plugin-compatibility-control') . '">' . __('N/A', 'better-plugin-compatibility-control') . '</span>';
$addverinfo = '<span class="bpcc_wrapper">' . $addminverinfo . ' &ndash; ' . $addmaxverinfo . '';
} else {
$addverinfo = '<span class="bpcc_wrapper"><span class="bpcc_maxversion" title="' . __('No readme.txt file for this plugin found. Contact the plugin author!', 'better-plugin-compatibility-control') . '">' . __('No compatibility data found', 'better-plugin-compatibility-control') . '</span></span>';
}
$links = array_merge( $links, array( $addverinfo ) );
return $links;
}
/**
* Initialize and load the plugin textdomain
*
* @since 1.0
* @author scripts@schloebe.de
*/
function bpcc_load_textdomain() {
if ( function_exists('load_plugin_textdomain') ) {
if ( !defined('WP_PLUGIN_DIR') ) {
load_plugin_textdomain('better-plugin-compatibility-control', str_replace( ABSPATH, '', dirname(__FILE__) ) . '/languages');
} else {
load_plugin_textdomain('better-plugin-compatibility-control', false, dirname(plugin_basename(__FILE__)) . '/languages');
}
}
}
/**
* Checks for the version of WordPress,
* and adds a message to inform the user
* if required WP version is less than 2.8
*
* @since 1.0
* @author scripts@schloebe.de
*/
function wpVersionFailed() {
echo "<div id='wpversionfailedmessage' class='error fade'><p>" . __('Better Plugin Compatibility Control requires at least WordPress 2.8!', 'better-plugin-compatibility-control') . "</p></div>";
}
}
 
if ( class_exists('BetterPluginCompatibilityControl') && is_admin() ) {
$betterplugincompatibilitycontrol = new BetterPluginCompatibilityControl();
}
?>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.