Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<?php
// $Id$
/**
* @file
* Feeds module.
*/
/**
* Implementation of hook_cron().
*/
function feeds_cron() {
feeds_include('queue');
feeds_queue_refresh();
}
/**
* Implementation of hook_perm().
*/
function feeds_perm() {
return array('use feeds', 'administer feeds');
}
/**
* Implementation of hook_feeds_plugin().
*/
function feeds_feeds_plugin() {
return array(
'FeedsHttpFetcher' => array(
'name' => t('HTTP fetcher'),
'file' => drupal_get_path('module', 'feeds') .'/plugins/FeedsHttpFetcher.inc',
'parent' => 'FeedsFetcher',
),
'FeedsSyndicationParser' => array(
'name' => t('Common syndication parser'),
'file' => drupal_get_path('module', 'feeds') .'/plugins/FeedsSyndicationParser.inc',
'parent' => 'FeedsParser',
),
'FeedsNodeProcessor' => array(
'name' => t('Node processor'),
'file' => drupal_get_path('module', 'feeds') .'/plugins/FeedsNodeProcessor.inc',
'parent' => 'FeedsProcessor',
),
);
}
/**
* Get all available plugins.
*
* @todo: more powerful tracing of parents.
*/
function feeds_get_plugins() {
feeds_include('feed');
$result = array();
$plugins = module_invoke_all('feeds_plugin');
foreach ($plugins as $plugin => $info) {
if ($info['parent'] == 'FeedsFetcher') { // @todo: walk tree.
$result['fetcher'][$plugin] = $info['name'] ? $info['name'] : $plugin;
}
elseif ($info['parent'] == 'FeedsParser') {
$result['parser'][$plugin] = $info['name'] ? $info['name'] : $plugin;
}
elseif ($info['parent'] == 'FeedsProcessor') {
$result['processor'][$plugin] = $info['name'] ? $info['name'] : $plugin;
}
}
return $result;
}
/**
* Load a plugin's file.
*/
function feeds_require_plugin($plugin) {
static $required;
$plugins = module_invoke_all('feeds_plugin');
if ($plugins[$plugin]['file'] && empty($required[$plugin])) {
require($plugins[$plugin]['file']);
$required[$plugin] = TRUE;
}
}
/**
* Menu loader. Loads a feeds configuration.
*/
function feeds_load($id) {
return feeds_get_feed($id);
}
/**
* Load all feeds.
*/
function feeds_load_all() {
ctools_include('export');
$configs = ctools_export_load_object('feeds_configuration', 'conditions', array('class' => 'Feed'));
foreach ($configs as $config) {
$feeds[$config->id] = feeds_get_feed($config->id);
}
return $feeds;
}
/**
* Singleton function.
*/
function feeds_get_feed($id) {
static $instantiated;
feeds_include('feed');
if (!isset($instantiated[$id])) {
$instantiated[$id] = new Feed($id);
}
return $instantiated[$id];
}
/**
* Create a configuration object.
*/
function feeds_create_configuration($id) {
feeds_include('configuration');
}
/**
* Get a configuration object for a given id.
*/
function feeds_get_configuration($id) {
feeds_include('configuration');
}
/**
* Delete a configuration object.
*/
function feeds_delete_configuration($id) {
}
/**
* Attach a configuration to a content type.
*/
function feeds_attach_configuration($id, $content_type) {
}
/**
* Detach a configuration from a content type.
*/
function feeds_detach_configuration($content_type) {
}
/**
* Create a feed.
*/
function feeds_create_feed($configuration) {
feeds_include('configuration');
feeds_include('feed');
$feed = new Feed($configuration);
return $feed;
}
/**
* Retrieve a feed object that is attached to a feed node.
* @todo.
*/
function feeds_get_feed_node($nid) {
$node = node_load($nid);
$configuration = feeds_get_configuration($node->type, TRUE);
}
/**
* Fetches, parses and processes a feed.
*
* @return
* TRUE if the feed could be imported completely,
* FALSE if a timeout occurred.
*/
function feeds_import($id, FeedsResource $source, $timeout = NULL) {
$importer = new FeedImporter($id, $source, $timeout);
return $importer->import();
}
/**
* Determines whether execution time is up.
*/
function feeds_timeout($timeout = NULL) {
$timeout_time = 0;
if ($timeout) {
$timeout_time = time() + $timeout;
}
if (time() > $timeout_time) {
return FALSE;
}
return TRUE;
}
/**
* Includes a feeds module include file.
*/
function feeds_include($file) {
static $included = array();
if (!isset($included[$file])) {
require_once './' . drupal_get_path('module', 'feeds') . "/includes/$file.inc";
}
$included[$file] = TRUE;
}