You are here

ad_types.txt in Advertisement 7.2

---------
Overview:
---------
This document is intended to help someone write a module for the ad api to
introduce a new ad type. The core ad module includes two ad type modules, one
for text ads and another for image ads. You can use the same api used by these
two ad type modules to create your own custom ad type module, for example you
may wish to write a module to ad support for flash ads. Some familiarity with
Drupal and PHP is required.

--------------------------
Naming your new ad module:
--------------------------
There are two ad types included with the core ad module, text ads and image
ads. Each ad type lives in its own module. Text ads are defined in the
ad_text module, and image ads are defined in the ad_image module. All
additional types of ads should be defined in modules following the same naming
scheme which is 'ad_' followed by the type of ad. For example, if you are
creating a module to add support for flash-based ads, you would call your
module ad_flash.

------------------------------
Registering a new style of ad:
------------------------------
Within the Drupal framework, ads are nodes. To create a new ad, a user
navigates to "create content >> ad", on which page they will be prompted
to select the type of the ad they wish to create. Your new ad type can
be added to this list by using the _adapi() hook and the 'type' operator. 
For example, if creating a module for flash ads, you might add the following 
function:

ad_flash_adapi($op, $ad = NULL) {
  switch ($op) {
    case 'type':
      return array(
        'flash' => array(
          'name' => t('Flash ad'),
          'module' => 'ad_flash',
          'description' => t('A flash advertisement.'),
          'help' => t('A flash advertisement.'),
        ),
      );
  }
}

------------------
Displaying your ad
------------------
To display an ad, your ad type module needs to define the _display_ad() hook.
Be aware that when this function is called, many standard Drupal functions
are not available to you as the adtype.php script will only bootstrap to
DRUPAL_BOOTSTRAP_DATABASE.

You are passed in an object which contains the ad ID (aid) and the redirect
URL (ie 'ad/redirect/13'). Utilize this information to return the complete
advertisement. For example:

function ad_static_display_ad($ad) {
  $return "<a href=\"$ad->redirect\">Static ad #$ad->aid</a>";
}

--------------------------------
Sharing your new ad_type module:
--------------------------------
The drupal.org CVS contributions repository requires that all included modules
be licesensed under the GPL. The ad module is dual licensed under both the
GPL and the BSD license, meeting this requirement. You can license your
new ad_style module under just the GPL, or under a dual license as long as
one of the licenses is the GPL.

If your module meets the above licensing requirements and you feel other Drupal
users could benefit from your work, contact the ad module maintainer to have
your module reviewed for inclusion.

File

documentation/ad_types.txt
View source
  1. ---------
  2. Overview:
  3. ---------
  4. This document is intended to help someone write a module for the ad api to
  5. introduce a new ad type. The core ad module includes two ad type modules, one
  6. for text ads and another for image ads. You can use the same api used by these
  7. two ad type modules to create your own custom ad type module, for example you
  8. may wish to write a module to ad support for flash ads. Some familiarity with
  9. Drupal and PHP is required.
  10. --------------------------
  11. Naming your new ad module:
  12. --------------------------
  13. There are two ad types included with the core ad module, text ads and image
  14. ads. Each ad type lives in its own module. Text ads are defined in the
  15. ad_text module, and image ads are defined in the ad_image module. All
  16. additional types of ads should be defined in modules following the same naming
  17. scheme which is 'ad_' followed by the type of ad. For example, if you are
  18. creating a module to add support for flash-based ads, you would call your
  19. module ad_flash.
  20. ------------------------------
  21. Registering a new style of ad:
  22. ------------------------------
  23. Within the Drupal framework, ads are nodes. To create a new ad, a user
  24. navigates to "create content >> ad", on which page they will be prompted
  25. to select the type of the ad they wish to create. Your new ad type can
  26. be added to this list by using the _adapi() hook and the 'type' operator.
  27. For example, if creating a module for flash ads, you might add the following
  28. function:
  29. ad_flash_adapi($op, $ad = NULL) {
  30. switch ($op) {
  31. case 'type':
  32. return array(
  33. 'flash' => array(
  34. 'name' => t('Flash ad'),
  35. 'module' => 'ad_flash',
  36. 'description' => t('A flash advertisement.'),
  37. 'help' => t('A flash advertisement.'),
  38. ),
  39. );
  40. }
  41. }
  42. ------------------
  43. Displaying your ad
  44. ------------------
  45. To display an ad, your ad type module needs to define the _display_ad() hook.
  46. Be aware that when this function is called, many standard Drupal functions
  47. are not available to you as the adtype.php script will only bootstrap to
  48. DRUPAL_BOOTSTRAP_DATABASE.
  49. You are passed in an object which contains the ad ID (aid) and the redirect
  50. URL (ie 'ad/redirect/13'). Utilize this information to return the complete
  51. advertisement. For example:
  52. function ad_static_display_ad($ad) {
  53. $return "redirect\">Static ad #$ad->aid";
  54. }
  55. --------------------------------
  56. Sharing your new ad_type module:
  57. --------------------------------
  58. The drupal.org CVS contributions repository requires that all included modules
  59. be licesensed under the GPL. The ad module is dual licensed under both the
  60. GPL and the BSD license, meeting this requirement. You can license your
  61. new ad_style module under just the GPL, or under a dual license as long as
  62. one of the licenses is the GPL.
  63. If your module meets the above licensing requirements and you feel other Drupal
  64. users could benefit from your work, contact the ad module maintainer to have
  65. your module reviewed for inclusion.