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

modules/user/views_handler_field_user_picture.inc

00001 <?php
00002 
00008 class views_handler_field_user_picture extends views_handler_field {
00009   function construct() {
00010     parent::construct();
00011     $this->additional_fields['uid'] = 'uid';
00012     $this->additional_fields['name'] = 'name';
00013     $this->additional_fields['mail'] = 'mail';
00014   }
00015 
00016   function element_type($none_supported = FALSE, $default_empty = FALSE, $inline = FALSE) {
00017     if ($inline) {
00018       return 'span';
00019     }
00020     if ($none_supported) {
00021       if ($this->options['element_type'] === '0') {
00022         return '';
00023       }
00024     }
00025     if ($this->options['element_type']) {
00026       return check_plain($this->options['element_type']);
00027     }
00028     if ($default_empty) {
00029       return '';
00030     }
00031     if (isset($this->definition['element type'])) {
00032       return $this->definition['element type'];
00033     }
00034 
00035     return 'div';
00036   }
00037 
00038   function option_definition() {
00039     $options = parent::option_definition();
00040     $options['link_photo_to_profile'] = array('default' => TRUE);
00041     $options['image_style'] = array('default' => '');
00042     return $options;
00043   }
00044 
00045   function options_form(&$form, &$form_state) {
00046     parent::options_form($form, $form_state);
00047     $form['link_photo_to_profile'] = array(
00048       '#title' => t("Link to user's profile"),
00049       '#description' => t("Link the user picture to the user's profile"),
00050       '#type' => 'checkbox',
00051       '#default_value' => $this->options['link_photo_to_profile'],
00052     );
00053 
00054     if (module_exists('image')) {
00055       $styles = image_styles();
00056       $style_options = array('' => t('Default'));
00057       foreach ($styles as $style) {
00058         $style_options[$style['name']] = $style['name'];
00059       }
00060 
00061       $form['image_style'] = array(
00062         '#title' => t('Image style'),
00063         '#description' => t('Using <em>Default</em> will use the site-wide image style for user pictures set in the <a href="!account-settings">Account settings</a>.', array('!account-settings' => url('admin/config/people/accounts', array('fragment' => 'edit-personalization')))),
00064         '#type' => 'select',
00065         '#options' => $style_options,
00066         '#default_value' => $this->options['image_style'],
00067       );
00068     }
00069   }
00070 
00071   function render($values) {
00072     if ($this->options['image_style'] && module_exists('image')) {
00073       // @todo: Switch to always using theme('user_picture') when it starts
00074       // supporting image styles. See http://drupal.org/node/1021564
00075       if ($picture_fid = $this->get_value($values)) {
00076         $picture = file_load($picture_fid);
00077         $picture_filepath = $picture->uri;
00078       }
00079       else {
00080         $picture_filepath = variable_get('user_picture_default', '');
00081       }
00082       if (file_valid_uri($picture_filepath)) {
00083         $output = theme('image_style', array('style_name' => $this->options['image_style'], 'path' => $picture_filepath));
00084         if ($this->options['link_photo_to_profile'] && user_access('access user profiles')) {
00085           $uid = $this->get_value($values, 'uid');
00086           $output = l($output, "user/$uid", array('html' => TRUE));
00087         }
00088       }
00089       else {
00090         $output = '';
00091       }
00092     }
00093     else {
00094       // Fake an account object.
00095       $account = new stdClass();
00096       if ($this->options['link_photo_to_profile']) {
00097         // Prevent template_preprocess_user_picture from adding a link
00098         // by not setting the uid.
00099         $account->uid = $this->get_value($values, 'uid');
00100       }
00101       $account->name = $this->get_value($values, 'name');
00102       $account->mail = $this->get_value($values, 'mail');
00103       $account->picture = $this->get_value($values);
00104       $output = theme('user_picture', array('account' => $account));
00105     }
00106 
00107     return $output;
00108   }
00109 }

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