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
<?php
// $Id$
/**
* @file
*/
/**
* Build overview of available configurations.
*/
function feeds_ui_build_overview() {
$rows = array();
if ($feeds = feeds_load_all()) {
foreach ($feeds as $feed) {
$rows[] = array(
$feed->getId(),
l(t('Edit'), 'admin/build/feeds/edit/'. $feed->getId()) .' | '.
l(t('Delete'), 'admin/build/feeds/delete/'. $feed->getId()),
);
}
}
$rows[] = array(
l(t('New configuration'), 'admin/build/feeds/create'),
' ',
);
$header = array(
t('Configurations'),
t('Operations'),
);
return theme('table', $header, $rows);
}
/**
* Create a new configuration.
*/
function feeds_ui_build_create_form(&$form_state) {
$form = array();
if (!$form_state['storage']['id']) {
$form['id'] = array(
'#type' => 'textfield',
'#title' => t('Id'),
'#description' => t('A unique identifier for this preset.'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Next'),
);
}
else {
$form += _feeds_ui_config_form();
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Create'),
);
}
return $form;
}
/**
* Submit handler for feeds_build_create_form().
*/
function feeds_ui_build_create_form_submit($form, &$form_state) {
if ($form_state['values']['id']) {
$form_state['storage']['id'] = $form_state['values']['id'];
}
else {
// Build and save feed.
feeds_include('feed');
$feed = new Feed($form_state['storage']['id'], $form_state['values']);
$feed->save();
drupal_set_message(t('Created configuration'));
// Unset storage to enable redirect.
unset($form_state['storage']);
$form_state['redirect'] = 'admin/build/feeds';
}
}
/**
* Edit an existing configuration.
*/
function feeds_ui_build_edit_form(&$form_state, $feed) {
$form = _feeds_ui_config_form ($feed);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
/**
* Edit an existing configuration.
*/
function feeds_ui_build_mapping_form(&$form_state, $feed) {
$form = array();
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
/**
* Edit an existing configuration.
*/
function feeds_ui_build_advanced_form(&$form_state, $feed) {
$form = array();
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
/**
* Helper, build edit UI for a feed. Used for editing and creating.
*/
function _feeds_ui_config_form($feed = NULL) {
$form = array();
$plugins = feeds_get_plugins();
$form['plugins'] = array(
'#type' => 'fieldset',
'#title' => t('Plugins'),
);
$form['plugins']['fetcher'] = array(
'#type' => 'radios',
'#title' => t('Fetcher'),
'#options' => $plugins['fetcher'],
'#description' => t('Select a fetcher for this preset'),
'#default_value' => empty($feed) ? key($plugins['fetcher']) : get_class($feed->fetcher),
);
$form['plugins']['parser'] = array(
'#type' => 'radios',
'#title' => t('Parser'),
'#options' => $plugins['parser'],
'#description' => t('Select a parser for this preset'),
'#default_value' => empty($feed) ? key($plugins['parser']) : get_class($feed->parser),
);
if (empty($feed)) {
$default = array(key($plugins['processor']));
}
else {
foreach ($feed->processors as $processor) {
$default[get_class($processor)] = get_class($processor);
}
}
$form['plugins']['processors'] = array(
'#type' => 'checkboxes',
'#title' => t('Processors'),
'#options' => $plugins['processor'],
'#description' => t('Select processors for this preset'),
'#default_value' => $default,
);
$form['settings'] = array(
'#type' => 'fieldset',
'#title' => t('Basic settings'),
);
$form['settings']['content_type'] = array(
'#type' => 'select',
'#title' => t('Attach to content type'),
'#description' => t('When you attach a feeds configuration to a node, you can use nodes for creating feeds on your site.'),
'#options' => array('' => t('None')) + node_get_types('names'),
'#default_value' => '',
);
$form['settings']['update'] = array(
'#type' => 'radios',
'#title' => t('Update existing'),
'#options' => array(1 => t('Yes'), 0 => t('No')),
'#default_value' => 0, // @todo
);
$period = drupal_map_assoc(array(1, 900, 1800, 3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 3628800, 4838400, 7257600, 15724800, 31536000), 'format_interval');
$period[FEEDAPI_CRON_NEVER_REFRESH] = t('Never refresh');
$period[1] = t('As often as possible');
$form['settings']['refresh_period'] = array(
'#type' => 'select',
'#title' => t('Minimum refresh period'),
'#options' => $period,
'#default_value' => 0, // @todo
);
return $form;
}