annotate modules/aggregator/aggregator.api.php @ 2:b74b41bb73f0

-- Google analytics module
author danieleb <danielebarchiesi@me.com>
date Thu, 22 Aug 2013 17:22:54 +0100
parents ff03f76ab3fe
children
rev   line source
danielebarchiesi@0 1 <?php
danielebarchiesi@0 2
danielebarchiesi@0 3 /**
danielebarchiesi@0 4 * @file
danielebarchiesi@0 5 * Documentation for aggregator API.
danielebarchiesi@0 6 */
danielebarchiesi@0 7
danielebarchiesi@0 8 /**
danielebarchiesi@0 9 * @addtogroup hooks
danielebarchiesi@0 10 * @{
danielebarchiesi@0 11 */
danielebarchiesi@0 12
danielebarchiesi@0 13 /**
danielebarchiesi@0 14 * Create an alternative fetcher for aggregator.module.
danielebarchiesi@0 15 *
danielebarchiesi@0 16 * A fetcher downloads feed data to a Drupal site. The fetcher is called at the
danielebarchiesi@0 17 * first of the three aggregation stages: first, data is downloaded by the
danielebarchiesi@0 18 * active fetcher; second, it is converted to a common format by the active
danielebarchiesi@0 19 * parser; and finally, it is passed to all active processors, which manipulate
danielebarchiesi@0 20 * or store the data.
danielebarchiesi@0 21 *
danielebarchiesi@0 22 * Modules that define this hook can be set as the active fetcher within the
danielebarchiesi@0 23 * configuration page. Only one fetcher can be active at a time.
danielebarchiesi@0 24 *
danielebarchiesi@0 25 * @param $feed
danielebarchiesi@0 26 * A feed object representing the resource to be downloaded. $feed->url
danielebarchiesi@0 27 * contains the link to the feed. Download the data at the URL and expose it
danielebarchiesi@0 28 * to other modules by attaching it to $feed->source_string.
danielebarchiesi@0 29 *
danielebarchiesi@0 30 * @return
danielebarchiesi@0 31 * TRUE if fetching was successful, FALSE otherwise.
danielebarchiesi@0 32 *
danielebarchiesi@0 33 * @see hook_aggregator_fetch_info()
danielebarchiesi@0 34 * @see hook_aggregator_parse()
danielebarchiesi@0 35 * @see hook_aggregator_process()
danielebarchiesi@0 36 *
danielebarchiesi@0 37 * @ingroup aggregator
danielebarchiesi@0 38 */
danielebarchiesi@0 39 function hook_aggregator_fetch($feed) {
danielebarchiesi@0 40 $feed->source_string = mymodule_fetch($feed->url);
danielebarchiesi@0 41 }
danielebarchiesi@0 42
danielebarchiesi@0 43 /**
danielebarchiesi@0 44 * Specify the title and short description of your fetcher.
danielebarchiesi@0 45 *
danielebarchiesi@0 46 * The title and the description provided are shown within the configuration
danielebarchiesi@0 47 * page. Use as title the human readable name of the fetcher and as description
danielebarchiesi@0 48 * a brief (40 to 80 characters) explanation of the fetcher's functionality.
danielebarchiesi@0 49 *
danielebarchiesi@0 50 * This hook is only called if your module implements hook_aggregator_fetch().
danielebarchiesi@0 51 * If this hook is not implemented aggregator will use your module's file name
danielebarchiesi@0 52 * as title and there will be no description.
danielebarchiesi@0 53 *
danielebarchiesi@0 54 * @return
danielebarchiesi@0 55 * An associative array defining a title and a description string.
danielebarchiesi@0 56 *
danielebarchiesi@0 57 * @see hook_aggregator_fetch()
danielebarchiesi@0 58 *
danielebarchiesi@0 59 * @ingroup aggregator
danielebarchiesi@0 60 */
danielebarchiesi@0 61 function hook_aggregator_fetch_info() {
danielebarchiesi@0 62 return array(
danielebarchiesi@0 63 'title' => t('Default fetcher'),
danielebarchiesi@0 64 'description' => t('Default fetcher for resources available by URL.'),
danielebarchiesi@0 65 );
danielebarchiesi@0 66 }
danielebarchiesi@0 67
danielebarchiesi@0 68 /**
danielebarchiesi@0 69 * Create an alternative parser for aggregator module.
danielebarchiesi@0 70 *
danielebarchiesi@0 71 * A parser converts feed item data to a common format. The parser is called
danielebarchiesi@0 72 * at the second of the three aggregation stages: first, data is downloaded
danielebarchiesi@0 73 * by the active fetcher; second, it is converted to a common format by the
danielebarchiesi@0 74 * active parser; and finally, it is passed to all active processors which
danielebarchiesi@0 75 * manipulate or store the data.
danielebarchiesi@0 76 *
danielebarchiesi@0 77 * Modules that define this hook can be set as the active parser within the
danielebarchiesi@0 78 * configuration page. Only one parser can be active at a time.
danielebarchiesi@0 79 *
danielebarchiesi@0 80 * @param $feed
danielebarchiesi@0 81 * An object describing the resource to be parsed. $feed->source_string
danielebarchiesi@0 82 * contains the raw feed data. The hook implementation should parse this data
danielebarchiesi@0 83 * and add the following properties to the $feed object:
danielebarchiesi@0 84 * - description: The human-readable description of the feed.
danielebarchiesi@0 85 * - link: A full URL that directly relates to the feed.
danielebarchiesi@0 86 * - image: An image URL used to display an image of the feed.
danielebarchiesi@0 87 * - etag: An entity tag from the HTTP header used for cache validation to
danielebarchiesi@0 88 * determine if the content has been changed.
danielebarchiesi@0 89 * - modified: The UNIX timestamp when the feed was last modified.
danielebarchiesi@0 90 * - items: An array of feed items. The common format for a single feed item
danielebarchiesi@0 91 * is an associative array containing:
danielebarchiesi@0 92 * - title: The human-readable title of the feed item.
danielebarchiesi@0 93 * - description: The full body text of the item or a summary.
danielebarchiesi@0 94 * - timestamp: The UNIX timestamp when the feed item was last published.
danielebarchiesi@0 95 * - author: The author of the feed item.
danielebarchiesi@0 96 * - guid: The global unique identifier (GUID) string that uniquely
danielebarchiesi@0 97 * identifies the item. If not available, the link is used to identify
danielebarchiesi@0 98 * the item.
danielebarchiesi@0 99 * - link: A full URL to the individual feed item.
danielebarchiesi@0 100 *
danielebarchiesi@0 101 * @return
danielebarchiesi@0 102 * TRUE if parsing was successful, FALSE otherwise.
danielebarchiesi@0 103 *
danielebarchiesi@0 104 * @see hook_aggregator_parse_info()
danielebarchiesi@0 105 * @see hook_aggregator_fetch()
danielebarchiesi@0 106 * @see hook_aggregator_process()
danielebarchiesi@0 107 *
danielebarchiesi@0 108 * @ingroup aggregator
danielebarchiesi@0 109 */
danielebarchiesi@0 110 function hook_aggregator_parse($feed) {
danielebarchiesi@0 111 if ($items = mymodule_parse($feed->source_string)) {
danielebarchiesi@0 112 $feed->items = $items;
danielebarchiesi@0 113 return TRUE;
danielebarchiesi@0 114 }
danielebarchiesi@0 115 return FALSE;
danielebarchiesi@0 116 }
danielebarchiesi@0 117
danielebarchiesi@0 118 /**
danielebarchiesi@0 119 * Specify the title and short description of your parser.
danielebarchiesi@0 120 *
danielebarchiesi@0 121 * The title and the description provided are shown within the configuration
danielebarchiesi@0 122 * page. Use as title the human readable name of the parser and as description
danielebarchiesi@0 123 * a brief (40 to 80 characters) explanation of the parser's functionality.
danielebarchiesi@0 124 *
danielebarchiesi@0 125 * This hook is only called if your module implements hook_aggregator_parse().
danielebarchiesi@0 126 * If this hook is not implemented aggregator will use your module's file name
danielebarchiesi@0 127 * as title and there will be no description.
danielebarchiesi@0 128 *
danielebarchiesi@0 129 * @return
danielebarchiesi@0 130 * An associative array defining a title and a description string.
danielebarchiesi@0 131 *
danielebarchiesi@0 132 * @see hook_aggregator_parse()
danielebarchiesi@0 133 *
danielebarchiesi@0 134 * @ingroup aggregator
danielebarchiesi@0 135 */
danielebarchiesi@0 136 function hook_aggregator_parse_info() {
danielebarchiesi@0 137 return array(
danielebarchiesi@0 138 'title' => t('Default parser'),
danielebarchiesi@0 139 'description' => t('Default parser for RSS, Atom and RDF feeds.'),
danielebarchiesi@0 140 );
danielebarchiesi@0 141 }
danielebarchiesi@0 142
danielebarchiesi@0 143 /**
danielebarchiesi@0 144 * Create a processor for aggregator.module.
danielebarchiesi@0 145 *
danielebarchiesi@0 146 * A processor acts on parsed feed data. Active processors are called at the
danielebarchiesi@0 147 * third and last of the aggregation stages: first, data is downloaded by the
danielebarchiesi@0 148 * active fetcher; second, it is converted to a common format by the active
danielebarchiesi@0 149 * parser; and finally, it is passed to all active processors that manipulate or
danielebarchiesi@0 150 * store the data.
danielebarchiesi@0 151 *
danielebarchiesi@0 152 * Modules that define this hook can be activated as a processor within the
danielebarchiesi@0 153 * configuration page.
danielebarchiesi@0 154 *
danielebarchiesi@0 155 * @param $feed
danielebarchiesi@0 156 * A feed object representing the resource to be processed. $feed->items
danielebarchiesi@0 157 * contains an array of feed items downloaded and parsed at the parsing stage.
danielebarchiesi@0 158 * See hook_aggregator_parse() for the basic format of a single item in the
danielebarchiesi@0 159 * $feed->items array. For the exact format refer to the particular parser in
danielebarchiesi@0 160 * use.
danielebarchiesi@0 161 *
danielebarchiesi@0 162 * @see hook_aggregator_process_info()
danielebarchiesi@0 163 * @see hook_aggregator_fetch()
danielebarchiesi@0 164 * @see hook_aggregator_parse()
danielebarchiesi@0 165 *
danielebarchiesi@0 166 * @ingroup aggregator
danielebarchiesi@0 167 */
danielebarchiesi@0 168 function hook_aggregator_process($feed) {
danielebarchiesi@0 169 foreach ($feed->items as $item) {
danielebarchiesi@0 170 mymodule_save($item);
danielebarchiesi@0 171 }
danielebarchiesi@0 172 }
danielebarchiesi@0 173
danielebarchiesi@0 174 /**
danielebarchiesi@0 175 * Specify the title and short description of your processor.
danielebarchiesi@0 176 *
danielebarchiesi@0 177 * The title and the description provided are shown within the configuration
danielebarchiesi@0 178 * page. Use as title the natural name of the processor and as description a
danielebarchiesi@0 179 * brief (40 to 80 characters) explanation of the functionality.
danielebarchiesi@0 180 *
danielebarchiesi@0 181 * This hook is only called if your module implements hook_aggregator_process().
danielebarchiesi@0 182 * If this hook is not implemented aggregator will use your module's file name
danielebarchiesi@0 183 * as title and there will be no description.
danielebarchiesi@0 184 *
danielebarchiesi@0 185 * @return
danielebarchiesi@0 186 * An associative array defining a title and a description string.
danielebarchiesi@0 187 *
danielebarchiesi@0 188 * @see hook_aggregator_process()
danielebarchiesi@0 189 *
danielebarchiesi@0 190 * @ingroup aggregator
danielebarchiesi@0 191 */
danielebarchiesi@0 192 function hook_aggregator_process_info() {
danielebarchiesi@0 193 return array(
danielebarchiesi@0 194 'title' => t('Default processor'),
danielebarchiesi@0 195 'description' => t('Creates lightweight records of feed items.'),
danielebarchiesi@0 196 );
danielebarchiesi@0 197 }
danielebarchiesi@0 198
danielebarchiesi@0 199 /**
danielebarchiesi@0 200 * Remove stored feed data.
danielebarchiesi@0 201 *
danielebarchiesi@0 202 * Aggregator calls this hook if either a feed is deleted or a user clicks on
danielebarchiesi@0 203 * "remove items".
danielebarchiesi@0 204 *
danielebarchiesi@0 205 * If your module stores feed items for example on hook_aggregator_process() it
danielebarchiesi@0 206 * is recommended to implement this hook and to remove data related to $feed
danielebarchiesi@0 207 * when called.
danielebarchiesi@0 208 *
danielebarchiesi@0 209 * @param $feed
danielebarchiesi@0 210 * The $feed object whose items are being removed.
danielebarchiesi@0 211 *
danielebarchiesi@0 212 * @ingroup aggregator
danielebarchiesi@0 213 */
danielebarchiesi@0 214 function hook_aggregator_remove($feed) {
danielebarchiesi@0 215 mymodule_remove_items($feed->fid);
danielebarchiesi@0 216 }
danielebarchiesi@0 217
danielebarchiesi@0 218 /**
danielebarchiesi@0 219 * @} End of "addtogroup hooks".
danielebarchiesi@0 220 */