= 3.0 and PHP >= 5.1.2
*/
// Define constants
define("AMAZONAUTOLINKSKEY", "amazonautolinks");
define("AMAZONAUTOLINKSPLUGINNAME", "Amazon Auto Links");
// Plugin Requirements
add_action( 'admin_init', 'AmazonAutoLinks_Requirements' );
// Register Classes
add_action('plugins_loaded', 'AmazonAutoLinks_RegisterClasses');
// Admin Page
add_action( 'plugins_loaded', create_function( '', '$oAALAdmin = new AmazonAutoLinks_Admin;' ) );
// Custom Admin CSS
add_action('admin_head', 'AmazonAutoLinks_CustomCSS');
// Widgets
add_action('widgets_init', 'AmazonAutoLinks_Widgets');
// for the plugin admin panel theming
function AmazonAutoLinks_CustomCSS() {
global $wp_version;
if ($_GET['page'] != AMAZONAUTOLINKSKEY)
return;
// if the option page of this plugin is loaded
if (IsSet($_POST[AMAZONAUTOLINKSKEY]['tab202']['proceedbutton']) || IsSet($_POST[AMAZONAUTOLINKSKEY]['tab100']['proceedbutton'])) {
$numTab = isset($_POST[AMAZONAUTOLINKSKEY]['tab202']['proceedbutton']) ? 202 : 100;
$numImageSize = $_POST[AMAZONAUTOLINKSKEY]['tab' . $numTab]['imagesize'];
$numIframeWidth = $numImageSize * 2 + 480; // $strFieldName = $this->pluginkey . '[tab' . $numTabnum . '][imagesize]'
if ( version_compare($wp_version, '3.1.9', "<" ) ) // if the WordPress version is below 3.2
$strIframeWidth = $numIframeWidth < 1180 ? 'width:100%;' : 'width:' . $numIframeWidth . 'px;'; // set the minimum width
else // if the WordPress version is above 3.2
$strIframeWidth = $numIframeWidth < 1180 ? 'width:1180px;' : 'width:' . $numIframeWidth . 'px;'; // set the minimum width
echo '';
} else if ($_GET['tab'] == 400) // for the upgrading to pro tab; the table needs additional styles
echo '';
}
// the function used to embed the Amazon products unit in a theme
function AmazonAutoLinks($unitlabel) {
$options = get_option(AMAZONAUTOLINKSKEY);
if (!IsSet($options['units'][$unitlabel])) {
echo AMAZONAUTOLINKSPLUGINNAME . ' ';
_e('Error: No such unit label exists.', 'amazonautolinks');
return;
}
$oAAL = new AmazonAutoLinks_Core($options['units'][$unitlabel], $options['general']);
echo $oAAL->fetch( $oAAL->UrlsFromUnitLabel($unitlabel, $options));
}
function AmazonAutoLinks_RegisterClasses() {
/*
This function reads class files in wp-include/plugins/[this-plugin-path]/classes
and registers them to be auto-loaded so that require() or include() in each class file is no longer necessary.
After that, it defines new clesses based on the regstered class names.
The class files must have a class definition with the file name without file extension.
This function should be trigered with the plugins_loaded() function; otherwise, the "header already sent" error may occur during
the plugin activation.
*/
global $strAALDirPath, $arrAALPHPfiles; // needs to be global since the following create_function() needs the values.
// Register classes
$strAALDirPath = dirname(__FILE__) . '/classes/';
$arrAALPHPfiles = array_map(create_function( '$a', 'return basename($a, ".php");' ), glob($strAALDirPath . '*.php'));
spl_autoload_register(
create_function('$class_name', '
global $arrAALPHPfiles, $strAALDirPath;
if (in_array($class_name, $arrAALPHPfiles))
include($strAALDirPath . $class_name . ".php");' )
);
// Define classes
$strClassNamePrefix = 'AmazonAutoLinks_'; // define a prefix of file name to avoid executing harmful code in file names.
foreach ($arrAALPHPfiles as $strFileName) {
// apply security filters
if (substr($strFileName, 0, strlen($strClassNamePrefix)) != $strClassNamePrefix)
continue; // filter out files whhch don't start with the prefix
if (preg_match("/[#;\(\){}]/", $strFileName))
continue; // if the file name contains characters looking like PHP code, skip it
// $strFileName: either ending with _ or Pro e.g. AmazonAutoLinks_Admin_ / AmazonAutoLinks_Admin_Pro
if (substr($strFileName, -4) == '_Pro') { // case, Pro
$strClassNamePro = $strFileName; // leave it as it is, e.g. AmazonAutoLinks_Admin_Pro -> AmazonAutoLinks_Admin_Pro
$strClassName = substr($strFileName, 0, -4); // removes the last four caracters. e.g. AmazonAutoLinks_Admin_Pro -> AmazonAutoLinks_Admin
} else { // case, Standard
$strClassNamePro = $strFileName . 'Pro'; // adds Pro, e.g. amazonautolinks_admin_ -> amazonautolinks_admin_pro
$strClassName = substr($strFileName, 0, -1); // removes the last one character. e.g. amazonautolinks_admin_ -> amazonautolinks_admin
}
// delare classes
if (class_exists($strClassNamePro) && !class_exists($strClassName))
eval("class $strClassName extends $strClassNamePro {};");
else if (class_exists($strFileName) && !class_exists($strClassName))
eval("class $strClassName extends $strFileName {};");
}
}
// requirements for this plugin to work in PHP version >= 5.1.2
function AmazonAutoLinks_Requirements() {
global $wp_version, $wpdb;
$plugin = plugin_basename( __FILE__ );
$plugin_data = get_plugin_data( __FILE__, false );
$numPHPver='5.1.2'; // required php version
$numWPver='3.0'; // required WordPress version
$bSufficient = True;
$strMsg = '';
if ( version_compare(phpversion(), $numPHPver, "<" ) ) {
$bSufficient = False;
$strMsg .= $plugin_data['Name'] . ': ' . __('The plugin requires the following PHP version or higher:', 'amazonautolinks')
. ' ' . $numPHPver . ' ' . __('Your PHP version is:', 'amazonautolinks') . phpversion()
. ' ' . __('Deactivating the plugin.', 'amazonautolinks') . '
';
}
if ( version_compare($wp_version, $numWPver, "<" ) ) {
$bSufficient = False;
$strMsg .= $plugin_data['Name'] . ': ' . __('The plugin requires the following WordPress version or higher:', 'amazonautolinks')
. ' ' . $numWPver . ' ' . __('Your WordPress version is:', 'amazonautolinks') . $wp_version . ' '
. __('Deactivating the plugin.', 'amazonautolinks') ;
}
if (!$bSufficient && is_plugin_active($plugin)) {
echo '
' . $strMsg . '