This is a patch that allows the site administrator to use php code to choose which Publisher ID will be chosen.

This patch came from a need to have better revenue sharing. Specifically, I wanted to have the percentage of sharing proportional to the votes on the node. The higher the votes, the better the percentage of revenue sharing the author will receive.

If no PHP code is entered, the module performs as it did before.

Please note: I'm a newb at making diffs. I hope it works.

CommentFileSizeAuthor
adsense.module.01.patch1.92 KBcoreyp_1

Comments

jamesJonas’s picture

This patch has great potential. Thx.

kbahey’s picture

Status: Needs review » Needs work

A far better way is to allow modules to override the choice of the Adsense ID.

This means that the adsense.module would have an API hook that other modules can implement to override the selection.

This is far superior to pasting PHP in a block. Code stays out of the database, and into proper modules.

jamesJonas’s picture

It is true that it would be more elegant to expose an API, but use of PHP would provide a good intermediary step. Several requests have been made for more sophisticated allocation of adsense rev (by role, workflow...), thus perhaps the investment in exposing an API in a later version would be worth it. Thanks for the reminder that we are working within the Drupal ecosystem of modules.

Uses and Mashups:
(1) Revenue % Allocation by role
(2) '' by vote
(3) '' by stage in workflow
(4) '' by user points
(5) '' by CCK
(6) " by user account age (introductory offer)

kbahey’s picture

PHP in blocks also allows casual users to shoot themselves in the foot, and open security wholes.

Rather than an intermediate step with these drawbacks, let us do it right with a simple API.

Here is a starter:

In the adsense.module we will have:

$adsense_id = module_invoke_all('adsense_id');

if (!$adsense_id) {
  // use the selection method in adsense.module
}
else {
  // We use $adsense_id that was assigned by a module
}

Then in the new.module we have:

function new_adsense_id() {
  // Chose the id whichever way you like
  $id = 'pub-11111111';
  return $id;
}

That is it. The only limitation is that you should have only one module that implements hook_adsense_id(). We can even add a check in the settings to display an error if more than one is selected.

To make it even cleaner, we can take out the default selection stuff and put it in a module call adsense_revenue_sharing.module, and make it optional. So people can use it as a starting point, disable it if they don't want to, ...etc.

kbahey’s picture

Version: 5.x-1.6 » 5.x-2.x-dev
Status: Needs work » Fixed

This is now implemented.

It should be in the 5.x-2.x release tomorrow.

See the main project page for code examples, or use the included adsense_basic.module as a starting point.

Go wild ...

jamesJonas’s picture

Wow! Very Cool.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.