Index: syndication.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/syndication/syndication.module,v retrieving revision 1.47 diff -u -r1.47 syndication.module --- syndication.module 24 Dec 2006 05:07:12 -0000 1.47 +++ syndication.module 8 Apr 2007 23:37:51 -0000 @@ -12,6 +12,13 @@ 'access' => user_access('access content'), 'callback' => 'syndication_page', 'weight' => 6); + + $items[] = array('path' => 'admin/content/syndication', + 'title' => t('RSS feed syndication'), + 'access' => user_access('access administration pages'), + 'callback' => 'drupal_get_form', + 'callback arguments' => array('syndication_admin_settings'), + 'type' => MENU_NORMAL_ITEM); } return $items; } @@ -40,19 +47,24 @@ function syndication_page () { $output = ''; - if (module_exist('atom')) { + if (module_exists('atom')) { $output .= theme('box', t('Atom feed'), l(t('Atom front page feed'), 'atom/feed')); } if (function_exists('blog_feed_user')) { $output .= theme('box', t('Blogs'), syndication_blogs()); } - if (module_exist('aggregator') && user_access('access news feeds')) { + if (module_exists('aggregator') && user_access('access news feeds')) { $output .= theme('box', t('External feeds'), syndication_opml()); } - if (module_exist('taxonomy') && user_access('access content')) { + if (module_exists('taxonomy') && user_access('access content')) { $output .= theme('box', t('Categories'), syndication_vocabularies()); } - + if (module_exists('views') && module_exists('views_rss') && user_access('access content')){ + if ($views = syndication_views_rss()){ //only bother generating the box if there are enabled views feeds + $output .= theme('box', t('Views'), $views); + } + } + // modules may add their own syndication boxes $result = array(); foreach (module_list() as $name) { @@ -70,47 +82,56 @@ } function syndication_blogs() { - if(module_exist('atom')) { - $prefix = '

'. t("At %sn, all users have a %rss and %atom feed for their blog, as well as each individual user.", array ('%sn' => variable_get('site_name', 'Drupal'), '%rss' => l(t('RSS'), 'blog/feed'), '%atom' => l(t('Atom'), 'blog/atom/feed'))). '

'; - } else { - $prefix = '

'. t('At %sn, %all and each user, have an RSS feed for their blog.', array ('%sn' => variable_get('site_name', 'Drupal'), '%all' => l(t('all users'), 'blog/feed'))). '

'; - } $result = db_query_range("SELECT DISTINCT(u.uid), u.name FROM {users} u INNER JOIN {node} n ON u.uid = n.uid WHERE n.type = 'blog' AND n.status = 1", 0, 16); while ($account = db_fetch_object($result)) { $author = $account->name .': '. l(t('RSS feed'), "blog/$account->uid/feed"); - $author .= module_exist('atom') ? ', '. l(t('Atom feed'), "blog/$account->uid/atom/feed") : ''; + $author .= module_exists('atom') ? ', '. l(t('Atom feed'), "blog/$account->uid/atom/feed") : ''; $authors[] = $author; } if ($authors) { - $output = theme('item_list', $authors, t('Recent Blog Authors')); + $output = theme('item_list', $authors, t('Recent Blog Authors')); } + $output .= drupal_get_form('syndication_users_form'); + return $output; +} +function syndication_users_form($form_values = NULL) { + if(module_exists('atom')) { + $prefix = '

'. t("At %sn, all users have a RSS and Atom feed for their blog, as well as each individual user.", array ('%sn' => variable_get('site_name', 'Drupal'), '@rss' => url('blog/feed'), '@atom' => url('blog/atom/feed'))). '

'; + } else { + $prefix = '

'. t('At %sn, all users and each individual user have an RSS feed for their blog.', array ('%sn' => variable_get('site_name', 'Drupal'), '@all' => url('blog/feed'))). '

'; + } + $form['#multistep'] = TRUE; + $form['#redirect'] = FALSE; $form['name'] = array('#type' => 'textfield', '#title' => t('Search users'), '#prefix' => $prefix, - '#description' => t('Enter a username to view her blog feed, and other details.')); + '#description' => t('Enter a username to view his/her blog feed, and other details.')); $form['submit'] = array('#type' => 'button', '#value' => t('Search')); - $output .= drupal_get_form('syndication_users', $form); - - if ($name = $_POST['edit']['name']) { - // TODO: this query was already executed in validate hook. if i knew what i was doing, i would not run it again here. - $result = db_query("SELECT uid, name FROM {users} WHERE uid > 0 and name LIKE '%s' ORDER BY access DESC", '%'. $name. '%'); - $i=0; - while ($account = db_fetch_object($result)) {; - $rows[$i][] = theme('username', $account). ':'; - $rows[$i][] = l(t("RSS feed"), "blog/$account->uid/feed"); - if (module_exist('atom')) { - $rows[$i][] = l(t("Atom feed"), "blog/$account->uid/atom/feed"); + if ($form_values != NULL) { + $output = ''; + if (!empty($form_values['name'])) { + $result = db_query("SELECT uid, name FROM {users} WHERE uid > 0 and name LIKE '%s' ORDER BY access DESC", '%'. $form_values['name']. '%'); + $i=0; + while ($account = db_fetch_object($result)) { + $rows[$i][] = theme('username', $account). ':'; + $rows[$i][] = l(t("RSS feed"), "blog/$account->uid/feed"); + if (module_exists('atom')) { + $rows[$i][] = l(t("Atom feed"), "blog/$account->uid/atom/feed"); + } + $rows[$i][] = l(t("blog"), "blog/$account->uid"); + $i++; } - $rows[$i][] = l(t("blog"), "blog/$account->uid"); - $i++; - } - if ($rows) { - $output .= theme('table', array(), $rows); - } + if ($rows) { + $output .= theme('table', array(), $rows); + } + $form['results'] = array( + '#type' => 'item', + '#title' => t('Search results'), + '#value' => $output); + } } - $output .= $frm; - return $output; + return $form; } // follows a similar pattern from og_vocab.module @@ -119,10 +140,10 @@ foreach (variable_get('syndication_vocabularies', array()) as $vid) { $vocab = taxonomy_get_vocabulary($vid); $tree = taxonomy_get_tree($vid); - // only show first 30 terms. wary of huge vocabs. not ideal. + // only show first 30 terms. wary of huge vocabs. not ideal. $tree = array_slice($tree, 0, 30); $items = syndication_taxonomy_build_list_items($index = 0, $tree); - if ($items) { + if ($items) { $output .= theme('item_list', $items, $vocab->name); } } @@ -139,8 +160,10 @@ if ($count) { $term_path = "taxonomy/term/$term->tid/0/feed"; $term_link = l(t($term->name), $term_path, array('title' => t($term->description))); - if ($term->depth) { + if ($term->depth>0) { $prefix = str_repeat('--', $term->depth). ' '; + } else { + $prefix = ''; } $item = $prefix. $term_link . " ($count)"; $items[] = $item; @@ -153,12 +176,9 @@ return $items; } -function syndication_users_validate($form_id, &$form) { - $result = db_query("SELECT uid, name FROM {users} WHERE name LIKE '%s' AND uid > 0 ORDER BY access DESC", '%'. $form["name"]. '%'); - if (db_num_rows($result)) { - $form['result'] = $result; - } - else { +function syndication_users_form_validate($form_id, $form_values) { + $result = db_query("SELECT uid, name FROM {users} WHERE name LIKE '%s' AND uid > 0 ORDER BY access DESC", '%'. $form_values["name"]. '%'); + if (!db_num_rows($result)) { form_set_error('name', t('Username not found.')); drupal_goto('syndication'); } @@ -170,17 +190,78 @@ return $output; } -function syndication_settings() { +function syndication_views_rss() { + $vids = variable_get('syndication_views', array()); + foreach ($vids as $key => $value){ + if (!$value) unset($vids[$key]); //throw away the vids that aren't enabled + } + if ($vids) { //only bother getting results if at least one vid is enabled + $result = _syndication_return_views_rss_feeds($vids); + while ($view = db_fetch_object($result)) { + $rows[] = l($view->page_title, $view->url . '/feed', array('class' => 'syndication_view_rss')); + } + $output = theme('syndication_views_rss', $rows); + } + return $output; +} + +/** + * Helper function to get all views that generate rss feeds from the database + * Accepts an array of views ids (vids) to limit the results + * + * @param $args - an array of views ids + * @return $result - database result object or null if no feeds exist + */ +function _syndication_return_views_rss_feeds($args = array()){ + if (count($args) > 0) { + for($i == 1; $i <= count($args); $i++){ + $where[] = '%d'; + } + } + if ($where){ + $where_clause = ' AND arg.vid IN ('. implode(', ', $where) .')'; + } + array_unshift($args, 'rss_feed'); //first query argument is always rss_feed + $query = "SELECT v.vid, v.page_title, v.url FROM {view_view} v LEFT JOIN {view_argument} arg ON arg.vid = v.vid WHERE arg.type = '%s'" . $where_clause; + $result = db_query($query, $args); + + if (db_num_rows($result) > 0){ + return $result; + } +} + +function theme_syndication_views_rss($rows){ + if (is_array($rows)){ + $output = theme('item_list', $rows, '', 'ul'); + } + return $output; +} + +function syndication_admin_settings() { foreach (taxonomy_get_vocabularies() as $vid => $vocab) { $options[$vid] = $vocab->name; } - $description = t('Select the vocabularies which should appear in the Categories block on the %page', array('%page' => l(t('syndication page'), 'syndication'))); - $form['syndication_vocabularies'] = array('#type' => 'checkboxes', - '#title' => t('Vocabularies'), - '#options' => $options, - '#default_value' => variable_get('syndication_vocabularies', array()), + $description = t('Select the vocabularies which should appear in the Categories block on the syndication page.', array('@page' => url('syndication'))); + $form['syndication_vocabularies'] = array('#type' => 'checkboxes', + '#title' => t('Vocabularies'), + '#options' => $options, + '#default_value' => variable_get('syndication_vocabularies', array()), '#description' => $description); - return $form; + + $options = array(); + $result = _syndication_return_views_rss_feeds(); + while ($view = db_fetch_object($result)){ + $options[$view->vid] = $view->page_title; + } + + $description = t('Select the views which should appear in the Views block on the syndication page.', array('@page' => url('syndication'))); + $form['syndication_views'] = array('#type' => 'checkboxes', + '#title' => t('Views'), + '#options' => $options, + '#default_value' => variable_get('syndication_views', array()), + '#description' => $description); + $form['array_filter'] = array('#type' => 'value', '#value' => TRUE); + return system_settings_form($form); } function syndication_help($section) {