'https://www.amazon.com.au/exec/obidos/ASIN/%s/%s', 'BR' => 'https://www.amazon.com.br/exec/obidos/ASIN/%s/%s', 'CA' => 'https://www.amazon.ca/exec/obidos/ASIN/%s/%s', 'DE' => 'https://www.amazon.de/exec/obidos/ASIN/%s/%s', 'FR' => 'https://www.amazon.fr/exec/obidos/ASIN/%s/%s', 'JP' => 'https://www.amazon.jp/exec/obidos/ASIN/%s/%s', 'MX' => 'https://www.amazon.com.mx/exec/obidos/ASIN/%s/%s', 'UK' => 'https://www.amazon.co.uk/exec/obidos/ASIN/%s/%s', 'US' => 'https://www.amazon.com/exec/obidos/ASIN/%s/%s', 'IN' => 'https://www.amazon.in/exec/obidos/ASIN/%s/%s', 'IT' => 'https://www.amazon.it/exec/obidos/ASIN/%s/%s', 'ES' => 'https://www.amazon.es/exec/obidos/ASIN/%s/%s', 'CN' => 'https://www.amazon.cn/exec/obidos/ASIN/%s/%s', ); /** * @var string */ protected $amazon_shop_url; /** * template placeholder prefix */ protected $tpl_prefix = '{$'; /** * template placeholder postfix */ protected $tpl_postfix = '}'; /** * template dir */ protected $tpl_dir = 'tpl'; /** * AmazonSimpleAdmin bb tag regex */ protected $bb_regex = '#\[asa(.[^\]]*|)\]([\w-]+)\[/asa\]#Usi'; /** * AmazonSimpleAdmin bb tag regex */ protected $bb_regex_collection = '#\[asa_collection(.[^\]]*|)\]([\w-\s]+)\[/asa_collection\]#Usi'; /** * param separator regex */ protected $_regex_param_separator = '/(,)(?=(?:[^"]|"[^"]*")*$)/m'; /** * user's Amazon Access Key ID */ protected $_amazon_api_key; /** * user's Amazon Access Key ID * @var string */ protected $_amazon_api_secret_key = ''; /** * user's Amazon Tracking ID */ protected $amazon_tracking_id; /** * selected country code */ protected $_amazon_country_code = 'US'; /** * @var */ protected $_amazon_api_connection_type = 'http'; /** * product preview status * @var bool */ protected $_product_preview = false; /** * @var bool */ protected $_asa_use_flat_box_default = false; /** * product preview status * @var bool */ protected $_parse_comments = false; /** * use AJAX * @var bool */ protected $_async_load = false; /** * use only amazon prices for placeholder $AmazonPrice * @var bool */ protected $_asa_use_amazon_price_only = false; /** * internal param delimiter * @var string */ protected $_internal_param_delimit = '[#asa_param_delim#]'; /** * * @var string */ protected $task; /** * wpdb object */ protected $db; /** * collection object */ protected $collection; protected $error = array(); protected $success = array(); /** * the amazon webservice object */ protected $amazon; /** * @var null|bool */ protected $_isCache; /** * the cache object * @var null|AsaZend_Cache_Core|AsaZend_Cache_Frontend_File */ protected $cache; /** * @var Asa_Debugger */ protected $_debugger; /** * @var debugger error message */ protected $_debugger_error; /** * @var AsaEmail */ protected $_email; protected $_tplCssBuffer = array(); /** * constructor */ public function __construct ($wpdb) { //$libdir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'lib'; //set_include_path(get_include_path() . PATH_SEPARATOR . $libdir); require_once ASA_LIB_DIR . 'AsaZend/Uri/Http.php'; require_once ASA_LIB_DIR . 'AsaZend/Service/Amazon.php'; require_once ASA_LIB_DIR . 'AsaZend/Service/Amazon/Accessories.php'; require_once ASA_LIB_DIR . 'AsaZend/Service/Amazon/EditorialReview.php'; require_once ASA_LIB_DIR . 'AsaZend/Service/Amazon/Image.php'; require_once ASA_LIB_DIR . 'AsaZend/Service/Amazon/Item.php'; require_once ASA_LIB_DIR . 'AsaZend/Service/Amazon/ListmaniaList.php'; require_once ASA_LIB_DIR . 'AsaZend/Service/Amazon/Offer.php'; require_once ASA_LIB_DIR . 'AsaZend/Service/Amazon/OfferSet.php'; require_once ASA_LIB_DIR . 'AsaZend/Service/Amazon/Query.php'; require_once ASA_LIB_DIR . 'AsaZend/Service/Amazon/ResultSet.php'; require_once ASA_LIB_DIR . 'AsaZend/Service/Amazon/SimilarProduct.php'; require_once ASA_LIB_DIR . 'Asa/Util/Buffer.php'; require_once ASA_LIB_DIR . 'Asa/ItemBuffer.php'; require_once dirname(__FILE__) . '/AsaWidget.php'; register_activation_hook( 'amazonsimpleadmin/amazonsimpleadmin.php', array($this, 'onActivation') ); register_uninstall_hook( 'amazonsimpleadmin/amazonsimpleadmin.php', array('AmazonSimpleAdmin', 'onUninstall') ); if ($this->isDebug()) { $this->_initDebugger(); } if (isset($_GET['task'])) { $this->task = strip_tags($_GET['task']); } $this->tpl_dir = dirname(__FILE__) . DIRECTORY_SEPARATOR . $this->tpl_dir . DIRECTORY_SEPARATOR; $this->db = $wpdb; $this->cache = $this->_initCache(); // init translation load_plugin_textdomain('asa1', false, 'amazonsimpleadmin/lang'); // Hook for adding admin menus add_action('admin_menu', array($this, 'createAdminMenu')); // register shortcode handlers add_shortcode( 'asa', array($this, 'handleShortcodeAsa')); add_shortcode( 'asa_collection', array($this, 'handleShortcodeAsaCollection')); // Hooks for adding shortcode support add_filter('the_excerpt', 'do_shortcode'); add_filter('the_excerpt_feed', 'do_shortcode'); add_filter('the_excerpt_rss', 'do_shortcode'); add_filter('the_content_feed', 'do_shortcode'); add_filter('the_content_rss', 'do_shortcode'); add_filter('widget_text', 'do_shortcode'); if (!get_option('_asa_hide_meta_link')) { add_action('wp_meta', array($this, 'addMetaLink')); } $this->_getAmazonUserData(); $this->_loadOptions(); if ($this->_parse_comments == true) { // Hook for adding content filter for user comments // Feature request from Sebastian Steinfort //add_filter('comment_text', array($this, 'parseContent'), 1); add_filter('comment_text', 'do_shortcode'); } if ($this->_product_preview == true) { add_action('wp_footer', array($this, 'addProductPreview')); } add_filter('upgrader_pre_install', array($this, 'onPreInstall'), 10, 2); add_filter('upgrader_post_install', array($this, 'onPostInstall'), 10, 2); add_action('in_plugin_update_message-amazonsimpleadmin/amazonsimpleadmin.php', array($this, 'handleUpdateMessage')); add_filter('plugin_action_links_amazonsimpleadmin/amazonsimpleadmin.php', array($this, 'addPluginActionLinks')); $this->amazon = $this->connect(); if (get_option('_asa_error_email_notification')) { require_once dirname(__FILE__) . '/AsaEmail.php'; $this->_email = AsaEmail::getInstance(); } $this->_beforeOutput($this->task); $this->_initCallback(); } public function onActivation() { $firstActivation = get_option('_asa_first_activation'); if (empty($firstActivation)) { // only on first activation update_option('_asa_cache_active', 1); update_option('_asa_cache_skip_on_admin', 1); update_option('_asa_first_activation', self::VERSION); } // on every activation require_once dirname(__FILE__) . '/AsaCapabilities.php'; $caps = new AsaCapabilities(); $caps->install(); } public static function onUninstall() { delete_option('_asa_first_activation'); delete_option('_asa_cache_active'); delete_option('_asa_cache_skip_on_admin'); delete_option('_asa_product_preview'); delete_option('_asa_use_flat_box_default'); delete_option('_asa_parse_comments'); delete_option('_asa_async_load'); delete_option('_asa_ajax_css_ani'); delete_option('_asa_hide_meta_link'); delete_option('_asa_use_short_amazon_links'); delete_option('_asa_use_amazon_price_only'); delete_option('_asa_debug'); delete_option('_asa_get_rating_alternative'); delete_option('_asa_custom_widget_class'); delete_option('_asa_replace_empty_main_price'); delete_option('_asa_disable_prefetch'); delete_option('_asa_error_handling'); delete_option('_asa_admin_error_frontend'); delete_option('_asa_use_error_tpl'); delete_option('_asa_error_email_notification'); delete_option('_asa_error_email_notification_bridge_page_id'); delete_option('_asa_cache_lifetime'); delete_option('_asa_cache_dir'); delete_option('_asa_cache_active'); delete_option('_asa_cache_disable_variable_lifetime'); delete_option('_asa_amazon_api_key'); delete_option('_asa_amazon_api_secret_key'); delete_option('_asa_amazon_tracking_id'); delete_option('_asa_api_connection_type'); delete_option('_asa_amazon_country_code'); delete_option('_asa_donated'); delete_option('_asa_newsletter'); require_once dirname(__FILE__) . '/AsaCapabilities.php'; $caps = new AsaCapabilities(); $caps->uninstall(); } /** * */ public function addPluginActionLinks($links) { $links[] = '' . __('Settings', 'asa1') . ''; return $links; } protected function _initCallback() { add_action('init', array($this, 'onWpInit')); } public function onWpInit() { if (!is_admin() && $this->_isAsync()) { // be sure to have jQuery if AJAX mode is active wp_enqueue_script('jquery'); } } /** * Called before installation / upgrade * */ public function onPreInstall() { try { $this->backupTemplates(); } catch (Exception $e) { } } /** * Called after installation / upgrade * */ public function onPostInstall() { try { $this->restoreTemplates(); } catch (Exception $e) { } } /** * Backups the template files * */ public function backupTemplates() { $dirIt = new DirectoryIterator($this->tpl_dir); $custom_tpl = array(); foreach ($dirIt as $fileinfo) { if ($fileinfo->isDir() || $fileinfo->isDot()) { continue; } $custom_tpl[] = $fileinfo->getFilename(); } if (count($custom_tpl) > 0) { $backup_destination = $this->_getBackupDestination(); mkdir($backup_destination); foreach($custom_tpl as $tpl_file) { $tpl_source_file = $this->tpl_dir . $tpl_file; $tpl_destination_file = $backup_destination . $tpl_file; $cp = copy($tpl_source_file, $tpl_destination_file); if ($cp == false) { $tpl_data = file_get_contents($tpl_source_file); $handle = fopen($tpl_destination_file, 'w'); fwrite($handle, $tpl_data); fclose($handle); } } } } /** * Restores the template files * */ public function restoreTemplates() { $backup_destination = $this->_getBackupDestination(); if (!is_dir($backup_destination)) { return false; } $dirIt = new DirectoryIterator($backup_destination); $custom_tpl = array(); foreach ($dirIt as $fileinfo) { if ($fileinfo->isDir() || $fileinfo->isDot()) { continue; } $custom_tpl[] = $fileinfo->getFilename(); } if (count($custom_tpl) > 0) { foreach($custom_tpl as $tpl_file) { $tpl_source_file = $backup_destination . $tpl_file; $tpl_destination_file = $this->tpl_dir . $tpl_file; $cp = copy($tpl_source_file, $tpl_destination_file); if ($cp == false) { $tpl_data = file_get_contents($tpl_source_file); $handle = fopen($tpl_destination_file, 'w'); fwrite($handle, $data); fclose($handle); } unlink($tpl_source_file); } } rmdir($backup_destination); } protected function _getBackupDestination() { $tmp = get_temp_dir() . 'amazonsimpleadmin_tpl_backup' . DIRECTORY_SEPARATOR; return $tmp; } /** * trys to connect to the amazon webservice * @return Asa_Service_Amazon|null */ protected function connect () { require_once ASA_LIB_DIR . 'Asa/Service/Amazon.php'; try { $amazon = Asa_Service_Amazon::factory( $this->_amazon_api_key, $this->_amazon_api_secret_key, $this->amazon_tracking_id, $this->_amazon_country_code, $this->_amazon_api_connection_type ); return $amazon; } catch (Exception $e) { if ($this->isDebug() && $this->_debugger != null) { $this->_debugger->write($e->getMessage()); } return null; } } /** * */ protected function _initCache () { if (!$this->isCache()) { return null; } try { require_once ASA_LIB_DIR . 'AsaZend/Cache.php'; $_asa_cache_dir = get_option('_asa_cache_dir'); $current_cache_dir = (!empty($_asa_cache_dir) ? $_asa_cache_dir : 'cache'); $frontendOptions = array( 'lifetime' => $this->getCacheLifetime(), 'automatic_serialization' => true ); $backendOptions = array( 'cache_dir' => dirname(__FILE__) . DIRECTORY_SEPARATOR . $current_cache_dir ); // getting a AsaZend_Cache_Core object $cache = AsaZend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions); return $cache; } catch (Exception $e) { return null; } } /** * Determines if cache is activated and cache dir is writable * @return bool */ public function isCache() { if ($this->_isCache === null) { $_asa_cache_dir = get_option('_asa_cache_dir'); $current_cache_dir = (!empty($_asa_cache_dir) ? $_asa_cache_dir : 'cache'); if (get_option('_asa_cache_active') && is_writable(dirname(__FILE__) . '/' . $current_cache_dir)) { $this->_isCache = true; } else { $this->_isCache = false; } } return $this->_isCache; } /** * @return AsaZend_Cache_Core|AsaZend_Cache_Frontend|AsaZend_Cache_Frontend_File|null */ public function getCache() { return $this->cache; } /** * @return int */ public function getCacheLifetime() { $_asa_cache_lifetime = get_option('_asa_cache_lifetime'); $lifetime = !empty($_asa_cache_lifetime) ? $_asa_cache_lifetime : self::CACHE_DEFAULT_LIFETIME; return (int)$lifetime; } /** * @return int */ public function getVariantCacheLifetime() { $lt = $this->getCacheLifetime(); $variantRange = floor($lt * 0.1); return $lt + rand(1, $variantRange); } /** * @return bool */ public function isVariantCacheLifetime() { $disableVariantLifetime = get_option('_asa_cache_disable_variable_lifetime'); return empty($disableVariantLifetime); } /** * @return bool */ public function isDebug() { return get_option('_asa_debug'); } /** * @return bool */ public function isErrorHandling() { return get_option('_asa_error_handling'); } public function getDebugger() { return $this->_debugger; } /** * @return void */ protected function _initDebugger() { require_once ASA_LIB_DIR . 'Asa/Debugger.php'; try { $this->_debugger = Asa_Debugger::factory(); } catch (Exception $e) { $this->_debugger_error = $e->getMessage(); } } /** * action function for above hook * */ public function createAdminMenu () { // Add a new submenu under Options: add_options_page('AmazonSimpleAdmin', 'AmazonSimpleAdmin', 'manage_options', 'amazonsimpleadmin/amazonsimpleadmin.php', array($this, 'createOptionsPage')); add_action('admin_head', array($this, 'getOptionsHead')); wp_enqueue_script( 'listman' ); } /** * creates the AmazonSimpleAdmin admin page * */ public function createOptionsPage () { echo '
'. sprintf( __('It is highly recommended to activate the cache!', 'asa1'), $this->plugin_url .'&task=cache') .'
'. __('Debugging mode is active. Be sure to deactivate it when you do not need it anymore.', 'asa1') .'
guide if you do not know how to use collections.', 'asa1'), 'https://www.wp-amazon-plugin.com/guide/'); ?>
error['submit_new_collection'])) { $this->_displayError($this->error['submit_new_collection']); } else if (isset($this->success['submit_new_collection'])) { $this->_displaySuccess($this->success['submit_new_collection']); } ?> error['submit_import'])) { $this->_displayError($this->error['submit_import']); } else if (isset($this->success['submit_import'])) { $this->_displaySuccess($this->success['submit_import']); } ?> error['submit_new_asin'])) { $this->_displayError($this->error['submit_new_asin']); } else if (isset($this->success['submit_new_asin'])) { $this->_displaySuccess($this->success['submit_new_asin']); } ?>| '; $table .= ' | '; $table .= ' | ASIN | '; $table .= ''. __('Price', 'asa1') .' | '; $table .= ''. __('Title', 'asa1') .' | '; $table .= ''. __('Timestamp', 'asa1') . ' | '; $table .= ''; $table .= ' |
|---|---|---|---|---|---|---|
| '; if (isset($item->SmallImage)) { $thumbnail = $item->SmallImage->Url->getUri(); } else { $thumbnail = asa_plugins_url( 'img/no_image.gif', __FILE__ ); } if (!isset($item->Offers->Offers)) { $price = '---'; } else { $price = $item->Offers->Offers[0]->FormattedPrice; } $table .= ' | '. $row->collection_item_asin .' | '; $table .= ''. $price .' | '; $table .= ''. $title .' | '; $table .= ''. date(str_replace(' \<\b\r \/\>', ',', __('Y-m-d \<\b\r \/\> g:i:s a')), $row->timestamp) .' | '; $table .= ''. __('latest', 'asa1') .' | '; $table .= '
' . __('Nothing found. Add some products.', 'asa1') .'
'; } ?>Usage Guide on the plugin\'s homepage to learn how to use it.', 'asa1'), 'https://www.wp-amazon-plugin.com/usage/' ); ?>
Step by Step Guide if you are new to this plugin.', 'asa1'), 'https://www.wp-amazon-plugin.com/guide/'); ?>
[asa tpl="flat_box_vertical"]ASIN[/asa][asa_collection tpl="flat_box_vertical"]collection_name[/asa]: Keeping your custom templates update safe
Could not load FAQ from '. $faqUrl . '
'; } } /** * the actual options page content * */ protected function _displayTestPage () { $templates = $this->getAllTemplates(); $mode = 'tpl'; if (count($_POST) > 0 && isset($_POST['asin']) && !empty($_POST['asin'])) { $asin = esc_attr($_POST['asin']); if (isset($_POST['tpl'])) { $tpl = esc_attr($_POST['tpl']); } else { $tpl = 'demo'; } if (isset($_POST['mode'])) { switch ($_POST['mode']) { case 'ratings': $mode = 'ratings'; break; default: $mode = 'tpl'; } } if (isset($_POST['block-log'])) { $blockLog = true; } } ?>' . __('Successfully retrieved customer ratings.', 'asa1') . '
'; echo '' . __('Total reviews:', 'asa1') . ' ' . $customerReviews->totalReviews . '
'; echo '' . __('Average rating:', 'asa1') . ' ' . $customerReviews->averageRating . '
'; echo '' . __('Image source:', 'asa1') . ' ' . $customerReviews->imgSrc . '
'; echo $customerReviews->imgTag; } else { echo '' . __('Customer ratings could not be retrieved.', 'asa1') . '
'; echo 'Error message: ' . $customerReviews->getErrorMessage() . '
'; echo '';
}
}
} elseif (count($_POST) > 0) {
_e('Invalid ASIN', 'asa1');
}
}
protected function _displayLogPage()
{
require_once dirname(__FILE__) . '/AsaLogListTable.php';
if (isset($_POST['action']) && $_POST['action'] == 'clear') {
$this->getLogger()->clear();
echo ''. __('All log entries have been deleted.') .'
';
}
$listTable = new AsaLogListTable();
$listTable->setLogger($this->getLogger());
$listTable->prepare_items();
?>
- Serbian: Ogi Djuraskovic (http://firstsiteguide.com/)
- Spanish: Andrew Kurtis (http://www.webhostinghub.com/)
- Russian: Ivanka (http://www.coupofy.com/)
- French: Marie-Aude (http://www.lumieredelune.com/)
_loadOptions();
?>
task == null): ?>
task != 'collections') :
?>
_amazon_api_key) && !empty($this->_amazon_api_secret_key)) {
try {
$this->amazon = $this->connect();
if ($this->amazon != null) {
$this->amazon->testConnection();
$success = true;
} else {
$message = __('Connection to Amazon Webservice failed. Please check the mandatory data.', 'asa1');
}
} catch (Exception $e) {
$message = $e->getMessage();
}
}
return array('success' => $success, 'message' => $message);
}
/**
* Retrieves connections status
*
* @return bool
*/
public function getConnectionStatus()
{
$result = $this->testConnection();
return $result['success'] === true;
}
/**
* Loads setup panel
*
*/
protected function _displaySetupPage ()
{
if (!current_user_can('asa1_edit_setup') && !current_user_can('activate_plugins')) {
do_action( 'admin_page_access_denied' );
wp_die( __( 'You do not have sufficient permissions to access this page.' ), 403 );
}
$_asa_status = false;
$this->_getAmazonUserData();
$connectionTestResult = $this->testConnection();
if ($connectionTestResult['success'] === true) {
$_asa_status = true;
} else {
$_asa_error = $connectionTestResult['message'];
}
?>
'. __('Error', 'asa1') .': '. $error .'
'; } /** * */ protected function _displaySuccess ($success) { echo ''. __('Success', 'asa1') .': '. $success .'
',
'RatingStarsSrc' => ($customerReviews->imgSrc != null) ? $customerReviews->imgSrc : asa_plugins_url( 'img/stars-0.gif', __FILE__ ),
'Director' => is_array($item->Director) ? implode(', ', $item->Director) : $item->Director,
'Actors' => is_array($item->Actor) ? implode(', ', $item->Actor) : $item->Actor,
'RunningTime' => $item->RunningTime,
'Format' => is_array($item->Format) ? implode(', ', $item->Format) : $item->Format,
'CustomRating' => !empty($parse_params['custom_rating']) ? '
' : '',
'ProductDescription' => isset($item->EditorialReviews[0]) ? $item->EditorialReviews[0]->Content : '',
'AmazonDescription' => !empty($item->EditorialReviews[1]) ? $item->EditorialReviews[1]->Content : '',
'Artist' => is_array($item->Artist) ? implode(', ', $item->Artist) : $item->Artist,
'Comment' => !empty($parse_params['comment']) ? $parse_params['comment'] : '',
'PercentageSaved' => !empty($percentageSaved) ? $percentageSaved : 0,
'Prime' => !empty($item->Offers->Offers[0]->IsEligibleForSuperSaverShipping) ? 'AmazonPrime' : '',
'PrimePic' => !empty($item->Offers->Offers[0]->IsEligibleForSuperSaverShipping) ? '
' : '',
'ProductReviewsURL' => $this->getAmazonShopUrl() . 'product-reviews/' . $item->ASIN . '/&tag=' . $this->getTrackingId(),
'TrackingId' => $this->getTrackingId(),
'AmazonShopURL' => $this->getAmazonShopUrl(),
'SalePriceAmount' => isset($item->Offers->SalePriceAmount) ? $this->_formatPrice($item->Offers->SalePriceAmount) : '',
'SalePriceCurrencyCode' => isset($item->Offers->SalePriceCurrencyCode) ? $item->Offers->SalePriceCurrencyCode : '',
'SalePriceFormatted' => isset($item->Offers->SalePriceFormatted) ? $item->Offers->SalePriceFormatted : '',
'Class' => !empty($parse_params['class']) ? $parse_params['class'] : '',
'OffersMainPriceAmount' => $offerMainPriceAmount,
'OffersMainPriceCurrencyCode' => $offerMainPriceCurrencyCode,
'OffersMainPriceFormattedPrice' => $offerMainPriceFormatted,
'AlignCss' => $alignCss // align
);
$search = $this->_getTplPlaceholders(array_keys($placeholderStack), true);
$replace = array_values($placeholderStack);
$result = preg_replace($search, $replace, $tpl);
// check for unresolved
preg_match_all('/\{\$([a-z0-9\-\>]*)\}/i', $result, $matches);
$unresolved = $matches[1];
if (count($unresolved) > 0) {
$unresolved_names = $matches[1];
$unresolved_placeholders = $matches[0];
$unresolved_search = array();
$unresolved_replace = array();
for ($i=0; $i