/[drupal]/drupal/modules/aggregator/aggregator.processor.inc
ViewVC logotype

Contents of /drupal/modules/aggregator/aggregator.processor.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.10 - (show annotations) (download) (as text)
Tue Jul 14 10:42:11 2009 UTC (4 months, 2 weeks ago) by dries
Branch: MAIN
CVS Tags: DRUPAL-7-0-UNSTABLE-10, DRUPAL-7-0-UNSTABLE-8, DRUPAL-7-0-UNSTABLE-9
Changes since 1.9: +2 -2 lines
File MIME type: text/x-php
- Patch #504074 by Bojhan, tic2000, royroy, catch, keith.smith et al: improved form description of teaser length setting.
1 <?php
2 // $Id: aggregator.processor.inc,v 1.9 2009/06/05 05:28:28 dries Exp $
3
4 /**
5 * @file
6 * Processor functions for the aggregator module.
7 */
8
9 /**
10 * Implement hook_aggregator_process_info().
11 */
12 function aggregator_aggregator_process_info() {
13 return array(
14 'title' => t('Default processor'),
15 'description' => t('Creates lightweight records from feed items.'),
16 );
17 }
18
19 /**
20 * Implement hook_aggregator_process().
21 */
22 function aggregator_aggregator_process($feed) {
23 if (is_object($feed)) {
24 if (is_array($feed->items)) {
25 foreach ($feed->items as $item) {
26 // Save this item. Try to avoid duplicate entries as much as possible. If
27 // we find a duplicate entry, we resolve it and pass along its ID is such
28 // that we can update it if needed.
29 if (!empty($item['guid'])) {
30 $entry = db_query("SELECT iid, timestamp FROM {aggregator_item} WHERE fid = :fid AND guid = :guid", array(':fid' => $feed->fid, ':guid' => $item['guid']))->fetchObject();
31 }
32 elseif ($item['link'] && $item['link'] != $feed->link && $item['link'] != $feed->url) {
33 $entry = db_query("SELECT iid, timestamp FROM {aggregator_item} WHERE fid = :fid AND link = :link", array(':fid' => $feed->fid, ':link' => $item['link']))->fetchObject();
34 }
35 else {
36 $entry = db_query("SELECT iid, timestamp FROM {aggregator_item} WHERE fid = :fid AND title = :title", array(':fid' => $feed->fid, ':title' => $item['title']))->fetchObject();
37 }
38 if (!$item['timestamp']) {
39 $item['timestamp'] = isset($entry->timestamp) ? $entry->timestamp : REQUEST_TIME;
40 }
41 aggregator_save_item(array('iid' => (isset($entry->iid) ? $entry->iid : ''), 'fid' => $feed->fid, 'timestamp' => $item['timestamp'], 'title' => $item['title'], 'link' => $item['link'], 'author' => $item['author'], 'description' => $item['description'], 'guid' => $item['guid']));
42 }
43 }
44 }
45 }
46
47 /**
48 * Implement hook_aggregator_remove().
49 */
50 function aggregator_aggregator_remove($feed) {
51 $iids = db_query('SELECT iid FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid))->fetchCol();
52 if ($iids) {
53 db_delete('aggregator_category_item')
54 ->condition('iid', $iids, 'IN')
55 ->execute();
56 }
57 db_delete('aggregator_item')
58 ->condition('fid', $feed->fid)
59 ->execute();
60
61 drupal_set_message(t('The news items from %site have been removed.', array('%site' => $feed->title)));
62 }
63
64 /**
65 * Implement hook_form_aggregator_admin_form_alter().
66 *
67 * Form alter aggregator module's own form to keep processor functionality
68 * separate from aggregator API functionality.
69 */
70 function aggregator_form_aggregator_admin_form_alter(&$form, $form_state) {
71 if (in_array('aggregator', variable_get('aggregator_processors', array('aggregator')))) {
72 $info = module_invoke('aggregator', 'aggregator_process', 'info');
73 $items = array(0 => t('none')) + drupal_map_assoc(array(3, 5, 10, 15, 20, 25), '_aggregator_items');
74 $period = drupal_map_assoc(array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 4838400, 9676800), 'format_interval');
75 $period[AGGREGATOR_CLEAR_NEVER] = t('Never');
76
77 // Only wrap into a collapsible fieldset if there is a basic configuration.
78 if (isset($form['basic_conf'])) {
79 $form['modules']['aggregator'] = array(
80 '#type' => 'fieldset',
81 '#title' => t('Default processor settings'),
82 '#description' => $info['description'],
83 '#collapsible' => TRUE,
84 '#collapsed' => !in_array('aggregator', variable_get('aggregator_processors', array('aggregator'))),
85 );
86 }
87 else {
88 $form['modules']['aggregator'] = array();
89 }
90
91 $form['modules']['aggregator']['aggregator_summary_items'] = array(
92 '#type' => 'select',
93 '#title' => t('Items shown in sources and categories pages') ,
94 '#default_value' => variable_get('aggregator_summary_items', 3),
95 '#options' => $items,
96 '#description' => t('Number of feed items displayed in feed and category summary pages.'),
97 );
98
99 $form['modules']['aggregator']['aggregator_clear'] = array(
100 '#type' => 'select',
101 '#title' => t('Discard items older than'),
102 '#default_value' => variable_get('aggregator_clear', 9676800),
103 '#options' => $period,
104 '#description' => t('The length of time to retain feed items before discarding. (Requires a correctly configured <a href="@cron">cron maintenance task</a>.)', array('@cron' => url('admin/reports/status'))),
105 );
106
107 $form['modules']['aggregator']['aggregator_category_selector'] = array(
108 '#type' => 'radios',
109 '#title' => t('Category selection type'),
110 '#default_value' => variable_get('aggregator_category_selector', 'checkboxes'),
111 '#options' => array('checkboxes' => t('checkboxes'),
112 'select' => t('multiple selector')),
113 '#description' => t('The type of category selection widget displayed on categorization pages. (For a small number of categories, checkboxes are easier to use, while a multiple selector works well with large numbers of categories.)'),
114 );
115 $form['modules']['aggregator']['aggregator_teaser_length'] = array(
116 '#type' => 'select',
117 '#title' => t('Length of trimmed description'),
118 '#default_value' => 600,
119 '#options' => drupal_map_assoc(array(0, 200, 400, 600, 800, 1000, 1200, 1400, 1600, 1800, 2000), '_aggregator_characters'),
120 '#description' => t("The maximum number of characters used in the trimmed version of content.")
121 );
122
123 }
124 }
125
126 /**
127 * Helper function for teaser length choices.
128 */
129 function _aggregator_characters($length) {
130 return ($length == 0) ? t('Unlimited') : format_plural($length, '1 character', '@count characters');
131 }
132
133 /**
134 * Add/edit/delete an aggregator item.
135 *
136 * @param $edit
137 * An associative array describing the item to be added/edited/deleted.
138 */
139 function aggregator_save_item($edit) {
140 if ($edit['title'] && empty($edit['iid'])) {
141 $edit['iid'] = db_insert('aggregator_item')
142 ->fields(array(
143 'title' => $edit['title'],
144 'link' => $edit['link'],
145 'author' => $edit['author'],
146 'description' => $edit['description'],
147 'guid' => $edit['guid'],
148 'timestamp' => $edit['timestamp'],
149 'fid' => $edit['fid'],
150 ))
151 ->execute();
152 }
153 if ($edit['iid'] && !$edit['title']) {
154 db_delete('aggregator_item')
155 ->condition('iid', $edit['iid'])
156 ->execute();
157 db_delete('aggregator_category_item')
158 ->condition('iid', $edit['iid'])
159 ->execute();
160 }
161 elseif ($edit['title'] && $edit['link']) {
162 // file the items in the categories indicated by the feed
163 $result = db_query('SELECT cid FROM {aggregator_category_feed} WHERE fid = :fid', array(':fid' => $edit['fid']));
164 foreach ($result as $category) {
165 db_merge('aggregator_category_item')
166 ->key(array('iid' => $edit['iid']))
167 ->fields(array(
168 'cid' => $category->cid,
169 ))
170 ->execute();
171 }
172 }
173 }
174
175 /**
176 * Expire feed items on $feed that are older than aggregator_clear.
177 *
178 * @param $feed
179 * Object describing feed.
180 */
181 function aggregator_expire($feed) {
182 $aggregator_clear = variable_get('aggregator_clear', 9676800);
183
184 if ($aggregator_clear != AGGREGATOR_CLEAR_NEVER) {
185 // Remove all items that are older than flush item timer.
186 $age = REQUEST_TIME - $aggregator_clear;
187 $iids = db_query('SELECT iid FROM {aggregator_item} WHERE fid = :fid AND timestamp < :timestamp', array(
188 ':fid' => $feed->fid,
189 ':timestamp' => $age,
190 ))
191 ->fetchCol();
192 if ($iids) {
193 db_delete('aggregator_category_item')
194 ->condition('iid', $iids, 'IN')
195 ->execute();
196 db_delete('aggregator_item')
197 ->condition('iid', $iids, 'IN')
198 ->execute();
199 }
200 }
201 }

  ViewVC Help
Powered by ViewVC 1.1.2