00001 <?php
00002
00003
00012 function aggregator_admin_overview() {
00013 return aggregator_view();
00014 }
00015
00022 function aggregator_view() {
00023 $result = db_query('SELECT f.*, COUNT(i.iid) AS items FROM {aggregator_feed} f LEFT JOIN {aggregator_item} i ON f.fid = i.fid GROUP BY f.fid, f.title, f.url, f.refresh, f.checked, f.link, f.description, f.etag, f.modified, f.image, f.block ORDER BY f.title');
00024
00025 $output = '<h3>' . t('Feed overview') . '</h3>';
00026
00027 $header = array(t('Title'), t('Items'), t('Last update'), t('Next update'), array('data' => t('Operations'), 'colspan' => '3'));
00028 $rows = array();
00029 while ($feed = db_fetch_object($result)) {
00030 $rows[] = array(l($feed->title, "aggregator/sources/$feed->fid"), format_plural($feed->items, '1 item', '@count items'), ($feed->checked ? t('@time ago', array('@time' => format_interval(time() - $feed->checked))) : t('never')), ($feed->checked ? t('%time left', array('%time' => format_interval($feed->checked + $feed->refresh - time()))) : t('never')), l(t('edit'), "admin/content/aggregator/edit/feed/$feed->fid"), l(t('remove items'), "admin/content/aggregator/remove/$feed->fid"), l(t('update items'), "admin/content/aggregator/update/$feed->fid"));
00031 }
00032 $output .= theme('table', $header, $rows);
00033
00034 $result = db_query('SELECT c.cid, c.title, count(ci.iid) as items FROM {aggregator_category} c LEFT JOIN {aggregator_category_item} ci ON c.cid = ci.cid GROUP BY c.cid, c.title ORDER BY title');
00035
00036 $output .= '<h3>' . t('Category overview') . '</h3>';
00037
00038 $header = array(t('Title'), t('Items'), t('Operations'));
00039 $rows = array();
00040 while ($category = db_fetch_object($result)) {
00041 $rows[] = array(l($category->title, "aggregator/categories/$category->cid"), format_plural($category->items, '1 item', '@count items'), l(t('edit'), "admin/content/aggregator/edit/category/$category->cid"));
00042 }
00043 $output .= theme('table', $header, $rows);
00044
00045 return $output;
00046 }
00047
00055 function aggregator_form_feed(&$form_state, $edit = array('refresh' => 900, 'title' => '', 'url' => '', 'fid' => NULL)) {
00056 $period = drupal_map_assoc(array(900, 1800, 3600, 7200, 10800, 21600, 32400, 43200, 64800, 86400, 172800, 259200, 604800, 1209600, 2419200), 'format_interval');
00057
00058 if ($edit['refresh'] == '') {
00059 $edit['refresh'] = 3600;
00060 }
00061
00062 $form['title'] = array('#type' => 'textfield',
00063 '#title' => t('Title'),
00064 '#default_value' => $edit['title'],
00065 '#maxlength' => 255,
00066 '#description' => t('The name of the feed (or the name of the website providing the feed).'),
00067 '#required' => TRUE,
00068 );
00069 $form['url'] = array('#type' => 'textfield',
00070 '#title' => t('URL'),
00071 '#default_value' => $edit['url'],
00072 '#maxlength' => 255,
00073 '#description' => t('The fully-qualified URL of the feed.'),
00074 '#required' => TRUE,
00075 );
00076 $form['refresh'] = array('#type' => 'select',
00077 '#title' => t('Update interval'),
00078 '#default_value' => $edit['refresh'],
00079 '#options' => $period,
00080 '#description' => t('The length of time between feed updates. (Requires a correctly configured <a href="@cron">cron maintenance task</a>.)', array('@cron' => url('admin/reports/status'))),
00081 );
00082
00083
00084 $options = array();
00085 $values = array();
00086 $categories = db_query('SELECT c.cid, c.title, f.fid FROM {aggregator_category} c LEFT JOIN {aggregator_category_feed} f ON c.cid = f.cid AND f.fid = %d ORDER BY title', $edit['fid']);
00087 while ($category = db_fetch_object($categories)) {
00088 $options[$category->cid] = check_plain($category->title);
00089 if ($category->fid) $values[] = $category->cid;
00090 }
00091 if ($options) {
00092 $form['category'] = array(
00093 '#type' => 'checkboxes',
00094 '#title' => t('Categorize news items'),
00095 '#default_value' => $values,
00096 '#options' => $options,
00097 '#description' => t('New feed items are automatically filed in the checked categories.'),
00098 );
00099 }
00100 $form['submit'] = array(
00101 '#type' => 'submit',
00102 '#value' => t('Save'),
00103 );
00104
00105 if ($edit['fid']) {
00106 $form['delete'] = array(
00107 '#type' => 'submit',
00108 '#value' => t('Delete'),
00109 );
00110 $form['fid'] = array(
00111 '#type' => 'hidden',
00112 '#value' => $edit['fid'],
00113 );
00114 }
00115
00116 return $form;
00117 }
00118
00122 function aggregator_form_feed_validate($form, &$form_state) {
00123 if ($form_state['values']['op'] == t('Save')) {
00124
00125 if (!valid_url($form_state['values']['url'], TRUE)) {
00126 form_set_error('url', t('The URL %url is invalid. Please enter a fully-qualified URL, such as http://www.example.com/feed.xml.', array('%url' => $form_state['values']['url'])));
00127 }
00128
00129 if (isset($form_state['values']['fid'])) {
00130 $result = db_query("SELECT title, url FROM {aggregator_feed} WHERE (title = '%s' OR url = '%s') AND fid <> %d", $form_state['values']['title'], $form_state['values']['url'], $form_state['values']['fid']);
00131 }
00132 else {
00133 $result = db_query("SELECT title, url FROM {aggregator_feed} WHERE title = '%s' OR url = '%s'", $form_state['values']['title'], $form_state['values']['url']);
00134 }
00135 while ($feed = db_fetch_object($result)) {
00136 if (strcasecmp($feed->title, $form_state['values']['title']) == 0) {
00137 form_set_error('title', t('A feed named %feed already exists. Please enter a unique title.', array('%feed' => $form_state['values']['title'])));
00138 }
00139 if (strcasecmp($feed->url, $form_state['values']['url']) == 0) {
00140 form_set_error('url', t('A feed with this URL %url already exists. Please enter a unique URL.', array('%url' => $form_state['values']['url'])));
00141 }
00142 }
00143 }
00144 }
00145
00151 function aggregator_form_feed_submit($form, &$form_state) {
00152 if ($form_state['values']['op'] == t('Delete')) {
00153 $title = $form_state['values']['title'];
00154
00155 unset($form_state['values']['title']);
00156 }
00157 aggregator_save_feed($form_state['values']);
00158 if (isset($form_state['values']['fid'])) {
00159 if (isset($form_state['values']['title'])) {
00160 drupal_set_message(t('The feed %feed has been updated.', array('%feed' => $form_state['values']['title'])));
00161 if (arg(0) == 'admin') {
00162 $form_state['redirect'] = 'admin/content/aggregator/';
00163 return;
00164 }
00165 else {
00166 $form_state['redirect'] = 'aggregator/sources/' . $form_state['values']['fid'];
00167 return;
00168 }
00169 }
00170 else {
00171 watchdog('aggregator', 'Feed %feed deleted.', array('%feed' => $title));
00172 drupal_set_message(t('The feed %feed has been deleted.', array('%feed' => $title)));
00173 if (arg(0) == 'admin') {
00174 $form_state['redirect'] = 'admin/content/aggregator/';
00175 return;
00176 }
00177 else {
00178 $form_state['redirect'] = 'aggregator/sources/';
00179 return;
00180 }
00181 }
00182 }
00183 else {
00184 watchdog('aggregator', 'Feed %feed added.', array('%feed' => $form_state['values']['title']), WATCHDOG_NOTICE, l(t('view'), 'admin/content/aggregator'));
00185 drupal_set_message(t('The feed %feed has been added.', array('%feed' => $form_state['values']['title'])));
00186 }
00187 }
00188
00189 function aggregator_admin_remove_feed($form_state, $feed) {
00190 return confirm_form(
00191 array(
00192 'feed' => array(
00193 '#type' => 'value',
00194 '#value' => $feed,
00195 ),
00196 ),
00197 t('Are you sure you want to remove all items from the feed %feed?', array('%feed' => $feed['title'])),
00198 'admin/content/aggregator',
00199 t('This action cannot be undone.'),
00200 t('Remove items'),
00201 t('Cancel')
00202 );
00203 }
00204
00211 function aggregator_admin_remove_feed_submit($form, &$form_state) {
00212 aggregator_remove($form_state['values']['feed']);
00213 $form_state['redirect'] = 'admin/content/aggregator';
00214 }
00215
00222 function aggregator_admin_refresh_feed($feed) {
00223 aggregator_refresh($feed);
00224 drupal_goto('admin/content/aggregator');
00225 }
00226
00233 function aggregator_admin_settings() {
00234 $items = array(0 => t('none')) + drupal_map_assoc(array(3, 5, 10, 15, 20, 25), '_aggregator_items');
00235 $period = drupal_map_assoc(array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 4838400, 9676800), 'format_interval');
00236
00237 $form['aggregator_allowed_html_tags'] = array(
00238 '#type' => 'textfield', '#title' => t('Allowed HTML tags'), '#size' => 80, '#maxlength' => 255,
00239 '#default_value' => variable_get('aggregator_allowed_html_tags', '<a> <b> <br> <dd> <dl> <dt> <em> <i> <li> <ol> <p> <strong> <u> <ul>'),
00240 '#description' => t('A space-separated list of HTML tags allowed in the content of feed items. (Tags in this list are not removed by Drupal.)'),
00241 );
00242
00243 $form['aggregator_summary_items'] = array(
00244 '#type' => 'select', '#title' => t('Items shown in sources and categories pages') ,
00245 '#default_value' => variable_get('aggregator_summary_items', 3), '#options' => $items,
00246 '#description' => t('Number of feed items displayed in feed and category summary pages.'),
00247 );
00248
00249 $form['aggregator_clear'] = array(
00250 '#type' => 'select', '#title' => t('Discard items older than'),
00251 '#default_value' => variable_get('aggregator_clear', 9676800), '#options' => $period,
00252 '#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'))),
00253 );
00254
00255 $form['aggregator_category_selector'] = array(
00256 '#type' => 'radios', '#title' => t('Category selection type'), '#default_value' => variable_get('aggregator_category_selector', 'checkboxes'),
00257 '#options' => array('checkboxes' => t('checkboxes'), 'select' => t('multiple selector')),
00258 '#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 work well with large numbers of categories.)'),
00259 );
00260
00261 return system_settings_form($form);
00262 }
00263
00271 function aggregator_form_category(&$form_state, $edit = array('title' => '', 'description' => '', 'cid' => NULL)) {
00272 $form['title'] = array('#type' => 'textfield',
00273 '#title' => t('Title'),
00274 '#default_value' => $edit['title'],
00275 '#maxlength' => 64,
00276 '#required' => TRUE,
00277 );
00278 $form['description'] = array('#type' => 'textarea',
00279 '#title' => t('Description'),
00280 '#default_value' => $edit['description'],
00281 );
00282 $form['submit'] = array('#type' => 'submit', '#value' => t('Save'));
00283
00284 if ($edit['cid']) {
00285 $form['delete'] = array('#type' => 'submit', '#value' => t('Delete'));
00286 $form['cid'] = array('#type' => 'hidden', '#value' => $edit['cid']);
00287 }
00288
00289 return $form;
00290 }
00291
00295 function aggregator_form_category_validate($form, &$form_state) {
00296 if ($form_state['values']['op'] == t('Save')) {
00297
00298 if (isset($form_state['values']['cid'])) {
00299 $category = db_fetch_object(db_query("SELECT cid FROM {aggregator_category} WHERE title = '%s' AND cid <> %d", $form_state['values']['title'], $form_state['values']['cid']));
00300 }
00301 else {
00302 $category = db_fetch_object(db_query("SELECT cid FROM {aggregator_category} WHERE title = '%s'", $form_state['values']['title']));
00303 }
00304 if ($category) {
00305 form_set_error('title', t('A category named %category already exists. Please enter a unique title.', array('%category' => $form_state['values']['title'])));
00306 }
00307 }
00308 }
00309
00315 function aggregator_form_category_submit($form, &$form_state) {
00316 if ($form_state['values']['op'] == t('Delete')) {
00317 $title = $form_state['values']['title'];
00318
00319 unset($form_state['values']['title']);
00320 }
00321 aggregator_save_category($form_state['values']);
00322 if (isset($form_state['values']['cid'])) {
00323 if (isset($form_state['values']['title'])) {
00324 drupal_set_message(t('The category %category has been updated.', array('%category' => $form_state['values']['title'])));
00325 if (arg(0) == 'admin') {
00326 $form_state['redirect'] = 'admin/content/aggregator/';
00327 return;
00328 }
00329 else {
00330 $form_state['redirect'] = 'aggregator/categories/' . $form_state['values']['cid'];
00331 return;
00332 }
00333 }
00334 else {
00335 watchdog('aggregator', 'Category %category deleted.', array('%category' => $title));
00336 drupal_set_message(t('The category %category has been deleted.', array('%category' => $title)));
00337 if (arg(0) == 'admin') {
00338 $form_state['redirect'] = 'admin/content/aggregator/';
00339 return;
00340 }
00341 else {
00342 $form_state['redirect'] = 'aggregator/categories/';
00343 return;
00344 }
00345 }
00346 }
00347 else {
00348 watchdog('aggregator', 'Category %category added.', array('%category' => $form_state['values']['title']), WATCHDOG_NOTICE, l(t('view'), 'admin/content/aggregator'));
00349 drupal_set_message(t('The category %category has been added.', array('%category' => $form_state['values']['title'])));
00350 }
00351 }