[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/calendar/calendar_ical/ -> calendar_plugin_display_ical.inc (source)

   1  <?php
   2  // $Id: calendar_plugin_display_ical.inc,v 1.1.2.5 2008/11/25 16:12:36 karens Exp $
   3  /**
   4   * The plugin that handles a feed, such as RSS or atom.
   5   *
   6   * For the most part, feeds are page displays but with some subtle differences.
   7   */
   8  class calendar_plugin_display_ical extends views_plugin_display_page {
   9    
  10    function get_style_type() { return 'ical'; }
  11  
  12    function uses_breadcrumb() { return FALSE; }
  13    
  14    /**
  15     * Feeds do not go through the normal page theming mechanism. Instead, they
  16     * go through their own little theme function and then return NULL so that
  17     * Drupal believes that the page has already rendered itself...which it has.
  18     */
  19    function execute() {
  20      $output = $this->view->render();
  21      if (empty($output)) {
  22        return drupal_not_found();
  23      }
  24      print $output;
  25    }
  26  
  27    function preview() {
  28      return '<pre>' . check_plain($this->view->render()) . '</pre>';
  29    }
  30  
  31    /**
  32     * Instead of going through the standard views_view.tpl.php, delegate this
  33     * to the style handler.
  34     */
  35    function render() {
  36      return $this->view->style_plugin->render($this->view->result);
  37    }
  38  
  39    function defaultable_sections($section = NULL) {
  40      if (in_array($section, array('style_options', 'style_plugin', 'row_options', 'row_plugin',))) {
  41        return FALSE;
  42      }
  43  
  44      $sections = parent::defaultable_sections($section);
  45  
  46      // Tell views our sitename_title option belongs in the title section.
  47      if ($section == 'title') {
  48        $sections[] = 'sitename_title';
  49      }
  50      elseif (!$section) {
  51        $sections['title'][] = 'sitename_title';
  52      }
  53      return $sections;
  54    }
  55  
  56    function option_definition() {
  57      $options = parent::option_definition();
  58  
  59      $options['displays'] = array('default' => array());
  60  
  61      // Overrides for standard stuff:
  62      $options['style_plugin']['default'] = 'rss';
  63      $options['style_options']['default']  = array('mission_description' => FALSE, 'description' => '');
  64      $options['sitename_title']['default'] = FALSE;
  65      $options['row_plugin']['default'] = '';
  66      $options['defaults']['default']['style_plugin'] = FALSE;
  67      $options['defaults']['default']['style_options'] = FALSE;
  68      $options['defaults']['default']['row_plugin'] = FALSE;
  69      $options['defaults']['default']['row_options'] = FALSE;
  70  
  71      return $options;
  72    }
  73  
  74    function options_summary(&$categories, &$options) {
  75      // It is very important to call the parent function here:
  76      parent::options_summary($categories, $options);
  77  
  78      // Since we're childing off the 'page' type, we'll still *call* our
  79      // category 'page' but let's override it so it says feed settings.
  80      $categories['page'] = array(
  81        'title' => t('iCal settings'),
  82      );
  83  
  84      if ($this->get_option('sitename_title')) {
  85        $options['title']['value'] = t('Using the site name');
  86      }
  87  
  88      // I don't think we want to give feeds menus directly.
  89      unset($options['menu']);
  90  
  91      $displays = array_filter($this->get_option('displays'));
  92      if (count($displays) > 1) {
  93        $attach_to = t('Multiple displays');
  94      }
  95      else if (count($displays) == 1) {
  96        $display = array_shift($displays);
  97        if (!empty($this->view->display[$display])) {
  98          $attach_to = $this->view->display[$display]->display_title;
  99        }
 100      }
 101  
 102      if (!isset($attach_to)) {
 103        $attach_to = t('None');
 104      }
 105  
 106      $options['displays'] = array(
 107        'category' => 'page',
 108        'title' => t('Attach to'),
 109        'value' => $attach_to,
 110      );
 111    }
 112  
 113    /**
 114     * Provide the default form for setting options.
 115     */
 116    function options_form(&$form, &$form_state) {
 117      // It is very important to call the parent function here.
 118      parent::options_form($form, $form_state);
 119  
 120      switch ($form_state['section']) {
 121        case 'title':
 122          $title = $form['title'];
 123          // A little juggling to move the 'title' field beyond our checkbox.
 124          unset($form['title']);
 125          $form['sitename_title'] = array(
 126            '#type' => 'checkbox',
 127            '#title' => t('Use the site name for the title'),
 128            '#default_value' => $this->get_option('sitename_title'),
 129          );
 130          $form['title'] = $title;
 131          $form['title']['#process'] = array('views_process_dependency');
 132          $form['title']['#dependency'] = array('edit-sitename-title' => array(FALSE));
 133          break;
 134        case 'displays':
 135          $form['#title'] .= t('Attach to');
 136          $displays = array();
 137          foreach ($this->view->display as $display_id => $display) {
 138            if (!empty($display->handler) && $display->handler->accept_attachments()) {
 139              $displays[$display_id] = $display->display_title;
 140            }
 141          }
 142          $form['displays'] = array(
 143            '#type' => 'checkboxes',
 144            '#description' => t('The ical icon will be shown only on the selected displays.'),
 145            '#options' => $displays,
 146            '#default_value' => $this->get_option('displays'),
 147          );
 148          break;
 149        case 'path':
 150          $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/%/%/ical", putting one % in the path for each argument you have defined in the view.');
 151          break;
 152      }
 153    }
 154  
 155    /**
 156     * Perform any necessary changes to the form values prior to storage.
 157     * There is no need for this function to actually store the data.
 158     */
 159    function options_submit($form, &$form_state) {
 160      // It is very important to call the parent function here:
 161      parent::options_submit($form, $form_state);
 162      switch ($form_state['section']) {
 163        case 'title':
 164          $this->set_option('sitename_title', $form_state['values']['sitename_title']);
 165          break;
 166        case 'displays':
 167          $this->set_option($form_state['section'], $form_state['values'][$form_state['section']]);
 168          break;
 169      }
 170    }
 171  
 172    /**
 173     * Attach to another view.
 174     */
 175    function attach_to($display_id) {
 176      $displays = $this->get_option('displays');
 177      if (empty($displays[$display_id])) {
 178        return;
 179      }
 180  
 181      // Defer to the feed style; it may put in meta information, and/or
 182      // attach a feed icon.
 183      $plugin = $this->get_plugin();
 184      if ($plugin) {
 185        $clone = $this->view->clone_view();
 186        $clone->set_display($this->display->id);
 187        $clone->build_title();
 188        $plugin->attach_to($display_id, $this->get_path(), $clone->get_title());
 189      }
 190    }
 191    
 192    /**
 193     * Display validation.
 194     */
 195    function validate() {
 196      $errors = parent::validate();
 197      
 198      $arguments = $this->display->handler->get_option('arguments');
 199      $filters = $this->display->handler->get_option('filters');
 200          
 201      if (!array_key_exists('date_argument', $arguments) && !array_key_exists('date_filter', $filters)) {
 202        if (empty($this->view->date_info->arg_missing)) {
 203          $errors[] = t("A Calendar period display will not work without a Date argument or a Date filter."); 
 204        }
 205        $this->view->date_info->arg_missing = TRUE;     
 206      }
 207      if (array_key_exists('date_argument', $arguments) && 
 208      ($arguments['date_argument']['default_action'] != 'default' || $arguments['date_argument']['default_argument_type'] != 'date')) {
 209        if (empty($this->view->date_info->arg_missing_default)) {
 210          $errors[] = calendar_errors('missing_argument_default');
 211        }
 212        $this->view->date_info->arg_missing_default = TRUE;
 213      }
 214  
 215      return $errors;
 216    }  
 217  }
 218  


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7