Révision 41cc1b08
Ajouté par Assos Assos il y a presque 9 ans
drupal7/sites/all/modules/feeds/feeds.module | ||
---|---|---|
35 | 35 |
'feeds_after_save', |
36 | 36 |
'feeds_after_import', |
37 | 37 |
'feeds_after_clear', |
38 |
'feeds_processor_targets', |
|
38 | 39 |
'feeds_processor_targets_alter', |
39 | 40 |
'feeds_parser_sources_alter', |
40 | 41 |
); |
... | ... | |
46 | 47 |
* Implements hook_cron(). |
47 | 48 |
*/ |
48 | 49 |
function feeds_cron() { |
49 |
if ($importers = feeds_reschedule()) { |
|
50 |
foreach ($importers as $id) { |
|
51 |
feeds_importer($id)->schedule(); |
|
52 |
$rows = db_query("SELECT feed_nid FROM {feeds_source} WHERE id = :id", array(':id' => $id)); |
|
53 |
foreach ($rows as $row) { |
|
54 |
feeds_source($id, $row->feed_nid)->schedule(); |
|
55 |
} |
|
56 |
} |
|
57 |
feeds_reschedule(FALSE); |
|
58 |
} |
|
59 | 50 |
// Expire old log entries. |
60 | 51 |
db_delete('feeds_log') |
61 | 52 |
->condition('request_time', REQUEST_TIME - 604800, '<') |
62 | 53 |
->execute(); |
54 |
|
|
55 |
// Find importers that need to be rescheduled. |
|
56 |
if (!$importers = feeds_reschedule()) { |
|
57 |
return; |
|
58 |
} |
|
59 |
|
|
60 |
// @todo Maybe we should queue this somehow as well. This could be potentially |
|
61 |
// very long. |
|
62 |
$sources = db_query("SELECT feed_nid, id FROM {feeds_source} WHERE id IN (:ids)", array(':ids' => $importers)); |
|
63 |
|
|
64 |
foreach ($sources as $source) { |
|
65 |
feeds_source($source->id, $source->feed_nid)->schedule(); |
|
66 |
} |
|
67 |
|
|
68 |
feeds_reschedule(FALSE); |
|
63 | 69 |
} |
64 | 70 |
|
65 | 71 |
/** |
... | ... | |
75 | 81 |
$info['feeds_source_clear'] = array( |
76 | 82 |
'queue name' => 'feeds_source_clear', |
77 | 83 |
); |
78 |
$info['feeds_importer_expire'] = array(
|
|
79 |
'queue name' => 'feeds_importer_expire',
|
|
84 |
$info['feeds_source_expire'] = array(
|
|
85 |
'queue name' => 'feeds_source_expire',
|
|
80 | 86 |
); |
81 | 87 |
$info['feeds_push_unsubscribe'] = array( |
82 | 88 |
'queue name' => 'feeds_push_unsubscribe', |
... | ... | |
91 | 97 |
$queues = array(); |
92 | 98 |
$queues['feeds_source_import'] = array( |
93 | 99 |
'worker callback' => 'feeds_source_import', |
94 |
'time' => 15,
|
|
100 |
'time' => 60,
|
|
95 | 101 |
); |
96 | 102 |
$queues['feeds_source_clear'] = array( |
97 | 103 |
'worker callback' => 'feeds_source_clear', |
98 |
'time' => 15, |
|
99 | 104 |
); |
100 |
$queues['feeds_importer_expire'] = array( |
|
101 |
'worker callback' => 'feeds_importer_expire', |
|
102 |
'time' => 15, |
|
105 |
$queues['feeds_source_expire'] = array( |
|
106 |
'worker callback' => 'feeds_source_expire', |
|
103 | 107 |
); |
104 | 108 |
$queues['feeds_push_unsubscribe'] = array( |
105 | 109 |
'worker callback' => 'feeds_push_unsubscribe', |
106 |
'time' => 15, |
|
107 | 110 |
); |
111 |
|
|
108 | 112 |
return $queues; |
109 | 113 |
} |
110 | 114 |
|
111 | 115 |
/** |
112 | 116 |
* Scheduler callback for importing from a source. |
113 | 117 |
*/ |
114 |
function feeds_source_import($job) { |
|
115 |
$source = feeds_source($job['type'], $job['id']); |
|
116 |
try { |
|
117 |
$source->existing()->import(); |
|
118 |
} |
|
119 |
catch (FeedsNotExistingException $e) { |
|
120 |
// Do nothing. |
|
121 |
} |
|
122 |
catch (Exception $e) { |
|
123 |
$source->log('import', $e->getMessage(), array(), WATCHDOG_ERROR); |
|
124 |
} |
|
118 |
function feeds_source_import(array $job) { |
|
119 |
$source = _feeds_queue_worker_helper($job, 'import'); |
|
125 | 120 |
$source->scheduleImport(); |
126 | 121 |
} |
127 | 122 |
|
128 | 123 |
/** |
129 | 124 |
* Scheduler callback for deleting all items from a source. |
130 | 125 |
*/ |
131 |
function feeds_source_clear($job) { |
|
132 |
$source = feeds_source($job['type'], $job['id']); |
|
133 |
try { |
|
134 |
$source->existing()->clear(); |
|
135 |
} |
|
136 |
catch (FeedsNotExistingException $e) { |
|
137 |
// Do nothing. |
|
138 |
} |
|
139 |
catch (Exception $e) { |
|
140 |
$source->log('clear', $e->getMessage(), array(), WATCHDOG_ERROR); |
|
141 |
} |
|
126 |
function feeds_source_clear(array $job) { |
|
127 |
$source = _feeds_queue_worker_helper($job, 'clear'); |
|
142 | 128 |
$source->scheduleClear(); |
143 | 129 |
} |
144 | 130 |
|
145 | 131 |
/** |
146 | 132 |
* Scheduler callback for expiring content. |
147 | 133 |
*/ |
148 |
function feeds_importer_expire($job) { |
|
149 |
$importer = feeds_importer($job['type']); |
|
134 |
function feeds_source_expire(array $job) { |
|
135 |
$source = _feeds_queue_worker_helper($job, 'expire'); |
|
136 |
$source->scheduleExpire(); |
|
137 |
} |
|
138 |
|
|
139 |
/** |
|
140 |
* Executes a method on a feed source. |
|
141 |
* |
|
142 |
* @param array $job |
|
143 |
* The job being run. |
|
144 |
* @param string $method |
|
145 |
* The method to execute. |
|
146 |
*/ |
|
147 |
function _feeds_queue_worker_helper(array $job, $method) { |
|
148 |
$source = feeds_source($job['type'], $job['id']); |
|
150 | 149 |
try { |
151 |
$importer->existing()->expire();
|
|
150 |
$source->existing()->$method();
|
|
152 | 151 |
} |
153 | 152 |
catch (FeedsNotExistingException $e) { |
154 | 153 |
// Do nothing. |
155 | 154 |
} |
156 | 155 |
catch (Exception $e) { |
157 |
$importer->log('expire', $e->getMessage(), array(), WATCHDOG_ERROR);
|
|
156 |
$source->log($method, $e->getMessage(), array(), WATCHDOG_ERROR);
|
|
158 | 157 |
} |
159 |
$importer->scheduleExpire(); |
|
158 |
|
|
159 |
return $source; |
|
160 | 160 |
} |
161 | 161 |
|
162 | 162 |
/** |
... | ... | |
198 | 198 |
/** |
199 | 199 |
* Reschedule one or all importers. |
200 | 200 |
* |
201 |
* @param $importer_id |
|
201 |
* @param string $importer_id
|
|
202 | 202 |
* If TRUE, all importers will be rescheduled, if FALSE, no importers will |
203 | 203 |
* be rescheduled, if an importer id, only importer of that id will be |
204 | 204 |
* rescheduled. |
205 | 205 |
* |
206 |
* @return |
|
207 |
* TRUE if all importers need rescheduling. FALSE if no rescheduling is |
|
208 |
* required. An array of importers that need rescheduling. |
|
206 |
* @return array |
|
207 |
* An list of importers that need rescheduling. |
|
209 | 208 |
*/ |
210 | 209 |
function feeds_reschedule($importer_id = NULL) { |
211 | 210 |
$reschedule = variable_get('feeds_reschedule', FALSE); |
211 |
|
|
212 | 212 |
if ($importer_id === TRUE || $importer_id === FALSE) { |
213 | 213 |
$reschedule = $importer_id; |
214 | 214 |
} |
215 | 215 |
elseif (is_string($importer_id) && $reschedule !== TRUE) { |
216 |
$reschedule = is_array($reschedule) ? $reschedule : array();
|
|
216 |
$reschedule = array_filter((array) $reschedule);
|
|
217 | 217 |
$reschedule[$importer_id] = $importer_id; |
218 | 218 |
} |
219 |
variable_set('feeds_reschedule', $reschedule); |
|
219 |
|
|
220 |
if (isset($importer_id)) { |
|
221 |
variable_set('feeds_reschedule', $reschedule); |
|
222 |
} |
|
223 |
|
|
220 | 224 |
if ($reschedule === TRUE) { |
221 | 225 |
return feeds_enabled_importers(); |
222 | 226 |
} |
227 |
elseif ($reschedule === FALSE) { |
|
228 |
return array(); |
|
229 |
} |
|
230 |
|
|
223 | 231 |
return $reschedule; |
224 | 232 |
} |
225 | 233 |
|
... | ... | |
274 | 282 |
'access callback' => 'feeds_page_access', |
275 | 283 |
'file' => 'feeds.pages.inc', |
276 | 284 |
); |
277 |
$items['import/%'] = array( |
|
285 |
$items['import/%feeds_importer'] = array(
|
|
278 | 286 |
'title callback' => 'feeds_importer_title', |
279 | 287 |
'title arguments' => array(1), |
280 | 288 |
'page callback' => 'drupal_get_form', |
... | ... | |
283 | 291 |
'access arguments' => array('import', 1), |
284 | 292 |
'file' => 'feeds.pages.inc', |
285 | 293 |
); |
286 |
$items['import/%/import'] = array( |
|
294 |
$items['import/%feeds_importer/import'] = array(
|
|
287 | 295 |
'title' => 'Import', |
288 | 296 |
'type' => MENU_DEFAULT_LOCAL_TASK, |
289 | 297 |
'weight' => -10, |
290 | 298 |
); |
291 |
$items['import/%/delete-items'] = array( |
|
299 |
$items['import/%feeds_importer/delete-items'] = array(
|
|
292 | 300 |
'title' => 'Delete items', |
293 | 301 |
'page callback' => 'drupal_get_form', |
294 | 302 |
'page arguments' => array('feeds_delete_tab_form', 1), |
... | ... | |
297 | 305 |
'file' => 'feeds.pages.inc', |
298 | 306 |
'type' => MENU_LOCAL_TASK, |
299 | 307 |
); |
300 |
$items['import/%/unlock'] = array( |
|
308 |
$items['import/%feeds_importer/unlock'] = array(
|
|
301 | 309 |
'title' => 'Unlock', |
302 | 310 |
'page callback' => 'drupal_get_form', |
303 | 311 |
'page arguments' => array('feeds_unlock_tab_form', 1), |
... | ... | |
306 | 314 |
'file' => 'feeds.pages.inc', |
307 | 315 |
'type' => MENU_LOCAL_TASK, |
308 | 316 |
); |
309 |
$items['import/%/template'] = array( |
|
317 |
$items['import/%feeds_importer/template'] = array(
|
|
310 | 318 |
'page callback' => 'feeds_importer_template', |
311 | 319 |
'page arguments' => array(1), |
312 | 320 |
'access callback' => 'feeds_access', |
... | ... | |
352 | 360 |
return $items; |
353 | 361 |
} |
354 | 362 |
|
363 |
/** |
|
364 |
* Implements hook_admin_paths(). |
|
365 |
*/ |
|
366 |
function feeds_admin_paths() { |
|
367 |
$paths = array( |
|
368 |
'import' => TRUE, |
|
369 |
'import/*' => TRUE, |
|
370 |
'node/*/import' => TRUE, |
|
371 |
'node/*/delete-items' => TRUE, |
|
372 |
'node/*/log' => TRUE, |
|
373 |
); |
|
374 |
return $paths; |
|
375 |
} |
|
376 |
|
|
355 | 377 |
/** |
356 | 378 |
* Menu loader callback. |
357 | 379 |
*/ |
358 | 380 |
function feeds_importer_load($id) { |
359 |
return feeds_importer($id); |
|
381 |
try { |
|
382 |
return feeds_importer($id)->existing(); |
|
383 |
} |
|
384 |
catch (FeedsNotExistingException $e) {} |
|
385 |
catch (InvalidArgumentException $e) {} |
|
386 |
|
|
387 |
return FALSE; |
|
360 | 388 |
} |
361 | 389 |
|
362 | 390 |
/** |
363 | 391 |
* Title callback. |
364 | 392 |
*/ |
365 |
function feeds_importer_title($id) { |
|
366 |
$importer = feeds_importer($id); |
|
393 |
function feeds_importer_title(FeedsImporter $importer) { |
|
367 | 394 |
return $importer->config['name']; |
368 | 395 |
} |
369 | 396 |
|
... | ... | |
405 | 432 |
return FALSE; |
406 | 433 |
} |
407 | 434 |
|
435 |
$importer_id = FALSE; |
|
408 | 436 |
if (is_string($param)) { |
409 | 437 |
$importer_id = $param; |
410 | 438 |
} |
439 |
elseif ($param instanceof FeedsImporter) { |
|
440 |
$importer_id = $param->id; |
|
441 |
} |
|
411 | 442 |
elseif ($param->type) { |
412 | 443 |
$importer_id = feeds_get_importer_id($param->type); |
413 | 444 |
} |
... | ... | |
617 | 648 |
if (feeds_importer($importer_id)->config['import_on_create'] && !isset($node->feeds['suppress_import'])) { |
618 | 649 |
$source->startImport(); |
619 | 650 |
} |
620 |
// Schedule source and importer.
|
|
651 |
// Schedule the source.
|
|
621 | 652 |
$source->schedule(); |
622 |
feeds_importer($importer_id)->schedule(); |
|
623 | 653 |
} |
624 | 654 |
} |
625 | 655 |
|
... | ... | |
691 | 721 |
return $extras; |
692 | 722 |
} |
693 | 723 |
|
724 |
/** |
|
725 |
* Implements hook_features_pipe_COMPONENT_alter() for component "feeds_importer". |
|
726 |
* |
|
727 |
* Automatically adds dependencies when a Feed importer is selected in Features. |
|
728 |
*/ |
|
729 |
function feeds_features_pipe_feeds_importer_alter(&$pipe, $data, &$export) { |
|
730 |
foreach ($data as $importer_id) { |
|
731 |
if ($importer = feeds_importer_load($importer_id)) { |
|
732 |
$export['dependencies'] = array_merge($export['dependencies'], $importer->dependencies()); |
|
733 |
} |
|
734 |
} |
|
735 |
} |
|
736 |
|
|
737 |
/** |
|
738 |
* Implements hook_system_info_alter(). |
|
739 |
* |
|
740 |
* Goes through a list of all modules that provide Feeds plugins and makes them |
|
741 |
* required if there are any importers using those plugins. |
|
742 |
*/ |
|
743 |
function feeds_system_info_alter(array &$info, $file, $type) { |
|
744 |
if ($type !== 'module' || !module_hook($file->name, 'feeds_plugins')) { |
|
745 |
return; |
|
746 |
} |
|
747 |
|
|
748 |
// Don't make Feeds require itself, otherwise you can't disable Feeds until |
|
749 |
// all importers are deleted. |
|
750 |
if ($file->name === 'feeds' || !function_exists('ctools_include')) { |
|
751 |
return; |
|
752 |
} |
|
753 |
|
|
754 |
// Get the plugins that belong to the current module. |
|
755 |
ctools_include('plugins'); |
|
756 |
$module_plugins = array(); |
|
757 |
foreach (ctools_get_plugins('feeds', 'plugins') as $plugin_id => $plugin) { |
|
758 |
if ($file->name === $plugin['module']) { |
|
759 |
$module_plugins[$plugin_id] = TRUE; |
|
760 |
} |
|
761 |
} |
|
762 |
|
|
763 |
// Check if any importers are using any plugins from the current module. |
|
764 |
foreach (feeds_importer_load_all(TRUE) as $importer) { |
|
765 |
|
|
766 |
// Skip importers that are defined in code and are provided by the current |
|
767 |
// module. This ensures that modules that define both an importer and a |
|
768 |
// plugin can still be disabled. |
|
769 |
if ($importer->export_type == EXPORT_IN_CODE) { |
|
770 |
$configs = ctools_export_load_object('feeds_importer', 'names', array($importer->id)); |
|
771 |
if (isset($configs[$importer->id]) && $configs[$importer->id]->export_module === $file->name) { |
|
772 |
continue; |
|
773 |
} |
|
774 |
} |
|
775 |
|
|
776 |
$configuration = $importer->getConfig(); |
|
777 |
|
|
778 |
foreach (array('fetcher', 'parser', 'processor') as $plugin_type) { |
|
779 |
$plugin_key = $configuration[$plugin_type]['plugin_key']; |
|
780 |
if (isset($module_plugins[$plugin_key])) { |
|
781 |
$info['required'] = TRUE; |
|
782 |
break 2; |
|
783 |
} |
|
784 |
} |
|
785 |
} |
|
786 |
|
|
787 |
if (empty($info['required'])) { |
|
788 |
return; |
|
789 |
} |
|
790 |
|
|
791 |
if (module_exists('feeds_ui') && user_access('administer feeds')) { |
|
792 |
$info['explanation'] = t('Feeds is currently using this module for one or more <a href="@link">importers</a>', array('@link' => url('admin/structure/feeds'))); |
|
793 |
} |
|
794 |
else { |
|
795 |
$info['explanation'] = t('Feeds is currently using this module for one or more importers'); |
|
796 |
} |
|
797 |
} |
|
798 |
|
|
799 |
/** |
|
800 |
* Implements hook_module_implements_alter(). |
|
801 |
*/ |
|
802 |
function feeds_module_implements_alter(array &$implementations, $hook) { |
|
803 |
if ($hook === 'feeds_processor_targets_alter') { |
|
804 |
// We need two implementations of this hook, so we add one that gets |
|
805 |
// called first, and move the normal one to last. |
|
806 |
$implementations = array('_feeds' => FALSE) + $implementations; |
|
807 |
|
|
808 |
// Move normal implementation to last. |
|
809 |
$group = $implementations['feeds']; |
|
810 |
unset($implementations['feeds']); |
|
811 |
$implementations['feeds'] = $group; |
|
812 |
} |
|
813 |
} |
|
814 |
|
|
815 |
/** |
|
816 |
* Implements hook_feeds_processor_targets_alter(). |
|
817 |
* |
|
818 |
* @see feeds_feeds_processor_targets() |
|
819 |
* @see feeds_feeds_processor_targets_alter() |
|
820 |
*/ |
|
821 |
function _feeds_feeds_processor_targets_alter(array &$targets, $entity_type, $bundle) { |
|
822 |
// If hook_feeds_processor_targets() hasn't been called, for instance, by |
|
823 |
// older processors, invoke it ourself. |
|
824 |
if (!drupal_static('feeds_feeds_processor_targets', FALSE)) { |
|
825 |
$targets += module_invoke_all('feeds_processor_targets', $entity_type, $bundle); |
|
826 |
} |
|
827 |
} |
|
828 |
|
|
829 |
/** |
|
830 |
* Implements hook_flush_caches(). |
|
831 |
*/ |
|
832 |
function feeds_flush_caches() { |
|
833 |
return array('cache_feeds_http'); |
|
834 |
} |
|
835 |
|
|
694 | 836 |
/** |
695 | 837 |
* @} |
696 | 838 |
*/ |
... | ... | |
777 | 919 |
function feeds_cache_clear($rebuild_menu = TRUE) { |
778 | 920 |
cache_clear_all('_feeds_importer_digest', 'cache'); |
779 | 921 |
drupal_static_reset('_feeds_importer_digest'); |
922 |
cache_clear_all('plugins:feeds:plugins', 'cache'); |
|
780 | 923 |
ctools_include('export'); |
781 | 924 |
ctools_export_load_object_reset('feeds_importer'); |
782 | 925 |
drupal_static_reset('_node_types_build'); |
... | ... | |
917 | 1060 |
/** |
918 | 1061 |
* Gets an instance of a class for a given plugin and id. |
919 | 1062 |
* |
920 |
* @param $plugin |
|
1063 |
* @param string $plugin
|
|
921 | 1064 |
* A string that is the key of the plugin to load. |
922 |
* @param $id |
|
1065 |
* @param string $id
|
|
923 | 1066 |
* A string that is the id of the object. |
924 | 1067 |
* |
925 |
* @return |
|
1068 |
* @return FeedsPlugin
|
|
926 | 1069 |
* A FeedsPlugin object. |
927 |
* |
|
928 |
* @throws Exception |
|
929 |
* If plugin can't be instantiated. |
|
930 | 1070 |
*/ |
931 | 1071 |
function feeds_plugin($plugin, $id) { |
932 | 1072 |
ctools_include('plugins'); |
1073 |
|
|
933 | 1074 |
if ($class = ctools_plugin_load_class('feeds', 'plugins', $plugin, 'handler')) { |
934 |
return FeedsConfigurable::instance($class, $id);
|
|
1075 |
return FeedsPlugin::instance($class, $id, ctools_get_plugins('feeds', 'plugins', $plugin));
|
|
935 | 1076 |
} |
1077 |
|
|
936 | 1078 |
$args = array('%plugin' => $plugin, '@id' => $id); |
937 | 1079 |
if (user_access('administer feeds')) { |
938 | 1080 |
$args['@link'] = url('admin/structure/feeds/' . $id); |
... | ... | |
941 | 1083 |
else { |
942 | 1084 |
drupal_set_message(t('Missing Feeds plugin %plugin. Please contact your site administrator.', $args), 'warning', FALSE); |
943 | 1085 |
} |
1086 |
|
|
944 | 1087 |
$class = ctools_plugin_load_class('feeds', 'plugins', 'FeedsMissingPlugin', 'handler'); |
945 |
return FeedsConfigurable::instance($class, $id); |
|
1088 |
|
|
1089 |
return FeedsPlugin::instance($class, $id); |
|
946 | 1090 |
} |
947 | 1091 |
|
948 | 1092 |
/** |
... | ... | |
957 | 1101 |
/** |
958 | 1102 |
* Includes a library file. |
959 | 1103 |
* |
960 |
* @param $file |
|
1104 |
* @param string $file
|
|
961 | 1105 |
* The filename to load from. |
962 |
* @param $library |
|
1106 |
* @param string $library
|
|
963 | 1107 |
* The name of the library. If libraries module is installed, |
964 | 1108 |
* feeds_include_library() will look for libraries with this name managed by |
965 | 1109 |
* libraries module. |
966 | 1110 |
*/ |
967 | 1111 |
function feeds_include_library($file, $library) { |
968 | 1112 |
static $included = array(); |
969 |
static $ignore_deprecated = array('simplepie'); |
|
970 |
|
|
971 |
if (!isset($included[$file])) { |
|
972 |
// Disable deprecated warning for libraries known for throwing them |
|
973 |
if (in_array($library, $ignore_deprecated)) { |
|
974 |
$level = error_reporting(); |
|
975 |
// We can safely use E_DEPRECATED since Drupal 7 requires PHP 5.3+ |
|
976 |
error_reporting($level ^ E_DEPRECATED ^ E_STRICT); |
|
977 |
} |
|
1113 |
|
|
1114 |
$key = $library . '/' . $file; |
|
1115 |
|
|
1116 |
if (!isset($included[$key])) { |
|
1117 |
$included[$key] = FALSE; |
|
978 | 1118 |
|
979 | 1119 |
$library_dir = variable_get('feeds_library_dir', FALSE); |
980 | 1120 |
$feeds_library_path = DRUPAL_ROOT . '/' . drupal_get_path('module', 'feeds') . "/libraries/$file"; |
1121 |
$libraries_path = module_exists('libraries') ? libraries_get_path($library) : FALSE; |
|
981 | 1122 |
|
982 | 1123 |
// Try first whether libraries module is present and load the file from |
983 | 1124 |
// there. If this fails, require the library from the local path. |
984 |
if (module_exists('libraries') && file_exists(libraries_get_path($library) . "/$file")) { |
|
985 |
require libraries_get_path($library) . "/$file"; |
|
986 |
$included[$file] = TRUE; |
|
1125 |
if ($libraries_path && is_file("$libraries_path/$file")) { |
|
1126 |
require "$libraries_path/$file"; |
|
1127 |
$included[$key] = TRUE; |
|
1128 |
} |
|
1129 |
elseif (is_file(DRUPAL_ROOT . '/sites/all/libraries/' . $key)) { |
|
1130 |
require DRUPAL_ROOT . '/sites/all/libraries/' . $key; |
|
1131 |
$included[$key] = TRUE; |
|
987 | 1132 |
} |
988 |
elseif ($library_dir && file_exists("$library_dir/$library/$file")) {
|
|
989 |
require "$library_dir/$library/$file";
|
|
990 |
$included[$file] = TRUE;
|
|
1133 |
elseif ($library_dir && is_file($library_dir . '/' . $key)) {
|
|
1134 |
require $library_dir . '/' . $key;
|
|
1135 |
$included[$key] = TRUE;
|
|
991 | 1136 |
} |
992 |
elseif (file_exists($feeds_library_path)) {
|
|
1137 |
elseif (is_file($feeds_library_path)) {
|
|
993 | 1138 |
// @todo: Throws "Deprecated function: Assigning the return value of new |
994 | 1139 |
// by reference is deprecated." |
995 | 1140 |
require $feeds_library_path; |
996 |
$included[$file] = TRUE;
|
|
1141 |
$included[$key] = TRUE;
|
|
997 | 1142 |
} |
998 |
// Restore error reporting level |
|
999 |
if (isset($level)) { |
|
1000 |
error_reporting($level); |
|
1001 |
} |
|
1002 |
} |
|
1003 |
if (isset($included[$file])) { |
|
1004 |
return TRUE; |
|
1005 | 1143 |
} |
1006 |
return FALSE; |
|
1144 |
|
|
1145 |
return $included[$key]; |
|
1007 | 1146 |
} |
1008 | 1147 |
|
1009 | 1148 |
/** |
1010 | 1149 |
* Checks whether a library is present. |
1011 | 1150 |
* |
1012 |
* @param $file |
|
1151 |
* @param string $file
|
|
1013 | 1152 |
* The filename to load from. |
1014 |
* @param $library |
|
1153 |
* @param string $library
|
|
1015 | 1154 |
* The name of the library. If libraries module is installed, |
1016 | 1155 |
* feeds_library_exists() will look for libraries with this name managed by |
1017 | 1156 |
* libraries module. |
1018 | 1157 |
*/ |
1019 | 1158 |
function feeds_library_exists($file, $library) { |
1020 |
|
|
1021 |
if (module_exists('libraries') && file_exists(libraries_get_path($library) . "/$file")) {
|
|
1159 |
$path = module_exists('libraries') ? libraries_get_path($library) : FALSE; |
|
1160 |
if ($path && is_file($path . '/' . $file)) {
|
|
1022 | 1161 |
return TRUE; |
1023 | 1162 |
} |
1024 |
|
|
1025 |
elseif (file_exists(DRUPAL_ROOT . '/' . drupal_get_path('module', 'feeds') . "/libraries/$file")) { |
|
1163 |
elseif (is_file(DRUPAL_ROOT . "/sites/all/libraries/$library/$file")) { |
|
1164 |
return TRUE; |
|
1165 |
} |
|
1166 |
elseif (is_file(DRUPAL_ROOT . '/' . drupal_get_path('module', 'feeds') . "/libraries/$file")) { |
|
1026 | 1167 |
return TRUE; |
1027 | 1168 |
} |
1028 |
|
|
1029 | 1169 |
elseif ($library_dir = variable_get('feeds_library_dir', FALSE)) { |
1030 |
if (file_exists("$library_dir/$library/$file")) {
|
|
1170 |
if (is_file("$library_dir/$library/$file")) {
|
|
1031 | 1171 |
return TRUE; |
1032 | 1172 |
} |
1033 | 1173 |
} |
... | ... | |
1039 | 1179 |
* Checks whether simplepie exists. |
1040 | 1180 |
*/ |
1041 | 1181 |
function feeds_simplepie_exists() { |
1042 |
return (feeds_library_exists('simplepie.compiled.php', 'simplepie') || |
|
1182 |
return ( |
|
1183 |
feeds_library_exists('autoloader.php', 'simplepie') || |
|
1184 |
feeds_library_exists('simplepie.compiled.php', 'simplepie') || |
|
1043 | 1185 |
feeds_library_exists('simplepie.mini.php', 'simplepie') || |
1044 | 1186 |
feeds_library_exists('simplepie.inc', 'simplepie') |
1045 | 1187 |
); |
... | ... | |
1049 | 1191 |
* Includes the simplepie library. |
1050 | 1192 |
*/ |
1051 | 1193 |
function feeds_include_simplepie() { |
1052 |
$files = array('simplepie.mini.php', 'simplepie.compiled.php', 'simplepie.inc'); |
|
1194 |
$files = array( |
|
1195 |
'autoloader.php', |
|
1196 |
'simplepie.mini.php', |
|
1197 |
'simplepie.compiled.php', |
|
1198 |
'simplepie.inc', |
|
1199 |
); |
|
1053 | 1200 |
|
1054 | 1201 |
foreach ($files as $file) { |
1055 | 1202 |
if (feeds_include_library($file, 'simplepie')) { |
1056 | 1203 |
return TRUE; |
1057 | 1204 |
} |
1058 | 1205 |
} |
1206 |
|
|
1059 | 1207 |
return FALSE; |
1060 | 1208 |
} |
1061 | 1209 |
|
... | ... | |
1157 | 1305 |
* Implements hook_entity_property_info_alter(). |
1158 | 1306 |
*/ |
1159 | 1307 |
function feeds_entity_property_info_alter(&$info) { |
1160 |
// Gather entities supported by Feeds processors. |
|
1161 |
$processors = FeedsPlugin::byType('processor'); |
|
1162 |
$supported_entities = array(); |
|
1163 |
foreach ($processors as $processor) { |
|
1164 |
$instance = feeds_plugin($processor['handler']['class'], '__none__'); |
|
1165 |
if (method_exists($instance, 'entityType')) { |
|
1166 |
$supported_entities[] = $instance->entityType(); |
|
1167 |
} |
|
1168 |
} |
|
1169 |
// Feeds processors can fake the entity info. Only set the property for |
|
1170 |
// defined entities. |
|
1171 |
$supported_entities = array_intersect(array_keys($info), $supported_entities); |
|
1172 | 1308 |
|
1173 |
foreach ($supported_entities as $entity_type) {
|
|
1309 |
foreach ($info as $entity_type => $entity_info) {
|
|
1174 | 1310 |
$info[$entity_type]['properties']['feed_nid'] = array( |
1175 | 1311 |
'label' => 'Feed NID', |
1176 | 1312 |
'type' => 'integer', |
1177 | 1313 |
'description' => t('Nid of the Feed Node that imported this entity.'), |
1178 | 1314 |
'getter callback' => 'feeds_get_feed_nid_entity_callback', |
1179 | 1315 |
); |
1316 |
$info[$entity_type]['properties']['feed_node'] = array( |
|
1317 |
'label' => 'Feed node', |
|
1318 |
'type' => 'node', |
|
1319 |
'description' => t('Feed Node that imported this entity.'), |
|
1320 |
'getter callback' => 'feeds_get_feed_nid_entity_callback', |
|
1321 |
); |
|
1180 | 1322 |
} |
1181 | 1323 |
} |
1182 | 1324 |
|
... | ... | |
1186 | 1328 |
function feeds_get_feed_nid_entity_callback($entity, array $options, $name, $entity_type) { |
1187 | 1329 |
list($entity_id, , ) = entity_extract_ids($entity_type, $entity); |
1188 | 1330 |
|
1189 |
$feed_nid = feeds_get_feed_nid($entity_id, $entity_type); |
|
1190 |
|
|
1191 |
if ($feed_nid === FALSE) { |
|
1192 |
return NULL; |
|
1331 |
$feed_nid = NULL; |
|
1332 |
if ($entity_id) { |
|
1333 |
$feed_nid = feeds_get_feed_nid($entity_id, $entity_type); |
|
1334 |
if ($feed_nid === FALSE) { |
|
1335 |
return NULL; |
|
1336 |
} |
|
1337 |
} |
|
1338 |
// If the entity has no ID (yet) try read the feed nid from the object |
|
1339 |
// directly. |
|
1340 |
elseif (isset($entity->feeds_item->feed_nid)) { |
|
1341 |
$feed_nid = $entity->feeds_item->feed_nid; |
|
1193 | 1342 |
} |
1194 | 1343 |
return $feed_nid; |
1195 | 1344 |
} |
Formats disponibles : Unified diff
Update feeds 7.x-2.0-alpha9 -> 7.x-2.0-beta1
Install lib simplepie 1.3.1