annotate documentation/ad_types.txt @ 0:d8a3998dac8e ad

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