source: sipes/modules_contrib/feeds/feeds.api.php @ ef72343

stableversion-3.0
Last change on this file since ef72343 was 177a560, checked in by José Gregorio Puentes <jpuentes@…>, 8 años ago

se agrego el directorio de modulos contribuidos de drupal

  • Propiedad mode establecida a 100755
File size: 7.7 KB
Línea 
1<?php
2
3/**
4 * @file
5 * Documentation of Feeds hooks.
6 */
7
8/**
9 * Feeds offers a CTools based plugin API. Fetchers, parsers and processors are
10 * declared to Feeds as plugins.
11 *
12 * @see feeds_feeds_plugins()
13 * @see FeedsFetcher
14 * @see FeedsParser
15 * @see FeedsProcessor
16 *
17 * @defgroup pluginapi Plugin API
18 * @{
19 */
20
21/**
22 * Example of a CTools plugin hook that needs to be implemented to make
23 * hook_feeds_plugins() discoverable by CTools and Feeds. The hook specifies
24 * that the hook_feeds_plugins() returns Feeds Plugin API version 1 style
25 * plugins.
26 */
27function hook_ctools_plugin_api($owner, $api) {
28  if ($owner == 'feeds' && $api == 'plugins') {
29    return array('version' => 1);
30  }
31}
32
33/**
34 * A hook_feeds_plugins() declares available Fetcher, Parser or Processor
35 * plugins to Feeds. For an example look at feeds_feeds_plugin(). For exposing
36 * this hook hook_ctools_plugin_api() MUST be implemented, too.
37 *
38 * @see feeds_feeds_plugin()
39 */
40function hook_feeds_plugins() {
41  $info = array();
42  $info['MyFetcher'] = array(
43    'name' => 'My Fetcher',
44    'description' => 'Fetches my stuff.',
45    'help' => 'More verbose description here. Will be displayed on fetcher selection menu.',
46    'handler' => array(
47      'parent' => 'FeedsFetcher',
48      'class' => 'MyFetcher',
49      'file' => 'MyFetcher.inc',
50      'path' => drupal_get_path('module', 'my_module'), // Feeds will look for MyFetcher.inc in the my_module directory.
51    ),
52  );
53  $info['MyParser'] = array(
54    'name' => 'ODK parser',
55    'description' => 'Parse my stuff.',
56    'help' => 'More verbose description here. Will be displayed on parser selection menu.',
57    'handler' => array(
58      'parent' => 'FeedsParser', // Being directly or indirectly an extension of FeedsParser makes a plugin a parser plugin.
59      'class' => 'MyParser',
60      'file' => 'MyParser.inc',
61      'path' => drupal_get_path('module', 'my_module'),
62    ),
63  );
64  $info['MyProcessor'] = array(
65    'name' => 'ODK parser',
66    'description' => 'Process my stuff.',
67    'help' => 'More verbose description here. Will be displayed on processor selection menu.',
68    'handler' => array(
69      'parent' => 'FeedsProcessor',
70      'class' => 'MyProcessor',
71      'file' => 'MyProcessor.inc',
72      'path' => drupal_get_path('module', 'my_module'),
73    ),
74  );
75  return $info;
76}
77
78/**
79 * @}
80 */
81
82/**
83 * @defgroup import Import and clear hooks
84 * @{
85 */
86
87/**
88 * Invoked after a feed source has been parsed, before it will be processed.
89 *
90 * @param $importer
91 *   FeedsImporter object that has been used for importing the feed.
92 * @param $source
93 *  FeedsSource object that describes the source that has been imported.
94 */
95function hook_feeds_after_parse(FeedsImporter $importer, FeedsSource $source) {
96  // For example, set title of imported content:
97  $source->batch->title = 'Import number '. my_module_import_id();
98}
99
100/**
101 * Invoked after a feed source has been imported.
102 *
103 * @param $importer
104 *   FeedsImporter object that has been used for importing the feed.
105 * @param $source
106 *  FeedsSource object that describes the source that has been imported.
107 */
108function hook_feeds_after_import(FeedsImporter $importer, FeedsSource $source) {
109  // See geotaxonomy module's implementation for an example.
110}
111
112/**
113 * Invoked after a feed source has been cleared of its items.
114 *
115 * @param $importer
116 *   FeedsImporter object that has been used for clearing the feed.
117 * @param $source
118 *  FeedsSource object that describes the source that has been cleared.
119 */
120function hook_feeds_after_clear(FeedsImporter $importer, FeedsSource $source) {
121}
122
123/**
124 * @}
125 */
126
127/**
128 * @defgroup mappingapi Mapping API
129 * @{
130 */
131
132/**
133 * Alter mapping sources.
134 *
135 * Use this hook to add additional mapping sources for any parser. Allows for
136 * registering a callback to be invoked at mapping time.
137 *
138 * my_callback(FeedsImportBatch $batch, $key)
139 *
140 * @see my_source_get_source().
141 * @see locale_feeds_parser_sources_alter().
142 */
143function hook_feeds_parser_sources_alter(&$sources, $content_type) {
144  $sources['my_source'] = array(
145    'name' => t('Images in description element'),
146    'description' => t('Images occuring in the description element of a feed item.'),
147    'callback' => 'my_source_get_source',
148  );
149}
150
151/**
152 * Callback specified in hook_feeds_parser_sources_alter().
153 *
154 * To be invoked on mapping time.
155 *
156 * @param $batch
157 *   The FeedsImportBatch object being mapped from.
158 * @param $key
159 *   The key specified in the $sources array in
160 *   hook_feeds_parser_sources_alter().
161 *
162 * @return
163 *   The value to be extracted from the source.
164 *
165 * @see hook_feeds_parser_sources_alter().
166 * @see locale_feeds_get_source().
167 */
168function my_source_get_source(FeedsImportBatch $batch, $key) {
169  $item = $batch->currentItem();
170  return my_source_parse_images($item['description']);
171}
172
173/**
174 * Alter mapping targets for users. Use this hook to add additional target
175 * options to the mapping form of User processors.
176 *
177 * For an example implementation, see mappers/profile.inc
178 *
179 * @param: &$targets
180 *  Array containing the targets to be offered to the user. Add to this array
181 *  to expose additional options. Remove from this array to suppress options.
182 */
183function hook_feeds_user_processor_targets_alter(&$targets) {
184  $targets['my_user_field'] = array(
185    'name' => t('My custom user field'),
186    'description' => t('Description of what my custom user field does.'),
187    'callback' => 'my_callback',
188  );
189}
190
191/**
192 * Alter mapping targets for nodes. Use this hook to add additional target
193 * options to the mapping form of Node processors.
194 *
195 * If the key in $targets[] does not correspond to the actual key on the node
196 * object ($node->key), real_target MUST be specified. See mappers/link.inc
197 *
198 * For an example implementation, see mappers/content.inc
199 *
200 * @param &$targets
201 *   Array containing the targets to be offered to the user. Add to this array
202 *   to expose additional options. Remove from this array to suppress options.
203 *   Remove with caution.
204 * @param $content_type
205 *   The content type of the target node.
206 */
207function hook_feeds_node_processor_targets_alter(&$targets, $content_type) {
208  $targets['my_node_field'] = array(
209    'name' => t('My custom node field'),
210    'description' => t('Description of what my custom node field does.'),
211    'callback' => 'my_callback',
212  );
213  $targets['my_node_field2'] = array(
214    'name' => t('My Second custom node field'),
215    'description' => t('Description of what my second custom node field does.'),
216    'callback' => 'my_callback2',
217    'real_target' => 'my_node_field_two', // Specify real target field on node.
218  );
219}
220
221/**
222 * Alter mapping targets for taxonomy terms. Use this hook to add additional
223 * target options to the mapping form of Taxonomy term processor.
224 *
225 * For an example implementation, look at geotaxnomy module.
226 * http://drupal.org/project/geotaxonomy
227 *
228 * @param &$targets
229 *   Array containing the targets to be offered to the user. Add to this array
230 *   to expose additional options. Remove from this array to suppress options.
231 *   Remove with caution.
232 * @param $vid
233 *   The vocabulary id
234 */
235function hook_feeds_term_processor_targets_alter(&$targets, $vid) {
236  if (variable_get('mymodule_vocabulary_'. $vid, 0)) {
237    $targets['lat'] = array(
238      'name' => t('Latitude'),
239      'description' => t('Latitude of the term.'),
240    );
241    $targets['lon'] = array(
242      'name' => t('Longitude'),
243      'description' => t('Longitude of the term.'),
244    );
245  }
246}
247
248/**
249 * Alter mapping targets for Data table entries. Use this hook to add additional
250 * target options to the mapping form of Data processor.
251 */
252function hook_feeds_data_processor_targets_alter(&$fields, $data_table) {
253  if ($data_table == mymodule_base_table()) {
254    $fields['mytable:category'] = array(
255      'name' => t('Category'),
256      'description' => t('One or more category terms.'),
257    );
258  }
259}
260
261/**
262 * @}
263 */
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.