Skip to content

Commit 1dfcd13

Browse files
Migrating plugin to be hosted at GitHub (#15)
* fixing the global logger location and instantiation * download testing validated * updating version
1 parent eaf2af8 commit 1dfcd13

10 files changed

Lines changed: 317 additions & 49 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
### Changelog
22

3+
#### 3.0.0
4+
* Released: 2020-07-03
5+
* Plugin is now hosted on [GitHub](https://github.com/HeyPublisher/amazon-book-store)
6+
* Fixed issue with call to function `split` not being found in PHP versions 7.0 and above.
7+
* Added an updater that will check GitHub for latest version and update locally.
8+
* Organized code around HeyPublisher/Base class
9+
* Validated plugin works up through WordPress 5.3
10+
311
#### 2.2.1
412
* Released: 2017-05-27
513
* Fixed an issue where affiliate code would not stick if changing from any international affiliate country back to US.
@@ -55,7 +63,7 @@
5563

5664
#### 1.0.1
5765
* Updated screenshots to highlight the fact that users should change their Amazon Associate ID.
58-
* Plugin is now owned and maintained by [Loudlever, Inc.](http://www.loudlever.com)
66+
* Plugin is now owned and maintained by [Loudlever, Inc.](https://www.loudlever.com)
5967
* Update Release (03/26/2010)
6068

6169
#### 1.0

‎README.md‎

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
11
## Amazon Book Store
22

3-
```
4-
Contributors: heypublisher, aguywithanidea, loudlever
5-
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=Y8SL68GN5J2PL
6-
Tags: affiliate, amazon, product, book store, affiliate sales,ASIN, Amazon Associate, monetize, heypublisher
7-
Requires at least: 4.0
8-
Tested up to: 4.7.3
9-
Stable tag: 2.2.1
10-
License: GPLv2 or later
11-
License URI: http://www.gnu.org/licenses/gpl-2.0.html
12-
```
13-
143
Sell Amazon products in sidebar widgets, unique to the individual POST or generically from a default pool of products that you define.
154

165
### Description
@@ -31,7 +20,7 @@ Install the plugin, then activate it. Once activated, configure the Widget:
3120

3221
**Configure the ASIN pool**
3322

34-
Navigate to 'Settings' -> 'Amazon Book Store'. Input your Amazon Affiliate ID and country, the add the ASINs for the products you want to be displayed in the widget. See [How to Find Amazon ASINs](http://askville.amazon.com/find-Amazon-ASIN-product-details-page/AnswerViewer.do?requestId=11106037) for more information. There are two categorizations of settings:
23+
Navigate to 'Settings' -> 'Amazon Book Store'. Input your Amazon Affiliate ID and country, the add the ASINs for the products you want to be displayed in the widget. See [How to Find Amazon ASINs](https://www.amazon.com/gp/seller/asin-upc-isbn-info.html) for more information. There are two categorizations of settings:
3524

3625
* POST Specific: When set, these products will be offered for sale when users read the associated POST.
3726
* Default: If the request is to a POST that does not have specific ASINs defined, the widget will display products from this group.

‎include/classes/AMZNBS/Admin.class.php‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22
namespace AMZNBS;
3+
34
/*
45
Admin Class
56
@@ -24,21 +25,22 @@ class Admin extends \HeyPublisher\Base {
2425
public function __construct() {
2526
parent::__construct();
2627
$this->options = get_option(SGW_PLUGIN_OPTTIONS);
27-
$this->log(sprintf("in constructor\nopts = %s",print_r($this->options,true)));
28+
$this->logger->debug(sprintf("in constructor\nopts = %s",print_r($this->options,true)));
2829
// $this->check_plugin_version(); // may need to reintroduce this
2930
$this->nav_slug = SGW_ADMIN_PAGE; // not 'amazon_bookstore' because this needs to map to dir name
3031
$this->slug = 'support-great-writers'; // not 'amazon_bookstore' because this needs to map to dir name
3132
// Sidebar configs
32-
$this->plugin['home'] = 'https://wordpress.org/plugins/support-great-writers/';
33-
$this->plugin['support'] = 'https://wordpress.org/support/plugin/support-great-writers';
33+
$this->plugin['home'] = 'https://github.com/HeyPublisher/amazon-book-store';
34+
$this->plugin['support'] = 'https://github.com/HeyPublisher/amazon-book-store/issues';
3435
$this->plugin['contact'] = 'mailto:wordpress@heypublisher.com';
36+
$this->plugin['more'] = 'https://github.com/HeyPublisher/';
3537
}
3638

3739
public function __destruct() {
3840
parent::__destruct();
3941
}
4042
public function activate_plugin() {
41-
$this->log("in the activate_plugin()");
43+
$this->logger->debug("in the activate_plugin()");
4244
$this->check_plugin_version();
4345
}
4446

@@ -71,20 +73,20 @@ public function plugin_filter() {
7173
}
7274

7375
public function check_plugin_version() {
74-
$this->log("in check_plugin_version()");
76+
$this->logger->debug("in check_plugin_version()");
7577

7678
$opts = get_option(SGW_PLUGIN_OPTTIONS);
7779
// printf("<pre>In check_plugin_version()\n opts = %s</pre>",print_r($opts,1));
7880
if (!$opts || !$opts[plugin] || $opts[plugin][version_last] == false) {
79-
$this->log("no old version - initializing");
81+
$this->logger->debug("no old version - initializing");
8082
$this->init_plugin();
8183
// there is a possible upgrade path from old widget to this one - in which case we want to migrate data
8284
$this->migrate_old_widget();
8385
return;
8486
}
8587
// check for upgrade option here
8688
if ($opts[plugin][version_current] != SGW_PLUGIN_VERSION) {
87-
$this->log("need to upgrade version");
89+
$this->logger->debug("need to upgrade version");
8890
$this->upgrade_plugin($opts);
8991
return;
9092
}
@@ -182,7 +184,7 @@ private function normalize_asin_list($list) {
182184
// $this->error = 'You must input at least one ASIN'; return false;
183185
}
184186
$new = array();
185-
$array = split(',',$list);
187+
$array = explode(',',$list);
186188
foreach ($array as $asin) {
187189
$x = trim($asin);
188190
if (strlen($x) != 10) {

‎include/classes/HeyPublisher/Base.class.php‎

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<?php
22
namespace HeyPublisher;
33

4+
if (!class_exists("\HeyPublisher\Base\Log")) {
5+
require_once(SGW_PLUGIN_FULLPATH . '/include/classes/HeyPublisher/Base/Log.class.php');
6+
}
7+
48
if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) { die('HeyPublisher: Illegal Page Call!'); }
59

610
/**
@@ -9,9 +13,9 @@
913
*/
1014
class Base {
1115
var $debug = true;
16+
var $logger = null;
1217
var $help = false;
1318
var $i18n = 'heypublisher'; // key for internationalization stubs
14-
var $log_file = '';
1519
var $plugin = array(
1620
'url' => 'https://www.heypublisher.com',
1721
'home' => 'https://wordpress.org/plugins/',
@@ -22,9 +26,11 @@ class Base {
2226
var $slug = ''; // should be defined in constructor of any class that extends this class.
2327

2428
public function __construct() {
29+
global $HEYPUB_LOGGER;
2530
// this can't be instantiated in var declaration
2631
// $this->plugin['url'] = plugins_url('../../',__FILE__);
27-
$this->log_file = dirname( __FILE__ ) . '/../../../error.log';
32+
$this->logger = $HEYPUB_LOGGER;
33+
$this->logger->debug("HeyPublisher::Base loaded");
2834
}
2935

3036
public function __destruct() {
@@ -60,15 +66,6 @@ public function box_footer() {
6066
return $text;
6167
}
6268

63-
/**
64-
* Logging function
65-
*/
66-
public function log($msg) {
67-
if ($this->debug && $this->log_file) {
68-
error_log(sprintf("%s\n",$msg),3,$this->log_file);
69-
}
70-
}
71-
7269
/**
7370
* Style the side-bar link appropriately
7471
*/
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
// Generic logging class.
3+
// Should be instantiated: $this->logger = new \HeyPublisher\Base\Log('file.log');
4+
// Then send logs: $this->logger->debug("message"); and it will be written to 'file.log'
5+
6+
namespace HeyPublisher\Base;
7+
8+
if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) { die('HeyPublisher: Illegal Page Call!'); }
9+
10+
// Logging class for all HeyPublisher plugins.
11+
// This class is instantiated automatically when loaded and will be accessible
12+
// via the global $HEYPUB_LOGGER
13+
class Log {
14+
var $enable = false;
15+
var $log_file = '';
16+
17+
// Pass in fully pathed file if you want to override default
18+
public function __construct($file='') {
19+
if (!$file) { $file = '/tmp/heypub_plugin_error.log'; }
20+
// this can't be instantiated in var declaration
21+
$this->log_file = $file;
22+
if (file_exists($this->log_file)) {
23+
// can only turn on logging if server-side environment exists
24+
$this->enable = (getenv('HEYPUB_DEBUG') === 'true');
25+
}
26+
}
27+
28+
// Logging function
29+
public function debug($msg) {
30+
if ($this->enable) {
31+
error_log(sprintf("%s\n",$msg),3,$this->log_file);
32+
}
33+
}
34+
}
35+
// This class sets a global accessor
36+
if (!isset($HEYPUB_LOGGER)) {
37+
$HEYPUB_LOGGER = new \HeyPublisher\Base\Log();
38+
$HEYPUB_LOGGER->debug("Instantiating HeyPublisher\Base\Log...");
39+
}
40+
?>

0 commit comments

Comments
 (0)