Révision ed9a13f1
Ajouté par Assos Assos il y a plus de 3 ans
drupal7/sites/all/modules/feeds/feeds.module | ||
---|---|---|
31 | 31 |
'feeds_after_parse', |
32 | 32 |
'feeds_before_import', |
33 | 33 |
'feeds_before_update', |
34 |
'feeds_prevalidate', |
|
34 | 35 |
'feeds_presave', |
35 | 36 |
'feeds_after_save', |
36 | 37 |
'feeds_after_import', |
... | ... | |
96 | 97 |
'queue name' => 'feeds_source_import', |
97 | 98 |
); |
98 | 99 |
// feeds_source_clear never gets called, since we now use the queue directly. |
99 |
// This is left in case any background jobs still running after an |
|
100 |
// This is left in case any background jobs are still running after an
|
|
100 | 101 |
// upgrade. |
101 | 102 |
$info['feeds_source_clear'] = array( |
102 | 103 |
'queue name' => 'feeds_source_clear', |
... | ... | |
137 | 138 |
|
138 | 139 |
/** |
139 | 140 |
* Scheduler callback for importing from a source. |
141 |
* |
|
142 |
* @param array $job |
|
143 |
* A job definition, which consists of at least the following elements: |
|
144 |
* - type (string) |
|
145 |
* The importer ID. |
|
146 |
* - id (int) |
|
147 |
* The Feed node ID if the importer is attached to a content type. Otherwise |
|
148 |
* 0. |
|
140 | 149 |
*/ |
141 | 150 |
function feeds_source_import(array $job) { |
142 | 151 |
$source = _feeds_queue_worker_helper($job, 'import'); |
... | ... | |
147 | 156 |
|
148 | 157 |
/** |
149 | 158 |
* Scheduler callback for deleting all items from a source. |
159 |
* |
|
160 |
* @param array $job |
|
161 |
* A job definition, which consists of at least the following elements: |
|
162 |
* - type (string) |
|
163 |
* The importer ID. |
|
164 |
* - id (int) |
|
165 |
* The Feed node ID if the importer is attached to a content type. Otherwise |
|
166 |
* 0. |
|
150 | 167 |
*/ |
151 | 168 |
function feeds_source_clear(array $job) { |
152 | 169 |
$source = _feeds_queue_worker_helper($job, 'clear'); |
... | ... | |
157 | 174 |
|
158 | 175 |
/** |
159 | 176 |
* Scheduler callback for expiring content. |
177 |
* |
|
178 |
* @param array $job |
|
179 |
* A job definition, which consists of at least the following elements: |
|
180 |
* - type (string) |
|
181 |
* The importer ID. |
|
182 |
* - id (int) |
|
183 |
* The Feed node ID if the importer is attached to a content type. Otherwise |
|
184 |
* 0. |
|
160 | 185 |
*/ |
161 | 186 |
function feeds_source_expire(array $job) { |
162 | 187 |
$source = _feeds_queue_worker_helper($job, 'expire'); |
... | ... | |
169 | 194 |
* Executes a method on a feed source. |
170 | 195 |
* |
171 | 196 |
* @param array $job |
172 |
* The job being run. |
|
197 |
* A job definition, which consists of at least the following elements: |
|
198 |
* - type (string) |
|
199 |
* The importer ID. |
|
200 |
* - id (int) |
|
201 |
* The Feed node ID if the importer is attached to a content type. Otherwise |
|
202 |
* 0. |
|
173 | 203 |
* @param string $method |
174 | 204 |
* The method to execute. |
175 | 205 |
*/ |
... | ... | |
190 | 220 |
} |
191 | 221 |
|
192 | 222 |
/** |
193 |
* Scheduler callback for syncing the feeds cache directory with the entries in |
|
194 |
* the cache. |
|
223 |
* Scheduler callback for keeping the cache dir and cache entries in sync. |
|
224 |
* |
|
225 |
* This makes sure that files that appear in the Feeds cache directory that are |
|
226 |
* no longer referenced in the cache_feeds_http bin, are cleaned up. |
|
227 |
* The entries saved in the cache_feeds_http bin and the actual cached files |
|
228 |
* saved on the file system can get out of sync when: |
|
229 |
* - Truncating the cache_feeds_http table manually. |
|
230 |
* - When using an alternative cache class for the cache_feeds_http bin |
|
231 |
* (other than 'FeedsHTTPCache'). |
|
195 | 232 |
*/ |
196 | 233 |
function feeds_sync_cache_feeds_http(array $job) { |
197 | 234 |
FeedsHTTPCache::getInstance('cache_feeds_http')->sync($job['files']); |
... | ... | |
199 | 236 |
|
200 | 237 |
/** |
201 | 238 |
* Scheduler callback for unsubscribing from PuSH hubs. |
239 |
* |
|
240 |
* @param array $job |
|
241 |
* A job definition, which consists of at least the following elements: |
|
242 |
* - type (string) |
|
243 |
* The importer ID. |
|
244 |
* - id (int) |
|
245 |
* The Feed node ID if the importer is attached to a content type. Otherwise |
|
246 |
* 0. |
|
202 | 247 |
*/ |
203 | 248 |
function feeds_push_unsubscribe($job) { |
204 | 249 |
$source = feeds_source($job['type'], $job['id']); |
250 |
/** @var FeedsFetcher $fetcher */ |
|
205 | 251 |
$fetcher = feeds_plugin('FeedsHTTPFetcher', $source->importer->id); |
206 | 252 |
$fetcher->unsubscribe($source); |
207 | 253 |
} |
... | ... | |
209 | 255 |
/** |
210 | 256 |
* Batch API worker callback. Used by FeedsSource::startBatchAPIJob(). |
211 | 257 |
* |
212 |
* @see FeedsSource::startBatchAPIJob(). |
|
213 |
* |
|
214 | 258 |
* @todo Harmonize Job Scheduler API callbacks with Batch API callbacks? |
215 | 259 |
* |
216 |
* @param $method |
|
260 |
* @param string $method
|
|
217 | 261 |
* Method to execute on importer; one of 'import' or 'clear'. |
218 |
* @param $importer_id |
|
262 |
* @param string $importer_id
|
|
219 | 263 |
* Identifier of a FeedsImporter object. |
220 |
* @param $feed_nid |
|
264 |
* @param int $feed_nid
|
|
221 | 265 |
* If importer is attached to content type, feed node id identifying the |
222 | 266 |
* source to be imported. |
223 |
* @param $context |
|
267 |
* @param array $context
|
|
224 | 268 |
* Batch context. |
269 |
* |
|
270 |
* @see FeedsSource::startBatchAPIJob() |
|
225 | 271 |
*/ |
226 | 272 |
function feeds_batch($method, $importer_id, $feed_nid = 0, &$context) { |
227 | 273 |
$context['finished'] = FEEDS_BATCH_COMPLETE; |
... | ... | |
236 | 282 |
/** |
237 | 283 |
* Reschedule one or all importers. |
238 | 284 |
* |
239 |
* @param string $importer_id |
|
285 |
* @param string|bool|null $importer_id
|
|
240 | 286 |
* If TRUE, all importers will be rescheduled, if FALSE, no importers will |
241 | 287 |
* be rescheduled, if an importer id, only importer of that id will be |
242 | 288 |
* rescheduled. |
243 | 289 |
* |
244 |
* @return array
|
|
245 |
* An list of importers that need rescheduling.
|
|
290 |
* @return string[]
|
|
291 |
* A list of importer ids that need rescheduling.
|
|
246 | 292 |
*/ |
247 | 293 |
function feeds_reschedule($importer_id = NULL) { |
248 | 294 |
$reschedule = variable_get('feeds_reschedule', FALSE); |
... | ... | |
270 | 316 |
} |
271 | 317 |
|
272 | 318 |
/** |
273 |
* Implements feeds_permission().
|
|
319 |
* Implements hook_permission().
|
|
274 | 320 |
*/ |
275 | 321 |
function feeds_permission() { |
276 | 322 |
$perms = array( |
277 | 323 |
'administer feeds' => array( |
278 | 324 |
'title' => t('Administer Feeds'), |
279 |
'description' => t('Create, update, delete importers, execute import and delete tasks on any importer.') |
|
325 |
'description' => t('Create, update, delete importers, execute import and delete tasks on any importer.'),
|
|
280 | 326 |
), |
281 | 327 |
); |
282 | 328 |
foreach (feeds_importer_load_all() as $importer) { |
... | ... | |
288 | 334 |
); |
289 | 335 |
$perms["unlock $importer->id feeds"] = array( |
290 | 336 |
'title' => t('Unlock imports from @name feeds', array('@name' => $importer->config['name'])), |
291 |
'description' => t('If a feed importation breaks for some reason, users with this permission can unlock them.') |
|
337 |
'description' => t('If a feed importation breaks for some reason, users with this permission can unlock them.'),
|
|
292 | 338 |
); |
293 | 339 |
} |
294 | 340 |
return $perms; |
... | ... | |
419 | 465 |
|
420 | 466 |
/** |
421 | 467 |
* Menu loader callback. |
468 |
* |
|
469 |
* @param string $id |
|
470 |
* The ID of the importer to load. |
|
471 |
* |
|
472 |
* @return FeedsImporter|false |
|
473 |
* A FeedsImporter instance if found. False otherwise. |
|
422 | 474 |
*/ |
423 | 475 |
function feeds_importer_load($id) { |
424 | 476 |
try { |
... | ... | |
427 | 479 |
return $importer; |
428 | 480 |
} |
429 | 481 |
} |
430 |
catch (InvalidArgumentException $e) {} |
|
482 |
catch (InvalidArgumentException $e) { |
|
483 |
} |
|
431 | 484 |
|
432 | 485 |
return FALSE; |
433 | 486 |
} |
434 | 487 |
|
435 | 488 |
/** |
436 | 489 |
* Title callback. |
490 |
* |
|
491 |
* @param FeedsImporter $importer |
|
492 |
* The importer to return the page title for. |
|
493 |
* |
|
494 |
* @return string |
|
495 |
* A page title. |
|
437 | 496 |
*/ |
438 | 497 |
function feeds_importer_title(FeedsImporter $importer) { |
439 | 498 |
return $importer->config['name']; |
... | ... | |
463 | 522 |
/** |
464 | 523 |
* Menu access callback. |
465 | 524 |
* |
466 |
* @param $action |
|
525 |
* @param string $action
|
|
467 | 526 |
* The action to be performed. Possible values are: |
468 |
* - import |
|
469 |
* - clear |
|
470 |
* - unlock |
|
471 |
* @param $param |
|
527 |
* - import;
|
|
528 |
* - clear;
|
|
529 |
* - unlock.
|
|
530 |
* @param object|string $param
|
|
472 | 531 |
* Node object or FeedsImporter id. |
532 |
* |
|
533 |
* @return bool |
|
534 |
* True if access is granted. False otherwise. |
|
473 | 535 |
*/ |
474 | 536 |
function feeds_access($action, $param) { |
475 | 537 |
if (!in_array($action, array('import', 'clear', 'unlock'))) { |
... | ... | |
502 | 564 |
* |
503 | 565 |
* Feeds imports require an additional access check because they are PHP |
504 | 566 |
* code and PHP is more locked down than administer feeds. |
567 |
* |
|
568 |
* @return bool |
|
569 |
* True if access is granted. False otherwise. |
|
505 | 570 |
*/ |
506 | 571 |
function feeds_importer_import_access() { |
507 | 572 |
return user_access('administer feeds') && user_access('use PHP for settings'); |
... | ... | |
509 | 574 |
|
510 | 575 |
/** |
511 | 576 |
* Menu access callback. |
577 |
* |
|
578 |
* @return bool |
|
579 |
* True if access is granted. False otherwise. |
|
512 | 580 |
*/ |
513 | 581 |
function feeds_page_access() { |
514 | 582 |
if (user_access('administer feeds')) { |
... | ... | |
531 | 599 |
foreach ($jobs as $job) { |
532 | 600 |
if (!isset($job['fetcher']) || !isset($job['source'])) { |
533 | 601 |
continue; |
534 |
}
|
|
602 |
} |
|
535 | 603 |
$job['fetcher']->subscribe($job['source']); |
536 | 604 |
} |
537 | 605 |
|
... | ... | |
782 | 850 |
} |
783 | 851 |
|
784 | 852 |
/** |
785 |
* Implements hook_features_pipe_COMPONENT_alter() for component "feeds_importer".
|
|
853 |
* Implements hook_features_pipe_COMPONENT_alter() for 'feeds_importer'.
|
|
786 | 854 |
* |
787 | 855 |
* Automatically adds dependencies when a Feed importer is selected in Features. |
788 | 856 |
*/ |
... | ... | |
930 | 998 |
|
931 | 999 |
foreach (feeds_importer_load_all() as $importer) { |
932 | 1000 |
$content['menu']['admin/content']['admin/content/feeds_import'][$importer->id] = array( |
933 |
'#title' => t($importer->config['name']),
|
|
1001 |
'#title' => check_plain($importer->config['name']),
|
|
934 | 1002 |
'#href' => !empty($importer->config['content_type']) ? 'node/add/' . str_replace('_', '-', $importer->config['content_type']) : 'import/' . check_plain($importer->id), |
935 | 1003 |
'#access' => user_access('administer feeds') || user_access("import $importer->id feeds"), |
936 | 1004 |
); |
... | ... | |
962 | 1030 |
} |
963 | 1031 |
} |
964 | 1032 |
|
965 |
|
|
966 | 1033 |
/** |
967 | 1034 |
* @} |
968 | 1035 |
*/ |
... | ... | |
975 | 1042 |
/** |
976 | 1043 |
* Loads all importers. |
977 | 1044 |
* |
978 |
* @param $load_disabled |
|
1045 |
* @param bool $load_disabled
|
|
979 | 1046 |
* Pass TRUE to load all importers, enabled or disabled, pass FALSE to only |
980 | 1047 |
* retrieve enabled importers. |
981 | 1048 |
* |
982 |
* @return |
|
1049 |
* @return array
|
|
983 | 1050 |
* An array of all feed configurations available. |
984 | 1051 |
*/ |
985 | 1052 |
function feeds_importer_load_all($load_disabled = FALSE) { |
... | ... | |
1019 | 1086 |
/** |
1020 | 1087 |
* Gets an array of enabled importer ids. |
1021 | 1088 |
* |
1022 |
* @return |
|
1089 |
* @return string[]
|
|
1023 | 1090 |
* An array where the values contain ids of enabled importers. |
1024 | 1091 |
*/ |
1025 | 1092 |
function feeds_enabled_importers() { |
... | ... | |
1029 | 1096 |
/** |
1030 | 1097 |
* Gets an enabled importer configuration by content type. |
1031 | 1098 |
* |
1032 |
* @param $content_type |
|
1099 |
* @param string $content_type
|
|
1033 | 1100 |
* A node type string. |
1034 | 1101 |
* |
1035 |
* @return |
|
1102 |
* @return string|false
|
|
1036 | 1103 |
* A FeedsImporter id if there is an importer for the given content type, |
1037 | 1104 |
* FALSE otherwise. |
1038 | 1105 |
*/ |
... | ... | |
1177 | 1244 |
/** |
1178 | 1245 |
* Gets an importer instance. |
1179 | 1246 |
* |
1180 |
* @param $id |
|
1247 |
* @param string $id
|
|
1181 | 1248 |
* The unique id of the importer object. |
1182 | 1249 |
* |
1183 |
* @return |
|
1250 |
* @return FeedsImporter
|
|
1184 | 1251 |
* A FeedsImporter object or an object of a class defined by the Drupal |
1185 | 1252 |
* variable 'feeds_importer_class'. There is only one importer object |
1186 | 1253 |
* per $id system-wide. |
... | ... | |
1192 | 1259 |
/** |
1193 | 1260 |
* Gets an instance of a source object. |
1194 | 1261 |
* |
1195 |
* @param $importer_id |
|
1262 |
* @param string $importer_id
|
|
1196 | 1263 |
* A FeedsImporter id. |
1197 |
* @param $feed_nid |
|
1264 |
* @param int $feed_nid
|
|
1198 | 1265 |
* The node id of a feed node if the source is attached to a feed node. |
1199 | 1266 |
* |
1200 |
* @return |
|
1201 |
* A FeedsSource object or an object of a class defiend by the Drupal
|
|
1267 |
* @return FeedsSource
|
|
1268 |
* A FeedsSource object or an object of a class defined by the Drupal
|
|
1202 | 1269 |
* variable 'source_class'. |
1203 | 1270 |
*/ |
1204 | 1271 |
function feeds_source($importer_id, $feed_nid = 0) { |
... | ... | |
1260 | 1327 |
* The name of the library. If libraries module is installed, |
1261 | 1328 |
* feeds_include_library() will look for libraries with this name managed by |
1262 | 1329 |
* libraries module. |
1330 |
* |
|
1331 |
* @return bool |
|
1332 |
* True if the requested library was found and included with success. False |
|
1333 |
* otherwise. |
|
1263 | 1334 |
*/ |
1264 | 1335 |
function feeds_include_library($file, $library) { |
1265 | 1336 |
static $included = array(); |
... | ... | |
1307 | 1378 |
* The name of the library. If libraries module is installed, |
1308 | 1379 |
* feeds_library_exists() will look for libraries with this name managed by |
1309 | 1380 |
* libraries module. |
1381 |
* |
|
1382 |
* @return bool |
|
1383 |
* True if the library exists. False otherwise. |
|
1310 | 1384 |
*/ |
1311 | 1385 |
function feeds_library_exists($file, $library) { |
1312 | 1386 |
$path = module_exists('libraries') ? libraries_get_path($library) : FALSE; |
... | ... | |
1328 | 1402 |
return FALSE; |
1329 | 1403 |
} |
1330 | 1404 |
|
1331 |
/**
|
|
1405 |
/** |
|
1332 | 1406 |
* Checks whether simplepie exists. |
1333 | 1407 |
*/ |
1334 | 1408 |
function feeds_simplepie_exists() { |
... | ... | |
1360 | 1434 |
return FALSE; |
1361 | 1435 |
} |
1362 | 1436 |
|
1363 |
/** |
|
1364 |
* @deprecated |
|
1365 |
* |
|
1366 |
* Simplified drupal_alter(). |
|
1367 |
* |
|
1368 |
* - None of that 'multiple parameters by ref' crazyness. |
|
1369 |
* - Don't use module_implements() to allow hot including on behalf |
|
1370 |
* implementations (see mappers/). |
|
1371 |
* |
|
1372 |
* @todo This needs to be removed and drupal_alter() used. This is crazy dumb. |
|
1373 |
*/ |
|
1374 |
function feeds_alter($type, &$data) { |
|
1375 |
$args = array(&$data); |
|
1376 |
$additional_args = func_get_args(); |
|
1377 |
array_shift($additional_args); |
|
1378 |
array_shift($additional_args); |
|
1379 |
$args = array_merge($args, $additional_args); |
|
1380 |
|
|
1381 |
$hook = $type . '_alter'; |
|
1382 |
foreach (module_list() as $module) { |
|
1383 |
if (module_hook($module, $hook)) { |
|
1384 |
call_user_func_array($module . '_' . $hook, $args); |
|
1385 |
} |
|
1386 |
} |
|
1387 |
} |
|
1388 |
|
|
1389 | 1437 |
/** |
1390 | 1438 |
* @} |
1391 | 1439 |
*/ |
... | ... | |
1393 | 1441 |
/** |
1394 | 1442 |
* Copy of valid_url() that supports the webcal scheme. |
1395 | 1443 |
* |
1396 |
* @see valid_url().
|
|
1444 |
* @see valid_url() |
|
1397 | 1445 |
* |
1398 | 1446 |
* @todo Replace with valid_url() when http://drupal.org/node/295021 is fixed. |
1399 | 1447 |
*/ |
... | ... | |
1428 | 1476 |
* Information about a new job to queue; or if set to NULL (default), leaves |
1429 | 1477 |
* the current queued jobs unchanged. |
1430 | 1478 |
* |
1431 |
* @return |
|
1479 |
* @return array
|
|
1432 | 1480 |
* An array of subscribe jobs to process. |
1433 | 1481 |
* |
1434 | 1482 |
* @see feeds_exit() |
... | ... | |
1445 | 1493 |
/** |
1446 | 1494 |
* Returns the list of queued jobs to be run. |
1447 | 1495 |
* |
1448 |
* @return |
|
1496 |
* @return array
|
|
1449 | 1497 |
* An array of subscribe jobs to process. |
1450 | 1498 |
* |
1451 | 1499 |
* @see feeds_set_subscription_job() |
... | ... | |
1519 | 1567 |
} |
1520 | 1568 |
|
1521 | 1569 |
// No feed item. Try to load the feed item if the entity has an ID. |
1522 |
list($entity_id, , ) = entity_extract_ids($entity_type, $entity);
|
|
1570 |
list($entity_id) = entity_extract_ids($entity_type, $entity); |
|
1523 | 1571 |
if ($entity_id) { |
1524 | 1572 |
$feeds_item = feeds_item_info_load($entity_type, $entity_id); |
1525 | 1573 |
|
... | ... | |
1541 | 1589 |
return; |
1542 | 1590 |
} |
1543 | 1591 |
|
1544 |
// Get the file record based on the URI. If not in the database just return.
|
|
1592 |
// Get the file record based on the URI. If not in the database just return. |
|
1545 | 1593 |
$files = file_load_multiple(array(), array('uri' => $uri)); |
1546 | 1594 |
foreach ($files as $item) { |
1547 | 1595 |
// Since some database servers sometimes use a case-insensitive comparison |
Formats disponibles : Unified diff
Weekly update of contrib modules