Amazon Recommendations with AWS plugin

Creating and modifying plugins.
caw
Regular
Posts: 13
Joined: Wed Jul 20, 2005 5:48 am

Amazon Recommendations with AWS plugin

Post by caw »

I wrote a new plugin that builds on the existing Amazon Recommendations plugin. It offers the following additional features:
  • Uses Amazon Web Service to gather data
  • Database backend, to facilitate...
  • ... easy backend interface to view/add/delete recommendations ("Manage ASINs")
  • Can show multiple recommendations in one box
  • Caches medium (for recommendations box) and small images (for backend viewing)
  • Uses <div class="serendipity_plugin_amazonaws_item"></div> around each for style
See it in action at my blog

Download it here

I relied somewhat on the original Amazon Recommendations code as well as the LinkList code for learning how to do events. This is my first real plugin (I've tweaked a couple for personal use).

Curtis.
MySchizoBuddy
Regular
Posts: 340
Joined: Sun Jun 12, 2005 5:28 am

Post by MySchizoBuddy »

is it possible to have a recommended reading appear based on the Entry
:)
caw
Regular
Posts: 13
Joined: Wed Jul 20, 2005 5:48 am

Post by caw »

MySchizoBuddy wrote:is it possible to have a recommended reading appear based on the Entry
:)
Probably :D

Curtis.
caw
Regular
Posts: 13
Joined: Wed Jul 20, 2005 5:48 am

Post by caw »

So I've made some additional updates:
  • Added ability to edit individual ASIN entries to tweak a title, author and images (e.g., to use an image other than the Amazon image -- must still reside in the uploads/amazon/ directory though).
  • Moved several options (amazonid, site) to the event plugin instead of the sidebar plugin and added some new options
  • Added ability to delete ASINs by comma-separated list
  • Added ability to sort ASINs for easier backend viewing
  • Added default image/thumbnail for when an image cannot be retrieved from Amazon
But the coolest one:
  • Added a new markup event to include image or text links in the body of a post. For example: [ASIN:0439784549] would add an image link to the newest Harry Potter book. If the ASIN is not already in the database, it will be added automatically.
Download it here

Curtis.
Oliver
Regular
Posts: 178
Joined: Mon Jan 10, 2005 7:43 pm
Location: Herne, Germany
Contact:

Post by Oliver »

