'syndication', 'title' => t('RSS feeds'), '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; } function syndication_block($op = 'list', $delta = 0) { if($op == 'list') { $blocks[0]['info'] = 'Syndicate (more)'; return $blocks; } elseif ($op == 'view') { if (user_access('access content')) { $block['subject'] = t('Syndicate'); $pagetype = arg(0); if ($pagetype == 'blog') { $userid = arg(1); $linkurl = is_numeric($userid) ? "blog/$userid/feed" : 'blog/feed'; } else { $linkurl = 'rss.xml'; } $block['content'] = theme('feed_icon', url($linkurl)); $block['content'] .= '
'. 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'))). '
'; } $form['name'] = array('#type' => 'textfield', '#title' => t('Search users'), '#prefix' => $prefix, '#description' => t('Enter a username to view her blog feed, and other details.')); $form['submit'] = array('#type' => 'button', '#value' => t('Search')); return $form; } function syndication_blogs() { $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_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 .= drupal_get_form('syndication_users'); if ($name = $_POST['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_exists('atom')) { $rows[$i][] = l(t("Atom feed"), "blog/$account->uid/atom/feed"); } $rows[$i][] = l(t("blog"), "blog/$account->uid"); $i++; } if ($rows) { $output .= theme('table', array(), $rows); } } $output .= $frm; return $output; } // follows a similar pattern from og_vocab.module // should ideally be in taxonomy.module function syndication_vocabularies() { 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. $tree = array_slice($tree, 0, 30); $items = syndication_taxonomy_build_list_items($index = 0, $tree); if ($items) { $output .= theme('item_list', $items, $vocab->name); } } return $output; } // helper function for syndication_taxonomy function syndication_taxonomy_build_list_items(&$index, $tree) { $items = array(); $current_depth = $tree[$index]->depth; while ($index < count($tree) && $tree[$index]->depth >= $current_depth) { $term = $tree[$index]; $count = taxonomy_term_count_nodes($term->tid); 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) { $prefix = str_repeat('--', $term->depth). ' '; } $item = $prefix. $term_link . " ($count)"; $items[] = $item; $index++; } else { $index++; } } 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 { form_set_error('name', t('Username not found.')); drupal_goto('syndication'); } } function syndication_opml() { $url = l(t('this OPML file'), 'aggregator/opml'); $output = t('In addition to displaying RSS feeds, %sn offers %link which lists all RSS feeds that are collected here.', array ('%sn' => variable_get('site_name', 'Drupal'), '%link' => $url)); return $output; } 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' => $description); if(module_exists('views') && module_exists('views_rss')){ $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 %page', array('%page' => l(t('syndication page'), '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) { $output = ''; switch ($section) { case 'admin/help#syndication': $output = syndication_help_intro(); $output .= syndication_help_api(); //TODO move this to Doxygen break; case 'admin/modules#description': $output .= t("Adds a Syndication block, links to more feeds"); break; } return $output; } function syndication_help_intro() { $output = 'Syndication.module offers a web page which centralizes all of the RSS feeds generated by Drupal. This helps users find interesting feeds from your web site.
Currently, the syndication page helps visitors find the following feeds.
function mymodule_syndication() {
// Creating the first box
$box[0]["subject"] = "Existentialism";
$box[0]["content"] = "So many feeds in this world";
// Lets create a one box more
$box[1]["subject"] = "Got any question?";
$box[1]["content"] = "Who, Where, Why, When";
return $block;
}
';
return $output;
}
?>