• Main Page
  • Related Pages
  • Modules
  • Classes
  • Files
  • File List
  • File Members

plugins/views_plugin_display_feed.inc

Go to the documentation of this file.
00001 <?php
00014 class views_plugin_display_feed extends views_plugin_display_page {
00015   function init(&$view, &$display, $options = NULL) {
00016     parent::init($view, $display, $options);
00017 
00018     // Set the default row style. Ideally this would be part of the option
00019     // definition, but in this case it's dependent on the view's base table,
00020     // which we don't know until init().
00021     $row_plugins = views_fetch_plugin_names('row', $this->get_style_type(), array($view->base_table));
00022     $default_row_plugin = key($row_plugins);
00023     if ($this->options['row_plugin'] == '') {
00024       $this->options['row_plugin'] = $default_row_plugin;
00025     }
00026   }
00027 
00028   function uses_breadcrumb() { return FALSE; }
00029   function get_style_type() { return 'feed'; }
00030 
00036   function execute() {
00037     $output = $this->view->render();
00038     if (empty($output)) {
00039       return drupal_not_found();
00040     }
00041     print $output;
00042   }
00043 
00044   function preview() {
00045     if (!empty($this->view->live_preview)) {
00046       return '<pre>' . check_plain($this->view->render()) . '</pre>';
00047     }
00048     return $this->view->render();
00049   }
00050 
00055   function render() {
00056     return $this->view->style_plugin->render($this->view->result);
00057   }
00058 
00059   function defaultable_sections($section = NULL) {
00060     if (in_array($section, array('style_options', 'style_plugin', 'row_options', 'row_plugin',))) {
00061       return FALSE;
00062     }
00063 
00064     $sections = parent::defaultable_sections($section);
00065 
00066     // Tell views our sitename_title option belongs in the title section.
00067     if ($section == 'title') {
00068       $sections[] = 'sitename_title';
00069     }
00070     elseif (!$section) {
00071       $sections['title'][] = 'sitename_title';
00072     }
00073     return $sections;
00074   }
00075 
00076   function option_definition() {
00077     $options = parent::option_definition();
00078 
00079     $options['displays'] = array('default' => array());
00080 
00081     // Overrides for standard stuff:
00082     $options['style_plugin']['default'] = 'rss';
00083     $options['style_options']['default']  = array('description' => '');
00084     $options['sitename_title']['default'] = FALSE;
00085     $options['row_plugin']['default'] = '';
00086     $options['defaults']['default']['style_plugin'] = FALSE;
00087     $options['defaults']['default']['style_options'] = FALSE;
00088     $options['defaults']['default']['row_plugin'] = FALSE;
00089     $options['defaults']['default']['row_options'] = FALSE;
00090 
00091     return $options;
00092   }
00093 
00094   function options_summary(&$categories, &$options) {
00095     // It is very important to call the parent function here:
00096     parent::options_summary($categories, $options);
00097 
00098     // Since we're childing off the 'page' type, we'll still *call* our
00099     // category 'page' but let's override it so it says feed settings.
00100     $categories['page'] = array(
00101       'title' => t('Feed settings'),
00102       'column' => 'second',
00103       'build' => array(
00104         '#weight' => -10,
00105       ),
00106     );
00107 
00108     if ($this->get_option('sitename_title')) {
00109       $options['title']['value'] = t('Using the site name');
00110     }
00111 
00112     // I don't think we want to give feeds menus directly.
00113     unset($options['menu']);
00114 
00115     $displays = array_filter($this->get_option('displays'));
00116     if (count($displays) > 1) {
00117       $attach_to = t('Multiple displays');
00118     }
00119     elseif (count($displays) == 1) {
00120       $display = array_shift($displays);
00121       if (!empty($this->view->display[$display])) {
00122         $attach_to = check_plain($this->view->display[$display]->display_title);
00123       }
00124     }
00125 
00126     if (!isset($attach_to)) {
00127       $attach_to = t('None');
00128     }
00129 
00130     $options['displays'] = array(
00131       'category' => 'page',
00132       'title' => t('Attach to'),
00133       'value' => $attach_to,
00134     );
00135   }
00136 
00140   function options_form(&$form, &$form_state) {
00141     parent::options_form($form, $form_state);
00142     // It is very important to call the parent function here.
00143     parent::options_form($form, $form_state);
00144 
00145     switch ($form_state['section']) {
00146       case 'title':
00147         $title = $form['title'];
00148         // A little juggling to move the 'title' field beyond our checkbox.
00149         unset($form['title']);
00150         $form['sitename_title'] = array(
00151           '#type' => 'checkbox',
00152           '#title' => t('Use the site name for the title'),
00153           '#default_value' => $this->get_option('sitename_title'),
00154         );
00155         $form['title'] = $title;
00156         $form['title']['#dependency'] = array('edit-sitename-title' => array(FALSE));
00157         break;
00158       case 'displays':
00159         $form['#title'] .= t('Attach to');
00160         $displays = array();
00161         foreach ($this->view->display as $display_id => $display) {
00162           if (!empty($display->handler) && $display->handler->accept_attachments()) {
00163             $displays[$display_id] = $display->display_title;
00164           }
00165         }
00166         $form['displays'] = array(
00167           '#type' => 'checkboxes',
00168           '#description' => t('The feed icon will be available only to the selected displays.'),
00169           '#options' => $displays,
00170           '#default_value' => $this->get_option('displays'),
00171         );
00172         break;
00173       case 'path':
00174         $form['path']['#description'] = t('This view will be displayed by visiting this path on your site. It is recommended that the path be something like "path/%/%/feed" or "path/%/%/rss.xml", putting one % in the path for each contextual filter you have defined in the view.');
00175     }
00176   }
00177 
00182   function options_submit(&$form, &$form_state) {
00183     // It is very important to call the parent function here:
00184     parent::options_submit($form, $form_state);
00185     switch ($form_state['section']) {
00186       case 'title':
00187         $this->set_option('sitename_title', $form_state['values']['sitename_title']);
00188         break;
00189       case 'displays':
00190         $this->set_option($form_state['section'], $form_state['values'][$form_state['section']]);
00191         break;
00192     }
00193   }
00194 
00198   function attach_to($display_id) {
00199     $displays = $this->get_option('displays');
00200     if (empty($displays[$display_id])) {
00201       return;
00202     }
00203 
00204     // Defer to the feed style; it may put in meta information, and/or
00205     // attach a feed icon.
00206     $plugin = $this->get_plugin();
00207     if ($plugin) {
00208       $clone = $this->view->clone_view();
00209       $clone->set_display($this->display->id);
00210       $clone->build_title();
00211       $plugin->attach_to($display_id, $this->get_path(), $clone->get_title());
00212 
00213       // Clean up
00214       $clone->destroy();
00215       unset($clone);
00216     }
00217   }
00218 
00219   function uses_link_display() {
00220     return TRUE;
00221   }
00222 }

Generated on Sun Feb 26 2012 12:52:51 for Views by  doxygen 1.7.1