Newer
Older
Alex Barth
committed
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
<?php
// $Id$
/**
* @file
* Definition of FeedsPlugin class.
*/
/**
* Implement source interface for all plugins.
*
* Note how this class does not attempt to store source information locally.
* Doing this would break the model where source information is represented by
* an object that is being passed into a Feed object and its plugins.
*
* There is only one instance of a Feed or a FeedsPlugin per feed configuration,
* whereas there is one instance of a FeedsSource per feed configuration, per
* source info definition.
*/
abstract class FeedsPlugin extends FeedsConfigurable implements FeedsSourceInterface {
/**
* Constructor.
*
* Initialize class variables.
*/
protected function __construct($id) {
parent::__construct($id);
$this->source_config = $this->sourceDefaults();
}
/**
* Save changes to the configuration of this object.
* Delegate saving to parent (= Feed) which will collect
* information from this object by way of getConfig() and store it.
*/
public function save() {
feeds_importer($this->id)->save();
}
/**
* Returns TRUE if $this->sourceForm() returns a form.
*/
public function hasSourceConfig() {
$form = $this->sourceForm(array());
return !empty($form);
}
/**
* Implementation of FeedsSourceInterface::sourceDefaults().
*/
public function sourceDefaults() {
$values = array_flip(array_keys($this->sourceForm(array())));
foreach ($values as $k => $v) {
$values[$k] = '';
}
return $values;
}
/**
* Callback methods, exposes source form.
*/
public function sourceForm($source_config) {
return array();
}
/**
* Validation handler for sourceForm.
*/
Alex Barth
committed
public function sourceFormValidate(&$source_config) {}
/**
* A source is being saved.
*/
public function sourceSave(FeedsSource $source) {}
/**
* A source is being deleted.
*/
public function sourceDelete(FeedsSource $source) {}
Alex Barth
committed
}
/**
* Used when a plugin is missing.
*/
class FeedsMissingPlugin extends FeedsPlugin {
public function menuItem() {
return array();
}