Everytime I try to install a/the sidebar-plugin after uploading the amazonaws-folder including files I get an error :(

Code: Select all

Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' in /is/htdocs/www.forum4winde.de/mods/s9y/plugins/serendipity_event_amazonaws/serendipity_plugin_amazonaws.php on line 15
And now, everytime, I try to install this or another plugin, I get this error and the plugins-list does not load.

I'm using Serendipity 0.8.2 and PHP 4.3.10. Someone knows why this happens?

Regards,

- Oliver
Image
caw
Regular
Posts: 13
Joined: Wed Jul 20, 2005 5:48 am

Post by caw »

Oliver wrote:Everytime I try to install a/the sidebar-plugin after uploading the amazonaws-folder including files I get an error :(
Fixed.

serendipity_event_amazonaws.tar.gz

Curtis.
gwilsonmail
Regular
Posts: 146
Joined: Tue Jul 12, 2005 9:12 pm
Location: Ottawa, Canada
Contact:

Post by gwilsonmail »

New file fixes the SIDEBAR issue.

If you replace the old files with the new files you get the following error in the EVENT PLUGINS section

Code: Select all

Event Plugins
Select the plugin which you wish to install

Plugin Action 

Fatal error: Cannot redeclare class serendipity_event_amazonaws in /home/httpd/vhosts/gizmocha.com/httpdocs/everydayxxxxx/plugins/serendipity_event_amazonaws/serendipity_event_amazonaws.php on line 6
gw
gwilsonmail
Regular
Posts: 146
Joined: Tue Jul 12, 2005 9:12 pm
Location: Ottawa, Canada
Contact:

Post by gwilsonmail »

same problem here. ASIN's not being added.

I also noticed that the info entered in the event plugin is not showing up in the sidebar plugin in the area at the bottom.
gw
caw
Regular
Posts: 13
Joined: Wed Jul 20, 2005 5:48 am

Post by caw »

RobA wrote:I tried your plugin(s) and get the error

ASIN not added: 0756400309

when I try to add one using the manage ASIN links.

Is there something wrong with that number (Tad Williams, Otherland V4 - Sea of Silver Light)?

I don't have a partner ID... does it need ome to work?
Shouldn't need a partner ID, though it may spit out malformed links/URLs if there isn't one. Are there any other errors, or just the "ASIN not added" one? (And is it only this ASIN, or any ASIN?)

P.S. You can link the event and sidebar plugins as dependant so they both get installed/uninstalled together by adding a

$this->dependencies = array('serendipity_plugin_amazonaws' => 'keep');
and
$this->dependencies = array('serendipity_event_amazonaws' => 'keep');

to the opposite files.
Thanks -- I think how I have it set up now is good, though. If you try to install the sidebar, it will automatically install the event, but not vice versa. It is possible some people might want the event for the [ASIN:....] markup without wanting the sidebar, so allowing the two to be installed/removed separately is desirable IMO.

For what it's worth, I re-tarred everything. Maybe I updated a file or two without adding them to the archive. Please try again.

serendipity_event_amazonaws.tar.gz
gwilsonmail wrote:If you replace the old files with the new files you get the following error in the EVENT PLUGINS section
No clue what's causing this -- do you have two instances of the event plugin installed perhaps?

Sorry for all the problems -- it's my first time (well, 0.2 time ;)) creating a plugin.

Curtis.
gwilsonmail
Regular
Posts: 146
Joined: Tue Jul 12, 2005 9:12 pm
Location: Ottawa, Canada
Contact:

Post by gwilsonmail »

This looks like a great plugin and might meet my needs for an amazon plugin.

I like the asin markup concept - it sounds like what I need but I don't know yet!.

You create a directory called - plugin_amazonaws_cache at the site's root-level. I'm assuming that you will be writing file to this. It needs to be manually chmod to 777 for it to work.

Maybe the plugin_amazonaws_cache directory should be created one level deeper in one of the directories that is already writable (then the change i mention would be un-necessary). Garvin has a cache mechanism plugin, it must setup a cache somewhere.

I uninstalled both the sidebar and the event plugins. and started fresh by installing the sidebar plugin (which installed the event plugin). I'm no further forward the asin's are not being added and the markup in the entry isn't being converted. The sidebar output on my page says -

Code: Select all

Warning: Invalid argument supplied for foreach() in /home/httpd/vhosts/gizmocha.com/httpdocs/everyxxxxxx/plugins/serendipity_event_amazonaws/serendipity_plugin_amazonaws.php on line 93
I'm guessing that's because there are no ASINs.

Let me know how I can help you debug this.
gw
gwilsonmail
Regular
Posts: 146
Joined: Tue Jul 12, 2005 9:12 pm
Location: Ottawa, Canada
Contact:

Post by gwilsonmail »

Another update - tried to figure out what was going on myself!

serendipity_config has some amazonaws entries - they look like the values from the plugin config screens.

The directories exist at

/plugin_amazonaws_cache
/uploads/amazon

BUT the default images are not in the /amazon folder.

It looks like an install failed. So when you check to see if the install has happened once before, whatever check you depend on is telling you it's OK, when it's not.
gw
Guest

Post by Guest »

I got it figured out!

This code doesn't work - no idea why!

Code: Select all

    # If there were no hits, create the table
    if ( !is_array($t) ) {
      # Create the table
      $q = "CREATE TABLE ".PLUGIN_AMAZONAWS_TABLE." (\n"  .
         "  " . PLUGIN_AMAZONAWS_ASINCOL." text {PRIMARY},\n"      .
         "  " . PLUGIN_AMAZONAWS_AUTHCOL." text default NULL,\n"   .
         "  " . PLUGIN_AMAZONAWS_TITLECOL." text default NULL,\n"  .
         "  " . PLUGIN_AMAZONAWS_IMGCOL." text default NULL,\n"    .
         "  " . PLUGIN_AMAZONAWS_THUMBCOL." text default NULL\n"   .
         ");";
This code isn't pretty but it does work

Code: Select all

            $q   = "CREATE TABLE {$serendipity['dbPrefix']}plugin_amazonaws (
                        asin   varchar(255) null,
                        author varchar(255) null,
                        title  varchar(255) null,
                        image  varchar(255) null,
                        thumb  varchar(255) null,
			primary key (asin)
                    )";
Except it creates a table with the wrong name (serendipity is missing), so i renamed the table and then i managed to get the whole thing to work!


VERY IMPRESSIVE JOB!
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

I didn't quite follow this thread - is there any interest into putting this plugin into our CVS? I can give the author of it CVS access to maintain it there...

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
caw
Regular
Posts: 13
Joined: Wed Jul 20, 2005 5:48 am

Post by caw »

gwilsonmail wrote:You create a directory called - plugin_amazonaws_cache at the site's root-level. I'm assuming that you will be writing file to this. It needs to be manually chmod to 777 for it to work.
:oops:

I had toyed around with caching AWS results, but didn't get it working right. All the cache-related lines should've been removed -- looks like I forgot one in the install method.

I uninstalled both the sidebar and the event plugins. and started fresh by installing the sidebar plugin (which installed the event plugin). I'm no further forward the asin's are not being added and the markup in the entry isn't being converted. The sidebar output on my page says -

Code: Select all

Warning: Invalid argument supplied for foreach() in /home/httpd/vhosts/gizmocha.com/httpdocs/everyxxxxxx/plugins/serendipity_event_amazonaws/serendipity_plugin_amazonaws.php on line 93
I'm guessing that's because there are no ASINs.

Let me know how I can help you debug this.
Thanks -- I'll look at it tonight after I get home from work (after I figure out what went wrong with my most recent php upgrade).

Curtis.
caw
Regular
Posts: 13
Joined: Wed Jul 20, 2005 5:48 am

Post by caw »

Looks like amazonaws_defines.inc.php isn't getting included for some reason.

Curtis.
Anonymous wrote:I got it figured out!

This code doesn't work - no idea why!

Code: Select all

    # If there were no hits, create the table
    if ( !is_array($t) ) {
      # Create the table
      $q = "CREATE TABLE ".PLUGIN_AMAZONAWS_TABLE." (\n"  .
         "  " . PLUGIN_AMAZONAWS_ASINCOL." text {PRIMARY},\n"      .
         "  " . PLUGIN_AMAZONAWS_AUTHCOL." text default NULL,\n"   .
         "  " . PLUGIN_AMAZONAWS_TITLECOL." text default NULL,\n"  .
         "  " . PLUGIN_AMAZONAWS_IMGCOL." text default NULL,\n"    .
         "  " . PLUGIN_AMAZONAWS_THUMBCOL." text default NULL\n"   .
         ");";
This code isn't pretty but it does work

Code: Select all

            $q   = "CREATE TABLE {$serendipity['dbPrefix']}plugin_amazonaws (
                        asin   varchar(255) null,
                        author varchar(255) null,
                        title  varchar(255) null,
                        image  varchar(255) null,
                        thumb  varchar(255) null,
			primary key (asin)
                    )";
Except it creates a table with the wrong name (serendipity is missing), so i renamed the table and then i managed to get the whole thing to work!


VERY IMPRESSIVE JOB!
Post Reply